Skip to content

Commit 5d88e07

Browse files
authored
feat(amd64): wqthread support for 15.0 (+ QoL for magic_delta) (#126)
1 parent 13421e0 commit 5d88e07

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

coregrind/m_syswrap/syswrap-amd64-darwin.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem,
451451

452452
if (0) VG_(printf)(
453453
"wqthread_hijack: self %#lx, kport %#lx, "
454-
"stackaddr %#lx, workitem %#lx, reuse/flags %x, sp %#lx\n",
455-
self, kport, stackaddr, workitem, (UInt)reuse, sp);
454+
"stackaddr %#lx, workitem %#lx, reuse/flags %#x, kevent_count %d, sp %#lx\n",
455+
self, kport, stackaddr, workitem, (UInt)reuse, kevent_count, sp);
456456

457457
/* Start the thread with all signals blocked. VG_(scheduler) will
458458
set the mask correctly when we finally get there. */
@@ -476,22 +476,14 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem,
476476
/* For whatever reason, tst->os_state.pthread appear to have a
477477
constant offset of 96 on 10.7, but zero on 10.6 and 10.5. No
478478
idea why. */
479-
# if DARWIN_VERS <= DARWIN_10_6
479+
# if DARWIN_VERS <= DARWIN_10_6 || DARWIN_VERS >= DARWIN_10_13
480480
UWord magic_delta = 0;
481481
# elif DARWIN_VERS == DARWIN_10_7 || DARWIN_VERS == DARWIN_10_8
482482
UWord magic_delta = 0x60;
483483
# elif DARWIN_VERS == DARWIN_10_9 \
484484
|| DARWIN_VERS == DARWIN_10_10 \
485485
|| DARWIN_VERS == DARWIN_10_11 \
486-
|| DARWIN_VERS == DARWIN_10_12 \
487-
|| DARWIN_VERS == DARWIN_10_13 \
488-
|| DARWIN_VERS == DARWIN_10_14 \
489-
|| DARWIN_VERS == DARWIN_10_15 \
490-
|| DARWIN_VERS == DARWIN_11_00 \
491-
|| DARWIN_VERS == DARWIN_12_00 \
492-
|| DARWIN_VERS == DARWIN_13_00 \
493-
|| DARWIN_VERS == DARWIN_14_00 \
494-
|| DARWIN_VERS == DARWIN_15_00
486+
|| DARWIN_VERS == DARWIN_10_12
495487
UWord magic_delta = 0xE0;
496488
# else
497489
# error "magic_delta: to be computed on new OS version"
@@ -514,6 +506,10 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem,
514506
tid, (void *)tst, tst->os_state.pthread, self);
515507

516508
vex = &tst->arch.vex;
509+
if (tst->os_state.pthread - magic_delta != self) {
510+
VG_(printf)("wqthread_hijack reuse: tst->os_state.pthread %#lx vs self %#lx (diff: %#lx vs %#lx)\n",
511+
tst->os_state.pthread, self, tst->os_state.pthread - self, magic_delta);
512+
}
517513
vg_assert(tst->os_state.pthread - magic_delta == self);
518514
}
519515
else {

coregrind/m_syswrap/syswrap-arm64-darwin.c

+4
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr kevent_list,
525525
tid, (void *)tst, tst->os_state.pthread, self);
526526

527527
vex = &tst->arch.vex;
528+
if (tst->os_state.pthread - magic_delta != self) {
529+
VG_(printf)("wqthread_hijack reuse: tst->os_state.pthread %#lx vs self %#lx (diff: %#lx vs %#lx)\n",
530+
tst->os_state.pthread, self, tst->os_state.pthread - self, magic_delta);
531+
}
528532
vg_assert(tst->os_state.pthread - magic_delta == self);
529533
}
530534
else {

coregrind/m_syswrap/syswrap-darwin.c

+10
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,19 @@ void update_syncstats ( CheckHowOften cho,
994994
// reorder
995995
static UInt reorder_ctr = 0;
996996
if (i > 0 && 0 == (1 & reorder_ctr++)) {
997+
#if defined(VGA_amd64)
998+
// Some kind of compiler xmm-based optimization which causes a EXC_I386_GPFLT
999+
// happens on amd64 on later macOS versions (seen on 15.0).
1000+
// Instead we do a boring memcpy.
1001+
SyncStats tmp;
1002+
VG_(memcpy)(&tmp, &syncstats[i-1], sizeof(SyncStats));
1003+
VG_(memcpy)(&syncstats[i-1], &syncstats[i], sizeof(SyncStats));
1004+
VG_(memcpy)(&syncstats[i], &tmp, sizeof(SyncStats));
1005+
#else
9971006
SyncStats tmp = syncstats[i-1];
9981007
syncstats[i-1] = syncstats[i];
9991008
syncstats[i] = tmp;
1009+
#endif
10001010
}
10011011
}
10021012

coregrind/m_syswrap/syswrap-x86-darwin.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem,
397397

398398
if (0) VG_(printf)(
399399
"wqthread_hijack: self %#lx, kport %#lx, "
400-
"stackaddr %#lx, workitem %#lx, reuse/flags %x, sp %#lx\n",
401-
self, kport, stackaddr, workitem, reuse, sp);
400+
"stackaddr %#lx, workitem %#lx, reuse/flags %x, kevent_count %d, sp %#lx\n",
401+
self, kport, stackaddr, workitem, reuse, kevent_count, sp);
402402

403403
/* Start the thread with all signals blocked. VG_(scheduler) will
404404
set the mask correctly when we finally get there. */
@@ -454,6 +454,10 @@ void wqthread_hijack(Addr self, Addr kport, Addr stackaddr, Addr workitem,
454454
tid, tst, tst->os_state.pthread, self);
455455

456456
vex = &tst->arch.vex;
457+
if (tst->os_state.pthread - magic_delta != self) {
458+
VG_(printf)("wqthread_hijack reuse: tst->os_state.pthread %#lx vs self %#lx (diff: %#lx vs %#lx)\n",
459+
tst->os_state.pthread, self, tst->os_state.pthread - self, magic_delta);
460+
}
457461
vg_assert(tst->os_state.pthread - magic_delta == self);
458462
}
459463
else {

0 commit comments

Comments
 (0)