diff options
Diffstat (limited to 'luni/src/main/native')
-rw-r--r-- | luni/src/main/native/Register.cpp | 1 | ||||
-rw-r--r-- | luni/src/main/native/android_system_OsConstants.cpp | 4 | ||||
-rw-r--r-- | luni/src/main/native/java_lang_RealToString.cpp | 4 | ||||
-rw-r--r-- | luni/src/main/native/java_util_jar_StrictJarFile.cpp | 1 | ||||
-rw-r--r-- | luni/src/main/native/libcore_icu_ICU.cpp | 9 | ||||
-rw-r--r-- | luni/src/main/native/libcore_io_Posix.cpp | 63 | ||||
-rw-r--r-- | luni/src/main/native/libcore_util_CharsetUtils.cpp | 250 | ||||
-rw-r--r-- | luni/src/main/native/sub.mk | 1 |
8 files changed, 77 insertions, 256 deletions
diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp index 0f2d0ad..acc1e4f 100644 --- a/luni/src/main/native/Register.cpp +++ b/luni/src/main/native/Register.cpp @@ -69,7 +69,6 @@ jint JNI_OnLoad(JavaVM* vm, void*) { REGISTER(register_libcore_io_AsynchronousCloseMonitor); REGISTER(register_libcore_io_Memory); REGISTER(register_libcore_io_Posix); - REGISTER(register_libcore_util_CharsetUtils); REGISTER(register_org_apache_harmony_dalvik_NativeTestTarget); REGISTER(register_org_apache_harmony_xml_ExpatParser); REGISTER(register_sun_misc_Unsafe); diff --git a/luni/src/main/native/android_system_OsConstants.cpp b/luni/src/main/native/android_system_OsConstants.cpp index a9031f4..a11ea76 100644 --- a/luni/src/main/native/android_system_OsConstants.cpp +++ b/luni/src/main/native/android_system_OsConstants.cpp @@ -36,6 +36,7 @@ #include <sys/socket.h> #include <sys/stat.h> #include <sys/wait.h> +#include <sys/xattr.h> #include <unistd.h> #include <net/if_arp.h> @@ -179,6 +180,7 @@ static void OsConstants_initConstants(JNIEnv* env, jclass c) { initConstant(env, c, "ENOLINK", ENOLINK); initConstant(env, c, "ENOMEM", ENOMEM); initConstant(env, c, "ENOMSG", ENOMSG); + initConstant(env, c, "ENONET", ENONET); initConstant(env, c, "ENOPROTOOPT", ENOPROTOOPT); initConstant(env, c, "ENOSPC", ENOSPC); initConstant(env, c, "ENOSR", ENOSR); @@ -555,6 +557,8 @@ static void OsConstants_initConstants(JNIEnv* env, jclass c) { initConstant(env, c, "WSTOPPED", WSTOPPED); initConstant(env, c, "WUNTRACED", WUNTRACED); initConstant(env, c, "W_OK", W_OK); + initConstant(env, c, "XATTR_CREATE", XATTR_CREATE); + initConstant(env, c, "XATTR_REPLACE", XATTR_REPLACE); initConstant(env, c, "X_OK", X_OK); initConstant(env, c, "_SC_2_CHAR_TERM", _SC_2_CHAR_TERM); initConstant(env, c, "_SC_2_C_BIND", _SC_2_C_BIND); diff --git a/luni/src/main/native/java_lang_RealToString.cpp b/luni/src/main/native/java_lang_RealToString.cpp index 7036fe8..9b412b5 100644 --- a/luni/src/main/native/java_lang_RealToString.cpp +++ b/luni/src/main/native/java_lang_RealToString.cpp @@ -80,7 +80,7 @@ void RealToString_bigIntDigitGenerator(JNIEnv* env, jobject obj, jlong f, jint e *R = f; *mplus = *mminus = 1; simpleShiftLeftHighPrecision (mminus, RM_SIZE, e); - if (f != (2 << (p - 1))) + if (f != (INT64_C(1) << p)) { simpleShiftLeftHighPrecision (R, RM_SIZE, e + 1); *S = 2; @@ -103,7 +103,7 @@ void RealToString_bigIntDigitGenerator(JNIEnv* env, jobject obj, jlong f, jint e } else { - if (isDenormalized || (f != (2 << (p - 1)))) + if (isDenormalized || (f != (INT64_C(1) << p))) { *R = f << 1; *S = 1; diff --git a/luni/src/main/native/java_util_jar_StrictJarFile.cpp b/luni/src/main/native/java_util_jar_StrictJarFile.cpp index 82547bd..03d0784 100644 --- a/luni/src/main/native/java_util_jar_StrictJarFile.cpp +++ b/luni/src/main/native/java_util_jar_StrictJarFile.cpp @@ -60,6 +60,7 @@ static jlong StrictJarFile_nativeOpenJarFile(JNIEnv* env, jobject, jstring fileN ZipArchiveHandle handle; int32_t error = OpenArchive(fileChars.c_str(), &handle); if (error) { + CloseArchive(handle); throwIoException(env, error); return static_cast<jlong>(-1); } diff --git a/luni/src/main/native/libcore_icu_ICU.cpp b/luni/src/main/native/libcore_icu_ICU.cpp index 0e744b7..d092978 100644 --- a/luni/src/main/native/libcore_icu_ICU.cpp +++ b/luni/src/main/native/libcore_icu_ICU.cpp @@ -890,9 +890,14 @@ void register_libcore_icu_ICU(JNIEnv* env) { } // Use the ICU data files that shipped with the device for everything else. + const char* systemPathPrefix = getenv("ANDROID_ROOT"); + if (systemPathPrefix == NULL) { + ALOGE("ANDROID_ROOT environment variable not set"); \ + abort(); + } std::string systemPath; - systemPath = u_getDataDirectory(); - systemPath += "/"; + systemPath = systemPathPrefix; + systemPath += "/usr/icu/"; systemPath += U_ICUDATA_NAME; systemPath += ".dat"; diff --git a/luni/src/main/native/libcore_io_Posix.cpp b/luni/src/main/native/libcore_io_Posix.cpp index f6af483..99b76f9 100644 --- a/luni/src/main/native/libcore_io_Posix.cpp +++ b/luni/src/main/native/libcore_io_Posix.cpp @@ -59,6 +59,7 @@ #include <sys/uio.h> #include <sys/utsname.h> #include <sys/wait.h> +#include <sys/xattr.h> #include <termios.h> #include <unistd.h> #include <memory> @@ -1061,6 +1062,28 @@ static jint Posix_getuid(JNIEnv*, jobject) { return getuid(); } +static jint Posix_getxattr(JNIEnv* env, jobject, jstring javaPath, + jstring javaName, jbyteArray javaOutValue) { + ScopedUtfChars path(env, javaPath); + if (path.c_str() == NULL) { + return -1; + } + ScopedUtfChars name(env, javaName); + if (name.c_str() == NULL) { + return -1; + } + ScopedBytesRW outValue(env, javaOutValue); + if (outValue.get() == NULL) { + return -1; + } + size_t outValueLength = env->GetArrayLength(javaOutValue); + ssize_t size = getxattr(path.c_str(), name.c_str(), outValue.get(), outValueLength); + if (size < 0) { + throwErrnoException(env, "getxattr"); + } + return size; +} + static jstring Posix_if_indextoname(JNIEnv* env, jobject, jint index) { char buf[IF_NAMESIZE]; char* name = if_indextoname(index, buf); @@ -1424,6 +1447,22 @@ static void Posix_remove(JNIEnv* env, jobject, jstring javaPath) { throwIfMinusOne(env, "remove", TEMP_FAILURE_RETRY(remove(path.c_str()))); } +static void Posix_removexattr(JNIEnv* env, jobject, jstring javaPath, jstring javaName) { + ScopedUtfChars path(env, javaPath); + if (path.c_str() == NULL) { + return; + } + ScopedUtfChars name(env, javaName); + if (name.c_str() == NULL) { + return; + } + + int res = removexattr(path.c_str(), name.c_str()); + if (res < 0) { + throwErrnoException(env, "removexattr"); + } +} + static void Posix_rename(JNIEnv* env, jobject, jstring javaOldPath, jstring javaNewPath) { ScopedUtfChars oldPath(env, javaOldPath); if (oldPath.c_str() == NULL) { @@ -1664,6 +1703,27 @@ static void Posix_setuid(JNIEnv* env, jobject, jint uid) { throwIfMinusOne(env, "setuid", TEMP_FAILURE_RETRY(setuid(uid))); } +static void Posix_setxattr(JNIEnv* env, jobject, jstring javaPath, jstring javaName, + jbyteArray javaValue, jint flags) { + ScopedUtfChars path(env, javaPath); + if (path.c_str() == NULL) { + return; + } + ScopedUtfChars name(env, javaName); + if (name.c_str() == NULL) { + return; + } + ScopedBytesRO value(env, javaValue); + if (value.get() == NULL) { + return; + } + size_t valueLength = env->GetArrayLength(javaValue); + int res = setxattr(path.c_str(), name.c_str(), value.get(), valueLength, flags); + if (res < 0) { + throwErrnoException(env, "setxattr"); + } +} + static void Posix_shutdown(JNIEnv* env, jobject, jobject javaFd, jint how) { int fd = jniGetFDFromFileDescriptor(env, javaFd); throwIfMinusOne(env, "shutdown", TEMP_FAILURE_RETRY(shutdown(fd, how))); @@ -1842,6 +1902,7 @@ static JNINativeMethod gMethods[] = { NATIVE_METHOD(Posix, getsockoptUcred, "(Ljava/io/FileDescriptor;II)Landroid/system/StructUcred;"), NATIVE_METHOD(Posix, gettid, "()I"), NATIVE_METHOD(Posix, getuid, "()I"), + NATIVE_METHOD(Posix, getxattr, "(Ljava/lang/String;Ljava/lang/String;[B)I"), NATIVE_METHOD(Posix, if_indextoname, "(I)Ljava/lang/String;"), NATIVE_METHOD(Posix, inet_pton, "(ILjava/lang/String;)Ljava/net/InetAddress;"), NATIVE_METHOD(Posix, ioctlInetAddress, "(Ljava/io/FileDescriptor;ILjava/lang/String;)Ljava/net/InetAddress;"), @@ -1873,6 +1934,7 @@ static JNINativeMethod gMethods[] = { NATIVE_METHOD(Posix, readv, "(Ljava/io/FileDescriptor;[Ljava/lang/Object;[I[I)I"), NATIVE_METHOD(Posix, recvfromBytes, "(Ljava/io/FileDescriptor;Ljava/lang/Object;IIILjava/net/InetSocketAddress;)I"), NATIVE_METHOD(Posix, remove, "(Ljava/lang/String;)V"), + NATIVE_METHOD(Posix, removexattr, "(Ljava/lang/String;Ljava/lang/String;)V"), NATIVE_METHOD(Posix, rename, "(Ljava/lang/String;Ljava/lang/String;)V"), NATIVE_METHOD(Posix, sendfile, "(Ljava/io/FileDescriptor;Ljava/io/FileDescriptor;Landroid/util/MutableLong;J)J"), NATIVE_METHOD(Posix, sendtoBytes, "(Ljava/io/FileDescriptor;Ljava/lang/Object;IIILjava/net/InetAddress;I)I"), @@ -1894,6 +1956,7 @@ static JNINativeMethod gMethods[] = { NATIVE_METHOD(Posix, setsockoptLinger, "(Ljava/io/FileDescriptor;IILandroid/system/StructLinger;)V"), NATIVE_METHOD(Posix, setsockoptTimeval, "(Ljava/io/FileDescriptor;IILandroid/system/StructTimeval;)V"), NATIVE_METHOD(Posix, setuid, "(I)V"), + NATIVE_METHOD(Posix, setxattr, "(Ljava/lang/String;Ljava/lang/String;[BI)V"), NATIVE_METHOD(Posix, shutdown, "(Ljava/io/FileDescriptor;I)V"), NATIVE_METHOD(Posix, socket, "(III)Ljava/io/FileDescriptor;"), NATIVE_METHOD(Posix, socketpair, "(IIILjava/io/FileDescriptor;Ljava/io/FileDescriptor;)V"), diff --git a/luni/src/main/native/libcore_util_CharsetUtils.cpp b/luni/src/main/native/libcore_util_CharsetUtils.cpp deleted file mode 100644 index 57c8172..0000000 --- a/luni/src/main/native/libcore_util_CharsetUtils.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "String" - -#include "JNIHelp.h" -#include "JniConstants.h" -#include "ScopedPrimitiveArray.h" -#include "jni.h" -#include "unicode/utf16.h" - -#include <string.h> - -/** - * Approximates java.lang.UnsafeByteSequence so we don't have to pay the cost of calling back into - * Java when converting a char[] to a UTF-8 byte[]. This lets us have UTF-8 conversions slightly - * faster than ICU for large char[]s without paying for the NIO overhead with small char[]s. - * - * We could avoid this by keeping the UTF-8 bytes on the native heap until we're done and only - * creating a byte[] on the Java heap when we know how big it needs to be, but one shouldn't lie - * to the garbage collector (nor hide potentially large allocations from it). - * - * Because a call to append might require an allocation, it might fail. Callers should always - * check the return value of append. - */ -class NativeUnsafeByteSequence { -public: - NativeUnsafeByteSequence(JNIEnv* env) - : mEnv(env), mJavaArray(NULL), mRawArray(NULL), mSize(-1), mOffset(0) - { - } - - ~NativeUnsafeByteSequence() { - // Release our pointer to the raw array, copying changes back to the Java heap. - if (mRawArray != NULL) { - mEnv->ReleaseByteArrayElements(mJavaArray, mRawArray, 0); - } - } - - bool append(jbyte b) { - if (mOffset == mSize && !resize(mSize * 2)) { - return false; - } - mRawArray[mOffset++] = b; - return true; - } - - bool resize(int newSize) { - if (newSize == mSize) { - return true; - } - - // Allocate a new array. - jbyteArray newJavaArray = mEnv->NewByteArray(newSize); - if (newJavaArray == NULL) { - return false; - } - jbyte* newRawArray = mEnv->GetByteArrayElements(newJavaArray, NULL); - if (newRawArray == NULL) { - return false; - } - - // Copy data out of the old array and then let go of it. - // Note that we may be trimming the array. - if (mRawArray != NULL) { - memcpy(newRawArray, mRawArray, mOffset); - mEnv->ReleaseByteArrayElements(mJavaArray, mRawArray, JNI_ABORT); - mEnv->DeleteLocalRef(mJavaArray); - } - - // Point ourselves at the new array. - mJavaArray = newJavaArray; - mRawArray = newRawArray; - mSize = newSize; - return true; - } - - jbyteArray toByteArray() { - // Trim any unused space, if necessary. - bool okay = resize(mOffset); - return okay ? mJavaArray : NULL; - } - -private: - JNIEnv* mEnv; - jbyteArray mJavaArray; - jbyte* mRawArray; - jint mSize; - jint mOffset; - - // Disallow copy and assignment. - NativeUnsafeByteSequence(const NativeUnsafeByteSequence&); - void operator=(const NativeUnsafeByteSequence&); -}; - -static void Charsets_asciiBytesToChars(JNIEnv* env, jclass, jbyteArray javaBytes, jint offset, jint length, jcharArray javaChars) { - ScopedByteArrayRO bytes(env, javaBytes); - if (bytes.get() == NULL) { - return; - } - ScopedCharArrayRW chars(env, javaChars); - if (chars.get() == NULL) { - return; - } - - const jbyte* src = &bytes[offset]; - jchar* dst = &chars[0]; - static const jchar REPLACEMENT_CHAR = 0xfffd; - for (int i = length - 1; i >= 0; --i) { - jchar ch = static_cast<jchar>(*src++ & 0xff); - *dst++ = (ch <= 0x7f) ? ch : REPLACEMENT_CHAR; - } -} - -static void Charsets_isoLatin1BytesToChars(JNIEnv* env, jclass, jbyteArray javaBytes, jint offset, jint length, jcharArray javaChars) { - ScopedByteArrayRO bytes(env, javaBytes); - if (bytes.get() == NULL) { - return; - } - ScopedCharArrayRW chars(env, javaChars); - if (chars.get() == NULL) { - return; - } - - const jbyte* src = &bytes[offset]; - jchar* dst = &chars[0]; - for (int i = length - 1; i >= 0; --i) { - *dst++ = static_cast<jchar>(*src++ & 0xff); - } -} - -/** - * Translates the given characters to US-ASCII or ISO-8859-1 bytes, using the fact that - * Unicode code points between U+0000 and U+007f inclusive are identical to US-ASCII, while - * U+0000 to U+00ff inclusive are identical to ISO-8859-1. - */ -static jbyteArray charsToBytes(JNIEnv* env, jcharArray javaChars, jint offset, jint length, jchar maxValidChar) { - ScopedCharArrayRO chars(env, javaChars); - if (chars.get() == NULL) { - return NULL; - } - - jbyteArray javaBytes = env->NewByteArray(length); - ScopedByteArrayRW bytes(env, javaBytes); - if (bytes.get() == NULL) { - return NULL; - } - - const jchar* src = &chars[offset]; - jbyte* dst = &bytes[0]; - for (int i = length - 1; i >= 0; --i) { - jchar ch = *src++; - if (ch > maxValidChar) { - ch = '?'; - } - *dst++ = static_cast<jbyte>(ch); - } - - return javaBytes; -} - -static jbyteArray Charsets_toAsciiBytes(JNIEnv* env, jclass, jcharArray javaChars, jint offset, jint length) { - return charsToBytes(env, javaChars, offset, length, 0x7f); -} - -static jbyteArray Charsets_toIsoLatin1Bytes(JNIEnv* env, jclass, jcharArray javaChars, jint offset, jint length) { - return charsToBytes(env, javaChars, offset, length, 0xff); -} - -static jbyteArray Charsets_toUtf8Bytes(JNIEnv* env, jclass, jcharArray javaChars, jint offset, jint length) { - ScopedCharArrayRO chars(env, javaChars); - if (chars.get() == NULL) { - return NULL; - } - - NativeUnsafeByteSequence out(env); - if (!out.resize(length)) { - return NULL; - } - - const int end = offset + length; - for (int i = offset; i < end; ++i) { - jint ch = chars[i]; - if (ch < 0x80) { - // One byte. - if (!out.append(ch)) { - return NULL; - } - } else if (ch < 0x800) { - // Two bytes. - if (!out.append((ch >> 6) | 0xc0) || !out.append((ch & 0x3f) | 0x80)) { - return NULL; - } - } else if (U16_IS_SURROGATE(ch)) { - // A supplementary character. - jchar high = (jchar) ch; - jchar low = (i + 1 != end) ? chars[i + 1] : 0; - if (!U16_IS_SURROGATE_LEAD(high) || !U16_IS_SURROGATE_TRAIL(low)) { - if (!out.append('?')) { - return NULL; - } - continue; - } - // Now we know we have a *valid* surrogate pair, we can consume the low surrogate. - ++i; - ch = U16_GET_SUPPLEMENTARY(high, low); - // Four bytes. - jbyte b1 = (ch >> 18) | 0xf0; - jbyte b2 = ((ch >> 12) & 0x3f) | 0x80; - jbyte b3 = ((ch >> 6) & 0x3f) | 0x80; - jbyte b4 = (ch & 0x3f) | 0x80; - if (!out.append(b1) || !out.append(b2) || !out.append(b3) || !out.append(b4)) { - return NULL; - } - } else { - // Three bytes. - jbyte b1 = (ch >> 12) | 0xe0; - jbyte b2 = ((ch >> 6) & 0x3f) | 0x80; - jbyte b3 = (ch & 0x3f) | 0x80; - if (!out.append(b1) || !out.append(b2) || !out.append(b3)) { - return NULL; - } - } - } - return out.toByteArray(); -} - -static JNINativeMethod gMethods[] = { - NATIVE_METHOD(Charsets, asciiBytesToChars, "([BII[C)V"), - NATIVE_METHOD(Charsets, isoLatin1BytesToChars, "([BII[C)V"), - NATIVE_METHOD(Charsets, toAsciiBytes, "([CII)[B"), - NATIVE_METHOD(Charsets, toIsoLatin1Bytes, "([CII)[B"), - NATIVE_METHOD(Charsets, toUtf8Bytes, "([CII)[B"), -}; -void register_libcore_util_CharsetUtils(JNIEnv* env) { - jniRegisterNativeMethods(env, "libcore/util/CharsetUtils", gMethods, NELEM(gMethods)); -} diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk index a90c683..73ed7cb 100644 --- a/luni/src/main/native/sub.mk +++ b/luni/src/main/native/sub.mk @@ -49,7 +49,6 @@ LOCAL_SRC_FILES := \ libcore_io_AsynchronousCloseMonitor.cpp \ libcore_io_Memory.cpp \ libcore_io_Posix.cpp \ - libcore_util_CharsetUtils.cpp \ org_apache_harmony_xml_ExpatParser.cpp \ readlink.cpp \ sun_misc_Unsafe.cpp \ |