Loading cmds/app_process/app_main.cpp +24 −22 Original line number Diff line number Diff line Loading @@ -30,8 +30,9 @@ void app_usage() class AppRuntime : public AndroidRuntime { public: AppRuntime() : mParentDir(NULL) AppRuntime(char* argBlockStart, const size_t argBlockLength) : AndroidRuntime(argBlockStart, argBlockLength) , mParentDir(NULL) , mClassName(NULL) , mClass(NULL) , mArgC(0) Loading Loading @@ -125,29 +126,30 @@ public: using namespace android; /* * sets argv0 to as much of newArgv0 as will fit */ static void setArgv0(const char *argv0, const char *newArgv0) { strlcpy(const_cast<char *>(argv0), newArgv0, strlen(argv0)); static size_t computeArgBlockSize(int argc, char* const argv[]) { // TODO: This assumes that all arguments are allocated in // contiguous memory. There isn't any documented guarantee // that this is the case, but this is how the kernel does it // (see fs/exec.c). // // Also note that this is a constant for "normal" android apps. // Since they're forked from zygote, the size of their command line // is the size of the zygote command line. // // We change the process name of the process by over-writing // the start of the argument block (argv[0]) with the new name of // the process, so we'd mysteriously start getting truncated process // names if the zygote command line decreases in size. uintptr_t start = reinterpret_cast<uintptr_t>(argv[0]); uintptr_t end = reinterpret_cast<uintptr_t>(argv[argc - 1]); end += strlen(argv[argc - 1]); return (end - start); } int main(int argc, char* const argv[]) { // These are global variables in ProcessState.cpp mArgC = argc; mArgV = argv; mArgLen = 0; for (int i=0; i<argc; i++) { mArgLen += strlen(argv[i]) + 1; } mArgLen--; AppRuntime runtime; const char* argv0 = argv[0]; AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv)); // Process command line arguments // ignore argv[0] argc--; Loading Loading @@ -184,7 +186,7 @@ int main(int argc, char* const argv[]) } if (niceName && *niceName) { setArgv0(argv0, niceName); runtime.setArgv0(niceName); set_process_name(niceName); } Loading core/jni/AndroidRuntime.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -229,9 +229,10 @@ int register_com_android_internal_os_RuntimeInit(JNIEnv* env) /*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL; AndroidRuntime::AndroidRuntime() : mExitWithoutCleanup(false) AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) : mExitWithoutCleanup(false), mArgBlockStart(argBlockStart), mArgBlockLength(argBlockLength) { SkGraphics::Init(); // this sets our preference for 16bit images during decode Loading Loading @@ -266,6 +267,10 @@ AndroidRuntime::~AndroidRuntime() return jniRegisterNativeMethods(env, className, gMethods, numMethods); } void AndroidRuntime::setArgv0(const char* argv0) { strlcpy(mArgBlockStart, argv0, mArgBlockLength); } status_t AndroidRuntime::callMain(const char* className, jclass clazz, int argc, const char* const argv[]) { Loading core/jni/android_util_Process.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,8 @@ #include <utils/Log.h> #include <binder/IPCThreadState.h> #include <binder/ProcessState.h> #include <binder/IServiceManager.h> #include <cutils/process_name.h> #include <cutils/sched_policy.h> #include <utils/String8.h> #include <utils/Vector.h> Loading Loading @@ -385,7 +385,9 @@ void android_os_Process_setArgV0(JNIEnv* env, jobject clazz, jstring name) } if (name8.size() > 0) { ProcessState::self()->setArgV0(name8.string()); const char* procName = name8.string(); set_process_name(procName); AndroidRuntime::getRuntime()->setArgv0(procName); } } Loading include/android_runtime/AndroidRuntime.h +5 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ namespace android { class AndroidRuntime { public: AndroidRuntime(); AndroidRuntime(char* argBlockStart, size_t argBlockSize); virtual ~AndroidRuntime(); enum StartMode { Loading @@ -44,6 +44,8 @@ public: Tool, }; void setArgv0(const char* argv0); /** * Register a set of methods in the specified class. */ Loading Loading @@ -120,6 +122,8 @@ private: Vector<JavaVMOption> mOptions; bool mExitWithoutCleanup; char* const mArgBlockStart; const size_t mArgBlockLength; /* JNI JavaVM pointer */ static JavaVM* mJavaVM; Loading Loading
cmds/app_process/app_main.cpp +24 −22 Original line number Diff line number Diff line Loading @@ -30,8 +30,9 @@ void app_usage() class AppRuntime : public AndroidRuntime { public: AppRuntime() : mParentDir(NULL) AppRuntime(char* argBlockStart, const size_t argBlockLength) : AndroidRuntime(argBlockStart, argBlockLength) , mParentDir(NULL) , mClassName(NULL) , mClass(NULL) , mArgC(0) Loading Loading @@ -125,29 +126,30 @@ public: using namespace android; /* * sets argv0 to as much of newArgv0 as will fit */ static void setArgv0(const char *argv0, const char *newArgv0) { strlcpy(const_cast<char *>(argv0), newArgv0, strlen(argv0)); static size_t computeArgBlockSize(int argc, char* const argv[]) { // TODO: This assumes that all arguments are allocated in // contiguous memory. There isn't any documented guarantee // that this is the case, but this is how the kernel does it // (see fs/exec.c). // // Also note that this is a constant for "normal" android apps. // Since they're forked from zygote, the size of their command line // is the size of the zygote command line. // // We change the process name of the process by over-writing // the start of the argument block (argv[0]) with the new name of // the process, so we'd mysteriously start getting truncated process // names if the zygote command line decreases in size. uintptr_t start = reinterpret_cast<uintptr_t>(argv[0]); uintptr_t end = reinterpret_cast<uintptr_t>(argv[argc - 1]); end += strlen(argv[argc - 1]); return (end - start); } int main(int argc, char* const argv[]) { // These are global variables in ProcessState.cpp mArgC = argc; mArgV = argv; mArgLen = 0; for (int i=0; i<argc; i++) { mArgLen += strlen(argv[i]) + 1; } mArgLen--; AppRuntime runtime; const char* argv0 = argv[0]; AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv)); // Process command line arguments // ignore argv[0] argc--; Loading Loading @@ -184,7 +186,7 @@ int main(int argc, char* const argv[]) } if (niceName && *niceName) { setArgv0(argv0, niceName); runtime.setArgv0(niceName); set_process_name(niceName); } Loading
core/jni/AndroidRuntime.cpp +8 −3 Original line number Diff line number Diff line Loading @@ -229,9 +229,10 @@ int register_com_android_internal_os_RuntimeInit(JNIEnv* env) /*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL; AndroidRuntime::AndroidRuntime() : mExitWithoutCleanup(false) AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) : mExitWithoutCleanup(false), mArgBlockStart(argBlockStart), mArgBlockLength(argBlockLength) { SkGraphics::Init(); // this sets our preference for 16bit images during decode Loading Loading @@ -266,6 +267,10 @@ AndroidRuntime::~AndroidRuntime() return jniRegisterNativeMethods(env, className, gMethods, numMethods); } void AndroidRuntime::setArgv0(const char* argv0) { strlcpy(mArgBlockStart, argv0, mArgBlockLength); } status_t AndroidRuntime::callMain(const char* className, jclass clazz, int argc, const char* const argv[]) { Loading
core/jni/android_util_Process.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -19,8 +19,8 @@ #include <utils/Log.h> #include <binder/IPCThreadState.h> #include <binder/ProcessState.h> #include <binder/IServiceManager.h> #include <cutils/process_name.h> #include <cutils/sched_policy.h> #include <utils/String8.h> #include <utils/Vector.h> Loading Loading @@ -385,7 +385,9 @@ void android_os_Process_setArgV0(JNIEnv* env, jobject clazz, jstring name) } if (name8.size() > 0) { ProcessState::self()->setArgV0(name8.string()); const char* procName = name8.string(); set_process_name(procName); AndroidRuntime::getRuntime()->setArgv0(procName); } } Loading
include/android_runtime/AndroidRuntime.h +5 −1 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ namespace android { class AndroidRuntime { public: AndroidRuntime(); AndroidRuntime(char* argBlockStart, size_t argBlockSize); virtual ~AndroidRuntime(); enum StartMode { Loading @@ -44,6 +44,8 @@ public: Tool, }; void setArgv0(const char* argv0); /** * Register a set of methods in the specified class. */ Loading Loading @@ -120,6 +122,8 @@ private: Vector<JavaVMOption> mOptions; bool mExitWithoutCleanup; char* const mArgBlockStart; const size_t mArgBlockLength; /* JNI JavaVM pointer */ static JavaVM* mJavaVM; Loading