Bug 456449: checked in WinMobile WinCE porting changes from Brad Lassey
authorwtc%google.com
Fri, 06 Feb 2009 00:52:53 +0000
changeset 4039 8289c462d6c8186658d373711289435b738fc9b7
parent 4038 47994da012de5066c1947f8e94ec55cd67ae208e
child 4040 5009233fa4a363424960a18b9b601c0f548420ae
push idunknown
push userunknown
push dateunknown
bugs456449
Bug 456449: checked in WinMobile WinCE porting changes from Brad Lassey <bugmail@lassey.us>. r=wtc.
pr/src/md/windows/ntmisc.c
--- a/pr/src/md/windows/ntmisc.c
+++ b/pr/src/md/windows/ntmisc.c
@@ -82,18 +82,20 @@ PRIntn _PR_MD_PUT_ENV(const char *name)
  *-----------------------------------------------------------------------
  */
 
 PR_IMPLEMENT(PRTime)
 PR_Now(void)
 {
     PRTime prt;
     FILETIME ft;
+    SYSTEMTIME st;
 
-    GetSystemTimeAsFileTime(&ft);
+    GetSystemTime(&st);
+    SystemTimeToFileTime(&st, &ft);
     _PR_FileTimeToPRTime(&ft, &prt);
     return prt;       
 }
 
 /*
  ***********************************************************************
  ***********************************************************************
  *
@@ -231,17 +233,29 @@ static int assembleEnvBlock(char **envp,
     char *cwdStart, *cwdEnd;
     size_t envBlockSize;
 
     if (envp == NULL) {
         *envBlock = NULL;
         return 0;
     }
 
+#ifdef WINCE
+    {
+        PRUnichar *wideCurEnv = mozce_GetEnvString();
+        int len = WideCharToMultiByte(CP_ACP, 0, wideCurEnv, -1,
+                                      NULL, 0, NULL, NULL);
+        curEnv = (char *) PR_MALLOC(len * sizeof(char));
+        WideCharToMultiByte(CP_ACP, 0, wideCurEnv, -1,
+                            curEnv, len, NULL, NULL);
+        free(wideCurEnv);
+    }
+#else
     curEnv = GetEnvironmentStrings();
+#endif
 
     cwdStart = curEnv;
     while (*cwdStart) {
         if (cwdStart[0] == '=' && cwdStart[1] != '\0'
                 && cwdStart[2] == ':' && cwdStart[3] == '=') {
             break;
         }
         cwdStart += strlen(cwdStart) + 1;
@@ -261,25 +275,33 @@ static int assembleEnvBlock(char **envp,
 
     for (env = envp; *env; env++) {
         envBlockSize += strlen(*env) + 1;
     }
     envBlockSize++;
 
     p = *envBlock = PR_MALLOC((PRUint32) envBlockSize);
     if (p == NULL) {
+#ifdef WINCE
+        PR_Free(curEnv);
+#else
         FreeEnvironmentStrings(curEnv);
+#endif
         return -1;
     }
 
     q = cwdStart;
     while (q < cwdEnd) {
         *p++ = *q++;
     }
+#ifdef WINCE
+    PR_Free(curEnv);
+#else
     FreeEnvironmentStrings(curEnv);
+#endif
 
     for (env = envp; *env; env++) {
         q = *env;
         while (*q) {
             *p++ = *q++;
         }
         *p++ = '\0';
     }
@@ -297,17 +319,24 @@ static int compare(const void *arg1, con
 }
 
 PRProcess * _PR_CreateWindowsProcess(
     const char *path,
     char *const *argv,
     char *const *envp,
     const PRProcessAttr *attr)
 {
+#ifdef WINCE
+    STARTUPINFOW startupInfo;
+    PRUnichar *wideCmdLine;
+    PRUnichar *wideCwd;
+    int len = 0;
+#else
     STARTUPINFO startupInfo;
+#endif
     PROCESS_INFORMATION procInfo;
     BOOL retVal;
     char *cmdLine = NULL;
     char *envBlock = NULL;
     char **newEnvp = NULL;
     const char *cwd = NULL; /* current working directory */
     PRProcess *proc = NULL;
     PRBool hasFdInheritBuffer;
@@ -318,16 +347,17 @@ PRProcess * _PR_CreateWindowsProcess(
         goto errorExit;
     }
 
     if (assembleCmdLine(argv, &cmdLine) == -1) {
         PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
         goto errorExit;
     }
 
+#ifndef WINCE
     /*
      * If attr->fdInheritBuffer is not NULL, we need to insert
      * it into the envp array, so envp cannot be NULL.
      */
     hasFdInheritBuffer = (attr && attr->fdInheritBuffer);
     if ((envp == NULL) && hasFdInheritBuffer) {
         envp = environ;
     }
@@ -387,17 +417,46 @@ PRProcess * _PR_CreateWindowsProcess(
             startupInfo.hStdError = (HANDLE) attr->stderrFd->secret->md.osfd;
             redirected = PR_TRUE;
         }
         if (redirected) {
             startupInfo.dwFlags |= STARTF_USESTDHANDLES;
         }
         cwd = attr->currentDirectory;
     }
+#endif
 
+#ifdef WINCE
+    len = MultiByteToWideChar(CP_ACP, 0, cmdLine, -1, NULL, 0);
+    wideCmdLine = (PRUnichar *)PR_MALLOC(len * sizeof(PRUnichar));
+    MultiByteToWideChar(CP_ACP, 0, cmdLine, -1, wideCmdLine, len);
+    len = MultiByteToWideChar(CP_ACP, 0, cwd, -1, NULL, 0);
+    wideCwd = PR_MALLOC(len * sizeof(PRUnichar));
+    MultiByteToWideChar(CP_ACP, 0, cwd, -1, wideCwd, len);
+    retVal = CreateProcessW(NULL,
+                            wideCmdLine,
+                            NULL,  /* security attributes for the new
+                                    * process */
+                            NULL,  /* security attributes for the primary
+                                    * thread in the new process */
+                            TRUE,  /* inherit handles */
+                            0,     /* creation flags */
+                            envBlock,  /* an environment block, consisting
+                                        * of a null-terminated block of
+                                        * null-terminated strings.  Each
+                                        * string is in the form:
+                                        *     name=value
+                                        * XXX: usually NULL */
+                            wideCwd,  /* current drive and directory */
+                            &startupInfo,
+                            &procInfo
+                           );
+    PR_Free(wideCmdLine);
+    PR_Free(wideCwd);
+#else
     retVal = CreateProcess(NULL,
                            cmdLine,
                            NULL,  /* security attributes for the new
                                    * process */
                            NULL,  /* security attributes for the primary
                                    * thread in the new process */
                            TRUE,  /* inherit handles */
                            0,     /* creation flags */
@@ -406,16 +465,18 @@ PRProcess * _PR_CreateWindowsProcess(
                                        * null-terminated strings.  Each
                                        * string is in the form:
                                        *     name=value
                                        * XXX: usually NULL */
                            cwd,  /* current drive and directory */
                            &startupInfo,
                            &procInfo
                           );
+#endif
+
     if (retVal == FALSE) {
         /* XXX what error code? */
         PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
         goto errorExit;
     }
 
     CloseHandle(procInfo.hThread);
     proc->md.handle = procInfo.hProcess;
@@ -598,18 +659,24 @@ PRStatus _MD_CreateFileMap(PRFileMap *fm
     if (fmap->prot == PR_PROT_READONLY) {
         flProtect = PAGE_READONLY;
         fmap->md.dwAccess = FILE_MAP_READ;
     } else if (fmap->prot == PR_PROT_READWRITE) {
         flProtect = PAGE_READWRITE;
         fmap->md.dwAccess = FILE_MAP_WRITE;
     } else {
         PR_ASSERT(fmap->prot == PR_PROT_WRITECOPY);
+#ifdef WINCE
+        /* WINCE does not have FILE_MAP_COPY. */
+        PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+        return PR_FAILURE;
+#else
         flProtect = PAGE_WRITECOPY;
         fmap->md.dwAccess = FILE_MAP_COPY;
+#endif
     }
 
     fmap->md.hFileMap = CreateFileMapping(
         (HANDLE) osfd,
         NULL,
         flProtect,
         dwHi,
         dwLo,