Skip to content

Instantly share code, notes, and snippets.

@ltiao
Created June 9, 2014 13:13
Show Gist options
  • Save ltiao/f733942a2331de16b4fd to your computer and use it in GitHub Desktop.
Save ltiao/f733942a2331de16b4fd to your computer and use it in GitHub Desktop.
I'm da real mvp
int sys_sbrk(__intptr_t change, void **retval) {
struct addrspace *as = proc_getas();
if (as == NULL) {
return EFAULT;
}
vaddr_t heapbreak = as->as_heapvbase + as->as_heapsize;
// we're not checking page alignment of
// change (amount) here or anything
// clever like that here (@273)
as->as_heapsize += change;
// address lower than the beginning of the heap
if (as->as_heapvbase + as->as_heapsize < as->as_heapvbase) {
*retval = (void *)-1;
return EINVAL;
}
// address growing into the stack
if (as->as_heapvbase + as->as_heapsize >= USERSTACK - PAGE_SIZE * VM_STACKPAGES) {
*retval = (void *)-1;
return EINVAL;
}
*retval = (void *) heapbreak;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment