Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_FD8896C7303E60BA2F965266BABB1E588009@qq.com>
Date: Mon, 27 May 2024 20:22:42 +0800
From: "IMMING" <2465853002@...com>
To: "musl" <musl@...ts.openwall.com>
Subject: A question about the implementation of pthread_create and start

Hi,&nbsp;I would like to ask a question about the implementation of pthread_create and&nbsp;start (musl v1.2.5)

My question is as follows, here is the code:
-----------------
int&nbsp;__pthread_create(pthread_t&nbsp;*restrict&nbsp;res,&nbsp;const&nbsp;pthread_attr_t&nbsp;*restrict&nbsp;attrp,&nbsp;void&nbsp;*(*entry)(void&nbsp;*),&nbsp;void&nbsp;*restrict&nbsp;arg)

...
	if&nbsp;(ret&nbsp;<&nbsp;0)&nbsp;{ 
		ret&nbsp;=&nbsp;-EAGAIN; 
	}&nbsp;else&nbsp;if&nbsp;(attr._a_sched)&nbsp;{ 
		ret&nbsp;=&nbsp;__syscall(SYS_sched_setscheduler, 
			new-&gt;tid,&nbsp;attr._a_policy,&nbsp;&amp;attr._a_prio); 
		if&nbsp;(a_swap(&amp;args-&gt;control,&nbsp;ret&nbsp;?&nbsp;3&nbsp;:&nbsp;0)&nbsp;==&nbsp;2)  <- line 1 
			__wake(&amp;args-&gt;control,&nbsp;1,&nbsp;1);                    <- line 2 
		if&nbsp;(ret) 
			__wait(&amp;args-&gt;control,&nbsp;0,&nbsp;3,&nbsp;0);                <- line 3
 
	}
...
-----------------
static&nbsp;int&nbsp;start(void&nbsp;*p) 
 ...
	struct&nbsp;start_args&nbsp;*args&nbsp;=&nbsp;p; 
	int&nbsp;state&nbsp;=&nbsp;args-&gt;control; 
	if&nbsp;(state)&nbsp;{ 
		if&nbsp;(a_cas(&amp;args-&gt;control,&nbsp;1,&nbsp;2)&nbsp;==&nbsp;1)           <- line 4 
			__wait(&amp;args-&gt;control,&nbsp;0,&nbsp;2,&nbsp;1);              <- line 5 
		if&nbsp;(args-&gt;control)&nbsp;{ 
			__syscall(SYS_set_tid_address,&nbsp;&amp;args-&gt;control); <- line 6 
			for&nbsp;(;;)&nbsp;__syscall(SYS_exit,&nbsp;0);              <- line 7 
		} 
	} 
	__syscall(SYS_rt_sigprocmask,&nbsp;SIG_SETMASK,&nbsp;&amp;args-&gt;sig_mask,&nbsp;0,&nbsp;_NSIG/8); 
...
-----------------

I think the calling route should be like this:


1.line 4(child thread)
2.line 5(child thread wait)
3.line 1(parent thread&nbsp;if SYS_sched_setscheduler false)
4.line 2(parent thread wake child thread)
5.line 3(parent&nbsp;thread wait if SYS_sched_setscheduler false) <- Problem point
6.line 6(child thread)

7.line 6(child thread exit)



My question is, if SYS_sched_setscheduler returns an error (a non-zero value), the parent thread will remain in a wait state and I have not found a way to wake it, 
which will cause the parent thread to remain stuck in the pthread_create function and unable to return

1.Is my analysis process correct?
2.Is the situation where the parent thread gets stuck in the waite as expected?
Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.