bug 459629 - Avoid code path with LoadLibraryEx called with LOAD_WITH_ALTERED_SEARCH_PATH in nsGlueLinkingWin for windows ce
authorBrad Lassey <blassey@mozilla.com>
Thu, 22 Jan 2009 22:55:01 -0500
changeset 24099 8672c246d00eeabb98d15045c763e72cc2246c9a
parent 24098 59a7078453b07488ca6ef40c52f232561d6f47b2
child 24100 bd6e3311bfab64678ca7fb88821db7d1c2f2f972
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs459629
milestone1.9.2a1pre
bug 459629 - Avoid code path with LoadLibraryEx called with LOAD_WITH_ALTERED_SEARCH_PATH in nsGlueLinkingWin for windows ce
build/wince/shunt/map.cpp
xulrunner/stub/nsXULStub.cpp
--- a/build/wince/shunt/map.cpp
+++ b/build/wince/shunt/map.cpp
@@ -344,17 +344,19 @@ MOZCE_SHUNT_API unsigned short *_wfullpa
 
   unsigned long len = wcslen(cwd);
   if(!(cwd[len-1] == TCHAR('/') || cwd[len-1] == TCHAR('\\'))&& len< maxLength){
     cwd[len] = TCHAR('\\');
     cwd[++len] = TCHAR('\0');
   }
   if(len+wcslen(relPath) < maxLength){
 #if (_WIN32_WCE > 300)
-    if ( 0 < CeGetCanonicalPathName(wcscat(cwd,relPath), absPath, maxLength, 0) )
+    if ( 0 < CeGetCanonicalPathName(relPath[0] == L'\\'? relPath : 
+                                                         wcscat(cwd,relPath), 
+                                    absPath, maxLength, 0))
       return absPath;
 #else
     #error Need CeGetCanonicalPathName to build.
     // NO ACTUAL CeGetCanonicalPathName function in earlier versions of WinCE
 #endif
   }
   return NULL;
 }
--- a/xulrunner/stub/nsXULStub.cpp
+++ b/xulrunner/stub/nsXULStub.cpp
@@ -256,19 +256,20 @@ main(int argc, char **argv)
 
   // On Linux/Win, look for XULRunner in appdir/xulrunner
 
   snprintf(greDir, sizeof(greDir),
            "%sxulrunner" XPCOM_FILE_PATH_SEPARATOR XPCOM_DLL,
            iniPath);
 
 #ifdef WINCE
-  DWORD fileAttrs = GetFileAttributesW(NS_ConvertUTF8toUTF16(greDir).get());
-  greFound = fileAttrs != INVALID_FILE_ATTRIBUTES && 
-             fileAttrs | FILE_ATTRIBUTE_DIRECTORY;
+  wchar_t wideGreDir[MAX_PATH];
+  MultiByteToWideChar(CP_ACP, 0, greDir, -1, wideGreDir, MAX_PATH);
+  DWORD fileAttrs = GetFileAttributesW(wideGreDir);
+  greFound = fileAttrs != INVALID_FILE_ATTRIBUTES;
 #else
   greFound = (access(greDir, R_OK) == 0);
 #endif
   strncpy(lastSlash, "application.ini", sizeof(iniPath) - (lastSlash - iniPath));
 
 #endif
 
   nsINIParser parser;
@@ -325,16 +326,17 @@ main(int argc, char **argv)
   strcpy(tmpPath, greDir);
   lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR);
   if (lastSlash) {
     *lastSlash = '\0';
   }
   DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH);
 #endif
 
+#ifndef WINCE
   rv = XPCOMGlueStartup(greDir);
   if (NS_FAILED(rv)) {
     Output(PR_TRUE, "Couldn't load XPCOM.\n");
     return 1;
   }
 
   static const nsDynamicFunctionLoad kXULFuncs[] = {
     { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
@@ -381,11 +383,40 @@ main(int argc, char **argv)
     }
 
     retval = XRE_main(argc, argv, appData);
   }
 
   NS_LogTerm();
 
   XPCOMGlueShutdown();
-
+#else
+  // LoadLibraryExW doesn't take the LOAD_WITH_ALTERED_SEARCH_PATH flag, caling
+  // xulrunner.exe from the gre dir sets the library search path correctly.
+  STARTUPINFO si;
+  PROCESS_INFORMATION pi;
+  ZeroMemory(&si, sizeof(si));
+  ZeroMemory(&pi, sizeof(si));
+  si.cb = sizeof(si);
+  wchar_t xrPath[MAX_PATH];
+  MultiByteToWideChar(CP_ACP, 0, greDir, -1, xrPath, MAX_PATH);
+  wchar_t* wLastSlash = wcsrchr(xrPath, PATH_SEPARATOR_CHAR);
+  if (wLastSlash) {
+    *wLastSlash = L'\0';
+  }
+  wcscat(xrPath, L"\\xulrunner.exe");
+  
+  wchar_t wideIniPath[MAX_PATH+2];
+  swprintf(wideIniPath, L"\"%S\"", iniPath);
+  
+  CreateProcessW(xrPath, wideIniPath, NULL, NULL, FALSE, 0, NULL, NULL, 
+                 &si, &pi); 
+  WaitForSingleObject(pi.hProcess, INFINITE);
+  DWORD retval = 0;
+  if (!GetExitCodeProcess(pi.hProcess, &retval))
+    printf("failed to get exit code, error = %d\n", retval = GetLastError());
+  
+  // Close process and thread handles.
+  CloseHandle(pi.hProcess);
+  CloseHandle(pi.hThread);
+#endif
   return retval;
 }