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

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: more fixes for bots Created 9 years, 3 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) {
bsy 2011/08/23 18:31:23 UNREFERENCED_PARAMETER(num_bytes);
Brad Chen 2011/08/23 21:15:09 Done.
47 typedef uintptr_t (base_addr_func)();
48 void *nacl_helper_so = dlopen(NULL, RTLD_LAZY | RTLD_NOLOAD);
Mark Seaborn 2011/08/23 18:26:36 I think it would be been neater to pass the sandbo
Brad Chen 2011/08/23 21:15:09 The reason I liked this way of doing it is it work
49 base_addr_func *nacl_helper_get_base_addr;
50 uintptr_t tmpint;
51 uintptr_t base_addr;
52
53 NaClLog(2, "NaCl_find_preserved_sandbox_memory(p, 0x%08"NACL_PRIxPTR")\n",
54 num_bytes);
55 *p = 0;
56 if (!nacl_helper_so) {
57 return 0;
58 }
59 tmpint = (uintptr_t)dlsym(nacl_helper_so, "nacl_helper_get_1G_address");
Mark Seaborn 2011/08/23 18:26:36 BTW, the usual style in service_runtime is a space
bsy 2011/08/23 18:31:23 style: space between (type) and expr
Brad Chen 2011/08/23 21:15:09 Done.
Brad Chen 2011/08/23 21:15:09 Done.
60 nacl_helper_get_base_addr = (base_addr_func*)tmpint;
Mark Seaborn 2011/08/23 18:26:36 Nit: Space before '*' You could just do a double
bsy 2011/08/23 18:31:23 style: spaces in (type *) expr;
Brad Chen 2011/08/23 21:15:09 Done.
Brad Chen 2011/08/23 21:15:09 Done.
61
62 if (!nacl_helper_get_base_addr) {
bsy 2011/08/23 18:31:23 if (NULL == nacl_helper_get_base_addr) {
Brad Chen 2011/08/23 21:15:09 Done.
63 return 0;
64 }
65 base_addr = nacl_helper_get_base_addr();
66 if (!base_addr) {
Mark Seaborn 2011/08/23 18:26:36 This is a bit odd because one might expect the bas
Brad Chen 2011/08/23 21:15:09 Agreed. However the Windows version of this same r
67 return 0;
68 }
69 NaClLog(2, "NaCl_find_preserved_sandbox_memory() at 0x%08"NACL_PRIxPTR"\n",
70 base_addr);
71 *p = (void *)base_addr;
bsy 2011/08/23 18:31:23 style nit: space in (void *) base_addr;
Brad Chen 2011/08/23 21:15:09 Done.
72 return 1;
73 }
74
32 void NaCl_page_free(void *p, 75 void NaCl_page_free(void *p,
33 size_t size) { 76 size_t size) {
34 if (p == 0 || size == 0) 77 if (p == 0 || size == 0)
35 return; 78 return;
36 if (munmap(p, size) != 0) { 79 if (munmap(p, size) != 0) {
37 NaClLog(LOG_FATAL, "NaCl_page_free: munmap() failed"); 80 NaClLog(LOG_FATAL, "NaCl_page_free: munmap() failed");
38 } 81 }
39 } 82 }
40 83
41 /* 84 /*
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 int NaCl_madvise(void *start, 230 int NaCl_madvise(void *start,
188 size_t length, 231 size_t length,
189 int advice) { 232 int advice) {
190 int ret = madvise(start, length, advice); 233 int ret = madvise(start, length, advice);
191 234
192 /* 235 /*
193 * MADV_DONTNEED and MADV_NORMAL are needed 236 * MADV_DONTNEED and MADV_NORMAL are needed
194 */ 237 */
195 return ret == -1 ? -errno : ret; 238 return ret == -1 ? -errno : ret;
196 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698