1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2018 SAP SE. 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 <poll.h>
  36 #include <sys/ioctl.h>
  37 #include <netdb.h>
  38 
  39 // File names are case-insensitive on windows only.
  40 inline int os::file_name_strncmp(const char* s1, const char* s2, size_t num) {
  41   return strncmp(s1, s2, num);
  42 }
  43 
  44 inline bool os::obsolete_option(const JavaVMOption *option) {
  45   return false;
  46 }
  47 
  48 inline bool os::uses_stack_guard_pages() {
  49   return true;
  50 }
  51 
  52 // Whether or not calling code should/can commit/uncommit stack pages
  53 // before guarding them. Answer for AIX is definitly no, because memory
  54 // is automatically committed on touch.
  55 inline bool os::must_commit_stack_guard_pages() {
  56   assert(uses_stack_guard_pages(), "sanity check");
  57   return false;
  58 }
  59 
  60 // On Aix, reservations are made on a page by page basis, nothing to do.
  61 inline void os::pd_split_reserved_memory(char *base, size_t size,
  62                                          size_t split, bool realloc) {
  63   // TODO: Determine whether Sys V memory is split. If yes, we need to treat
  64   // this the same way Windows treats its VirtualAlloc allocations.
  65 }
  66 
  67 // Bang the shadow pages if they need to be touched to be mapped.
  68 inline void os::map_stack_shadow_pages(address sp) {
  69 }
  70 
  71 inline void os::dll_unload(void *lib) {
  72   ::dlclose(lib);
  73 }
  74 
  75 inline const int os::default_file_open_flags() { return 0;}
  76 
  77 inline jlong os::lseek(int fd, jlong offset, int whence) {
  78   return (jlong) ::lseek64(fd, offset, whence);
  79 }
  80 
  81 inline int os::fsync(int fd) {
  82   return ::fsync(fd);
  83 }
  84 
  85 inline int os::ftruncate(int fd, jlong length) {
  86   return ::ftruncate64(fd, length);
  87 }
  88 
  89 // macros for restartable system calls
  90 
  91 #define RESTARTABLE(_cmd, _result) do { \
  92     _result = _cmd; \
  93   } while(((int)_result == OS_ERR) && (errno == EINTR))
  94 
  95 #define RESTARTABLE_RETURN_INT(_cmd) do { \
  96   int _result; \
  97   RESTARTABLE(_cmd, _result); \
  98   return _result; \
  99 } while(false)
 100 
 101 // We don't have NUMA support on Aix, but we need this for compilation.
 102 inline bool os::numa_has_static_binding()   { ShouldNotReachHere(); return true; }
 103 inline bool os::numa_has_group_homing()     { ShouldNotReachHere(); return false;  }
 104 
 105 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
 106   size_t res;
 107   RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
 108   return res;
 109 }
 110 
 111 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
 112   size_t res;
 113   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
 114   return res;
 115 }
 116 
 117 inline int os::close(int fd) {
 118   return ::close(fd);
 119 }
 120 
 121 inline int os::socket_close(int fd) {
 122   return ::close(fd);
 123 }
 124 
 125 inline int os::socket(int domain, int type, int protocol) {
 126   return ::socket(domain, type, protocol);
 127 }
 128 
 129 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
 130   RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
 131 }
 132 
 133 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
 134   RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
 135 }
 136 
 137 inline int os::raw_send(int fd, char *buf, size_t nBytes, uint flags) {
 138   return os::send(fd, buf, nBytes, flags);
 139 }
 140 
 141 inline int os::connect(int fd, struct sockaddr *him, socklen_t len) {
 142   RESTARTABLE_RETURN_INT(::connect(fd, him, len));
 143 }
 144 
 145 inline struct hostent* os::get_host_by_name(char* name) {
 146   return ::gethostbyname(name);
 147 }
 148 
 149 inline bool os::supports_monotonic_clock() {
 150   // mread_real_time() is monotonic on AIX (see os::javaTimeNanos() comments)
 151   return true;
 152 }
 153 
 154 inline void os::exit(int num) {
 155   ::exit(num);
 156 }
 157 
 158 #endif // OS_AIX_VM_OS_AIX_INLINE_HPP