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

Side by Side Diff: third_party/tcmalloc/chromium/src/base/vdso_support.h

Issue 7050034: Merge google-perftools r109 (the current contents of third_party/tcmalloc/vendor) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 2008 Google Inc. All Rights Reserved. 1 // Copyright 2008 Google Inc. All Rights Reserved.
2 // Author: ppluzhnikov@google.com (Paul Pluzhnikov) 2 // Author: ppluzhnikov@google.com (Paul Pluzhnikov)
3 // 3 //
4 // Allow dynamic symbol lookup in the kernel VDSO page. 4 // Allow dynamic symbol lookup in the kernel VDSO page.
5 // 5 //
6 // VDSO stands for "Virtual Dynamic Shared Object" -- a page of 6 // VDSO stands for "Virtual Dynamic Shared Object" -- a page of
7 // executable code, which looks like a shared library, but doesn't 7 // executable code, which looks like a shared library, but doesn't
8 // necessarily exist anywhere on disk, and which gets mmap()ed into 8 // necessarily exist anywhere on disk, and which gets mmap()ed into
9 // every process by kernels which support VDSO, such as 2.6.x for 32-bit 9 // every process by kernels which support VDSO, such as 2.6.x for 32-bit
10 // executables, and 2.6.24 and above for 64-bit executables. 10 // executables, and 2.6.24 and above for 64-bit executables.
(...skipping 12 matching lines...) Expand all
23 // fn = reinterpret_cast<FN>(info.address); 23 // fn = reinterpret_cast<FN>(info.address);
24 // } 24 // }
25 25
26 #ifndef BASE_VDSO_SUPPORT_H_ 26 #ifndef BASE_VDSO_SUPPORT_H_
27 #define BASE_VDSO_SUPPORT_H_ 27 #define BASE_VDSO_SUPPORT_H_
28 28
29 #include <config.h> 29 #include <config.h>
30 #ifdef HAVE_FEATURES_H 30 #ifdef HAVE_FEATURES_H
31 #include <features.h> // for __GLIBC__ 31 #include <features.h> // for __GLIBC__
32 #endif 32 #endif
33 #include "base/basictypes.h"
33 34
34 // Maybe one day we can rewrite this file not to require the elf 35 // Maybe one day we can rewrite this file not to require the elf
35 // symbol extensions in glibc, but for right now we need them. 36 // symbol extensions in glibc, but for right now we need them.
36 #if defined(__ELF__) && defined(__GLIBC__) 37 #if defined(__ELF__) && defined(__GLIBC__)
37 38
38 #define HAVE_VDSO_SUPPORT 1 39 #define HAVE_VDSO_SUPPORT 1
39 40
40 #include <stdlib.h> // for NULL 41 #include <stdlib.h> // for NULL
41 #include <link.h> // for ElfW 42 #include <link.h> // for ElfW
42 #include "base/basictypes.h"
43 43
44 namespace base { 44 namespace base {
45 45
46 // NOTE: this class may be used from within tcmalloc, and can not 46 // NOTE: this class may be used from within tcmalloc, and can not
47 // use any memory allocation routines. 47 // use any memory allocation routines.
48 class VDSOSupport { 48 class VDSOSupport {
49 public: 49 public:
50 // Sentinel: there could never be a VDSO at this address. 50 // Sentinel: there could never be a VDSO at this address.
51 static const void *const kInvalidBase; 51 static const void *const kInvalidBase;
52 52
53 // Information about a single vdso symbol. 53 // Information about a single vdso symbol.
54 // All pointers are into .dynsym, .dynstr, or .text of the VDSO. 54 // All pointers are into .dynsym, .dynstr, or .text of the VDSO.
55 // Do not free() them or modify through them. 55 // Do not free() them or modify through them.
56 struct SymbolInfo { 56 struct SymbolInfo {
57 const char *name; // E.g. "__vdso_getcpu" 57 const char *name; // E.g. "__vdso_getcpu"
58 const char *version; // E.g. "LINUX_2.6", could be "" 58 const char *version; // E.g. "LINUX_2.6", could be ""
59 // for unversioned symbol. 59 // for unversioned symbol.
60 const void *address; // Relocated symbol address. 60 const void *address; // Relocated symbol address.
61 const ElfW(Sym) *symbol; // Symbol in the dynamic symbol table. 61 const ElfW(Sym) *symbol; // Symbol in the dynamic symbol table.
62 }; 62 };
63 63
64 // Supports iteration over all dynamic symbols. 64 // Supports iteration over all dynamic symbols.
65 class SymbolIterator { 65 class SymbolIterator {
66 public: 66 public:
67 friend struct VDSOSupport; 67 friend class VDSOSupport;
68 const SymbolInfo *operator->() const; 68 const SymbolInfo *operator->() const;
69 const SymbolInfo &operator*() const; 69 const SymbolInfo &operator*() const;
70 SymbolIterator& operator++(); 70 SymbolIterator& operator++();
71 bool operator!=(const SymbolIterator &rhs) const; 71 bool operator!=(const SymbolIterator &rhs) const;
72 bool operator==(const SymbolIterator &rhs) const; 72 bool operator==(const SymbolIterator &rhs) const;
73 private: 73 private:
74 SymbolIterator(const void *const image, int index); 74 SymbolIterator(const void *const image, int index);
75 void Update(int incr); 75 void Update(int incr);
76 SymbolInfo info_; 76 SymbolInfo info_;
77 int index_; 77 int index_;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 // image_ represents VDSO ELF image in memory. 141 // image_ represents VDSO ELF image in memory.
142 // image_.ehdr_ == NULL implies there is no VDSO. 142 // image_.ehdr_ == NULL implies there is no VDSO.
143 ElfMemImage image_; 143 ElfMemImage image_;
144 144
145 // Cached value of auxv AT_SYSINFO_EHDR, computed once. 145 // Cached value of auxv AT_SYSINFO_EHDR, computed once.
146 // This is a tri-state: 146 // This is a tri-state:
147 // kInvalidBase => value hasn't been determined yet. 147 // kInvalidBase => value hasn't been determined yet.
148 // 0 => there is no VDSO. 148 // 0 => there is no VDSO.
149 // else => vma of VDSO Elf{32,64}_Ehdr. 149 // else => vma of VDSO Elf{32,64}_Ehdr.
150 //
151 // When testing with mock VDSO, low bit is set.
152 // The low bit is always available because vdso_base_ is
153 // page-aligned.
150 static const void *vdso_base_; 154 static const void *vdso_base_;
151 155
152 // NOLINT on 'long' because these routines mimic kernel api. 156 // NOLINT on 'long' because these routines mimic kernel api.
153 // The 'cache' parameter may be used by some versions of the kernel, 157 // The 'cache' parameter may be used by some versions of the kernel,
154 // and should be NULL or point to a static buffer containing at 158 // and should be NULL or point to a static buffer containing at
155 // least two 'long's. 159 // least two 'long's.
156 static long InitAndGetCPU(unsigned *cpu, void *cache, // NOLINT 'long'. 160 static long InitAndGetCPU(unsigned *cpu, void *cache, // NOLINT 'long'.
157 void *unused); 161 void *unused);
158 static long GetCPUViaSyscall(unsigned *cpu, void *cache, // NOLINT 'long'. 162 static long GetCPUViaSyscall(unsigned *cpu, void *cache, // NOLINT 'long'.
159 void *unused); 163 void *unused);
(...skipping 13 matching lines...) Expand all
173 // Return current CPU, using (fast) __vdso_getcpu@LINUX_2.6 if present, 177 // Return current CPU, using (fast) __vdso_getcpu@LINUX_2.6 if present,
174 // otherwise use syscall(SYS_getcpu,...). 178 // otherwise use syscall(SYS_getcpu,...).
175 // May return -1 with errno == ENOSYS if the kernel doesn't 179 // May return -1 with errno == ENOSYS if the kernel doesn't
176 // support SYS_getcpu. 180 // support SYS_getcpu.
177 int GetCPU(); 181 int GetCPU();
178 } // namespace base 182 } // namespace base
179 183
180 #endif // __ELF__ and __GLIBC__ 184 #endif // __ELF__ and __GLIBC__
181 185
182 #endif // BASE_VDSO_SUPPORT_H_ 186 #endif // BASE_VDSO_SUPPORT_H_
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/base/thread_annotations.h ('k') | third_party/tcmalloc/chromium/src/base/vdso_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698