Bug 456449: checked in some more WinMobile WinCE porting changes from
authorwtc%google.com
Wed, 04 Feb 2009 23:44:01 +0000
changeset 4032 2117b2359c33a6473065aa261ce44038d959a5dc
parent 4031 308ccbdcc8a787f6f7715e84629aa96d43acc0e5
child 4033 271db86d9e6518efa31f3f131b83d873aac74ca3
push idunknown
push userunknown
push dateunknown
bugs456449
Bug 456449: checked in some more WinMobile WinCE porting changes from Brad Lassey <bugmail@lassey.us>. r=wtc. Modified Files: Makefile.in ntsec.c objs.mk w32ipcsem.c w32shm.c w95sock.c w95thred.c
pr/src/md/windows/Makefile.in
pr/src/md/windows/ntsec.c
pr/src/md/windows/objs.mk
pr/src/md/windows/w32ipcsem.c
pr/src/md/windows/w32shm.c
pr/src/md/windows/w95sock.c
pr/src/md/windows/w95thred.c
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -57,17 +57,17 @@ CSRCS = \
     w16io.c  \
     w16gc.c  \
     w16error.c  \
     w16stdio.c  \
     w16callb.c \
     ntinrval.c \
     $(NULL)
 else
-ifeq ($(OS_TARGET), WIN95)
+ifeq (,$(filter-out WIN95 WINCE, $(OS_TARGET)))
 CSRCS =          \
     ntmisc.c \
     ntsec.c   \
     ntsem.c   \
     ntinrval.c \
     ntgc.c \
 	w95thred.c \
 	w95io.c \
--- a/pr/src/md/windows/ntsec.c
+++ b/pr/src/md/windows/ntsec.c
@@ -64,16 +64,19 @@ static struct {
 /*
  * Initialize the SIDs for owner, primary group, and the Everyone
  * group in the _pr_nt_sids structure.
  *
  * This function needs to be called by NSPR initialization.
  */
 void _PR_NT_InitSids(void)
 {
+#ifdef WINCE /* not supported */
+    return;
+#else
     SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
     HANDLE hToken = NULL; /* initialized to an arbitrary value to
                            * silence a Purify UMR warning */
     UCHAR infoBuffer[1024];
     PTOKEN_OWNER pTokenOwner = (PTOKEN_OWNER) infoBuffer;
     PTOKEN_PRIMARY_GROUP pTokenPrimaryGroup
             = (PTOKEN_PRIMARY_GROUP) infoBuffer;
     DWORD dwLength;
@@ -123,36 +126,41 @@ void _PR_NT_InitSids(void)
     PR_ASSERT(rv != 0);
 
     /* Create a well-known SID for the Everyone group. */
     rv = AllocateAndInitializeSid(&SIDAuthWorld, 1,
             SECURITY_WORLD_RID,
             0, 0, 0, 0, 0, 0, 0,
             &_pr_nt_sids.everyone);
     PR_ASSERT(rv != 0);
+#endif
 }
 
 /*
  * Free the SIDs for owner, primary group, and the Everyone group
  * in the _pr_nt_sids structure.
  *
  * This function needs to be called by NSPR cleanup.
  */
 void
 _PR_NT_FreeSids(void)
 {
+#ifdef WINCE
+    return;
+#else
     if (_pr_nt_sids.owner) {
         PR_Free(_pr_nt_sids.owner);
     }
     if (_pr_nt_sids.group) {
         PR_Free(_pr_nt_sids.group);
     }
     if (_pr_nt_sids.everyone) {
         FreeSid(_pr_nt_sids.everyone);
     }
+#endif
 }
 
 /*
  * Construct a security descriptor whose discretionary access-control
  * list implements the specified mode bits.  The SIDs for owner, group,
  * and everyone are obtained from the global _pr_nt_sids structure.
  * Both the security descriptor and access-control list are returned
  * and should be freed by a _PR_NT_FreeSecurityDescriptorACL call.
@@ -163,16 +171,20 @@ void
  */
 PRStatus
 _PR_NT_MakeSecurityDescriptorACL(
     PRIntn mode,
     DWORD accessTable[],
     PSECURITY_DESCRIPTOR *resultSD,
     PACL *resultACL)
 {
+#ifdef WINCE
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return PR_FAILURE;
+#else
     PSECURITY_DESCRIPTOR pSD = NULL;
     PACL pACL = NULL;
     DWORD cbACL;  /* size of ACL */
     DWORD accessMask;
 
     if (_pr_nt_sids.owner == NULL) {
         PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
         return PR_FAILURE;
@@ -256,16 +268,17 @@ PRStatus
 failed:
     if (pSD) {
         PR_Free(pSD);
     }
     if (pACL) {
         PR_Free(pACL);
     }
     return PR_FAILURE;
+#endif
 }
 
 /*
  * Free the specified security descriptor and access-control list
  * previously created by _PR_NT_MakeSecurityDescriptorACL.
  */
 void
 _PR_NT_FreeSecurityDescriptorACL(PSECURITY_DESCRIPTOR pSD, PACL pACL)
--- a/pr/src/md/windows/objs.mk
+++ b/pr/src/md/windows/objs.mk
@@ -46,17 +46,17 @@ CSRCS = ntmisc.c \
 	ntthread.c \
 	ntdllmn.c \
 	win32_errors.c \
 	w32ipcsem.c \
 	w32poll.c \
 	w32rng.c \
 	w32shm.c
 else
-ifeq ($(OS_TARGET),WIN95)
+ifeq (,$(filter-out WIN95 WINCE, $(OS_TARGET)))
 CSRCS =	ntmisc.c \
 	ntsec.c \
 	ntsem.c \
 	ntinrval.c \
 	ntgc.c \
 	w95thred.c \
 	w95io.c \
 	w95cv.c \
--- a/pr/src/md/windows/w32ipcsem.c
+++ b/pr/src/md/windows/w32ipcsem.c
@@ -37,16 +37,40 @@
 
 /*
  * File: w32ipcsem.c
  * Description: implements named semaphores for NT and WIN95.
  */
 
 #include "primpl.h"
 
+#ifdef WINCE
+static HANDLE OpenSemaphore(DWORD inDesiredAccess,
+                            BOOL inInheritHandle,
+                            const char *inName)
+{
+    HANDLE retval = NULL;
+    HANDLE semaphore = NULL;
+    PRUnichar wideName[MAX_PATH];  /* name size is limited to MAX_PATH */
+    
+    MultiByteToWideChar(CP_ACP, 0, inName, -1, wideName, MAX_PATH);
+    /* 0x7fffffff is the max count for our semaphore */
+    semaphore = CreateSemaphoreW(NULL, 0, 0x7fffffff, wideName);
+    if (NULL != semaphore) {
+        DWORD lastErr = GetLastError();
+      
+        if (ERROR_ALREADY_EXISTS != lastErr)
+            CloseHandle(semaphore);
+        else
+            retval = semaphore;
+    }
+    return retval;
+}
+#endif
+
 /*
  * NSPR-to-NT access right mapping table for semaphore objects.
  *
  * The SYNCHRONIZE access is required by WaitForSingleObject.
  * The SEMAPHORE_MODIFY_STATE access is required by ReleaseSemaphore.
  * The OR of these three access masks must equal SEMAPHORE_ALL_ACCESS.
  * This is because if a semaphore object with the specified name
  * exists, CreateSemaphore requests SEMAPHORE_ALL_ACCESS access to
@@ -142,17 +166,26 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
     if (flags & PR_SEM_CREATE) {
         if (_PR_NT_MakeSecurityDescriptorACL(mode, semAccessTable,
                 &pSD, &pACL) == PR_SUCCESS) {
             sa.nLength = sizeof(sa);
             sa.lpSecurityDescriptor = pSD;
             sa.bInheritHandle = FALSE;
             lpSA = &sa;
         }
-        sem->sem = CreateSemaphore(lpSA, value, 0x7fffffff, osname);
+#ifdef WINCE
+        {
+            /* The size of a sem's name is limited to MAX_PATH. */
+            PRUnichar wosname[MAX_PATH]; 
+            MultiByteToWideChar(CP_ACP, 0, osname, -1, wosname, MAX_PATH);
+            sem->sem = CreateSemaphoreW(lpSA, value, 0x7fffffff, wosname);
+        }
+#else
+        sem->sem = CreateSemaphoreA(lpSA, value, 0x7fffffff, osname);
+#endif
         if (lpSA != NULL) {
             _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
         }
         if (sem->sem == NULL) {
             _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
             PR_DELETE(sem);
             return NULL;
         }
--- a/pr/src/md/windows/w32shm.c
+++ b/pr/src/md/windows/w32shm.c
@@ -114,23 +114,42 @@ extern PRSharedMemory * _MD_OpenSharedMe
 
         if (_PR_NT_MakeSecurityDescriptorACL(mode, filemapAccessTable,
                 &pSD, &pACL) == PR_SUCCESS) {
             sa.nLength = sizeof(sa);
             sa.lpSecurityDescriptor = pSD;
             sa.bInheritHandle = FALSE;
             lpSA = &sa;
         }
-        shm->handle = CreateFileMapping(
+#ifdef WINCE
+        {
+            /*
+             * This is assuming that the name will never be larger than
+             * MAX_PATH.  Should we dynamically allocate?
+             */
+            PRUnichar wideIpcName[MAX_PATH];
+            MultiByteToWideChar(CP_ACP, 0, shm->ipcname, -1,
+                                wideIpcName, MAX_PATH);
+            shm->handle = CreateFileMappingW(
+                (HANDLE)-1 ,
+                lpSA,
+                flProtect,
+                dwHi,
+                dwLo,
+                wideIpcName);
+        }
+#else
+        shm->handle = CreateFileMappingA(
             (HANDLE)-1 ,
             lpSA,
             flProtect,
             dwHi,
             dwLo,
             shm->ipcname);
+#endif
         if (lpSA != NULL) {
             _PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
         }
 
         if ( NULL == shm->handle ) {
             PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
                 ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
                     shm->ipcname )); 
@@ -151,17 +170,22 @@ extern PRSharedMemory * _MD_OpenSharedMe
             } else {
                 PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
                     ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
                         shm->ipcname, shm->handle ));
                 return(shm);
             }
         }
     } else {
+#ifdef WINCE
+        PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
+        shm->handle = NULL;  /* OpenFileMapping not supported */
+#else
         shm->handle = OpenFileMapping( FILE_MAP_WRITE, TRUE, shm->ipcname );
+#endif
         if ( NULL == shm->handle ) {
             _PR_MD_MAP_DEFAULT_ERROR( GetLastError());
             PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, 
                 ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
                     shm->ipcname, PR_GetOSError())); 
             PR_FREEIF( shm->ipcname );
             PR_DELETE( shm );
             return(NULL);
--- a/pr/src/md/windows/w95sock.c
+++ b/pr/src/md/windows/w95sock.c
@@ -114,17 +114,17 @@ void _PR_MD_InitSockets(void)
 
     memset(&osvi, 0, sizeof(osvi));
     osvi.dwOSVersionInfoSize = sizeof(osvi);
     GetVersionEx(&osvi);
 
     /* if Vista or later... */
     if (osvi.dwMajorVersion >= 6)
     {
-        libWinsock2 = LoadLibrary("Ws2_32.dll");
+        libWinsock2 = LoadLibraryW(L"Ws2_32.dll");
         if (libWinsock2)
         {
             wsaioctlProc = (WSAIOCTLPROC)GetProcAddress(libWinsock2, 
                                                         "WSAIoctl");
             if (wsaioctlProc)
             {
                 socketSetCompatMode = PR_TRUE;
             }
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -229,35 +229,45 @@ void
 void
 _PR_MD_EXIT(PRIntn status)
 {
     _exit(status);
 }
 
 PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask )
 {
+#ifdef WINCE
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return -1;
+#else
     DWORD_PTR rv;
 
     rv = SetThreadAffinityMask(thread->md.handle, mask);
 
     return rv?0:-1;
+#endif
 }
 
 PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
 {
+#ifdef WINCE
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return -1;
+#else
     BOOL rv;
     DWORD_PTR process_mask;
     DWORD_PTR system_mask;
 
     rv = GetProcessAffinityMask(GetCurrentProcess(),
             &process_mask, &system_mask);
     if (rv)
         *mask = (PRUint32)process_mask;
 
     return rv?0:-1;
+#endif
 }
 
 void 
 _PR_MD_SUSPEND_CPU(_PRCPU *cpu) 
 {
     _PR_MD_SUSPEND_THREAD(cpu->thread);
 }