~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to misc/mprotect.ch

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
In this file are all changes necessary to implement the 4.3BSD system
 
2
call mprotect, and the changes to make sigreturn pass back the address
 
3
where a fault occurred as the `code' arg.   Note that sun passes the
 
4
address as a 4'th arg.   This might be preferable, but would involve
 
5
changes to locore.s.
 
6
 
 
7
This has been tested on an hp370 running 4.3 BSD from MT Xinu.
 
8
 
 
9
A man page entry for the call as implemented below.
 
10
 
 
11
Inserting file /usr/man/man2/mprotect.2
 
12
---Begin File /usr/man/man2/mprotect.2---
 
13
.\" @(#)mprotect.2 
 
14
.TH MPROTECT 2 "9 December 1989"
 
15
.SH NAME
 
16
mprotect \- specify protection of data section memory
 
17
.SH SYNOPSIS
 
18
.nf
 
19
.ft B
 
20
#include <sys/mman.h>
 
21
.ft
 
22
.LP
 
23
.ft B
 
24
mprotect(addr, len, prot)
 
25
caddr_t addr;
 
26
int len, prot;
 
27
.ft
 
28
.fi
 
29
.IX  mprotect  ""  \fLmprotect\fP
 
30
.IX  "memory management"  mprotect  ""  \fLmprotect\fP
 
31
.IX  "change protections \(em \fLmprotect\fP"
 
32
.SH DESCRIPTION
 
33
.LP
 
34
.B mprotect(\|)
 
35
changes the access protections on the mappings specified
 
36
by
 
37
the range
 
38
[\fIaddr, addr + len\fP\^)
 
39
to be that specified by
 
40
.IR prot .
 
41
Legitimate values for
 
42
.I prot
 
43
are PROT_READ and (PROT_WRITE | PROT_READ). 
 
44
.SH RETURN VALUE
 
45
.LP
 
46
.B mprotect(\|)
 
47
returns 0 on success, \-1 on failure.
 
48
.SH ERRORS
 
49
.B mprotect(\|)
 
50
will fail if:
 
51
.TP 15
 
52
.SM EINVAL
 
53
.I addr
 
54
is not a multiple of the page size as returned
 
55
by
 
56
.BR getpagesize (2).
 
57
.TP
 
58
.SM ENOMEM
 
59
Addresses in the range
 
60
[\fIaddr, addr + len\fP)
 
61
are not in the data section of a process.
 
62
.LP
 
63
.SH SEE ALSO
 
64
.BR getpagesize (2),
 
65
 
 
66
---End File /usr/man/man2/mprotect.2---
 
67
 
 
68
 
 
69
You need to compile the following and add it to /lib/libc.a
 
70
 
 
71
Inserting file /usr/src/lib/libc/hp300/sys/mprotect.c
 
72
---Begin File /usr/src/lib/libc/hp300/sys/mprotect.c---
 
73
#ifdef SYSLIBC_SCCS
 
74
_sccsid:.asciz  "@(#)mprotect.c"
 
75
#endif SYSLIBC_SCCS
 
76
 
 
77
#include "SYS.h"
 
78
 
 
79
SYSCALL(mprotect)
 
80
        rts
 
81
---End File /usr/src/lib/libc/hp300/sys/mprotect.c---
 
82
 
 
83
 
 
84
 
 
85
*** hp300/machdep.c.orig        Tue Aug 29 13:09:56 1989
 
86
--- hp300/machdep.c     Mon Dec 11 17:07:18 1989
 
87
***************
 
88
*** 560,566 ****
 
89
  #endif
 
90
        sigf.sf_signum = sig;
 
91
        sigf.sf_code = 0;
 
92
!       if (sig == SIGILL || sig == SIGFPE) {
 
93
                sigf.sf_code = u.u_code;
 
94
                u.u_code = 0;
 
95
        }
 
96
--- 560,566 ----
 
97
  #endif
 
98
        sigf.sf_signum = sig;
 
99
        sigf.sf_code = 0;
 
100
!       if (sig == SIGILL || sig == SIGFPE || sig == SIGBUS) {
 
101
                sigf.sf_code = u.u_code;
 
102
                u.u_code = 0;
 
103
        }
 
104
*** sys/kern_mman.c.orig        Tue Aug 29 13:16:29 1989
 
105
--- sys/kern_mman.c     Thu Dec 14 10:07:39 1989
 
106
***************
 
107
*** 249,257 ****
 
108
        u.u_pofile[fd] &= ~UF_MAPPED;
 
109
  }
 
110
  
 
111
  mprotect()
 
112
! {
 
113
  
 
114
  }
 
115
  
 
116
  madvise()
 
117
--- 249,296 ----
 
118
        u.u_pofile[fd] &= ~UF_MAPPED;
 
119
  }
 
120
  
 
121
 
122
  mprotect()
 
123
! {     struct a {
 
124
!               caddr_t addr;
 
125
!               int     len;
 
126
!               int     prot;
 
127
!       } *uap = (struct a *)u.u_ap;
 
128
!       int fv,off;
 
129
!       int tprot;
 
130
!       register struct pte *pte;
 
131
!       struct cmap *c;
 
132
!       int s;
 
133
  
 
134
+       u.u_r.r_val1 = -1;
 
135
 
136
+       if ((uap->len < 0  ||
 
137
+            (int)uap->addr & CLOFSET)) {
 
138
+         u.u_error = EINVAL;
 
139
+         return;
 
140
+       }
 
141
 
142
 
143
+       if ((uap->prot & PROT_WRITE) == 0)
 
144
+         tprot= PG_RO;
 
145
+       else tprot=PG_RW;
 
146
+       /* check the pages are in data section  */
 
147
+       if (!(isadsv(u.u_procp, btoc(uap->addr))
 
148
+             &&isadsv(u.u_procp ,btoc(uap->addr+uap->len) -1)))
 
149
+         {     u.u_error = ENOMEM;
 
150
+               return;}
 
151
+               
 
152
 
153
+       fv = btop(uap->addr);
 
154
+       pte = vtopte(u.u_procp, fv);
 
155
+       for (off = 0; off < uap->len; off += NBPG) {
 
156
+         
 
157
+         *(u_int *)pte &= ~PG_PROT;
 
158
+         *(u_int *)pte |= tprot;
 
159
+         pte++;}
 
160
 
161
+       newptes(vtopte(u.u_procp, fv), fv, btoc(uap->len));
 
162
+       u.u_r.r_val1 = 0;
 
163
  }
 
164
  
 
165
  madvise()
 
166
*** hp300/trap.c.orig   Tue Aug 29 13:09:59 1989
 
167
--- hp300/trap.c        Mon Dec 11 17:48:59 1989
 
168
***************
 
169
*** 112,117 ****
 
170
--- 112,118 ----
 
171
  
 
172
        case T_BUSERR+USER:     /* bus error */
 
173
        case T_ADDRERR+USER:    /* address error */
 
174
+               u.u_code=v;
 
175
                i = SIGBUS;
 
176
                break;
 
177
  
 
178
***************
 
179
*** 293,298 ****
 
180
--- 294,300 ----
 
181
                                        printf("PTF|WPF...\n");
 
182
                                        if (type == T_MMUFLT)
 
183
                                                goto copyfault;
 
184
+                                       u.u_code=v;
 
185
                                        i = SIGBUS;
 
186
                                        break;
 
187
                                }
 
188
***************
 
189
*** 346,351 ****
 
190
--- 348,354 ----
 
191
  #endif
 
192
                        if (type == T_MMUFLT)
 
193
                                goto copyfault;
 
194
+                       u.u_code=v;
 
195
                        i = SIGBUS;
 
196
                        break;
 
197
                }