1
0
mirror of https://github.com/golang/go synced 2024-11-21 19:14:44 -07:00

runtime: fix Plan 9 "lingering goroutines bug".

R=rsc, r
CC=golang-dev
https://golang.org/cl/4589042
This commit is contained in:
Yuval Pavel Zholkover 2011-06-10 17:23:54 +10:00 committed by Rob Pike
parent 9b409ac7ee
commit 0924185840
3 changed files with 62 additions and 3 deletions

View 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

View 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);

View 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");
}