From d743c7745d1fcdf53f9575bf903a6af88b23f776 Mon Sep 17 00:00:00 2001
From: Zebediah Figura <z.figura12@gmail.com>
Date: Sun, 29 Jul 2018 16:53:58 -0500
Subject: [PATCH 77/83] ntdll, server: Specify EFD_SEMAPHORE on the server
 side.

This just makes things cleaner; since we already pass the type to the server
there's no reason to pass this as well.
---
 dlls/ntdll/esync.c  | 20 ++++++--------------
 server/esync.c      | 11 ++++++++---
 server/protocol.def |  1 -
 3 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/dlls/ntdll/esync.c b/dlls/ntdll/esync.c
index 53a93f3cf..4f418b211 100644
--- a/dlls/ntdll/esync.c
+++ b/dlls/ntdll/esync.c
@@ -33,9 +33,6 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
-#ifdef HAVE_SYS_EVENTFD_H
-# include <sys/eventfd.h>
-#endif
 #ifdef HAVE_SYS_MMAN_H
 # include <sys/mman.h>
 #endif
@@ -52,10 +49,6 @@
 #include "ntdll_misc.h"
 #include "esync.h"
 
-#ifndef EFD_SEMAPHORE
-#define EFD_SEMAPHORE 1
-#endif
-
 WINE_DEFAULT_DEBUG_CHANNEL(esync);
 
 int do_esync(void)
@@ -116,7 +109,7 @@ static int shm_addrs_size;  /* length of the allocated shm_addrs array */
 static long pagesize;
 
 static NTSTATUS create_esync( enum esync_type type, HANDLE *handle,
-    ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr, int initval, int flags );
+    ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr, int initval );
 
 void esync_init(void)
 {
@@ -128,7 +121,7 @@ void esync_init(void)
         HANDLE handle;
         NTSTATUS ret;
 
-        ret = create_esync( 0, &handle, 0, NULL, 0, 0 );
+        ret = create_esync( 0, &handle, 0, NULL, 0 );
         if (ret != STATUS_NOT_IMPLEMENTED)
         {
             ERR("Server is running with WINEESYNC but this process is not, please enable WINEESYNC or restart wineserver.\n");
@@ -327,7 +320,7 @@ NTSTATUS esync_close( HANDLE handle )
 }
 
 static NTSTATUS create_esync( enum esync_type type, HANDLE *handle,
-    ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr, int initval, int flags )
+    ACCESS_MASK access, const OBJECT_ATTRIBUTES *attr, int initval )
 {
     NTSTATUS ret;
     data_size_t len;
@@ -346,7 +339,6 @@ static NTSTATUS create_esync( enum esync_type type, HANDLE *handle,
     {
         req->access  = access;
         req->initval = initval;
-        req->flags   = flags;
         req->type    = type;
         wine_server_add_data( req, objattr, len );
         ret = wine_server_call( req );
@@ -438,7 +430,7 @@ NTSTATUS esync_create_semaphore(HANDLE *handle, ACCESS_MASK access,
      * before anyone else can open the object. */
     RtlEnterCriticalSection( &shm_init_section );
 
-    ret = create_esync( ESYNC_SEMAPHORE, handle, access, attr, initial, EFD_SEMAPHORE );
+    ret = create_esync( ESYNC_SEMAPHORE, handle, access, attr, initial );
     if (!ret)
     {
         /* Initialize the shared memory portion.
@@ -539,7 +531,7 @@ NTSTATUS esync_create_event( HANDLE *handle, ACCESS_MASK access,
 
     RtlEnterCriticalSection( &shm_init_section );
 
-    ret = create_esync( type, handle, access, attr, initial, 0 );
+    ret = create_esync( type, handle, access, attr, initial );
 
     if (!ret)
     {
@@ -755,7 +747,7 @@ NTSTATUS esync_create_mutex( HANDLE *handle, ACCESS_MASK access,
 
     RtlEnterCriticalSection( &shm_init_section );
 
-    ret = create_esync( ESYNC_MUTEX, handle, access, attr, initial ? 0 : 1, 0 );
+    ret = create_esync( ESYNC_MUTEX, handle, access, attr, initial ? 0 : 1 );
     if (!ret)
     {
         /* Initialize the shared memory portion. */
diff --git a/server/esync.c b/server/esync.c
index cb4de2daa..f5556e91c 100644
--- a/server/esync.c
+++ b/server/esync.c
@@ -180,7 +180,7 @@ static int type_matches( enum esync_type type1, enum esync_type type2 )
 }
 
 static struct esync *create_esync( struct object *root, const struct unicode_str *name,
-    unsigned int attr, int initval, int flags, enum esync_type type,
+    unsigned int attr, int initval, enum esync_type type,
     const struct security_descriptor *sd )
 {
 #ifdef HAVE_SYS_EVENTFD_H
@@ -190,8 +190,13 @@ static struct esync *create_esync( struct object *root, const struct unicode_str
     {
         if (get_error() != STATUS_OBJECT_NAME_EXISTS)
         {
+            int flags = EFD_CLOEXEC | EFD_NONBLOCK;
+
+            if (type == ESYNC_SEMAPHORE)
+                flags |= EFD_SEMAPHORE;
+
             /* initialize it if it didn't already exist */
-            esync->fd = eventfd( initval, flags | EFD_CLOEXEC | EFD_NONBLOCK );
+            esync->fd = eventfd( initval, flags );
             if (esync->fd == -1)
             {
                 perror( "eventfd" );
@@ -409,7 +414,7 @@ DECL_HANDLER(create_esync)
 
     if (!objattr) return;
 
-    if ((esync = create_esync( root, &name, objattr->attributes, req->initval, req->flags, req->type, sd )))
+    if ((esync = create_esync( root, &name, objattr->attributes, req->initval, req->type, sd )))
     {
         if (get_error() == STATUS_OBJECT_NAME_EXISTS)
             reply->handle = alloc_handle( current->process, esync, req->access, objattr->attributes );
diff --git a/server/protocol.def b/server/protocol.def
index f55da3a0e..220c7c407 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -4046,7 +4046,6 @@ struct handle_info
 @REQ(create_esync)
     unsigned int access;        /* wanted access rights */
     int          initval;       /* initial value */
-    int          flags;         /* flags (EFD_SEMAPHORE or 0) */
     int          type;          /* type of esync object (see below) */
     VARARG(objattr,object_attributes); /* object attributes */
 @REPLY
-- 
2.20.1

