Skip to contentSkip to conversation

User mode: Handle the timezone argument for gettimeofday and settimeofday

PATCH New Laurent Desnogues 1 participant 1 message Jul 11, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 User mode: Handle the timezone argument for gettimeofday and settimeofday

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

linux-user/syscall.c +55 -7
index 0009623..326da72 100644
@@ -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
linux-user/syscall_defs.h +5 -0
index ac5dbc5..43d3e2e 100644
@@ -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;