2579e6675f237239210fa8b311be080023985537
[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
51 /* inline functions ***********************************************************/
52
53 inline static void *system_calloc(size_t nmemb, size_t size)
54 {
55 #if defined(HAVE_CALLOC)
56         return calloc(nmemb, size);
57 #else
58 # error calloc not available
59 #endif
60 }
61
62 inline static void system_free(void *ptr)
63 {
64 #if defined(HAVE_FREE)
65         free(ptr);
66 #else
67 # error free not available
68 #endif
69 }
70
71 inline static int system_getpagesize(void)
72 {
73 #if defined(HAVE_GETPAGESIZE)
74         return getpagesize();
75 #else
76 # error getpagesize not available
77 #endif
78 }
79
80 inline static void *system_malloc(size_t size)
81 {
82 #if defined(HAVE_MALLOC)
83         return malloc(size);
84 #else
85 # error malloc not available
86 #endif
87 }
88
89 inline static void *system_memcpy(void *dest, const void *src, size_t n)
90 {
91 #if defined(HAVE_MEMCPY)
92         return memcpy(dest, src, n);
93 #else
94 # error memcpy not available
95 #endif
96 }
97
98 inline static void *system_memset(void *s, int c, size_t n)
99 {
100 #if defined(HAVE_MEMSET)
101         return memset(s, c, n);
102 #else
103 # error memset not available
104 #endif
105 }
106
107 inline static void *system_realloc(void *ptr, size_t size)
108 {
109 #if defined(HAVE_REALLOC)
110         return realloc(ptr, size);
111 #else
112 # error realloc not available
113 #endif
114 }
115
116
117 /* function prototypes ********************************************************/
118
119 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
120 int   system_processors_online(void);
121
122 #endif /* _VMCORE_SYSTEM_H */
123
124
125 /*
126  * These are local overrides for various environment variables in Emacs.
127  * Please do not remove this and leave it at the end of the file, where
128  * Emacs will automagically detect them.
129  * ---------------------------------------------------------------------
130  * Local variables:
131  * mode: c
132  * indent-tabs-mode: t
133  * c-basic-offset: 4
134  * tab-width: 4
135  * End:
136  * vim:noexpandtab:sw=4:ts=4:
137  */