1 /*
   2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef OS_LINUX_VM_OS_LINUX_INLINE_HPP
  26 #define OS_LINUX_VM_OS_LINUX_INLINE_HPP
  27 
  28 #include "runtime/atomic.hpp"
  29 #include "runtime/os.hpp"
  30 #ifdef TARGET_OS_ARCH_linux_x86
  31 # include "atomic_linux_x86.inline.hpp"
  32 # include "orderAccess_linux_x86.inline.hpp"
  33 #endif
  34 #ifdef TARGET_OS_ARCH_linux_sparc
  35 # include "atomic_linux_sparc.inline.hpp"
  36 # include "orderAccess_linux_sparc.inline.hpp"
  37 #endif
  38 #ifdef TARGET_OS_ARCH_linux_zero
  39 # include "atomic_linux_zero.inline.hpp"
  40 # include "orderAccess_linux_zero.inline.hpp"
  41 #endif
  42 
  43 inline void* os::thread_local_storage_at(int index) {
  44   return pthread_getspecific((pthread_key_t)index);
  45 }
  46 
  47 inline const char* os::file_separator() {
  48   return "/";
  49 }
  50 
  51 inline const char* os::line_separator() {
  52   return "\n";
  53 }
  54 
  55 inline const char* os::path_separator() {
  56   return ":";
  57 }
  58 
  59 inline const char* os::jlong_format_specifier() {
  60   return "%lld";
  61 }
  62 
  63 inline const char* os::julong_format_specifier() {
  64   return "%llu";
  65 }
  66 
  67 // File names are case-sensitive on windows only
  68 inline int os::file_name_strcmp(const char* s1, const char* s2) {
  69   return strcmp(s1, s2);
  70 }
  71 
  72 inline bool os::obsolete_option(const JavaVMOption *option) {
  73   return false;
  74 }
  75 
  76 inline bool os::uses_stack_guard_pages() {
  77   return true;
  78 }
  79 
  80 inline bool os::allocate_stack_guard_pages() {
  81   assert(uses_stack_guard_pages(), "sanity check");
  82   return true;
  83 }
  84 
  85 
  86 // On Linux, reservations are made on a page by page basis, nothing to do.
  87 inline void os::split_reserved_memory(char *base, size_t size,
  88                                       size_t split, bool realloc) {
  89 }
  90 
  91 
  92 // Bang the shadow pages if they need to be touched to be mapped.
  93 inline void os::bang_stack_shadow_pages() {
  94 }
  95 
  96 inline DIR* os::opendir(const char* dirname)
  97 {
  98   assert(dirname != NULL, "just checking");
  99   return ::opendir(dirname);
 100 }
 101 
 102 inline int os::readdir_buf_size(const char *path)
 103 {
 104   return NAME_MAX + sizeof(dirent) + 1;
 105 }
 106 
 107 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
 108 {
 109   dirent* p;
 110   int status;
 111   assert(dirp != NULL, "just checking");
 112 
 113   // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
 114   // version. Here is the doc for this function:
 115   // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
 116 
 117   if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
 118     errno = status;
 119     return NULL;
 120   } else
 121     return p;
 122 }
 123 
 124 inline int os::closedir(DIR *dirp)
 125 {
 126   assert(dirp != NULL, "just checking");
 127   return ::closedir(dirp);
 128 }
 129 
 130 // macros for restartable system calls
 131 
 132 #define RESTARTABLE(_cmd, _result) do { \
 133     _result = _cmd; \
 134   } while(((int)_result == OS_ERR) && (errno == EINTR))
 135 
 136 #define RESTARTABLE_RETURN_INT(_cmd) do { \
 137   int _result; \
 138   RESTARTABLE(_cmd, _result); \
 139   return _result; \
 140 } while(false)
 141 
 142 inline bool os::numa_has_static_binding()   { return true; }
 143 inline bool os::numa_has_group_homing()     { return false;  }
 144 
 145 #endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP