* src/vmcore/system.h (system_mprotect): New function.
[cacao.git] / src / vmcore / system.h
1 /* src/vmcore/system.h - system (OS) functions
2
3    Copyright (C) 2007
4    CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _VMCORE_SYSTEM_H
27 #define _VMCORE_SYSTEM_H
28
29 #include "config.h"
30
31 /* NOTE: In this file we check for all system headers, because we wrap
32    all system calls into inline functions for better portability. */
33
34 #if defined(HAVE_STDINT_H)
35 # include <stdint.h>
36 #endif
37
38 #if defined(HAVE_STDLIB_H)
39 # include <stdlib.h>
40 #endif
41
42 #if defined(HAVE_STRING_H)
43 # include <string.h>
44 #endif
45
46 #if defined(HAVE_UNISTD_H)
47 # include <unistd.h>
48 #endif
49
50 #if defined(HAVE_SYS_MMAN_H)
51 # include <sys/mman.h>
52 #endif
53
54
55 /* inline functions ***********************************************************/
56
57 inline static void *system_calloc(size_t nmemb, size_t size)
58 {
59 #if defined(HAVE_CALLOC)
60         return calloc(nmemb, size);
61 #else
62 # error calloc not available
63 #endif
64 }
65
66 inline static void system_free(void *ptr)
67 {
68 #if defined(HAVE_FREE)
69         free(ptr);
70 #else
71 # error free not available
72 #endif
73 }
74
75 inline static int system_getpagesize(void)
76 {
77 #if defined(HAVE_GETPAGESIZE)
78         return getpagesize();
79 #else
80 # error getpagesize not available
81 #endif
82 }
83
84 inline static void *system_malloc(size_t size)
85 {
86 #if defined(HAVE_MALLOC)
87         return malloc(size);
88 #else
89 # error malloc not available
90 #endif
91 }
92
93 inline static void *system_memcpy(void *dest, const void *src, size_t n)
94 {
95 #if defined(HAVE_MEMCPY)
96         return memcpy(dest, src, n);
97 #else
98 # error memcpy not available
99 #endif
100 }
101
102 inline static void *system_memset(void *s, int c, size_t n)
103 {
104 #if defined(HAVE_MEMSET)
105         return memset(s, c, n);
106 #else
107 # error memset not available
108 #endif
109 }
110
111 inline static int system_mprotect(void *addr, size_t len, int prot)
112 {
113 #if defined(HAVE_MPROTECT)
114         return mprotect(addr, len, prot);
115 #else
116 # error mprotect not available
117 #endif
118 }
119
120 inline static void *system_realloc(void *ptr, size_t size)
121 {
122 #if defined(HAVE_REALLOC)
123         return realloc(ptr, size);
124 #else
125 # error realloc not available
126 #endif
127 }
128
129
130 /* function prototypes ********************************************************/
131
132 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
133 int   system_processors_online(void);
134
135 #endif /* _VMCORE_SYSTEM_H */
136
137
138 /*
139  * These are local overrides for various environment variables in Emacs.
140  * Please do not remove this and leave it at the end of the file, where
141  * Emacs will automagically detect them.
142  * ---------------------------------------------------------------------
143  * Local variables:
144  * mode: c
145  * indent-tabs-mode: t
146  * c-basic-offset: 4
147  * tab-width: 4
148  * End:
149  * vim:noexpandtab:sw=4:ts=4:
150  */