Chromium Code Reviews| Index: src/trusted/service_runtime/linux/sel_memory.c |
| diff --git a/src/trusted/service_runtime/linux/sel_memory.c b/src/trusted/service_runtime/linux/sel_memory.c |
| index c1de0e199acbdc46e572ff08fbcdd2158c16a8b8..44847080c7e0cc1ae0f8ce1f1af6a9b82a31ebbe 100644 |
| --- a/src/trusted/service_runtime/linux/sel_memory.c |
| +++ b/src/trusted/service_runtime/linux/sel_memory.c |
| @@ -12,6 +12,7 @@ |
| #include <sys/stat.h> |
| #include <sys/types.h> |
| +#include <dlfcn.h> |
| #include <errno.h> |
| #include <fcntl.h> |
| #include <stdint.h> |
| @@ -29,6 +30,42 @@ |
| #include "native_client/src/trusted/service_runtime/include/machine/_types.h" |
| +/* |
| + * Find sandbox memory pre-reserved by the nacl_helper in chrome. The |
| + * nacl_helper, if present, reserves the bottom 1G of the address space |
| + * for use by Native Client. |
| + * |
| + * NOTE: num_bytes is currently ignored. It should be 1GB on Linux and |
| + * 1GB plus a few pages on ARM. TODO(bradchen): deal with num_bytes. |
| + * |
| + * Out parameter p should be either: |
| + * 0: reserved memory was not found |
| + * less than 128K: indicates the bottom 1G was reserved. |
| + */ |
| +int NaCl_find_prereserved_sandbox_memory(void **p, |
| + size_t num_bytes) { |
| + typedef uintptr_t (base_addr_func)(); |
| + void* nacl_helper_so = dlopen(NULL, RTLD_LAZY | RTLD_NOLOAD); |
|
Mark Seaborn
2011/08/18 23:09:45
" *" style
Brad Chen
2011/08/19 00:24:35
Done.
|
| + base_addr_func* nacl_helper_get_base_addr; |
|
Mark Seaborn
2011/08/18 23:09:45
" *" style
Brad Chen
2011/08/19 00:24:35
Done.
|
| + uintptr_t tmpint; |
| + uintptr_t base_addr; |
| + |
| + NaClLog(2, "NaCl_find_preserved_sandbox_memory(p, 0x%08"NACL_PRIxPTR")\n", |
| + num_bytes); |
| + *p = 0; |
| + if (!nacl_helper_so) return 0; |
|
Mark Seaborn
2011/08/18 23:09:45
Prefer:
if (x) {
blah
}
Brad Chen
2011/08/19 00:24:35
Done.
|
| + tmpint = (uintptr_t)dlsym(nacl_helper_so, "nacl_helper_get_1G_address"); |
| + nacl_helper_get_base_addr = (base_addr_func*)tmpint; |
| + |
| + if (!nacl_helper_get_base_addr) return 0; |
| + base_addr = nacl_helper_get_base_addr(); |
| + if (base_addr == 0) return 0; |
| + NaClLog(2, "NaCl_find_preserved_sandbox_memory() at 0x%08"NACL_PRIxPTR"\n", |
| + base_addr); |
| + *p = (void *)base_addr; |
| + return 1; |
| +} |
| + |
| void NaCl_page_free(void *p, |
| size_t size) { |
| if (p == 0 || size == 0) |