Seemingly implement system calls (still appears to have a bug).
This commit is contained in:
parent
bbdb8bd811
commit
eae0475758
|
@ -19,8 +19,25 @@ sys_cputs(const char *s, size_t len)
|
||||||
{
|
{
|
||||||
// Check that the user has permission to read memory [s, s+len).
|
// Check that the user has permission to read memory [s, s+len).
|
||||||
// Destroy the environment if not.
|
// Destroy the environment if not.
|
||||||
|
const char* bottom = ROUNDDOWN(s, PGSIZE);
|
||||||
|
size_t aligned_count = ROUNDUP(len, PGSIZE) / PGSIZE;
|
||||||
|
while(aligned_count--) {
|
||||||
|
if (!(curenv->env_pgdir[PDX(bottom)] & PTE_P)) {
|
||||||
|
cprintf("[%08x] Tried to print unmapped address\n", curenv->env_id);
|
||||||
|
env_destroy(curenv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// LAB 3: Your code here.
|
pde_t pgdir_allowed = curenv->env_pgdir[PDX(bottom)] & PTE_U;
|
||||||
|
pde_t pt_allowed = *pgdir_walk(curenv->env_pgdir, bottom, 0) & PTE_U;
|
||||||
|
if(((curenv->env_tf.tf_cs & 0b11) > 1) && !(pt_allowed & pgdir_allowed)) {
|
||||||
|
cprintf("[%08x] Tried to print forbidden memory\n", curenv->env_id);
|
||||||
|
env_destroy(curenv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bottom += PGSIZE;
|
||||||
|
}
|
||||||
|
|
||||||
// Print the string supplied by the user.
|
// Print the string supplied by the user.
|
||||||
cprintf("%.*s", len, s);
|
cprintf("%.*s", len, s);
|
||||||
|
@ -70,9 +87,16 @@ syscall(uint32_t syscallno, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4,
|
||||||
// Return any appropriate return value.
|
// Return any appropriate return value.
|
||||||
// LAB 3: Your code here.
|
// LAB 3: Your code here.
|
||||||
|
|
||||||
panic("syscall not implemented");
|
|
||||||
|
|
||||||
switch (syscallno) {
|
switch (syscallno) {
|
||||||
|
case SYS_cputs:
|
||||||
|
sys_cputs((const char*) a1, a2);
|
||||||
|
return 0;
|
||||||
|
case SYS_cgetc:
|
||||||
|
return sys_cgetc();
|
||||||
|
case SYS_getenvid:
|
||||||
|
return sys_getenvid();
|
||||||
|
case SYS_env_destroy:
|
||||||
|
return sys_env_destroy(a1);
|
||||||
default:
|
default:
|
||||||
return -E_INVAL;
|
return -E_INVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,13 @@ trap_dispatch(struct Trapframe *tf)
|
||||||
page_fault_handler(tf);
|
page_fault_handler(tf);
|
||||||
} else if (tf->tf_trapno == T_BRKPT) {
|
} else if (tf->tf_trapno == T_BRKPT) {
|
||||||
monitor(tf);
|
monitor(tf);
|
||||||
|
} else if (tf->tf_trapno == T_SYSCALL) {
|
||||||
|
syscall(tf->tf_regs.reg_eax,
|
||||||
|
tf->tf_regs.reg_edx,
|
||||||
|
tf->tf_regs.reg_ecx,
|
||||||
|
tf->tf_regs.reg_ebx,
|
||||||
|
tf->tf_regs.reg_edi,
|
||||||
|
tf->tf_regs.reg_esi);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unexpected trap: The user process or the kernel has a bug.
|
// Unexpected trap: The user process or the kernel has a bug.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user