Skip to contentSkip to conversation

linux-user/syscall.c: Add SO_RCVTIMEO and SO_SNDTIMEO for getsockopt

PATCH Superseded [email protected] 2 participants 4 messages Jan 8, 2016 – Jan 11, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user/syscall.c: Add SO_RCVTIMEO and SO_SNDTIMEO for getsockopt

From: Chen Gang <[email protected]>

Just implement them according to the other features implementations.

---
 linux-user/syscall.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
linux-user/syscall.c +23 -2
index 12a6cd2..f27148a 100644
@@ -1685,6 +1685,7 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
     abi_long ret;
     int len, val;
     socklen_t lv;
+    struct timeval tv;
 
     switch(level) {
     case TARGET_SOL_SOCKET:
@@ -1692,10 +1693,30 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         switch (optname) {
         /* These don't just return a single integer */
         case TARGET_SO_LINGER:
-        case TARGET_SO_RCVTIMEO:
-        case TARGET_SO_SNDTIMEO:
         case TARGET_SO_PEERNAME:
             goto unimplemented;
+
+        case TARGET_SO_RCVTIMEO:
+            optname = SO_RCVTIMEO;
+            goto time_case;
+        case TARGET_SO_SNDTIMEO:
+            optname = SO_SNDTIMEO;
+        time_case:
+            if (optlen < sizeof(struct target_timeval)) {
+                return -TARGET_EINVAL;
+            }
+            lv = sizeof(tv);
+            ret = get_errno(getsockopt(sockfd, level, optname, &tv, &lv));
+            if (ret < 0) {
+                return ret;
+            }
+            if (copy_to_user_timeval(optval_addr, &tv)) {
+                return -TARGET_EFAULT;
+            }
+            if (put_user_u32(sizeof(struct target_timeval), optlen)) {
+                return -TARGET_EFAULT;
+            }
+            break;
         case TARGET_SO_PEERCRED: {
             struct ucred cr;
             socklen_t crlen;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 22 lines · Le 08/01/2016 02:59, [email protected] a écrit :

From: Chen Gang <[email protected]>

Just implement them according to the other features implementations.

---
 linux-user/syscall.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
linux-user/syscall.c +1 -0
index 12a6cd2..f27148a 100644
@@ -1685,6 +1685,7 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
     abi_long ret;
     int len, val;
     socklen_t lv;
+    struct timeval tv;
 
     switch(level) {
     case TARGET_SOL_SOCKET:

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1698

Quoted 8 lines
linux-user/syscall.c +1 -2
@@ -1692,10 +1693,30 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         switch (optname) {
         /* These don't just return a single integer */
         case TARGET_SO_LINGER:
-        case TARGET_SO_RCVTIMEO:
-        case TARGET_SO_SNDTIMEO:
         case TARGET_SO_PEERNAME:
             goto unimplemented;
+

useless blank line

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1704

Quoted 6 lines
linux-user/syscall.c +6 -0
+        case TARGET_SO_RCVTIMEO:
+            optname = SO_RCVTIMEO;
+            goto time_case;
+        case TARGET_SO_SNDTIMEO:
+            optname = SO_SNDTIMEO;
+        time_case:

Something like in "int_case", I think optlen is a pointer, not the length:

        if (get_user_u32(len, optlen))
            return -TARGET_EFAULT;
        if (len < 0)
            return -TARGET_EINVAL;

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1707

Quoted 3 lines
linux-user/syscall.c +3 -0
+            if (optlen < sizeof(struct target_timeval)) {
+                return -TARGET_EINVAL;
+            }

You don't have to check the len (kernel doesn't), EINVAL is not listed in the getsockopt() error cases, it should be an EFAULT, and this will be managed by copy_to_user_timeval().

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1712

Quoted 5 lines
linux-user/syscall.c +5 -0
+            lv = sizeof(tv);
+            ret = get_errno(getsockopt(sockfd, level, optname, &tv, &lv));
+            if (ret < 0) {
+                return ret;
+            }

if (len > lv)

    len = lv;

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1718

Quoted 6 lines
linux-user/syscall.c +6 -0
+            if (copy_to_user_timeval(optval_addr, &tv)) {
+                return -TARGET_EFAULT;
+            }
+            if (put_user_u32(sizeof(struct target_timeval), optlen)) {
+                return -TARGET_EFAULT;
+            }
        if (put_user_u32(len, optlen))
            return -TARGET_EFAULT;

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1722

Quoted 5 lines
linux-user/syscall.c +1 -0
+            break;
         case TARGET_SO_PEERCRED: {
             struct ucred cr;
             socklen_t crlen;

Laurent

author
#2 lore raw

Firstly, thank you very much for your careful work.

Quoted 3 lines · Laurent Vivier

Le 08/01/2016 02:59, [email protected] a écrit :

[...]

Quoted 12 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1698

Quoted 9 lines
linux-user/syscall.c +1 -2
@@ -1692,10 +1693,30 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         switch (optname) {
         /* These don't just return a single integer */
         case TARGET_SO_LINGER:
-        case TARGET_SO_RCVTIMEO:
-        case TARGET_SO_SNDTIMEO:
         case TARGET_SO_PEERNAME:
             goto unimplemented;
+

useless blank line

OK.

Quoted 7 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1704

Quoted 6 lines
linux-user/syscall.c +6 -0
+        case TARGET_SO_RCVTIMEO:
+            optname = SO_RCVTIMEO;
+            goto time_case;
+        case TARGET_SO_SNDTIMEO:
+            optname = SO_SNDTIMEO;
+        time_case:
Quoted 7 lines

Something like in "int_case", I think optlen is a pointer, not the length:

        if (get_user_u32(len, optlen))
            return -TARGET_EFAULT;
        if (len < 0)
            return -TARGET_EINVAL;

OK.

Quoted 9 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1707

Quoted 4 lines
linux-user/syscall.c +3 -0
+            if (optlen < sizeof(struct target_timeval)) {
+                return -TARGET_EINVAL;
+            }

You don't have to check the len (kernel doesn't), EINVAL is not listed in the getsockopt() error cases, it should be an EFAULT, and this will be managed by copy_to_user_timeval().

OK.

Quoted 9 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1712

Quoted 5 lines
linux-user/syscall.c +5 -0
+            lv = sizeof(tv);
+            ret = get_errno(getsockopt(sockfd, level, optname, &tv, &lv));
+            if (ret < 0) {
+                return ret;
+            }

if (len > lv)

    len = lv;

OK.

Quoted 10 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1718

Quoted 6 lines
linux-user/syscall.c +6 -0
+            if (copy_to_user_timeval(optval_addr, &tv)) {
+                return -TARGET_EFAULT;
+            }
+            if (put_user_u32(sizeof(struct target_timeval), optlen)) {
+                return -TARGET_EFAULT;
+            }
        if (put_user_u32(len, optlen))
            return -TARGET_EFAULT;

OK. I shall send patch v2 for it, in the next week.

Thanks.

Signature · 3 lines
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed
author
#3 lore raw

Oh, sorry, after check again, I guess, we need continue to discuss.

Quoted 11 lines · Chen Gang
Quoted 9 lines · Laurent Vivier

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1707

Quoted 4 lines
linux-user/syscall.c +3 -0
+            if (optlen < sizeof(struct target_timeval)) {
+                return -TARGET_EINVAL;
+            }

You don't have to check the len (kernel doesn't), EINVAL is not listed in the getsockopt() error cases, it should be an EFAULT, and this will be managed by copy_to_user_timeval().

After "man getsockopt", there is EINVAL in its error cases.

Quoted 11 lines

OK.

Quoted 9 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1712

Quoted 5 lines
linux-user/syscall.c +5 -0
+            lv = sizeof(tv);
+            ret = get_errno(getsockopt(sockfd, level, optname, &tv, &lv));
+            if (ret < 0) {
+                return ret;
+            }

if (len > lv)

    len = lv;

For me, len is for target, lv is for host, they cann't be compared with each other.

Quoted 13 lines

OK.

Quoted 10 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1718

Quoted 6 lines
linux-user/syscall.c +6 -0
+            if (copy_to_user_timeval(optval_addr, &tv)) {
+                return -TARGET_EFAULT;
+            }
+            if (put_user_u32(sizeof(struct target_timeval), optlen)) {
+                return -TARGET_EFAULT;
+            }
        if (put_user_u32(len, optlen))
            return -TARGET_EFAULT;

For me, we still need put sizeof(struct target_timeval) to optlen, since the host lengh should be sizeof(struct timeval).

Quoted 4 lines

OK. I shall send patch v2 for it, in the next week.

Thanks.

Signature · 3 lines
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed