Gilles Chanteperdrix wrote:
> Hi,
> 
> it seems that rt_task_shadow currently leaves the self tsd assigned (and
> uninitialized) in case of error. So, here is an attempt to fix this
> situation:

Good point.

> 
> Index: src/skins/native/task.c
> ===================================================================
> --- src/skins/native/task.c     (revision 4727)
> +++ src/skins/native/task.c     (working copy)
> @@ -187,15 +187,8 @@
> 
>  #ifdef HAVE___THREAD
>         self = &__native_self;
> -#else /* !HAVE___THREAD */
> -       self = pthread_getspecific(__native_tskey);
> +#endif /* HAVE___THREAD */
> 
> -       if (!self)
> -               self = malloc(sizeof(*self));
> -
> -       pthread_setspecific(__native_tskey, self);
> -#endif /* !HAVE___THREAD */
> -
>         if (task == NULL)
>                 task = &task_desc; /* Discarded. */
> 
> @@ -217,9 +210,13 @@
>                                 NULL);
> 
>         if (!err) {
> -               if (self)
> -                       *self = *task;
> +#ifndef HAVE___THREAD
> +               self = malloc(sizeof(*self));

Hmm, this creates a potential relaxation point (and may raise SIGXCPU if
the warn flag is set). I would prefer to keep early allocation and
release the chunk properly on error (as well as reset the tsd).

> 
> +               pthread_setspecific(__native_tskey, self);
> +#endif /* !HAVE___THREAD */
> +               *self = *task;

And if self is NULL, ie. malloc failed for whatever obscure reasons? The
existing code skipped over this, maybe we should actually handle it and
return an error code.

> +
>                 xeno_set_current();
> 
>                 if (mode & T_WARNSW)
> 
> 

Jan

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core

Reply via email to