Changeset 53657 in vbox for trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libctf
- Timestamp:
- Jan 2, 2015 12:28:56 PM (10 years ago)
- Location:
- trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libctf/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libctf/common/ctf_lib.c
r53650 r53657 25 25 */ 26 26 27 #ifndef VBOX 27 28 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 … … 36 37 #include <dlfcn.h> 37 38 #include <gelf.h> 38 39 #else 40 # include <libctf.h> 41 # include <ctf_impl.h> 42 # include <iprt/param.h> 43 # include <sys/stat.h> 44 # include <stdio.h> 45 # include <fcntl.h> 46 # ifdef _MSC_VER 47 # include <io.h> 48 # else 49 # include <unistd.h> 50 # endif 51 # define stat64 stat 52 # define fstat64 fstat 53 # define open64 open 54 # define off64_t int64_t 55 #endif 56 57 #ifndef VBOX /* staticly linked in */ 39 58 #ifdef _LP64 40 59 static const char *_libctf_zlib = "/usr/lib/64/libz.so"; … … 48 67 void *z_dlp; 49 68 } zlib; 69 #endif /* !VBOX */ 50 70 51 71 static size_t _PAGESIZE; 52 72 static size_t _PAGEMASK; 53 73 74 #ifndef VBOX 54 75 #pragma init(_libctf_init) 55 76 void 56 77 _libctf_init(void) 57 { 78 #else 79 void libctf_init(void) 80 #endif 81 { 82 #ifndef VBOX 58 83 const char *p = getenv("LIBCTF_DECOMPRESSOR"); 59 84 60 85 if (p != NULL) 61 86 _libctf_zlib = p; /* use alternate decompression library */ 87 #endif 62 88 63 89 _libctf_debug = getenv("LIBCTF_DEBUG") != NULL; 64 90 91 #ifndef VBOX 65 92 _PAGESIZE = getpagesize(); 93 #else 94 _PAGESIZE = PAGE_SIZE; 95 #endif 66 96 _PAGEMASK = ~(_PAGESIZE - 1); 67 97 } 98 99 #ifdef VBOX 100 /* 101 * Fake MMAP for read only access. 102 */ 103 # define munmap(a_pvMem, a_cbMem) \ 104 RTMemPageFree(a_pvMem, a_cbMem) 105 106 # define mmap64(a_pvAddr, a_cb, a_fProt, a_fFlags, a_fd, a_offFile) \ 107 VBoxCtfMap64Fake(a_pvAddr, a_cb, a_fProt, a_fFlags, a_fd, a_offFile) 108 109 # undef PROT_READ 110 # define PROT_READ 0xfeed 111 # undef MAP_PRIVATE 112 # define MAP_PRIVATE 0xbeef 113 114 static void *VBoxCtfMap64Fake(void *pvAddr, size_t cb, int fProt, int fFlags, int fd, int64_t offFile) 115 { 116 off_t const offSaved = lseek(fd, 0, SEEK_CUR); 117 void *pvRet; 118 int err; 119 120 Assert(pvAddr == NULL); NOREF(pvAddr); 121 Assert(fProt == PROT_READ); 122 Assert(fFlags == MAP_PRIVATE); 123 if ((off_t)offFile != offFile) { 124 errno = EIO; 125 return MAP_FAILED; 126 } 127 128 if (lseek(offFile, offFile, SEEK_SET) >= 0) { 129 130 pvRet = RTMemPageAllocZ(cb); 131 if (!pvRet) { 132 #ifdef _MSC_VER 133 ssize_t cbRead = read(fd, pvRet, (unsigned int)cb); 134 #else 135 ssize_t cbRead = read(fd, pvRet, cb); 136 #endif 137 if (cbRead < 0) { 138 RTMemPageFree(pvRet, cb); 139 pvRet = MAP_FAILED; 140 } 141 } else { 142 errno = ENOMEM; 143 pvRet = MAP_FAILED; 144 } 145 146 /* restore original position */ 147 err = errno; 148 lseek(offSaved, 0, SEEK_SET); 149 errno = err; 150 } 151 152 return pvRet; 153 } 154 155 /* 156 * pread64 157 */ 158 #define pread64(a_fd, a_pvBuf, a_cbToRead, a_offFile) \ 159 VBoxCtfPRead64(a_fd, a_pvBuf, a_cbToRead, a_offFile) 160 161 static ssize_t VBoxCtfPRead64(int fd, void *pvBuf, size_t cbToRead, int64_t offFile) 162 { 163 if ((off_t)offFile != offFile) { 164 errno = EIO; 165 return -1; 166 } 167 168 if (lseek(fd, offFile, SEEK_SET) < 0) 169 return -1; 170 #ifndef _MSC_VER 171 return read(fd, pvBuf, cbToRead); 172 #else 173 return read(fd, pvBuf, (unsigned int)cbToRead); 174 #endif 175 } 176 177 178 179 #endif /* VBOX */ 180 181 #ifndef VBOX 68 182 69 183 /* … … 113 227 return (zlib.z_error(err)); 114 228 } 229 230 #endif /* VBOX */ 115 231 116 232 /* -
trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libctf/common/ctf_subr.c
r53650 r53657 25 25 */ 26 26 27 #ifndef VBOX 27 28 #pragma ident "%Z%%M% %I% %E% SMI" 29 #endif 28 30 29 31 #include <ctf_impl.h> 30 32 #include <libctf.h> 33 #ifndef VBOX 31 34 #include <sys/mman.h> 32 35 #include <stdarg.h> 36 #else 37 # include <iprt/asm.h> 38 # include <iprt/log.h> 39 #endif 33 40 34 41 void * 35 42 ctf_data_alloc(size_t size) 36 43 { 44 #ifndef VBOX 37 45 return (mmap(NULL, size, PROT_READ | PROT_WRITE, 38 46 MAP_PRIVATE | MAP_ANON, -1, 0)); 47 #else 48 void *pv = RTMemPageAlloc(size); 49 return pv == NULL ? MAP_FAILED : pv; 50 #endif 39 51 } 40 52 … … 42 54 ctf_data_free(void *buf, size_t size) 43 55 { 56 #ifndef VBOX 44 57 (void) munmap(buf, size); 58 #else 59 RTMemPageFree(buf, size); 60 #endif 45 61 } 46 62 … … 48 64 ctf_data_protect(void *buf, size_t size) 49 65 { 66 #ifndef VBOX 50 67 (void) mprotect(buf, size, PROT_READ); 68 #else 69 int rc = RTMemProtect(buf, size, RTMEM_PROT_READ); 70 AssertRC(rc); 71 #endif 51 72 } 52 73 … … 54 75 ctf_alloc(size_t size) 55 76 { 77 #ifndef VBOX 56 78 return (malloc(size)); 79 #else 80 return RTMemAlloc(size); 81 #endif 57 82 } 58 83 … … 61 86 ctf_free(void *buf, size_t size) 62 87 { 88 #ifndef VBOX 63 89 free(buf); 90 #else 91 RTMemFree(buf); 92 #endif 64 93 } 65 94 … … 78 107 79 108 va_start(alist, format); 109 #ifndef VBOX 80 110 (void) fputs("libctf DEBUG: ", stderr); 81 111 (void) vfprintf(stderr, format, alist); 112 #else 113 RTLogPrintf("libctf DEBUG: %N", format, alist); 114 #endif 82 115 va_end(alist); 83 116 } -
trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libctf/common/libctf.h
r53652 r53657 56 56 extern int _libctf_debug; 57 57 58 #ifdef VBOX 59 extern void libctf_init(void); 60 #endif 61 58 62 #ifdef __cplusplus 59 63 }
Note:
See TracChangeset
for help on using the changeset viewer.