X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fos.hpp;h=752b76364ad621a5eceb5a70f1e2ee6c0a52aa9a;hb=334739c9af0158813c6d0dea07d90d53a44cd0c0;hp=e8bc08fad54abeda86564340f338572afff2b19f;hpb=de341f918a85a2ca61ab48811fc1735f1cc67a84;p=cacao.git diff --git a/src/vm/os.hpp b/src/vm/os.hpp index e8bc08fad..752b76364 100644 --- a/src/vm/os.hpp +++ b/src/vm/os.hpp @@ -1,6 +1,6 @@ /* src/vm/os.hpp - system (OS) functions - Copyright (C) 2007, 2008 + Copyright (C) 2007, 2008, 2009, 2010 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO Copyright (C) 2008 Theobroma Systems Ltd. @@ -89,6 +89,16 @@ # include #endif +#if defined(__DARWIN__) +# if defined(HAVE_MACH_MACH_H) +# include +# endif +#endif + +#if defined(HAVE_SYS_LOADAVG_H) +# include +#endif + #if defined(HAVE_SYS_MMAN_H) # include #endif @@ -105,6 +115,10 @@ # include #endif +#if defined(HAVE_SYS_UTSNAME_H) +# include +#endif + #ifdef __cplusplus @@ -112,56 +126,69 @@ class os { public: // Inline functions. - static inline void abort(); - static inline int accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen); - static inline int access(const char *pathname, int mode); - static inline int atoi(const char* nptr); - static inline int backtrace(void** array, int size); - static inline char** backtrace_symbols(void* const* array, int size) throw (); - static inline void* calloc(size_t nmemb, size_t size); - static inline int close(int fd); - static inline int connect(int sockfd, const struct sockaddr* serv_addr, socklen_t addrlen); + static inline void abort(); + static inline int accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen); + static inline int access(const char *pathname, int mode); + static inline int atoi(const char* nptr); + static inline int backtrace(void** array, int size); + static inline char** backtrace_symbols(void* const* array, int size) throw (); + static inline void* calloc(size_t nmemb, size_t size); + static inline int close(int fd); + static inline int connect(int sockfd, const struct sockaddr* serv_addr, socklen_t addrlen); #if defined(ENABLE_JRE_LAYOUT) - static inline char* dirname(char* path); -#endif - static inline int dlclose(void* handle); - static inline char* dlerror(void); - static inline void* dlopen(const char* filename, int flag); - 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 size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream); - static inline void free(void* ptr); - static inline char* getenv(const char* name); - static inline int gethostname(char* name, size_t len); - static inline int getpagesize(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 inline void* malloc(size_t size); - static inline void* memcpy(void* dest, const void* src, size_t n); - static inline void* memset(void* s, int c, size_t n); - static inline int mprotect(void* addr, size_t len, int prot); - static inline int scandir(const char* dir, struct dirent*** namelist, int(*filter)(const struct dirent*), int(*compar)(const void*, const void*)); - static inline int setsockopt(int s, int level, int optname, const void* optval, socklen_t optlen); - static inline int shutdown(int s, int how); - static inline int socket(int domain, int type, int protocol); - static inline int stat(const char* path, struct stat* buf); + static inline char* dirname(char* path); +#endif + static inline int dlclose(void* handle); + static inline char* dlerror(void); + static inline void* dlopen(const char* filename, int flag); + 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 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 inline void* malloc(size_t size); + static inline void* memcpy(void* dest, const void* src, size_t n); + static inline void* memset(void* s, int c, size_t n); + static inline int mprotect(void* addr, size_t len, int prot); + static inline ssize_t readlink(const char* path, char* buf, size_t bufsiz); + static inline int scandir(const char* dir, struct dirent*** namelist, int(*filter)(const struct dirent*), int(*compar)(const void*, const void*)); + static inline ssize_t send(int s, const void* buf, size_t len, int flags); + static inline int setsockopt(int s, int level, int optname, const void* optval, socklen_t optlen); + static inline int shutdown(int s, int how); + static inline int socket(int domain, int type, int protocol); + static inline int stat(const char* path, struct stat* buf); #if defined(__SOLARIS__) - static inline int str2sig(const char* str, int* signum); + static inline int str2sig(const char* str, int* signum); #endif - static inline char* strcat(char* dest, const char* src); - static inline int strcmp(const char* s1, const char* s2); - static inline char* strcpy(char* dest, const char* src); - static inline char* strdup(const char* s); - static inline size_t strlen(const char* s); - static inline char* strerror(int errnum); + static inline char* strcat(char* dest, const char* src); + static inline int strcmp(const char* s1, const char* s2); + static inline char* strcpy(char* dest, const char* src); + static inline char* strdup(const char* s); + static inline size_t strlen(const char* s); + static inline char* strerror(int errnum); // Convenience functions. + 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 + 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 *)); }; @@ -271,7 +298,9 @@ inline int os::dlclose(void* handle) inline char* os::dlerror(void) { #if defined(HAVE_DLERROR) - return ::dlerror(); + // At least FreeBSD defines dlerror() to return a const char*, so + // we simply cast it. + return (char*) ::dlerror(); #else # error dlerror not available #endif @@ -318,7 +347,7 @@ inline int os::fprintf(FILE* stream, const char* format, ...) #if defined(HAVE_FPRINTF) va_list ap; va_start(ap, format); - int result = ::fprintf(stream, format, ap); + int result = ::vfprintf(stream, format, ap); va_end(ap); return result; #else @@ -362,6 +391,15 @@ inline static int system_ftruncate(int fd, off_t length) #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) @@ -380,6 +418,15 @@ inline int os::gethostname(char* name, size_t len) #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) @@ -389,6 +436,15 @@ inline int os::getpagesize(void) #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) @@ -479,6 +535,15 @@ inline static ssize_t system_read(int fd, void *buf, size_t count) #endif } +inline ssize_t os::readlink(const char* path, char* buf, size_t bufsiz) +{ +#if defined(HAVE_READLINK) + return ::readlink(path, buf, bufsiz); +#else +# error readlink not available +#endif +} + inline static void *system_realloc(void *ptr, size_t size) { #if defined(HAVE_REALLOC) @@ -488,30 +553,31 @@ inline static void *system_realloc(void *ptr, size_t size) #endif } +template +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 } +inline ssize_t os::send(int s, const void* buf, size_t len, int flags) +{ + // TODO Should be restartable on Linux and interruptible on Solaris. +#if defined(HAVE_SEND) + return ::send(s, buf, len, flags); +#else +# error send not available +#endif +} + inline int os::setsockopt(int s, int level, int optname, const void* optval, socklen_t optlen) { #if defined(HAVE_SETSOCKOPT) @@ -626,27 +692,10 @@ inline static ssize_t system_write(int fd, const void *buf, size_t count) 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); -int os_dlclose(void* handle); -char* os_dlerror(void); -void* os_dlopen(const char* filename, int flag); -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);