// Allocate and initialize stack at sz
sz = PGROUNDUP(sz);
- sz += PGSIZE; // leave an invalid page
if(!allocuvm(pgdir, (char *)sz, PGSIZE))
goto bad;
mem = uva2ka(pgdir, (char *)sz);
return 0;
}
-// XXX should we copy the string?
-
// Fetch the nul-terminated string at addr from process p.
// Doesn't actually copy the string - just sets *pp to point at it.
// Returns length of string, not including nul.
return -1;
if((uint)i >= proc->sz || (uint)i+size >= proc->sz)
return -1;
- // *pp = proc->mem + i; // XXXXX
- *pp = (char *) i; // XXXXX
+ *pp = (char *) i;
return 0;
}
#include "user.h"
#include "fs.h"
#include "fcntl.h"
+#include "syscall.h"
+#include "traps.h"
char buf[2048];
char name[3];
}
void
-stacktest(void)
+validateint(int *p)
{
- printf(stdout, "stack test\n");
- char dummy = 1;
- char *p = &dummy;
- int ppid = getpid();
- int pid = fork();
- if(pid < 0){
- printf(stdout, "fork failed\n");
- exit();
- }
- if(pid == 0){
- // should cause a trap:
- p[-4096] = 'z';
- kill(ppid);
- printf(stdout, "stack test failed: page before stack was writeable\n");
- exit();
+ int res;
+ asm("mov %%esp, %%ebx\n\t"
+ "mov %3, %%esp\n\t"
+ "int %2\n\t"
+ "mov %%ebx, %%esp" :
+ "=a" (res) :
+ "a" (SYS_sleep), "n" (T_SYSCALL), "c" (p) :
+ "ebx");
+}
+
+void
+validatetest(void)
+{
+ int hi = 1100*1024;
+
+ printf(stdout, "validate test\n");
+
+ uint p;
+ for (p = 0; p <= (uint)hi; p += 4096) {
+ int pid;
+ if ((pid = fork()) == 0) {
+ // try to crash the kernel by passing in a badly placed integer
+ validateint((int*)p);
+ exit();
+ }
+ sleep(0);
+ sleep(0);
+ kill(pid);
+ wait();
+
+ // try to crash the kernel by passing in a bad string pointer
+ if (link("nosuchfile", (char*)p) != -1) {
+ printf(stdout, "link should not succeed\n");
+ exit();
+ }
}
- wait();
- printf(stdout, "stack test OK\n");
+
+ printf(stdout, "validate ok\n");
}
int
}
close(open("usertests.ran", O_CREATE));
- stacktest();
sbrktest();
+ validatetest();
opentest();
writetest();