Commit 8d157075 authored by Gabriel Marin's avatar Gabriel Marin Committed by Commit Bot

tcmalloc: Use indirect system calls in the mmap malloc hooks.

sys_{mmap|munmap|mremap}(...) calls are replaced with
syscall(SYS_{mmap|munmap|mremap}, ...), as the former are not allowed
by Chromium's sandbox.

BUG=724399,b:70905156

Change-Id: I04d87567a7c6194a0619140ffd5d4449c73a398b
Reviewed-on: https://chromium-review.googlesource.com/1130786Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Commit-Queue: Gabriel Marin <gmx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580904}
parent b8c04f45
...@@ -61,7 +61,9 @@ ...@@ -61,7 +61,9 @@
static inline void* do_mmap64(void *start, size_t length, static inline void* do_mmap64(void *start, size_t length,
int prot, int flags, int prot, int flags,
int fd, __off64_t offset) __THROW { int fd, __off64_t offset) __THROW {
return sys_mmap(start, length, prot, flags, fd, offset); // The original gperftools uses sys_mmap() here. But, it is not allowed by
// Chromium's sandbox.
return (void*)syscall(SYS_mmap, start, length, prot, flags, fd, offset);
} }
#define MALLOC_HOOK_HAVE_DO_MMAP64 1 #define MALLOC_HOOK_HAVE_DO_MMAP64 1
...@@ -189,7 +191,9 @@ extern "C" int munmap(void* start, size_t length) __THROW { ...@@ -189,7 +191,9 @@ extern "C" int munmap(void* start, size_t length) __THROW {
MallocHook::InvokeMunmapHook(start, length); MallocHook::InvokeMunmapHook(start, length);
int result; int result;
if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) { if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) {
result = sys_munmap(start, length); // The original gperftools uses sys_munmap() here. But, it is not allowed
// by Chromium's sandbox.
result = syscall(SYS_munmap, start, length);
} }
return result; return result;
} }
...@@ -200,7 +204,10 @@ extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size, ...@@ -200,7 +204,10 @@ extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size,
va_start(ap, flags); va_start(ap, flags);
void *new_address = va_arg(ap, void *); void *new_address = va_arg(ap, void *);
va_end(ap); va_end(ap);
void* result = sys_mremap(old_addr, old_size, new_size, flags, new_address); // The original gperftools uses sys_mremap() here. But, it is not allowed by
// Chromium's sandbox.
void* result = (void*)syscall(SYS_mremap, old_addr, old_size, new_size, flags,
new_address);
MallocHook::InvokeMremapHook(result, old_addr, old_size, new_size, flags, MallocHook::InvokeMremapHook(result, old_addr, old_size, new_size, flags,
new_address); new_address);
return result; return result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment