#include "config.h"
-/* NOTE: In this file we check for all system headers, because we wrap
- all system calls into functions for better portability. */
-
-#if defined(HAVE_ERRNO_H)
-# include <errno.h>
-#endif
-
-#if defined(HAVE_STDINT_H)
-# include <stdint.h>
-#endif
-
-#if defined(HAVE_STRING_H)
-# include <string.h>
-#endif
-
-#if defined(HAVE_UNISTD_H)
-# include <unistd.h>
-#endif
-
-#if defined(HAVE_SYS_MMAN_H)
-# include <sys/mman.h>
-#endif
-
#if defined(__DARWIN__)
# include <mach/mach.h>
# include <mach/mach_host.h>
/* this should work on BSD */
/* #include <sys/sysctl.h> */
+#include "mm/memory.hpp"
+
+#include "vm/os.hpp"
#include "vm/vm.hpp"
/**
- * Prints an error message, appends ":" plus the strerror-message of
- * errnum and aborts the VM.
- *
- * @param errnum Error number.
- * @param text Error message to print.
+ * Common code for both os::abort_errnum and os::abort_errno.
*/
-void os::abort_errnum(int errnum, const char* text, ...)
+static void abort_verrnum(int errnum, const char* text, va_list ap)
{
- va_list ap;
-
// Print the log message.
log_start();
- va_start(ap, text);
log_vprint(text, ap);
- va_end(ap);
// Print the strerror-message of errnum.
log_print(": %s", os::strerror(errnum));
os::abort();
}
+/**
+ * Prints an error message, appends ":" plus the strerror-message of
+ * errnum and aborts the VM.
+ *
+ * @param errnum Error number.
+ * @param text Error message to print.
+ */
+void os::abort_errnum(int errnum, const char* text, ...)
+{
+ va_list ap;
+
+ va_start(ap, text);
+ abort_verrnum(errnum, text, ap);
+ va_end(ap);
+}
+
/**
* Equal to abort_errnum, but uses errno to get the error number.
va_list ap;
va_start(ap, text);
- abort_errnum(errno, text, ap);
+ abort_verrnum(errno, text, ap);
va_end(ap);
}
+/**
+ * Return the current working directory.
+ *
+ * @return Pointer to a char array allocated by MNEW, or
+ * NULL if memory could not be allocated.
+ */
+char* os::getcwd(void)
+{
+ int32_t size = 1024;
+
+ char* buf = MNEW(char, size);
+
+ while (buf != NULL) {
+ if (getcwd(buf, size) != NULL)
+ return buf;
+
+ MFREE(buf, char, size);
+
+ /* too small buffer or a more serious problem */
+
+ if (errno != ERANGE)
+ abort_errno("os::getcwd: getcwd failed");
+
+ /* double the buffer size */
+
+ size *= 2;
+
+ buf = MNEW(char, size);
+ }
+
+ return NULL;
+}
+
+
/**
* Maps anonymous memory, even on systems not defining
* MAP_ANON(YMOUS).
extern "C" {
void* os_mmap_anonymous(void *addr, size_t len, int prot, int flags) { return os::mmap_anonymous(addr, len, prot, flags); }
- void os_abort(void) { os::abort(); }
- int os_access(const char* pathname, int mode) { return os::access(pathname, mode); }
int os_atoi(const char* nptr) { return os::atoi(nptr); }
- void* os_calloc(size_t nmemb, size_t size) { return os::calloc(nmemb, size); }
-#if defined(ENABLE_JRE_LAYOUT)
- char* os_dirname(char* path) { return os::dirname(path); }
-#endif
- char* os_dlerror(void) { return os::dlerror(); }
- void* os_dlsym(void* handle, const char* symbol) { return os::dlsym(handle, symbol); }
- int os_fclose(FILE* fp) { return os::fclose(fp); }
- FILE* os_fopen(const char* path, const char* mode) { return os::fopen(path, mode); }
- size_t os_fread(void* ptr, size_t size, size_t nmemb, FILE* stream) { return os::fread(ptr, size, nmemb, stream); }
- void os_free(void* ptr) { os::free(ptr); }
int os_getpagesize(void) { return os::getpagesize(); }
void* os_memcpy(void* dest, const void* src, size_t n) { return os::memcpy(dest, src, n); }
void* os_memset(void* s, int c, size_t n) { return os::memset(s, c, n); }
- int os_mprotect(void* addr, size_t len, int prot) { return os::mprotect(addr, len, prot); }
- int os_scandir(const char* dir, struct dirent*** namelist, int(*filter)(const struct dirent*), int(*compar)(const void*, const void*)) { return os::scandir(dir, namelist, filter, compar); }
- int os_stat(const char* path, struct stat* buf) { return os::stat(path, buf); }
- char* os_strcat(char* dest, const char* src) { return os::strcat(dest, src); }
- char* os_strcpy(char* dest, const char* src) { return os::strcpy(dest, src); }
char* os_strdup(const char* s) { return os::strdup(s); }
int os_strlen(const char* s) { return os::strlen(s); }