diff options
author | Jason Wright <jason@cvs.openbsd.org> | 2003-08-19 19:17:55 +0000 |
---|---|---|
committer | Jason Wright <jason@cvs.openbsd.org> | 2003-08-19 19:17:55 +0000 |
commit | ec989ae52a42eacd68dd9470eb170a6a08c490dd (patch) | |
tree | 85b86ca3657917631444c6d444ae53f202964297 /regress/sys/arch | |
parent | e7bfb4baef8ce89dfda2c841d38b8333e6870bb3 (diff) |
Keep the permissions on the page we're messing with as strict as possible
(ie. W^X semantics). based on discussion with Theo.
Diffstat (limited to 'regress/sys/arch')
-rw-r--r-- | regress/sys/arch/sparc64/emul-popc/simm/simm13.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/regress/sys/arch/sparc64/emul-popc/simm/simm13.c b/regress/sys/arch/sparc64/emul-popc/simm/simm13.c index 8894e27dbad..8c1ca6dc93c 100644 --- a/regress/sys/arch/sparc64/emul-popc/simm/simm13.c +++ b/regress/sys/arch/sparc64/emul-popc/simm/simm13.c @@ -1,4 +1,4 @@ -/* $OpenBSD: simm13.c,v 1.3 2003/08/19 05:49:22 jason Exp $ */ +/* $OpenBSD: simm13.c,v 1.4 2003/08/19 19:17:54 jason Exp $ */ /* * Copyright (c) 2003 Jason L. Wright (jason@thought.net) @@ -62,10 +62,20 @@ gen_simm(u_int32_t *p, int imm) int64_t a_popc_imm(void *v, int i) { - int (*func)(void) = v; + int64_t (*func)(void) = v, r; + if (mprotect(v, 2 * sizeof(union instr), PROT_READ|PROT_WRITE) == -1) + err(1, "mprotect"); gen_simm(v, i); - return ((*func)()); + + if (mprotect(v, 2 * sizeof(union instr), PROT_EXEC) == -1) + err(1, "mprotect"); + r = (*func)(); + + if (mprotect(v, 2 * sizeof(union instr), PROT_NONE) == -1) + err(1, "mprotect"); + + return (r); } int64_t @@ -86,8 +96,7 @@ main() int i, a, c; int r = 0; - v = mmap(NULL, 2 * sizeof(union instr), PROT_WRITE|PROT_EXEC|PROT_READ, - MAP_ANON, -1, 0); + v = mmap(NULL, 2 * sizeof(union instr), PROT_NONE, MAP_ANON, -1, 0); if (v == MAP_FAILED) err(1, "mmap"); |