* [Qemu-devel] [PATCH] User mode: Handle the timezone argument for gettimeofday and settimeofday
@ 2009-07-11 14:35 Laurent Desnogues
0 siblings, 0 replies; only message in thread
From: Laurent Desnogues @ 2009-07-11 14:35 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 261 bytes --]
Hello,
this patch:
- adds the timezone parameter to gettimeofday and settimeofday
- allows the timeval pointer to be NULL (as per the man page of my
system and quick testing)
Laurent
Signed-off-by: Laurent Desnogues <laurent.desnogues@gmail.com>
[-- Attachment #2: timezone.patch --]
[-- Type: application/octet-stream, Size: 3251 bytes --]
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0009623..326da72 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -849,6 +849,38 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
return 0;
}
+static inline abi_long copy_from_user_timezone(struct timezone *tz,
+ abi_ulong target_tz_addr)
+{
+ struct target_timezone *target_tz;
+
+ if (!lock_user_struct(VERIFY_READ, target_tz, target_tz_addr, 1))
+ return -TARGET_EFAULT;
+
+ __get_user(tz->tz_minuteswest, &target_tz->tz_minuteswest);
+ __get_user(tz->tz_dsttime, &target_tz->tz_dsttime);
+
+ unlock_user_struct(target_tz, target_tz_addr, 0);
+
+ return 0;
+}
+
+static inline abi_long copy_to_user_timezone(abi_ulong target_tz_addr,
+ const struct timezone *tz)
+{
+ struct target_timezone *target_tz;
+
+ if (!lock_user_struct(VERIFY_WRITE, target_tz, target_tz_addr, 0))
+ return -TARGET_EFAULT;
+
+ __put_user(tz->tz_minuteswest, &target_tz->tz_minuteswest);
+ __put_user(tz->tz_dsttime, &target_tz->tz_dsttime);
+
+ unlock_user_struct(target_tz, target_tz_addr, 1);
+
+ return 0;
+}
+
static inline abi_long copy_from_user_mq_attr(struct mq_attr *attr,
abi_ulong target_mq_attr_addr)
{
@@ -5065,19 +5097,35 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
case TARGET_NR_gettimeofday:
{
struct timeval tv;
- ret = get_errno(gettimeofday(&tv, NULL));
+ struct timezone tz;
+ ret = get_errno(gettimeofday(&tv, &tz));
if (!is_error(ret)) {
- if (copy_to_user_timeval(arg1, &tv))
- goto efault;
+ if (arg1) {
+ if (copy_to_user_timeval(arg1, &tv))
+ goto efault;
+ }
+ if (arg2) {
+ if (copy_to_user_timezone(arg2, &tz))
+ goto efault;
+ }
}
}
break;
case TARGET_NR_settimeofday:
{
- struct timeval tv;
- if (copy_from_user_timeval(&tv, arg1))
- goto efault;
- ret = get_errno(settimeofday(&tv, NULL));
+ struct timeval tv1, *tv = &tv1;
+ struct timezone tz1, *tz = &tz1;
+ if (arg1) {
+ if (copy_from_user_timeval(tv, arg1))
+ goto efault;
+ } else
+ tv = NULL;
+ if (arg2) {
+ if (copy_from_user_timezone(tz, arg2))
+ goto efault;
+ } else
+ tz = NULL;
+ ret = get_errno(settimeofday(tv, tz));
}
break;
#ifdef TARGET_NR_select
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index ac5dbc5..43d3e2e 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -138,6 +138,11 @@ struct target_timeval {
abi_long tv_usec;
};
+struct target_timezone {
+ int tz_minuteswest;
+ int tz_dsttime;
+};
+
struct target_timespec {
abi_long tv_sec;
abi_long tv_nsec;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-07-11 14:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-11 14:35 [Qemu-devel] [PATCH] User mode: Handle the timezone argument for gettimeofday and settimeofday Laurent Desnogues
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).