mirrored from https://gitlab.winehq.org/wine/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathsync.c
More file actions
843 lines (699 loc) · 25.8 KB
/
Copy pathsync.c
File metadata and controls
843 lines (699 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
/*
* Kernel synchronization objects
*
* Copyright 1998 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "wincon.h"
#include "winerror.h"
#include "winnls.h"
#include "winternl.h"
#include "winioctl.h"
#include "ddk/wdm.h"
#include "wine/asm.h"
#include "kernel_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(sync);
static const struct _KUSER_SHARED_DATA *user_shared_data = (struct _KUSER_SHARED_DATA *)0x7ffe0000;
static void get_create_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
SECURITY_ATTRIBUTES *sa, const WCHAR *name )
{
attr->Length = sizeof(*attr);
attr->RootDirectory = 0;
attr->ObjectName = NULL;
attr->Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
attr->SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
attr->SecurityQualityOfService = NULL;
if (name)
{
RtlInitUnicodeString( nameW, name );
attr->ObjectName = nameW;
BaseGetNamedObjectDirectory( &attr->RootDirectory );
}
}
static BOOL get_open_object_attributes( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *nameW,
BOOL inherit, const WCHAR *name )
{
HANDLE dir;
if (!name)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
RtlInitUnicodeString( nameW, name );
BaseGetNamedObjectDirectory( &dir );
InitializeObjectAttributes( attr, nameW, inherit ? OBJ_INHERIT : 0, dir, NULL );
return TRUE;
}
/******************************************************************************
* GetTickCount64 (KERNEL32.@)
*/
ULONGLONG WINAPI DECLSPEC_HOTPATCH GetTickCount64(void)
{
ULONG high, low;
do
{
high = user_shared_data->u.TickCount.High1Time;
low = user_shared_data->u.TickCount.LowPart;
}
while (high != user_shared_data->u.TickCount.High2Time);
/* note: we ignore TickCountMultiplier */
return (ULONGLONG)high << 32 | low;
}
/***********************************************************************
* GetTickCount (KERNEL32.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
{
/* note: we ignore TickCountMultiplier */
return user_shared_data->u.TickCount.LowPart;
}
/***********************************************************************
* RegisterWaitForSingleObject (KERNEL32.@)
*/
BOOL WINAPI RegisterWaitForSingleObject( HANDLE *wait, HANDLE object, WAITORTIMERCALLBACK callback,
void *context, ULONG timeout, ULONG flags )
{
return (*wait = RegisterWaitForSingleObjectEx( object, callback, context, timeout, flags)) != NULL;
}
/***********************************************************************
* UnregisterWait (KERNEL32.@)
*/
BOOL WINAPI UnregisterWait( HANDLE handle )
{
return set_ntstatus( RtlDeregisterWait( handle ));
}
/***********************************************************************
* MakeCriticalSectionGlobal (KERNEL32.@)
*/
void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit )
{
/* let's assume that only one thread at a time will try to do this */
HANDLE sem = crit->LockSemaphore;
if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 );
crit->LockSemaphore = ConvertToGlobalHandle( sem );
if (crit->DebugInfo != (void *)(ULONG_PTR)-1)
RtlFreeHeap( GetProcessHeap(), 0, crit->DebugInfo );
crit->DebugInfo = NULL;
}
/***********************************************************************
* ReinitializeCriticalSection (KERNEL32.@)
*
* Initialise an already used critical section.
*
* PARAMS
* crit [O] Critical section to initialise.
*
* RETURNS
* Nothing.
*/
void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit )
{
if ( !crit->LockSemaphore )
RtlInitializeCriticalSection( crit );
}
/***********************************************************************
* UninitializeCriticalSection (KERNEL32.@)
*
* UnInitialise a critical section after use.
*
* PARAMS
* crit [O] Critical section to uninitialise (destroy).
*
* RETURNS
* Nothing.
*/
void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
{
RtlDeleteCriticalSection( crit );
}
/***********************************************************************
* OpenMutexA (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenMutexW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenMutexW( access, inherit, buffer );
}
/*
* Semaphores
*/
/***********************************************************************
* CreateSemaphoreA (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
{
return CreateSemaphoreExA( sa, initial, max, name, 0, SEMAPHORE_ALL_ACCESS );
}
/***********************************************************************
* CreateSemaphoreExA (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreExA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max,
LPCSTR name, DWORD flags, DWORD access )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateSemaphoreExW( sa, initial, max, NULL, flags, access );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return CreateSemaphoreExW( sa, initial, max, buffer, flags, access );
}
/***********************************************************************
* OpenSemaphoreA (KERNEL32.@)
*/
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenSemaphoreW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenSemaphoreW( access, inherit, buffer );
}
/*
* Jobs
*/
/******************************************************************************
* CreateJobObjectW (KERNEL32.@)
*/
HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES sa, LPCWSTR name )
{
HANDLE ret = 0;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
NTSTATUS status;
get_create_object_attributes( &attr, &nameW, sa, name );
status = NtCreateJobObject( &ret, JOB_OBJECT_ALL_ACCESS, &attr );
if (status == STATUS_OBJECT_NAME_EXISTS)
SetLastError( ERROR_ALREADY_EXISTS );
else
SetLastError( RtlNtStatusToDosError(status) );
return ret;
}
/******************************************************************************
* CreateJobObjectA (KERNEL32.@)
*/
HANDLE WINAPI CreateJobObjectA( LPSECURITY_ATTRIBUTES attr, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateJobObjectW( attr, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return CreateJobObjectW( attr, buffer );
}
/******************************************************************************
* OpenJobObjectW (KERNEL32.@)
*/
HANDLE WINAPI OpenJobObjectW( DWORD access, BOOL inherit, LPCWSTR name )
{
HANDLE ret;
UNICODE_STRING nameW;
OBJECT_ATTRIBUTES attr;
if (!get_open_object_attributes( &attr, &nameW, inherit, name )) return 0;
if (!set_ntstatus( NtOpenJobObject( &ret, access, &attr ))) return 0;
return ret;
}
/******************************************************************************
* OpenJobObjectA (KERNEL32.@)
*/
HANDLE WINAPI OpenJobObjectA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenJobObjectW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenJobObjectW( access, inherit, buffer );
}
/******************************************************************************
* TerminateJobObject (KERNEL32.@)
*/
BOOL WINAPI TerminateJobObject( HANDLE job, UINT exit_code )
{
return set_ntstatus( NtTerminateJobObject( job, exit_code ));
}
/******************************************************************************
* QueryInformationJobObject (KERNEL32.@)
*/
BOOL WINAPI QueryInformationJobObject( HANDLE job, JOBOBJECTINFOCLASS class, LPVOID info,
DWORD len, DWORD *ret_len )
{
return set_ntstatus( NtQueryInformationJobObject( job, class, info, len, ret_len ));
}
/******************************************************************************
* SetInformationJobObject (KERNEL32.@)
*/
BOOL WINAPI SetInformationJobObject( HANDLE job, JOBOBJECTINFOCLASS class, LPVOID info, DWORD len )
{
return set_ntstatus( NtSetInformationJobObject( job, class, info, len ));
}
/******************************************************************************
* AssignProcessToJobObject (KERNEL32.@)
*/
BOOL WINAPI AssignProcessToJobObject( HANDLE job, HANDLE process )
{
return set_ntstatus( NtAssignProcessToJobObject( job, process ));
}
/*
* Timers
*/
/***********************************************************************
* CreateWaitableTimerA (KERNEL32.@)
*/
HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
{
return CreateWaitableTimerExA( sa, name, manual ? CREATE_WAITABLE_TIMER_MANUAL_RESET : 0,
TIMER_ALL_ACCESS );
}
/***********************************************************************
* CreateWaitableTimerExA (KERNEL32.@)
*/
HANDLE WINAPI CreateWaitableTimerExA( SECURITY_ATTRIBUTES *sa, LPCSTR name, DWORD flags, DWORD access )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateWaitableTimerExW( sa, NULL, flags, access );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return CreateWaitableTimerExW( sa, buffer, flags, access );
}
/***********************************************************************
* OpenWaitableTimerA (KERNEL32.@)
*/
HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenWaitableTimerW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenWaitableTimerW( access, inherit, buffer );
}
/***********************************************************************
* DeleteTimerQueue (KERNEL32.@)
*/
BOOL WINAPI DeleteTimerQueue(HANDLE TimerQueue)
{
return DeleteTimerQueueEx(TimerQueue, NULL);
}
/***********************************************************************
* CancelTimerQueueTimer (KERNEL32.@)
*/
BOOL WINAPI CancelTimerQueueTimer(HANDLE queue, HANDLE timer)
{
return DeleteTimerQueueTimer( queue, timer, NULL );
}
/*
* Mappings
*/
/***********************************************************************
* CreateFileMappingA (KERNEL32.@)
*/
HANDLE WINAPI CreateFileMappingA( HANDLE file, SECURITY_ATTRIBUTES *sa, DWORD protect,
DWORD size_high, DWORD size_low, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateFileMappingW( file, sa, protect, size_high, size_low, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return CreateFileMappingW( file, sa, protect, size_high, size_low, buffer );
}
/***********************************************************************
* OpenFileMappingA (KERNEL32.@)
*/
HANDLE WINAPI OpenFileMappingA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenFileMappingW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenFileMappingW( access, inherit, buffer );
}
/*
* Pipes
*/
/***********************************************************************
* CreateNamedPipeA (KERNEL32.@)
*/
HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
DWORD dwPipeMode, DWORD nMaxInstances,
DWORD nOutBufferSize, DWORD nInBufferSize,
DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateNamedPipeW( NULL, dwOpenMode, dwPipeMode, nMaxInstances,
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return INVALID_HANDLE_VALUE;
}
return CreateNamedPipeW( buffer, dwOpenMode, dwPipeMode, nMaxInstances,
nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
}
/***********************************************************************
* WaitNamedPipeA (KERNEL32.@)
*/
BOOL WINAPI WaitNamedPipeA (LPCSTR name, DWORD nTimeOut)
{
WCHAR buffer[MAX_PATH];
if (!name) return WaitNamedPipeW( NULL, nTimeOut );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return FALSE;
}
return WaitNamedPipeW( buffer, nTimeOut );
}
/***********************************************************************
* GetNamedPipeClientProcessId (KERNEL32.@)
*/
BOOL WINAPI GetNamedPipeClientProcessId( HANDLE pipe, ULONG *id )
{
IO_STATUS_BLOCK iosb;
return set_ntstatus( NtFsControlFile( pipe, NULL, NULL, NULL, &iosb,
FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE, (void *)"ClientProcessId",
sizeof("ClientProcessId"), id, sizeof(*id) ));
}
/***********************************************************************
* GetNamedPipeServerProcessId (KERNEL32.@)
*/
BOOL WINAPI GetNamedPipeServerProcessId( HANDLE pipe, ULONG *id )
{
IO_STATUS_BLOCK iosb;
return set_ntstatus( NtFsControlFile( pipe, NULL, NULL, NULL, &iosb,
FSCTL_PIPE_GET_CONNECTION_ATTRIBUTE, (void *)"ServerProcessId",
sizeof("ServerProcessId"), id, sizeof(*id) ));
}
/***********************************************************************
* GetNamedPipeClientSessionId (KERNEL32.@)
*/
BOOL WINAPI GetNamedPipeClientSessionId( HANDLE pipe, ULONG *id )
{
FIXME( "%p, %p\n", pipe, id );
if (!id) return FALSE;
*id = NtCurrentTeb()->Peb->SessionId;
return TRUE;
}
/***********************************************************************
* GetNamedPipeServerSessionId (KERNEL32.@)
*/
BOOL WINAPI GetNamedPipeServerSessionId( HANDLE pipe, ULONG *id )
{
FIXME( "%p, %p\n", pipe, id );
if (!id) return FALSE;
*id = NtCurrentTeb()->Peb->SessionId;
return TRUE;
}
/***********************************************************************
* GetNamedPipeHandleStateA (KERNEL32.@)
*/
BOOL WINAPI GetNamedPipeHandleStateA(
HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
LPSTR lpUsername, DWORD nUsernameMaxSize)
{
WCHAR *username = NULL;
BOOL ret;
WARN("%p %p %p %p %p %p %d: semi-stub\n", hNamedPipe, lpState, lpCurInstances,
lpMaxCollectionCount, lpCollectDataTimeout, lpUsername, nUsernameMaxSize);
if (lpUsername && nUsernameMaxSize &&
!(username = HeapAlloc(GetProcessHeap(), 0, nUsernameMaxSize * sizeof(WCHAR)))) return FALSE;
ret = GetNamedPipeHandleStateW(hNamedPipe, lpState, lpCurInstances, lpMaxCollectionCount,
lpCollectDataTimeout, username, nUsernameMaxSize);
if (ret && username)
WideCharToMultiByte(CP_ACP, 0, username, -1, lpUsername, nUsernameMaxSize, NULL, NULL);
HeapFree(GetProcessHeap(), 0, username);
return ret;
}
/***********************************************************************
* CallNamedPipeA (KERNEL32.@)
*/
BOOL WINAPI CallNamedPipeA(
LPCSTR lpNamedPipeName, LPVOID lpInput, DWORD dwInputSize,
LPVOID lpOutput, DWORD dwOutputSize,
LPDWORD lpBytesRead, DWORD nTimeout)
{
DWORD len;
LPWSTR str = NULL;
BOOL ret;
TRACE("%s %p %d %p %d %p %d\n",
debugstr_a(lpNamedPipeName), lpInput, dwInputSize,
lpOutput, dwOutputSize, lpBytesRead, nTimeout);
if( lpNamedPipeName )
{
len = MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, NULL, 0 );
str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, lpNamedPipeName, -1, str, len );
}
ret = CallNamedPipeW( str, lpInput, dwInputSize, lpOutput,
dwOutputSize, lpBytesRead, nTimeout );
if( lpNamedPipeName )
HeapFree( GetProcessHeap(), 0, str );
return ret;
}
/******************************************************************************
* CreateMailslotA [KERNEL32.@]
*
* See CreateMailslotW.
*/
HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
{
DWORD len;
HANDLE handle;
LPWSTR name = NULL;
TRACE("%s %d %d %p\n", debugstr_a(lpName),
nMaxMessageSize, lReadTimeout, sa);
if( lpName )
{
len = MultiByteToWideChar( CP_ACP, 0, lpName, -1, NULL, 0 );
name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, lpName, -1, name, len );
}
handle = CreateMailslotW( name, nMaxMessageSize, lReadTimeout, sa );
HeapFree( GetProcessHeap(), 0, name );
return handle;
}
/******************************************************************************
* CreateMailslotW [KERNEL32.@]
*
* Create a mailslot with specified name.
*
* PARAMS
* lpName [I] Pointer to string for mailslot name
* nMaxMessageSize [I] Maximum message size
* lReadTimeout [I] Milliseconds before read time-out
* sa [I] Pointer to security structure
*
* RETURNS
* Success: Handle to mailslot
* Failure: INVALID_HANDLE_VALUE
*/
HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
{
HANDLE handle = INVALID_HANDLE_VALUE;
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
LARGE_INTEGER timeout;
IO_STATUS_BLOCK iosb;
TRACE("%s %d %d %p\n", debugstr_w(lpName),
nMaxMessageSize, lReadTimeout, sa);
if (!RtlDosPathNameToNtPathName_U( lpName, &nameW, NULL, NULL ))
{
SetLastError( ERROR_PATH_NOT_FOUND );
return INVALID_HANDLE_VALUE;
}
if (nameW.Length >= MAX_PATH * sizeof(WCHAR) )
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
RtlFreeUnicodeString( &nameW );
return INVALID_HANDLE_VALUE;
}
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.Attributes = OBJ_CASE_INSENSITIVE;
attr.ObjectName = &nameW;
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
attr.SecurityQualityOfService = NULL;
if (lReadTimeout != MAILSLOT_WAIT_FOREVER)
timeout.QuadPart = (ULONGLONG) lReadTimeout * -10000;
else
timeout.QuadPart = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
if (!set_ntstatus( NtCreateMailslotFile( &handle, GENERIC_READ | SYNCHRONIZE, &attr,
&iosb, 0, 0, nMaxMessageSize, &timeout )))
handle = INVALID_HANDLE_VALUE;
RtlFreeUnicodeString( &nameW );
return handle;
}
/******************************************************************************
* GetMailslotInfo [KERNEL32.@]
*
* Retrieve information about a mailslot.
*
* PARAMS
* hMailslot [I] Mailslot handle
* lpMaxMessageSize [O] Address of maximum message size
* lpNextSize [O] Address of size of next message
* lpMessageCount [O] Address of number of messages
* lpReadTimeout [O] Address of read time-out
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*/
BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
LPDWORD lpNextSize, LPDWORD lpMessageCount,
LPDWORD lpReadTimeout )
{
FILE_MAILSLOT_QUERY_INFORMATION info;
IO_STATUS_BLOCK iosb;
TRACE("%p %p %p %p %p\n",hMailslot, lpMaxMessageSize,
lpNextSize, lpMessageCount, lpReadTimeout);
if (!set_ntstatus( NtQueryInformationFile( hMailslot, &iosb, &info, sizeof info,
FileMailslotQueryInformation )))
return FALSE;
if( lpMaxMessageSize )
*lpMaxMessageSize = info.MaximumMessageSize;
if( lpNextSize )
*lpNextSize = info.NextMessageSize;
if( lpMessageCount )
*lpMessageCount = info.MessagesAvailable;
if( lpReadTimeout )
{
if (info.ReadTimeout.QuadPart == (((LONGLONG)0x7fffffff << 32) | 0xffffffff))
*lpReadTimeout = MAILSLOT_WAIT_FOREVER;
else
*lpReadTimeout = info.ReadTimeout.QuadPart / -10000;
}
return TRUE;
}
/******************************************************************************
* SetMailslotInfo [KERNEL32.@]
*
* Set the read timeout of a mailslot.
*
* PARAMS
* hMailslot [I] Mailslot handle
* dwReadTimeout [I] Timeout in milliseconds.
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*/
BOOL WINAPI SetMailslotInfo( HANDLE hMailslot, DWORD dwReadTimeout)
{
FILE_MAILSLOT_SET_INFORMATION info;
IO_STATUS_BLOCK iosb;
TRACE("%p %d\n", hMailslot, dwReadTimeout);
if (dwReadTimeout != MAILSLOT_WAIT_FOREVER)
info.ReadTimeout.QuadPart = (ULONGLONG)dwReadTimeout * -10000;
else
info.ReadTimeout.QuadPart = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
return set_ntstatus( NtSetInformationFile( hMailslot, &iosb, &info, sizeof info,
FileMailslotSetInformation ));
}
/******************************************************************************
* BindIoCompletionCallback (KERNEL32.@)
*/
BOOL WINAPI BindIoCompletionCallback( HANDLE handle, LPOVERLAPPED_COMPLETION_ROUTINE func, ULONG flags )
{
return set_ntstatus( RtlSetIoCompletionCallback( handle, (PRTL_OVERLAPPED_COMPLETION_ROUTINE)func, flags ));
}
#ifdef __i386__
/***********************************************************************
* InterlockedCompareExchange (KERNEL32.@)
*/
/* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
__ASM_STDCALL_FUNC(InterlockedCompareExchange, 12,
"movl 12(%esp),%eax\n\t"
"movl 8(%esp),%ecx\n\t"
"movl 4(%esp),%edx\n\t"
"lock; cmpxchgl %ecx,(%edx)\n\t"
"ret $12")
/***********************************************************************
* InterlockedExchange (KERNEL32.@)
*/
/* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */
__ASM_STDCALL_FUNC(InterlockedExchange, 8,
"movl 8(%esp),%eax\n\t"
"movl 4(%esp),%edx\n\t"
"lock; xchgl %eax,(%edx)\n\t"
"ret $8")
/***********************************************************************
* InterlockedExchangeAdd (KERNEL32.@)
*/
/* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */
__ASM_STDCALL_FUNC(InterlockedExchangeAdd, 8,
"movl 8(%esp),%eax\n\t"
"movl 4(%esp),%edx\n\t"
"lock; xaddl %eax,(%edx)\n\t"
"ret $8")
/***********************************************************************
* InterlockedIncrement (KERNEL32.@)
*/
/* LONG WINAPI InterlockedIncrement( PLONG dest ); */
__ASM_STDCALL_FUNC(InterlockedIncrement, 4,
"movl 4(%esp),%edx\n\t"
"movl $1,%eax\n\t"
"lock; xaddl %eax,(%edx)\n\t"
"incl %eax\n\t"
"ret $4")
/***********************************************************************
* InterlockedDecrement (KERNEL32.@)
*/
__ASM_STDCALL_FUNC(InterlockedDecrement, 4,
"movl 4(%esp),%edx\n\t"
"movl $-1,%eax\n\t"
"lock; xaddl %eax,(%edx)\n\t"
"decl %eax\n\t"
"ret $4")
#endif /* __i386__ */