From: Baolin Wang <baolin.wang@linaro.org>
To: tglx@linutronix.de
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org,
baolin.wang@linaro.org, y2038@lists.linaro.org
Subject: [PATCH v4 06/25] time/posix-timers:Introduce {get,put}_timespec and {get,put}_itimerspec
Date: Mon, 1 Jun 2015 19:55:08 +0800 [thread overview]
Message-ID: <1433159708-4780-1-git-send-email-baolin.wang@linaro.org> (raw)
These are new helper functions that convert between a user timespec/
itimerspec and a kernel timespec64/itimerspec64 structure.
These macros can change the types underneath from both ends and it
will work efficiently on both 32-bit and 64-bit that can avoid the
CONFIG_64BIT macro in syscall functions, and also it can make the
syscall functions more simple.
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
kernel/time/posix-timers.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 31ea01f..96efe1d 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -147,6 +147,35 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags);
__timr; \
})
+#define __get_timespec(kts, uts) \
+ (__get_user((kts)->tv_sec, &(uts)->tv_sec) || \
+ __get_user((kts)->tv_nsec, &(uts)->tv_nsec))
+
+#define __put_timespec(kts, uts) \
+ (__put_user((kts)->tv_sec, &(uts)->tv_sec) || \
+ __put_user((kts)->tv_nsec, &(uts)->tv_nsec))
+
+#define get_timespec(kts, uts) \
+ ((access_ok(VERIFY_READ, (uts), sizeof(*(uts))) || \
+ __get_timespec((kts), (uts))) ? \
+ -EFAULT : 0)
+
+#define put_timespec(kts, uts) \
+ ((access_ok(VERIFY_WRITE, (uts), sizeof(*(uts))) || \
+ __put_timespec((kts), (uts))) ? \
+ -EFAULT : 0)
+
+#define get_itimerspec(kit, uit) \
+ ((access_ok(VERIFY_READ, (uit), sizeof(*(uit))) || \
+ __get_timespec(&(kit)->it_interval, &(uit)->it_interval) || \
+ __get_timespec(&(kit)->it_value, &(uit)->it_value)))
+
+#define put_itimerspec(kit, uit) \
+ ((access_ok(VERIFY_WRITE, (uit), sizeof(*(uit))) || \
+ __put_timespec(&(kit)->it_interval, &(uit)->it_interval) || \
+ __put_timespec(&(kit)->it_value, &(uit)->it_value)) ? \
+ -EFAULT : 0)
+
static int hash(struct signal_struct *sig, unsigned int nr)
{
return hash_32(hash32_ptr(sig) ^ nr, HASH_BITS(posix_timers_hashtable));
--
1.7.9.5
next reply other threads:[~2015-06-01 11:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-01 11:55 Baolin Wang [this message]
2015-06-02 19:20 ` [PATCH v4 06/25] time/posix-timers:Introduce {get,put}_timespec and {get,put}_itimerspec Thomas Gleixner
2015-06-04 15:04 ` [Y2038] [PATCH v4 06/25] time/posix-timers:Introduce {get, put}_timespec and {get, put}_itimerspec Arnd Bergmann
2015-06-05 9:59 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1433159708-4780-1-git-send-email-baolin.wang@linaro.org \
--to=baolin.wang@linaro.org \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=y2038@lists.linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).