From 4bbce085beb2053fef4cfe3e75a8086a1b2c8c9d Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 13 Feb 2015 15:36:51 -0500 Subject: [PATCH] Implement CreateSemaphoreExA/W Any managed code that touches the ThreadPool is currently crashing when the ThreadPool tries to initialize. This is due to it creating a semaphore via CreateSemaphoreExA/W in the pal, and those functions not being implemented. This commit just implements those functions by delegating to their non-Ex counterparts. With this change, ThreadPool.QueueUserWorkItem, Task.Run, etc. are able to successfully schedule work and have it executed. --- src/pal/inc/pal.h | 11 ++++++++++ src/pal/src/synchobj/semaphore.cpp | 34 ++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index b5ee386516c2..22a4cf21c974 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -1489,6 +1489,17 @@ CreateSemaphoreA( IN LONG lMaximumCount, IN LPCSTR lpName); +PALIMPORT +HANDLE +PALAPI +CreateSemaphoreExA( + IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, + IN LONG lInitialCount, + IN LONG lMaximumCount, + IN LPCSTR lpName, + IN /*_Reserved_*/ DWORD dwFlags, + IN DWORD dwDesiredAccess); + PALIMPORT HANDLE PALAPI diff --git a/src/pal/src/synchobj/semaphore.cpp b/src/pal/src/synchobj/semaphore.cpp index 64905ad48452..a5fe3b89ff3c 100644 --- a/src/pal/src/synchobj/semaphore.cpp +++ b/src/pal/src/synchobj/semaphore.cpp @@ -61,7 +61,7 @@ CAllowedObjectTypes aotSempahore(otiSemaphore); CreateSemaphoreExA Note: -lpSemaphoreAttributes currentely ignored: +lpSemaphoreAttributes currently ignored: -- Win32 object security not supported -- handles to semaphore objects are not inheritable @@ -75,11 +75,20 @@ CreateSemaphoreExA( IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, IN LONG lInitialCount, IN LONG lMaximumCount, - IN LPCSTR lpName) + IN LPCSTR lpName, + IN /*_Reserved_*/ DWORD dwFlags, + IN DWORD dwDesiredAccess) { - // TODO: Implement this! - ERROR("Needs Implementation!!!"); - return NULL; + // dwFlags is reserved and unused, and dwDesiredAccess is currently + // only ever used as SEMAPHORE_ALL_ACCESS. The other parameters + // all map to CreateSemaphoreA. + _ASSERTE(SEMAPHORE_ALL_ACCESS == dwDesiredAccess); + + return CreateSemaphoreA( + lpSemaphoreAttributes, + lInitialCount, + lMaximumCount, + lpName); } /*++ @@ -87,7 +96,7 @@ CreateSemaphoreExA( CreateSemaphoreA Note: - lpSemaphoreAttributes currentely ignored: + lpSemaphoreAttributes currently ignored: -- Win32 object security not supported -- handles to semaphore objects are not inheritable @@ -190,9 +199,16 @@ CreateSemaphoreExW( IN /*_Reserved_*/ DWORD dwFlags, IN DWORD dwDesiredAccess) { - // TODO: Implement this! - ERROR("Needs Implementation!!!"); - return NULL; + // dwFlags is reserved and unused, and dwDesiredAccess is currently + // only ever used as SEMAPHORE_ALL_ACCESS. The other parameters + // all map to CreateSemaphoreW. + _ASSERTE(SEMAPHORE_ALL_ACCESS == dwDesiredAccess); + + return CreateSemaphoreW( + lpSemaphoreAttributes, + lInitialCount, + lMaximumCount, + lpName); } /*++