aboutsummaryrefslogtreecommitdiff
path: root/src/malloc_hook_mmap_linux.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/malloc_hook_mmap_linux.h')
-rwxr-xr-xsrc/malloc_hook_mmap_linux.h64
1 files changed, 40 insertions, 24 deletions
diff --git a/src/malloc_hook_mmap_linux.h b/src/malloc_hook_mmap_linux.h
index 1c4c766..b86ff6c 100755
--- a/src/malloc_hook_mmap_linux.h
+++ b/src/malloc_hook_mmap_linux.h
@@ -1,4 +1,3 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
// Copyright (c) 2005, Google Inc.
// All rights reserved.
//
@@ -41,23 +40,47 @@
#endif
#include <unistd.h>
+#if defined(__ANDROID__)
+#include <sys/syscall.h>
+//#include <sys/linux-syscalls.h>
+#else
#include <syscall.h>
+#endif
#include <sys/mman.h>
#include <errno.h>
#include "base/linux_syscall_support.h"
+// SYS_mmap2, SYS_munmap, SYS_mremap and __off64_t are not defined in Android.
+#if defined(__ANDROID__)
+#if defined(__NR_mmap) && !defined(SYS_mmap)
+#define SYS_mmap __NR_mmap
+#endif
+#ifndef SYS_mmap2
+#define SYS_mmap2 __NR_mmap2
+#endif
+#ifndef SYS_munmap
+#define SYS_munmap __NR_munmap
+#endif
+#ifndef SYS_mremap
+#define SYS_mremap __NR_mremap
+#endif
+typedef off64_t __off64_t;
+#endif // defined(__ANDROID__)
+
// The x86-32 case and the x86-64 case differ:
// 32b has a mmap2() syscall, 64b does not.
// 64b and 32b have different calling conventions for mmap().
// I test for 64-bit first so I don't have to do things like
// '#if (defined(__mips__) && !defined(__MIPS64__))' as a mips32 check.
-#if defined(__x86_64__) || defined(__PPC64__) || defined(__aarch64__) || (defined(_MIPS_SIM) && _MIPS_SIM == _ABI64)
+#if defined(__x86_64__) || defined(__PPC64__) || (defined(_MIPS_SIM) && _MIPS_SIM == _ABI64)
static inline void* do_mmap64(void *start, size_t length,
int prot, int flags,
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
@@ -105,7 +128,7 @@ static inline void* do_mmap64(void *start, size_t length,
// Fall back to old 32-bit offset mmap() call
// Old syscall interface cannot handle six args, so pass in an array
int32 args[6] = { (int32) start, (int32) length, prot, flags, fd,
- (int32)(off_t) offset };
+ (off_t) offset };
result = (void *)syscall(SYS_mmap, args);
}
#else
@@ -117,21 +140,7 @@ static inline void* do_mmap64(void *start, size_t length,
return result;
}
-#define MALLOC_HOOK_HAVE_DO_MMAP64 1
-
-#elif defined(__s390x__)
-
-static inline void* do_mmap64(void *start, size_t length,
- int prot, int flags,
- int fd, __off64_t offset) __THROW {
- // mmap on s390x uses the old syscall interface
- unsigned long args[6] = { (unsigned long) start, (unsigned long) length,
- (unsigned long) prot, (unsigned long) flags,
- (unsigned long) fd, (unsigned long) offset };
- return sys_mmap(args);
-}
-
-#define MALLOC_HOOK_HAVE_DO_MMAP64 1
+//#define MALLOC_HOOK_HAVE_DO_MMAP64 1
#endif // #if defined(__x86_64__)
@@ -162,8 +171,10 @@ extern "C" {
void* mremap(void* old_addr, size_t old_size, size_t new_size,
int flags, ...) __THROW
ATTRIBUTE_SECTION(malloc_hook);
+#if !defined(__ANDROID__)
void* sbrk(ptrdiff_t increment) __THROW
ATTRIBUTE_SECTION(malloc_hook);
+#endif
}
extern "C" void* mmap64(void *start, size_t length, int prot, int flags,
@@ -199,7 +210,9 @@ extern "C" int munmap(void* start, size_t length) __THROW {
MallocHook::InvokeMunmapHook(start, length);
int 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;
}
@@ -210,13 +223,17 @@ extern "C" void* mremap(void* old_addr, size_t old_size, size_t new_size,
va_start(ap, flags);
void *new_address = va_arg(ap, void *);
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,
new_address);
return result;
}
-#ifndef __UCLIBC__
+// Don't hook sbrk() in Android, since it doesn't expose __sbrk.
+#if !defined(__ANDROID__)
// libc's version:
extern "C" void* __sbrk(ptrdiff_t increment);
@@ -226,8 +243,7 @@ extern "C" void* sbrk(ptrdiff_t increment) __THROW {
MallocHook::InvokeSbrkHook(result, increment);
return result;
}
-
-#endif
+#endif // !defined(__ANDROID__)
/*static*/void* MallocHook::UnhookedMMap(void *start, size_t length, int prot,
int flags, int fd, off_t offset) {