summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-07-28 15:49:10 -0400
committerRich Felker <dalias@aerifal.cx>2019-07-28 17:09:30 -0400
commit2ab90de7ac53317a63d999b3e26d44d66684464c (patch)
tree4250e51524a0c47aa3815db9d1f45516bd79c563
parent1334e3668034615b23793a20277aabc441fee718 (diff)
downloadmusl-2ab90de7ac53317a63d999b3e26d44d66684464c.tar.gz
mq_timedsend, mq_timedreceive: add time64, decouple 32-bit time_t
time64 syscall is used only if it's the only one defined for the arch, or if the requested absolute timeout does not fit in 32 bits. on current 32-bit archs where time_t is a 32-bit type, this makes it statically unreachable. on 64-bit archs, there is no change to the code after preprocessing. on current 32-bit archs, the timeout is passed via an intermediate copy to remove the assumption that time_t is a 32-bit type.
-rw-r--r--src/mq/mq_timedreceive.c17
-rw-r--r--src/mq/mq_timedsend.c17
2 files changed, 34 insertions, 0 deletions
diff --git a/src/mq/mq_timedreceive.c b/src/mq/mq_timedreceive.c
index 2cef6a86..f41b6642 100644
--- a/src/mq/mq_timedreceive.c
+++ b/src/mq/mq_timedreceive.c
@@ -1,7 +1,24 @@
#include <mqueue.h>
+#include <errno.h>
#include "syscall.h"
+#define IS32BIT(x) !((x)+0x80000000ULL>>32)
+#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
+
ssize_t mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at)
{
+#ifdef SYS_mq_timedreceive_time64
+ time_t s = at ? at->tv_sec : 0;
+ long ns = at ? at->tv_nsec : 0;
+ long r = -ENOSYS;
+ if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || !IS32BIT(s))
+ r = __syscall_cp(SYS_mq_timedreceive_time64, mqd, msg, len, prio,
+ at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0);
+ if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || r != -ENOSYS)
+ return __syscall_ret(r);
+ return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio,
+ at ? ((long[]){CLAMP(s), ns}) : 0);
+#else
return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio, at);
+#endif
}
diff --git a/src/mq/mq_timedsend.c b/src/mq/mq_timedsend.c
index 1c00aa0b..56cfcbb8 100644
--- a/src/mq/mq_timedsend.c
+++ b/src/mq/mq_timedsend.c
@@ -1,7 +1,24 @@
#include <mqueue.h>
+#include <errno.h>
#include "syscall.h"
+#define IS32BIT(x) !((x)+0x80000000ULL>>32)
+#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
+
int mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, const struct timespec *at)
{
+#ifdef SYS_mq_timedsend_time64
+ time_t s = at ? at->tv_sec : 0;
+ long ns = at ? at->tv_nsec : 0;
+ long r = -ENOSYS;
+ if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || !IS32BIT(s))
+ r = __syscall_cp(SYS_mq_timedsend_time64, mqd, msg, len, prio,
+ at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0);
+ if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || r != -ENOSYS)
+ return __syscall_ret(r);
+ return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio,
+ at ? ((long[]){CLAMP(s), ns}) : 0);
+#else
return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio, at);
+#endif
}