https://git.reactos.org/?p=reactos.git;a=commitdiff;h=18a9993d69b142cfd8da51862a19e3dca4763187

commit 18a9993d69b142cfd8da51862a19e3dca4763187
Author:     Denis Malikov <file...@gmail.com>
AuthorDate: Sun Nov 18 23:51:20 2018 +0700
Commit:     Mark Jansen <mark.jan...@reactos.org>
CommitDate: Thu Aug 15 15:50:59 2019 +0200

    [KERNEL32] implement CreateSemaphoreExW/A and adjust macroses for it
---
 dll/win32/kernel32/client/job.c     |  2 +-
 dll/win32/kernel32/client/synch.c   | 62 ++++++++++++++++++++++++++++++++++---
 dll/win32/kernel32/include/base_x.h |  9 ++----
 dll/win32/kernel32/kernel32.spec    |  4 +--
 4 files changed, 63 insertions(+), 14 deletions(-)

diff --git a/dll/win32/kernel32/client/job.c b/dll/win32/kernel32/client/job.c
index a15944b4234..c40f7fc6654 100644
--- a/dll/win32/kernel32/client/job.c
+++ b/dll/win32/kernel32/client/job.c
@@ -39,7 +39,7 @@ CreateJobObjectW(IN LPSECURITY_ATTRIBUTES lpJobAttributes,
                  IN LPCWSTR lpName)
 {
     /* Create the NT object */
-    CreateNtObjectFromWin32Api(JobObject, JobObject, JOB_OBJECT, 
lpJobAttributes, lpName);
+    CreateNtObjectFromWin32Api(JobObject, JobObject, JOB_OBJECT_ALL_ACCESS, 
lpJobAttributes, lpName);
 }
 
 /*
diff --git a/dll/win32/kernel32/client/synch.c 
b/dll/win32/kernel32/client/synch.c
index 267950fcc1f..f7df2f710a2 100644
--- a/dll/win32/kernel32/client/synch.c
+++ b/dll/win32/kernel32/client/synch.c
@@ -332,7 +332,7 @@ CreateWaitableTimerW(IN LPSECURITY_ATTRIBUTES 
lpTimerAttributes OPTIONAL,
                      IN BOOL bManualReset,
                      IN LPCWSTR lpTimerName OPTIONAL)
 {
-    CreateNtObjectFromWin32Api(WaitableTimer, Timer, TIMER,
+    CreateNtObjectFromWin32Api(WaitableTimer, Timer, TIMER_ALL_ACCESS,
                                lpTimerAttributes,
                                lpTimerName,
                                bManualReset ? NotificationTimer : 
SynchronizationTimer);
@@ -446,13 +446,67 @@ CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES 
lpSemaphoreAttributes  OPTIONAL,
                  IN LONG lMaximumCount,
                  IN LPCWSTR lpName  OPTIONAL)
 {
-    CreateNtObjectFromWin32Api(Semaphore, Semaphore, SEMAPHORE,
+    CreateNtObjectFromWin32Api(Semaphore, Semaphore, SEMAPHORE_ALL_ACCESS,
                                lpSemaphoreAttributes,
                                lpName,
                                lInitialCount,
                                lMaximumCount);
 }
 
+HANDLE
+WINAPI
+DECLSPEC_HOTPATCH
+CreateSemaphoreExW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes  OPTIONAL,
+                   IN LONG lInitialCount,
+                   IN LONG lMaximumCount,
+                   IN LPCWSTR lpName  OPTIONAL,
+                   IN DWORD dwFlags OPTIONAL,
+                   IN DWORD dwDesiredAccess OPTIONAL)
+{
+    CreateNtObjectFromWin32Api(Semaphore, Semaphore, dwDesiredAccess,
+                               lpSemaphoreAttributes,
+                               lpName,
+                               lInitialCount,
+                               lMaximumCount);
+}
+
+HANDLE
+WINAPI
+DECLSPEC_HOTPATCH
+CreateSemaphoreExA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL,
+                   IN LONG lInitialCount,
+                   IN LONG lMaximumCount,
+                   IN LPCSTR lpName  OPTIONAL,
+                   IN DWORD dwFlags OPTIONAL,
+                   IN DWORD dwDesiredAccess OPTIONAL)
+{
+    ConvertAnsiToUnicodePrologue
+    
+    if (!lpName)
+    {
+        return CreateSemaphoreExW(lpSemaphoreAttributes,
+                                  lInitialCount,
+                                  lMaximumCount,
+                                  NULL,
+                                  dwFlags,
+                                  dwDesiredAccess);
+    }
+
+    ConvertAnsiToUnicodeBody(lpName)
+
+    if (NT_SUCCESS(Status))
+    {
+        return CreateSemaphoreExW(lpSemaphoreAttributes,
+                                  lInitialCount,
+                                  lMaximumCount,
+                                  UnicodeCache->Buffer,
+                                  dwFlags,
+                                  dwDesiredAccess);
+    }
+
+    ConvertAnsiToUnicodeEpilogue
+}
+
 /*
  * @implemented
  */
@@ -523,7 +577,7 @@ CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes  
OPTIONAL,
              IN BOOL bInitialOwner,
              IN LPCWSTR lpName  OPTIONAL)
 {
-    CreateNtObjectFromWin32Api(Mutex, Mutant, MUTEX,
+    CreateNtObjectFromWin32Api(Mutex, Mutant, MUTEX_ALL_ACCESS,
                                lpMutexAttributes,
                                lpName,
                                bInitialOwner);
@@ -599,7 +653,7 @@ CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes  
OPTIONAL,
              IN BOOL bInitialState,
              IN LPCWSTR lpName  OPTIONAL)
 {
-    CreateNtObjectFromWin32Api(Event, Event, EVENT,
+    CreateNtObjectFromWin32Api(Event, Event, EVENT_ALL_ACCESS,
                                lpEventAttributes,
                                lpName,
                                bManualReset ? NotificationEvent : 
SynchronizationEvent,
diff --git a/dll/win32/kernel32/include/base_x.h 
b/dll/win32/kernel32/include/base_x.h
index 4db8186f654..7b54bbdd9a2 100644
--- a/dll/win32/kernel32/include/base_x.h
+++ b/dll/win32/kernel32/include/base_x.h
@@ -132,14 +132,9 @@
 // This macro uses the CreateNtObjectFromWin32Api macros from above to create 
an
 // NT object based on the Win32 API settings.
 //
-// Note that it is hardcoded to always use XXX_ALL_ACCESS permissions, which is
-// the behavior up until Vista. When/if the target moves to Vista, the macro 
can
-// be improved to support caller-specified access masks, as the underlying 
macro
-// above does support this.
-//
-#define CreateNtObjectFromWin32Api(obj, ntobj, capsobj, sec, name, ...)        
 \
+#define CreateNtObjectFromWin32Api(obj, ntobj, access, sec, name, ...)         
\
     CreateNtObjectFromWin32ApiPrologue                                         
 \
-    CreateNtObjectFromWin32ApiBody(ntobj, sec, name, capsobj##_ALL_ACCESS, 
##__VA_ARGS__); \
+    CreateNtObjectFromWin32ApiBody(ntobj, sec, name, access, ##__VA_ARGS__); \
     CreateNtObjectFromWin32ApiEpilogue
 
 //
diff --git a/dll/win32/kernel32/kernel32.spec b/dll/win32/kernel32/kernel32.spec
index 6e1506985c0..36122395322 100644
--- a/dll/win32/kernel32/kernel32.spec
+++ b/dll/win32/kernel32/kernel32.spec
@@ -158,8 +158,8 @@
 @ stdcall CreateProcessW(wstr wstr ptr ptr long long ptr wstr ptr ptr)
 @ stdcall CreateRemoteThread(long ptr long ptr long long ptr)
 @ stdcall CreateSemaphoreA(ptr long long str)
-@ stdcall -stub -version=0x600+ CreateSemaphoreExA(ptr long long str long long)
-@ stdcall -stub -version=0x600+ CreateSemaphoreExW(ptr long long wstr long 
long)
+@ stdcall -version=0x600+ CreateSemaphoreExA(ptr long long str long long)
+@ stdcall -version=0x600+ CreateSemaphoreExW(ptr long long wstr long long)
 @ stdcall CreateSemaphoreW(ptr long long wstr)
 @ stdcall -i386 CreateSocketHandle()
 @ stdcall -version=0x600+ CreateSymbolicLinkA(str str long)

Reply via email to