linux-user: syscall: Add SO_LINGER for setsockopt
PATCH 1/1 linux-user: syscall: Add SO_LINGER for setsockopt
From: Chen Gang <[email protected]>
Just implement it according to the other features implementations.
--- linux-user/syscall.c | 16 +++++++++++++++- linux-user/syscall_defs.h | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-)
linux-user/syscall.c +16 -1
@@ -1409,6 +1409,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,int val;struct ip_mreqn *ip_mreq;struct ip_mreq_source *ip_mreq_source; +struct linger lg; +struct target_linger *tlg; +switch (level) {case SOL_TCP :
@@ -1659,7 +1662,19 @@ set_timeout:case TARGET_SO_RCVLOWAT : optname =SO_RCVLOWAT ;break ; -break ; +case TARGET_SO_LINGER : + optname =SO_LINGER ; +if (optlen !=sizeof (struct target_linger )) { +return -TARGET_EINVAL ; + } +if (!lock_user_struct (VERIFY_READ , tlg, optval_addr,1 )) { +return -TARGET_EFAULT ; + } +__get_user (lg.l_onoff, &tlg->l_onoff); +__get_user (lg.l_linger, &tlg->l_linger); +unlock_user_struct (tlg, optval_addr,0 ); +return get_errno (setsockopt (sockfd,SOL_SOCKET , optname, + &lg,sizeof (lg)));default : goto unimplemented; }
linux-user/syscall_defs.h +5 -0
@@ -165,6 +165,11 @@ struct target_ip_mreq_source {uint32_t imr_sourceaddr; }; +struct target_linger { +int l_onoff;/* Linger active */ +int l_linger;/* How long to linger for */ +}; +struct target_timeval {abi_long tv_sec;abi_long tv_usec;
Signature · 1 line
1.9.1
Quoted 25 lines · Le 08/01/2016 03:03, [email protected] a écrit :
From: Chen Gang <[email protected]>
Just implement it according to the other features implementations.
Signed-off-by Chen Gang <[email protected]>--- linux-user/syscall.c | 16 +++++++++++++++- linux-user/syscall_defs.h | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-)linux-user/syscall.c +3
-0@@ -1409,6 +1409,9 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,int val;struct ip_mreqn *ip_mreq;struct ip_mreq_source *ip_mreq_source; +struct linger lg; +struct target_linger *tlg; +switch (level) {case SOL_TCP :
linux-user/syscall.c set_timeout: · line 1669
Quoted 9 lines
linux-user/syscall.c +5
-1@@ -1659,7 +1662,19 @@ set_timeout:case TARGET_SO_RCVLOWAT : optname =SO_RCVLOWAT ;break ; -break ; +case TARGET_SO_LINGER : + optname =SO_LINGER ; +if (optlen !=sizeof (struct target_linger )) { +return -TARGET_EINVAL ; + }
OK, this time you're right, there is this check in the kernel too... and optlen is really the length for setsockopt(), not a pointer.
linux-user/syscall.c set_timeout: · line 1675
Quoted 6 lines
linux-user/syscall.c +6
-0+if (!lock_user_struct (VERIFY_READ , tlg, optval_addr,1 )) { +return -TARGET_EFAULT ; + } +__get_user (lg.l_onoff, &tlg->l_onoff); +__get_user (lg.l_linger, &tlg->l_linger); +unlock_user_struct (tlg, optval_addr,0 );
You can't unlock the structure you're going to use.
linux-user/syscall.c set_timeout: · line 1677
Quoted 2 lines
linux-user/syscall.c +2
-0+return get_errno (setsockopt (sockfd,SOL_SOCKET , optname, + &lg,sizeof (lg)));
Why do you use "SOL_SOCKET" instead of "level" ?
Quoted 8 lines
linux-user/syscall.c +0
-0default : goto unimplemented; }linux-user/syscall_defs.h +0
-0
linux-user/syscall_defs.h struct target_ip_mreq_source { · line 172
Quoted 8 lines
linux-user/syscall_defs.h +5
-0@@ -165,6 +165,11 @@ struct target_ip_mreq_source {uint32_t imr_sourceaddr; }; +struct target_linger { +int l_onoff;/* Linger active */ +int l_linger;/* How long to linger for */ +}; +
Must be "abi_int" to force good alignment for the target.
Quoted 4 lines
linux-user/syscall_defs.h +0
-0struct target_timeval {abi_long tv_sec;abi_long tv_usec;
Quoted 10 lines · Laurent Vivier
linux-user/syscall.c set_timeout: · line 1675
Quoted 7 lines
linux-user/syscall.c +6
-0+if (!lock_user_struct (VERIFY_READ , tlg, optval_addr,1 )) { +return -TARGET_EFAULT ; + } +__get_user (lg.l_onoff, &tlg->l_onoff); +__get_user (lg.l_linger, &tlg->l_linger); +unlock_user_struct (tlg, optval_addr,0 );You can't unlock the structure you're going to use.
OK, thanks.
Quoted 5 lines
linux-user/syscall.c set_timeout: · line 1677
Quoted 2 lines
linux-user/syscall.c +2
-0+return get_errno (setsockopt (sockfd,SOL_SOCKET , optname, + &lg,sizeof (lg)));Why do you use "
SOL_SOCKET" instead of "level" ?
At present, level is TARGET_SOL_SOCKET, but we need SOL_SOCKET.
Quoted 8 lines
Quoted 8 lines
linux-user/syscall_defs.h +0
-0@@ -165,6 +165,11 @@ struct target_ip_mreq_source {uint32_t imr_sourceaddr; };
Quoted 8 lines
linux-user/syscall_defs.h struct target_ip_mreq_source { · line 172
Quoted 5 lines
linux-user/syscall_defs.h +5
-0+struct target_linger { +int l_onoff;/* Linger active */ +int l_linger;/* How long to linger for */ +}; +Must be "
abi_int" to force good alignment for the target.
OK, thanks.
Signature · 3 lines
Chen Gang (陈刚) Open, share, and attitude like air, water, and life which God blessed
Quoted 16 lines · Chen Gang
Quoted 10 lines · Laurent Vivier
linux-user/syscall.c set_timeout: · line 1675
Quoted 7 lines
linux-user/syscall.c +6
-0+if (!lock_user_struct (VERIFY_READ , tlg, optval_addr,1 )) { +return -TARGET_EFAULT ; + } +__get_user (lg.l_onoff, &tlg->l_onoff); +__get_user (lg.l_linger, &tlg->l_linger); +unlock_user_struct (tlg, optval_addr,0 );You can't unlock the structure you're going to use.
OK, thanks.
Quoted 7 lines
Quoted 5 lines
linux-user/syscall.c set_timeout: · line 1677
Quoted 2 lines
linux-user/syscall.c +2
-0+return get_errno (setsockopt (sockfd,SOL_SOCKET , optname, + &lg,sizeof (lg)));Why do you use "
SOL_SOCKET" instead of "level" ?At present, level is
TARGET_SOL_SOCKET, but we needSOL_SOCKET.
Yes, you're right... so there is a bug in TARGET_SO_BINDTODEVICE which is using "level" :)
Quoted 22 lines
Quoted 10 lines
Quoted 10 lines
linux-user/syscall_defs.h +0
-0@@ -165,6 +165,11 @@ struct target_ip_mreq_source {uint32_t imr_sourceaddr; };Quoted 8 lines
linux-user/syscall_defs.h struct target_ip_mreq_source { · line 172
Quoted 5 lines
linux-user/syscall_defs.h +5
-0+struct target_linger { +int l_onoff;/* Linger active */ +int l_linger;/* How long to linger for */ +}; +Must be "
abi_int" to force good alignment for the target.OK, thanks.
Quoted 4 lines · Laurent Vivier
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
linux-user/syscall.c +2
-0+return get_errno (setsockopt (sockfd,SOL_SOCKET , optname, + &lg,sizeof (lg)));
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Why do you use "
SOL_SOCKET" instead of "level" ?At present, level is
TARGET_SOL_SOCKET, but we needSOL_SOCKET.Yes, you're right... so there is a bug in
TARGET_SO_BINDTODEVICEwhich is using "level" :)
OK, thanks. I shall send patch v2 for it, next week.
Signature · 3 lines
Chen Gang (陈刚) Open, share, and attitude like air, water, and life which God blessed