posix: fix pthread_cond_*wait return value overwriting
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 26 lines · [email protected] wrote:
ksrc/skins/posix/syscall.c +5
-2@@ -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 &&
ksrc/skins/posix/syscall.c static int __pthread_cond_wait_prologue(struct pt_regs *regs) · line 1578
Quoted 7 lines
ksrc/skins/posix/syscall.c +4
-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.
Quoted 8 lines
ksrc/skins/posix/syscall.c +3
-3+ 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
ksrc/skins/posix/syscall.c static int __pthread_cond_wait_prologue(struct pt_regs *regs) · line 1591
Quoted 10 lines
ksrc/skins/posix/syscall.c +4
-2+ &&__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
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 29 lines · Jan Kiszka
Quoted 28 lines · [email protected] wrote:
ksrc/skins/posix/syscall.c +5
-2@@ -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)))
Quoted 8 lines
ksrc/skins/posix/syscall.c static int __pthread_cond_wait_prologue(struct pt_regs *regs) · line 1578
Quoted 5 lines
ksrc/skins/posix/syscall.c +4
-0return -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.
In fact, you could even limit perr = err to "case 0:".
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 29 lines · Jan Kiszka
Quoted 28 lines · [email protected] wrote:
ksrc/skins/posix/syscall.c +5
-2@@ -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)))
Quoted 8 lines
ksrc/skins/posix/syscall.c static int __pthread_cond_wait_prologue(struct pt_regs *regs) · line 1578
Quoted 5 lines
ksrc/skins/posix/syscall.c +4
-0return -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.
No, err may be 0, if the epilogue returns 0.
The following table should explains how I came to this solution:
perr err wanted err == 0 ? perr : err
0 0 0 0
0 EINTR EINTR EINTR
0 * * *
ETIMEDOUT 0 ETIMEDOUT ETIMEDOUNT
ETIMEDOUT EINTR EINTR EINTR
(epi ETIMEDOUT)
ETIMEDOUT * * *
EINTR -(perr) EINTR EINTR
* -(perr) * *
Signature · 1 line
Gilles.
Quoted 42 lines · Gilles Chanteperdrix
Quoted 28 lines · Jan Kiszka
Quoted 27 lines · [email protected] wrote:
ksrc/skins/posix/syscall.c +5
-2@@ -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,Quoted 8 lines
ksrc/skins/posix/syscall.c static int __pthread_cond_wait_prologue(struct pt_regs *regs) · line 1578
Quoted 6 lines
ksrc/skins/posix/syscall.c +4
-0sizeof(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.
No, err may be 0, if the epilogue returns 0.
The following table should explains how I came to this solution:
Quoted 11 lines
perr err wanted err == 0 ? perr : err
0 0 0 0
0 EINTR EINTR EINTR
0 * * *
ETIMEDOUT 0 ETIMEDOUT ETIMEDOUNT
ETIMEDOUT EINTR EINTR EINTR
(epi ETIMEDOUT)
ETIMEDOUT * * *
EINTR -(perr) EINTR EINTR
* -(perr) * *
Right for my second suggestion. But err = [-]EINTR from the prologue will remain != 0.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 54 lines · Jan Kiszka
Quoted 41 lines · Gilles Chanteperdrix
Quoted 28 lines · Jan Kiszka
Quoted 27 lines · [email protected] wrote:
ksrc/skins/posix/syscall.c +5
-2@@ -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,Quoted 8 lines
ksrc/skins/posix/syscall.c static int __pthread_cond_wait_prologue(struct pt_regs *regs) · line 1578
Quoted 6 lines
ksrc/skins/posix/syscall.c +4
-0sizeof(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.
No, err may be 0, if the epilogue returns 0.
The following table should explains how I came to this solution:
Quoted 11 lines
perr err wanted err == 0 ? perr : err
0 0 0 0
0 EINTR EINTR EINTR
0 * * *
ETIMEDOUT 0 ETIMEDOUT ETIMEDOUNT
ETIMEDOUT EINTR EINTR EINTR
(epi ETIMEDOUT)
ETIMEDOUT * * *
EINTR -(perr) EINTR EINTR
* -(perr) * *
Quoted 2 lines
Right for my second suggestion. But err = [-]EINTR from the prologue will remain != 0.
Yes, Ok. Maybe a (failed) attempt to get gcc to stop whining about perr being used non-initialized, which remained in the way. Which I finally solved by initializing the local variable with 0.
Signature · 1 line
Gilles.