/* src/vm/os.hpp - system (OS) functions
- Copyright (C) 2007, 2008
+ Copyright (C) 2007, 2008, 2009, 2010, 2011
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
Copyright (C) 2008 Theobroma Systems Ltd.
# include <unistd.h>
#endif
+#if defined(__DARWIN__)
+# if defined(HAVE_MACH_MACH_H)
+# include <mach/mach.h>
+# endif
+#endif
+
+#if defined(HAVE_SYS_LOADAVG_H)
+# include <sys/loadavg.h>
+#endif
+
#if defined(HAVE_SYS_MMAN_H)
# include <sys/mman.h>
#endif
# include <sys/types.h>
#endif
+#if defined(HAVE_SYS_UTSNAME_H)
+# include <sys/utsname.h>
+#endif
+
#ifdef __cplusplus
static inline void* dlsym(void* handle, const char* symbol);
static inline int fclose(FILE* fp);
static inline FILE* fopen(const char* path, const char* mode);
- static inline int fprintf(FILE* stream, const char* format, ...);
+ static inline int vfprintf ( FILE * stream, const char * format, va_list arg );
static inline size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
static inline void free(void* ptr);
+ static inline char* getcwd(char* buf, size_t size);
static inline char* getenv(const char* name);
static inline int gethostname(char* name, size_t len);
+ static inline int getloadavg(double loadavg[], int nelem);
static inline int getpagesize(void);
+ static inline pid_t getpid(void);
static inline int getsockname(int s, struct sockaddr* name, socklen_t* namelen);
static inline int getsockopt(int s, int level, int optname, void* optval, socklen_t* optlen);
static inline int listen(int sockfd, int backlog);
static void abort(const char* text, ...);
static void abort_errnum(int errnum, const char* text, ...);
static void abort_errno(const char* text, ...);
+ static char* getcwd(void);
static void* mmap_anonymous(void *addr, size_t len, int prot, int flags);
static void print_backtrace();
static int processors_online();
+
+ // Template helper
+ template<class _F1, class _F2>
+ static int call_scandir(int (*scandir)(const char *, struct dirent ***, _F1, _F2), const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *));
};
#endif
}
-inline int os::fprintf(FILE* stream, const char* format, ...)
+//fprintf is mandatory and can't be replaced with an equivalent fast wrapper
+#if !defined (HAVE_FPRINTF)
+#error fprintf not available
+#endif
+
+inline int os::vfprintf ( FILE * stream, const char * format, va_list arg )
{
-#if defined(HAVE_FPRINTF)
- va_list ap;
- va_start(ap, format);
- int result = ::fprintf(stream, format, ap);
- va_end(ap);
+#if defined(HAVE_VFPRINTF)
+ int result = ::vfprintf(stream, format, arg);
return result;
#else
-# error fprintf not available
+# error vfprintf not available
#endif
}
#endif
}
+inline char* os::getcwd(char* buf, size_t size)
+{
+#if defined(HAVE_GETCWD)
+ return ::getcwd(buf, size);
+#else
+# error getcwd not available
+#endif
+}
+
inline char* os::getenv(const char* name)
{
#if defined(HAVE_GETENV)
#endif
}
+inline int os::getloadavg(double loadavg[], int nelem)
+{
+#if defined(HAVE_GETLOADAVG)
+ return ::getloadavg(loadavg, nelem);
+#else
+# error getloadavg not available
+#endif
+}
+
inline int os::getpagesize(void)
{
#if defined(HAVE_GETPAGESIZE)
#endif
}
+inline pid_t os::getpid(void)
+{
+#if defined(HAVE_GETPID)
+ return ::getpid();
+#else
+# error getpid not available
+#endif
+}
+
inline int os::getsockname(int s, struct sockaddr* name, socklen_t* namelen)
{
#if defined(HAVE_GETSOCKNAME)
#endif
}
+template<class _F1, class _F2>
+inline int os::call_scandir(int (*scandir)(const char *, struct dirent ***, _F1, _F2), const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
+{
+ return scandir(dir, namelist, (_F1) filter, (_F2) compar);
+}
+
inline int os::scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
-/*
-#elif defined(__SOLARIS__)
-inline int os::scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const struct dirent **, const struct dirent **))
-#elif defined(__IRIX__)
-inline int os::scandir(const char *dir, struct dirent ***namelist, int(*filter)(dirent_t *), int(*compar)(dirent_t **, dirent_t **))
-#else
-inline int os::scandir(const char *dir, struct dirent ***namelist, int(*filter)(struct dirent *), int(*compar)(const void *, const void *))
-#endif
-*/
{
#if defined(HAVE_SCANDIR)
-# if defined(__LINUX__)
- return ::scandir(dir, namelist, filter, compar);
-#elif defined(__SOLARIS__)
- return ::scandir(dir, namelist, filter, (int (*)(const dirent**, const dirent**)) compar);
-# else
- return ::scandir(dir, namelist, (int (*)(struct dirent*)) filter, compar);
-# endif
+ return call_scandir(::scandir, dir, namelist, filter, compar);
#else
# error scandir not available
#endif
void* os_mmap_anonymous(void *addr, size_t len, int prot, int flags);
-void os_abort(void);
-int os_access(const char* pathname, int mode);
int os_atoi(const char* nptr);
-void* os_calloc(size_t nmemb, size_t size);
-char* os_dirname(char* path);
-char* os_dlerror(void);
-void* os_dlsym(void* handle, const char* symbol);
-int os_fclose(FILE* fp);
-FILE* os_fopen(const char* path, const char* mode);
-size_t os_fread(void* ptr, size_t size, size_t nmemb, FILE* stream);
-void os_free(void* ptr);
int os_getpagesize(void);
void* os_memcpy(void* dest, const void* src, size_t n);
void* os_memset(void* s, int c, size_t n);
-int os_mprotect(void* addr, size_t len, int prot);
-int os_scandir(const char* dir, struct dirent*** namelist, int(*filter)(const struct dirent*), int(*compar)(const void*, const void*));
-int os_stat(const char* path, struct stat* buf);
-char* os_strcat(char* dest, const char* src);
-char* os_strcpy(char* dest, const char* src);
char* os_strdup(const char* s);
int os_strlen(const char* s);