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