void switchuvm(struct proc*);
void switchkvm(void);
int copyout(pde_t*, uint, void*, uint);
+void clear_pte_u(pde_t *pgdir, char *uva);
// number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
iunlockput(ip);
ip = 0;
- // Allocate a one-page stack at the next page boundary
+ // Allocate two pages at the next page boundary.
+ // Make the first inaccessible.
+ // Use the second as the user stack.
sz = PGROUNDUP(sz);
- if((sz = allocuvm(pgdir, sz, sz + PGSIZE)) == 0)
+ if((sz = allocuvm(pgdir, sz, sz + 2*PGSIZE)) == 0)
goto bad;
+ clear_pte_u(pgdir, (char*)(sz-2*PGSIZE));
+ sp = sz;
// Push argument strings, prepare rest of stack in ustack.
- sp = sz;
for(argc = 0; argv[argc]; argc++) {
if(argc >= MAXARG)
goto bad;
for(i = 0; i < MAXARG-1; i++)
args[i] = "bigargs test: failed\n ";
args[MAXARG-1] = 0;
- printf(stdout, "bigarg test %d\n", (MAXARG-1)*strlen(args[0]));
+ printf(stdout, "bigarg test\n");
exec("echo", args);
printf(stdout, "bigarg test ok\n");
fd = open("bigarg-ok", O_CREATE);
}
return 0;
}
+
+// Clear PTE_U on a page. Used to create an inaccessible
+// page beneath the user stack.
+void
+clear_pte_u(pde_t *pgdir, char *uva)
+{
+ pte_t *pte;
+
+ pte = walkpgdir(pgdir, uva, 0);
+ if(pte == 0)
+ panic("clear_pte_u");
+ *pte &= ~PTE_U;
+}