All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai-core <xenomai@xenomai.org>
Subject: [Xenomai-core] [Xenomai-git] posix: fix pthread_cond_*wait return value overwriting
Date: Mon, 08 Mar 2010 18:28:57 +0100	[thread overview]
Message-ID: <4B9533D9.7050203@domain.hid> (raw)
In-Reply-To: <mailman.4536.1268063545.8399.xenomai-git@xenomai.org>

xenomai-git-request@domain.hid wrote:
> diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
> index 6c3ec3a..2a97a2d 100644
> --- a/ksrc/skins/posix/syscall.c
> +++ b/ksrc/skins/posix/syscall.c
> @@ -1520,7 +1520,7 @@ static int __pthread_cond_wait_prologue(struct pt_regs *regs)
>  	union __xeno_mutex mx, *umx;
>  	unsigned timed, count;
>  	struct timespec ts;
> -	int err;
> +	int err, perr = 0;
>  
>  	ucnd = (union __xeno_cond *)__xn_reg_arg1(regs);
>  	umx = (union __xeno_mutex *)__xn_reg_arg2(regs);
> @@ -1560,7 +1560,10 @@ static int __pthread_cond_wait_prologue(struct pt_regs *regs)
>  						    &mx.shadow_mutex,
>  						    &count, timed, XN_INFINITE);
>  
> -	if (err == 0 || err == ETIMEDOUT) {
> +	switch(err) {
> +	case 0:
> +	case ETIMEDOUT:
> +		perr = errno = err;
>  		err = -pse51_cond_timedwait_epilogue(cur, &cnd.shadow_cond,
>  					    	    &mx.shadow_mutex, count);
>  		if (err == 0 &&
> @@ -1569,14 +1572,20 @@ static int __pthread_cond_wait_prologue(struct pt_regs *regs)
>  					   &mx.shadow_mutex.lockcnt,
>  					   sizeof(umx->shadow_mutex.lockcnt)))
>  			return -EFAULT;
> +		break;
> +
> +	case EINTR:
> +		perr = err;

Minor cleanup: This is not needed as err != 0, so perr will not be
evaluated anymore. Same for native.

> +		errno = 0;	/* epilogue should return 0. */
> +		break;
>  	}
>  
> -	if (err == EINTR
> -	    && __xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs),
> -				      &count, sizeof(count)))
> +	if (err == EINTR 
> +	    &&__xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs),
> +				     &count, sizeof(count)))
>  			return -EFAULT;
> -	
> -	return -err;
> +
> +	return err == 0 ? -perr : -err;
>  }
>  
>  /* pthread_cond_wait_epilogue(cond, mutex, count) */

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux


       reply	other threads:[~2010-03-08 17:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.4536.1268063545.8399.xenomai-git@xenomai.org>
2010-03-08 17:28 ` Jan Kiszka [this message]
2010-03-08 17:31   ` [Xenomai-core] [Xenomai-git] posix: fix pthread_cond_*wait return value overwriting Jan Kiszka
2010-03-08 17:35   ` Gilles Chanteperdrix
2010-03-08 17:39     ` Jan Kiszka
2010-03-08 17:47       ` Gilles Chanteperdrix

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=4B9533D9.7050203@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --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.