Skip to contentSkip to conversation

linux-user: make host_to_target_cmsg support SO_TIMESTAMP cmsg_type

PATCH Superseded Jing Huang 2 participants 2 messages Jul 24, 2012

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jing Huang

author
#0 lore raw

PATCH v5 3/3 linux-user: make host_to_target_cmsg support SO_TIMESTAMP cmsg_type

---
 linux-user/syscall.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
linux-user/syscall.c +16 -4
index cc2a1c3..a5fa7a7 100644
@@ -1347,16 +1347,28 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
         target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
 
-        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
-            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
-            memcpy(target_data, data, len);
-        } else {
+        if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) &&
+                                (cmsg->cmsg_type == SCM_RIGHTS)) {
             int *fd = (int *)data;
             int *target_fd = (int *)target_data;
             int i, numfds = len / sizeof(int);
 
             for (i = 0; i < numfds; i++)
                 target_fd[i] = tswap32(fd[i]);
+        } else if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) &&
+                                (cmsg->cmsg_type == SO_TIMESTAMP) &&
+                                (len == sizeof(struct timeval))) {
+            /* copy struct timeval to target */
+            struct timeval *tv = (struct timeval *)data;
+            struct target_timeval *target_tv =
+                                 (struct target_timeval *)target_data;
+
+            target_tv->tv_sec = tswapl(tv->tv_sec);
+            target_tv->tv_usec = tswapl(tv->tv_usec);
+        } else {
+            gemu_log("Unsupported ancillary data: %d/%d\n",
+                                        cmsg->cmsg_level, cmsg->cmsg_type);
+            memcpy(target_data, data, len);
         }
 
         cmsg = CMSG_NXTHDR(msgh, cmsg);
Signature · 1 line
1.7.8.6
#1 lore raw
Quoted 3 lines · Jing Huang

Please don't add a reviewed-by line for me unless I specifically say it's OK to do so.

Quoted 24 lines
---
 linux-user/syscall.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
linux-user/syscall.c +2 -4
index cc2a1c3..a5fa7a7 100644
@@ -1347,16 +1347,28 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
         target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
 
-        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
-            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
-            memcpy(target_data, data, len);
-        } else {
+        if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) &&
+                                (cmsg->cmsg_type == SCM_RIGHTS)) {
             int *fd = (int *)data;
             int *target_fd = (int *)target_data;
             int i, numfds = len / sizeof(int);
 
             for (i = 0; i < numfds; i++)
                 target_fd[i] = tswap32(fd[i]);

linux-user/syscall.c static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, · line 1367

Quoted 10 lines
linux-user/syscall.c +10 -0
+        } else if ((cmsg->cmsg_level == TARGET_SOL_SOCKET) &&
+                                (cmsg->cmsg_type == SO_TIMESTAMP) &&
+                                (len == sizeof(struct timeval))) {
+            /* copy struct timeval to target */
+            struct timeval *tv = (struct timeval *)data;
+            struct target_timeval *target_tv =
+                                 (struct target_timeval *)target_data;
+
+            target_tv->tv_sec = tswapl(tv->tv_sec);
+            target_tv->tv_usec = tswapl(tv->tv_usec);

I hate to make you roll yet another version of these patches but I've just noticed:
these should be tswapal(), not tswapl(), because the fields in target_timeval are of type abi_ulong. (This makes a difference only for a few targets which define TARGET_ABI32 to indicate that the target's "long" type is 32 bits even though pointers are 64 bits.)

That really is the last thing, I promise.

-- PMM