@@ -1,4 +1,4 @@
-/* $NetBSD: callcontext.c,v 1.26 2011/11/02 16:43:04 yamt Exp $ */
+/* $NetBSD: callcontext.c,v 1.27 2011/12/06 21:15:39 skrll Exp $ */
/*
* Copyright (c) 2006, 2007, 2008 Antti Kantee. All Rights Reserved.
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
-__RCSID("$NetBSD: callcontext.c,v 1.26 2011/11/02 16:43:04 yamt Exp $");
+__RCSID("$NetBSD: callcontext.c,v 1.27 2011/12/06 21:15:39 skrll Exp $");
#endif /* !lint */
#include <sys/types.h>
@@ -188,7 +188,7 @@
struct puffs_cc *volatile pcc;
void *sp;
size_t stacksize = 1<<pu->pu_cc_stackshift;
- long psize = sysconf(_SC_PAGESIZE);
+ const long psize = sysconf(_SC_PAGESIZE);
if (puffs_fakecc)
return &fakecc;
@@ -201,7 +201,11 @@
pcc = sp;
memset(pcc, 0, sizeof(struct puffs_cc));
+#ifndef __MACHINE_STACK_GROWS_UP
mprotect((uint8_t *)sp + psize, (size_t)psize, PROT_NONE);
+#else
+ mprotect((uint8_t *)sp + stacksize - psize, (size_t)psize, PROT_NONE);
+#endif
/* initialize both ucontext's */
if (getcontext(&pcc->pcc_uc) == -1) {
@@ -245,6 +249,8 @@
pcc->pcc_func = func;
pcc->pcc_farg = pcc;
} else {
+ const long psize = sysconf(_SC_PAGESIZE);
+
/* link context */
pcc->pcc_uc.uc_link = &pcc->pcc_uc_ret;
@@ -254,8 +260,8 @@
* swapcontext(). However, it gets lost. So reinit it.
*/
st = &pcc->pcc_uc.uc_stack;
- st->ss_sp = pcc;
- st->ss_size = stacksize;
+ st->ss_sp = ((uint8_t *)(void *)pcc) + psize;
+ st->ss_size = stacksize - psize;
st->ss_flags = 0;
/*