aboutsummaryrefslogtreecommitdiff
path: root/linux-user/syscall.c
diff options
context:
space:
mode:
authorLaurent Vivier <laurent@vivier.eu>2015-10-28 21:40:44 +0100
committerRiku Voipio <riku.voipio@linaro.org>2016-01-08 15:20:08 +0200
commit7b36f78274e701ee17db3171ec7e9f732a60f031 (patch)
treebd9e728774c4666511bf89471c9914fc27f949ba /linux-user/syscall.c
parent5d4d36658578bd5672576e95bec2b5e7a86dd3db (diff)
linux-user: add a function hook to translate sockaddr
Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
Diffstat (limited to 'linux-user/syscall.c')
-rw-r--r--linux-user/syscall.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 25b846b9a2..3484132e34 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -296,9 +296,11 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
};
typedef abi_long (*TargetFdDataFunc)(void *, size_t);
+typedef abi_long (*TargetFdAddrFunc)(void *, abi_ulong, socklen_t);
typedef struct TargetFdTrans {
TargetFdDataFunc host_to_target_data;
TargetFdDataFunc target_to_host_data;
+ TargetFdAddrFunc target_to_host_addr;
} TargetFdTrans;
static TargetFdTrans **target_fd_trans;
@@ -313,6 +315,14 @@ static TargetFdDataFunc fd_trans_host_to_target_data(int fd)
return NULL;
}
+static TargetFdAddrFunc fd_trans_target_to_host_addr(int fd)
+{
+ if (fd < target_fd_max && target_fd_trans[fd]) {
+ return target_fd_trans[fd]->target_to_host_addr;
+ }
+ return NULL;
+}
+
static void fd_trans_register(int fd, TargetFdTrans *trans)
{
unsigned int oldmax;
@@ -1162,7 +1172,7 @@ static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
return 0;
}
-static inline abi_long target_to_host_sockaddr(struct sockaddr *addr,
+static inline abi_long target_to_host_sockaddr(int fd, struct sockaddr *addr,
abi_ulong target_addr,
socklen_t len)
{
@@ -1170,6 +1180,10 @@ static inline abi_long target_to_host_sockaddr(struct sockaddr *addr,
sa_family_t sa_family;
struct target_sockaddr *target_saddr;
+ if (fd_trans_target_to_host_addr(fd)) {
+ return fd_trans_target_to_host_addr(fd)(addr, target_addr, len);
+ }
+
target_saddr = lock_user(VERIFY_READ, target_addr, len, 1);
if (!target_saddr)
return -TARGET_EFAULT;
@@ -2115,7 +2129,7 @@ static abi_long do_bind(int sockfd, abi_ulong target_addr,
addr = alloca(addrlen+1);
- ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ ret = target_to_host_sockaddr(sockfd, addr, target_addr, addrlen);
if (ret)
return ret;
@@ -2135,7 +2149,7 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr,
addr = alloca(addrlen+1);
- ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ ret = target_to_host_sockaddr(sockfd, addr, target_addr, addrlen);
if (ret)
return ret;
@@ -2155,8 +2169,9 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
if (msgp->msg_name) {
msg.msg_namelen = tswap32(msgp->msg_namelen);
msg.msg_name = alloca(msg.msg_namelen+1);
- ret = target_to_host_sockaddr(msg.msg_name, tswapal(msgp->msg_name),
- msg.msg_namelen);
+ ret = target_to_host_sockaddr(fd, msg.msg_name,
+ tswapal(msgp->msg_name),
+ msg.msg_namelen);
if (ret) {
goto out2;
}
@@ -2418,7 +2433,7 @@ static abi_long do_sendto(int fd, abi_ulong msg, size_t len, int flags,
return -TARGET_EFAULT;
if (target_addr) {
addr = alloca(addrlen+1);
- ret = target_to_host_sockaddr(addr, target_addr, addrlen);
+ ret = target_to_host_sockaddr(fd, addr, target_addr, addrlen);
if (ret) {
unlock_user(host_msg, msg, 0);
return ret;