1
0
mirror of https://github.com/golang/go synced 2024-10-04 17:21:20 -06:00
go/src/pkg
Russ Cox 2f0cae46d8 runtime: work around kernel bug in Snow Leopard signal handling
Could not take a signal on threads other than the main thread.
If you look at the spinning binary with dtrace, you can see a
fault happening over and over:

    $ dtrace -n '
    fbt::user_trap:entry /execname=="boot32" && self->count < 10/
    {
        self->count++;
        printf("%s %x %x %x %x", probefunc, arg1, arg2, arg3, arg4);
        stack();
        tracemem(arg4, 256);
    }'

    dtrace: description 'fbt::user_trap:entry ' matched 1 probe
    CPU     ID                    FUNCTION:NAME
      1  17015                  user_trap:entry user_trap 0 10 79af0a0 79af0a0
                  mach_kernel`lo_alltraps+0x12a

             0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f  0123456789abcdef
         0: 0e 00 00 00 37 00 00 00 00 00 00 00 1f 00 00 00  ....7...........
        10: 1f 00 00 00 a8 33 00 00 00 00 00 01 00 00 00 00  .....3..........
        20: 98 ba dc fe 07 09 00 00 00 00 00 00 98 ba dc fe  ................
        30: 06 00 00 00 0d 00 00 00 34 00 00 00 9e 1c 00 00  ........4.......
        40: 17 00 00 00 00 02 00 00 ac 30 00 00 1f 00 00 00  .........0......
        50: 00 00 00 00 00 00 00 00 0d 00 00 00 e0 e6 29 00  ..............).
        60: 34 00 00 00 00 00 00 00 9e 1c 00 00 00 00 00 00  4...............
        70: 17 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00  ................
        80: ac 30 00 00 00 00 00 00 1f 00 00 00 00 00 00 00  .0..............
        90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
        a0: 48 00 00 00 10 00 00 00 85 00 00 00 a0 f2 29 00  H.............).
        b0: 69 01 00 02 00 00 00 00 e6 93 04 82 ff 7f 00 00  i...............
        c0: 2f 00 00 00 00 00 00 00 06 02 00 00 00 00 00 00  /...............
        d0: 78 ee 42 01 01 00 00 00 1f 00 00 00 00 00 00 00  x.B.............
        e0: 00 ed 9a 07 00 00 00 00 00 00 00 00 00 00 00 00  ................
        f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

    ...

The memory dump shows a 32-bit exception frame:

    x86_saved_state32

    gs = 0x37
    fs = 0
    es = 0x1f
    ds = 0x1f
    edi = 0x33a8
    esi = 0x01000000
    ebp = 0
    cr2 = 0xfedcba98
    ebx = 0x0907
    edx = 0
    ecx = 0xfedcba98
    eax = 0x06
    trapno = 0x0d
    err = 0x34
    eip = 0x1c9e
    cs = 0x17
    efl = 0x0200
    uesp = 0x30ac
    ss = 0x1f

The cr2 of 0xfedcba98 is the address that the new thread read
to cause the fault, but note that the trap is now a GP fault with
error code 0x34, meaning it's moved past the cr2 problem and on
to an invaild segment selector.  The 0x34 is suspiciously similar
to the 0x37 in gs, and sure enough, OS X forces gs to have
that value in the signal handler, and if your thread hasn't set
up that segment (known as USER_CTHREAD), you'll fault on the IRET
into the signal handler and never be able to handle a signal.

The kernel bug is that it forces segment 0x37 without making sure
it is a valid segment.  Leopard also forced 0x37 but had the courtesy
to set it up first.

Since OS X requires us to set up that segment (using the
thread_fast_set_cthread_self system call), we might as well
use it instead of the more complicated i386_set_ldt call to
set up our per-OS thread storage.

Also add some more zeros to bsdthread_register for new arguments
in Snow Leopard (apparently unnecessary, but being careful).

Fixes #510.

R=r
CC=golang-dev
https://golang.org/cl/824046
2010-04-08 13:24:37 -07:00
..
archive/tar gofmt: experiment: align values in map composites where possible 2010-03-02 13:46:51 -08:00
asn1 gofmt: modified algorithm for alignment of multi-line composite/list entries 2010-03-04 17:37:15 -08:00
big comment typos 2010-03-29 16:31:41 +11:00
bignum Corrected broken assertion. 2010-02-01 16:14:22 -08:00
bufio single argument panic 2010-03-30 10:34:57 -07:00
bytes single argument panic 2010-03-30 10:34:57 -07:00
cmath cmath: new package 2010-04-05 22:10:27 -07:00
compress gofmt: experiment: align values in map composites where possible 2010-03-02 13:46:51 -08:00
container simplify various code using new map index rule 2010-03-30 10:51:11 -07:00
crypto crypto/tls: good defaults 2010-04-05 14:38:02 -07:00
debug debug/proc: fix typo in package documentation 2010-04-02 16:20:47 -07:00
ebnf strings: delete Runes, Bytes 2010-02-25 16:01:29 -08:00
encoding encoding/base64: fix typo in comment 2010-03-08 18:12:25 -08:00
exec exec: add dir argument to Run. 2010-02-18 18:32:33 -08:00
exp simplify various code using new map index rule 2010-03-30 10:51:11 -07:00
expvar simplify various code using new map index rule 2010-03-30 10:51:11 -07:00
flag flags: better tests. 2010-04-06 16:46:52 -07:00
fmt fmt: enable the complex tests now that 8g supports complex 2010-03-09 14:17:14 -08:00
go go/printer: follow-up on CL 802043 2010-03-30 16:49:51 -07:00
gob simplify various code using new map index rule 2010-03-30 10:51:11 -07:00
hash hash/crc64: new package implementing 64-bit CRC 2010-03-12 17:38:18 -08:00
http http: fix documentation example 2010-04-05 22:55:05 -07:00
image image/jpeg: fix typos 2010-03-15 22:10:47 -07:00
io io/ioutil: fix bug in ReadFile when Open succeeds but Stat fails 2010-04-05 23:36:52 -07:00
json json: use panic/recover to handle errors in Marshal 2010-04-01 11:19:37 +11:00
log runtime: fix Caller 2010-04-05 23:36:37 -07:00
math math: atan2 special cases (negative zero) 2010-04-08 13:24:04 -07:00
mime simplify various code using new map index rule 2010-03-30 10:51:11 -07:00
net net: use chan bool instead of chan *netFD to avoid cycle 2010-04-06 16:50:27 -07:00
netchan gofmt: experiment: align values in map composites where possible 2010-03-02 13:46:51 -08:00
nntp nntp: new package, NNTP client 2010-04-04 23:23:48 -07:00
once simplify various code using new map index rule 2010-03-30 10:51:11 -07:00
os syscall: implementing some mingw syscalls required by os package 2010-04-02 01:11:17 -07:00
patch strings: delete Runes, Bytes 2010-02-25 16:01:29 -08:00
path math, path: minor comment fixes 2010-03-11 16:40:32 -08:00
rand gofmt: more consistent formatting of const/var decls 2010-03-16 16:45:54 -07:00
reflect simplify various code using new map index rule 2010-03-30 10:51:11 -07:00
regexp testing/regexp: use recover. 2010-03-31 17:57:50 -07:00
rpc delete all uses of panicln by rewriting them using panic or, 2010-03-24 16:46:53 -07:00
runtime runtime: work around kernel bug in Snow Leopard signal handling 2010-04-08 13:24:37 -07:00
scanner gofmt: experiment: align values in map composites where possible 2010-03-02 13:46:51 -08:00
sort sort: fix comment typo 2010-02-02 23:01:21 -08:00
strconv single argument panic 2010-03-30 10:34:57 -07:00
strings Unicode: provide an ability to supplement the case-mapping tables 2010-03-30 17:51:03 -07:00
sync sync: allow to work on armv5 2010-02-18 15:37:16 -08:00
syscall syscall package: document that errno is zeroed on success 2010-04-06 10:28:55 -07:00
syslog syslog: increase test timeout from 10ms to 100ms 2010-03-11 09:46:16 -08:00
tabwriter tabwriter: use panic/recover to handle errors 2010-03-31 16:01:22 -07:00
template single argument panic 2010-03-30 10:34:57 -07:00
testing testing/regexp: use recover. 2010-03-31 17:57:50 -07:00
time time: do not segment time strings by character class. 2010-03-30 14:54:32 -07:00
unicode Unicode: fix stupid typo in comment. 2010-03-30 18:33:06 -07:00
unsafe runtime: introduce unsafe.New and unsafe.NewArray 2009-12-07 15:51:58 -08:00
utf8 strings: delete Runes, Bytes 2010-02-25 16:01:29 -08:00
utf16 utf16: new package 2010-03-16 18:44:37 -07:00
websocket single argument panic on non-darwin and in comments 2010-03-30 13:15:16 -07:00
xml xml: use io.ReadByter in place of local readByter 2010-03-27 23:12:30 -07:00
deps.bash fix deps.bash. \t does not mean tab in some seds. 2010-04-06 10:53:48 -07:00
Makefile cmath: new package 2010-04-05 22:10:27 -07:00