8187443: Forest Consolidation: Move files to unified layout

Reviewed-by: darcy, ihse
This commit is contained in:
Erik Joelsson 2017-09-12 19:03:39 +02:00
parent 270fe13182
commit 3789983e89
56923 changed files with 3 additions and 15727 deletions

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "ProcessHandleImpl_unix.h"
#include <procfs.h>
/*
* Implementation of native ProcessHandleImpl functions for Solaris.
* See ProcessHandleImpl_unix.c for more details.
*/
void os_initNative(JNIEnv *env, jclass clazz) {}
jint os_getChildren(JNIEnv *env, jlong jpid, jlongArray jarray,
jlongArray jparentArray, jlongArray jstimesArray) {
return unix_getChildren(env, jpid, jarray, jparentArray, jstimesArray);
}
pid_t os_getParentPidAndTimings(JNIEnv *env, pid_t pid, jlong *total, jlong *start) {
return unix_getParentPidAndTimings(env, pid, total, start);
}
void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
unix_getCmdlineAndUserInfo(env, jinfo, pid);
}

View file

@ -0,0 +1,273 @@
/*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/* CopyrightVersion 1.2 */
/* This is a special library that should be loaded before libc &
* libthread to interpose the signal handler installation functions:
* sigaction(), signal(), sigset().
* Used for signal-chaining. See RFE 4381843.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <dlfcn.h>
#include <thread.h>
#include <synch.h>
#include "jvm_solaris.h"
#define bool int
#define true 1
#define false 0
static struct sigaction *sact = (struct sigaction *)NULL; /* saved signal handlers */
static sigset_t jvmsigs;
/* used to synchronize the installation of signal handlers */
static mutex_t mutex = DEFAULTMUTEX;
static cond_t cond = DEFAULTCV;
static thread_t tid = 0;
typedef void (*sa_handler_t)(int);
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
typedef sa_handler_t (*signal_t)(int, sa_handler_t);
typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
static signal_t os_signal = 0; /* os's version of signal()/sigset() */
static sigaction_t os_sigaction = 0; /* os's version of sigaction() */
static bool jvm_signal_installing = false;
static bool jvm_signal_installed = false;
/* assume called within signal_lock */
static void allocate_sact() {
size_t maxsignum;
maxsignum = SIGRTMAX;
if (sact == NULL) {
sact = (struct sigaction *)malloc((maxsignum+1) * (size_t)sizeof(struct sigaction));
memset(sact, 0, (maxsignum+1) * (size_t)sizeof(struct sigaction));
}
if (sact == NULL) {
printf("%s\n", "libjsig.so unable to allocate memory");
exit(0);
}
sigemptyset(&jvmsigs);
}
static void signal_lock() {
mutex_lock(&mutex);
/* When the jvm is installing its set of signal handlers, threads
* other than the jvm thread should wait */
if (jvm_signal_installing) {
if (tid != thr_self()) {
cond_wait(&cond, &mutex);
}
}
}
static void signal_unlock() {
mutex_unlock(&mutex);
}
static sa_handler_t call_os_signal(int sig, sa_handler_t disp,
bool is_sigset) {
if (os_signal == NULL) {
if (!is_sigset) {
os_signal = (signal_t)dlsym(RTLD_NEXT, "signal");
} else {
os_signal = (signal_t)dlsym(RTLD_NEXT, "sigset");
}
if (os_signal == NULL) {
printf("%s\n", dlerror());
exit(0);
}
}
return (*os_signal)(sig, disp);
}
static void save_signal_handler(int sig, sa_handler_t disp, bool is_sigset) {
sigset_t set;
if (sact == NULL) {
allocate_sact();
}
sact[sig].sa_handler = disp;
sigemptyset(&set);
sact[sig].sa_mask = set;
if (!is_sigset) {
sact[sig].sa_flags = SA_NODEFER;
if (sig != SIGILL && sig != SIGTRAP && sig != SIGPWR) {
sact[sig].sa_flags |= SA_RESETHAND;
}
} else {
sact[sig].sa_flags = 0;
}
}
static sa_handler_t set_signal(int sig, sa_handler_t disp, bool is_sigset) {
sa_handler_t oldhandler;
bool sigblocked;
signal_lock();
if (sact == NULL) {
allocate_sact();
}
if (jvm_signal_installed && sigismember(&jvmsigs, sig)) {
/* jvm has installed its signal handler for this signal. */
/* Save the handler. Don't really install it. */
if (is_sigset) {
/* We won't honor the SIG_HOLD request to change the signal mask */
sigblocked = sigismember(&(sact[sig].sa_mask), sig);
}
oldhandler = sact[sig].sa_handler;
save_signal_handler(sig, disp, is_sigset);
if (is_sigset && sigblocked) {
oldhandler = SIG_HOLD;
}
signal_unlock();
return oldhandler;
} else if (jvm_signal_installing) {
/* jvm is installing its signal handlers. Install the new
* handlers and save the old ones. jvm uses sigaction().
* Leave the piece here just in case. */
oldhandler = call_os_signal(sig, disp, is_sigset);
save_signal_handler(sig, oldhandler, is_sigset);
/* Record the signals used by jvm */
sigaddset(&jvmsigs, sig);
signal_unlock();
return oldhandler;
} else {
/* jvm has no relation with this signal (yet). Install the
* the handler. */
oldhandler = call_os_signal(sig, disp, is_sigset);
signal_unlock();
return oldhandler;
}
}
sa_handler_t signal(int sig, sa_handler_t disp) {
return set_signal(sig, disp, false);
}
sa_handler_t sigset(int sig, sa_handler_t disp) {
return set_signal(sig, disp, true);
}
static int call_os_sigaction(int sig, const struct sigaction *act,
struct sigaction *oact) {
if (os_sigaction == NULL) {
os_sigaction = (sigaction_t)dlsym(RTLD_NEXT, "sigaction");
if (os_sigaction == NULL) {
printf("%s\n", dlerror());
exit(0);
}
}
return (*os_sigaction)(sig, act, oact);
}
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
int res;
struct sigaction oldAct;
signal_lock();
if (sact == NULL ) {
allocate_sact();
}
if (jvm_signal_installed && sigismember(&jvmsigs, sig)) {
/* jvm has installed its signal handler for this signal. */
/* Save the handler. Don't really install it. */
if (oact != NULL) {
*oact = sact[sig];
}
if (act != NULL) {
sact[sig] = *act;
}
signal_unlock();
return 0;
} else if (jvm_signal_installing) {
/* jvm is installing its signal handlers. Install the new
* handlers and save the old ones. */
res = call_os_sigaction(sig, act, &oldAct);
sact[sig] = oldAct;
if (oact != NULL) {
*oact = oldAct;
}
/* Record the signals used by jvm */
sigaddset(&jvmsigs, sig);
signal_unlock();
return res;
} else {
/* jvm has no relation with this signal (yet). Install the
* the handler. */
res = call_os_sigaction(sig, act, oact);
signal_unlock();
return res;
}
}
/* The four functions for the jvm to call into */
void JVM_begin_signal_setting() {
signal_lock();
jvm_signal_installing = true;
tid = thr_self();
signal_unlock();
}
void JVM_end_signal_setting() {
signal_lock();
jvm_signal_installed = true;
jvm_signal_installing = false;
cond_broadcast(&cond);
signal_unlock();
}
struct sigaction *JVM_get_signal_action(int sig) {
if (sact == NULL) {
allocate_sact();
}
/* Does race condition make sense here? */
if (sigismember(&jvmsigs, sig)) {
return &sact[sig];
}
return NULL;
}
int JVM_get_libjsig_version() {
return JSIG_VERSION_1_4_1;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef OS_SOLARIS_DTRACE_LIBJVM_DB_H
#define OS_SOLARIS_DTRACE_LIBJVM_DB_H
#include <proc_service.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct jvm_agent jvm_agent_t;
#define JVM_DB_VERSION 1
jvm_agent_t *Jagent_create(struct ps_prochandle *P, int vers);
/*
* Called from Jframe_iter() for each java frame. If it returns 0, then
* Jframe_iter() proceeds to the next frame. Otherwise, the return value is
* immediately returned to the caller of Jframe_iter().
*
* Parameters:
* 'cld' is client supplied data (to maintain iterator state, if any).
* 'name' is java method name.
* 'bci' is byte code index. it will be -1 if not available.
* 'line' is java source line number. it will be 0 if not available.
* 'handle' is an abstract client handle, reserved for future expansions
*/
typedef int java_stack_f(void *cld, const prgregset_t regs, const char* name, int bci, int line, void *handle);
/*
* Iterates over the java frames at the current location. Returns -1 if no java
* frames were found, or if there was some unrecoverable error. Otherwise,
* returns the last value returned from 'func'.
*/
int Jframe_iter(jvm_agent_t *agent, prgregset_t gregs, java_stack_f *func, void* cld);
void Jagent_destroy(jvm_agent_t *J);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif // OS_SOLARIS_DTRACE_LIBJVM_DB_H

View file

@ -0,0 +1,562 @@
/*
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include <door.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <thread.h>
#include <unistd.h>
#include "jvm_dtrace.h"
// NOTE: These constants are used in JVM code as well.
// KEEP JVM CODE IN SYNC if you are going to change these...
#define DTRACE_ALLOC_PROBES 0x1
#define DTRACE_METHOD_PROBES 0x2
#define DTRACE_MONITOR_PROBES 0x4
#define DTRACE_ALL_PROBES -1
// generic error messages
#define JVM_ERR_OUT_OF_MEMORY "out of memory (native heap)"
#define JVM_ERR_INVALID_PARAM "invalid input parameter(s)"
#define JVM_ERR_NULL_PARAM "input paramater is NULL"
// error messages for attach
#define JVM_ERR_CANT_OPEN_DOOR "cannot open door file"
#define JVM_ERR_CANT_CREATE_ATTACH_FILE "cannot create attach file"
#define JVM_ERR_DOOR_FILE_PERMISSION "door file is not secure"
#define JVM_ERR_CANT_SIGNAL "cannot send SIGQUIT to target"
// error messages for enable probe
#define JVM_ERR_DOOR_CMD_SEND "door command send failed"
#define JVM_ERR_DOOR_CANT_READ_STATUS "cannot read door command status"
#define JVM_ERR_DOOR_CMD_STATUS "door command error status"
// error message for detach
#define JVM_ERR_CANT_CLOSE_DOOR "cannot close door file"
#define RESTARTABLE(_cmd, _result) do { \
do { \
_result = _cmd; \
} while((_result == -1) && (errno == EINTR)); \
} while(0)
struct _jvm_t {
pid_t pid;
int door_fd;
};
static int libjvm_dtrace_debug;
static void print_debug(const char* fmt,...) {
if (libjvm_dtrace_debug) {
va_list alist;
va_start(alist, fmt);
fputs("libjvm_dtrace DEBUG: ", stderr);
vfprintf(stderr, fmt, alist);
va_end(alist);
}
}
/* Key for thread local error message */
static thread_key_t jvm_error_key;
/* init function for this library */
static void init_jvm_dtrace() {
/* check for env. var for debug mode */
libjvm_dtrace_debug = getenv("LIBJVM_DTRACE_DEBUG") != NULL;
/* create key for thread local error message */
if (thr_keycreate(&jvm_error_key, NULL) != 0) {
print_debug("can't create thread_key_t for jvm error key\n");
// exit(1); ?
}
}
#pragma init(init_jvm_dtrace)
/* set thread local error message */
static void set_jvm_error(const char* msg) {
thr_setspecific(jvm_error_key, (void*)msg);
}
/* clear thread local error message */
static void clear_jvm_error() {
thr_setspecific(jvm_error_key, NULL);
}
/* file handling functions that can handle interrupt */
static int file_open(const char* path, int flag) {
int ret;
RESTARTABLE(open(path, flag), ret);
return ret;
}
static int file_close(int fd) {
return close(fd);
}
static int file_read(int fd, char* buf, int len) {
int ret;
RESTARTABLE(read(fd, buf, len), ret);
return ret;
}
/* send SIGQUIT signal to given process */
static int send_sigquit(pid_t pid) {
int ret;
RESTARTABLE(kill(pid, SIGQUIT), ret);
return ret;
}
/* called to check permissions on attach file */
static int check_permission(const char* path) {
struct stat64 sb;
uid_t uid, gid;
int res;
/*
* Check that the path is owned by the effective uid/gid of this
* process. Also check that group/other access is not allowed.
*/
uid = geteuid();
gid = getegid();
res = stat64(path, &sb);
if (res != 0) {
print_debug("stat failed for %s\n", path);
return -1;
}
if ((sb.st_uid != uid) || (sb.st_gid != gid) ||
((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0)) {
print_debug("well-known file %s is not secure\n", path);
return -1;
}
return 0;
}
#define ATTACH_FILE_PATTERN "/tmp/.attach_pid%d"
/* fill-in the name of attach file name in given buffer */
static void fill_attach_file_name(char* path, int len, pid_t pid) {
memset(path, 0, len);
sprintf(path, ATTACH_FILE_PATTERN, pid);
}
#define DOOR_FILE_PATTERN "/tmp/.java_pid%d"
/* open door file for the given JVM */
static int open_door(pid_t pid) {
char path[PATH_MAX + 1];
int fd;
sprintf(path, DOOR_FILE_PATTERN, pid);
fd = file_open(path, O_RDONLY);
if (fd < 0) {
set_jvm_error(JVM_ERR_CANT_OPEN_DOOR);
print_debug("cannot open door file %s\n", path);
return -1;
}
print_debug("opened door file %s\n", path);
if (check_permission(path) != 0) {
set_jvm_error(JVM_ERR_DOOR_FILE_PERMISSION);
print_debug("check permission failed for %s\n", path);
file_close(fd);
fd = -1;
}
return fd;
}
/* create attach file for given process */
static int create_attach_file(pid_t pid) {
char path[PATH_MAX + 1];
int fd;
fill_attach_file_name(path, sizeof(path), pid);
fd = file_open(path, O_CREAT | O_RDWR);
if (fd < 0) {
set_jvm_error(JVM_ERR_CANT_CREATE_ATTACH_FILE);
print_debug("cannot create file %s\n", path);
} else {
print_debug("created attach file %s\n", path);
}
return fd;
}
/* delete attach file for given process */
static void delete_attach_file(pid_t pid) {
char path[PATH_MAX + 1];
fill_attach_file_name(path, sizeof(path), pid);
int res = unlink(path);
if (res) {
print_debug("cannot delete attach file %s\n", path);
} else {
print_debug("deleted attach file %s\n", path);
}
}
/* attach to given JVM */
jvm_t* jvm_attach(pid_t pid) {
jvm_t* jvm;
int door_fd, attach_fd, i = 0;
jvm = (jvm_t*) calloc(1, sizeof(jvm_t));
if (jvm == NULL) {
set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
print_debug("calloc failed in %s at %d\n", __FILE__, __LINE__);
return NULL;
}
jvm->pid = pid;
attach_fd = -1;
door_fd = open_door(pid);
if (door_fd < 0) {
print_debug("trying to create attach file\n");
if ((attach_fd = create_attach_file(pid)) < 0) {
goto quit;
}
/* send QUIT signal to the target so that it will
* check for the attach file.
*/
if (send_sigquit(pid) != 0) {
set_jvm_error(JVM_ERR_CANT_SIGNAL);
print_debug("sending SIGQUIT failed\n");
goto quit;
}
/* give the target VM time to start the attach mechanism */
do {
int res;
RESTARTABLE(poll(0, 0, 200), res);
door_fd = open_door(pid);
i++;
} while (i <= 50 && door_fd == -1);
if (door_fd < 0) {
print_debug("Unable to open door to process %d\n", pid);
goto quit;
}
}
quit:
if (attach_fd >= 0) {
file_close(attach_fd);
delete_attach_file(jvm->pid);
}
if (door_fd >= 0) {
jvm->door_fd = door_fd;
clear_jvm_error();
} else {
free(jvm);
jvm = NULL;
}
return jvm;
}
/* return the last thread local error message */
const char* jvm_get_last_error() {
const char* res = NULL;
thr_getspecific(jvm_error_key, (void**)&res);
return res;
}
/* detach the givenb JVM */
int jvm_detach(jvm_t* jvm) {
if (jvm) {
int res = 0;
if (jvm->door_fd != -1) {
if (file_close(jvm->door_fd) != 0) {
set_jvm_error(JVM_ERR_CANT_CLOSE_DOOR);
res = -1;
} else {
clear_jvm_error();
}
}
free(jvm);
return res;
} else {
set_jvm_error(JVM_ERR_NULL_PARAM);
print_debug("jvm_t* is NULL\n");
return -1;
}
}
/*
* A simple table to translate some known errors into reasonable
* error messages
*/
static struct {
int err;
const char* msg;
} const error_messages[] = {
{ 100, "Bad request" },
{ 101, "Protocol mismatch" },
{ 102, "Resource failure" },
{ 103, "Internal error" },
{ 104, "Permission denied" },
};
/*
* Lookup the given error code and return the appropriate
* message. If not found return NULL.
*/
static const char* translate_error(int err) {
int table_size = sizeof(error_messages) / sizeof(error_messages[0]);
int i;
for (i=0; i<table_size; i++) {
if (err == error_messages[i].err) {
return error_messages[i].msg;
}
}
return NULL;
}
/*
* Current protocol version
*/
static const char* PROTOCOL_VERSION = "1";
#define RES_BUF_SIZE 128
/*
* Enqueue attach-on-demand command to the given JVM
*/
static
int enqueue_command(jvm_t* jvm, const char* cstr, int arg_count, const char** args) {
size_t size;
door_arg_t door_args;
char res_buffer[RES_BUF_SIZE];
int rc, i;
char* buf = NULL;
int result = -1;
/*
* First we get the command string and create the start of the
* argument string to send to the target VM:
* <ver>\0<cmd>\0
*/
if (cstr == NULL) {
print_debug("command name is NULL\n");
goto quit;
}
size = strlen(PROTOCOL_VERSION) + strlen(cstr) + 2;
buf = (char*)malloc(size);
if (buf != NULL) {
char* pos = buf;
strcpy(buf, PROTOCOL_VERSION);
pos += strlen(PROTOCOL_VERSION)+1;
strcpy(pos, cstr);
} else {
set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
print_debug("malloc failed at %d in %s\n", __LINE__, __FILE__);
goto quit;
}
/*
* Next we iterate over the arguments and extend the buffer
* to include them.
*/
for (i=0; i<arg_count; i++) {
cstr = args[i];
if (cstr != NULL) {
size_t len = strlen(cstr);
char* newbuf = (char*)realloc(buf, size+len+1);
if (newbuf == NULL) {
set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
print_debug("realloc failed in %s at %d\n", __FILE__, __LINE__);
goto quit;
}
buf = newbuf;
strcpy(buf+size, cstr);
size += len+1;
}
}
/*
* The arguments to the door function are in 'buf' so we now
* do the door call
*/
door_args.data_ptr = buf;
door_args.data_size = size;
door_args.desc_ptr = NULL;
door_args.desc_num = 0;
door_args.rbuf = (char*)&res_buffer;
door_args.rsize = sizeof(res_buffer);
RESTARTABLE(door_call(jvm->door_fd, &door_args), rc);
/*
* door_call failed
*/
if (rc == -1) {
print_debug("door_call failed\n");
} else {
/*
* door_call succeeded but the call didn't return the the expected jint.
*/
if (door_args.data_size < sizeof(int)) {
print_debug("Enqueue error - reason unknown as result is truncated!");
} else {
int* res = (int*)(door_args.data_ptr);
if (*res != 0) {
const char* msg = translate_error(*res);
if (msg == NULL) {
print_debug("Unable to enqueue command to target VM: %d\n", *res);
} else {
print_debug("Unable to enqueue command to target VM: %s\n", msg);
}
} else {
/*
* The door call should return a file descriptor to one end of
* a socket pair
*/
if ((door_args.desc_ptr != NULL) &&
(door_args.desc_num == 1) &&
(door_args.desc_ptr->d_attributes & DOOR_DESCRIPTOR)) {
result = door_args.desc_ptr->d_data.d_desc.d_descriptor;
} else {
print_debug("Reply from enqueue missing descriptor!\n");
}
}
}
}
quit:
if (buf) free(buf);
return result;
}
/* read status code for a door command */
static int read_status(int fd) {
char ch, buf[16];
int index = 0;
while (1) {
if (file_read(fd, &ch, sizeof(ch)) != sizeof(ch)) {
set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
print_debug("door cmd status: read status failed\n");
return -1;
}
buf[index++] = ch;
if (ch == '\n') {
buf[index - 1] = '\0';
return atoi(buf);
}
if (index == sizeof(buf)) {
set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
print_debug("door cmd status: read status overflow\n");
return -1;
}
}
}
static const char* ENABLE_DPROBES_CMD = "enabledprobes";
/* enable one or more DTrace probes for a given JVM */
int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types) {
int fd, status = 0;
char ch;
const char* args[1];
char buf[16];
int probe_type = 0, index;
int count = 0;
if (jvm == NULL) {
set_jvm_error(JVM_ERR_NULL_PARAM);
print_debug("jvm_t* is NULL\n");
return -1;
}
if (num_probe_types == 0 || probe_types == NULL ||
probe_types[0] == NULL) {
set_jvm_error(JVM_ERR_INVALID_PARAM);
print_debug("invalid probe type argument(s)\n");
return -1;
}
for (index = 0; index < num_probe_types; index++) {
const char* p = probe_types[index];
if (strcmp(p, JVM_DTPROBE_OBJECT_ALLOC) == 0) {
probe_type |= DTRACE_ALLOC_PROBES;
count++;
} else if (strcmp(p, JVM_DTPROBE_METHOD_ENTRY) == 0 ||
strcmp(p, JVM_DTPROBE_METHOD_RETURN) == 0) {
probe_type |= DTRACE_METHOD_PROBES;
count++;
} else if (strcmp(p, JVM_DTPROBE_MONITOR_ENTER) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_ENTERED) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_EXIT) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_WAIT) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_WAITED) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_NOTIFY) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_NOTIFYALL) == 0) {
probe_type |= DTRACE_MONITOR_PROBES;
count++;
} else if (strcmp(p, JVM_DTPROBE_ALL) == 0) {
probe_type |= DTRACE_ALL_PROBES;
count++;
}
}
if (count == 0) {
return count;
}
sprintf(buf, "%d", probe_type);
args[0] = buf;
fd = enqueue_command(jvm, ENABLE_DPROBES_CMD, 1, args);
if (fd < 0) {
set_jvm_error(JVM_ERR_DOOR_CMD_SEND);
return -1;
}
status = read_status(fd);
// non-zero status is error
if (status) {
set_jvm_error(JVM_ERR_DOOR_CMD_STATUS);
print_debug("%s command failed (status: %d) in target JVM\n",
ENABLE_DPROBES_CMD, status);
file_close(fd);
return -1;
}
// read from stream until EOF
while (file_read(fd, &ch, sizeof(ch)) == sizeof(ch)) {
if (libjvm_dtrace_debug) {
printf("%c", ch);
}
}
file_close(fd);
clear_jvm_error();
return count;
}

View file

@ -0,0 +1,86 @@
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef _JVM_DTRACE_H_
#define _JVM_DTRACE_H_
/*
* Interface to dynamically turn on probes in Hotspot JVM. Currently,
* this interface can be used to dynamically enable certain DTrace
* probe points that are costly to have "always on".
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
struct _jvm_t;
typedef struct _jvm_t jvm_t;
/* Attach to the given JVM process. Returns NULL on failure.
jvm_get_last_error() returns last error message. */
jvm_t* jvm_attach(pid_t pid);
/* Returns the last error message from this library or NULL if none. */
const char* jvm_get_last_error();
/* few well-known probe type constants for 'probe_types' param below */
#define JVM_DTPROBE_METHOD_ENTRY "method-entry"
#define JVM_DTPROBE_METHOD_RETURN "method-return"
#define JVM_DTPROBE_MONITOR_ENTER "monitor-contended-enter"
#define JVM_DTPROBE_MONITOR_ENTERED "monitor-contended-entered"
#define JVM_DTPROBE_MONITOR_EXIT "monitor-contended-exit"
#define JVM_DTPROBE_MONITOR_WAIT "monitor-wait"
#define JVM_DTPROBE_MONITOR_WAITED "monitor-waited"
#define JVM_DTPROBE_MONITOR_NOTIFY "monitor-notify"
#define JVM_DTPROBE_MONITOR_NOTIFYALL "monitor-notifyall"
#define JVM_DTPROBE_OBJECT_ALLOC "object-alloc"
#define JVM_DTPROBE_ALL "*"
/* Enable the specified DTrace probes of given probe types on
* the specified JVM. Returns >= 0 on success, -1 on failure.
* On success, this returns number of probe_types enabled.
* On failure, jvm_get_last_error() returns the last error message.
*/
int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types);
/* Note: There is no jvm_disable_dtprobes function. Probes are automatically
* disabled when there are no more clients requiring those probes.
*/
/* Detach the given JVM. Returns 0 on success, -1 on failure.
* jvm_get_last_error() returns the last error message.
*/
int jvm_detach(jvm_t* jvm);
#ifdef __cplusplus
}
#endif
#endif /* _JVM_DTRACE_H_ */

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <errno.h>
#include <sys/socket.h>
#include <stropts.h>
#include <unistd.h>
#include "jvm.h"
#include "net_util.h"
/* Support for restartable system calls on Solaris. */
#define RESTARTABLE_RETURN_INT(_cmd) do { \
int _result; \
if (1) { \
do { \
_result = _cmd; \
} while((_result == -1) && (errno == EINTR)); \
return _result; \
} \
} while(0)
int NET_Read(int s, void* buf, size_t len) {
RESTARTABLE_RETURN_INT(recv(s, buf, len, 0));
}
int NET_NonBlockingRead(int s, void* buf, size_t len) {
RESTARTABLE_RETURN_INT(recv(s, buf, len, MSG_DONTWAIT));
}
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
struct sockaddr *from, socklen_t *fromlen) {
RESTARTABLE_RETURN_INT(recvfrom(s, buf, len, flags, from, fromlen));
}
int NET_ReadV(int s, const struct iovec * vector, int count) {
RESTARTABLE_RETURN_INT(readv(s, vector, count));
}
int NET_WriteV(int s, const struct iovec * vector, int count) {
RESTARTABLE_RETURN_INT(writev(s, vector, count));
}
int NET_Send(int s, void *msg, int len, unsigned int flags) {
RESTARTABLE_RETURN_INT(send(s, msg, len, flags));
}
int NET_SendTo(int s, const void *msg, int len, unsigned int flags,
const struct sockaddr *to, int tolen) {
RESTARTABLE_RETURN_INT(sendto(s, msg, len, flags, to, tolen));
}
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
RESTARTABLE_RETURN_INT(connect(s, addr, addrlen));
}
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
RESTARTABLE_RETURN_INT(accept(s, addr, addrlen));
}
int NET_SocketClose(int fd) {
return close(fd);
}
int NET_Dup2(int fd, int fd2) {
return dup2(fd, fd2);
}
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout));
}
int NET_Timeout(JNIEnv *env, int s, long timeout, jlong nanoTimeStamp) {
int result;
jlong prevNanoTime = nanoTimeStamp;
jlong nanoTimeout = (jlong) timeout * NET_NSEC_PER_MSEC;
struct pollfd pfd;
pfd.fd = s;
pfd.events = POLLIN;
for(;;) {
result = poll(&pfd, 1, nanoTimeout / NET_NSEC_PER_MSEC);
if (result < 0 && errno == EINTR) {
jlong newNanoTime = JVM_NanoTime(env, 0);
nanoTimeout -= newNanoTime - prevNanoTime;
if (nanoTimeout < NET_NSEC_PER_MSEC)
return 0;
prevNanoTime = newNanoTime;
} else {
return result;
}
}
}

View file

@ -0,0 +1,189 @@
/*
* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jlong.h"
#include "sun_nio_ch_DevPollArrayWrapper.h"
#include <poll.h>
#include <unistd.h>
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef uint32_t caddr32_t;
/* /dev/poll ioctl */
#define DPIOC (0xD0 << 8)
#define DP_POLL (DPIOC | 1) /* poll on fds in cached in /dev/poll */
#define DP_ISPOLLED (DPIOC | 2) /* is this fd cached in /dev/poll */
#define DEVPOLLSIZE 1000 /* /dev/poll table size increment */
#define POLLREMOVE 0x0800 /* Removes fd from monitored set */
/*
* /dev/poll DP_POLL ioctl format
*/
typedef struct dvpoll {
pollfd_t *dp_fds; /* pollfd array */
nfds_t dp_nfds; /* num of pollfd's in dp_fds[] */
int dp_timeout; /* time out in millisec */
} dvpoll_t;
typedef struct dvpoll32 {
caddr32_t dp_fds; /* pollfd array */
uint32_t dp_nfds; /* num of pollfd's in dp_fds[] */
int32_t dp_timeout; /* time out in millisec */
} dvpoll32_t;
#ifdef __cplusplus
}
#endif
#define RESTARTABLE(_cmd, _result) do { \
do { \
_result = _cmd; \
} while((_result == -1) && (errno == EINTR)); \
} while(0)
static int
idevpoll(jint wfd, int dpctl, struct dvpoll a)
{
jlong start, now;
int remaining = a.dp_timeout;
struct timeval t;
int diff;
gettimeofday(&t, NULL);
start = t.tv_sec * 1000 + t.tv_usec / 1000;
for (;;) {
/* poll(7d) ioctl does not return remaining count */
int res = ioctl(wfd, dpctl, &a);
if (res < 0 && errno == EINTR) {
if (remaining >= 0) {
gettimeofday(&t, NULL);
now = t.tv_sec * 1000 + t.tv_usec / 1000;
diff = now - start;
remaining -= diff;
if (diff < 0 || remaining <= 0) {
return 0;
}
start = now;
a.dp_timeout = remaining;
}
} else {
return res;
}
}
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_DevPollArrayWrapper_init(JNIEnv *env, jobject this)
{
int wfd = open("/dev/poll", O_RDWR);
if (wfd < 0) {
JNU_ThrowIOExceptionWithLastError(env, "Error opening driver");
return -1;
}
return wfd;
}
JNIEXPORT void JNICALL
Java_sun_nio_ch_DevPollArrayWrapper_register(JNIEnv *env, jobject this,
jint wfd, jint fd, jint mask)
{
struct pollfd a[1];
int n;
a[0].fd = fd;
a[0].events = mask;
a[0].revents = 0;
n = write(wfd, &a[0], sizeof(a));
if (n != sizeof(a)) {
if (n < 0) {
JNU_ThrowIOExceptionWithLastError(env, "Error writing pollfds");
} else {
JNU_ThrowIOException(env, "Unexpected number of bytes written");
}
}
}
JNIEXPORT void JNICALL
Java_sun_nio_ch_DevPollArrayWrapper_registerMultiple(JNIEnv *env, jobject this,
jint wfd, jlong address,
jint len)
{
unsigned char *pollBytes = (unsigned char *)jlong_to_ptr(address);
unsigned char *pollEnd = pollBytes + sizeof(struct pollfd) * len;
while (pollBytes < pollEnd) {
int bytesWritten = write(wfd, pollBytes, (int)(pollEnd - pollBytes));
if (bytesWritten < 0) {
JNU_ThrowIOExceptionWithLastError(env, "Error writing pollfds");
return;
}
pollBytes += bytesWritten;
}
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_DevPollArrayWrapper_poll0(JNIEnv *env, jobject this,
jlong address, jint numfds,
jlong timeout, jint wfd)
{
struct dvpoll a;
void *pfd = (void *) jlong_to_ptr(address);
int result = 0;
a.dp_fds = pfd;
a.dp_nfds = numfds;
a.dp_timeout = (int)timeout;
if (timeout <= 0) { /* Indefinite or no wait */
RESTARTABLE (ioctl(wfd, DP_POLL, &a), result);
} else { /* Bounded wait; bounded restarts */
result = idevpoll(wfd, DP_POLL, a);
}
if (result < 0) {
JNU_ThrowIOExceptionWithLastError(env, "Error reading driver");
return -1;
}
return result;
}
JNIEXPORT void JNICALL
Java_sun_nio_ch_DevPollArrayWrapper_interrupt(JNIEnv *env, jclass this, jint fd)
{
int fakebuf[1];
fakebuf[0] = 1;
if (write(fd, fakebuf, 1) < 0) {
JNU_ThrowIOExceptionWithLastError(env,
"Write to interrupt fd failed");
}
}

View file

@ -0,0 +1,134 @@
/*
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jlong.h"
#include "nio_util.h"
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <port.h>
#include "sun_nio_ch_SolarisEventPort.h"
JNIEXPORT jint JNICALL
Java_sun_nio_ch_SolarisEventPort_port_1create
(JNIEnv* env, jclass clazz)
{
int port = port_create();
if (port == -1) {
JNU_ThrowIOExceptionWithLastError(env, "port_create");
}
return (jint)port;
}
JNIEXPORT void JNICALL
Java_sun_nio_ch_SolarisEventPort_port_1close
(JNIEnv* env, jclass clazz, jint port)
{
int res;
RESTARTABLE(close(port), res);
}
JNIEXPORT jboolean JNICALL
Java_sun_nio_ch_SolarisEventPort_port_1associate
(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events)
{
uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
if (port_associate((int)port, (int)source, object, (int)events, NULL) == 0) {
return JNI_TRUE;
} else {
if (errno != EBADFD)
JNU_ThrowIOExceptionWithLastError(env, "port_associate");
return JNI_FALSE;
}
}
JNIEXPORT jboolean JNICALL
Java_sun_nio_ch_SolarisEventPort_port_1dissociate
(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress)
{
uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
if (port_dissociate((int)port, (int)source, object) == 0) {
return JNI_TRUE;
} else {
if (errno != ENOENT)
JNU_ThrowIOExceptionWithLastError(env, "port_dissociate");
return JNI_FALSE;
}
}
JNIEXPORT void JNICALL
Java_sun_nio_ch_SolarisEventPort_port_1send(JNIEnv* env, jclass clazz,
jint port, jint events)
{
if (port_send((int)port, (int)events, NULL) == -1) {
JNU_ThrowIOExceptionWithLastError(env, "port_send");
}
}
JNIEXPORT void JNICALL
Java_sun_nio_ch_SolarisEventPort_port_1get(JNIEnv* env, jclass clazz,
jint port, jlong eventAddress)
{
int res;
port_event_t* ev = (port_event_t*)jlong_to_ptr(eventAddress);
RESTARTABLE(port_get((int)port, ev, NULL), res);
if (res == -1) {
JNU_ThrowIOExceptionWithLastError(env, "port_get");
}
}
JNIEXPORT jint JNICALL
Java_sun_nio_ch_SolarisEventPort_port_1getn(JNIEnv* env, jclass clazz,
jint port, jlong arrayAddress, jint max, jlong timeout)
{
int res;
uint_t n = 1;
port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress);
timespec_t ts;
timespec_t* tsp;
if (timeout >= 0L) {
ts.tv_sec = timeout / 1000;
ts.tv_nsec = 1000000 * (timeout % 1000);
tsp = &ts;
} else {
tsp = NULL;
}
res = port_getn((int)port, list, (uint_t)max, &n, tsp);
if (res == -1) {
if (errno != ETIME && errno != EINTR)
JNU_ThrowIOExceptionWithLastError(env, "port_getn");
}
return (jint)n;
}

View file

@ -0,0 +1,143 @@
/*
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jlong.h"
#include <strings.h>
#include <errno.h>
#include <sys/acl.h>
#include <sys/mnttab.h>
#include <sys/mkdev.h>
#include "jni.h"
#include "sun_nio_fs_SolarisNativeDispatcher.h"
static jfieldID entry_name;
static jfieldID entry_dir;
static jfieldID entry_fstype;
static jfieldID entry_options;
static jfieldID entry_dev;
static void throwUnixException(JNIEnv* env, int errnum) {
jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
"(I)V", errnum);
if (x != NULL) {
(*env)->Throw(env, x);
}
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_SolarisNativeDispatcher_init(JNIEnv *env, jclass clazz) {
clazz = (*env)->FindClass(env, "sun/nio/fs/UnixMountEntry");
CHECK_NULL(clazz);
entry_name = (*env)->GetFieldID(env, clazz, "name", "[B");
CHECK_NULL(entry_name);
entry_dir = (*env)->GetFieldID(env, clazz, "dir", "[B");
CHECK_NULL(entry_dir);
entry_fstype = (*env)->GetFieldID(env, clazz, "fstype", "[B");
CHECK_NULL(entry_fstype);
entry_options = (*env)->GetFieldID(env, clazz, "opts", "[B");
CHECK_NULL(entry_options);
entry_dev = (*env)->GetFieldID(env, clazz, "dev", "J");
CHECK_NULL(entry_dev);
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_SolarisNativeDispatcher_facl(JNIEnv* env, jclass this, jint fd,
jint cmd, jint nentries, jlong address)
{
void* aclbufp = jlong_to_ptr(address);
int n = -1;
n = facl((int)fd, (int)cmd, (int)nentries, aclbufp);
if (n == -1) {
throwUnixException(env, errno);
}
return (jint)n;
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_SolarisNativeDispatcher_getextmntent(JNIEnv* env, jclass this,
jlong value, jobject entry)
{
struct extmnttab ent;
FILE* fp = jlong_to_ptr(value);
jsize len;
jbyteArray bytes;
char* name;
char* dir;
char* fstype;
char* options;
dev_t dev;
if (getextmntent(fp, &ent, 0))
return -1;
name = ent.mnt_special;
dir = ent.mnt_mountp;
fstype = ent.mnt_fstype;
options = ent.mnt_mntopts;
dev = makedev(ent.mnt_major, ent.mnt_minor);
if (dev == NODEV) {
throwUnixException(env, errno);
return -1;
}
len = strlen(name);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)name);
(*env)->SetObjectField(env, entry, entry_name, bytes);
len = strlen(dir);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)dir);
(*env)->SetObjectField(env, entry, entry_dir, bytes);
len = strlen(fstype);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)fstype);
(*env)->SetObjectField(env, entry, entry_fstype, bytes);
len = strlen(options);
bytes = (*env)->NewByteArray(env, len);
if (bytes == NULL)
return -1;
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte*)options);
(*env)->SetObjectField(env, entry, entry_options, bytes);
if (dev != 0)
(*env)->SetLongField(env, entry, entry_dev, (jlong)dev);
return 0;
}

View file

@ -0,0 +1,104 @@
/*
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jlong.h"
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <port.h> // Solaris 10
#include "sun_nio_fs_SolarisWatchService.h"
static void throwUnixException(JNIEnv* env, int errnum) {
jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",
"(I)V", errnum);
if (x != NULL) {
(*env)->Throw(env, x);
}
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_SolarisWatchService_init(JNIEnv *env, jclass clazz)
{
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_SolarisWatchService_portCreate
(JNIEnv* env, jclass clazz)
{
int port = port_create();
if (port == -1) {
throwUnixException(env, errno);
}
return (jint)port;
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_SolarisWatchService_portAssociate
(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress, jint events)
{
uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
if (port_associate((int)port, (int)source, object, (int)events, NULL) == -1) {
throwUnixException(env, errno);
}
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_SolarisWatchService_portDissociate
(JNIEnv* env, jclass clazz, jint port, jint source, jlong objectAddress)
{
uintptr_t object = (uintptr_t)jlong_to_ptr(objectAddress);
if (port_dissociate((int)port, (int)source, object) == -1) {
throwUnixException(env, errno);
}
}
JNIEXPORT void JNICALL
Java_sun_nio_fs_SolarisWatchService_portSend(JNIEnv* env, jclass clazz,
jint port, jint events)
{
if (port_send((int)port, (int)events, NULL) == -1) {
throwUnixException(env, errno);
}
}
JNIEXPORT jint JNICALL
Java_sun_nio_fs_SolarisWatchService_portGetn(JNIEnv* env, jclass clazz,
jint port, jlong arrayAddress, jint max)
{
uint_t n = 1;
port_event_t* list = (port_event_t*)jlong_to_ptr(arrayAddress);
if (port_getn((int)port, list, (uint_t)max, &n, NULL) == -1) {
throwUnixException(env, errno);
}
return (jint)n;
}