1 /* src/vmcore/system.c - system (OS) functions
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
28 /* NOTE: In this file we check for all system headers, because we wrap
29 all system calls into functions for better portability. */
31 #if defined(HAVE_ERRNO_H)
35 #if defined(HAVE_STDINT_H)
39 #if defined(HAVE_STRING_H)
43 #if defined(HAVE_UNISTD_H)
47 #if defined(HAVE_SYS_MMAN_H)
48 # include <sys/mman.h>
51 #if defined(__DARWIN__)
52 # include <mach/mach.h>
53 # include <mach/mach_host.h>
54 # include <mach/host_info.h>
57 /* this should work on BSD */
58 /* #include <sys/sysctl.h> */
63 /* system_mmap_anonymous *******************************************************
65 Maps anonymous memory, even on systems not defining
68 *******************************************************************************/
70 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags)
74 #if defined(MAP_ANON) || defined(MAP_ANONYMOUS)
75 p = mmap(addr, len, prot,
76 # if defined(MAP_ANON)
79 MAP_ANONYMOUS | flags,
85 fd = open("/dev/zero", O_RDONLY, 0);
88 vm_abort("system_mmap_anonymous: open failed: %s", strerror(errno));
90 p = mmap(addr, len, prot, flags, fd, 0);
93 #if defined(MAP_FAILED)
98 vm_abort("system_mmap_anonymous: mmap failed: %s", strerror(errno));
104 /* system_processors_online ****************************************************
106 Returns the number of online processors in the system.
109 online processor count
111 *******************************************************************************/
113 int system_processors_online(void)
115 #if defined(_SC_NPROC_ONLN)
117 return (int) sysconf(_SC_NPROC_ONLN);
119 #elif defined(_SC_NPROCESSORS_ONLN)
121 return (int) sysconf(_SC_NPROCESSORS_ONLN);
123 #elif defined(__DARWIN__)
125 host_basic_info_data_t hinfo;
126 mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
129 rc = host_info(mach_host_self(), HOST_BASIC_INFO,
130 (host_info_t) &hinfo, &hinfo_count);
132 if (rc != KERN_SUCCESS) {
136 /* XXX michi: according to my infos this should be
137 hinfo.max_cpus, can someone please confirm or deny that? */
138 return (int) hinfo.avail_cpus;
140 #elif defined(__FREEBSD__)
141 # error IMPLEMENT ME!
143 /* this should work in BSD */
145 int ncpu, mib[2], rc;
151 rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
153 return (int32_t) ncpu;
165 * These are local overrides for various environment variables in Emacs.
166 * Please do not remove this and leave it at the end of the file, where
167 * Emacs will automagically detect them.
168 * ---------------------------------------------------------------------
171 * indent-tabs-mode: t
175 * vim:noexpandtab:sw=4:ts=4: