This commit is contained in:
cinap_lenrek 2013-05-27 01:20:46 +02:00
commit 6025ad06da
8 changed files with 52 additions and 53 deletions

View file

@ -734,10 +734,6 @@ syscall(Ureg* ureg)
scallnr = ureg->ax; scallnr = ureg->ax;
up->scallnr = scallnr; up->scallnr = scallnr;
if(scallnr == RFORK && up->fpstate == FPactive){
fpsave(&up->fpsave);
up->fpstate = FPinactive;
}
spllo(); spllo();
up->nerrlab = 0; up->nerrlab = 0;

View file

@ -536,7 +536,10 @@ closechanq(Chan *c)
if(up != 0 && palloc.Lock.p != up && canqlock(&clunkq.q)){ if(up != 0 && palloc.Lock.p != up && canqlock(&clunkq.q)){
c = up->dot; c = up->dot;
up->dot = nil; up->dot = nil;
if(!waserror()){
kproc("closeproc", closeproc, nil); kproc("closeproc", closeproc, nil);
poperror();
}
up->dot = c; up->dot = c;
}else }else
wakeup(&clunkq.r); wakeup(&clunkq.r);

View file

@ -748,29 +748,33 @@ rdconf(void)
} else } else
mustrd = 1; mustrd = 1;
/* read it */ if(waserror()){
cc = nil; if(!mustrd)
c = nil;
if (waserror()){
if (cc != nil)
cclose(cc);
if (c)
free(c);
if (!mustrd)
return; return;
nexterror(); nexterror();
} }
/* read it */
cc = namec(s, Aopen, OREAD, 0); cc = namec(s, Aopen, OREAD, 0);
devtab[cc->type]->read(cc, confstr, sizeof confstr, 0); if(waserror()){
cclose(cc);
nexterror();
}
devtab[cc->type]->read(cc, confstr, sizeof confstr, 0);
poperror();
cclose(cc); cclose(cc);
cc = nil;
/* validate, copy and erase config; mconfig will repopulate confstr */ /* validate, copy and erase config; mconfig will repopulate confstr */
if (strncmp(confstr, cfgstr, sizeof cfgstr - 1) != 0) if (strncmp(confstr, cfgstr, sizeof cfgstr - 1) != 0)
error("bad #k config, first line must be: 'fsdev:\\n'"); error("bad #k config, first line must be: 'fsdev:\\n'");
kstrdup(&c, confstr + sizeof cfgstr - 1);
memset(confstr, 0, sizeof confstr);
c = nil;
kstrdup(&c, confstr + sizeof cfgstr - 1);
if(waserror()){
free(c);
nexterror();
}
memset(confstr, 0, sizeof confstr);
/* process config copy one line at a time */ /* process config copy one line at a time */
for (p = c; p != nil && *p != '\0'; p = e){ for (p = c; p != nil && *p != '\0'; p = e){
e = strchr(p, '\n'); e = strchr(p, '\n');
@ -780,8 +784,10 @@ rdconf(void)
e++; e++;
mconfig(p, e - p); mconfig(p, e - p);
} }
USED(cc); /* until now, can be used in waserror clause */
poperror(); poperror();
free(c);
poperror(); /* mustrd */
} }
static int static int

View file

@ -1558,10 +1558,10 @@ sdwstat(Chan* c, uchar* dp, int n)
d = nil; d = nil;
if(waserror()){ if(waserror()){
free(d);
qunlock(&unit->ctl); qunlock(&unit->ctl);
if(sdev != nil) if(sdev != nil)
decref(&sdev->r); decref(&sdev->r);
free(d);
nexterror(); nexterror();
} }
@ -1600,13 +1600,11 @@ sdwstat(Chan* c, uchar* dp, int n)
error(Eperm); error(Eperm);
if(d[0].mode != ~0UL) if(d[0].mode != ~0UL)
perm->perm = (perm->perm & ~0777) | (d[0].mode & 0777); perm->perm = (perm->perm & ~0777) | (d[0].mode & 0777);
poperror();
free(d);
d = nil; USED(d);
qunlock(&unit->ctl); qunlock(&unit->ctl);
if(sdev != nil) if(sdev != nil)
decref(&sdev->r); decref(&sdev->r);
poperror(); free(d);
return n; return n;
} }

View file

@ -421,7 +421,6 @@ struct Segment
Pte **map; Pte **map;
int mapsize; int mapsize;
Pte *ssegmap[SSEGMAPSIZE]; Pte *ssegmap[SSEGMAPSIZE];
Lock semalock;
Sema sema; Sema sema;
ulong mark; /* portcountrefs */ ulong mark; /* portcountrefs */
}; };

View file

@ -1067,7 +1067,7 @@ pexit(char *exitstr, int freemem)
Proc *p; Proc *p;
Segment **s, **es; Segment **s, **es;
long utime, stime; long utime, stime;
Waitq *wq, *f, *next; Waitq *wq;
Fgrp *fgrp; Fgrp *fgrp;
Egrp *egrp; Egrp *egrp;
Rgrp *rgrp; Rgrp *rgrp;
@ -1178,9 +1178,9 @@ pexit(char *exitstr, int freemem)
wakeup(&up->waitr); wakeup(&up->waitr);
unlock(&up->exl); unlock(&up->exl);
for(f = up->waitq; f; f = next) { while((wq = up->waitq) != 0){
next = f->next; up->waitq = wq->next;
free(f); free(wq);
} }
/* release debuggers */ /* release debuggers */
@ -1374,7 +1374,6 @@ kproc(char *name, void (*func)(void *), void *arg)
p->kp = 1; p->kp = 1;
p->noswap = 1; p->noswap = 1;
p->fpsave = up->fpsave;
p->scallnr = up->scallnr; p->scallnr = up->scallnr;
p->s = up->s; p->s = up->s;
p->nerrlab = 0; p->nerrlab = 0;

View file

@ -264,7 +264,10 @@ attachimage(int type, Chan *c, ulong base, ulong len)
while(!(i = imagealloc.free)) { while(!(i = imagealloc.free)) {
unlock(&imagealloc); unlock(&imagealloc);
imagereclaim(); imagereclaim();
sched(); if(!imagealloc.free){
freebroken(); /* can use the memory */
resrcwait("no image after reclaim");
}
lock(&imagealloc); lock(&imagealloc);
} }
@ -328,7 +331,7 @@ imagereclaim(void)
* end of the list (see putpage) so start there and work * end of the list (see putpage) so start there and work
* backward. * backward.
*/ */
for(p = palloc.tail; p && p->image && n<1000; p = p->prev) { for(p = palloc.tail; p && p->image && (n<1000 || !imagealloc.free); p = p->prev) {
if(p->ref == 0 && canlock(p)) { if(p->ref == 0 && canlock(p)) {
if(p->ref == 0) { if(p->ref == 0) {
n++; n++;

View file

@ -226,7 +226,7 @@ sysexec(ulong *arg)
char *a, *charp, *args, *file, *file0; char *a, *charp, *args, *file, *file0;
char *progarg[sizeof(Exec)/2+1], *elem, progelem[64]; char *progarg[sizeof(Exec)/2+1], *elem, progelem[64];
ulong ssize, tstk, nargs, nbytes, n, bssend; ulong ssize, tstk, nargs, nbytes, n, bssend;
int indir, commit; int indir;
Exec exec; Exec exec;
char line[sizeof(Exec)]; char line[sizeof(Exec)];
Fgrp *f; Fgrp *f;
@ -234,16 +234,16 @@ sysexec(ulong *arg)
ulong magic, text, entry, data, bss; ulong magic, text, entry, data, bss;
Tos *tos; Tos *tos;
commit = 0;
indir = 0; indir = 0;
elem = nil; elem = nil;
validaddr(arg[0], 1, 0); validaddr(arg[0], 1, 0);
file0 = validnamedup((char*)arg[0], 1); file0 = validnamedup((char*)arg[0], 1);
if(waserror()){ if(waserror()){
free(file0); free(file0);
if(elem != up->text)
free(elem); free(elem);
/* Disaster after commit */ /* Disaster after commit */
if(commit) if(!up->seg[SSEG])
pexit(up->errstr, 1); pexit(up->errstr, 1);
nexterror(); nexterror();
} }
@ -386,14 +386,9 @@ sysexec(ulong *arg)
memmove(charp, *argp++, n); memmove(charp, *argp++, n);
charp += n; charp += n;
} }
free(file0);
file0 = nil; /* so waserror() won't free file0 */
USED(file0);
free(up->text); free(up->text);
up->text = elem; up->text = elem;
elem = nil; /* so waserror() won't free elem */
USED(elem);
/* copy args; easiest from new process's stack */ /* copy args; easiest from new process's stack */
n = charp - args; n = charp - args;
@ -415,9 +410,6 @@ sysexec(ulong *arg)
} }
up->nargs = n; up->nargs = n;
commit = 1;
USED(commit);
/* /*
* Committed. * Committed.
* Free old memory. * Free old memory.
@ -428,9 +420,9 @@ sysexec(ulong *arg)
/* prevent a second free if we have an error */ /* prevent a second free if we have an error */
up->seg[i] = 0; up->seg[i] = 0;
} }
for(i = BSEG+1; i < NSEG; i++) { for(i = ESEG+1; i < NSEG; i++) {
s = up->seg[i]; s = up->seg[i];
if(s != 0 && (s->type&SG_CEXEC)) { if(s != 0 && (s->type&SG_CEXEC) != 0) {
putseg(s); putseg(s);
up->seg[i] = 0; up->seg[i] = 0;
} }
@ -439,9 +431,10 @@ sysexec(ulong *arg)
/* /*
* Close on exec * Close on exec
*/ */
f = up->fgrp; if((f = up->fgrp) != nil){
for(i=0; i<=f->maxfd; i++) for(i=0; i<=f->maxfd; i++)
fdclose(i, CCEXEC); fdclose(i, CCEXEC);
}
/* Text. Shared. Attaches to cache image if possible */ /* Text. Shared. Attaches to cache image if possible */
/* attachimage returns a locked cache image */ /* attachimage returns a locked cache image */
@ -484,9 +477,10 @@ sysexec(ulong *arg)
if(devtab[tc->type]->dc == L'/') if(devtab[tc->type]->dc == L'/')
up->basepri = PriRoot; up->basepri = PriRoot;
up->priority = up->basepri; up->priority = up->basepri;
cclose(tc);
poperror(); /* tc */ poperror(); /* tc */
poperror(); /* elem */ cclose(tc);
poperror(); /* file0 */
free(file0);
qlock(&up->debug); qlock(&up->debug);
up->nnote = 0; up->nnote = 0;
@ -830,9 +824,9 @@ sysrendezvous(ulong *arg)
val = p->rendval; val = p->rendval;
p->rendval = arg[1]; p->rendval = arg[1];
unlock(up->rgrp); unlock(up->rgrp);
while(p->mach != 0)
;
ready(p); ready(p);
return val; return val;
} }
l = &p->rendhash; l = &p->rendhash;
@ -1140,7 +1134,8 @@ syssemrelease(ulong *arg)
if((s = seg(up, (ulong)addr, 0)) == nil) if((s = seg(up, (ulong)addr, 0)) == nil)
error(Ebadarg); error(Ebadarg);
/* delta == 0 is a no-op, not a release */
if(delta < 0 || *addr < 0) if(delta < 0 || *addr < 0)
error(Ebadarg); error(Ebadarg);
return semrelease(s, addr, arg[1]); return semrelease(s, addr, delta);
} }