Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- wine-rt-1.6.1.orig/dlls/advapi32/service.c
- +++ wine-rt-1.6.1/dlls/advapi32/service.c
- @@ -460,6 +460,11 @@ static BOOL service_run_main_thread(void
- HANDLE wait_handles[MAXIMUM_WAIT_OBJECTS];
- UINT wait_services[MAXIMUM_WAIT_OBJECTS];
- dispatcher_data *disp = HeapAlloc( GetProcessHeap(), 0, sizeof(*disp) );
- + WCHAR en[] = { 's','r','v','t','h','r','d','X','X','X','X',0 };
- + int hashNum;
- + WCHAR *hashLoc = en + 7;
- + unsigned int seed;
- + struct timeval tv;
- disp->manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_CONNECT );
- if (!disp->manager)
- @@ -479,8 +484,22 @@ static BOOL service_run_main_thread(void
- return FALSE;
- }
- - service_event = CreateEventW( NULL, FALSE, FALSE, NULL );
- - stop_event = CreateEventW( NULL, FALSE, FALSE, NULL );
- + // Hash the name to avoid collisions between services.exe and rm-host.exe
- + gettimeofday(&tv, 0);
- + seed = (unsigned int)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
- + while (*hashLoc != 0) {
- + hashNum = (rand_r(&seed) >> 16) % 62;
- + if (hashNum < 10)
- + *hashLoc = '0'+hashNum;
- + else if (hashNum < 36)
- + *hashLoc = 'a'+hashNum-10;
- + else
- + *hashLoc = 'A'+hashNum-36;
- + hashLoc++;
- + }
- +
- + service_event = CreateEventW( NULL, FALSE, FALSE, en );
- + stop_event = CreateEventW( NULL, FALSE, FALSE, en );
- /* FIXME: service_control_dispatcher should be merged into the main thread */
- wait_handles[0] = __wine_make_process_system();
- --- wine-rt-1.6.1.orig/dlls/ntdll/heap.c
- +++ wine-rt-1.6.1/dlls/ntdll/heap.c
- @@ -44,6 +44,7 @@
- #include "wine/list.h"
- #include "wine/debug.h"
- #include "wine/server.h"
- +#include "ntdll_misc.h"
- WINE_DEFAULT_DEBUG_CHANNEL(heap);
- @@ -177,6 +178,8 @@ static HEAP *processHeap; /* main proce
- static BOOL HEAP_IsRealArena( HEAP *heapPtr, DWORD flags, LPCVOID block, BOOL quiet );
- +static PIPEOBJ processHeapSemaphore;
- +
- /* mark a block of memory as free for debugging purposes */
- static inline void mark_block_free( void *ptr, SIZE_T size, DWORD flags )
- {
- @@ -1564,6 +1567,11 @@ HANDLE WINAPI RtlCreateHeap( ULONG flags
- }
- else if (!addr)
- {
- + if (use_pipe_objects()) {
- + init_pipe_object(&processHeapSemaphore, SEMAPHORE_MAGIC, 0);
- + subheap->heap->critSection.LockSemaphore = &processHeapSemaphore;
- + }
- +
- processHeap = subheap->heap; /* assume the first heap we create is the process main heap */
- list_init( &processHeap->entry );
- }
- --- wine-rt-1.6.1.orig/dlls/ntdll/ntdll_misc.h
- +++ wine-rt-1.6.1/dlls/ntdll/ntdll_misc.h
- @@ -185,6 +185,22 @@ extern int ntdll_wcstoumbs(DWORD flags,
- extern int CDECL NTDLL__vsnprintf( char *str, SIZE_T len, const char *format, __ms_va_list args ) DECLSPEC_HIDDEN;
- extern int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_va_list args ) DECLSPEC_HIDDEN;
- +#define EVENT_MAGIC 0x4556
- +#define SEMAPHORE_MAGIC 0x5373
- +#define MUTEX_MAGIC 0x4D55
- +
- +typedef struct _PIPEOBJ
- +{
- + WORD wMagic;
- + int fd[2]; /* Pipe handles */
- + struct _PIPEOBJ* next;
- + struct _PIPEOBJ* prev;
- +} PIPEOBJ, *LPPIPEOBJ;
- +
- +extern NTSTATUS close_pipe_object(HANDLE handle, BOOL freemem);
- +extern NTSTATUS init_pipe_object(LPPIPEOBJ pobj, WORD type, int signaled);
- +extern BOOL use_pipe_objects(void);
- +
- /* load order */
- enum loadorder
- --- wine-rt-1.6.1.orig/dlls/ntdll/om.c
- +++ wine-rt-1.6.1/dlls/ntdll/om.c
- @@ -373,6 +373,9 @@ NTSTATUS close_handle( HANDLE handle )
- */
- NTSTATUS WINAPI NtClose( HANDLE Handle )
- {
- + if (HIWORD(Handle) != 0 && close_pipe_object(Handle, TRUE) == STATUS_SUCCESS && use_pipe_objects())
- + return(STATUS_SUCCESS);
- +
- return close_handle( Handle );
- }
- --- wine-rt-1.6.1.orig/dlls/ntdll/sync.c
- +++ wine-rt-1.6.1/dlls/ntdll/sync.c
- @@ -47,6 +47,8 @@
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- +#include <fcntl.h>
- +
- #define NONAMELESSUNION
- #define NONAMELESSSTRUCT
- @@ -133,6 +135,244 @@ void NTDLL_free_struct_sd(struct securit
- RtlFreeHeap(GetProcessHeap(), 0, server_sd);
- }
- +#define is_pipe_object(h) (h != INVALID_HANDLE_VALUE && HIWORD(h) != 0)
- +#define is_pipe_event(h) (is_pipe_object(h) && ((LPPIPEOBJ)h)->wMagic == EVENT_MAGIC)
- +#define is_pipe_semaphore(h) (is_pipe_object(h) && ((LPPIPEOBJ)h)->wMagic == SEMAPHORE_MAGIC)
- +#define is_pipe_mutex(h) (is_pipe_object(h) && ((LPPIPEOBJ)h)->wMagic == MUTEX_MAGIC)
- +
- +static CRITICAL_SECTION csPipeObjs;
- +static CRITICAL_SECTION_DEBUG critsect_debug =
- +{
- + 0, 0, &csPipeObjs,
- + { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
- + 0, 0, { (DWORD_PTR)(__FILE__ ": csPipeObjs") }
- +};
- +static CRITICAL_SECTION csPipeObjs = { &critsect_debug, -1, 0, 0, 0, 0 };
- +
- +static LPPIPEOBJ pipeobjs;
- +static int pipe_count;
- +
- +/******************************************************************************
- + * use_pipe_objects
- + */
- +BOOL use_pipe_objects(void)
- +{
- + static const char* s_enable_pipe_sync = 0;
- + if (s_enable_pipe_sync == 0) {
- + const char* env;
- + extern int __wine_main_argc;
- + extern char** __wine_main_argv;
- +
- + s_enable_pipe_sync = "0";
- + env = getenv("L_ENABLE_PIPE_SYNC_FOR_APP");
- + if (env) {
- + /* note: PEB command line is not available when this is first called so use main args */
- + if (__wine_main_argc < 2)
- + ERR("bad __wine_main_argc: %d\n", __wine_main_argc);
- + else if (strstr(__wine_main_argv[1], env) != 0) {
- + MESSAGE("Honoring L_ENABLE_PIPE_SYNC_FOR_APP: %s (%s)\n", env, __wine_main_argv[1]);
- + s_enable_pipe_sync = "1";
- + }
- + }
- + }
- + return(*s_enable_pipe_sync != '0');
- +}
- +
- +/******************************************************************************
- + * is_valid_pipe_object
- + */
- +BOOL is_valid_pipe_object(HANDLE handle)
- +{
- + BOOL valid = FALSE;
- + LPPIPEOBJ p = (LPPIPEOBJ) pipeobjs;
- +
- + RtlEnterCriticalSection(&csPipeObjs);
- + while (p)
- + {
- + if (p == handle)
- + {
- + valid = TRUE;
- + break;
- + }
- +
- + p = p->next;
- + }
- + RtlLeaveCriticalSection(&csPipeObjs);
- +
- + TRACE("%p valid=%d\n", handle, valid);
- +
- + return valid;
- +}
- +
- +
- +
- +/******************************************************************************
- + * close_pipe_object
- + */
- +NTSTATUS close_pipe_object(HANDLE handle, BOOL freemem)
- +{
- + NTSTATUS ret = STATUS_SUCCESS;
- +
- + TRACE("%p\n", handle);
- +
- + if (is_valid_pipe_object(handle) &&
- + (is_pipe_event(handle) ||
- + is_pipe_semaphore(handle) ||
- + is_pipe_mutex(handle)))
- +
- + {
- + LPPIPEOBJ pobj = (LPPIPEOBJ) handle;
- +
- + close(pobj->fd[0]);
- + close(pobj->fd[1]);
- + pobj->wMagic = 0;
- +
- + RtlEnterCriticalSection(&csPipeObjs);
- + if (pobj->next)
- + pobj->next->prev = pobj->prev;
- + if (pobj->prev)
- + pobj->prev->next = pobj->next;
- + if (pipeobjs == pobj)
- + pipeobjs = pobj->next;
- + pipe_count--;
- + RtlLeaveCriticalSection(&csPipeObjs);
- +
- + if (freemem)
- + RtlFreeHeap(GetProcessHeap(), 0, pobj);
- + }
- + else
- + ret = STATUS_INVALID_HANDLE;
- +
- + return ret;
- +}
- +
- +
- +/******************************************************************************
- + * wait_for_pipe_object
- + */
- +static NTSTATUS wait_for_pipe_object(LPPIPEOBJ pobj, const LARGE_INTEGER *timeout, int clear)
- +{
- + char c;
- + NTSTATUS ret;
- + struct pollfd pfd;
- + int tm;
- +
- + pfd.fd = pobj->fd[0];
- + pfd.events = POLLIN;
- + pfd.revents = 0;
- +
- + if (!timeout)
- + tm = -1;
- + else
- + tm = (-timeout->QuadPart) / (ULONGLONG)10000;
- +
- + TRACE("%p timeout=%d\n", pobj, tm);
- +
- + if (poll(&pfd, 1, tm) == -1)
- + ret = WAIT_FAILED;
- + else if (pfd.revents & POLLIN)
- + {
- + ret = WAIT_OBJECT_0;
- +
- + TRACE("pipe object signaled before time out\n");
- + if (clear)
- + {
- + if (read(pobj->fd[0], &c, 1) != 1) /* Clear the signal */
- + {
- + ERR("Failed to clear pipe object\n");
- + ret = WAIT_FAILED;
- + }
- + }
- + }
- + else
- + {
- + TRACE("pipe object timed out\n");
- + ret = WAIT_TIMEOUT;
- + }
- +
- + return ret;
- +}
- +
- +
- +static NTSTATUS create_pipe_object(HANDLE *h, WORD type, int signaled)
- +{
- + NTSTATUS ret;
- + LPPIPEOBJ pobj = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(PIPEOBJ));
- +
- + ret = init_pipe_object(pobj, type, signaled);
- + if (ret)
- + RtlFreeHeap(GetProcessHeap(), 0, pobj);
- + else
- + *h = (HANDLE)pobj;
- +
- + return ret;
- +}
- +
- +NTSTATUS init_pipe_object(LPPIPEOBJ pobj, WORD type, int signaled)
- +{
- + NTSTATUS ret = STATUS_SUCCESS;
- +
- + pobj->wMagic = type;
- +
- + if (pipe(pobj->fd) < 0)
- + {
- + ERR("failed to create pipe object\n");
- + return STATUS_NO_MEMORY; /* Most likely reached fd limit */
- + }
- +
- + fcntl(pobj->fd[0], F_SETFL, O_NONBLOCK);
- + fcntl(pobj->fd[1], F_SETFL, O_NONBLOCK);
- +
- + if (signaled)
- + {
- + if (write(pobj->fd[1], "s", 1) != 1)
- + {
- + close_pipe_object(pobj, FALSE);
- + ERR("failed to signal pipe object\n");
- + ret = STATUS_UNSUCCESSFUL;
- + }
- + }
- +
- + if (SUCCEEDED(ret))
- + {
- + RtlEnterCriticalSection(&csPipeObjs);
- + pobj->prev = 0;
- + pobj->next = pipeobjs;
- + if (pipeobjs)
- + pipeobjs->prev = pobj;
- + pipeobjs = pobj;
- + pipe_count++;
- + RtlLeaveCriticalSection(&csPipeObjs);
- + }
- +
- + TRACE("handle=%p type 0x%04x ret=0x%08d pipe count=%d\n", pobj, type, ret, pipe_count);
- +
- + return ret;
- +}
- +
- +
- +static NTSTATUS signal_pipe_object(LPPIPEOBJ pobj)
- +{
- + LARGE_INTEGER timeout;
- +
- + ZeroMemory(&timeout, sizeof(timeout));
- +
- + if (wait_for_pipe_object(pobj, &timeout, 0) == WAIT_TIMEOUT)
- + {
- + if (write(pobj->fd[1], "s", 1) != 1)
- + {
- + ERR("Failed to signal pipe object %p\n", pobj);
- + return STATUS_UNSUCCESSFUL;
- + }
- + /* don't starve other same priority threads on same fd */
- + sched_yield();
- + }
- +
- + TRACE("%p signaled\n", pobj);
- +
- + return STATUS_SUCCESS;
- +}
- +
- /*
- * Semaphores
- */
- @@ -151,6 +391,9 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT P
- struct object_attributes objattr;
- struct security_descriptor *sd = NULL;
- + TRACE("Max Count=%ld InitialCount = %ld\n", MaximumCount, InitialCount);
- +
- +
- if (MaximumCount <= 0 || InitialCount < 0 || InitialCount > MaximumCount)
- return STATUS_INVALID_PARAMETER;
- if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
- @@ -164,19 +407,25 @@ NTSTATUS WINAPI NtCreateSemaphore( OUT P
- if (ret != STATUS_SUCCESS) return ret;
- }
- - SERVER_START_REQ( create_semaphore )
- + if (!len && MaximumCount == 1 && use_pipe_objects())
- {
- - req->access = access;
- - req->attributes = (attr) ? attr->Attributes : 0;
- - req->initial = InitialCount;
- - req->max = MaximumCount;
- - wine_server_add_data( req, &objattr, sizeof(objattr) );
- - if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
- - if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
- - ret = wine_server_call( req );
- - *SemaphoreHandle = wine_server_ptr_handle( reply->handle );
- + ret = create_pipe_object(SemaphoreHandle, SEMAPHORE_MAGIC, InitialCount);
- + }
- + else {
- + SERVER_START_REQ( create_semaphore )
- + {
- + req->access = access;
- + req->attributes = (attr) ? attr->Attributes : 0;
- + req->initial = InitialCount;
- + req->max = MaximumCount;
- + wine_server_add_data( req, &objattr, sizeof(objattr) );
- + if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
- + if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
- + ret = wine_server_call( req );
- + *SemaphoreHandle = wine_server_ptr_handle( reply->handle );
- + }
- + SERVER_END_REQ;
- }
- - SERVER_END_REQ;
- NTDLL_free_struct_sd( sd );
- @@ -229,6 +478,12 @@ NTSTATUS WINAPI NtQuerySemaphore(
- NTSTATUS WINAPI NtReleaseSemaphore( HANDLE handle, ULONG count, PULONG previous )
- {
- NTSTATUS ret;
- +
- + TRACE("%p\n", handle);
- +
- + if (is_pipe_semaphore(handle))
- + return signal_pipe_object((LPPIPEOBJ)handle);
- +
- SERVER_START_REQ( release_semaphore )
- {
- req->handle = wine_server_obj_handle( handle );
- @@ -269,19 +524,27 @@ NTSTATUS WINAPI NtCreateEvent( PHANDLE E
- if (ret != STATUS_SUCCESS) return ret;
- }
- - SERVER_START_REQ( create_event )
- + /* Use pipe for anonymous auto-reset event */
- + if (!len && type != NotificationEvent /* !ManualReset, see req below */ && use_pipe_objects())
- {
- - req->access = DesiredAccess;
- - req->attributes = (attr) ? attr->Attributes : 0;
- - req->manual_reset = (type == NotificationEvent);
- - req->initial_state = InitialState;
- - wine_server_add_data( req, &objattr, sizeof(objattr) );
- - if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
- - if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
- - ret = wine_server_call( req );
- - *EventHandle = wine_server_ptr_handle( reply->handle );
- + ret = create_pipe_object(EventHandle, EVENT_MAGIC, InitialState);
- + }
- + else
- + {
- + SERVER_START_REQ( create_event )
- + {
- + req->access = DesiredAccess;
- + req->attributes = (attr) ? attr->Attributes : 0;
- + req->manual_reset = (type == NotificationEvent);
- + req->initial_state = InitialState;
- + wine_server_add_data( req, &objattr, sizeof(objattr) );
- + if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
- + if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
- + ret = wine_server_call( req );
- + *EventHandle = wine_server_ptr_handle( reply->handle );
- + }
- + SERVER_END_REQ;
- }
- - SERVER_END_REQ;
- NTDLL_free_struct_sd( sd );
- @@ -324,6 +587,11 @@ NTSTATUS WINAPI NtSetEvent( HANDLE handl
- {
- NTSTATUS ret;
- + TRACE("%p\n", handle);
- +
- + if (is_pipe_event(handle))
- + return signal_pipe_object((LPPIPEOBJ)handle);
- +
- /* FIXME: set NumberOfThreadsReleased */
- SERVER_START_REQ( event_op )
- @@ -443,6 +711,8 @@ NTSTATUS WINAPI NtCreateMutant(OUT HANDL
- if (len >= MAX_PATH * sizeof(WCHAR)) return STATUS_NAME_TOO_LONG;
- + TRACE("\n");
- +
- objattr.rootdir = wine_server_obj_handle( attr ? attr->RootDirectory : 0 );
- objattr.sd_len = 0;
- objattr.name_len = len;
- @@ -452,18 +722,25 @@ NTSTATUS WINAPI NtCreateMutant(OUT HANDL
- if (status != STATUS_SUCCESS) return status;
- }
- - SERVER_START_REQ( create_mutex )
- + if (!len && use_pipe_objects())
- {
- - req->access = access;
- - req->attributes = (attr) ? attr->Attributes : 0;
- - req->owned = InitialOwner;
- - wine_server_add_data( req, &objattr, sizeof(objattr) );
- - if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
- - if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
- - status = wine_server_call( req );
- - *MutantHandle = wine_server_ptr_handle( reply->handle );
- + status = create_pipe_object(MutantHandle, MUTEX_MAGIC, !InitialOwner);
- + }
- + else
- + {
- + SERVER_START_REQ( create_mutex )
- + {
- + req->access = access;
- + req->attributes = (attr) ? attr->Attributes : 0;
- + req->owned = InitialOwner;
- + wine_server_add_data( req, &objattr, sizeof(objattr) );
- + if (objattr.sd_len) wine_server_add_data( req, sd, objattr.sd_len );
- + if (len) wine_server_add_data( req, attr->ObjectName->Buffer, len );
- + status = wine_server_call( req );
- + *MutantHandle = wine_server_ptr_handle( reply->handle );
- + }
- + SERVER_END_REQ;
- }
- - SERVER_END_REQ;
- NTDLL_free_struct_sd( sd );
- @@ -504,6 +781,11 @@ NTSTATUS WINAPI NtReleaseMutant( IN HAND
- {
- NTSTATUS status;
- + TRACE("%p\n", handle);
- +
- + if (is_pipe_mutex(handle))
- + return signal_pipe_object((LPPIPEOBJ)handle);
- +
- SERVER_START_REQ( release_mutex )
- {
- req->handle = wine_server_obj_handle( handle );
- @@ -826,7 +1108,22 @@ NTSTATUS WINAPI NtWaitForMultipleObjects
- {
- select_op_t select_op;
- UINT i, flags = SELECT_INTERRUPTIBLE;
- + int j;
- +
- + TRACE("count=%ld handles=%p wait_all=%d alertable=%d timeout=%p %lld\n", count, handles, wait_all, alertable, timeout, timeout ? timeout->QuadPart : -1);
- + if (count == 1 && is_pipe_object(handles[0]))
- + return wait_for_pipe_object((LPPIPEOBJ)*handles, timeout, 1);
- + for (j = 0; j < count; ++j) {
- + if (is_pipe_object(handles[j])) {
- + static int s_once = 1;
- + if (s_once) {
- + ERR("Cannot wait on both pipe objects and multiple objects (only warning!); j=%d, count=%d, handle=%x\n", j, count, (unsigned int) handles[j]);
- + s_once = 0;
- + }
- + return STATUS_INVALID_PARAMETER_2;
- + }
- + }
- if (!count || count > MAXIMUM_WAIT_OBJECTS) return STATUS_INVALID_PARAMETER_1;
- if (alertable) flags |= SELECT_ALERTABLE;
- --- wine-rt-1.6.1.orig/dlls/rpcrt4/rpc_transport.c
- +++ wine-rt-1.6.1/dlls/rpcrt4/rpc_transport.c
- @@ -637,9 +637,30 @@ typedef struct _RpcServerProtseq_np
- static RpcServerProtseq *rpcrt4_protseq_np_alloc(void)
- {
- + WCHAR n[] = { 'r','p','c','m','e','X','X','X','X',0 };
- RpcServerProtseq_np *ps = HeapAlloc(GetProcessHeap(), 0, sizeof(*ps));
- + int hashNum;
- + WCHAR *hashLoc = n + 5;
- + unsigned int seed;
- + struct timeval tv;
- +
- + // Hash the name to avoid collisions between services.exe and rm-host.exe
- + gettimeofday(&tv, 0);
- + seed = (unsigned int)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
- + while (*hashLoc != 0) {
- + hashNum = (rand_r(&seed) >> 16) % 62;
- + if (hashNum < 10)
- + *hashLoc = '0'+hashNum;
- + else if (hashNum < 36)
- + *hashLoc = 'a'+hashNum-10;
- + else
- + *hashLoc = 'A'+hashNum-36;
- + hashLoc++;
- + }
- +
- if (ps)
- - ps->mgr_event = CreateEventW(NULL, FALSE, FALSE, NULL);
- + ps->mgr_event = CreateEventW(NULL, FALSE, FALSE, n);
- +
- return &ps->common;
- }
- --- wine-rt-1.6.1.orig/programs/winedevice/device.c
- +++ wine-rt-1.6.1/programs/winedevice/device.c
- @@ -286,11 +286,12 @@ static DWORD WINAPI service_handler( DWO
- static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
- {
- + WCHAR en[] = { 'w','d','s','e',0 };
- SERVICE_STATUS status;
- WINE_TRACE( "starting service %s\n", wine_dbgstr_w(driver_name) );
- - stop_event = CreateEventW( NULL, TRUE, FALSE, NULL );
- + stop_event = CreateEventW( NULL, TRUE, FALSE, en );
- service_handle = RegisterServiceCtrlHandlerExW( driver_name, service_handler, NULL );
- if (!service_handle)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement