kstrdup(&elem, up->genbuf);
n = devtab[tc->type]->read(tc, &exec, sizeof(Exec), 0);
- if(n < 2)
+ if(n <= 2)
error(Ebadexec);
magic = l2be(exec.magic);
- text = l2be(exec.text);
- entry = l2be(exec.entry);
- if(n==sizeof(Exec) && (magic == AOUT_MAGIC)){
- if(magic == S_MAGIC){
+ if(n == sizeof(Exec) && magic == AOUT_MAGIC){
+ text = l2be(exec.text);
+ entry = l2be(exec.entry);
+ switch(magic){
+ case S_MAGIC:
text += 8;
- align = 0x200000ull; /* 2MB segment alignment for amd64 */
+ align = 0x200000; /* 2MB segment alignment for amd64 */
+ break;
+ case V_MAGIC:
+ align = 0x4000; /* MIPS has 16K page alignment */
+ break;
}
if(text >= (USTKTOP-USTKSIZE)-(UTZERO+sizeof(Exec))
|| entry < UTZERO+sizeof(Exec)
/*
* Process #! /bin/sh args ...
*/
- memmove(line, &exec, sizeof(Exec));
+ memmove(line, &exec, n);
if(indir || line[0]!='#' || line[1]!='!')
error(Ebadexec);
n = shargs(line, n, progarg);
- if(n == 0)
+ if(n < 1)
error(Ebadexec);
indir = 1;
/*
* First arg becomes complete file name
*/
progarg[n++] = file;
- progarg[n] = 0;
+ progarg[n] = nil;
argp0++;
file = progarg[0];
if(strlen(elem) >= sizeof progelem)
s += 2;
n -= 2; /* skip #! */
- for(i=0; s[i]!='\n'; i++)
- if(i == n-1)
+ for(i=0;; i++){
+ if(i >= n)
return 0;
+ if(s[i]=='\n')
+ break;
+ }
s[i] = 0;
- *ap = 0;
+
i = 0;
for(;;) {
while(*s==' ' || *s=='\t')
s++;
if(*s == 0)
break;
- i++;
- *ap++ = s;
- *ap = 0;
+ ap[i++] = s++;
while(*s && *s!=' ' && *s!='\t')
s++;
if(*s == 0)
break;
- else
- *s++ = 0;
+ *s++ = 0;
}
+ ap[i] = nil;
return i;
}
case SG_TEXT:
case SG_DATA:
case SG_STACK:
+ case SG_PHYSICAL:
+ case SG_FIXED:
error(Ebadarg);
default:
return (uintptr)ibrk(va_arg(list, uintptr), i);
uintptr from, to;
from = va_arg(list, uintptr);
+ to = va_arg(list, ulong);
+ to += from;
+ if(to < from)
+ error(Ebadarg);
s = seg(up, from, 1);
if(s == nil)
error(Ebadarg);
- to = va_arg(list, ulong);
- to += from;
to &= ~(BY2PG-1);
from = PGROUND(from);
-
+ if(from >= to) {
+ qunlock(s);
+ return 0;
+ }
if(to > s->top) {
qunlock(s);
error(Ebadarg);
}
-
mfreeseg(s, from, (to - from) / BY2PG);
qunlock(s);
flushmmu();