]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix Plan 9 "lingering goroutines bug".
authorYuval Pavel Zholkover <paulzhol@gmail.com>
Fri, 10 Jun 2011 07:23:54 +0000 (17:23 +1000)
committerRob Pike <r@golang.org>
Fri, 10 Jun 2011 07:23:54 +0000 (17:23 +1000)
R=rsc, r
CC=golang-dev
https://golang.org/cl/4589042

src/pkg/runtime/plan9/386/sys.s
src/pkg/runtime/plan9/os.h
src/pkg/runtime/plan9/thread.c

index f760b782fe4a06a0d3f77e7c7d1f8d1a859bff3e..1cb570b68c371703a42cff87fcbe4c9370cc5351 100644 (file)
@@ -9,6 +9,11 @@
 TEXT runtime·setldt(SB),7,$0
        RET
 
+TEXT runtime·open(SB),7,$0
+       MOVL    $14, AX
+       INT     $64
+       RET
+
 TEXT runtime·write(SB),7,$0
        MOVL    $20, AX
        INT     $64
index 9444acc9888317cd41efea7989400cc059c670e5..b2f7357ec64b371031b60467c73affd1a7fdf785 100644 (file)
@@ -6,6 +6,14 @@ extern int32 runtime·write(int32 fd, void* buffer, int32 nbytes);
 extern void runtime·exits(int8* msg);
 extern int32 runtime·brk_(void*);
 
+/* open */
+enum
+{
+       OREAD                   = 0,
+       OWRITE                  = 1,
+       ORDWR                   = 2
+};
+
 /* rfork */
 enum
 {
@@ -22,6 +30,28 @@ enum
        RFREND          = (1<<13),
        RFNOMNT         = (1<<14)
 };
+
+typedef struct Tos Tos;
+typedef intptr Plink;
+
+struct Tos {
+       struct                  /* Per process profiling */
+       {
+               Plink   *pp;    /* known to be 0(ptr) */
+               Plink   *next;  /* known to be 4(ptr) */
+               Plink   *last;
+               Plink   *first;
+               uint32  pid;
+               uint32  what;
+       } prof;
+       uint64  cyclefreq;      /* cycle clock frequency if there is one, 0 otherwise */
+       int64   kcycles;        /* cycles spent in kernel */
+       int64   pcycles;        /* cycles spent in process (kernel + user) */
+       uint32  pid;            /* might as well put the pid here */
+       uint32  clock;
+       /* top of stack is here */
+};
+
 extern int32 runtime·rfork(int32 flags, void *stk, M *m, G *g, void (*fn)(void));
 extern int32 runtime·plan9_semacquire(uint32 *addr, int32 block);
 extern int32 runtime·plan9_semrelease(uint32 *addr, int32 count);
index 7c6ca45a3d66724f0ae666de108ec47dc3453bea..ef9a23e8e2e177a6e5bbe314e7483cd44fb2157a 100644 (file)
@@ -27,24 +27,48 @@ runtime·initsig(int32 queue)
 {
 }
 
+extern Tos *_tos;
 void
 runtime·exit(int32)
 {
+       int32 fd;
+       uint8 buf[128];
+       uint8 tmp[16];
+       uint8 *p, *q;
+       int32 pid;
+       
+       runtime·memclr(buf, sizeof buf);
+       runtime·memclr(tmp, sizeof tmp);
+       pid = _tos->pid;
+
+       /* build path string /proc/pid/notepg */
+       for(q=tmp; pid > 0;) {
+               *q++ = '0' + (pid%10);
+               pid = pid/10;
+       }
+       p = buf;
+       runtime·mcpy((void*)p, (void*)"/proc/", 6);
+       p += 6;
+       for(q--; q >= tmp;)
+               *p++ = *q--;
+       runtime·mcpy((void*)p, (void*)"/notepg", 7);
+       
+       /* post interrupt note */
+       fd = runtime·open(buf, OWRITE);
+       runtime·write(fd, "interrupt", 9);
        runtime·exits(nil);
 }
 
 void
 runtime·newosproc(M *m, G *g, void *stk, void (*fn)(void))
 {
-       USED(m, g, stk, fn);
-       
        m->tls[0] = m->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, m, g, fn, runtime·rfork, m->id, m->tls[0], &m);
        }        
        
-       if (runtime·rfork(RFPROC | RFMEM, stk, m, g, fn) < 0 )
+       if (runtime·rfork(RFPROC|RFMEM|RFNOWAIT, stk, m, g, fn) < 0 )
                runtime·throw("newosproc: rfork failed");
 }