Opened 16 years ago

Closed 16 years ago

#1646 closed bug (invalid)

the pthread_key_create_2-1 posix test invokes the debugger

Reported by: kaoutsis Owned by: bonefish
Priority: normal Milestone: R1
Component: System/Kernel Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

source file is: src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/2-1.c

Attachments (4)

tls-test.cpp (203 bytes ) - added by kaoutsis 16 years ago.
a test to see what tls_get() returns for an unknown key on beos
tls-test2-beos-results.txt (3.2 KB ) - added by kaoutsis 16 years ago.
tls-test2.cpp (294 bytes ) - added by kaoutsis 16 years ago.
the range of key values are from 0 to 69 to this test
tls-test2-haiku-results.txt (3.0 KB ) - added by kaoutsis 16 years ago.
the haiku results: test-app crashes for values bigger than 63

Download all attachments as: .zip

Change History (22)

comment:1 by kaoutsis, 16 years ago

crashes inside in the pthread_getspecific():

[...]
int main()
{
	pthread_key_t key;
	void* rc;

	/* Verify that the value associated with "key" in a new thread is NULL */
	rc = pthread_getspecific(key);
	if(rc != NULL)
	{
		printf("pthread_key_create_2-1 Test FAILED\n");
		return PTS_FAIL;
	}
[...]

comment:2 by kaoutsis, 16 years ago

the problem may be that the program didn't call the pthread_setspecific(), or there is any call to pthread_create() so the thread local store is uninitialized ?

comment:3 by korli, 16 years ago

pthread_getspecific() should return NULL for unknown keys. And tls_get() should do the same. It seems tls_get() doesn't return NULL for unknown keys. Could you check on BeOS ? The bug seems to be in tls_get() which doesn't check the key.

in reply to:  3 ; comment:4 by kaoutsis, 16 years ago

Replying to korli:

pthread_getspecific() should return NULL for unknown keys. And tls_get() should do the same. It seems tls_get() doesn't return NULL for unknown keys. Could you check on BeOS ? The bug seems to be in tls_get() which doesn't check the key.

On beos tls_get() returns NULL for unknown keys, i will attach the tls-test.cpp that ran on beos: $ g++ tls-test.cpp -o tls-test -lroot $ ./tls-test tls_get returns null $

by kaoutsis, 16 years ago

Attachment: tls-test.cpp added

a test to see what tls_get() returns for an unknown key on beos

comment:5 by bonefish, 16 years ago

tls_get()/tls_set() must not be called with an invalid key (they are implemented inline in BeOS, so we can't really do much about this). If the pthreads implementation relies on tls_get() behaving a certain way, it is broken.

That aside, we don't clear the TLS slots upon thread construction, which we probably should do. The related code is in src/system/kernel/arch/x86/arch_thread.c:arch_thread_init_tls(), if anyone wants to do that.

comment:6 by axeld, 16 years ago

Component: - GeneralSystem/Kernel

We shouldn't have to clear the TLS slots since they are put into a clean area (as part of the thread's stack). If they are dirty, some code uses this part early on, and that shouldn't happen.

in reply to:  6 ; comment:7 by bonefish, 16 years ago

Replying to axeld:

We shouldn't have to clear the TLS slots since they are put into a clean area (as part of the thread's stack). If they are dirty, some code uses this part early on, and that shouldn't happen.

Please have a look at arch_thread_init_tls() -- the TLS data are copied from a mostly uninitialized array on the stack. A memset() there will do the trick, but the pthreads issue should probably be looked into first, before it is hidden.

comment:8 by korli, 16 years ago

The test pass successfully with this change. Could you check ?

Index: src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-2.c =================================================================== --- src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-2.c (révision 23000) +++ src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-2.c (copie de travail) @@ -46,7 +46,7 @@

int main() {

pthread_t new_th;

  • void *value_ptr;

+ void *value_ptr = NULL;

/* Create a key */ for(i = 0;i<NUM_OF_THREADS;i++)

in reply to:  8 comment:9 by kaoutsis, 16 years ago

Replying to korli:

The test pass successfully with this change. Could you check ?

Index: src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-2.c =================================================================== --- src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-2.c (révision 23000) +++ src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/pthread_key_create/1-2.c (copie de travail) @@ -46,7 +46,7 @@

int main() {

pthread_t new_th;

  • void *value_ptr;

+ void *value_ptr = NULL;

/* Create a key */ for(i = 0;i<NUM_OF_THREADS;i++)

i checked and it passed, but to be frank, i don't understand what the author wants to achieve. Note that the above fragment of code is from 1-2.c which is the case of #1644 (this is ticket #1646 for the file 2-1.c)

in reply to:  8 ; comment:10 by bonefish, 16 years ago

Replying to korli:

@@ -46,7 +46,7 @@

int main() {

pthread_t new_th;

  • void *value_ptr;

+ void *value_ptr = NULL;

/* Create a key */ for(i = 0;i<NUM_OF_THREADS;i++)

If this changes the behavior, our wait_for_thread() is obviously broken, as it should overwrite value_ptr in each iteration before being checked, so that the initial value should be irrelevant.

in reply to:  10 comment:11 by korli, 16 years ago

Replying to bonefish:

If this changes the behavior, our wait_for_thread() is obviously broken, as it should overwrite value_ptr in each iteration before being checked, so that the initial value should be irrelevant.

Yes, it seems wait_for_thread() doesn't find the thread and doesn't overwrite value_ptr. BTW shouldn't it find the thread death entry ? Or is it too late and it's gone with the thread clean process ?

in reply to:  7 ; comment:12 by axeld, 16 years ago

Replying to bonefish:

Please have a look at arch_thread_init_tls() -- the TLS data are copied from a mostly uninitialized array on the stack. A memset() there will do the trick, but the pthreads issue should probably be looked into first, before it is hidden.

That array is 8 bytes large (2 TLS entries), and is completely initialized and then copied to the TLS array; a memset() wouldn't change anything.

in reply to:  4 ; comment:13 by kaoutsis, 16 years ago

Replying to kaoutsis:

Replying to korli:

pthread_getspecific() should return NULL for unknown keys. And tls_get() should do the same. It seems tls_get() doesn't return NULL for unknown keys. Could you check on BeOS ? The bug seems to be in tls_get() which doesn't check the key.

On beos tls_get() returns NULL for unknown keys, i will attach the tls-test.cpp that ran on beos: $ g++ tls-test.cpp -o tls-test -lroot $ ./tls-test tls_get returns null $

i don't know if this helps: i ran the little test on haiku and returns null also; if this little test is valid to check the returned value of tls_get() for unknown keys?

in reply to:  13 ; comment:14 by korli, 16 years ago

Replying to kaoutsis:

i don't know if this helps: i ran the little test on haiku and returns null also; if this little test is valid to check the returned value of tls_get() for unknown keys?

Maybe try with a value bigger than 64 (TLS_MAX_KEYS).

in reply to:  12 comment:15 by bonefish, 16 years ago

Owner: changed from axeld to bonefish
Status: newassigned

Replying to axeld:

Replying to bonefish:

Please have a look at arch_thread_init_tls() -- the TLS data are copied from a mostly uninitialized array on the stack. A memset() there will do the trick, but the pthreads issue should probably be looked into first, before it is hidden.

That array is 8 bytes large (2 TLS entries), and is completely initialized and then copied to the TLS array; a memset() wouldn't change anything.

My mistake, you're right of course. I wonder why this has been brought up, anyway. Apparently Haiku returns NULL for undefined keys, and the test program doesn't even use undefined keys in the first place.

Indeed wait_for_thread() is broken (and was even before my changes for job control support). When invoked for a thread of the same team that has already gone, it always fails. I suppose we need to introduce a per team list of dead threads. Currently there's only a list for child processes. I'll look into that.

in reply to:  14 ; comment:16 by kaoutsis, 16 years ago

Replying to korli:

Replying to kaoutsis:

i don't know if this helps: i ran the little test on haiku and returns null also; if this little test is valid to check the returned value of tls_get() for unknown keys?

Maybe try with a value bigger than 64 (TLS_MAX_KEYS).

ok, i will attach tls-test2.cpp, and tls-test2-beos-results.txt; briefly: on beos when the key is negative, test crashes, when key is zero, tls_get doesn't return null, and when key is > 0 until value 990 tls_get returns null. Later i will post the haiku results.

by kaoutsis, 16 years ago

Attachment: tls-test2-beos-results.txt added

by kaoutsis, 16 years ago

Attachment: tls-test2.cpp added

the range of key values are from 0 to 69 to this test

by kaoutsis, 16 years ago

Attachment: tls-test2-haiku-results.txt added

the haiku results: test-app crashes for values bigger than 63

in reply to:  16 comment:17 by kaoutsis, 16 years ago

Replying to kaoutsis:

Replying to korli:

Replying to kaoutsis:

i don't know if this helps: i ran the little test on haiku and returns null also; if this little test is valid to check the returned value of tls_get() for unknown keys?

Maybe try with a value bigger than 64 (TLS_MAX_KEYS).

ok, i will attach tls-test2.cpp, and tls-test2-beos-results.txt; briefly: on beos when the key is negative, test crashes, when key is zero, tls_get doesn't return null, and when key is > 0 until value 990 tls_get returns null. Later i will post the haiku results.

i changed the test-app a bit, the range of key values are now from 0 to 69: so for negative values both hrev5 and haiku crashes, for values 0 and 1 both tls_get doesn't return null, for values 2 to 63 on both systems tls_get return null, and for values 64 and up haiku crashes, in the hrev5 instead tls_get() returns null

comment:18 by bonefish, 16 years ago

Resolution: invalid
Status: assignedclosed

The test program is broken. The behavior of a pthread_getspecific() called with an invalid key is undefined as per specification. Commented the bad code block in hrev23010.

Note: See TracTickets for help on using tickets.