All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls: Check for time64 unsafe syscalls before using them
@ 2020-02-13  6:25 Khem Raj
  2020-02-13  6:45 ` Yang Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Khem Raj @ 2020-02-13  6:25 UTC (permalink / raw)
  To: ltp

musl is using 64bit time_t now on 32bit architectures and these syscalls
no longer exist, therefore its better to check for them being available
before using them

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 lib/tst_clocks.c                                        | 9 +++++++++
 testcases/kernel/syscalls/gettimeofday/gettimeofday01.c | 4 ++++
 testcases/kernel/syscalls/gettimeofday/gettimeofday02.c | 4 ++++
 3 files changed, 17 insertions(+)

diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index 35798a4aaf..6a5b05c4ea 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -28,15 +28,24 @@
 
 int tst_clock_getres(clockid_t clk_id, struct timespec *res)
 {
+#if defined(__NR_clock_getres)
 	return syscall(SYS_clock_getres, clk_id, res);
+#endif
+	return -1;
 }
 
 int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
 {
+#if defined(__NR_clock_gettime)
 	return syscall(SYS_clock_gettime, clk_id, ts);
+#endif
+	return -1;
 }
 
 int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
 {
+#if defined(__NR_clock_settime)
 	return syscall(SYS_clock_settime, clk_id, ts);
+#endif
+	return -1;
 }
diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
index 583d8f7b9b..b498de5b68 100644
--- a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
+++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
@@ -41,7 +41,11 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 
+#ifdef __NR_gettimeofday
 #define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
+#else
+#define gettimeofday(a,b) (-1)
+#endif
 
 char *TCID = "gettimeofday01";
 int TST_TOTAL = 1;
diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
index 1d60f448e8..218e017df8 100644
--- a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
+++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
@@ -23,7 +23,11 @@
 
 #include "tst_test.h"
 
+#ifdef __NR_gettimeofday
 #define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
+#else
+#define gettimeofday(a,b) (-1)
+#endif
 
 static volatile sig_atomic_t done;
 static char *str_rtime;
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH] syscalls: Check for time64 unsafe syscalls before using them
  2020-02-13  6:25 [LTP] [PATCH] syscalls: Check for time64 unsafe syscalls before using them Khem Raj
@ 2020-02-13  6:45 ` Yang Xu
  2020-02-13 13:52   ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Xu @ 2020-02-13  6:45 UTC (permalink / raw)
  To: ltp

Hi Khem

Can we use simple tst_syscall to fix this like commit 333a47be 
("socketcall01: Use tst_syscall")?

Best Regards
Yang Xu
> musl is using 64bit time_t now on 32bit architectures and these syscalls
> no longer exist, therefore its better to check for them being available
> before using them
> 
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
>   lib/tst_clocks.c                                        | 9 +++++++++
>   testcases/kernel/syscalls/gettimeofday/gettimeofday01.c | 4 ++++
>   testcases/kernel/syscalls/gettimeofday/gettimeofday02.c | 4 ++++
>   3 files changed, 17 insertions(+)
> 
> diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
> index 35798a4aaf..6a5b05c4ea 100644
> --- a/lib/tst_clocks.c
> +++ b/lib/tst_clocks.c
> @@ -28,15 +28,24 @@
>   
>   int tst_clock_getres(clockid_t clk_id, struct timespec *res)
>   {
> +#if defined(__NR_clock_getres)
>   	return syscall(SYS_clock_getres, clk_id, res);
> +#endif
> +	return -1;
>   }
>   
>   int tst_clock_gettime(clockid_t clk_id, struct timespec *ts)
>   {
> +#if defined(__NR_clock_gettime)
>   	return syscall(SYS_clock_gettime, clk_id, ts);
> +#endif
> +	return -1;
>   }
>   
>   int tst_clock_settime(clockid_t clk_id, struct timespec *ts)
>   {
> +#if defined(__NR_clock_settime)
>   	return syscall(SYS_clock_settime, clk_id, ts);
> +#endif
> +	return -1;
>   }
> diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
> index 583d8f7b9b..b498de5b68 100644
> --- a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
> +++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
> @@ -41,7 +41,11 @@
>   #include <sys/syscall.h>
>   #include <unistd.h>
>   
> +#ifdef __NR_gettimeofday
>   #define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
> +#else
> +#define gettimeofday(a,b) (-1)
> +#endif
>   
>   char *TCID = "gettimeofday01";
>   int TST_TOTAL = 1;
> diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
> index 1d60f448e8..218e017df8 100644
> --- a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
> +++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
> @@ -23,7 +23,11 @@
>   
>   #include "tst_test.h"
>   
> +#ifdef __NR_gettimeofday
>   #define gettimeofday(a,b)  syscall(__NR_gettimeofday,a,b)
> +#else
> +#define gettimeofday(a,b) (-1)
> +#endif
>   
>   static volatile sig_atomic_t done;
>   static char *str_rtime;
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [LTP] [PATCH] syscalls: Check for time64 unsafe syscalls before using them
  2020-02-13  6:45 ` Yang Xu
@ 2020-02-13 13:52   ` Petr Vorel
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2020-02-13 13:52 UTC (permalink / raw)
  To: ltp

Hi Khem, Xu,

> Can we use simple tst_syscall to fix this like commit 333a47be
> ("socketcall01: Use tst_syscall")?
+1
NOTE: legacy API (test.h, used by gettimeofday01.c) uses ltp_syscall().

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-13 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-13  6:25 [LTP] [PATCH] syscalls: Check for time64 unsafe syscalls before using them Khem Raj
2020-02-13  6:45 ` Yang Xu
2020-02-13 13:52   ` Petr Vorel

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.