+/**
+ * Prints an error message and aborts the VM.
+ *
+ * @param text Error message to print.
+ */
+void os::abort(const char* text, ...)
+{
+ va_list ap;
+
+ // Print the log message.
+ log_start();
+
+ va_start(ap, text);
+ log_vprint(text, ap);
+ va_end(ap);
+
+ log_finish();
+
+ // Print a backtrace.
+ os::print_backtrace();
+
+ // Now abort the VM.
+ os::abort();
+}
+
+
+/**
+ * Common code for both os::abort_errnum and os::abort_errno.
+ */
+static void abort_verrnum(int errnum, const char* text, va_list ap)
+{
+ // Print the log message.
+ log_start();
+
+ log_vprint(text, ap);
+
+ // Print the strerror-message of errnum.
+ log_print(": %s", os::strerror(errnum));
+
+ log_finish();
+
+ // Print a backtrace.
+ os::print_backtrace();
+
+ // Now abort the VM.
+ 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.
+ *
+ * @param text Error message to print.
+ */
+void os::abort_errno(const char* text, ...)
+{
+ va_list ap;
+
+ va_start(ap, text);
+ 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;
+}
+
+