Wed, 21 Dec 2011 15:48:16 -0500
7091417: recvfrom's 6th input should be of type socklen_t
Summary: Revamp class os's socket method formal args to match socket.h, insert casts in appropriate places, and copyin-copyout int*'s that s/b socklen_t*'s in jvm.cpp.
Reviewed-by: coleenp, dholmes
Contributed-by: erik.gahlin@oracle.com, rickard.backman@oracle.com, nils.loodin@oracle.com, markus.gronlund@oracle.com
1 /*
2 * Copyright (c) 1999, 2011, 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 */
25 #ifndef OS_BSD_VM_OS_BSD_INLINE_HPP
26 #define OS_BSD_VM_OS_BSD_INLINE_HPP
28 #include "runtime/atomic.hpp"
29 #include "runtime/os.hpp"
30 #ifdef TARGET_OS_ARCH_bsd_x86
31 # include "atomic_bsd_x86.inline.hpp"
32 # include "orderAccess_bsd_x86.inline.hpp"
33 #endif
34 #ifdef TARGET_OS_ARCH_bsd_zero
35 # include "atomic_bsd_zero.inline.hpp"
36 # include "orderAccess_bsd_zero.inline.hpp"
37 #endif
39 // System includes
41 #include <unistd.h>
42 #include <sys/socket.h>
43 #include <sys/poll.h>
44 #include <netdb.h>
46 inline void* os::thread_local_storage_at(int index) {
47 return pthread_getspecific((pthread_key_t)index);
48 }
50 inline const char* os::file_separator() {
51 return "/";
52 }
54 inline const char* os::line_separator() {
55 return "\n";
56 }
58 inline const char* os::path_separator() {
59 return ":";
60 }
62 inline const char* os::jlong_format_specifier() {
63 return "%lld";
64 }
66 inline const char* os::julong_format_specifier() {
67 return "%llu";
68 }
70 // File names are case-sensitive on windows only
71 inline int os::file_name_strcmp(const char* s1, const char* s2) {
72 return strcmp(s1, s2);
73 }
75 inline bool os::obsolete_option(const JavaVMOption *option) {
76 return false;
77 }
79 inline bool os::uses_stack_guard_pages() {
80 return true;
81 }
83 inline bool os::allocate_stack_guard_pages() {
84 assert(uses_stack_guard_pages(), "sanity check");
85 #if !defined(__FreeBSD__) || __FreeBSD__ < 5
86 // Since FreeBSD 4 uses malloc() for allocating the thread stack
87 // there is no need to do anything extra to allocate the guard pages
88 return false;
89 #else
90 // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.
91 // Must 'allocate' them or guard pages are ignored.
92 return true;
93 #endif
94 }
97 // On Bsd, reservations are made on a page by page basis, nothing to do.
98 inline void os::split_reserved_memory(char *base, size_t size,
99 size_t split, bool realloc) {
100 }
103 // Bang the shadow pages if they need to be touched to be mapped.
104 inline void os::bang_stack_shadow_pages() {
105 }
107 inline void os::dll_unload(void *lib) {
108 ::dlclose(lib);
109 }
111 inline const int os::default_file_open_flags() { return 0;}
113 inline DIR* os::opendir(const char* dirname)
114 {
115 assert(dirname != NULL, "just checking");
116 return ::opendir(dirname);
117 }
119 inline int os::readdir_buf_size(const char *path)
120 {
121 return NAME_MAX + sizeof(dirent) + 1;
122 }
124 inline jlong os::lseek(int fd, jlong offset, int whence) {
125 return (jlong) ::lseek(fd, offset, whence);
126 }
128 inline int os::fsync(int fd) {
129 return ::fsync(fd);
130 }
132 inline char* os::native_path(char *path) {
133 return path;
134 }
136 inline int os::ftruncate(int fd, jlong length) {
137 return ::ftruncate(fd, length);
138 }
140 inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
141 {
142 dirent* p;
143 int status;
144 assert(dirp != NULL, "just checking");
146 // NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
147 // version. Here is the doc for this function:
148 // http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
150 if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
151 errno = status;
152 return NULL;
153 } else
154 return p;
155 }
157 inline int os::closedir(DIR *dirp) {
158 assert(dirp != NULL, "argument is NULL");
159 return ::closedir(dirp);
160 }
162 // macros for restartable system calls
164 #define RESTARTABLE(_cmd, _result) do { \
165 _result = _cmd; \
166 } while(((int)_result == OS_ERR) && (errno == EINTR))
168 #define RESTARTABLE_RETURN_INT(_cmd) do { \
169 int _result; \
170 RESTARTABLE(_cmd, _result); \
171 return _result; \
172 } while(false)
174 inline bool os::numa_has_static_binding() { return true; }
175 inline bool os::numa_has_group_homing() { return false; }
177 inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
178 size_t res;
179 RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
180 return res;
181 }
183 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
184 size_t res;
185 RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
186 return res;
187 }
189 inline int os::close(int fd) {
190 RESTARTABLE_RETURN_INT(::close(fd));
191 }
193 inline int os::socket_close(int fd) {
194 RESTARTABLE_RETURN_INT(::close(fd));
195 }
197 inline int os::socket(int domain, int type, int protocol) {
198 return ::socket(domain, type, protocol);
199 }
201 inline int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
202 RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, flags));
203 }
205 inline int os::send(int fd, char* buf, size_t nBytes, uint flags) {
206 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags));
207 }
209 inline int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) {
210 return os::send(fd, buf, nBytes, flags);
211 }
213 inline int os::timeout(int fd, long timeout) {
214 julong prevtime,newtime;
215 struct timeval t;
217 gettimeofday(&t, NULL);
218 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
220 for(;;) {
221 struct pollfd pfd;
223 pfd.fd = fd;
224 pfd.events = POLLIN | POLLERR;
226 int res = ::poll(&pfd, 1, timeout);
228 if (res == OS_ERR && errno == EINTR) {
230 // On Bsd any value < 0 means "forever"
232 if(timeout >= 0) {
233 gettimeofday(&t, NULL);
234 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
235 timeout -= newtime - prevtime;
236 if(timeout <= 0)
237 return OS_OK;
238 prevtime = newtime;
239 }
240 } else
241 return res;
242 }
243 }
245 inline int os::listen(int fd, int count) {
246 return ::listen(fd, count);
247 }
249 inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
250 RESTARTABLE_RETURN_INT(::connect(fd, him, len));
251 }
253 inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
254 // At least OpenBSD and FreeBSD can return EINTR from accept.
255 RESTARTABLE_RETURN_INT(::accept(fd, him, len));
256 }
258 inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
259 sockaddr* from, socklen_t* fromlen) {
260 RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
261 }
263 inline int os::sendto(int fd, char* buf, size_t len, uint flags,
264 struct sockaddr *to, socklen_t tolen) {
265 RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
266 }
268 inline int os::socket_shutdown(int fd, int howto) {
269 return ::shutdown(fd, howto);
270 }
272 inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
273 return ::bind(fd, him, len);
274 }
276 inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
277 return ::getsockname(fd, him, len);
278 }
280 inline int os::get_host_name(char* name, int namelen) {
281 return ::gethostname(name, namelen);
282 }
284 inline struct hostent* os::get_host_by_name(char* name) {
285 return ::gethostbyname(name);
286 }
288 inline int os::get_sock_opt(int fd, int level, int optname,
289 char *optval, socklen_t* optlen) {
290 return ::getsockopt(fd, level, optname, optval, optlen);
291 }
293 inline int os::set_sock_opt(int fd, int level, int optname,
294 const char* optval, socklen_t optlen) {
295 return ::setsockopt(fd, level, optname, optval, optlen);
296 }
297 #endif // OS_BSD_VM_OS_BSD_INLINE_HPP