diff options
author | Nick Kralevich <nnk@google.com> | 2014-04-25 14:59:37 -0700 |
---|---|---|
committer | Nick Kralevich <nnk@google.com> | 2014-04-29 11:23:24 -0700 |
commit | 5215e4c0db7530519981f1e505e6db82401802f2 (patch) | |
tree | e49d0c3fa8c29d0f4313a5ecdf598eb56a434032 /luni | |
parent | f3305fa5d4f282e705fd7ba30b07caa3c0f9da71 (diff) | |
download | libcore-5215e4c0db7530519981f1e505e6db82401802f2.zip libcore-5215e4c0db7530519981f1e505e6db82401802f2.tar.gz libcore-5215e4c0db7530519981f1e505e6db82401802f2.tar.bz2 |
add prctl / PR_SET_NO_NEW_PRIVS
Add java wrappers for prctl and PR_SET_NO_NEW_PRIVS.
Change-Id: I649a755ea9354b0290b25292bc65901b1528c1d5
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/java/android/system/Os.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/android/system/OsConstants.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/ForwardingOs.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/Os.java | 1 | ||||
-rw-r--r-- | luni/src/main/java/libcore/io/Posix.java | 1 | ||||
-rw-r--r-- | luni/src/main/native/android_system_OsConstants.cpp | 4 | ||||
-rw-r--r-- | luni/src/main/native/libcore_io_Posix.cpp | 9 |
7 files changed, 18 insertions, 0 deletions
diff --git a/luni/src/main/java/android/system/Os.java b/luni/src/main/java/android/system/Os.java index 0ca22a9..d280ea8 100644 --- a/luni/src/main/java/android/system/Os.java +++ b/luni/src/main/java/android/system/Os.java @@ -112,6 +112,7 @@ public final class Os { public static FileDescriptor[] pipe() throws ErrnoException { return Libcore.os.pipe(); } public static int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return Libcore.os.poll(fds, timeoutMs); } public static void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { Libcore.os.posix_fallocate(fd, offset, length); } + public static int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return Libcore.os.prctl(option, arg2, arg3, arg4, arg5); }; public static int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, buffer, offset); } public static int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pread(fd, bytes, byteOffset, byteCount, offset); } public static int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return Libcore.os.pwrite(fd, buffer, offset); } diff --git a/luni/src/main/java/android/system/OsConstants.java b/luni/src/main/java/android/system/OsConstants.java index d751a18..3bf70f6 100644 --- a/luni/src/main/java/android/system/OsConstants.java +++ b/luni/src/main/java/android/system/OsConstants.java @@ -296,6 +296,7 @@ public final class OsConstants { public static final int POLLRDNORM = placeholder(); public static final int POLLWRBAND = placeholder(); public static final int POLLWRNORM = placeholder(); + public static final int PR_SET_NO_NEW_PRIVS = placeholder(); public static final int PROT_EXEC = placeholder(); public static final int PROT_NONE = placeholder(); public static final int PROT_READ = placeholder(); diff --git a/luni/src/main/java/libcore/io/ForwardingOs.java b/luni/src/main/java/libcore/io/ForwardingOs.java index 3e63cf6..9a993c5 100644 --- a/luni/src/main/java/libcore/io/ForwardingOs.java +++ b/luni/src/main/java/libcore/io/ForwardingOs.java @@ -115,6 +115,7 @@ public class ForwardingOs implements Os { public FileDescriptor[] pipe() throws ErrnoException { return os.pipe(); } public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException { return os.poll(fds, timeoutMs); } public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException { os.posix_fallocate(fd, offset, length); } + public int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException { return os.prctl(option, arg2, arg3, arg4, arg5); }; public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, buffer, offset); } public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException { return os.pread(fd, bytes, byteOffset, byteCount, offset); } public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { return os.pwrite(fd, buffer, offset); } diff --git a/luni/src/main/java/libcore/io/Os.java b/luni/src/main/java/libcore/io/Os.java index 7a71261..e55ae5c 100644 --- a/luni/src/main/java/libcore/io/Os.java +++ b/luni/src/main/java/libcore/io/Os.java @@ -108,6 +108,7 @@ public interface Os { /* TODO: if we used the non-standard ppoll(2) behind the scenes, we could take a long timeout. */ public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException; public void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException; + public int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException; public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException; public int pread(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount, long offset) throws ErrnoException, InterruptedIOException; public int pwrite(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException; diff --git a/luni/src/main/java/libcore/io/Posix.java b/luni/src/main/java/libcore/io/Posix.java index c2dccce..8d99f5e 100644 --- a/luni/src/main/java/libcore/io/Posix.java +++ b/luni/src/main/java/libcore/io/Posix.java @@ -109,6 +109,7 @@ public final class Posix implements Os { public native FileDescriptor[] pipe() throws ErrnoException; public native int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException; public native void posix_fallocate(FileDescriptor fd, long offset, long length) throws ErrnoException; + public native int prctl(int option, long arg2, long arg3, long arg4, long arg5) throws ErrnoException; public int pread(FileDescriptor fd, ByteBuffer buffer, long offset) throws ErrnoException, InterruptedIOException { if (buffer.isDirect()) { return preadBytes(fd, buffer, buffer.position(), buffer.remaining(), offset); diff --git a/luni/src/main/native/android_system_OsConstants.cpp b/luni/src/main/native/android_system_OsConstants.cpp index bfba1a9..cc3054a 100644 --- a/luni/src/main/native/android_system_OsConstants.cpp +++ b/luni/src/main/native/android_system_OsConstants.cpp @@ -30,6 +30,7 @@ #include <stdlib.h> #include <sys/ioctl.h> #include <sys/mman.h> +#include <sys/prctl.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/wait.h> @@ -361,6 +362,9 @@ static void OsConstants_initConstants(JNIEnv* env, jclass c) { initConstant(env, c, "POLLRDNORM", POLLRDNORM); initConstant(env, c, "POLLWRBAND", POLLWRBAND); initConstant(env, c, "POLLWRNORM", POLLWRNORM); +#if defined(PR_SET_NO_NEW_PRIVS) + initConstant(env, c, "PR_SET_NO_NEW_PRIVS", PR_SET_NO_NEW_PRIVS); +#endif initConstant(env, c, "PROT_EXEC", PROT_EXEC); initConstant(env, c, "PROT_NONE", PROT_NONE); initConstant(env, c, "PROT_READ", PROT_READ); diff --git a/luni/src/main/native/libcore_io_Posix.cpp b/luni/src/main/native/libcore_io_Posix.cpp index 7fcec29..db1a886 100644 --- a/luni/src/main/native/libcore_io_Posix.cpp +++ b/luni/src/main/native/libcore_io_Posix.cpp @@ -44,6 +44,7 @@ #include <stdlib.h> #include <sys/ioctl.h> #include <sys/mman.h> +#include <sys/prctl.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> @@ -1076,6 +1077,13 @@ static void Posix_posix_fallocate(JNIEnv* env, jobject, jobject javaFd, jlong of } } +static jint Posix_prctl(JNIEnv* env, jobject, jint option, jlong arg2, jlong arg3, jlong arg4, jlong arg5) { + int result = prctl(static_cast<int>(option), + static_cast<unsigned long>(arg2), static_cast<unsigned long>(arg3), + static_cast<unsigned long>(arg4), static_cast<unsigned long>(arg5)); + return throwIfMinusOne(env, "prctl", result); +} + static jint Posix_preadBytes(JNIEnv* env, jobject, jobject javaFd, jobject javaBytes, jint byteOffset, jint byteCount, jlong offset) { ScopedBytesRW bytes(env, javaBytes); if (bytes.get() == NULL) { @@ -1542,6 +1550,7 @@ static JNINativeMethod gMethods[] = { NATIVE_METHOD(Posix, pipe, "()[Ljava/io/FileDescriptor;"), NATIVE_METHOD(Posix, poll, "([Landroid/system/StructPollfd;I)I"), NATIVE_METHOD(Posix, posix_fallocate, "(Ljava/io/FileDescriptor;JJ)V"), + NATIVE_METHOD(Posix, prctl, "(IJJJJ)I"), NATIVE_METHOD(Posix, preadBytes, "(Ljava/io/FileDescriptor;Ljava/lang/Object;IIJ)I"), NATIVE_METHOD(Posix, pwriteBytes, "(Ljava/io/FileDescriptor;Ljava/lang/Object;IIJ)I"), NATIVE_METHOD(Posix, readBytes, "(Ljava/io/FileDescriptor;Ljava/lang/Object;II)I"), |