2121 * Protected by sigio_lock(), also used by sigio_cleanup, which is an
2222 * exitcall.
2323 */
24- static int write_sigio_pid = -1 ;
25- static unsigned long write_sigio_stack ;
24+ static struct os_helper_thread * write_sigio_td ;
2625
2726/*
2827 * These arrays are initialized before the sigio thread is started, and
@@ -48,15 +47,15 @@ static struct pollfds current_poll;
4847static struct pollfds next_poll ;
4948static struct pollfds all_sigio_fds ;
5049
51- static int write_sigio_thread (void * unused )
50+ static void * write_sigio_thread (void * unused )
5251{
5352 struct pollfds * fds , tmp ;
5453 struct pollfd * p ;
5554 int i , n , respond_fd ;
5655 char c ;
5756
58- os_set_pdeathsig ();
59- os_fix_helper_signals ();
57+ os_fix_helper_thread_signals ();
58+
6059 fds = & current_poll ;
6160 while (1 ) {
6261 n = poll (fds -> poll , fds -> used , -1 );
@@ -98,7 +97,7 @@ static int write_sigio_thread(void *unused)
9897 }
9998 }
10099
101- return 0 ;
100+ return NULL ;
102101}
103102
104103static int need_poll (struct pollfds * polls , int n )
@@ -152,11 +151,10 @@ static void update_thread(void)
152151 return ;
153152 fail :
154153 /* 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 ;
158157 }
159- write_sigio_pid = -1 ;
160158 close (sigio_private [0 ]);
161159 close (sigio_private [1 ]);
162160 close (write_sigio_fds [0 ]);
@@ -220,7 +218,7 @@ int __ignore_sigio_fd(int fd)
220218 * sigio_cleanup has already run, then update_thread will hang
221219 * or fail because the thread is no longer running.
222220 */
223- if (write_sigio_pid == -1 )
221+ if (! write_sigio_td )
224222 return - EIO ;
225223
226224 for (i = 0 ; i < current_poll .used ; i ++ ) {
@@ -279,14 +277,14 @@ static void write_sigio_workaround(void)
279277 int err ;
280278 int l_write_sigio_fds [2 ];
281279 int l_sigio_private [2 ];
282- int l_write_sigio_pid ;
280+ struct os_helper_thread * l_write_sigio_td ;
283281
284282 /* We call this *tons* of times - and most ones we must just fail. */
285283 sigio_lock ();
286- l_write_sigio_pid = write_sigio_pid ;
284+ l_write_sigio_td = write_sigio_td ;
287285 sigio_unlock ();
288286
289- if (l_write_sigio_pid != -1 )
287+ if (l_write_sigio_td )
290288 return ;
291289
292290 err = os_pipe (l_write_sigio_fds , 1 , 1 );
@@ -312,7 +310,7 @@ static void write_sigio_workaround(void)
312310 * Did we race? Don't try to optimize this, please, it's not so likely
313311 * to happen, and no more than once at the boot.
314312 */
315- if (write_sigio_pid != -1 )
313+ if (write_sigio_td )
316314 goto out_free ;
317315
318316 current_poll = ((struct pollfds ) { .poll = p ,
@@ -325,18 +323,15 @@ static void write_sigio_workaround(void)
325323 memcpy (write_sigio_fds , l_write_sigio_fds , sizeof (l_write_sigio_fds ));
326324 memcpy (sigio_private , l_sigio_private , sizeof (l_sigio_private ));
327325
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 )
333328 goto out_clear ;
334329
335330 sigio_unlock ();
336331 return ;
337332
338333out_clear :
339- write_sigio_pid = -1 ;
334+ write_sigio_td = NULL ;
340335 write_sigio_fds [0 ] = -1 ;
341336 write_sigio_fds [1 ] = -1 ;
342337 sigio_private [0 ] = -1 ;
@@ -394,12 +389,11 @@ void maybe_sigio_broken(int fd)
394389
395390static void sigio_cleanup (void )
396391{
397- if (write_sigio_pid == -1 )
392+ if (! write_sigio_td )
398393 return ;
399394
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 ;
403397}
404398
405399__uml_exitcall (sigio_cleanup );
0 commit comments