Skip to content

Commit f8bd2f9

Browse files
author
Robert Morris
committed
synchronize usertests and exec with util lab
1 parent c28e177 commit f8bd2f9

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

kernel/exec.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ exec(char *path, char **argv)
7575
p = myproc();
7676
uint64 oldsz = p->sz;
7777

78-
// Allocate two pages at the next page boundary.
78+
// Allocate some pages at the next page boundary.
7979
// Make the first inaccessible as a stack guard.
80-
// Use the second as the user stack.
80+
// Use the rest as the user stack.
8181
sz = PGROUNDUP(sz);
8282
uint64 sz1;
83-
if((sz1 = uvmalloc(pagetable, sz, sz + 2*PGSIZE, PTE_W)) == 0)
83+
if((sz1 = uvmalloc(pagetable, sz, sz + (USERSTACK+1)*PGSIZE, PTE_W)) == 0)
8484
goto bad;
8585
sz = sz1;
86-
uvmclear(pagetable, sz-2*PGSIZE);
86+
uvmclear(pagetable, sz-(USERSTACK+1)*PGSIZE);
8787
sp = sz;
88-
stackbase = sp - PGSIZE;
88+
stackbase = sp - USERSTACK*PGSIZE;
8989

9090
// Push argument strings, prepare rest of stack in ustack.
9191
for(argc = 0; argv[argc]; argc++) {

kernel/param.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
#define NBUF (MAXOPBLOCKS*3) // size of disk block cache
1212
#define FSSIZE 2000 // size of file system in blocks
1313
#define MAXPATH 128 // maximum file path name
14+
#define USERSTACK 1 // user stack pages
15+

user/usertests.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -2310,9 +2310,14 @@ bigargtest(char *s)
23102310
if(pid == 0){
23112311
static char *args[MAXARG];
23122312
int i;
2313+
char big[400];
2314+
memset(big, ' ', sizeof(big));
2315+
big[sizeof(big)-1] = '\0';
23132316
for(i = 0; i < MAXARG-1; i++)
2314-
args[i] = "bigargs test: failed\n ";
2317+
args[i] = big;
23152318
args[MAXARG-1] = 0;
2319+
// this exec() should fail (and return) because the
2320+
// arguments are too large.
23162321
exec("echo", args);
23172322
fd = open("bigarg-ok", O_CREATE);
23182323
close(fd);
@@ -2409,7 +2414,7 @@ stacktest(char *s)
24092414
pid = fork();
24102415
if(pid == 0) {
24112416
char *sp = (char *) r_sp();
2412-
sp -= PGSIZE;
2417+
sp -= USERSTACK*PGSIZE;
24132418
// the *sp should cause a trap.
24142419
printf("%s: stacktest: read below stack %d\n", s, *sp);
24152420
exit(1);

0 commit comments

Comments
 (0)