Include tids in android.util.Process exceptions.
Bug: 30746129 Change-Id: Id90a40b9df68a8d590bb864546c1bbc9c0edd916
This commit is contained in:
@@ -58,21 +58,19 @@ static pthread_key_t gBgKey = -1;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For both of these, err should be in the errno range (positive), not a status_t (negative)
|
// For both of these, err should be in the errno range (positive), not a status_t (negative)
|
||||||
|
static void signalExceptionForError(JNIEnv* env, int err, int tid) {
|
||||||
static void signalExceptionForPriorityError(JNIEnv* env, int err)
|
|
||||||
{
|
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case EINVAL:
|
case EINVAL:
|
||||||
jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
|
jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
|
||||||
|
"Invalid argument: %d", tid);
|
||||||
break;
|
break;
|
||||||
case ESRCH:
|
case ESRCH:
|
||||||
jniThrowException(env, "java/lang/IllegalArgumentException", "Given thread does not exist");
|
jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
|
||||||
|
"Given thread %d does not exist", tid);
|
||||||
break;
|
break;
|
||||||
case EPERM:
|
case EPERM:
|
||||||
jniThrowException(env, "java/lang/SecurityException", "No permission to modify given thread");
|
jniThrowExceptionFmt(env, "java/lang/SecurityException",
|
||||||
break;
|
"No permission to modify given thread %d", tid);
|
||||||
case EACCES:
|
|
||||||
jniThrowException(env, "java/lang/SecurityException", "No permission to set to given priority");
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
jniThrowException(env, "java/lang/RuntimeException", "Unknown error");
|
jniThrowException(env, "java/lang/RuntimeException", "Unknown error");
|
||||||
@@ -80,23 +78,27 @@ static void signalExceptionForPriorityError(JNIEnv* env, int err)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void signalExceptionForGroupError(JNIEnv* env, int err)
|
static void signalExceptionForPriorityError(JNIEnv* env, int err, int tid) {
|
||||||
{
|
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case EINVAL:
|
|
||||||
jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
|
|
||||||
break;
|
|
||||||
case ESRCH:
|
|
||||||
jniThrowException(env, "java/lang/IllegalArgumentException", "Given thread does not exist");
|
|
||||||
break;
|
|
||||||
case EPERM:
|
|
||||||
jniThrowException(env, "java/lang/SecurityException", "No permission to modify given thread");
|
|
||||||
break;
|
|
||||||
case EACCES:
|
case EACCES:
|
||||||
jniThrowException(env, "java/lang/SecurityException", "No permission to set to given group");
|
jniThrowExceptionFmt(env, "java/lang/SecurityException",
|
||||||
|
"No permission to set the priority of %d", tid);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
jniThrowException(env, "java/lang/RuntimeException", "Unknown error");
|
signalExceptionForError(env, err, tid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void signalExceptionForGroupError(JNIEnv* env, int err, int tid) {
|
||||||
|
switch (err) {
|
||||||
|
case EACCES:
|
||||||
|
jniThrowExceptionFmt(env, "java/lang/SecurityException",
|
||||||
|
"No permission to set the group of %d", tid);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
signalExceptionForError(env, err, tid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,7 +173,7 @@ void android_os_Process_setThreadGroup(JNIEnv* env, jobject clazz, int tid, jint
|
|||||||
SchedPolicy sp = (SchedPolicy) grp;
|
SchedPolicy sp = (SchedPolicy) grp;
|
||||||
int res = set_sched_policy(tid, sp);
|
int res = set_sched_policy(tid, sp);
|
||||||
if (res != NO_ERROR) {
|
if (res != NO_ERROR) {
|
||||||
signalExceptionForGroupError(env, -res);
|
signalExceptionForGroupError(env, -res, tid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +185,7 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
|
|||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
|
|
||||||
if ((grp == SP_FOREGROUND) || (grp > SP_MAX)) {
|
if ((grp == SP_FOREGROUND) || (grp > SP_MAX)) {
|
||||||
signalExceptionForGroupError(env, EINVAL);
|
signalExceptionForGroupError(env, EINVAL, pid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +221,7 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
|
|||||||
if (!(d = opendir(proc_path))) {
|
if (!(d = opendir(proc_path))) {
|
||||||
// If the process exited on us, don't generate an exception
|
// If the process exited on us, don't generate an exception
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
signalExceptionForGroupError(env, errno);
|
signalExceptionForGroupError(env, errno, pid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +256,7 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
|
|||||||
#ifdef ENABLE_CPUSETS
|
#ifdef ENABLE_CPUSETS
|
||||||
int err = set_cpuset_policy(t_pid, sp);
|
int err = set_cpuset_policy(t_pid, sp);
|
||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
signalExceptionForGroupError(env, -err);
|
signalExceptionForGroupError(env, -err, t_pid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -266,14 +268,14 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
|
|||||||
// set both cpuset and cgroup for general threads
|
// set both cpuset and cgroup for general threads
|
||||||
err = set_cpuset_policy(t_pid, sp);
|
err = set_cpuset_policy(t_pid, sp);
|
||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
signalExceptionForGroupError(env, -err);
|
signalExceptionForGroupError(env, -err, t_pid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
err = set_sched_policy(t_pid, sp);
|
err = set_sched_policy(t_pid, sp);
|
||||||
if (err != NO_ERROR) {
|
if (err != NO_ERROR) {
|
||||||
signalExceptionForGroupError(env, -err);
|
signalExceptionForGroupError(env, -err, t_pid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +287,7 @@ jint android_os_Process_getProcessGroup(JNIEnv* env, jobject clazz, jint pid)
|
|||||||
{
|
{
|
||||||
SchedPolicy sp;
|
SchedPolicy sp;
|
||||||
if (get_sched_policy(pid, &sp) != 0) {
|
if (get_sched_policy(pid, &sp) != 0) {
|
||||||
signalExceptionForGroupError(env, errno);
|
signalExceptionForGroupError(env, errno, pid);
|
||||||
}
|
}
|
||||||
return (int) sp;
|
return (int) sp;
|
||||||
}
|
}
|
||||||
@@ -400,7 +402,7 @@ jintArray android_os_Process_getExclusiveCores(JNIEnv* env, jobject clazz) {
|
|||||||
jintArray cpus;
|
jintArray cpus;
|
||||||
int pid = getpid();
|
int pid = getpid();
|
||||||
if (get_sched_policy(pid, &sp) != 0) {
|
if (get_sched_policy(pid, &sp) != 0) {
|
||||||
signalExceptionForGroupError(env, errno);
|
signalExceptionForGroupError(env, errno, pid);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
get_exclusive_cpuset_cores(sp, &cpu_set);
|
get_exclusive_cpuset_cores(sp, &cpu_set);
|
||||||
@@ -449,10 +451,10 @@ jint android_os_Process_getThreadScheduler(JNIEnv* env, jclass clazz,
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
policy = sched_getscheduler(tid);
|
policy = sched_getscheduler(tid);
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
signalExceptionForPriorityError(env, errno);
|
signalExceptionForPriorityError(env, errno, tid);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
signalExceptionForPriorityError(env, ENOSYS);
|
signalExceptionForPriorityError(env, ENOSYS, tid);
|
||||||
#endif
|
#endif
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
@@ -466,10 +468,10 @@ void android_os_Process_setThreadScheduler(JNIEnv* env, jclass clazz,
|
|||||||
param.sched_priority = pri;
|
param.sched_priority = pri;
|
||||||
int rc = sched_setscheduler(tid, policy, ¶m);
|
int rc = sched_setscheduler(tid, policy, ¶m);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
signalExceptionForPriorityError(env, errno);
|
signalExceptionForPriorityError(env, errno, tid);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
signalExceptionForPriorityError(env, ENOSYS);
|
signalExceptionForPriorityError(env, ENOSYS, tid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,9 +496,9 @@ void android_os_Process_setThreadPriority(JNIEnv* env, jobject clazz,
|
|||||||
int rc = androidSetThreadPriority(pid, pri);
|
int rc = androidSetThreadPriority(pid, pri);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
if (rc == INVALID_OPERATION) {
|
if (rc == INVALID_OPERATION) {
|
||||||
signalExceptionForPriorityError(env, errno);
|
signalExceptionForPriorityError(env, errno, pid);
|
||||||
} else {
|
} else {
|
||||||
signalExceptionForGroupError(env, errno);
|
signalExceptionForGroupError(env, errno, pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,7 +518,7 @@ jint android_os_Process_getThreadPriority(JNIEnv* env, jobject clazz,
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
jint pri = getpriority(PRIO_PROCESS, pid);
|
jint pri = getpriority(PRIO_PROCESS, pid);
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
signalExceptionForPriorityError(env, errno);
|
signalExceptionForPriorityError(env, errno, pid);
|
||||||
}
|
}
|
||||||
//ALOGI("Returning priority of %" PRId32 ": %" PRId32 "\n", pid, pri);
|
//ALOGI("Returning priority of %" PRId32 ": %" PRId32 "\n", pid, pri);
|
||||||
return pri;
|
return pri;
|
||||||
|
|||||||
Reference in New Issue
Block a user