Fix retval parameter to pthread_join()
PATCH 1/1 Fix retval parameter to pthread_join()
The retval parameter to pthread_join() is a pointer to a pointer. There are several instances where a pointer to int is being passed instead. This can result in a bus error on sparc64 when the pointer is not aligned on a 64-bit boundary. Of course, it's a potential problem on any 64-bit platform.
--- testcases/kernel/io/ltp-aiodio/aio-stress.c | 3 +-- testcases/kernel/io/stress_cd/stress_cd.c | 9 +++++---- testcases/kernel/mem/mtest05/mmstress.c | 4 ++-- testcases/kernel/mem/mtest06/mmap1.c | 8 ++++---- testcases/kernel/mem/mtest06/mmap3.c | 9 +++++---- testcases/kernel/mem/mtest06/shmat1.c | 10 +++++----- testcases/kernel/mem/mtest07/shm_test.c | 6 +++--- testcases/network/nfs/nfsstress/make_tree.c | 6 +++--- .../conformance/interfaces/pthread_cond_timedwait/4-1.c | 6 +++--- 9 files changed, 31 insertions(+), 30 deletions(-)
testcases/kernel/io/ltp-aiodio/aio-stress.c +1 -2
@@ -1233,7 +1233,6 @@ typedef void *(*start_routine) (void *);int run_workers (struct thread_info *t,int num_threads) {int ret; -int thread_ret;int i;for (i =0 ; i < num_threads; i++) {
@@ -1246,7 +1245,7 @@ int run_workers(struct thread_info *t, int num_threads) } }for (i =0 ; i < num_threads; i++) { - ret =pthread_join (t[i].tid, (void *)&thread_ret); + ret =pthread_join (t[i].tid,NULL );if (ret) {perror ("pthread_join" );exit (1 );
testcases/kernel/io/stress_cd/stress_cd.c +5 -4
@@ -143,15 +143,16 @@ int main(int argc, char **argv)sys_error ("pthread_attr_destroy failed" , __LINE__);for (i =0 ; i < num_threads; i++) { -int exit_value; +void *exit_value;printf ("\tThread [main]: waiting for thread: %d\n" , i +1 );/*if (pthread_join ((pthread_t*) array [i], (void **) &exit_value)) */ -if (pthread_join ((pthread_t ) array[i], (void **)&exit_value)) +if (pthread_join (array[i], &exit_value))sys_error ("pthread_join failed" , __LINE__);if (debug) -printf ("\tThread [%d]: return %d\n" , i +1 , exit_value); - rc += exit_value; +printf ("\tThread [%d]: return %ld\n" , i +1 , + (long )exit_value); + rc += (long )exit_value; }free (array);free (arg);
testcases/kernel/mem/mtest05/mmstress.c +2 -2
@@ -361,7 +361,7 @@ RETINFO_t *map_and_thread(char *tmpfile, /* name of temporary file to be createdint fd =0 ;/* file descriptor of the file created */ int thrd_ndx =0 ;/* index to the number of threads created */ int map_type =0 ;/* specifies the type of the mapped object */ -int *th_status =0 ;/* status of the thread when it is finished */ +int **th_status;/* status of the thread when it is finished */ long th_args[5 ];/* argument list passed to thread_fault() */ char *empty_buf =NULL ;/* empty buffer used to fill temp file */ long pagesize/* contains page size at runtime */
@@ -489,7 +489,7 @@ RETINFO_t *map_and_thread(char *tmpfile, /* name of temporary file to be created retinfo->status =FAILED ;return retinfo; }else { -if ((int )*th_status ==1 ) { +if ((long )*th_status ==1 ) {tst_resm (TINFO ,"thread [%ld] - process exited with errors" , (long )pthread_ids[thrd_ndx]);
testcases/kernel/mem/mtest06/mmap1.c +4 -4
@@ -285,7 +285,7 @@ int main(int argc, char **argv)int num_iter;double exec_time;int fd; -int status[2 ]; +void *status;pthread_t thid[2 ];long chld_args[3 ];extern char *optarg;
@@ -387,15 +387,15 @@ int main(int argc, char **argv)tst_resm (TINFO ,"created reading thread[%lu]" , thid[1 ]);for (i =0 ; i <2 ; i++) { -if ((ret =pthread_join (thid[i], (void *)&status[i]))) +if ((ret =pthread_join (thid[i], &status)))tst_brkm (TBROK ,NULL ,"main(): pthread_join(): %s" ,strerror (ret)); -if (status[i]) +if (status)tst_brkm (TFAIL ,NULL ,"thread [%lu] - process exited " -"with %d" , thid[i], status[i]); +"with %ld" , thid[i], (long )status); }close (fd);
testcases/kernel/mem/mtest06/mmap3.c +5 -4
@@ -264,7 +264,7 @@ int main(int argc, /* number of input parameters. */int num_thrd;/* number of threads to create */ int thrd_ndx;/* index into the array of threads. */ float exec_time;/* period for which the test is executed */ -int status;/* exit status for light weight process */ +void *status;/* exit status for light weight process */ int sig_ndx;/* index into signal handler structure. */ pthread_t thid[1000 ];/* pids of process that will map/write/unmap */ long chld_args[3 ];/* arguments to funcs execed by child process */
@@ -362,14 +362,15 @@ int main(int argc, /* number of input parameters. *//* wait for the children to terminate */ for (thrd_ndx =0 ; thrd_ndx < num_thrd; thrd_ndx++) { -if (pthread_join (thid[thrd_ndx], (void *)&status)) { +if (pthread_join (thid[thrd_ndx], &status)) {perror ("main(): pthread_create()" );exit (-1 ); }else {if (status) {fprintf (stderr, -"thread [%d] - process exited with errors %d\n" , -WEXITSTATUS (status), status); +"thread [%d] - process exited with errors %ld\n" , +WEXITSTATUS ((long )status), + (long )status);exit (-1 ); } }
testcases/kernel/mem/mtest06/shmat1.c +5 -5
@@ -392,7 +392,7 @@ int main(int argc, /* number of input parameters. */int num_iter;/* number of iteration to perform */ int thrd_ndx;/* index into the array of threads. */ double exec_time;/* period for which the test is executed */ -int status[1 ];/* exit status for light weight process */ +void *status;/* exit status for light weight process */ int sig_ndx;/* index into signal handler structure. */ pthread_t thid[1000 ];/* pids of process that will map/write/unmap */ long chld_args[3 ];/* arguments to funcs execed by child process */
@@ -497,14 +497,14 @@ int main(int argc, /* number of input parameters. *//* wait for the children to terminate */ for (thrd_ndx =0 ; thrd_ndx <3 ; thrd_ndx++) { -if (pthread_join (thid[thrd_ndx], (void *)status)) { +if (pthread_join (thid[thrd_ndx], &status)) {perror ("main(): pthread_create()" );exit (-1 ); } -if (*status ==-1 ) { +if (status == (void *)-1 ) {fprintf (stderr, -"thread [%#lx] - process exited with errors %d\n" , - thid[thrd_ndx], *status); +"thread [%#lx] - process exited with errors %ld\n" , + thid[thrd_ndx], (long )status);exit (-1 ); } }
testcases/kernel/mem/mtest07/shm_test.c +3 -3
@@ -273,7 +273,7 @@ int main(int argc, /* number of input parameters */int num_thrd =MAXT ;/* number of threads to create */ int num_reps =MAXR ;/* number of repatitions the test is run */ int thrd_ndx;/* index into the array of thread ids */ -int th_status;/* exit status of LWP's */ +void * th_status;/* exit status of LWP's */ int map_size;/* size of the file mapped. */ int shmkey =1969 ;/* key used to generate shmid by shmget() */ pthread_t thrdid[30 ];/* maxinum of 30 threads allowed */
@@ -344,12 +344,12 @@ int main(int argc, /* number of input parameters */sync ();for (thrd_ndx =0 ; thrd_ndx < num_thrd; thrd_ndx++) { -if (pthread_join (thrdid[thrd_ndx], (void *)&th_status) !=0 ) { +if (pthread_join (thrdid[thrd_ndx], &th_status) !=0 ) {perror ("shmat_rd_wr(): pthread_join()" );exit (-1 ); }else {dprt ("WE ARE HERE %d\n" , __LINE__); -if (th_status ==-1 ) { +if (th_status == (void *)-1 ) {fprintf (stderr,"thread [%ld] - process exited with errors\n" , (long )thrdid[thrd_ndx]);
testcases/network/nfs/nfsstress/make_tree.c +3 -3
@@ -721,7 +721,7 @@ int main(int argc, /* number of input parameters */int num_dirs =MAXD ;/* number of subdirectories to create */ int num_files =MAXF ;/* number of files in each subdirectory */ int thrd_ndx;/* index into the array of thread ids */ -int th_status[1 ];/* exit status of LWP's */ +void *th_status;/* exit status of LWP's */ pthread_t thrdid[30 ];/* maxinum of 30 threads allowed */ long chld_args[3 ];/* arguments to the thread function */ extern int optopt;/* options to the program */
@@ -778,12 +778,12 @@ int main(int argc, /* number of input parameters */sync ();for (thrd_ndx =0 ; thrd_ndx < num_thrd; thrd_ndx++) { -if (pthread_join (thrdid[thrd_ndx], (void **)&th_status) !=0 ) { +if (pthread_join (thrdid[thrd_ndx], &th_status) !=0 ) {perror ("crte_mk_rm(): pthread_join()" );exit (-1 ); }else {dprt ("WE ARE HERE %d\n" , __LINE__); -if (*th_status ==-1 ) { +if (th_status == (void *)-1 ) {fprintf (stderr,"thread [%ld] - process exited with errors\n" , thrdid[thrd_ndx]);
testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_timedwait/4-1.c +3 -3
@@ -67,7 +67,7 @@ void *t1_func(void *arg)int main (void ) {pthread_t thread1; -int th_ret; +void *th_ret;if (pthread_mutex_init (&td.mutex,NULL ) !=0 ) {fprintf (stderr,"Fail to initialize mutex\n" );
@@ -85,6 +85,6 @@ int main(void)fprintf (stderr,"Main: no condition is going to be met\n" ); -pthread_join (thread1, (void *)&th_ret); -return th_ret; +pthread_join (thread1, &th_ret); +return (long )th_ret; }
Signature · 13 lines
1.8.2.2 ------------------------------------------------------------------------------ Get 100% visibility into Java/.NET code with AppDynamics Lite It's a free troubleshooting tool designed for production Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://p.sf.net/sfu/appdyn_d2d_ap2 _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi!
Quoted 14 lines
testcases/kernel/mem/mtest05/mmstress.c +1
-1@@ -361,7 +361,7 @@ RETINFO_t *map_and_thread(char *tmpfile, /* name of temporary file to be createdint fd =0 ;/* file descriptor of the file created */ int thrd_ndx =0 ;/* index to the number of threads created */ int map_type =0 ;/* specifies the type of the mapped object */ -int *th_status =0 ;/* status of the thread when it is finished */ +int **th_status;/* status of the thread when it is finished */ long th_args[5 ];/* argument list passed to thread_fault() */ char *empty_buf =NULL ;/* empty buffer used to fill temp file */ long pagesize/* contains page size at runtime */
testcases/kernel/mem/mtest05/mmstress.c RETINFO_t *map_and_thread(char *tmpfile, /* name of temporary file to be created · line 495
Quoted 8 lines
testcases/kernel/mem/mtest05/mmstress.c +1
-1@@ -489,7 +489,7 @@ RETINFO_t *map_and_thread(char *tmpfile, /* name of temporary file to be created retinfo->status =FAILED ;return retinfo; }else { -if ((int )*th_status ==1 ) { +if ((long )*th_status ==1 ) {tst_resm (TINFO ,"thread [%ld] - process exited with errors" , (long )pthread_ids[thrd_ndx]);
This is far to complicated as it is. What about removing the malloc and using void * variable and cast to long as it is in the rest of the testcases?
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET Get 100% visibility into your production application - at no cost. Code-level diagnostics for performance bottlenecks with <2% overhead Download for free and get started troubleshooting in minutes. http://p.sf.net/sfu/appdyn_d2d_ap1 _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
[email protected]
AppliedHi!
Quoted 7 lines
The retval parameter to
pthread_join()is a pointer to a pointer. There are several instances where a pointer to int is being passed instead. This can result in a bus error on sparc64 when the pointer is not aligned on a 64-bit boundary. Of course, it's a potential problem on any 64-bit platform.Also removed an unnecessary malloc & free from
mmstress.c
Applied, thanks.
Signature · 13 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list