Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Userspace stack space seems to be rather fragile #3

Open
penberg opened this issue Jan 3, 2012 · 1 comment
Open

Userspace stack space seems to be rather fragile #3

penberg opened this issue Jan 3, 2012 · 1 comment

Comments

@penberg
Copy link
Contributor

penberg commented Jan 3, 2012

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);
    
@chobits
Copy link
Owner

chobits commented Jan 4, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants