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

Side by Side Diff: third_party/tcmalloc/vendor/src/malloc_hook_mmap_linux.h

Issue 9316021: Update the tcmalloc vendor branch to r144 (gperftools 2.0). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reuploading Created 8 years, 9 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 // Copyright (c) 2005, Google Inc. 1 // Copyright (c) 2005, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 30 matching lines...) Expand all
41 41
42 #include <unistd.h> 42 #include <unistd.h>
43 #include <syscall.h> 43 #include <syscall.h>
44 #include <sys/mman.h> 44 #include <sys/mman.h>
45 #include <errno.h> 45 #include <errno.h>
46 #include "base/linux_syscall_support.h" 46 #include "base/linux_syscall_support.h"
47 47
48 // The x86-32 case and the x86-64 case differ: 48 // The x86-32 case and the x86-64 case differ:
49 // 32b has a mmap2() syscall, 64b does not. 49 // 32b has a mmap2() syscall, 64b does not.
50 // 64b and 32b have different calling conventions for mmap(). 50 // 64b and 32b have different calling conventions for mmap().
51 #if defined(__i386__) || defined(__PPC__) 51
52 // I test for 64-bit first so I don't have to do things like
53 // '#if (defined(__mips__) && !defined(__MIPS64__))' as a mips32 check.
54 #if defined(__x86_64__) || defined(__PPC64__) || (defined(_MIPS_SIM) && _MIPS_SI M == _ABI64)
52 55
53 static inline void* do_mmap64(void *start, size_t length, 56 static inline void* do_mmap64(void *start, size_t length,
54 int prot, int flags, 57 int prot, int flags,
58 int fd, __off64_t offset) __THROW {
59 return sys_mmap(start, length, prot, flags, fd, offset);
60 }
61
62 #define MALLOC_HOOK_HAVE_DO_MMAP64 1
63
64 #elif defined(__i386__) || defined(__PPC__) || defined(__mips__) || \
65 defined(__arm__)
66
67 static inline void* do_mmap64(void *start, size_t length,
68 int prot, int flags,
55 int fd, __off64_t offset) __THROW { 69 int fd, __off64_t offset) __THROW {
56 void *result; 70 void *result;
57 71
58 // Try mmap2() unless it's not supported 72 // Try mmap2() unless it's not supported
59 static bool have_mmap2 = true; 73 static bool have_mmap2 = true;
60 if (have_mmap2) { 74 if (have_mmap2) {
61 static int pagesize = 0; 75 static int pagesize = 0;
62 if (!pagesize) pagesize = getpagesize(); 76 if (!pagesize) pagesize = getpagesize();
63 77
64 // Check that the offset is page aligned 78 // Check that the offset is page aligned
(...skipping 13 matching lines...) Expand all
78 } 92 }
79 93
80 if (((off_t)offset) != offset) { 94 if (((off_t)offset) != offset) {
81 // If we're trying to map a 64-bit offset, fail now since we don't 95 // If we're trying to map a 64-bit offset, fail now since we don't
82 // have 64-bit mmap() support. 96 // have 64-bit mmap() support.
83 result = MAP_FAILED; 97 result = MAP_FAILED;
84 errno = EINVAL; 98 errno = EINVAL;
85 goto out; 99 goto out;
86 } 100 }
87 101
102 #ifdef __NR_mmap
88 { 103 {
89 // Fall back to old 32-bit offset mmap() call 104 // Fall back to old 32-bit offset mmap() call
90 // Old syscall interface cannot handle six args, so pass in an array 105 // Old syscall interface cannot handle six args, so pass in an array
91 int32 args[6] = { (int32) start, length, prot, flags, fd, (off_t) offset }; 106 int32 args[6] = { (int32) start, (int32) length, prot, flags, fd,
107 (off_t) offset };
92 result = (void *)syscall(SYS_mmap, args); 108 result = (void *)syscall(SYS_mmap, args);
93 } 109 }
110 #else
111 // Some Linux ports like ARM EABI Linux has no mmap, just mmap2.
112 result = MAP_FAILED;
113 #endif
114
94 out: 115 out:
95 return result; 116 return result;
96 } 117 }
97 118
98 #define MALLOC_HOOK_HAVE_DO_MMAP64 1 119 #define MALLOC_HOOK_HAVE_DO_MMAP64 1
99 120
100 #elif defined(__x86_64__) || defined(__PPC64__) // #if defined(__i386__) || ... 121 #endif // #if defined(__x86_64__)
101
102 static inline void* do_mmap64(void *start, size_t length,
103 int prot, int flags,
104 int fd, __off64_t offset) __THROW {
105 return (void *)syscall(SYS_mmap, start, length, prot, flags, fd, offset);
106 }
107
108 #define MALLOC_HOOK_HAVE_DO_MMAP64 1
109
110 #endif // #if defined(__i386__) || defined(__PPC__)
111 122
112 123
113 #ifdef MALLOC_HOOK_HAVE_DO_MMAP64 124 #ifdef MALLOC_HOOK_HAVE_DO_MMAP64
114 125
115 // We use do_mmap64 abstraction to put MallocHook::InvokeMmapHook 126 // We use do_mmap64 abstraction to put MallocHook::InvokeMmapHook
116 // calls right into mmap and mmap64, so that the stack frames in the caller's 127 // calls right into mmap and mmap64, so that the stack frames in the caller's
117 // stack are at the same offsets for all the calls of memory allocating 128 // stack are at the same offsets for all the calls of memory allocating
118 // functions. 129 // functions.
119 130
120 // Put all callers of MallocHook::Invoke* in this module into 131 // Put all callers of MallocHook::Invoke* in this module into
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 int result; 225 int result;
215 if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) { 226 if (!MallocHook::InvokeMunmapReplacement(start, length, &result)) {
216 result = syscall(SYS_munmap, start, length); 227 result = syscall(SYS_munmap, start, length);
217 } 228 }
218 return result; 229 return result;
219 } 230 }
220 231
221 #undef MALLOC_HOOK_HAVE_DO_MMAP64 232 #undef MALLOC_HOOK_HAVE_DO_MMAP64
222 233
223 #endif // #ifdef MALLOC_HOOK_HAVE_DO_MMAP64 234 #endif // #ifdef MALLOC_HOOK_HAVE_DO_MMAP64
OLDNEW
« no previous file with comments | « third_party/tcmalloc/vendor/src/malloc_hook_mmap_freebsd.h ('k') | third_party/tcmalloc/vendor/src/memfs_malloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698