synchronize usertests and exec with util lab

This commit is contained in:
Robert Morris 2024-08-10 05:08:04 -04:00
parent c28e177f8d
commit f8bd2f9739
3 changed files with 14 additions and 7 deletions

View file

@ -75,17 +75,17 @@ exec(char *path, char **argv)
p = myproc();
uint64 oldsz = p->sz;
// Allocate two pages at the next page boundary.
// Allocate some pages at the next page boundary.
// Make the first inaccessible as a stack guard.
// Use the second as the user stack.
// Use the rest as the user stack.
sz = PGROUNDUP(sz);
uint64 sz1;
if((sz1 = uvmalloc(pagetable, sz, sz + 2*PGSIZE, PTE_W)) == 0)
if((sz1 = uvmalloc(pagetable, sz, sz + (USERSTACK+1)*PGSIZE, PTE_W)) == 0)
goto bad;
sz = sz1;
uvmclear(pagetable, sz-2*PGSIZE);
uvmclear(pagetable, sz-(USERSTACK+1)*PGSIZE);
sp = sz;
stackbase = sp - PGSIZE;
stackbase = sp - USERSTACK*PGSIZE;
// Push argument strings, prepare rest of stack in ustack.
for(argc = 0; argv[argc]; argc++) {

View file

@ -11,3 +11,5 @@
#define NBUF (MAXOPBLOCKS*3) // size of disk block cache
#define FSSIZE 2000 // size of file system in blocks
#define MAXPATH 128 // maximum file path name
#define USERSTACK 1 // user stack pages

View file

@ -2310,9 +2310,14 @@ bigargtest(char *s)
if(pid == 0){
static char *args[MAXARG];
int i;
char big[400];
memset(big, ' ', sizeof(big));
big[sizeof(big)-1] = '\0';
for(i = 0; i < MAXARG-1; i++)
args[i] = "bigargs test: failed\n ";
args[i] = big;
args[MAXARG-1] = 0;
// this exec() should fail (and return) because the
// arguments are too large.
exec("echo", args);
fd = open("bigarg-ok", O_CREATE);
close(fd);
@ -2409,7 +2414,7 @@ stacktest(char *s)
pid = fork();
if(pid == 0) {
char *sp = (char *) r_sp();
sp -= PGSIZE;
sp -= USERSTACK*PGSIZE;
// the *sp should cause a trap.
printf("%s: stacktest: read below stack %d\n", s, *sp);
exit(1);