21
21
* Protected by sigio_lock(), also used by sigio_cleanup, which is an
22
22
* exitcall.
23
23
*/
24
- static int write_sigio_pid = -1 ;
25
- static unsigned long write_sigio_stack ;
24
+ static struct os_helper_thread * write_sigio_td ;
26
25
27
26
/*
28
27
* These arrays are initialized before the sigio thread is started, and
@@ -48,15 +47,15 @@ static struct pollfds current_poll;
48
47
static struct pollfds next_poll ;
49
48
static struct pollfds all_sigio_fds ;
50
49
51
- static int write_sigio_thread (void * unused )
50
+ static void * write_sigio_thread (void * unused )
52
51
{
53
52
struct pollfds * fds , tmp ;
54
53
struct pollfd * p ;
55
54
int i , n , respond_fd ;
56
55
char c ;
57
56
58
- os_set_pdeathsig ();
59
- os_fix_helper_signals ();
57
+ os_fix_helper_thread_signals ();
58
+
60
59
fds = & current_poll ;
61
60
while (1 ) {
62
61
n = poll (fds -> poll , fds -> used , -1 );
@@ -98,7 +97,7 @@ static int write_sigio_thread(void *unused)
98
97
}
99
98
}
100
99
101
- return 0 ;
100
+ return NULL ;
102
101
}
103
102
104
103
static int need_poll (struct pollfds * polls , int n )
@@ -152,11 +151,10 @@ static void update_thread(void)
152
151
return ;
153
152
fail :
154
153
/* Critical section start */
155
- if (write_sigio_pid != -1 ) {
156
- os_kill_process ( write_sigio_pid , 1 );
157
- free_stack ( write_sigio_stack , 0 ) ;
154
+ if (write_sigio_td ) {
155
+ os_kill_helper_thread ( write_sigio_td );
156
+ write_sigio_td = NULL ;
158
157
}
159
- write_sigio_pid = -1 ;
160
158
close (sigio_private [0 ]);
161
159
close (sigio_private [1 ]);
162
160
close (write_sigio_fds [0 ]);
@@ -220,7 +218,7 @@ int __ignore_sigio_fd(int fd)
220
218
* sigio_cleanup has already run, then update_thread will hang
221
219
* or fail because the thread is no longer running.
222
220
*/
223
- if (write_sigio_pid == -1 )
221
+ if (! write_sigio_td )
224
222
return - EIO ;
225
223
226
224
for (i = 0 ; i < current_poll .used ; i ++ ) {
@@ -279,14 +277,14 @@ static void write_sigio_workaround(void)
279
277
int err ;
280
278
int l_write_sigio_fds [2 ];
281
279
int l_sigio_private [2 ];
282
- int l_write_sigio_pid ;
280
+ struct os_helper_thread * l_write_sigio_td ;
283
281
284
282
/* We call this *tons* of times - and most ones we must just fail. */
285
283
sigio_lock ();
286
- l_write_sigio_pid = write_sigio_pid ;
284
+ l_write_sigio_td = write_sigio_td ;
287
285
sigio_unlock ();
288
286
289
- if (l_write_sigio_pid != -1 )
287
+ if (l_write_sigio_td )
290
288
return ;
291
289
292
290
err = os_pipe (l_write_sigio_fds , 1 , 1 );
@@ -312,7 +310,7 @@ static void write_sigio_workaround(void)
312
310
* Did we race? Don't try to optimize this, please, it's not so likely
313
311
* to happen, and no more than once at the boot.
314
312
*/
315
- if (write_sigio_pid != -1 )
313
+ if (write_sigio_td )
316
314
goto out_free ;
317
315
318
316
current_poll = ((struct pollfds ) { .poll = p ,
@@ -325,18 +323,15 @@ static void write_sigio_workaround(void)
325
323
memcpy (write_sigio_fds , l_write_sigio_fds , sizeof (l_write_sigio_fds ));
326
324
memcpy (sigio_private , l_sigio_private , sizeof (l_sigio_private ));
327
325
328
- write_sigio_pid = run_helper_thread (write_sigio_thread , NULL ,
329
- CLONE_FILES | CLONE_VM ,
330
- & write_sigio_stack );
331
-
332
- if (write_sigio_pid < 0 )
326
+ err = os_run_helper_thread (& write_sigio_td , write_sigio_thread , NULL );
327
+ if (err < 0 )
333
328
goto out_clear ;
334
329
335
330
sigio_unlock ();
336
331
return ;
337
332
338
333
out_clear :
339
- write_sigio_pid = -1 ;
334
+ write_sigio_td = NULL ;
340
335
write_sigio_fds [0 ] = -1 ;
341
336
write_sigio_fds [1 ] = -1 ;
342
337
sigio_private [0 ] = -1 ;
@@ -394,12 +389,11 @@ void maybe_sigio_broken(int fd)
394
389
395
390
static void sigio_cleanup (void )
396
391
{
397
- if (write_sigio_pid == -1 )
392
+ if (! write_sigio_td )
398
393
return ;
399
394
400
- os_kill_process (write_sigio_pid , 1 );
401
- free_stack (write_sigio_stack , 0 );
402
- write_sigio_pid = -1 ;
395
+ os_kill_helper_thread (write_sigio_td );
396
+ write_sigio_td = NULL ;
403
397
}
404
398
405
399
__uml_exitcall (sigio_cleanup );
0 commit comments