Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: src/trusted/service_runtime/linux/sel_memory.c

Issue 7677036: Enable the service runtime to use a zero-based sandbox on Linux. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Fixes for Bennet's review Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * NaCl Service Runtime memory allocation code 8 * NaCl Service Runtime memory allocation code
9 */ 9 */
10 10
11 #include <sys/mman.h> 11 #include <sys/mman.h>
12 #include <sys/stat.h> 12 #include <sys/stat.h>
13 #include <sys/types.h> 13 #include <sys/types.h>
14 14
15 #include <dlfcn.h>
15 #include <errno.h> 16 #include <errno.h>
16 #include <fcntl.h> 17 #include <fcntl.h>
17 #include <stdint.h> 18 #include <stdint.h>
18 #include <stdio.h> 19 #include <stdio.h>
19 #include <string.h> 20 #include <string.h>
20 #include <unistd.h> 21 #include <unistd.h>
21 22
22 #include "native_client/src/include/nacl_platform.h" 23 #include "native_client/src/include/nacl_platform.h"
23 #include "native_client/src/include/portability.h" 24 #include "native_client/src/include/portability.h"
24 #include "native_client/src/shared/platform/nacl_exit.h" 25 #include "native_client/src/shared/platform/nacl_exit.h"
25 #include "native_client/src/shared/platform/nacl_global_secure_random.h" 26 #include "native_client/src/shared/platform/nacl_global_secure_random.h"
26 #include "native_client/src/shared/platform/nacl_log.h" 27 #include "native_client/src/shared/platform/nacl_log.h"
27 #include "native_client/src/trusted/service_runtime/sel_memory.h" 28 #include "native_client/src/trusted/service_runtime/sel_memory.h"
28 #include "native_client/src/trusted/service_runtime/nacl_config.h" 29 #include "native_client/src/trusted/service_runtime/nacl_config.h"
29 #include "native_client/src/trusted/service_runtime/include/machine/_types.h" 30 #include "native_client/src/trusted/service_runtime/include/machine/_types.h"
30 31
31 32
33 /*
34 * Find sandbox memory pre-reserved by the nacl_helper in chrome. The
35 * nacl_helper, if present, reserves the bottom 1G of the address space
36 * for use by Native Client.
37 *
38 * NOTE: num_bytes is currently ignored. It should be 1GB on Linux and
39 * 1GB plus a few pages on ARM. TODO(bradchen): deal with num_bytes.
40 *
41 * Out parameter p should be either:
42 * 0: reserved memory was not found
43 * less than 128K: indicates the bottom 1G was reserved.
44 */
45 int NaCl_find_prereserved_sandbox_memory(void **p,
46 size_t num_bytes) {
47 typedef uintptr_t (base_addr_func)();
48 void *nacl_helper_so = dlopen(NULL, RTLD_LAZY | RTLD_NOLOAD);
49 base_addr_func *nacl_helper_get_base_addr;
50 uintptr_t tmpint;
51 uintptr_t base_addr;
52
53 UNREFERENCED_PARAMETER(num_bytes);
54 NaClLog(2, "NaCl_find_preserved_sandbox_memory(p, 0x%08"NACL_PRIxPTR")\n",
55 num_bytes);
56 *p = 0;
57 if (!nacl_helper_so) {
58 return 0;
59 }
60 tmpint = (uintptr_t) dlsym(nacl_helper_so, "nacl_helper_get_1G_address");
61 nacl_helper_get_base_addr = (base_addr_func*) tmpint;
62
63 if (NULL == nacl_helper_get_base_addr) {
64 return 0;
65 }
66 base_addr = nacl_helper_get_base_addr();
67 if (0 == base_addr) {
68 return 0;
69 }
70 NaClLog(2, "NaCl_find_preserved_sandbox_memory() at 0x%08"NACL_PRIxPTR"\n",
71 base_addr);
72 *p = (void *) base_addr;
73 return 1;
74 }
75
32 void NaCl_page_free(void *p, 76 void NaCl_page_free(void *p,
33 size_t size) { 77 size_t size) {
34 if (p == 0 || size == 0) 78 if (p == 0 || size == 0)
35 return; 79 return;
36 if (munmap(p, size) != 0) { 80 if (munmap(p, size) != 0) {
37 NaClLog(LOG_FATAL, "NaCl_page_free: munmap() failed"); 81 NaClLog(LOG_FATAL, "NaCl_page_free: munmap() failed");
38 } 82 }
39 } 83 }
40 84
41 /* 85 /*
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 int NaCl_madvise(void *start, 231 int NaCl_madvise(void *start,
188 size_t length, 232 size_t length,
189 int advice) { 233 int advice) {
190 int ret = madvise(start, length, advice); 234 int ret = madvise(start, length, advice);
191 235
192 /* 236 /*
193 * MADV_DONTNEED and MADV_NORMAL are needed 237 * MADV_DONTNEED and MADV_NORMAL are needed
194 */ 238 */
195 return ret == -1 ? -errno : ret; 239 return ret == -1 ? -errno : ret;
196 } 240 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/build.scons ('k') | src/trusted/service_runtime/service_runtime.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698