From f8bd2f9739571a0d6b5f8b191bc058f53b4cc7bc Mon Sep 17 00:00:00 2001 From: Robert Morris <rtm@csail.mit.edu> Date: Sat, 10 Aug 2024 05:08:04 -0400 Subject: [PATCH] synchronize usertests and exec with util lab --- kernel/exec.c | 10 +++++----- kernel/param.h | 2 ++ user/usertests.c | 9 +++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/kernel/exec.c b/kernel/exec.c index e18bbb6..6d7c452 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -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++) { diff --git a/kernel/param.h b/kernel/param.h index 6624bff..80ec6d3 100644 --- a/kernel/param.h +++ b/kernel/param.h @@ -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 + diff --git a/user/usertests.c b/user/usertests.c index d9c21b9..28b53f9 100644 --- a/user/usertests.c +++ b/user/usertests.c @@ -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);