Changeset 11565

Dec 31, 2008, 1:02:15 AM (11 years ago)

Implement DarwinSigReturn? in terms of the new darwin_sigreturn glue.
We've been trying to do sigreturn via a syscall, but haven't been
doing the syscall correctly. The syscall's been returning with an
error (and without setting the thread's context), and we've been
falling off the end of the functions that use DarwinSigReturn?
(suspend_resume_handler, interrupt_handler) and returning to code in
sigtramp() which does a sigreturn to whatever context is in %esi/%rbx.
We've done So Many Bad Things (copying contexts between stacks,
switching stacks) that what's in that register (a C nvr) is pretty
arbitrary, but it seems to be one of (a) predictably the right thing,
if the interrupt occurred on the foreign stack; (b) accidentally the
right thing, if the nvr contained the "right" context (c) the old
context - received on the lisp stack - if the nvr was not used or
was used to hold the old context before copying.

When -O2 was in effect on Darwin, it seems that we lucked out and
accidentally got (b), which means that a thread's context was restored
to something that may have been updated by the GC. With less aggressive
optimization settings, a thread that was running lisp code when suspended
or interrupted would resume with its registers pointing to where they'd
pointed before the GC ran (as it often would have in the suspend case).

I think that this is likely to be a large part of the 'things are flaky
unless -O2 is in effect' problems that've been around for a while. There
may be other bugs (e.g., bogus TRAs on the lisp stack) that aren't related
to this, but it hasn't been possible to debug them with -O2 in effect and
-O2 seems to have accidentally masked this sigreturn problem.

1 edited


  • trunk/source/lisp-kernel/x86-exceptions.h

    r11521 r11565  
    3333#include <sys/syscall.h>
    34 #define DarwinSigReturn(context) syscall(0x2000000|SYS_sigreturn,context,0x1e)
     34#define DarwinSigReturn(context) do {\
     35    darwin_sigreturn(context);\
     36    Bug(context,"sigreturn returned");\
     37  } while (0)
    3539#define xpGPRvector(x) ((natural *)(&(UC_MCONTEXT(x)->__ss)))
    3640#define xpGPR(x,gprno) (xpGPRvector(x)[gprno])
Note: See TracChangeset for help on using the changeset viewer.