aboutsummaryrefslogtreecommitdiffstats
path: root/elff/elff-common.h
blob: 87297365ffa3fcc8ef9c2f01bfdae8cfad485831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Copyright (C) 2007-2010 The Android Open Source Project
**
** This software is licensed under the terms of the GNU General Public
** License version 2, as published by the Free Software Foundation, and
** may be copied, distributed, and modified under those terms.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
*/

/*
 * Includes common headers for the ELFF library.
 */

#ifndef ELFF_ELFF_COMMON_H_
#define ELFF_ELFF_COMMON_H_

#include "stddef.h"
#include "sys/types.h"
#include "assert.h"
#include "memory.h"
#include "errno.h"
#ifdef  WIN32
#include "windows.h"
#else   // WIN32
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif  // WIN32

static inline void _set_errno(uint32_t err) {
    errno = err;
}

/* Main operator new. We overwrite it to redirect memory
 * allocations to qemu_malloc, instead of malloc. */
inline void* operator new(size_t size) {
    return qemu_malloc(size);
}

/* Main operator delete. We overwrite it to redirect memory
 * deallocation to qemu_free, instead of free. */
inline void operator delete(void* p) {
    if (p != NULL) {
        qemu_free(p);
    }
}

/* Main operator delete for arrays. We overwrite it to redirect
 * memory deallocation to qemu_free, instead of free. */
inline void operator delete[](void* p) {
    if (p != NULL) {
        qemu_free(p);
    }
}

#endif  // ELFF_ELFF_COMMON_H_