typedef struct Gobuf Gobuf;
typedef union Lock Lock;
typedef struct M M;
-typedef struct P P;
+typedef struct P P;
typedef struct Mem Mem;
typedef union Note Note;
typedef struct Slice Slice;
uintptr cret; // return value from C
uint64 procid; // for debuggers, but offset not hard-coded
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
P* p; // attached P for executing Go code (nil if not executing Go code)
P* nextp;
MOVL AX, m(CX)
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)
// Exit the entire program (like C exit)
// set up m, g
get_tls(CX)
+ MOVQ 8(CX), AX
MOVQ R13, m(CX)
MOVQ m_g0(R13), DI
MOVQ DI, g(CX)
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)
// Exit the entire program (like C exit)
// set up g
MOVW m_g0(R9), R10
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 R9, (R9)
RET
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
CLD
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
RET
mp->tls[0] = mp->id; // so 386 asm can find it
if(0){
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);
ThrParam param;
Sigset oset;
- USED(fn); // thr_start assumes fn == mstart
- USED(gp); // thr_start assumes gp == mp->g0
+ // thr_start assumes gp == mp->g0
+ if(gp != mp->g0)
+ runtime·throw("invalid newosproc gp");
if(0){
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);
param.tls_size = sizeof mp->tls;
mp->tls[0] = mp->id; // so 386 asm can find it
+ mp->tls[2] = (uintptr)fn;
runtime·thr_new(¶m, sizeof param);
runtime·sigprocmask(&oset, nil);
mp->tls[0] = mp->id; // so 386 asm can find it
if(0){
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
if(0) {
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);
}
mp->tls[0] = mp->id; // so 386 asm can find it
if(0) {
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);
}
mp->tls[0] = mp->id; // so 386 asm can find it
mp->tls[0] = mp->id; // so 386 asm can find it
if(0){
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)
void *thandle;
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,
nil, (uintptr)0x20000, runtime·tstart_stdcall, mp,