]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix new scheduler on freebsd, windows
authorRuss Cox <rsc@golang.org>
Fri, 1 Mar 2013 13:30:11 +0000 (08:30 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 1 Mar 2013 13:30:11 +0000 (08:30 -0500)
R=devon.odell
CC=golang-dev
https://golang.org/cl/7443046

13 files changed:
src/pkg/runtime/runtime.h
src/pkg/runtime/sys_freebsd_386.s
src/pkg/runtime/sys_freebsd_amd64.s
src/pkg/runtime/sys_freebsd_arm.s
src/pkg/runtime/sys_windows_386.s
src/pkg/runtime/sys_windows_amd64.s
src/pkg/runtime/thread_darwin.c
src/pkg/runtime/thread_freebsd.c
src/pkg/runtime/thread_linux.c
src/pkg/runtime/thread_netbsd.c
src/pkg/runtime/thread_openbsd.c
src/pkg/runtime/thread_plan9.c
src/pkg/runtime/thread_windows.c

index 831510fd6f0396b1480e0c49ac4b92415d9dd918..665f15e9241d7a3731464cb0777fd38ec3ec605b 100644 (file)
@@ -52,7 +52,7 @@ typedef       struct  G               G;
 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;
@@ -265,7 +265,7 @@ struct      M
        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;
index 4a9d7b40faf5d604daa34ba34cd8b243da6b515a..f779c666e70eb3dbd2a6ee77979409f268e54d3a 100644 (file)
@@ -38,7 +38,12 @@ TEXT runtime·thr_start(SB),7,$0
        
        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)
index e8c0899cf797aebef1f90ae2efcec5ef18e58f25..94f37021c538000f1f1b36a7de52b33cdbe891cf 100644 (file)
@@ -34,12 +34,18 @@ TEXT runtime·thr_start(SB),7,$0
 
        // 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)
index b6b007759bd32ebce95d1dd996cb588995be17e0..d9e3339324330bb0d869491c4f7cca6d0f193599 100644 (file)
@@ -33,7 +33,11 @@ TEXT runtime·thr_start(SB),7,$0
        // 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
index a4ac7463a36a580393573a1af70dff688b84806e..4cb725e197e6d048f5fe09f023b779e2443ec3c9 100644 (file)
@@ -260,7 +260,10 @@ TEXT runtime·tstart(SB),7,$0
 
        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
 
index fe88f3b7544ac975470b9f0f54cde0276d27384e..94e5d79917ac75277664cc4543ff59865cfdc46a 100644 (file)
@@ -329,7 +329,11 @@ TEXT runtime·tstart_stdcall(SB),7,$0
        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
index 1a13eba1cdbc24a3a7886985525a2f7b68470d3a..1400e6e7bc9b1ecf9cefe91a01f76a93c9a1cadf 100644 (file)
@@ -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
        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);
index d7758eaafbbeada1bf39406f041b1fcb2dd6c1c9..06edc22fe1e5e10ec58dc27dd953044b72c8e459 100644 (file)
@@ -82,12 +82,13 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
        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);
@@ -103,6 +104,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
        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(&param, sizeof param);
        runtime·sigprocmask(&oset, nil);
index 85c3e6b8cf61a143505ac711b31485b76466d47d..3f450580692587873374a837fc88303aebe27441 100644 (file)
@@ -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
        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
index aba8fea7a2ef0a1d5c068049c56fc2b97107dac4..b9ec33acd5f2c0f649cd05251c027d8dfd0ef2bc 100644 (file)
@@ -153,7 +153,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
        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
index 525dc697e018ca2571bc4e9904a12dc912426a27..f35c3bb4413eb024516699dc909910b847da204d 100644 (file)
@@ -132,7 +132,7 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
        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
index f2169e8e68db9af2fc464e18352cbbfd980f1fb1..866b1e7806f92b00f13b225b0381e3acb7be4a49 100644 (file)
@@ -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
        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)
index 4d95e998707267ba6a8178146aa04136ce11ff36..5ff35b811ed06593815126f0a20625ffbf1219e5 100644 (file)
@@ -192,8 +192,12 @@ runtime·newosproc(M *mp, G *gp, void *stk, void (*fn)(void))
        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,