-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0038-server-ntdll-Add-a-do_ntsync-helper.patch
258 lines (229 loc) · 8.4 KB
/
0038-server-ntdll-Add-a-do_ntsync-helper.patch
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
From 4028a9a20bf5d7ac015a5ce710abee11999d842f Mon Sep 17 00:00:00 2001
From: William Horvath <[email protected]>
Date: Fri, 28 Feb 2025 22:55:27 -0800
Subject: [PATCH] server, ntdll: Add a do_ntsync helper.
Also add WINENTSYNC=0 as a shorthand for WINE_DISABLE_FAST_SYNC=1.
---
dlls/ntdll/unix/esync.c | 3 +-
dlls/ntdll/unix/fsync.c | 3 +-
dlls/ntdll/unix/sync.c | 13 +++++++
dlls/ntdll/unix/unix_private.h | 1 +
server/esync.c | 3 +-
server/fsync.c | 3 +-
server/inproc_sync.c | 64 ++++++++++++++++++++++++----------
server/main.c | 5 +--
server/object.h | 1 +
9 files changed, 66 insertions(+), 30 deletions(-)
diff --git a/dlls/ntdll/unix/esync.c b/dlls/ntdll/unix/esync.c
index 245f158881e..f0629434cc7 100644
--- a/dlls/ntdll/unix/esync.c
+++ b/dlls/ntdll/unix/esync.c
@@ -61,8 +61,7 @@ NTSTATUS WINAPI do_esync(void)
static int do_esync_cached = -1;
if (do_esync_cached == -1)
- do_esync_cached = !(getenv("WINEESYNC") && !atoi(getenv("WINEESYNC"))) && !do_fsync() &&
- getenv( "WINE_DISABLE_FAST_SYNC" ) && atoi( getenv( "WINE_DISABLE_FAST_SYNC" ) );
+ do_esync_cached = !(getenv("WINEESYNC") && !atoi(getenv("WINEESYNC"))) && !do_fsync() && !do_ntsync();
return do_esync_cached;
#else
diff --git a/dlls/ntdll/unix/fsync.c b/dlls/ntdll/unix/fsync.c
index 254a5c19208..56f915b4ccf 100644
--- a/dlls/ntdll/unix/fsync.c
+++ b/dlls/ntdll/unix/fsync.c
@@ -160,8 +160,7 @@ NTSTATUS WINAPI do_fsync(void)
if (do_fsync_cached == -1)
{
syscall( __NR_futex_waitv, NULL, 0, 0, NULL, 0 );
- do_fsync_cached = errno != ENOSYS && !(getenv("WINEFSYNC") && !atoi(getenv("WINEFSYNC"))) &&
- getenv( "WINE_DISABLE_FAST_SYNC" ) && atoi( getenv( "WINE_DISABLE_FAST_SYNC" ) );
+ do_fsync_cached = errno != ENOSYS && !(getenv("WINEFSYNC") && !atoi(getenv("WINEFSYNC"))) && !do_ntsync();
}
return do_fsync_cached;
diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c
index 0116f4f6aa1..479ed0cd786 100644
--- a/dlls/ntdll/unix/sync.c
+++ b/dlls/ntdll/unix/sync.c
@@ -1219,6 +1219,14 @@ static NTSTATUS inproc_signal_and_wait( HANDLE signal, HANDLE wait,
return ret;
}
+int do_ntsync(void)
+{
+ static int do_ntsync_cached = -1;
+ if (do_ntsync_cached == -1)
+ do_ntsync_cached = (get_linux_sync_device() >= 0);
+ return do_ntsync_cached;
+}
+
#else
void close_inproc_sync_obj( HANDLE handle )
@@ -1277,6 +1285,11 @@ static NTSTATUS inproc_signal_and_wait( HANDLE signal, HANDLE wait,
return STATUS_NOT_IMPLEMENTED;
}
+int do_ntsync(void)
+{
+ return 0;
+}
+
#endif
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index 89d1b05f5c5..8970cbf1be9 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -399,6 +399,7 @@ extern NTSTATUS wow64_wine_spawnvp( void *args );
extern void dbg_init(void);
extern void close_inproc_sync_obj( HANDLE handle );
+extern int do_ntsync(void);
extern NTSTATUS call_user_apc_dispatcher( CONTEXT *context_ptr, ULONG_PTR arg1, ULONG_PTR arg2, ULONG_PTR arg3,
PNTAPCFUNC func, NTSTATUS status );
diff --git a/server/esync.c b/server/esync.c
index fa73a4651ee..abf454ec100 100644
--- a/server/esync.c
+++ b/server/esync.c
@@ -51,8 +51,7 @@ int do_esync(void)
static int do_esync_cached = -1;
if (do_esync_cached == -1)
- do_esync_cached = !(getenv("WINEESYNC") && !atoi(getenv("WINEESYNC"))) && !do_fsync() &&
- getenv( "WINE_DISABLE_FAST_SYNC" ) && atoi( getenv( "WINE_DISABLE_FAST_SYNC" ) );
+ do_esync_cached = !(getenv("WINEESYNC") && !atoi(getenv("WINEESYNC"))) && !do_fsync() && !do_ntsync();
return do_esync_cached;
#else
diff --git a/server/fsync.c b/server/fsync.c
index 229e3b8aa9c..3d14810e101 100644
--- a/server/fsync.c
+++ b/server/fsync.c
@@ -59,8 +59,7 @@ int do_fsync(void)
if (do_fsync_cached == -1)
{
syscall( __NR_futex_waitv, 0, 0, 0, 0, 0);
- do_fsync_cached = errno != ENOSYS && !(getenv("WINEFSYNC") && !atoi(getenv("WINEFSYNC"))) &&
- getenv( "WINE_DISABLE_FAST_SYNC" ) && atoi( getenv( "WINE_DISABLE_FAST_SYNC" ) );
+ do_fsync_cached = errno != ENOSYS && !(getenv("WINEFSYNC") && !atoi(getenv("WINEFSYNC"))) && !do_ntsync();
}
return do_fsync_cached;
diff --git a/server/inproc_sync.c b/server/inproc_sync.c
index 10a4d0e2538..9562e4fc581 100644
--- a/server/inproc_sync.c
+++ b/server/inproc_sync.c
@@ -126,12 +126,31 @@ static enum server_fd_type inproc_sync_get_fd_type( struct fd *fd )
return FD_TYPE_FILE;
}
+static int get_ntsync_fd(void)
+{
+ int fd = open( "/dev/ntsync", O_CLOEXEC | O_RDONLY );
+ if (fd == -1)
+ {
+ static int once;
+ file_set_error();
+ if (!once++) fprintf( stderr, "Cannot open /dev/ntsync: %s\n", strerror( errno ) );
+ return 0;
+ }
+ return fd;
+}
+
static struct linux_device *get_linux_device(void)
{
struct linux_device *device;
static int initialized;
int unix_fd;
+ if (!do_ntsync())
+ {
+ set_error( STATUS_NOT_IMPLEMENTED );
+ return NULL;
+ }
+
if (initialized)
{
if (linux_device_object)
@@ -141,24 +160,7 @@ static struct linux_device *get_linux_device(void)
return linux_device_object;
}
- if (getenv( "WINE_DISABLE_FAST_SYNC" ) && atoi( getenv( "WINE_DISABLE_FAST_SYNC" ) ))
- {
- static int once;
- set_error( STATUS_NOT_IMPLEMENTED );
- if (!once++) fprintf(stderr, "ntsync is explicitly disabled.\n");
- initialized = 1;
- return NULL;
- }
-
- unix_fd = open( "/dev/ntsync", O_CLOEXEC | O_RDONLY );
- if (unix_fd == -1)
- {
- static int once;
- file_set_error();
- if (!once++) fprintf(stderr, "Cannot open /dev/ntsync: %s\n", strerror(errno));
- initialized = 1;
- return NULL;
- }
+ if (!(unix_fd = get_ntsync_fd())) return NULL;
if (!(device = alloc_object( &linux_device_ops )))
{
@@ -181,6 +183,26 @@ static struct linux_device *get_linux_device(void)
return device;
}
+int do_ntsync(void)
+{
+ static int do_ntsync_cached = -1;
+ if (do_ntsync_cached == -1)
+ {
+ int temp_fd;
+ do_ntsync_cached = 1;
+ if ((getenv( "WINE_DISABLE_FAST_SYNC" ) && atoi( getenv( "WINE_DISABLE_FAST_SYNC" ) )) ||
+ (getenv( "WINENTSYNC" ) && !atoi( getenv( "WINENTSYNC" ) )))
+ {
+ fprintf( stderr, "ntsync is explicitly disabled.\n" );
+ do_ntsync_cached = 0;
+ }
+ /* lightweight permission check, full get_linux_device breaks when done at early startup */
+ else if ((temp_fd = get_ntsync_fd())) close( temp_fd );
+ else do_ntsync_cached = 0;
+ }
+ return do_ntsync_cached;
+}
+
struct inproc_sync
{
struct object obj;
@@ -402,6 +424,12 @@ void abandon_inproc_mutex( thread_id_t tid, struct inproc_sync *inproc_sync )
{
}
+int do_ntsync(void)
+{
+ set_error( STATUS_NOT_IMPLEMENTED );
+ return 0;
+}
+
#endif
DECL_HANDLER(get_linux_sync_device)
diff --git a/server/main.c b/server/main.c
index 0cd24e25b22..5a198d13423 100644
--- a/server/main.c
+++ b/server/main.c
@@ -230,8 +230,6 @@ int main( int argc, char *argv[] )
sock_init();
open_master_socket();
- if (getenv( "WINE_DISABLE_FAST_SYNC" ) && atoi( getenv( "WINE_DISABLE_FAST_SYNC" ) ))
- {
if (do_fsync())
fsync_init();
@@ -239,9 +237,8 @@ int main( int argc, char *argv[] )
if (do_esync())
esync_init();
- if (!do_fsync() && !do_esync())
+ if (!do_fsync() && !do_esync() && !do_ntsync())
fprintf( stderr, "wineserver: using server-side synchronization.\n" );
- }
if (debug_level) fprintf( stderr, "wineserver: starting (pid=%ld)\n", (long) getpid() );
set_current_time();
diff --git a/server/object.h b/server/object.h
index ce8242036d3..27927528d24 100644
--- a/server/object.h
+++ b/server/object.h
@@ -257,6 +257,7 @@ extern struct inproc_sync *create_inproc_semaphore( unsigned int count, unsigned
extern void set_inproc_event( struct inproc_sync *obj );
extern void reset_inproc_event( struct inproc_sync *obj );
extern void abandon_inproc_mutex( thread_id_t tid, struct inproc_sync *inproc_sync );
+extern int do_ntsync(void);
extern struct inproc_sync *no_get_inproc_sync( struct object *obj );
--
2.48.1