aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code/protli.c
diff options
context:
space:
mode:
authorNick Barnes2001-10-31 14:40:56 +0000
committerNick Barnes2001-10-31 14:40:56 +0000
commit7acfca905d76140f4cc0b09c9a12de237de364cd (patch)
tree3ed8babfa3a73d30f29e08ca5d5adcda4ca4e826 /mps/code/protli.c
parentb7ce4893f9902d57cd67ac9a92fa6c3d5a8fc833 (diff)
downloademacs-7acfca905d76140f4cc0b09c9a12de237de364cd.tar.gz
emacs-7acfca905d76140f4cc0b09c9a12de237de364cd.zip
Branch imports for masters.
Copied from Perforce Change: 23678 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code/protli.c')
-rw-r--r--mps/code/protli.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/mps/code/protli.c b/mps/code/protli.c
new file mode 100644
index 00000000000..20c9dfc5b55
--- /dev/null
+++ b/mps/code/protli.c
@@ -0,0 +1,90 @@
1/* impl.c.protli: PROTECTION FOR LINUX
2 *
3 * $HopeName: $
4 * Copyright (C) 1995,1999 Harlequin Group, all rights reserved
5 *
6 */
7
8#include "mpm.h"
9
10#ifndef MPS_OS_LI
11#error "protli.c is Linux specific, but MPS_OS_LI is not set"
12#endif
13#ifndef PROTECTION
14#error "protli.c implements protection, but PROTECTION is not set"
15#endif
16
17#include <limits.h>
18#include <stddef.h>
19#include <stdlib.h>
20#include <sys/mman.h>
21
22SRCID(protli, "$HopeName: $");
23
24
25/* ProtSet -- set protection
26 *
27 * This is just a thin veneer on top of mprotect(2).
28 */
29
30void ProtSet(Addr base, Addr limit, AccessSet mode)
31{
32 int flags;
33 int res;
34
35 AVER(sizeof(int) == sizeof(Addr)); /* should be redundant; will fail on Alpha */
36 AVER(base < limit);
37 AVER(base != 0);
38 AVER(AddrOffset(base, limit) <= INT_MAX); /* should be redundant */
39
40#if 0
41 /* .flags.trouble: This less strict version of flags (which allows write
42 * access unless explicitly told not to) caused mmqa test 37 to fail.
43 * This might be a bug in MPS, so for now we go with the stricter
44 * version that matches the Win32 implementation. */
45 flags = 0;
46 if((mode & AccessREAD) == 0)
47 flags |= PROT_READ | PROT_EXEC;
48 if((mode & AccessWRITE) == 0)
49 flags |= PROT_WRITE;
50#endif
51 flags = PROT_READ | PROT_WRITE | PROT_EXEC;
52 if((mode & AccessWRITE) != 0)
53 flags = PROT_READ | PROT_EXEC;
54 if((mode & AccessREAD) != 0)
55 flags = 0;
56
57 res = mprotect((void *)base, (size_t)AddrOffset(base, limit), flags);
58 AVER(res == 0);
59}
60
61
62/* ProtSync -- synchronize protection settings with hardware
63 *
64 * This does nothing under Linux.
65 */
66
67void ProtSync(Arena arena)
68{
69 NOOP;
70}
71
72
73
74/* ProtTramp -- protection trampoline
75 *
76 * The protection trampoline is trivial under Linux, as there is nothing
77 * that needs to be done in the dynamic context of the mutator in order
78 * to catch faults. (Contrast this with Win32 Structured Exception
79 * Handling.)
80 */
81
82void ProtTramp(void **resultReturn, void *(*f)(void *, size_t),
83 void *p, size_t s)
84{
85 AVER(resultReturn != NULL);
86 AVER(FUNCHECK(f));
87 /* Can't check p and s as they are interpreted by the client */
88
89 *resultReturn = (*f)(p, s);
90}