On 07/01/2016 01:12 PM, Richard Henderson wrote:
On 06/30/2016 12:37 AM, Peter Lieven wrote:
+void *qemu_alloc_stack(size_t sz)
+{
+    /* allocate sz bytes plus one extra page for a guard
+     * page at the bottom of the stack */
+    void *ptr = mmap(NULL, sz + getpagesize(), PROT_NONE,
+                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+    if (ptr == MAP_FAILED) {
+        abort();
+    }
+    if (mmap(ptr + getpagesize(), sz, PROT_READ | PROT_WRITE,
+        MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) == MAP_FAILED) {
+        abort();
+    }

Rare platforms now, but fwiw, this is incorrect for hppa and ia64.

For hppa, stack grows up, so the guard page needs to be at the top.

For ia64, there are two stacks, the "normal" program stack (grows down) and the register window stack (grows up). The guard page goes in between.

See e.g. glibc/nptl/allocatestack.c

#ifdef NEED_SEPARATE_REGISTER_STACK
          char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);
#elif _STACK_GROWS_DOWN
          char *guard = mem;
#elif _STACK_GROWS_UP
          char *guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1);
#endif
          if (mprotect (guard, guardsize, PROT_NONE) != 0)



r~

Reply via email to