| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: mremap.2,v 1.7 2018/05/03 05:09:48 wiz Exp $ | | 1 | .\" $NetBSD: mremap.2,v 1.8 2023/03/01 20:08:41 riastradh Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2007 Thomas Klausner and Joerg Sonnenberger | | 3 | .\" Copyright (c) 2007 Thomas Klausner and Joerg Sonnenberger |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" Redistribution and use in source and binary forms, with or without | | 6 | .\" Redistribution and use in source and binary forms, with or without |
7 | .\" modification, are permitted provided that the following conditions | | 7 | .\" modification, are permitted provided that the following conditions |
8 | .\" are met: | | 8 | .\" are met: |
9 | .\" 1. Redistributions of source code must retain the above copyright | | 9 | .\" 1. Redistributions of source code must retain the above copyright |
10 | .\" notice, this list of conditions and the following disclaimer. | | 10 | .\" notice, this list of conditions and the following disclaimer. |
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer in the | | 12 | .\" notice, this list of conditions and the following disclaimer in the |
13 | .\" documentation and/or other materials provided with the distribution. | | 13 | .\" documentation and/or other materials provided with the distribution. |
14 | .\" | | 14 | .\" |
| @@ -127,27 +127,27 @@ return_2_end(void) | | | @@ -127,27 +127,27 @@ return_2_end(void) |
127 | } | | 127 | } |
128 | | | 128 | |
129 | int | | 129 | int |
130 | main(int argc, char *argv[]) | | 130 | main(int argc, char *argv[]) |
131 | { | | 131 | { |
132 | void *maprw, *maprx; | | 132 | void *maprw, *maprx; |
133 | int rv; | | 133 | int rv; |
134 | size_t page = (size_t)sysconf(_SC_PAGESIZE); | | 134 | size_t page = (size_t)sysconf(_SC_PAGESIZE); |
135 | | | 135 | |
136 | // Create the first mapping that has no protections, but intended | | 136 | // Create the first mapping that has no protections, but intended |
137 | // protections only | | 137 | // protections only |
138 | maprw = mmap(NULL, page, | | 138 | maprw = mmap(NULL, page, |
139 | PROT_MPROTECT(PROT_EXEC|PROT_WRITE|PROT_READ), | | 139 | PROT_MPROTECT(PROT_EXEC|PROT_WRITE|PROT_READ), |
140 | MAP_ANON, -1, 0); | | 140 | MAP_ANON|MAP_PRIVATE, -1, 0); |
141 | if (maprw == MAP_FAILED) | | 141 | if (maprw == MAP_FAILED) |
142 | err(EXIT_FAILURE, "mmap failed"); | | 142 | err(EXIT_FAILURE, "mmap failed"); |
143 | | | 143 | |
144 | // Create the second mapping for the same physical space, which | | 144 | // Create the second mapping for the same physical space, which |
145 | // again has no protections. | | 145 | // again has no protections. |
146 | maprx = mremap(maprw, page, NULL, page, MAP_REMAPDUP); | | 146 | maprx = mremap(maprw, page, NULL, page, MAP_REMAPDUP); |
147 | if (maprx == MAP_FAILED) | | 147 | if (maprx == MAP_FAILED) |
148 | err(EXIT_FAILURE, "mremap failed"); | | 148 | err(EXIT_FAILURE, "mremap failed"); |
149 | | | 149 | |
150 | // Set the first mapping read/write | | 150 | // Set the first mapping read/write |
151 | if (mprotect(maprw, page, PROT_READ|PROT_WRITE) == -1) | | 151 | if (mprotect(maprw, page, PROT_READ|PROT_WRITE) == -1) |
152 | err(EXIT_FAILURE, "mprotect(rw) failed"); | | 152 | err(EXIT_FAILURE, "mprotect(rw) failed"); |
153 | | | 153 | |