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