1 /* 2 * Copyright (c) 1999, 2018, 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_BSD_VM_OS_BSD_INLINE_HPP 26 #define OS_BSD_VM_OS_BSD_INLINE_HPP 27 28 #include "runtime/os.hpp" 29 30 // System includes 31 32 #include <unistd.h> 33 #include <sys/socket.h> 34 #include <poll.h> 35 #include <netdb.h> 36 37 // File names are case-insensitive on windows only 38 inline int os::file_name_strncmp(const char* s1, const char* s2, size_t num) { 39 return strncmp(s1, s2, num); 40 } 41 42 inline bool os::uses_stack_guard_pages() { 43 return true; 44 } 45 46 inline bool os::must_commit_stack_guard_pages() { 47 assert(uses_stack_guard_pages(), "sanity check"); 48 #if !defined(__FreeBSD__) || __FreeBSD__ < 5 49 // Since FreeBSD 4 uses malloc() for allocating the thread stack 50 // there is no need to do anything extra to allocate the guard pages 51 return false; 52 #else 53 // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks. 54 // Must 'allocate' them or guard pages are ignored. 55 return true; 56 #endif 57 } 58 59 60 // On Bsd, 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 } 64 65 66 // Bang the shadow pages if they need to be touched to be mapped. 67 inline void os::map_stack_shadow_pages(address sp) { 68 } 69 70 inline void os::dll_unload(void *lib) { 71 ::dlclose(lib); 72 } 73 74 inline const int os::default_file_open_flags() { return 0;} 75 76 inline jlong os::lseek(int fd, jlong offset, int whence) { 77 return (jlong) ::lseek(fd, offset, whence); 78 } 79 80 inline int os::fsync(int fd) { 81 return ::fsync(fd); 82 } 83 84 inline int os::ftruncate(int fd, jlong length) { 85 return ::ftruncate(fd, length); 86 } 87 88 // macros for restartable system calls 89 90 #define RESTARTABLE(_cmd, _result) do { \ 91 _result = _cmd; \ 92 } while(((int)_result == OS_ERR) && (errno == EINTR)) 93 94 #define RESTARTABLE_RETURN_INT(_cmd) do { \ 95 int _result; \ 96 RESTARTABLE(_cmd, _result); \ 97 return _result; \ 98 } while(false) 99 100 inline bool os::numa_has_static_binding() { return true; } 101 inline bool os::numa_has_group_homing() { return false; } 102 103 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { 104 size_t res; 105 RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); 106 return res; 107 } 108 109 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { 110 size_t res; 111 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); 112 return res; 113 } 114 115 inline int os::close(int fd) { 116 return ::close(fd); 117 } 118 119 inline int os::socket_close(int fd) { 120 return ::close(fd); 121 } 122 123 inline int os::socket(int domain, int type, int protocol) { 124 return ::socket(domain, type, protocol); 125 } 126 127 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) { 128 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags)); 129 } 130 131 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) { 132 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); 133 } 134 135 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { 136 return os::send(fd, buf, nBytes, flags); 137 } 138 139 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) { 140 RESTARTABLE_RETURN_INT(::connect(fd, him, len)); 141 } 142 143 inline struct hostent* os::get_host_by_name(char* name) { 144 return ::gethostbyname(name); 145 } 146 147 inline bool os::supports_monotonic_clock() { 148 #ifdef __APPLE__ 149 return true; 150 #else 151 return Bsd::_clock_gettime != NULL; 152 #endif 153 } 154 155 inline void os::exit(int num) { 156 ::exit(num); 157 } 158 159 #endif // OS_BSD_VM_OS_BSD_INLINE_HPP