- some fixes for setrlimit() and write()

- fixes ELF loader when host page size is greater than target page size
 - add SO_LINGER to getsockopt()/setsockopt()
 - move TargetFdTrans from syscall.c
   v2: add "#include <linux/netlink.h>" in linux-user/fd-trans.c
 -----BEGIN PGP SIGNATURE-----
 
 iQIcBAABAgAGBQJbqp/BAAoJEPMMOL0/L748HUsP/R4XQMUEQqwvpnFDZwO2fSXQ
 0ndJrvhRtYhhA16e707eZLJ3GsAc4RgrgrcuN1Zou85Pj9MqJxv5Y9beJTNYpdmc
 ZGGcrmj/bMdxVjCSdH36NFaZH05UDKtgwLyqngI3lJ9Fe74QGJpA8MkySp/WLJnO
 12juWcoDZCzpGfxjPGtN5EXamN30zuoJKuhJB+I1d6KX7weSjVjFB1W4ABJOo2Ex
 jJMBpp1COXz3lYwu4qUqG/bbqToGCNQUnDIM6IPZdlj9TWb/1TFzmd16+EY/0lVz
 WZMXHQ4obWnCwvPOoAUyhgyoHwF2e7M9KmKMQe47RLnVY2G79GsP7NMuwVotJlZM
 CKd5EWEHCTMA7RBpDWt/DfYfuBhUZadfDoKxUYiMVieOQOl7S5tmVoOeWCTAjU7K
 OY5eD29ILZsN8/iIfvJHtIV5FzUzDjBxr9ia27AxGbfWf+4+F3WYvPHv6YFtfOe5
 qZ6w01hz6qay1j/t0cwdoEbUWfe9K6z8pRn1zgODS4PYE2d9x+IcnE23QHz4e3Y+
 B8jZK+02JAx1erq6eDTgLuQmHOeLKsEJeXJvMejpx85CFOZY9MidJ4kolrZj5aI2
 HnCZL3mRezpspbvkS0qvvMh/pCUNqLNSDHZMu71z7viX1MURYrlQJLb4vOUydlgv
 rtItfamBNO2wgPjkAAKq
 =ru6z
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-3.1-pull-request' into staging

- some fixes for setrlimit() and write()
- fixes ELF loader when host page size is greater than target page size
- add SO_LINGER to getsockopt()/setsockopt()
- move TargetFdTrans from syscall.c
  v2: add "#include <linux/netlink.h>" in linux-user/fd-trans.c

# gpg: Signature made Tue 25 Sep 2018 21:51:13 BST
# gpg:                using RSA key F30C38BD3F2FBE3C
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>"
# gpg:                 aka "Laurent Vivier <laurent@vivier.eu>"
# gpg:                 aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>"
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F  5173 F30C 38BD 3F2F BE3C

* remotes/vivier2/tags/linux-user-for-3.1-pull-request:
  linux-user: do setrlimit selectively
  linux-user: write(fd, NULL, 0) parity with linux's treatment of same
  linux-user: elf: mmap all the target-pages of hostpage for data segment
  linux-user: add SO_LINGER to {g,s}etsockopt
  linux-user: move TargetFdTrans functions to their own file

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2018-09-28 11:22:36 +01:00
commit aa8e26de96
6 changed files with 1589 additions and 1453 deletions

View File

@ -1,7 +1,7 @@
obj-y = main.o syscall.o strace.o mmap.o signal.o \
elfload.o linuxload.o uaccess.o uname.o \
safe-syscall.o $(TARGET_ABI_DIR)/signal.o \
$(TARGET_ABI_DIR)/cpu_loop.o exit.o
$(TARGET_ABI_DIR)/cpu_loop.o exit.o fd-trans.o
obj-$(TARGET_HAS_BFLT) += flatload.o
obj-$(TARGET_I386) += vm86.o

View File

@ -1439,7 +1439,10 @@ struct exec
#define QMAGIC 0314
/* Necessary parameters */
#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE
#define TARGET_ELF_EXEC_PAGESIZE \
(((eppnt->p_align & ~qemu_host_page_mask) != 0) ? \
TARGET_PAGE_SIZE : MAX(qemu_host_page_size, TARGET_PAGE_SIZE))
#define TARGET_ELF_PAGELENGTH(_v) ROUND_UP((_v), TARGET_ELF_EXEC_PAGESIZE)
#define TARGET_ELF_PAGESTART(_v) ((_v) & \
~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1))
#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1))
@ -2281,7 +2284,7 @@ static void load_elf_image(const char *image_name, int image_fd,
for (i = 0; i < ehdr->e_phnum; i++) {
struct elf_phdr *eppnt = phdr + i;
if (eppnt->p_type == PT_LOAD) {
abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em;
abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len;
int elf_prot = 0;
if (eppnt->p_flags & PF_R) elf_prot = PROT_READ;
@ -2291,8 +2294,9 @@ static void load_elf_image(const char *image_name, int image_fd,
vaddr = load_bias + eppnt->p_vaddr;
vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr);
vaddr_ps = TARGET_ELF_PAGESTART(vaddr);
vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po);
error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po,
error = target_mmap(vaddr_ps, vaddr_len,
elf_prot, MAP_PRIVATE | MAP_FIXED,
image_fd, eppnt->p_offset - vaddr_po);
if (error == -1) {

1409
linux-user/fd-trans.c Normal file

File diff suppressed because it is too large Load Diff

97
linux-user/fd-trans.h Normal file
View File

@ -0,0 +1,97 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FD_TRANS_H
#define FD_TRANS_H
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;
extern TargetFdTrans **target_fd_trans;
extern unsigned int target_fd_max;
static inline TargetFdDataFunc fd_trans_target_to_host_data(int fd)
{
if (fd >= 0 && fd < target_fd_max && target_fd_trans[fd]) {
return target_fd_trans[fd]->target_to_host_data;
}
return NULL;
}
static inline TargetFdDataFunc fd_trans_host_to_target_data(int fd)
{
if (fd >= 0 && fd < target_fd_max && target_fd_trans[fd]) {
return target_fd_trans[fd]->host_to_target_data;
}
return NULL;
}
static inline TargetFdAddrFunc fd_trans_target_to_host_addr(int fd)
{
if (fd >= 0 && fd < target_fd_max && target_fd_trans[fd]) {
return target_fd_trans[fd]->target_to_host_addr;
}
return NULL;
}
static inline void fd_trans_register(int fd, TargetFdTrans *trans)
{
unsigned int oldmax;
if (fd >= target_fd_max) {
oldmax = target_fd_max;
target_fd_max = ((fd >> 6) + 1) << 6; /* by slice of 64 entries */
target_fd_trans = g_renew(TargetFdTrans *,
target_fd_trans, target_fd_max);
memset((void *)(target_fd_trans + oldmax), 0,
(target_fd_max - oldmax) * sizeof(TargetFdTrans *));
}
target_fd_trans[fd] = trans;
}
static inline void fd_trans_unregister(int fd)
{
if (fd >= 0 && fd < target_fd_max) {
target_fd_trans[fd] = NULL;
}
}
static inline void fd_trans_dup(int oldfd, int newfd)
{
fd_trans_unregister(newfd);
if (oldfd < target_fd_max && target_fd_trans[oldfd]) {
fd_trans_register(newfd, target_fd_trans[oldfd]);
}
}
extern TargetFdTrans target_packet_trans;
#ifdef CONFIG_RTNETLINK
extern TargetFdTrans target_netlink_route_trans;
#endif
extern TargetFdTrans target_netlink_audit_trans;
extern TargetFdTrans target_signalfd_trans;
extern TargetFdTrans target_eventfd_trans;
#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
(defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
defined(__NR_inotify_init1))
extern TargetFdTrans target_inotify_trans;
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -203,6 +203,11 @@ struct target_ip_mreq_source {
uint32_t imr_sourceaddr;
};
struct target_linger {
abi_int l_onoff; /* Linger active */
abi_int l_linger; /* How long to linger for */
};
struct target_timeval {
abi_long tv_sec;
abi_long tv_usec;