1 /*
   2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2015 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #ifndef OS_AIX_VM_OS_AIX_INLINE_HPP
  27 #define OS_AIX_VM_OS_AIX_INLINE_HPP
  28 
  29 #include "runtime/os.hpp"
  30 
  31 // System includes
  32 
  33 #include <unistd.h>
  34 #include <sys/socket.h>
  35 #include <sys/poll.h>
  36 #include <sys/ioctl.h>
  37 #include <netdb.h>
  38 
  39 inline void* os::thread_local_storage_at(int index) {
  40   return pthread_getspecific((pthread_key_t)index);
  41 }
  42 
  43 // File names are case-sensitive on windows only.
  44 inline int os::file_name_strcmp(const char* s1, const char* s2) {
  45   return strcmp(s1, s2);
  46 }
  47 
  48 inline bool os::obsolete_option(const JavaVMOption *option) {
  49   return false;
  50 }
  51 
  52 inline bool os::uses_stack_guard_pages() {
  53   return true;
  54 }
  55 
  56 // Whether or not calling code should/can commit/uncommit stack pages
  57 // before guarding them. Answer for AIX is definitly no, because memory
  58 // is automatically committed on touch.
  59 inline bool os::allocate_stack_guard_pages() {
  60   assert(uses_stack_guard_pages(), "sanity check");
  61   return false;
  62 }
  63 
  64 // On Aix, reservations are made on a page by page basis, nothing to do.
  65 inline void os::pd_split_reserved_memory(char *base, size_t size,
  66                                          size_t split, bool realloc) {
  67 }
  68 
  69 // Bang the shadow pages if they need to be touched to be mapped.
  70 inline void os::bang_stack_shadow_pages() {
  71 }
  72 
  73 inline void os::dll_unload(void *lib) {
  74   ::dlclose(lib);
  75 }
  76 
  77 inline const int os::default_file_open_flags() { return 0;}
  78 
  79 inline DIR* os::opendir(const char* dirname) {
  80   assert(dirname != NULL, "just checking");
  81   return ::opendir(dirname);
  82 }
  83 
  84 inline int os::readdir_buf_size(const char *path) {
  85   // According to aix sys/limits, NAME_MAX must be retrieved at runtime.
  86   const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX);
  87   return my_NAME_MAX + sizeof(dirent) + 1;
  88 }
  89 
  90 inline jlong os::lseek(int fd, jlong offset, int whence) {
  91   return (jlong) ::lseek64(fd, offset, whence);
  92 }
  93 
  94 inline int os::fsync(int fd) {
  95   return ::fsync(fd);
  96 }
  97 
  98 inline char* os::native_path(char *path) {
  99   return path;
 100 }
 101 
 102 inline int os::ftruncate(int fd, jlong length) {
 103   return ::ftruncate64(fd, length);
 104 }
 105 
 106 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) {
 107   dirent* p;
 108   int status;
 109   assert(dirp != NULL, "just checking");
 110 
 111   // NOTE: Linux readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
 112   // version. Here is the doc for this function:
 113   // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
 114 
 115   if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
 116     errno = status;
 117     return NULL;
 118   } else
 119     return p;
 120 }
 121 
 122 inline int os::closedir(DIR *dirp) {
 123   assert(dirp != NULL, "argument is NULL");
 124   return ::closedir(dirp);
 125 }
 126 
 127 // macros for restartable system calls
 128 
 129 #define RESTARTABLE(_cmd, _result) do { \
 130     _result = _cmd; \
 131   } while(((int)_result == OS_ERR) && (errno == EINTR))
 132 
 133 #define RESTARTABLE_RETURN_INT(_cmd) do { \
 134   int _result; \
 135   RESTARTABLE(_cmd, _result); \
 136   return _result; \
 137 } while(false)
 138 
 139 // We don't have NUMA support on Aix, but we need this for compilation.
 140 inline bool os::numa_has_static_binding()   { ShouldNotReachHere(); return true; }
 141 inline bool os::numa_has_group_homing()     { ShouldNotReachHere(); return false;  }
 142 
 143 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
 144   size_t res;
 145   RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
 146   return res;
 147 }
 148 
 149 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
 150   size_t res;
 151   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
 152   return res;
 153 }
 154 
 155 inline int os::close(int fd) {
 156   return ::close(fd);
 157 }
 158 
 159 inline int os::socket_close(int fd) {
 160   return ::close(fd);
 161 }
 162 
 163 inline int os::socket(int domain, int type, int protocol) {
 164   return ::socket(domain, type, protocol);
 165 }
 166 
 167 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
 168   RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
 169 }
 170 
 171 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
 172   RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
 173 }
 174 
 175 inline int os::raw_send(int fd, char *buf, size_t nBytes, uint flags) {
 176   return os::send(fd, buf, nBytes, flags);
 177 }
 178 
 179 inline int os::connect(int fd, struct sockaddr *him, socklen_t len) {
 180   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
 181 }
 182 
 183 inline struct hostent* os::get_host_by_name(char* name) {
 184   return ::gethostbyname(name);
 185 }
 186 
 187 inline bool os::supports_monotonic_clock() {
 188   // mread_real_time() is monotonic on AIX (see os::javaTimeNanos() comments)
 189   return true;
 190 }
 191 
 192 inline void os::exit(int num) {
 193   ::exit(num);
 194 }
 195 
 196 #endif // OS_AIX_VM_OS_AIX_INLINE_HPP