Module Name:    src
Committed By:   skrll
Date:           Tue Dec  6 21:15:39 UTC 2011

Modified Files:
        src/lib/libpuffs: callcontext.c

Log Message:
Deal with __MACHINE_STACK_GROWS_UP machines.

constify the other psize while I'm here.

Thanks to Christos for looking.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libpuffs/callcontext.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpuffs/callcontext.c
diff -u src/lib/libpuffs/callcontext.c:1.26 src/lib/libpuffs/callcontext.c:1.27
--- src/lib/libpuffs/callcontext.c:1.26	Wed Nov  2 16:43:04 2011
+++ src/lib/libpuffs/callcontext.c	Tue Dec  6 21:15:39 2011
@@ -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 @@ slowccalloc(struct puffs_usermount *pu)
 	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 @@ slowccalloc(struct puffs_usermount *pu)
 	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 @@ puffs__cc_create(struct puffs_usermount 
 		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 @@ puffs__cc_create(struct puffs_usermount 
 		 * 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;
 
 		/*

Reply via email to