mirror of
https://github.com/golang/go
synced 2024-11-26 21:11:57 -07:00
runtime: fix new scheduler on freebsd, windows
R=devon.odell CC=golang-dev https://golang.org/cl/7443046
This commit is contained in:
parent
8d732368c2
commit
c5f694a5c9
@ -52,7 +52,7 @@ typedef struct G G;
|
|||||||
typedef struct Gobuf Gobuf;
|
typedef struct Gobuf Gobuf;
|
||||||
typedef union Lock Lock;
|
typedef union Lock Lock;
|
||||||
typedef struct M M;
|
typedef struct M M;
|
||||||
typedef struct P P;
|
typedef struct P P;
|
||||||
typedef struct Mem Mem;
|
typedef struct Mem Mem;
|
||||||
typedef union Note Note;
|
typedef union Note Note;
|
||||||
typedef struct Slice Slice;
|
typedef struct Slice Slice;
|
||||||
@ -265,7 +265,7 @@ struct M
|
|||||||
uintptr cret; // return value from C
|
uintptr cret; // return value from C
|
||||||
uint64 procid; // for debuggers, but offset not hard-coded
|
uint64 procid; // for debuggers, but offset not hard-coded
|
||||||
G* gsignal; // signal-handling G
|
G* gsignal; // signal-handling G
|
||||||
uint32 tls[8]; // thread-local storage (for 386 extern register)
|
uint64 tls[4]; // thread-local storage (for x86 extern register)
|
||||||
G* curg; // current running goroutine
|
G* curg; // current running goroutine
|
||||||
P* p; // attached P for executing Go code (nil if not executing Go code)
|
P* p; // attached P for executing Go code (nil if not executing Go code)
|
||||||
P* nextp;
|
P* nextp;
|
||||||
|
@ -38,7 +38,12 @@ TEXT runtime·thr_start(SB),7,$0
|
|||||||
|
|
||||||
MOVL AX, m(CX)
|
MOVL AX, m(CX)
|
||||||
CALL runtime·stackcheck(SB) // smashes AX
|
CALL runtime·stackcheck(SB) // smashes AX
|
||||||
CALL runtime·mstart(SB)
|
|
||||||
|
// newosproc left the function we should call in mp->tls[2] for us.
|
||||||
|
get_tls(CX)
|
||||||
|
MOVQ 8(CX), AX
|
||||||
|
CALL AX
|
||||||
|
|
||||||
MOVL 0, AX // crash (not reached)
|
MOVL 0, AX // crash (not reached)
|
||||||
|
|
||||||
// Exit the entire program (like C exit)
|
// Exit the entire program (like C exit)
|
||||||
|
@ -34,12 +34,18 @@ TEXT runtime·thr_start(SB),7,$0
|
|||||||
|
|
||||||
// set up m, g
|
// set up m, g
|
||||||
get_tls(CX)
|
get_tls(CX)
|
||||||
|
MOVQ 8(CX), AX
|
||||||
MOVQ R13, m(CX)
|
MOVQ R13, m(CX)
|
||||||
MOVQ m_g0(R13), DI
|
MOVQ m_g0(R13), DI
|
||||||
MOVQ DI, g(CX)
|
MOVQ DI, g(CX)
|
||||||
|
|
||||||
CALL runtime·stackcheck(SB)
|
CALL runtime·stackcheck(SB)
|
||||||
CALL runtime·mstart(SB)
|
|
||||||
|
// newosproc left the function we should call in mp->tls[2] for us.
|
||||||
|
get_tls(CX)
|
||||||
|
MOVQ 16(CX), AX
|
||||||
|
CALL AX
|
||||||
|
|
||||||
MOVQ 0, AX // crash (not reached)
|
MOVQ 0, AX // crash (not reached)
|
||||||
|
|
||||||
// Exit the entire program (like C exit)
|
// Exit the entire program (like C exit)
|
||||||
|
@ -33,7 +33,11 @@ TEXT runtime·thr_start(SB),7,$0
|
|||||||
// set up g
|
// set up g
|
||||||
MOVW m_g0(R9), R10
|
MOVW m_g0(R9), R10
|
||||||
BL runtime·emptyfunc(SB) // fault if stack check is wrong
|
BL runtime·emptyfunc(SB) // fault if stack check is wrong
|
||||||
BL runtime·mstart(SB)
|
|
||||||
|
// newosproc left the function we should call in mp->tls[2] for us.
|
||||||
|
MOVW (m_tls+8)(m), R0
|
||||||
|
BL (R0)
|
||||||
|
|
||||||
MOVW $2, R9 // crash (not reached)
|
MOVW $2, R9 // crash (not reached)
|
||||||
MOVW R9, (R9)
|
MOVW R9, (R9)
|
||||||
RET
|
RET
|
||||||
|
@ -260,7 +260,10 @@ TEXT runtime·tstart(SB),7,$0
|
|||||||
|
|
||||||
CALL runtime·stackcheck(SB) // clobbers AX,CX
|
CALL runtime·stackcheck(SB) // clobbers AX,CX
|
||||||
|
|
||||||
CALL runtime·mstart(SB)
|
// start function is in tls[2]
|
||||||
|
get_tls(CX)
|
||||||
|
MOVL 8(CX), AX
|
||||||
|
CALL AX
|
||||||
|
|
||||||
RET
|
RET
|
||||||
|
|
||||||
|
@ -329,7 +329,11 @@ TEXT runtime·tstart_stdcall(SB),7,$0
|
|||||||
CLD
|
CLD
|
||||||
|
|
||||||
CALL runtime·stackcheck(SB) // clobbers AX,CX
|
CALL runtime·stackcheck(SB) // clobbers AX,CX
|
||||||
CALL runtime·mstart(SB)
|
|
||||||
|
// start function is in tls[2]
|
||||||
|
get_tls(CX)
|
||||||
|
MOVQ 16(CX), AX
|
||||||
|
CALL AX
|
||||||
|
|
||||||
XORL AX, AX // return 0 == success
|
XORL AX, AX // return 0 == success
|
||||||
RET
|
RET
|
||||||
|
@ -95,7 +95,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
mp->tls[0] = mp->id; // so 386 asm can find it
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
||||||
if(0){
|
if(0){
|
||||||
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
||||||
stk, mp, gp, fn, mp->id, mp->tls[0], &mp);
|
stk, mp, gp, fn, mp->id, (int32)mp->tls[0], &mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset);
|
runtime·sigprocmask(SIG_SETMASK, &sigset_all, &oset);
|
||||||
|
@ -82,12 +82,13 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
ThrParam param;
|
ThrParam param;
|
||||||
Sigset oset;
|
Sigset oset;
|
||||||
|
|
||||||
USED(fn); // thr_start assumes fn == mstart
|
// thr_start assumes gp == mp->g0
|
||||||
USED(gp); // thr_start assumes gp == mp->g0
|
if(gp != mp->g0)
|
||||||
|
runtime·throw("invalid newosproc gp");
|
||||||
|
|
||||||
if(0){
|
if(0){
|
||||||
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
||||||
stk, mp, gp, fn, mp->id, mp->tls[0], &mp);
|
stk, mp, gp, fn, mp->id, (int32)mp->tls[0], &mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime·sigprocmask(&sigset_all, &oset);
|
runtime·sigprocmask(&sigset_all, &oset);
|
||||||
@ -103,6 +104,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
param.tls_size = sizeof mp->tls;
|
param.tls_size = sizeof mp->tls;
|
||||||
|
|
||||||
mp->tls[0] = mp->id; // so 386 asm can find it
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
||||||
|
mp->tls[2] = (uintptr)fn;
|
||||||
|
|
||||||
runtime·thr_new(¶m, sizeof param);
|
runtime·thr_new(¶m, sizeof param);
|
||||||
runtime·sigprocmask(&oset, nil);
|
runtime·sigprocmask(&oset, nil);
|
||||||
|
@ -143,7 +143,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
mp->tls[0] = mp->id; // so 386 asm can find it
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
||||||
if(0){
|
if(0){
|
||||||
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p clone=%p id=%d/%d ostk=%p\n",
|
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p clone=%p id=%d/%d ostk=%p\n",
|
||||||
stk, mp, gp, fn, runtime·clone, mp->id, mp->tls[0], &mp);
|
stk, mp, gp, fn, runtime·clone, mp->id, (int32)mp->tls[0], &mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable signals during clone, so that the new thread starts
|
// Disable signals during clone, so that the new thread starts
|
||||||
|
@ -153,7 +153,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
if(0) {
|
if(0) {
|
||||||
runtime·printf(
|
runtime·printf(
|
||||||
"newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
"newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
||||||
stk, mp, gp, fn, mp->id, mp->tls[0], &mp);
|
stk, mp, gp, fn, mp->id, (int32)mp->tls[0], &mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp->tls[0] = mp->id; // so 386 asm can find it
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
||||||
|
@ -132,7 +132,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
if(0) {
|
if(0) {
|
||||||
runtime·printf(
|
runtime·printf(
|
||||||
"newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
"newosproc stk=%p m=%p g=%p fn=%p id=%d/%d ostk=%p\n",
|
||||||
stk, mp, gp, fn, mp->id, mp->tls[0], &mp);
|
stk, mp, gp, fn, mp->id, (int32)mp->tls[0], &mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp->tls[0] = mp->id; // so 386 asm can find it
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
||||||
|
@ -228,7 +228,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
mp->tls[0] = mp->id; // so 386 asm can find it
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
||||||
if(0){
|
if(0){
|
||||||
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p rfork=%p id=%d/%d ostk=%p\n",
|
runtime·printf("newosproc stk=%p m=%p g=%p fn=%p rfork=%p id=%d/%d ostk=%p\n",
|
||||||
stk, mp, gp, fn, runtime·rfork, mp->id, mp->tls[0], &mp);
|
stk, mp, gp, fn, runtime·rfork, mp->id, (int32)mp->tls[0], &mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(runtime·rfork(RFPROC|RFMEM|RFNOWAIT, stk, mp, gp, fn) < 0)
|
if(runtime·rfork(RFPROC|RFMEM|RFNOWAIT, stk, mp, gp, fn) < 0)
|
||||||
|
@ -192,8 +192,12 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
|
|||||||
void *thandle;
|
void *thandle;
|
||||||
|
|
||||||
USED(stk);
|
USED(stk);
|
||||||
USED(gp); // assuming gp = mp->g0
|
|
||||||
USED(fn); // assuming fn = mstart
|
// assume gp == mp->g0
|
||||||
|
if(gp != mp->g0)
|
||||||
|
runtime·throw("invalid newosproc gp");
|
||||||
|
|
||||||
|
mp->tls[2] = (uintptr)fn;
|
||||||
|
|
||||||
thandle = runtime·stdcall(runtime·CreateThread, 6,
|
thandle = runtime·stdcall(runtime·CreateThread, 6,
|
||||||
nil, (uintptr)0x20000, runtime·tstart_stdcall, mp,
|
nil, (uintptr)0x20000, runtime·tstart_stdcall, mp,
|
||||||
|
Loading…
Reference in New Issue
Block a user