Module: xenomai-jki
Branch: for-upstream
Commit: 368b0bd6663a9aff89cdc2d331460db0b619830d
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=368b0bd6663a9aff89cdc2d331460db0b619830d

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Mar  2 23:22:22 2010 +0100

POSIX: Work around for error code corruption in pthread_cond_[timed]wait

This is the some work around for POSIX as already applied on Native. The
temporary storage of the prologue error in xnthread's errcode is a bit
more fragile here as POSIX services uses this variable for saving errno.
Therefore, user space that makes use of signal handlers should better
migrate to revised syscalls that will be added later on.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 ksrc/skins/posix/syscall.c |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
index 6c3ec3a..59be317 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, epilogue_err;
 
        ucnd = (union __xeno_cond *)__xn_reg_arg1(regs);
        umx = (union __xeno_mutex *)__xn_reg_arg2(regs);
@@ -1560,14 +1560,21 @@ static int __pthread_cond_wait_prologue(struct pt_regs 
*regs)
                                                    &mx.shadow_mutex,
                                                    &count, timed, XN_INFINITE);
 
+       /* Old user space prevents that we can return EINTR (it would loop
+          forever if we did). So drop this error. */
+       cur->errcode = err != EINTR ? err : 0;
+
        if (err == 0 || err == ETIMEDOUT) {
-               err = -pse51_cond_timedwait_epilogue(cur, &cnd.shadow_cond,
-                                                   &mx.shadow_mutex, count);
-               if (err == 0 &&
-                   __xn_safe_copy_to_user((void __user *)
-                                          &umx->shadow_mutex.lockcnt,
-                                          &mx.shadow_mutex.lockcnt,
-                                          sizeof(umx->shadow_mutex.lockcnt)))
+               epilogue_err =
+                       -pse51_cond_timedwait_epilogue(cur, &cnd.shadow_cond,
+                                                      &mx.shadow_mutex,
+                                                      count);
+               if (epilogue_err != 0)
+                       err = epilogue_err;
+               else if (__xn_safe_copy_to_user((void __user *)
+                                               &umx->shadow_mutex.lockcnt,
+                                               &mx.shadow_mutex.lockcnt,
+                                               
sizeof(umx->shadow_mutex.lockcnt)))
                        return -EFAULT;
        }
 
@@ -1618,7 +1625,7 @@ static int __pthread_cond_wait_epilogue(struct pt_regs 
*regs)
                                      sizeof(umx->shadow_mutex.lockcnt)))
                return -EFAULT;
 
-       return err;
+       return err ? err : -cur->errcode;
 }
 
 static int __pthread_cond_signal(struct pt_regs *regs)


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

Reply via email to