Skip to content

Commit a140d80

Browse files
committed
improve sigframe and fix test
1 parent 25cf5b8 commit a140d80

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

coregrind/m_sigframe/sigframe-arm64-darwin.c

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,21 @@
5656
be important for Darwin. (be conservative)
5757
*/
5858

59+
const UInt MAGIC_PI = 0x31415927U;
60+
61+
struct vg_sigframe {
62+
UInt magicPI;
63+
UInt sigNo_private;
64+
vki_sigset_t mask;
65+
VexGuestARM64State vex;
66+
VexGuestARM64State vex_shadow1;
67+
VexGuestARM64State vex_shadow2;
68+
};
69+
5970
struct hacky_sigframe {
6071
vki_siginfo_t info;
6172
struct vki_ucontext uc;
62-
63-
unsigned long retcode[2];
64-
65-
UInt magicPI;
66-
UInt sigNo_private;
67-
vki_sigset_t mask;
68-
VexGuestARM64State vex;
69-
VexGuestARM64State vex_shadow1;
70-
VexGuestARM64State vex_shadow2;
73+
struct vg_sigframe vg;
7174
};
7275

7376

@@ -150,16 +153,21 @@ void VG_(sigframe_create)( ThreadId tid,
150153
if (! ML_(sf_maybe_extend_stack)(tst, sp, size, flags))
151154
return; // Give up. No idea if this is correct
152155

153-
frame = (struct hacky_sigframe *) sp;
156+
frame = (struct hacky_sigframe *) sp;
157+
158+
VG_TRACK( pre_mem_write, Vg_CoreSignal, tst->tid, "signal handler internal frame",
159+
(Addr)frame, offsetof(struct hacky_sigframe, vg));
154160

155161
/* save stuff in frame */
156-
// FIXME: track writes?
157-
frame->magicPI = 0x31415927;
158-
frame->sigNo_private = siginfo->si_signo;
159-
frame->mask = tst->sig_mask;
160-
frame->vex = tst->arch.vex;
161-
frame->vex_shadow1 = tst->arch.vex_shadow1;
162-
frame->vex_shadow2 = tst->arch.vex_shadow2;
162+
frame->vg.magicPI = MAGIC_PI;
163+
frame->vg.sigNo_private = siginfo->si_signo;
164+
frame->vg.mask = tst->sig_mask;
165+
frame->vg.vex = tst->arch.vex;
166+
frame->vg.vex_shadow1 = tst->arch.vex_shadow1;
167+
frame->vg.vex_shadow2 = tst->arch.vex_shadow2;
168+
169+
VG_TRACK( post_mem_write, Vg_CoreSignal, tst->tid,
170+
(Addr)frame, offsetof(struct hacky_sigframe, vg));
163171

164172
/* Fill in the siginfo and ucontext. */
165173
VG_TRACK( pre_mem_write, Vg_CoreSignal, tst->tid, "signal handler frame",
@@ -237,19 +245,19 @@ void VG_(sigframe_destroy)( ThreadId tid, Bool isRT )
237245
sp = VG_(get_SP)(tid);
238246

239247
frame = (struct hacky_sigframe *)sp;
240-
vg_assert(frame->magicPI == 0x31415927);
248+
vg_assert(frame->vg.magicPI == MAGIC_PI);
241249

242250
vg_assert(VG_IS_16_ALIGNED((Addr)frame));
243251

244252
/* restore the entire guest state, and shadows, from the frame. */
245-
tst->arch.vex = frame->vex;
246-
tst->arch.vex_shadow1 = frame->vex_shadow1;
247-
tst->arch.vex_shadow2 = frame->vex_shadow2;
253+
tst->arch.vex = frame->vg.vex;
254+
tst->arch.vex_shadow1 = frame->vg.vex_shadow1;
255+
tst->arch.vex_shadow2 = frame->vg.vex_shadow2;
248256
restore_from_ucontext(tst, &frame->uc);
249257

250-
tst->sig_mask = frame->mask;
251-
tst->tmp_sig_mask = frame->mask;
252-
sigNo = frame->sigNo_private;
258+
tst->sig_mask = frame->vg.mask;
259+
tst->tmp_sig_mask = frame->vg.mask;
260+
sigNo = frame->vg.sigNo_private;
253261

254262
if (VG_(clo_trace_signals))
255263
VG_(message)(Vg_DebugMsg,

memcheck/tests/sigaltstack.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@ int main(int argv, char** argc) {
1818
// We give EXEC permissions because this won't work on ppc32 unless you
1919
// ask for an alt stack with EXEC permissions,
2020
// since signal returning requires execution of code on the stack.
21+
#if defined(VGO_darwin)
22+
char *stk = (char *)mmap(0, size, PROT_READ|PROT_WRITE,
23+
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
24+
if (stk == MAP_FAILED) {
25+
perror("mmap");
26+
return 1;
27+
}
28+
#else
2129
char *stk = (char *)mmap(0, size, PROT_READ|PROT_WRITE|PROT_EXEC,
2230
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
31+
#endif
2332
sigstk.ss_sp = stk;
2433

2534
sigstk.ss_size = size;

0 commit comments

Comments
 (0)