1 /* Copyright (C) 2007-2010 The Android Open Source Project 2 ** 3 ** This software is licensed under the terms of the GNU General Public 4 ** License version 2, as published by the Free Software Foundation, and 5 ** may be copied, distributed, and modified under those terms. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ** GNU General Public License for more details. 11 */ 12 13 /* 14 * Includes common headers for the ELFF library. 15 */ 16 17 #ifndef ELFF_ELFF_COMMON_H_ 18 #define ELFF_ELFF_COMMON_H_ 19 20 #include "stddef.h" 21 #include "sys/types.h" 22 #include "assert.h" 23 #include "memory.h" 24 #include "errno.h" 25 #ifdef WIN32 26 #include "windows.h" 27 #else // WIN32 28 #include <sys/mman.h> 29 #include <sys/stat.h> 30 #include <fcntl.h> 31 #endif // WIN32 32 33 static inline void _set_errno(uint32_t err) { 34 errno = err; 35 } 36 37 /* Main operator new. We overwrite it to redirect memory 38 * allocations to qemu_malloc, instead of malloc. */ 39 inline void* operator new(size_t size) { 40 return qemu_malloc(size); 41 } 42 43 /* Main operator delete. We overwrite it to redirect memory 44 * deallocation to qemu_free, instead of free. */ 45 inline void operator delete(void* p) { 46 if (p != NULL) { 47 qemu_free(p); 48 } 49 } 50 51 /* Main operator delete for arrays. We overwrite it to redirect 52 * memory deallocation to qemu_free, instead of free. */ 53 inline void operator delete[](void* p) { 54 if (p != NULL) { 55 qemu_free(p); 56 } 57 } 58 59 #endif // ELFF_ELFF_COMMON_H_ 60