diff options
author | Andrew Niefer | 2006-11-13 22:55:40 +0000 |
---|---|---|
committer | Andrew Niefer | 2006-11-13 22:55:40 +0000 |
commit | 65358aa65c659e23ae3301bc60f55ad25be81e9d (patch) | |
tree | 669a51d2d2504b6d81233a3988bf2a15978b2472 | |
parent | 47ef073c6ebba76275577670bc6dc2b198218765 (diff) | |
download | rt.equinox.framework-65358aa65c659e23ae3301bc60f55ad25be81e9d.tar.gz rt.equinox.framework-65358aa65c659e23ae3301bc60f55ad25be81e9d.tar.xz rt.equinox.framework-65358aa65c659e23ae3301bc60f55ad25be81e9d.zip |
Remove shared memory code, Add JNI. win32-mingw compiles.
10 files changed, 308 insertions, 568 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/.cdtproject b/bundles/org.eclipse.equinox.launcher/.cdtproject index d81ca9d42..da9d75c21 100644 --- a/bundles/org.eclipse.equinox.launcher/.cdtproject +++ b/bundles/org.eclipse.equinox.launcher/.cdtproject @@ -56,5 +56,23 @@ <pathentry kind="out" path=""/> <pathentry kind="con" path="org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"/> </item> +<item id="org.eclipse.cdt.make.core.buildtargets"> +<buildTargets> +<target name="win32-mingw-all" path="library" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> +<buildCommand>make</buildCommand> +<buildArguments>-C win32 -f make_mingw.mak</buildArguments> +<buildTarget>all</buildTarget> +<stopOnError>false</stopOnError> +<useDefaultCommand>false</useDefaultCommand> +</target> +<target name="win32-clean" path="library" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> +<buildCommand>make</buildCommand> +<buildArguments>-C win32 -fmake_mingw.mak</buildArguments> +<buildTarget>clean</buildTarget> +<stopOnError>false</stopOnError> +<useDefaultCommand>false</useDefaultCommand> +</target> +</buildTargets> +</item> </data> </cdtproject> diff --git a/bundles/org.eclipse.equinox.launcher/.project b/bundles/org.eclipse.equinox.launcher/.project index c88f4d22b..d629aa792 100644 --- a/bundles/org.eclipse.equinox.launcher/.project +++ b/bundles/org.eclipse.equinox.launcher/.project @@ -18,34 +18,38 @@ <value>org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser;</value> </dictionary> <dictionary> + <key>org.eclipse.cdt.make.core.environment</key> + <value>JAVA_JNI=C:/Dev/Java/IBM_1.5.0/include|DEFAULT_OS=${system_property:osgi.os}|DEFAULT_WS=${system_property:osgi.ws}|DEFAULT_OS_ARCH=${system_property:osgi.arch}|</value> + </dictionary> + <dictionary> <key>org.eclipse.cdt.make.core.enableAutoBuild</key> <value>false</value> </dictionary> <dictionary> - <key>org.eclipse.cdt.make.core.environment</key> - <value></value> + <key>org.eclipse.cdt.make.core.build.target.inc</key> + <value>all</value> </dictionary> <dictionary> <key>org.eclipse.cdt.make.core.enableFullBuild</key> <value>true</value> </dictionary> <dictionary> - <key>org.eclipse.cdt.make.core.build.target.inc</key> - <value>all</value> - </dictionary> - <dictionary> <key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key> <value>true</value> </dictionary> <dictionary> - <key>org.eclipse.cdt.make.core.build.target.clean</key> - <value>clean</value> + <key>org.eclipse.cdt.make.core.build.location</key> + <value>\org.eclipse.equinox.launcher\library\${system_property:osgi.ws}</value> </dictionary> <dictionary> <key>org.eclipse.cdt.make.core.build.command</key> <value>make</value> </dictionary> <dictionary> + <key>org.eclipse.cdt.make.core.build.target.clean</key> + <value>clean</value> + </dictionary> + <dictionary> <key>org.eclipse.cdt.make.core.enableCleanBuild</key> <value>true</value> </dictionary> diff --git a/bundles/org.eclipse.equinox.launcher/library/eclipse.c b/bundles/org.eclipse.equinox.launcher/library/eclipse.c index 798125765..63df06b97 100644 --- a/bundles/org.eclipse.equinox.launcher/library/eclipse.c +++ b/bundles/org.eclipse.equinox.launcher/library/eclipse.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -179,7 +179,6 @@ */ #include "eclipseOS.h" -#include "eclipseShm.h" #include "eclipseConfig.h" #ifdef _WIN32 @@ -209,8 +208,7 @@ static _TCHAR* program = NULL; /* full pathname of the program */ static _TCHAR* programDir = NULL; /* directory where program resides */ static _TCHAR* javaVM = NULL; /* full pathname of the Java VM to run */ static _TCHAR* jarFile = NULL; /* full pathname of the startup jar file to run */ -static _TCHAR* sharedID = NULL; /* ID for the shared memory */ - +static _TCHAR* exitData = NULL; /* exit data set from Java */ /* Define the special exit codes returned from Eclipse. */ #define RESTART_LAST_EC 23 #define RESTART_NEW_EC 24 @@ -223,7 +221,7 @@ static _TCHAR* exitMsg = _T_ECLIPSE("JVM terminated. Exit code=%d\n%s"); static _TCHAR* goVMMsg = _T_ECLIPSE("Start VM: %s\n"); static _TCHAR* pathMsg = _T_ECLIPSE("%s\n'%s' in your current PATH"); static _TCHAR* showMsg = _T_ECLIPSE("Could not load splash bitmap:\n%s"); -static _TCHAR* shareMsg = _T_ECLIPSE("No shared data available."); +static _TCHAR* shareMsg = _T_ECLIPSE("No exit data available."); static _TCHAR* noVMMsg = _T_ECLIPSE("A Java Runtime Environment (JRE) or Java Development Kit (JDK)\n\ must be available in order to run %s. No Java virtual machine\n\ @@ -245,7 +243,6 @@ companion startup.jar file (in the same directory as the executable)."); #define NOSPLASH _T_ECLIPSE("-nosplash") #define LAUNCHER _T_ECLIPSE("-launcher") #define SHOWSPLASH _T_ECLIPSE("-showsplash") -#define EXITDATA _T_ECLIPSE("-exitdata") #define STARTUP _T_ECLIPSE("-startup") #define VM _T_ECLIPSE("-vm") #define WS _T_ECLIPSE("-ws") @@ -259,7 +256,6 @@ static int noSplash = 0; /* True: do not show splash win */ static _TCHAR* osArg = _T_ECLIPSE(DEFAULT_OS); static _TCHAR* osArchArg = _T_ECLIPSE(DEFAULT_OS_ARCH); static _TCHAR* showSplashArg = NULL; /* showsplash data (main launcher window) */ -static _TCHAR* exitDataArg = NULL; static _TCHAR * startupArg = DEFAULT_STARTUP; /* path of the startup.jar the user wants to run relative to the program path */ static _TCHAR* vmName = NULL; /* Java VM that the user wants to run */ static _TCHAR* wsArg = _T_ECLIPSE(DEFAULT_WS); /* the SWT supported GUI to be used */ @@ -283,7 +279,6 @@ static Option options[] = { { OS, &osArg, NULL, 2 }, { OSARCH, &osArchArg, NULL, 2 }, { SHOWSPLASH, &showSplashArg, NULL, 2 }, - { EXITDATA, &exitDataArg, NULL, 2 }, { STARTUP, &startupArg, NULL, 2 }, { VM, &vmName, NULL, 2 }, { NAME, &name, NULL, 2 }, @@ -307,7 +302,6 @@ static _TCHAR** getVMCommand( int argc, _TCHAR* argv[] ); static _TCHAR* formatVmCommandMsg( _TCHAR* args[] ); _TCHAR* getProgramDir(); static _TCHAR* getDefaultOfficialName(); -static int isMainEclipse( int argc, _TCHAR **argv ); #ifdef _WIN32 #ifdef UNICODE @@ -349,7 +343,6 @@ int main( int argc, _TCHAR* argv[] ) { _TCHAR* splashBitmap; _TCHAR* ch; - _TCHAR* data; _TCHAR* shippedVM = NULL; _TCHAR* vmSearchPath = NULL; _TCHAR** vmCommand = NULL; @@ -388,7 +381,7 @@ int main( int argc, _TCHAR* argv[] ) } /* Parse configuration file arguments */ - if (isMainEclipse(argc, argv) && readConfigFile(program, argv[0], &configArgc, &configArgv) == 0) + if (readConfigFile(program, argv[0], &configArgc, &configArgv) == 0) { parseArgs (&configArgc, configArgv); } @@ -422,22 +415,6 @@ int main( int argc, _TCHAR* argv[] ) exit( 1 ); } - /* If the exit data option was given, set exit data */ - if (exitDataArg != NULL) - { - /* If an extra argument was given, use it as the exit data, otherwise clear exit data */ - data = argc > 1 ? argv[1] : NULL; - if (data != NULL && _tcslen( data ) > MAX_SHARED_LENGTH - 1) - { - exitCode = EINVAL; - } - else { - exitCode = setSharedData( exitDataArg, data ); - } - if (exitCode != 0 && debug) displayMessage( officialName, shareMsg ); - exit( exitCode ); - } - /* If the showsplash option was given */ if (showSplashArg != NULL && argc > 1) { @@ -490,12 +467,6 @@ int main( int argc, _TCHAR* argv[] ) } } - if (createSharedData( &sharedID, MAX_SHARED_LENGTH )) { - if (debug) { - if (debug) displayMessage( officialName, shareMsg ); - } - } - /* Construct the absolute name of the startup jar */ jarFile = malloc( (_tcslen( programDir ) + _tcslen( startupArg ) + 1) * sizeof( _TCHAR ) ); jarFile = _tcscpy( jarFile, programDir ); @@ -526,9 +497,9 @@ int main( int argc, _TCHAR* argv[] ) case RESTART_LAST_EC: break; case RESTART_NEW_EC: - if (getSharedData( sharedID, &data ) == 0) { + if (exitData != 0) { if (vmCommandList != NULL) freeArgList( vmCommandList ); - vmCommand = vmCommandList = parseArgList( data ); + vmCommand = vmCommandList = parseArgList( exitData ); } else { vmCommand = NULL; if (debug) displayMessage( officialName, shareMsg ); @@ -538,7 +509,8 @@ int main( int argc, _TCHAR* argv[] ) _TCHAR *title = _tcsdup(officialName); vmCommand = NULL; errorMsg = NULL; - if (getSharedData( sharedID, &errorMsg ) == 0) { + if (exitData != 0) { + errorMsg = exitData; if (_tcslen( errorMsg ) == 0) { free( errorMsg ); errorMsg = NULL; @@ -581,28 +553,10 @@ int main( int argc, _TCHAR* argv[] ) if ( configArgv != NULL ) freeConfig( configArgv ); if (configArgc > 1) free( argv ); free( officialName ); - if ( sharedID != NULL ) { - if (destroySharedData( sharedID ) != 0) { - if (debug) displayMessage( officialName, shareMsg ); - } - free( sharedID ); - } return 0; } -/* Return 1 if the current Eclipse is the process that starts the java IDE - * Return 0 if it is an Eclipse used to display a splash screen or to write - * data to a shared memory segment. - * The main Eclipse is the only one that reads the eclipse.ini file. - */ -static int isMainEclipse( int argc, _TCHAR **argv ) -{ - /* It is the main eclipse if the argument 3 is neither SHOWSPLASH nor EXITDATA */ - if (argc < 4) return 1; - return (_tcsicmp( argv[3], SHOWSPLASH ) != 0 && _tcsicmp( argv[3], EXITDATA ) != 0); -} - /* * Parse arguments of the command. */ @@ -902,10 +856,10 @@ static _TCHAR** getVMCommand( int argc, _TCHAR* argv[] ) /* Allocate the arg list for the exec call. * (VM + userVMargs + defaultVMargs + requiredVMargs + OS <os> + WS <ws> + ARCH <arch> + LAUNCHER <launcher> + NAME <officialName> + - * + SHOWSPLASH <cmd> + EXITDATA <cmd> + argv[] + VM + <vm> + VMARGS + userVMargs + defaultVMargs + requiredVMargs + * + SHOWSPLASH <cmd> + argv[] + VM + <vm> + VMARGS + userVMargs + defaultVMargs + requiredVMargs * + NULL) */ - totalArgs = 1 + nUserVMarg + nDefVMarg + nReqVMarg + 2 + 2 + 2 + 2 + 2 + 2 + 2 + argc + 2 + 1 + nUserVMarg + nDefVMarg + nReqVMarg + 1; + totalArgs = 1 + nUserVMarg + nDefVMarg + nReqVMarg + 2 + 2 + 2 + 2 + 2 + 2 + argc + 2 + 1 + nUserVMarg + nDefVMarg + nReqVMarg + 1; execArg = malloc( totalArgs * sizeof( _TCHAR* ) ); dst = 0; execArg[ dst++ ] = javaVM; @@ -951,12 +905,6 @@ static _TCHAR** getVMCommand( int argc, _TCHAR* argv[] ) execArg[ dst++ ] = splashTimeout; } - /* Append the exit data command. */ - if (sharedID) { - execArg[ dst++ ] = EXITDATA; - execArg[ dst++ ] = sharedID; - } - /* Append the remaining user defined arguments. */ for (src = 1; src < argc; src++) { diff --git a/bundles/org.eclipse.equinox.launcher/library/eclipseJNI.c b/bundles/org.eclipse.equinox.launcher/library/eclipseJNI.c new file mode 100644 index 000000000..342ef9a18 --- /dev/null +++ b/bundles/org.eclipse.equinox.launcher/library/eclipseJNI.c @@ -0,0 +1,163 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +#include "eclipseJNI.h" +#include "eclipseOS.h" +#include <stdlib.h> + +static JNINativeMethod natives[] = {{"_update_splash", "()V", &update_splash}, + {"_get_splash_handle", "()I", &get_splash_handle}, + {"_set_exit_data", "(Ljava/lang/String;)V", &set_exit_data}}; + +/* local methods */ +static jstring newJavaString(JNIEnv *env, _TCHAR * str); + +#ifndef UNICODE /* we only want one version of these functions */ +/* JNI Callback methods */ +JNIEXPORT void JNICALL set_exit_data(JNIEnv * env, jobject obj, jstring s){ + setExitData(env, s); +} + +JNIEXPORT void JNICALL update_splash(JNIEnv * env, jobject obj){ + +} + +JNIEXPORT jint JNICALL get_splash_handle(JNIEnv * env, jobject obj){ + return 0; +} +#endif + +void setExitData(JNIEnv *env, jstring s){ + _TCHAR * copy = malloc((*env)->GetStringLength(env, s) * sizeof(_TCHAR*)); + const _TCHAR * data; +#ifdef UNICODE + data = (*env)->GetStringChars(env, s, 0); + _tcscpy( copy, data ); + (*env)->ReleaseStringChars(env, s, data); +#else + data = (*env)->GetStringUTFChars(env, s, 0); + _tcscpy( copy, data ); + (*env)->ReleaseStringUTFChars(env, s, data); +#endif +} +static jstring newJavaString(JNIEnv *env, _TCHAR * str) +{ + jstring newString = 0; + int length = _tcslen(str); + +#ifdef UNICODE + newString = (*env)->NewString(env, str, length); +#else + jbyteArray bytes = (*env)->NewByteArray(env, length); + (*env)->SetByteArrayRegion(env, bytes, 0, length, str); + if (!(*env)->ExceptionOccurred(env)) { + jclass stringClass = (*env)->FindClass(env, "java/lang/String"); + jmethodID ctor = (*env)->GetMethodID(env, stringClass, "<init>", "([B)V"); + newString = (*env)->NewObject(env, stringClass, ctor, bytes); + } + (*env)->DeleteLocalRef(env, bytes); +#endif + + return newString; +} + +static jobjectArray createRunArgs( JNIEnv *env, _TCHAR * args[] ) { + int index = 0, length = -1; + + /*count the number of elements first*/ + while(args[++length] != NULL); + + jclass stringClass = (*env)->FindClass(env, "java/lang/String"); + jobjectArray stringArray = (*env)->NewObjectArray(env, length, stringClass, 0); + for( index = 0; index < length; index++) { + jstring string = newJavaString(env, args[index]); + (*env)->SetObjectArrayElement(env, stringArray, index, string); + (*env)->DeleteLocalRef(env, string); + } + return stringArray; +} + +/** + * Convert a wide string to a narrow one suitable for use in JNI. + * Caller must free the null terminated string returned. + */ +static char *toNarrow(_TCHAR* src) +{ +#ifdef UNICODE + int byteCount = WideCharToMultiByte (CP_ACP, 0, (wchar_t *)src, -1, NULL, 0, NULL, NULL); + char *dest = malloc(byteCount+1); + dest[byteCount] = 0; + WideCharToMultiByte (CP_ACP, 0, (wchar_t *)src, -1, dest, byteCount, NULL, NULL); + return dest; +#else + return _tcsdup(src); +#endif +} + +int launchJavaVM(_TCHAR *dllPath, _TCHAR* progArgs[], int vmArgc, _TCHAR* vmArgv[] ) { + int i; + int jvmExitCode = 0; + void * jniLibrary; + JNI_createJavaVM createJavaVM; + JavaVMInitArgs init_args; + JavaVMOption * options; + JavaVM * jvm; + JNIEnv *env; + + jniLibrary = loadLibrary(dllPath); + if(jniLibrary == NULL) { + return -1; /*error*/ + } + + createJavaVM = findSymbol(jniLibrary, "JNI_CreateJavaVM"); + if(createJavaVM == NULL) { + return -1; /*error*/ + } + + options = malloc(vmArgc * sizeof(JavaVMOption)); + for(i = 0; i < vmArgc; i++){ + options[i].optionString = toNarrow(vmArgv[i]); + options[i].extraInfo = 0; + } + + init_args.version = JNI_VERSION_1_2; + init_args.options = options; + init_args.nOptions = vmArgc; + init_args.ignoreUnrecognized = JNI_TRUE; + + if( createJavaVM(&jvm, &env, &init_args) == 0 ) { + jclass mainClass = (*env)->FindClass(env, "org/eclipse/core/launcher/Main"); + + int numNatives = sizeof(natives) / sizeof(natives[0]); + (*env)->RegisterNatives(env, mainClass, natives, numNatives); + + jmethodID mainConstructor = (*env)->GetMethodID(env, mainClass, "<init>", "()V"); + jobject mainObject = (*env)->NewObject(env, mainClass, mainConstructor); + jmethodID runMethod = (*env)->GetMethodID(env, mainClass, "run", "([Ljava/lang/String;)I"); + if(runMethod != NULL) { + jobjectArray methodArgs = createRunArgs(env, progArgs); + jvmExitCode = (*env)->CallIntMethod(env, mainObject, runMethod, methodArgs); + } + /*(*jvm)->DestroyJavaVM(jvm);*/ + } + unloadLibrary(jniLibrary); + free(progArgs); + + /* toNarrow allocated new strings, free them */ + for(i = 0; i < vmArgc; i++){ + free( options[i].optionString ); + } + + return jvmExitCode; +} + + + diff --git a/bundles/org.eclipse.equinox.launcher/library/eclipseJNI.h b/bundles/org.eclipse.equinox.launcher/library/eclipseJNI.h new file mode 100644 index 000000000..e5f1a2c57 --- /dev/null +++ b/bundles/org.eclipse.equinox.launcher/library/eclipseJNI.h @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +#ifndef ECLIPSE_JNI_H +#define ECLIPSE_JNI_H + +#include "eclipseUnicode.h" +#include <jni.h> + +#ifdef UNICODE +#define loadVMLibrary loadVMLibraryW +#define unloadVMLibrary unloadVMLibraryW +#define getInvocationFunction getInvocationFunctionW +#define launchJavaVM launchJavaVMW +#define setExitData setExitDataW +#endif + +typedef jint (JNICALL *JNI_createJavaVM)(JavaVM **pvm, JNIEnv **env, void *args); + +void setExitData(JNIEnv *env, jstring s); + +/* JNI Callback methods */ +/* Use name mangling since we may be linking these from java with System.LoadLibrary */ +#define set_exit_data Java_org_eclipse_core_launcher_JNIBridge__1set_1exit_1data +#define update_splash Java_org_eclipse_core_launcher_JNIBridge__1update_1splash +#define get_splash_handle Java_org_eclipse_core_launcher_JNIBridge__1get_1splash_1handle + +/* + * org_eclipse_core_launcher_JNIBridge#_set_exit_data + * Signature: (Ljava/lang/String;)V + */ +extern JNIEXPORT void JNICALL set_exit_data(JNIEnv *, jobject, jstring); + +/* + * org_eclipse_core_launcher_JNIBridge#_update_splash + * Signature: ()V + */ +extern JNIEXPORT void JNICALL update_splash(JNIEnv *, jobject); + +/* + * org_eclipse_core_launcher_JNIBridge#_get_splash_handle + * Signature: ()I + */ +extern JNIEXPORT jint JNICALL get_splash_handle(JNIEnv *, jobject); + +#endif diff --git a/bundles/org.eclipse.equinox.launcher/library/eclipseOS.h b/bundles/org.eclipse.equinox.launcher/library/eclipseOS.h index 3f6dd4860..b65d9f0e2 100644 --- a/bundles/org.eclipse.equinox.launcher/library/eclipseOS.h +++ b/bundles/org.eclipse.equinox.launcher/library/eclipseOS.h @@ -29,6 +29,10 @@ #define findCommand findCommandW #define getProgramDir getProgramDirW #define officialName officialNameW +#define exitData exitDataW +#define loadLibrary loadLibraryW +#define unloadLibrary unloadLibraryW +#define findSymbol findSymbolW #endif /* Operating System Dependent Information */ @@ -43,6 +47,7 @@ extern _TCHAR* consoleVM; /* name of VM to use for debugging */ extern _TCHAR* defaultVM; /* name of VM to use normally */ extern _TCHAR* shippedVMDir; /* VM bin directory with separator */ extern _TCHAR* officialName; /* Program official name */ +extern _TCHAR* exitData; /* exit data set from Java */ /* OS Specific Functions */ @@ -107,5 +112,18 @@ extern _TCHAR** getArgVM( _TCHAR *vm ); */ extern int startJavaVM( _TCHAR* args[] ); + +/* Load the specified shared library + */ +extern void * loadLibrary( _TCHAR * library ); + +/* Unload the shared library + */ +extern void unloadLibrary( void * handle ); + +/* Find the given symbol in the shared library + */ +extern void * findSymbol( void * handle, char * symbol ); + #endif /* ECLIPSE_OS_H */ diff --git a/bundles/org.eclipse.equinox.launcher/library/eclipseShm.c b/bundles/org.eclipse.equinox.launcher/library/eclipseShm.c deleted file mode 100644 index 9e21aee35..000000000 --- a/bundles/org.eclipse.equinox.launcher/library/eclipseShm.c +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Silenio Quarti - *******************************************************************************/ - -#include "eclipseOS.h" -#include "eclipseShm.h" - -#ifdef _WIN32 - -#include <stdio.h> - -#ifdef __MINGW32__ -#include <stdlib.h> -#endif - -int createSharedData(_TCHAR** id, int size) { - HANDLE mapHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, NULL); - if (mapHandle == 0) return -1; - if (id != NULL) { - *id = malloc(18 * sizeof(_TCHAR)); - _stprintf(*id, _T_ECLIPSE("%lx_%lx"), GetCurrentProcessId(), (DWORD) mapHandle); - } - return 0; -} - -static int getShmID(_TCHAR* id, LPDWORD processID, LPHANDLE handle) { - if (id != NULL && _tcslen(id) > 0) { - DWORD i1, i2; - if (_stscanf(id, _T_ECLIPSE("%lx_%lx"), &i1, &i2) != 2) return -1; - *processID = (DWORD)i1; - *handle = (HANDLE)i2; - return 0; - } - return -1; -} - -int destroySharedData(_TCHAR* id) { - DWORD processID; - HANDLE handle; - if (getShmID(id, &processID, &handle) == -1) return -1; - if (!CloseHandle(handle)) return -1; - return 0; -} - -int getSharedData(_TCHAR* id, _TCHAR** data) { - _TCHAR *sharedData, *newData = NULL; - DWORD processID; - HANDLE handle, mapHandle = NULL, processHandle; - if (getShmID(id, &processID, &handle) == -1) return -1; - if (processID == GetCurrentProcessId()) { - mapHandle = handle; - } else { - processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID); - if (processHandle == NULL) return -1; - DuplicateHandle(processHandle, handle, GetCurrentProcess(), &mapHandle, DUPLICATE_SAME_ACCESS, FALSE, DUPLICATE_SAME_ACCESS); - CloseHandle(processHandle); - } - if (mapHandle == NULL) return -1; - sharedData = MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0); - if (sharedData == NULL) return -1; - if (data != NULL) { - int length = (_tcslen(sharedData) + 1) * sizeof(_TCHAR); - newData = malloc(length); - memcpy(newData, sharedData, length); - } - if (!UnmapViewOfFile(sharedData)) { - free(newData); - return -1; - } - if (handle != mapHandle) { - CloseHandle(mapHandle); - } - *data = newData; - return 0; -} - -int setSharedData(_TCHAR* id, _TCHAR* data) { - _TCHAR* sharedData; - DWORD processID; - HANDLE handle, mapHandle = NULL, processHandle; - if (getShmID(id, &processID, &handle) == -1) return -1; - if (processID == GetCurrentProcessId()) { - mapHandle = handle; - } else { - processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID); - if (processHandle == NULL) return -1; - DuplicateHandle(processHandle, handle, GetCurrentProcess(), &mapHandle, DUPLICATE_SAME_ACCESS, FALSE, DUPLICATE_SAME_ACCESS); - CloseHandle(processHandle); - } - if (mapHandle == NULL) return -1; - sharedData = MapViewOfFile(mapHandle, FILE_MAP_WRITE, 0, 0, 0); - if (sharedData == NULL) return -1; - if (data != NULL) { - int length = (_tcslen(data) + 1) * sizeof(_TCHAR); - memcpy(sharedData, data, length); - } else { - memset(sharedData, 0, sizeof(_TCHAR)); - } - if (!UnmapViewOfFile(sharedData)) { - return -1; - } - if (handle != mapHandle) { - CloseHandle(mapHandle); - } - return 0; -} - -#elif PHOTON - -#include <fcntl.h> -#include <sys/mman.h> -#include <string.h> -#include <stdlib.h> -#include <stdio.h> - -int createSharedData(char** id, int size) { - int fd; - char* location = "/tmp/eclipse_%x"; - char* name = malloc(strlen(location) + 9); - sprintf(name, location, getpid()); - if ((fd = shm_open(name, O_RDWR | O_CREAT, 0666 )) == -1) return -1; - if (ftruncate(fd, size) == -1 ) { - shm_unlink(name); - return -1; - } - close( fd ); - if (id != NULL) { - *id = name; - } - return 0; -} - -int destroySharedData(char* id) { - return shm_unlink(id); -} - -int getSharedData(char* id, char** data) { - int fd, length, size; - char *sharedData, *newData = NULL; - if ((fd = shm_open(id, O_RDWR, 0666 )) == -1) return -1; - size = lseek(fd, 0, SEEK_END); - sharedData = mmap( 0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); - if (sharedData != MAP_FAILED) { - if (data != NULL) { - length = strlen(sharedData) + 1; - newData = malloc(length); - memcpy(newData, sharedData, length); - } - munmap(sharedData, size); - } - close(fd); - *data = newData; - return newData == NULL ? -1 : 0; -} - -int setSharedData(char* id, char* data) { - int fd, length, size; - char *sharedData; - if ((fd = shm_open(id, O_RDWR, 0666 )) == -1) return -1; - size = lseek(fd, 0, SEEK_END); - sharedData = mmap( 0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); - if (sharedData != MAP_FAILED) { - if (data != NULL) { - length = strlen(data) + 1; - memcpy(sharedData, data, length); - } else { - memset(sharedData, 0, sizeof(char)); - } - munmap(sharedData, size); - } - close(fd); - return 0; -} - -#else /* Unix like platforms */ - -#include <sys/shm.h> -#include <string.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> - -int createSharedData(char** id, int size) { - int shmid; - key_t key = getpid(); - if ((shmid = shmget(key, size, IPC_CREAT | 0666)) < 0) { - return -1; - } - if (id != NULL) { - *id = malloc(9 * sizeof(char)); - sprintf(*id, "%x", shmid); - } - return 0; -} - -static int getShmID(char* id) { - int shmid = -1; - /* Determine the shared memory id. */ - if (id != NULL && strlen(id) > 0) { - sscanf(id, "%x", &shmid); - } - return shmid; -} - -int destroySharedData(char* id) { - int shmid = getShmID(id); - if (shmid == -1) return -1; - return shmctl(shmid, IPC_RMID, NULL); -} - -int getSharedData( char* id, char** data ) { - char *sharedData, *newData = NULL; - int length; - int shmid = getShmID(id); - if (shmid == -1) return -1; - sharedData = shmat(shmid, (void *)0, 0); - if (sharedData == (char *)(-1)) return -1; - length = strlen(sharedData) + 1; - newData = malloc(length); - memcpy(newData, sharedData, length); - if (shmdt(sharedData) != 0) { - free(newData); - return -1; - } - *data = newData; - return 0; -} - -int setSharedData(char* id, char* data) { - char* sharedData; - int length; - int shmid = getShmID(id); - if (shmid == -1) return -1; - sharedData = shmat(shmid, (void *)0, 0); - if (sharedData == (char *)(-1)) return -1; - if (data != NULL) { - length = strlen(data) + 1; - memcpy(sharedData, data, length); - } else { - memset(sharedData, 0, sizeof(char)); - } - if (shmdt(sharedData) != 0) { - return -1; - } - return 0; -} - -#endif /* Unix like platforms */ diff --git a/bundles/org.eclipse.equinox.launcher/library/eclipseShm.h b/bundles/org.eclipse.equinox.launcher/library/eclipseShm.h deleted file mode 100644 index 861615d4f..000000000 --- a/bundles/org.eclipse.equinox.launcher/library/eclipseShm.h +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Silenio Quarti - *******************************************************************************/ - -#ifndef ECLIPSE_SHM_H -#define ECLIPSE_SHM_H - -#ifdef UNICODE -#define createSharedData createSharedDataW -#define destroySharedData destroySharedDataW -#define getSharedData getSharedDataW -#define setSharedData setSharedDataW -#endif - -/* Shared memory utilities */ - -/** - * Creates and initializes a shared memory segment - * with the specified size in bytes. The id for the - * shared memory segment is stored in the id argument - * and can be used from any process. It must be freed - * with free(). - * - * Returns 0 if success. - */ -extern int createSharedData(_TCHAR** id, int size); - -/** - * Destroy the shared memory segment specified by the - * id argument. The id is the same as the one return - * by createSharedData(). This function must be called - * by the same process that created the segment. - * - * Returns 0 if success. - */ -extern int destroySharedData(_TCHAR* id); - -/** - * Gets a copy of the shared memory segment specified - * by the id argument. The copy is stored in the data - * argument as a null terminated string and must be - * freed by free(). - * - * Returns 0 if success. - */ -extern int getSharedData(_TCHAR* id, _TCHAR** data); - -/** - * Sets the shared memory segment specified by the id - * argument with a null terminated string specified by - * data. - * - * Returns 0 if sucess. - */ -extern int setSharedData(_TCHAR* id, _TCHAR* data); - -#endif /* ECLIPSE_SHM_H */ - - diff --git a/bundles/org.eclipse.equinox.launcher/library/win32/eclipseWin.c b/bundles/org.eclipse.equinox.launcher/library/win32/eclipseWin.c index 35e8089d7..217d43d22 100644 --- a/bundles/org.eclipse.equinox.launcher/library/win32/eclipseWin.c +++ b/bundles/org.eclipse.equinox.launcher/library/win32/eclipseWin.c @@ -46,16 +46,10 @@ static int jvmExitTimeout = 100; static int jvmExitTimerId = 99; /* Define local variables for handling the splash window and its image. */ -static int splashTimerId = 88, inputTimerId = 89; - -static HWND label = NULL, progress = NULL; -static COLORREF foreground = 0; -static RECT progressRect = {0, 0, 0, 0}, messageRect = {0, 0, 0, 0}; -static int value = 0, maximum = 100; +static int splashTimerId = 88; /* Local functions */ static void CALLBACK detectJvmExit( HWND hwnd, UINT uMsg, UINT id, DWORD dwTime ); -static HBITMAP loadSplashImage(_TCHAR *baseDir, _TCHAR *fileName); static void CALLBACK splashTimeout( HWND hwnd, UINT uMsg, UINT id, DWORD dwTime ); static LRESULT WINAPI WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -94,128 +88,6 @@ void initWindowSystem( int* pArgc, _TCHAR* argv[], int showSplash ) SetWindowLong (topWindow, GWL_WNDPROC, (LONG) WndProc); } - -static void readRect(_TCHAR *str, RECT *rect) { - int x, y, width, height; - _TCHAR *temp = str, *comma; - comma = _tcschr(temp, _T(',')); - if (comma == NULL) return; - comma[0] = 0; - x = _ttoi(temp); - temp = comma + 1; - comma = _tcschr(temp, _T(',')); - if (comma == NULL) return; - comma[0] = 0; - y = _ttoi(temp); - temp = comma + 1; - comma = _tcschr(temp, _T(',')); - if (comma == NULL) return; - comma[0] = 0; - width = _ttoi(temp); - temp = comma + 1; - height = _ttoi(temp); - rect->left = x; - rect->top = y; - rect->right = x + width; - rect->bottom = y + height; -} - -static void readColor(_TCHAR *str, COLORREF *color) { - int value = _ttoi(str); - *color = ((value & 0xFF0000) >> 16) | (value & 0xFF00) | ((value & 0xFF) << 16); -} - -static void readInput() { - int available; - FILE *fd = stdin; -#ifdef _UNICODE - WCHAR *buffer1 = NULL; -#endif - char *buffer = NULL; - _TCHAR *equals = NULL, *end, *line; - HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); - available = GetFileSize (hStdin, NULL) - SetFilePointer (hStdin, 0, NULL, FILE_CURRENT); - if (available <= 0) return; - buffer = malloc(available + 1); - if (!ReadFile(hStdin, buffer, available, &available, NULL)) { - return; - } - if (available <= 0) { - free(buffer); - return; - } - buffer[available] = 0; -#ifdef _UNICODE - { - buffer1 = malloc((available + 1) * sizeof(TCHAR)); - available = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPCSTR)buffer, available, (LPWSTR)buffer1, available); - buffer1[available] = 0; - line = buffer1; - } -#else - line = buffer; -#endif - while (line != NULL) { - end = _tcschr(line, _T('\n')); - equals = _tcschr(line, _T('=')); - if (end != NULL) end[0] = 0; - if (equals != NULL) { - _TCHAR *str = (_TCHAR *)equals + 1; - equals[0] = 0; - if (_tcscmp(line, _T("maximum")) == 0) { - maximum = _ttoi(str); - if (progress) { - SendMessage (progress, PBM_SETRANGE32, 0, maximum); - } - } else if (_tcscmp(line, _T("value")) == 0) { - value = _ttoi(str); - if (progress) { - SendMessage (progress, PBM_SETPOS, value, 0); - } - } else if (_tcscmp(line, _T("progressRect")) == 0) { - readRect(str, &progressRect); - if (progress) { - int flags = SWP_NOZORDER | SWP_DRAWFRAME | SWP_NOACTIVATE; - SetWindowPos (progress, 0, progressRect.left, progressRect.top, progressRect.right - progressRect.left, progressRect.bottom - progressRect.top, flags); - } - } else if (_tcscmp(line, _T("messageRect")) == 0) { - readRect(str, &messageRect); - if (label) { - int flags = SWP_NOZORDER | SWP_DRAWFRAME | SWP_NOACTIVATE; - SetWindowPos (label, 0, messageRect.left, messageRect.top, messageRect.right - messageRect.left, messageRect.bottom - messageRect.top, flags); - } - } else if (_tcscmp(line, _T("foreground")) == 0) { - readColor(str, &foreground); - if (label) { - RECT rect; - GetWindowRect (label, &rect); - MapWindowPoints (0, topWindow, (POINT *)&rect, 2); - InvalidateRect (topWindow, &rect, 1); - } - } else if (_tcscmp(line, _T("message")) == 0) { - if (label) { - RECT rect; - SetWindowText (label, str); - GetWindowRect (label, &rect); - MapWindowPoints (0, topWindow, (POINT *)&rect, 2); - InvalidateRect (topWindow, &rect, 1); - } - } - - } - if (end != NULL) line = end + 1; - else line = NULL; - } - free(buffer); -#ifdef _UNICODE - if (buffer1 != NULL) free(buffer1); -#endif -} - -static void CALLBACK timerProc( HWND hwnd, UINT uMsg, UINT id, DWORD dwTime ) { - readInput(); -} - /* Show the Splash Window * * Open the bitmap, insert into the splash window and display it. @@ -252,33 +124,6 @@ int showSplash( _TCHAR* timeoutString, _TCHAR* featureImage ) /* Load the bitmap into the splash popup window. */ SendMessage( topWindow, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hBitmap ); - progress = CreateWindowEx (0, _T("msctls_progress32"), - _T(""), - WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, - 0, - 0, - 0, - 0, - topWindow, - NULL, - GetModuleHandle (NULL), - NULL); - label = CreateWindowEx (0, _T("STATIC"), - _T(""), - WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, - 0, - 0, - 0, - 0, - topWindow, - NULL, - GetModuleHandle (NULL), - NULL); - SendMessage (label, WM_SETFONT, (WPARAM)GetStockObject (DEFAULT_GUI_FONT), (LPARAM)1); - - readInput(); - SetTimer( topWindow, inputTimerId, 50, timerProc ); - /* Centre the splash window and display it. */ GetWindowRect (topWindow, &rect); width = GetSystemMetrics (SM_CXSCREEN); @@ -437,14 +282,24 @@ static LRESULT WINAPI WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPara case WM_CLOSE: PostQuitMessage( 0 ); break; - case WM_CTLCOLORSTATIC: - if ((HWND)lParam == label) { - SetTextColor((HDC)wParam, foreground); - SetBkMode((HDC)wParam, TRANSPARENT); - return (LRESULT)GetStockObject (NULL_BRUSH); - } - break; } return CallWindowProc (oldProc, hwnd, uMsg, wParam, lParam); } +/* Load the specified shared library + */ +void * loadLibrary( _TCHAR * library ){ + return LoadLibrary(library); +} + +/* Unload the shared library + */ +void unloadLibrary( void * handle ){ + FreeLibrary(handle); +} + +/* Find the given symbol in the shared library + */ +void * findSymbol( void * handle, char * symbol ){ + return GetProcAddress(handle, symbol); +} diff --git a/bundles/org.eclipse.equinox.launcher/library/win32/make_mingw.mak b/bundles/org.eclipse.equinox.launcher/library/win32/make_mingw.mak index 5b38f9172..ab9ebb525 100644 --- a/bundles/org.eclipse.equinox.launcher/library/win32/make_mingw.mak +++ b/bundles/org.eclipse.equinox.launcher/library/win32/make_mingw.mak @@ -21,6 +21,11 @@ # DEFAULT_OS_ARCH - the default value of the "-arch" switch # DEFAULT_WS - the default value of the "-ws" switch +#if PROGRAM_OUTPUT is not set, assume eclipse.exe +ifeq ($(PROGRAM_OUTPUT),) + PROGRAM_OUTPUT=eclipse.exe +endif + # Allow for cross-compiling under linux OSTYPE ?= $(shell if uname -s | grep -iq cygwin ; then echo cygwin; else echo linux; fi) ifeq ($(OSTYPE),cygwin) @@ -40,15 +45,15 @@ $(error Unable to find $(CCVER)-pc-cygwin-gcc) endif # Define the object modules to be compiled and flags. -OBJS = eclipse.o eclipseWin.o eclipseShm.o eclipseConfig.o eclipseUtil.o \ - aeclipse.o aeclipseWin.o aeclipseShm.o aeclipseConfig.o aeclipseUtil.o +OBJS = eclipse.o eclipseWin.o eclipseConfig.o eclipseUtil.o eclipseJNI.o\ + aeclipse.o aeclipseWin.o aeclipseConfig.o aeclipseUtil.o aeclipseJNI.o LIBS = -lkernel32 -luser32 -lgdi32 -lcomctl32 -lmsvcrt LDFLAGS = -mwindows -mno-cygwin RES = eclipse.res EXEC = $(PROGRAM_OUTPUT) DEBUG = $(CDEBUG) CFLAGS = -O -s -Wall \ - -I. $(SYSINC) \ + -I. -I$(JAVA_JNI) $(SYSINC) \ -D_WIN32 \ -DWIN32_LEAN_AND_MEAN \ -mno-cygwin @@ -60,36 +65,36 @@ WCFLAGS = -DUNICODE $(ACFLAGS) all: $(EXEC) -eclipse.o: ../eclipseOS.h ../eclipseUnicode.h ../eclipse.c ../eclipseShm.h +eclipse.o: ../eclipseOS.h ../eclipseUnicode.h ../eclipse.c $(CC) $(DEBUG) $(WCFLAGS) -c -o $@ ../eclipse.c eclipseUtil.o: ../eclipseUtil.h ../eclipseUnicode.h ../eclipseUtil.c $(CC) $(DEBUG) $(WCFLAGS) -c -o $@ ../eclipseUtil.c -eclipseShm.o: ../eclipseShm.h ../eclipseUnicode.h ../eclipseShm.c - $(CC) $(DEBUG) $(WCFLAGS) -c -o $@ ../eclipseShm.c - eclipseConfig.o: ../eclipseConfig.h ../eclipseUnicode.h ../eclipseConfig.c $(CC) $(DEBUG) $(WCFLAGS) -c -o $@ ../eclipseConfig.c eclipseWin.o: ../eclipseOS.h ../eclipseUnicode.h eclipseWin.c $(CC) $(DEBUG) $(WCFLAGS) -c -o $@ eclipseWin.c -aeclipse.o: ../eclipseOS.h ../eclipseUnicode.h ../eclipse.c ../eclipseShm.h +eclipseJNI.o: ../eclipseUnicode.h ../eclipseJNI.c + $(CC) $(DEBUG) $(WCFLAGS) -c -o $@ ../eclipseJNI.c + +aeclipse.o: ../eclipseOS.h ../eclipseUnicode.h ../eclipse.c $(CC) $(DEBUG) $(ACFLAGS) -c -o $@ ../eclipse.c aeclipseUtil.o: ../eclipseUtil.h ../eclipseUnicode.h ../eclipseUtil.c $(CC) $(DEBUG) $(ACFLAGS) -c -o $@ ../eclipseUtil.c -aeclipseShm.o: ../eclipseShm.h ../eclipseUnicode.h ../eclipseShm.c - $(CC) $(DEBUG) $(ACFLAGS) -c -o $@ ../eclipseShm.c - aeclipseConfig.o: ../eclipseConfig.h ../eclipseUnicode.h ../eclipseConfig.c $(CC) $(DEBUG) $(ACFLAGS) -c -o $@ ../eclipseConfig.c aeclipseWin.o: ../eclipseOS.h ../eclipseUnicode.h eclipseWin.c $(CC) $(DEBUG) $(ACFLAGS) -c -o $@ eclipseWin.c +aeclipseJNI.o: ../eclipseUnicode.h ../eclipseJNI.c + $(CC) $(DEBUG) $(ACFLAGS) -c -o $@ ../eclipseJNI.c + $(RES): eclipse.rc $(RC) --output-format=coff --include-dir=.. -o $@ $< |