1 /*
2 * Copyright (c) 1999, 2012, 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 *
241 julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
242 temp_limit = align_size_down_(temp_limit, min_allocation_size);
243 if (is_allocatable(temp_limit)) {
244 lower_limit = temp_limit;
245 } else {
246 upper_limit = temp_limit;
247 }
248 }
249 *limit = lower_limit;
250 }
251 return true;
252 #endif
253 }
254
255 const char* os::get_current_directory(char *buf, size_t buflen) {
256 return getcwd(buf, buflen);
257 }
258
259 FILE* os::open(int fd, const char* mode) {
260 return ::fdopen(fd, mode);
261 }
262
263 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
264 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
265 }
266
267 /*
268 * See the caveats for this class in os_posix.hpp
269 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
270 * method and returns false. If none of the signals are raised, returns true.
271 * The callback is supposed to provide the method that should be protected.
272 */
273 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
274 assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
275 assert(!WatcherThread::watcher_thread()->has_crash_protection(),
276 "crash_protection already set?");
277
278 if (sigsetjmp(_jmpbuf, 1) == 0) {
279 // make sure we can see in the signal handler that we have crash protection
280 // installed
|
1 /*
2 * Copyright (c) 1999, 2013, 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 *
241 julong temp_limit = ((upper_limit - lower_limit) / 2) + lower_limit;
242 temp_limit = align_size_down_(temp_limit, min_allocation_size);
243 if (is_allocatable(temp_limit)) {
244 lower_limit = temp_limit;
245 } else {
246 upper_limit = temp_limit;
247 }
248 }
249 *limit = lower_limit;
250 }
251 return true;
252 #endif
253 }
254
255 const char* os::get_current_directory(char *buf, size_t buflen) {
256 return getcwd(buf, buflen);
257 }
258
259 FILE* os::open(int fd, const char* mode) {
260 return ::fdopen(fd, mode);
261 }
262
263 void* os::getDefaultProcessHandle() {
264 return (void*)::dlopen(NULL, RTLD_LAZY);
265 }
266
267 char* os::buildAgentFunctionName(const char *symName, const char *name,
268 bool is_absolute_path) {
269 char *agentEntryName;
270 size_t len;
271 size_t nameLen;
272 size_t prefixLen = strlen(JNI_LIB_PREFIX);
273 size_t suffixLen = strlen(JNI_LIB_SUFFIX);
274 const char *start;
275
276 if (name != NULL) {
277 len = nameLen = strlen(name);
278 if (is_absolute_path) {
279 // Need to strip path, prefix and suffix
280 if ((start = strrchr(name, *os::file_separator())) != NULL) {
281 name = ++start;
282 }
283 if (len <= (prefixLen + suffixLen)) {
284 return NULL;
285 }
286 name += prefixLen;
287 nameLen = strlen(name) - suffixLen;
288 }
289 }
290 len = (name != NULL ? nameLen : 0) + strlen(symName) + 2;
291 agentEntryName = NEW_C_HEAP_ARRAY(char, len, mtThread);
292 if (agentEntryName == NULL) {
293 return NULL;
294 }
295 strcpy(agentEntryName, symName);
296 if (name != NULL) {
297 strcat(agentEntryName, "_");
298 strncat(agentEntryName, name, nameLen);
299 }
300 return agentEntryName;
301 }
302
303 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
304 assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");
305 }
306
307 /*
308 * See the caveats for this class in os_posix.hpp
309 * Protects the callback call so that SIGSEGV / SIGBUS jumps back into this
310 * method and returns false. If none of the signals are raised, returns true.
311 * The callback is supposed to provide the method that should be protected.
312 */
313 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
314 assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
315 assert(!WatcherThread::watcher_thread()->has_crash_protection(),
316 "crash_protection already set?");
317
318 if (sigsetjmp(_jmpbuf, 1) == 0) {
319 // make sure we can see in the signal handler that we have crash protection
320 // installed
|