diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-06-30 15:34:22 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-06-30 15:34:22 +0200 |
commit | d39f5aa373a4422f7a5f3ee764fb0f6b0b719d61 (patch) | |
tree | 1833f8b72a4b3a8f00d0d143b079a8fcad01c6ae /src/pkg/runtime/windows | |
parent | 8652e6c371b8905498d3d314491d36c58d5f68d5 (diff) | |
download | golang-upstream/58.tar.gz |
Imported Upstream version 58upstream/58
Diffstat (limited to 'src/pkg/runtime/windows')
-rw-r--r-- | src/pkg/runtime/windows/386/sys.s | 16 | ||||
-rw-r--r-- | src/pkg/runtime/windows/thread.c | 40 |
2 files changed, 48 insertions, 8 deletions
diff --git a/src/pkg/runtime/windows/386/sys.s b/src/pkg/runtime/windows/386/sys.s index 15f7f95b8..d38405075 100644 --- a/src/pkg/runtime/windows/386/sys.s +++ b/src/pkg/runtime/windows/386/sys.s @@ -59,15 +59,21 @@ TEXT runtime·setlasterror(SB),7,$0 TEXT runtime·sigtramp(SB),7,$0 PUSHL BP // cdecl + PUSHL BX + PUSHL SI + PUSHL DI PUSHL 0(FS) CALL runtime·sigtramp1(SB) POPL 0(FS) + POPL DI + POPL SI + POPL BX POPL BP RET -TEXT runtime·sigtramp1(SB),0,$16-28 +TEXT runtime·sigtramp1(SB),0,$16-40 // unwinding? - MOVL info+12(FP), BX + MOVL info+24(FP), BX MOVL 4(BX), CX // exception flags ANDL $6, CX MOVL $1, AX @@ -75,15 +81,15 @@ TEXT runtime·sigtramp1(SB),0,$16-28 // place ourselves at the top of the SEH chain to // ensure SEH frames lie within thread stack bounds - MOVL frame+16(FP), CX // our SEH frame + MOVL frame+28(FP), CX // our SEH frame MOVL CX, 0(FS) // copy arguments for call to sighandler MOVL BX, 0(SP) MOVL CX, 4(SP) - MOVL context+20(FP), BX + MOVL context+32(FP), BX MOVL BX, 8(SP) - MOVL dispatcher+24(FP), BX + MOVL dispatcher+36(FP), BX MOVL BX, 12(SP) CALL runtime·sighandler(SB) diff --git a/src/pkg/runtime/windows/thread.c b/src/pkg/runtime/windows/thread.c index 2ce92dcfb..81ad68033 100644 --- a/src/pkg/runtime/windows/thread.c +++ b/src/pkg/runtime/windows/thread.c @@ -324,13 +324,31 @@ runtime·ctrlhandler1(uint32 type) return 0; } +// Will keep all callbacks in a linked list, so they don't get garbage collected. +typedef struct Callback Callback; +struct Callback { + Callback* link; + void* gobody; + byte asmbody; +}; + +typedef struct Callbacks Callbacks; +struct Callbacks { + Lock; + Callback* link; + int32 n; +}; + +static Callbacks cbs; + // Call back from windows dll into go. byte * runtime·compilecallback(Eface fn, bool cleanstack) { Func *f; int32 argsize, n; - byte *ret, *p; + byte *p; + Callback *c; if(fn.type->kind != KindFunc) runtime·panicstring("not a function"); @@ -348,7 +366,23 @@ runtime·compilecallback(Eface fn, bool cleanstack) if(cleanstack) n += 2; // ... argsize - ret = p = runtime·mal(n); + runtime·lock(&cbs); + for(c = cbs.link; c != nil; c = c->link) { + if(c->gobody == fn.data) { + runtime·unlock(&cbs); + return &c->asmbody; + } + } + if(cbs.n >= 2000) + runtime·throw("too many callback functions"); + c = runtime·mal(sizeof *c + n); + c->gobody = fn.data; + c->link = cbs.link; + cbs.link = c; + cbs.n++; + runtime·unlock(&cbs); + + p = &c->asmbody; // MOVL fn, AX *p++ = 0xb8; @@ -376,7 +410,7 @@ runtime·compilecallback(Eface fn, bool cleanstack) } else *p = 0xc3; - return ret; + return &c->asmbody; } void |