From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Henri Roosen <henriroosen@gmail.com>
Cc: Xenomai <xenomai@xenomai.org>
Subject: Re: [Xenomai] kernel NULL pointer dereference
Date: Wed, 05 Sep 2012 22:38:21 +0200 [thread overview]
Message-ID: <5047B83D.5030403@xenomai.org> (raw)
In-Reply-To: <5047A68D.3020001@xenomai.org>
On 09/05/2012 09:22 PM, Gilles Chanteperdrix wrote:
> On 09/05/2012 02:25 PM, Gilles Chanteperdrix wrote:
>
>> On 09/05/2012 02:10 PM, Henri Roosen wrote:
>>> I will find out why the application is doing a sys_exit. However I'm
>>> not sure how this is related to the thread affinity; when not setting
>>> the affinity, the problem is not reproducable.
>>
>> Thanks for the trace. When we find the bug we will say, of course, that
>> is the reason! Anyway, at first sight, the bug does not seem related to
>> multi-processor, I would say the difference with affinity is a
>> difference in how the cleanup happens in your application (namely the
>> case where a mutex holder is destroyed while another thread which is
>> waiting for the mutex is still alive).
>
>
> Indeed, the bug is reproducible on any UP board with the following
> test case. With RPI enabled, the NULL user_task pointer is a problem in
> RPI handling functions, but with RPI disabled, I get the same backtrace
> as you.
The real test code, which really triggers the bug
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <pthread.h>
#include <semaphore.h>
pthread_mutex_t mutex;
sem_t ready;
void locker(void)
{
pthread_set_name_np(pthread_self(), "locker");
pthread_mutex_lock(&mutex);
sem_post(&ready);
}
void waiter(void)
{
pthread_set_name_np(pthread_self(), "waiter");
sem_wait(&ready);
pthread_mutex_lock(&mutex);
}
void *thread(void *cookie)
{
locker();
sleep(1);
return cookie;
}
int main(void)
{
pthread_mutexattr_t mattr;
struct sched_param sp;
pthread_t tid;
int rc;
mlockall(MCL_CURRENT | MCL_FUTURE);
pthread_mutexattr_init(&mattr);
pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
rc = pthread_mutex_init(&mutex, &mattr);
pthread_mutexattr_destroy(&mattr);
if (rc) {
fprintf(stderr, "pthread_mutex_init: %s\n", strerror(rc));
return 1;
}
rc = sem_init(&ready, 0, 0);
if (rc) {
perror("sem_init");
return 1;
}
rc = pthread_create(&tid, NULL, thread, NULL);
if (rc) {
fprintf(stderr, "pthread_create: %s\n", strerror(rc));
return 1;
}
sp.sched_priority = 99;
pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp);
waiter();
return 0;
}
--
Gilles.
next prev parent reply other threads:[~2012-09-05 20:38 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-04 13:42 [Xenomai] kernel NULL pointer dereference Henri Roosen
2012-09-04 14:10 ` Gilles Chanteperdrix
2012-09-04 14:28 ` Henri Roosen
2012-09-04 18:33 ` Gilles Chanteperdrix
2012-09-04 18:43 ` Gilles Chanteperdrix
2012-09-08 6:18 ` Gilles Chanteperdrix
2012-09-04 19:21 ` Gilles Chanteperdrix
2012-09-05 7:26 ` Henri Roosen
2012-09-05 7:28 ` Gilles Chanteperdrix
2012-09-05 7:42 ` Henri Roosen
2012-09-05 8:28 ` Gilles Chanteperdrix
2012-09-05 9:29 ` Henri Roosen
2012-09-05 11:03 ` Gilles Chanteperdrix
2012-09-05 11:21 ` Gilles Chanteperdrix
2012-09-05 12:10 ` Henri Roosen
2012-09-05 12:25 ` Gilles Chanteperdrix
2012-09-05 19:22 ` Gilles Chanteperdrix
2012-09-05 20:38 ` Gilles Chanteperdrix [this message]
2012-09-06 8:40 ` Henri Roosen
2012-09-06 8:57 ` Gilles Chanteperdrix
2012-09-06 14:33 ` Henri Roosen
2012-09-06 18:47 ` Gilles Chanteperdrix
2012-09-05 20:14 ` Gilles Chanteperdrix
2012-09-08 10:41 ` Philippe Gerum
2012-09-08 10:43 ` Gilles Chanteperdrix
2012-09-08 11:57 ` Gilles Chanteperdrix
2012-09-08 12:10 ` Philippe Gerum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5047B83D.5030403@xenomai.org \
--to=gilles.chanteperdrix@xenomai.org \
--cc=henriroosen@gmail.com \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.