Skip to contentSkip to conversation

Odd posix thread bug in xenomai 2.6.x

Xenomai Lennart Sorensen 2 participants 4 messages Jun 10, 2015

lore
Share & tools
lore
#0 lore raw

I have encountered a kernel crash in the xeno_posix. I end up with a k_tid of 0x0000000c which is of course not valid.

So far I have tracked it down to here:

        /* We need an anonymous registry entry to obtain a handle for fast
           mutex locking. */
        ret = xnthread_register(&thread->threadbase, "");
        if (ret) {
                thread_destroy(thread);
                return ret;
        }

So if xnthread_register fails, it returns -12, but since the callers to pthread_create all expect (as documented) for the return value of pthread_create to be 0 or positive, getting -12 is bad since that is then inverted by the caller to make it negative and returned and is then treated as a valid k_tid which it isn't.

I think -12 means ENOMEM, so clearly I have another config error (or bug) to fix to solve that. But still pthread_create should probably be doing return -ret in this case. I suspect I did something stupid to even hit this case, so quite likely it just hasn't been hit before and hence not noticed.

This is the only place in pthread_create that could return a negative value too.

Signature · 1 line
Len Sorensen
#1 lore raw
Quoted 19 lines · Lennart Sorensen

I have encountered a kernel crash in the xeno_posix. I end up with a k_tid of 0x0000000c which is of course not valid.

So far I have tracked it down to here:

        /* We need an anonymous registry entry to obtain a handle for fast
           mutex locking. */
        ret = xnthread_register(&thread->threadbase, "");
        if (ret) {
                thread_destroy(thread);
                return ret;
        }

So if xnthread_register fails, it returns -12, but since the callers to pthread_create all expect (as documented) for the return value of pthread_create to be 0 or positive, getting -12 is bad since that is then inverted by the caller to make it negative and returned and is then treated as a valid k_tid which it isn't.

Quoted 8 lines

I think -12 means ENOMEM, so clearly I have another config error (or bug) to fix to solve that. But still pthread_create should probably be doing 'return -ret' in this case. I suspect I did something stupid to even hit this case, so quite likely it just hasn't been hit before and hence not noticed.

This is the only place in pthread_create that could return a negative value too.

And I had in fact got the memory settings in xenomai wrong in my new kernel build. I expect once I fix those, I won't get ENOMEM anymore, and hence won't hit this bug anymore. Off to test that.

Signature · 1 line
Len Sorensen
#2 lore raw
Quoted 26 lines · Lennart Sorensen
Quoted 25 lines · Lennart Sorensen

I have encountered a kernel crash in the xeno_posix. I end up with a k_tid of 0x0000000c which is of course not valid.

So far I have tracked it down to here:

        /* We need an anonymous registry entry to obtain a handle for fast
           mutex locking. */
        ret = xnthread_register(&thread->threadbase, "");
        if (ret) {
                thread_destroy(thread);
                return ret;
        }

So if xnthread_register fails, it returns -12, but since the callers to pthread_create all expect (as documented) for the return value of pthread_create to be 0 or positive, getting -12 is bad since that is then inverted by the caller to make it negative and returned and is then treated as a valid k_tid which it isn't.

I think -12 means ENOMEM, so clearly I have another config error (or bug) to fix to solve that. But still pthread_create should probably be doing 'return -ret' in this case. I suspect I did something stupid to even hit this case, so quite likely it just hasn't been hit before and hence not noticed.

Quoted 6 lines
Quoted 2 lines

This is the only place in pthread_create that could return a negative value too.

And I had in fact got the memory settings in xenomai wrong in my new kernel build. I expect once I fix those, I won't get ENOMEM anymore, and hence won't hit this bug anymore. Off to test that.

And the test passed. So fixing the sign of the return code fixes the bug, and fixing the heap size solves the cause of even triggering the bug.

Would you like a proper patch submission, or will someone just fix that line?

Signature · 1 line
Len Sorensen
#3 lore raw
Quoted 39 lines · Lennart Sorensen
Quoted 29 lines · Lennart Sorensen
Quoted 6 lines · Lennart Sorensen

I have encountered a kernel crash in the xeno_posix. I end up with a k_tid of 0x0000000c which is of course not valid.

So far I have tracked it down to here:

        /* We need an anonymous registry entry to obtain a handle for

fast

Quoted 11 lines
           mutex locking. */
        ret = xnthread_register(&thread->threadbase, "");
        if (ret) {
                thread_destroy(thread);
                return ret;
        }

So if xnthread_register fails, it returns -12, but since the callers to pthread_create all expect (as documented) for the return value of pthread_create to be 0 or positive, getting -12 is bad since that is then inverted by the caller to make it negative and returned and is

then

Quoted 3 lines

treated as a valid k_tid which it isn't.

I think -12 means ENOMEM, so clearly I have another config error (or

bug)

Quoted 1 line

to fix to solve that. But still pthread_create should probably be

doing

Quoted 2 lines

'return -ret' in this case. I suspect I did something stupid to even hit this case, so quite likely it just hasn't been hit before and

hence

Quoted 8 lines
Quoted 4 lines

not noticed.

This is the only place in pthread_create that could return a negative value too.

And I had in fact got the memory settings in xenomai wrong in my new kernel build. I expect once I fix those, I won't get ENOMEM anymore, and hence won't hit this bug anymore. Off to test that.

Quoted 6 lines

And the test passed. So fixing the sign of the return code fixes the bug, and fixing the heap size solves the cause of even triggering the bug.

Would you like a proper patch submission, or will someone just fix that line?

Please send a patch.

Signature · 1 line
                    Gilles.