tinyos icon indicating copy to clipboard operation
tinyos copied to clipboard

Userspace stack space seems to be rather fragile

Open penberg opened this issue 13 years ago • 1 comments

I tried allocating 4K on userspace stack and noticed that the kernel crashes hard. You can see the issue if you update the new user/utils/pwd.c to look like this:

penberg@jaguar:~/src/tinyos$ git diff diff --git a/user/utils/pwd.c b/user/utils/pwd.c index 53aee22..3c46b49 100644 --- a/user/utils/pwd.c +++ b/user/utils/pwd.c @@ -1,10 +1,10 @@ #include <ulib.h>

#define BUF_SIZE 4096 -static char buf[BUF_SIZE];

int main(int argc, char **argv) {

  •   char buf[BUF_SIZE];
      char *cwd;
    
      cwd = getcwd(buf, BUF_SIZE);
    

penberg avatar Jan 03 '12 22:01 penberg

Hi, penberg It only allocs one page(just 4KB) as userspace stack in sys_execute()->task_execute()->execute_argument() and the page is mapped on userspace address USER_STACK(3GB - 4KB - 4KB), so if we alloc 4KB or larger on userspace stack, it will trigger pagefault. Here is userspace memory map:


  • kernel space ---------------------- 0xc000 0000

  • 4KB hole ---------------------- 0xbfff f000

  • user stack ---------------------- 0xbfff e000

  • other parts ---------------------- 0x000 0000

    I think there are two solutions:

  • alloc enough user space stack in sys_execute() I am now busy at college final exam, so I may not submit new patch in time :"(

  • just use global defined data: 'static char buf[..]' or 'char buf[..]' Because tinyos doesnt provide brk/sbrk and malloc() now, we need manage the memory manually.) When I use global defined 'static char buf[4MB]', it triggers a pagefault panic. The new patch 'Fix bug: map wrong userspace virtual address in map_userspace()' for this panic has been commited.

    Thanks, Xiaochen

chobits avatar Jan 04 '12 04:01 chobits