Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpuffs Deal with __MACHINE_STACK_GROWS_UP machines.



details:   https://anonhg.NetBSD.org/src/rev/c441dbb0218c
branches:  trunk
changeset: 771892:c441dbb0218c
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Dec 06 21:15:39 2011 +0000

description:
Deal with __MACHINE_STACK_GROWS_UP machines.

constify the other psize while I'm here.

Thanks to Christos for looking.

diffstat:

 lib/libpuffs/callcontext.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (59 lines):

diff -r 80c789b4a148 -r c441dbb0218c lib/libpuffs/callcontext.c
--- a/lib/libpuffs/callcontext.c        Tue Dec 06 19:41:03 2011 +0000
+++ b/lib/libpuffs/callcontext.c        Tue Dec 06 21:15:39 2011 +0000
@@ -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;
 
                /*



Home | Main Index | Thread Index | Old Index