linux-user: Fix assorted Qemu user mode issues
v6 cover linux-user: Fix assorted Qemu user mode issues
From: Aleksandar Markovic <[email protected]>
v5->v6:
- reworked all patches according to review feedback
- added two new patches on relatively simple issues
v4->v5:
- removed three cleanup patches
v3->v4:
- rebased to the latest code
- added patch on clock_adjtime() support
- minor commit messages improvements
v2->v3:
- rebased to the latest code
- merged patches on adjtimex(), sysfs(), and ustat() from another series
- added patch on socketcall() support
- cleanup patches reorganized
v1->v2:
- improved usage of "#ifdefs" in patch on syslog()
- removed EIDRM-related code from patch on msgrcv(), since this error code is already handled well
- added three cleanup patches
(also, v1 for some reason did not appear on qemu-devel, but mails are sent)
This series fixes certain Qemu user mode issues. The fixes mainly originate from observation of LTP tests failures for execution in Qemu user mode on various platforms. The series also contains a cleanup patch.
Aleksandar Markovic (10):
linux-user: Add support for adjtimex() syscall
linux-user: Add support for clock_adjtime() syscall
linux-user: Add support for sysfs() syscall
linux-user: Add support for syncfs() syscall
linux-user: Add support for ustat() syscall
linux-user: Fix mq_open() syscall support
linux-user: Fix msgrcv() and msgsnd() syscalls support
linux-user: Fix socketcall() syscall support
linux-user: Fix syslog() syscall support
linux-user: Remove a duplicate item from strace.list
linux-user/strace.c | 260 ++++++++++++++++++++++++++++++--- linux-user/strace.list | 13 +- linux-user/syscall.c | 356 ++++++++++++++++++++++++++++++++++++---------- linux-user/syscall_defs.h | 101 ++++++++++--- 4 files changed, 611 insertions(+), 119 deletions(-)
Signature · 1 line
2.9.3
PATCH v6 1/10 linux-user: Add support for adjtimex() syscall
From: Aleksandar Markovic <[email protected]>
This patch implements Qemu user mode adjtimex() syscall support.
Syscall adjtimex() reads and optionally sets parameters for a clock adjustment algorithm used in network synchonization or similar scenarios.
Its declaration is:
int adjtimex(struct timex *buf);
The correspondent source code in the Linux kernel is at kernel/time.c, line 206.
The Qemu implementation is based on invocation of host's adjtimex(), and its key part is in the "TARGET_NR_adjtimex" case segment of the the main switch statement of the function do_syscall(), in linux-user/syscalls.c. All necessary conversions of the data structures from target to host and from host to target are covered. Two new functions, target_to_host_timex() and host_to_target_timex(), are provided for the purpose of such conversions. For that purpose, the support for related structure "timex" had tp be added to the file linux-user/syscall_defs.h, based on its definition in Linux kernel. Also, the relevant support for "-strace" Qemu option is included in files linux-user/strace.c and linux-user/strace.list.
This patch also fixes failures of LTP tests adjtimex01 and adjtimex02, if executed in Qemu user mode.
--- linux-user/strace.c | 46 +++++++++++++++++++++++++ linux-user/strace.list | 3 +- linux-user/syscall.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++- linux-user/syscall_defs.h | 28 +++++++++++++++ 4 files changed, 162 insertions(+), 2 deletions(-)
linux-user/strace.c +46 -0
@@ -483,6 +483,52 @@ print_syscall_ret_newselect(const struct syscallname *name, abi_long ret) }#endif +/* special meanings of adjtimex()' non-negative return values */ +#define TARGET_TIME_OK 0/* clock synchronized, no leap second */ +#define TARGET_TIME_INS 1/* insert leap second */ +#define TARGET_TIME_DEL 2/* delete leap second */ +#define TARGET_TIME_OOP 3/* leap second in progress */ +#define TARGET_TIME_WAIT 4/* leap second has occurred */ +#define TARGET_TIME_ERROR 5/* clock not synchronized */ +static void +print_syscall_ret_adjtimex (const struct syscallname *name,abi_long ret) +{ +const char *errstr =NULL ; + +gemu_log (" = " ); +if (ret <0 ) { +gemu_log ("-1 errno=%d" , errno); + errstr =target_strerror (-ret); +if (errstr) { +gemu_log (" (%s)" , errstr); + } + }else { +gemu_log (TARGET_ABI_FMT_ld, ret); +switch (ret) { +case TARGET_TIME_OK : +gemu_log (" TIME_OK (clock synchronized, no leap second)" ); +break ; +case TARGET_TIME_INS : +gemu_log (" TIME_INS (insert leap second)" ); +break ; +case TARGET_TIME_DEL : +gemu_log (" TIME_DEL (delete leap second)" ); +break ; +case TARGET_TIME_OOP : +gemu_log (" TIME_OOP (leap second in progress)" ); +break ; +case TARGET_TIME_WAIT : +gemu_log (" TIME_WAIT (leap second has occurred)" ); +break ; +case TARGET_TIME_ERROR : +gemu_log (" TIME_ERROR (clock not synchronized)" ); +break ; + } + } + +gemu_log ("\n" ); +} + UNUSED static struct flags access_flags[] = {FLAG_GENERIC (F_OK ),FLAG_GENERIC (R_OK ),
linux-user/strace.list +2 -1
@@ -16,7 +16,8 @@ { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_adjtimex -{ TARGET_NR_adjtimex, "adjtimex" , NULL, NULL, NULL }, +{ TARGET_NR_adjtimex, "adjtimex" , "%s(%p)", NULL, + print_syscall_ret_adjtimex }, #endif #ifdef TARGET_NR_afs_syscall { TARGET_NR_afs_syscall, "afs_syscall" , NULL, NULL, NULL },
linux-user/syscall.c +86 -1
105 lines not on this page · raw message
linux-user/syscall_defs.h +28 -0
@@ -207,6 +207,34 @@ struct target_itimerspec {struct target_timespec it_value; }; +struct target_timex { +abi_uint modes;/* Mode selector */ +abi_long offset;/* Time offset */ +abi_long freq;/* Frequency offset */ +abi_long maxerror;/* Maximum error (microseconds) */ +abi_long esterror;/* Estimated error (microseconds) */ +abi_int status;/* Clock command/status */ +abi_long constant;/* PLL (phase-locked loop) time constant */ +abi_long precision;/* Clock precision (microseconds, ro) */ +abi_long tolerance;/* Clock freq. tolerance (ppm, ro) */ +struct target_timeval time;/* Current time */ +abi_long tick;/* Microseconds between clock ticks */ +abi_long ppsfreq;/* PPS (pulse per second) frequency */ +abi_long jitter;/* PPS jitter (ro); nanoseconds */ +abi_int shift;/* PPS interval duration (seconds) */ +abi_long stabil;/* PPS stability */ +abi_long jitcnt;/* PPS jitter limit exceeded (ro) */ +abi_long calcnt;/* PPS calibration intervals */ +abi_long errcnt;/* PPS calibration errors */ +abi_long stbcnt;/* PPS stability limit exceeded */ +abi_int tai;/* TAI offset */ + +/* Further padding bytes to allow for future expansion */ + abi_int:32; abi_int:32; abi_int:32; abi_int:32; + abi_int:32; abi_int:32; abi_int:32; abi_int:32; + abi_int:32; abi_int:32; abi_int:32; +}; +typedef abi_long target_clock_t ;#define TARGET_HZ 100
Signature · 1 line
2.9.3
PATCH v6 2/10 linux-user: Add support for clock_adjtime() syscall
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
This patch implements Qemu user mode clock_adjtime() syscall support.
The implementation is based on invocation of host's clock_adjtime(), and is very similar to the implementation of adjtimex() syscall support. The main difference is the presence of "clockid_t" argument in clock_adjtime().
--- linux-user/strace.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 3 ++ linux-user/syscall.c | 17 +++++++++++ 3 files changed, 96 insertions(+)
linux-user/strace.c +76 -0
@@ -341,6 +341,69 @@ print_fdset(int n, abi_ulong target_fds_addr) }#endif +#ifdef TARGET_NR_clock_adjtime +/* IDs of the various system clocks */ +#define TARGET_CLOCK_REALTIME 0 +#define TARGET_CLOCK_MONOTONIC 1 +#define TARGET_CLOCK_PROCESS_CPUTIME_ID 2 +#define TARGET_CLOCK_THREAD_CPUTIME_ID 3 +#define TARGET_CLOCK_MONOTONIC_RAW 4 +#define TARGET_CLOCK_REALTIME_COARSE 5 +#define TARGET_CLOCK_MONOTONIC_COARSE 6 +#define TARGET_CLOCK_BOOTTIME 7 +#define TARGET_CLOCK_REALTIME_ALARM 8 +#define TARGET_CLOCK_BOOTTIME_ALARM 9 +#define TARGET_CLOCK_SGI_CYCLE 10 +#define TARGET_CLOCK_TAI 11 + +static void +print_clockid (int clockid,int last) +{ +switch (clockid) { +case TARGET_CLOCK_REALTIME : +gemu_log ("CLOCK_REALTIME" ); +break ; +case TARGET_CLOCK_MONOTONIC : +gemu_log ("CLOCK_MONOTONIC" ); +break ; +case TARGET_CLOCK_PROCESS_CPUTIME_ID : +gemu_log ("CLOCK_PROCESS_CPUTIME_ID" ); +break ; +case TARGET_CLOCK_THREAD_CPUTIME_ID : +gemu_log ("CLOCK_THREAD_CPUTIME_ID" ); +break ; +case TARGET_CLOCK_MONOTONIC_RAW : +gemu_log ("CLOCK_MONOTONIC_RAW" ); +break ; +case TARGET_CLOCK_REALTIME_COARSE : +gemu_log ("CLOCK_REALTIME_COARSE" ); +break ; +case TARGET_CLOCK_MONOTONIC_COARSE : +gemu_log ("CLOCK_MONOTONIC_COARSE" ); +break ; +case TARGET_CLOCK_BOOTTIME : +gemu_log ("CLOCK_BOOTTIME" ); +break ; +case TARGET_CLOCK_REALTIME_ALARM : +gemu_log ("CLOCK_REALTIME_ALARM" ); +break ; +case TARGET_CLOCK_BOOTTIME_ALARM : +gemu_log ("CLOCK_BOOTTIME_ALARM" ); +break ; +case TARGET_CLOCK_SGI_CYCLE : +gemu_log ("CLOCK_SGI_CYCLE" ); +break ; +case TARGET_CLOCK_TAI : +gemu_log ("CLOCK_TAI" ); +break ; +default : +gemu_log ("%d" , clockid); +break ; + } +gemu_log ("%s" ,get_comma (last)); +} +#endif +/* * Sysycall specific output functions */
@@ -1002,6 +1065,19 @@ print_chmod(const struct syscallname *name, }#endif +#ifdef TARGET_NR_clock_adjtime +static void +print_clock_adjtime (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_syscall_prologue (name); +print_clockid (arg0,0 ); +print_pointer (arg1,1 ); +print_syscall_epilogue (name); +} +#endif +#ifdef TARGET_NR_clone static void do_print_clone(unsigned int flags, abi_ulong newsp, abi_ulong parent_tidptr, target_ulong newtls,
linux-user/strace.list +3 -0
@@ -73,6 +73,9 @@ #ifdef TARGET_NR_chroot { TARGET_NR_chroot, "chroot" , NULL, NULL, NULL }, #endif +#ifdef TARGET_NR_clock_adjtime +{ TARGET_NR_clock_adjtime, "clock_adjtime" , NULL, print_clock_adjtime, NULL }, +#endif #ifdef TARGET_NR_clock_getres { TARGET_NR_clock_getres, "clock_getres" , NULL, NULL, NULL }, #endif
linux-user/syscall.c +17 -0
@@ -9506,6 +9506,23 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } }break ; +#if defined(TARGET_NR_clock_adjtime) +case TARGET_NR_clock_adjtime: + { +struct timex host_buf; + +if (target_to_host_timex (&host_buf, arg2) !=0 ) { + goto efault; + } + ret =get_errno (clock_adjtime (arg1, &host_buf)); +if (!is_error (ret)) { +if (host_to_target_timex (arg2, &host_buf) !=0 ) { + goto efault; + } + } + } +break ; +#endif #ifdef TARGET_NR_create_modulecase TARGET_NR_create_module:#endif
Signature · 1 line
2.9.3
PATCH v6 3/10 linux-user: Add support for sysfs() syscall
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
This patch implements Qemu user mode sysfs() syscall support.
Syscall sysfs() involves returning information about the filesystem types currently present in the kernel, and can operate in three distinct flavors, depending on its first argument.
Its specific is that its declaration is threefold:
int sysfs(int option, const char *fsname); int sysfs(int option, unsigned int fs_index, char *buf); int sysfs(int option);
Its implementation in Linux kernel is at fs/filesystems.c, line 184.
The implementation in Qemu user mode is based on invocation of host's sysfs(), and its key part is in the correspondent case segment of the main switch statement of the function do_syscall(), in file linux-user/syscalls.c. All necessary conversions of data structures from target to host and from host to target are covered. Based on the value of the first argument, three cases are distinguished, and such conversions are implemented separately for each case. Relevant support for "-strace" option is included in files linux-user/strace.c and linux-user/strace.list.
This patch also fixes failures of LTP tests sysfs01, sysfs02, sysfs03, sysfs04, sysfs05, and sysfs06, if executed in Qemu user mode.
--- linux-user/strace.c | 27 +++++++++++++++++++++++++++ linux-user/strace.list | 2 +- linux-user/syscall.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 3 deletions(-)
linux-user/strace.c +27 -0
@@ -2248,6 +2248,33 @@ print_kill(const struct syscallname *name, }#endif +#ifdef TARGET_NR_sysfs +static void +print_sysfs (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_syscall_prologue (name); +/* arg0 is normally 1, 2, or 3 */ +switch (arg0) { +case 1 : +print_raw_param ("%d" , arg0,0 ); +print_string (arg1,1 ); +break ; +case 2 : +print_raw_param ("%d" , arg0,0 ); +print_raw_param ("%u" , arg1,0 ); +print_pointer (arg2,1 ); +break ; +/* if arg0 is 3, desired output is the same as default */ +default : +print_raw_param ("%d" , arg0,1 ); +break ; + } +print_syscall_epilogue (name); +} +#endif +/* * An array of all of the syscalls we know about */
linux-user/strace.list +1 -1
@@ -1372,7 +1372,7 @@ { TARGET_NR_sys_epoll_wait, "sys_epoll_wait" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_sysfs -{ TARGET_NR_sysfs, "sysfs" , NULL, NULL, NULL }, +{ TARGET_NR_sysfs, "sysfs" , NULL, print_sysfs, NULL }, #endif #ifdef TARGET_NR_sysinfo { TARGET_NR_sysinfo, "sysinfo" , NULL, NULL, NULL },
linux-user/syscall.c +35 -2
@@ -9544,9 +9544,42 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_bdflush: goto unimplemented;#endif -#ifdef TARGET_NR_sysfs +#if defined(TARGET_NR_sysfs)case TARGET_NR_sysfs: - goto unimplemented; +switch (arg1) { +case 1 : + { + p =lock_user_string (arg2); +if (!p) { + goto efault; + } + ret =get_errno (syscall (__NR_sysfs, arg1, p)); +unlock_user (p, arg2,0 ); + } +break ; +case 2 : + { +char buf[PATH_MAX ]; +memset (buf,0 ,PATH_MAX ); + ret =get_errno (syscall (__NR_sysfs, arg1, arg2, buf)); +if (!is_error (ret)) { +int len =PATH_MAX ; +if (len >strlen (buf)) { + len =strlen (buf); + } +if (copy_to_user (arg3, buf, len) !=0 ) { + goto efault; + } + } + } +break ; +case 3 : + ret =get_errno (syscall (__NR_sysfs, arg1)); +break ; +default : + ret = -EINVAL ; + } +break ;#endif case TARGET_NR_personality: ret =get_errno (personality (arg1));
Signature · 1 line
2.9.3
PATCH v6 4/10 linux-user: Add support for syncfs() syscall
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
This patch implements syncfs() syscall support. The implementation consists of a straightforward invocation of host's syncfs() only.
--- linux-user/syscall.c | 5 +++++ 1 file changed, 5 insertions(+)
linux-user/syscall.c +5 -0
@@ -7943,6 +7943,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,sync (); ret =0 ;break ; +#if defined(TARGET_NR_syncfs) +case TARGET_NR_syncfs: + ret =get_errno (syncfs (arg1)); +break ; +#endif case TARGET_NR_kill: ret =get_errno (safe_kill (arg1,target_to_host_signal (arg2)));break ;
Signature · 1 line
2.9.3
PATCH v6 5/10 linux-user: Add support for ustat() syscall
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
This patch implements Qemu user mode ustat() syscall support.
Syscall ustat() returns information about a mounted filesystem.
Its declaration is:
int ustat(dev_t dev, struct ustat *ubuf);
Its Linux kernel implementation is at fs/compat.c, line 334.
The Qemu implementation proposed in this patch is similar to the Qemu implementations of statfs(), fstatfs() and other related syscalls. It is based on invocation of host's ustat(), and its key part is in the correspondent case segment of the main switch statement of the function do_syscall(), in file linux-user/syscalls.c. All necessary conversions of data structures from target to host and from host to target are covered. Support for target_ustat is included. Sufficient support for "-strace" option for this syscall is already present, and this patch does not change it.
This patch also fixes failures of LTP tests ustat01, and ustat02, if executed on Qemu-emulated systems.
--- linux-user/syscall.c | 23 +++++++++++++++++++++-- linux-user/syscall_defs.h | 6 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-)
linux-user/syscall.c +21 -2
@@ -48,6 +48,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,#include <sys/shm.h> #include <sys/sem.h> #include <sys/statfs.h> +#include <ustat.h> #include <utime.h> #include <sys/sysinfo.h> #include <sys/signalfd.h>
@@ -8100,9 +8101,27 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ret =get_errno (chroot (p));unlock_user (p, arg1,0 );break ; -#ifdef TARGET_NR_ustat +#if defined(TARGET_NR_ustat)case TARGET_NR_ustat: - goto unimplemented; + { +struct ustat ust; + + ret =get_errno (ustat (arg1, &ust)); +if (!is_error (ret)) { +struct target_ustat *target_ust; + +if (!lock_user_struct (VERIFY_WRITE , target_ust, arg2,0 )) { + goto efault; + } +__put_user (ust.f_tfree, &target_ust->f_tfree); +__put_user (ust.f_tinode, &target_ust->f_tinode); +memcpy (target_ust->f_fname, ust.f_fname,6 ); +memcpy (target_ust->f_fpack, ust.f_fpack,6 ); +unlock_user_struct (target_ust, arg2,1 ); + } + } +break ; +#endif #ifdef TARGET_NR_dup2case TARGET_NR_dup2:
linux-user/syscall_defs.h +6 -0
@@ -2158,6 +2158,12 @@ struct target_statfs64 { };#endif +struct target_ustat { +abi_ulong f_tfree; +abi_int f_tinode; +char f_fname[6 ]; +char f_fpack[6 ]; +};#define TARGET_F_DUPFD 0/* dup */ #define TARGET_F_GETFD 1/* get close_on_exec */
Signature · 1 line
2.9.3
PATCH v6 6/10 linux-user: Fix mq_open() syscall support
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
Conversion of file creation flags (O_CREAT, ...) from target to host was missing.
Also, this patch implements better error handling.
--- linux-user/syscall.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
linux-user/syscall.c +9 -7
@@ -11402,16 +11402,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)case TARGET_NR_mq_open: { -struct mq_attr posix_mq_attr, *attrp; +struct mq_attr posix_mq_attr; +int host_flags; + host_flags =target_to_host_bitmask (arg2, fcntl_flags_tbl); +if (copy_from_user_mq_attr (&posix_mq_attr, arg4) !=0 ) { + goto efault; + } p =lock_user_string (arg1 -1 ); -if (arg4 !=0 ) { -copy_from_user_mq_attr (&posix_mq_attr, arg4); - attrp = &posix_mq_attr; - }else { - attrp =0 ; +if (!p) { + goto efault; } - ret =get_errno (mq_open (p, arg2, arg3, attrp)); + ret =get_errno (mq_open (p, host_flags, arg3, &posix_mq_attr));unlock_user (p, arg1,0 ); }break ;
Signature · 1 line
2.9.3
PATCH v6 7/10 linux-user: Fix msgrcv() and msgsnd() syscalls support
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
If syscalls msgrcv() and msgsnd() fail, they return E2BIG, EACCES, EAGAIN, EFAULT, EIDRM, EINTR, EINVAL, ENOMEM, or ENOMSG.
By examining negative scenarios of these syscalls for Mips, it was established that ENOMSG does not have the same value accross all platforms, but it is nevertheless not included for conversion in the correspondant conversion table defined in linux-user/syscall.c. This is certainly a bug, since it leads to the incorrect emulation of msgrcv() and msgsnd() for scenarios involving ENOMSG.
This patch fixes this by extending the conversion table to include ENOMSG.
Also, LTP test msgrcv04 will be fixed for some platforms.
--- linux-user/syscall.c | 3 +++ 1 file changed, 3 insertions(+)
linux-user/syscall.c +3 -0
@@ -750,6 +750,9 @@ static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = { #ifdef ENOTRECOVERABLE [ENOTRECOVERABLE ] =TARGET_ENOTRECOVERABLE , #endif +#ifdef ENOMSG + [ENOMSG] = TARGET_ENOMSG, +#endif };static inline int host_to_target_errno (int err)
Signature · 1 line
2.9.3
PATCH v6 8/10 linux-user: Fix socketcall() syscall support
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
Since not all Linux host platforms support socketcall() (most notably Intel), do_socketcall() function in Qemu's syscalls.c is implemented to mirror the corespondant implementation of socketcall() in Linux kernel, and to utilise individual socket operations that are supported on all Linux platforms. (see kernel source file net/socket.c, definition of socketcall).
However, error codes produced by Qemu implementation are wrong for the cases of invalid values of the first argument. Also, naming of constants is not consistent with kernel one, and not consistant with Qemu convention of prefixing such constants with "TARGET_". This patch in that light brings do_socketcall() closer to its kernel counterpart, and in that way fixes the errors and yields more consisrtent Qemu code.
There were also three missing cases (among 20) for strace support for socketcall(). The array that contains pointers for appropriate printing functions is updated with 3 elements, however pointers to functions are left NULL, and its implementation is left for future.
Also, this patch fixes failure of LTP test socketcall02, if executed on some Qemu emulated sywstems (uer mode).
--- linux-user/strace.c | 39 ++++++++------- linux-user/syscall.c | 119 ++++++++++++++++++++++++---------------------- linux-user/syscall_defs.h | 42 ++++++++-------- 3 files changed, 105 insertions(+), 95 deletions(-)
linux-user/strace.c +21 -18
@@ -1657,29 +1657,32 @@ print_optint: }#define PRINT_SOCKOP (name, func) \ - [SOCKOP_##name] = { #name, func } + [TARGET_SYS_##name] = { #name, func }static struct {const char *name;void (*print)(const char *,abi_long ); } scall[] = { -PRINT_SOCKOP (socket, do_print_socket), -PRINT_SOCKOP (bind, do_print_sockaddr), -PRINT_SOCKOP (connect, do_print_sockaddr), -PRINT_SOCKOP (listen, do_print_listen), -PRINT_SOCKOP (accept, do_print_sockaddr), -PRINT_SOCKOP (getsockname, do_print_sockaddr), -PRINT_SOCKOP (getpeername, do_print_sockaddr), -PRINT_SOCKOP (socketpair, do_print_socketpair), -PRINT_SOCKOP (send, do_print_sendrecv), -PRINT_SOCKOP (recv, do_print_sendrecv), -PRINT_SOCKOP (sendto, do_print_msgaddr), -PRINT_SOCKOP (recvfrom, do_print_msgaddr), -PRINT_SOCKOP (shutdown, do_print_shutdown), -PRINT_SOCKOP (sendmsg, do_print_msg), -PRINT_SOCKOP (recvmsg, do_print_msg), -PRINT_SOCKOP (setsockopt, do_print_sockopt), -PRINT_SOCKOP (getsockopt, do_print_sockopt), +PRINT_SOCKOP (SOCKET , do_print_socket), +PRINT_SOCKOP (BIND , do_print_sockaddr), +PRINT_SOCKOP (CONNECT , do_print_sockaddr), +PRINT_SOCKOP (LISTEN , do_print_listen), +PRINT_SOCKOP (ACCEPT , do_print_sockaddr), +PRINT_SOCKOP (GETSOCKNAME , do_print_sockaddr), +PRINT_SOCKOP (GETPEERNAME , do_print_sockaddr), +PRINT_SOCKOP (SOCKETPAIR , do_print_socketpair), +PRINT_SOCKOP (SEND , do_print_sendrecv), +PRINT_SOCKOP (RECV , do_print_sendrecv), +PRINT_SOCKOP (SENDTO , do_print_msgaddr), +PRINT_SOCKOP (RECVFROM , do_print_msgaddr), +PRINT_SOCKOP (SHUTDOWN , do_print_shutdown), +PRINT_SOCKOP (SETSOCKOPT , do_print_sockopt), +PRINT_SOCKOP (GETSOCKOPT , do_print_sockopt), +PRINT_SOCKOP (SENDMSG , do_print_msg), +PRINT_SOCKOP (RECVMSG , do_print_msg), +PRINT_SOCKOP (ACCEPT4 ,NULL ), +PRINT_SOCKOP (RECVMMSG ,NULL ), +PRINT_SOCKOP (SENDMMSG ,NULL ), }; static void
linux-user/syscall.c +62 -57
151 lines not on this page · raw message
linux-user/syscall_defs.h +22 -20
48 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v6 9/10 linux-user: Fix syslog() syscall support
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
There are currently several problems related to syslog() support.
For example, if the second argument "bufp" of target syslog() syscall is NULL, the current implementation always returns error code EFAULT. However, NULL is a perfectly valid value for the second argument for many use cases of this syscall. This is, for example, visible from this excerpt of man page for syslog(2):
Quoted 3 lines
EINVAL Bad arguments (e.g., bad type; or for type 2, 3, or 4, buf is
NULL, or len is less than zero; or for type 8, the level is outside the range 1 to 8).
Moreover, the argument "bufp" is ignored for all cases of values of the first argument, except 2, 3 and 4. This means that for such cases (the first argument is not 2, 3 or 4), there is no need to pass "buf" between host and target, and it can be set to NULL while calling host's syslog(), without loss of emulation accuracy.
Note also that if "bufp" is NULL and the first argument is 2, 3 or 4, the correct returned error code is EINVAL, not EFAULT.
All these details are reflected in this patch.
"#ifdef TARGET_NR_syslog" is also proprerly inserted when needed.
Support for Qemu's "-strace" switch for syslog() syscall is included too.
LTP tests syslog11 and syslog12 pass with this patch (while fail without it), on any platform.
--- linux-user/strace.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 2 +- linux-user/syscall.c | 49 ++++++++++++++++++++++++++++---- linux-user/syscall_defs.h | 25 ++++++++++++++++ 4 files changed, 141 insertions(+), 7 deletions(-)
linux-user/strace.c +72 -0
@@ -1809,6 +1809,78 @@ print_rt_sigprocmask(const struct syscallname *name, }#endif +#ifdef TARGET_NR_syslog +static void +print_syslog_action (abi_ulong arg,int last) +{ +const char *type; + +switch (arg) { +case TARGET_SYSLOG_ACTION_CLOSE : { + type ="SYSLOG_ACTION_CLOSE" ; +break ; + } +case TARGET_SYSLOG_ACTION_OPEN : { + type ="SYSLOG_ACTION_OPEN" ; +break ; + } +case TARGET_SYSLOG_ACTION_READ : { + type ="SYSLOG_ACTION_READ" ; +break ; + } +case TARGET_SYSLOG_ACTION_READ_ALL : { + type ="SYSLOG_ACTION_READ_ALL" ; +break ; + } +case TARGET_SYSLOG_ACTION_READ_CLEAR : { + type ="SYSLOG_ACTION_READ_CLEAR" ; +break ; + } +case TARGET_SYSLOG_ACTION_CLEAR : { + type ="SYSLOG_ACTION_CLEAR" ; +break ; + } +case TARGET_SYSLOG_ACTION_CONSOLE_OFF : { + type ="SYSLOG_ACTION_CONSOLE_OFF" ; +break ; + } +case TARGET_SYSLOG_ACTION_CONSOLE_ON : { + type ="SYSLOG_ACTION_CONSOLE_ON" ; +break ; + } +case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL : { + type ="SYSLOG_ACTION_CONSOLE_LEVEL" ; +break ; + } +case TARGET_SYSLOG_ACTION_SIZE_UNREAD : { + type ="SYSLOG_ACTION_SIZE_UNREAD" ; +break ; + } +case TARGET_SYSLOG_ACTION_SIZE_BUFFER : { + type ="SYSLOG_ACTION_SIZE_BUFFER" ; +break ; + } +default : { +print_raw_param ("%ld" , arg, last); +return ; + } + } +gemu_log ("%s%s" , type,get_comma (last)); +} + +static void +print_syslog (const struct syscallname *name, +abi_long arg0,abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4,abi_long arg5) +{ +print_syscall_prologue (name); +print_syslog_action (arg0,0 ); +print_pointer (arg1,0 ); +print_raw_param ("%d" , arg2,1 ); +print_syscall_epilogue (name); +} +#endif +#ifdef TARGET_NR_mknod static void print_mknod(const struct syscallname *name,
linux-user/strace.list +1 -1
@@ -1381,7 +1381,7 @@ { TARGET_NR_sys_kexec_load, "sys_kexec_load" , NULL, NULL, NULL }, #endif #ifdef TARGET_NR_syslog -{ TARGET_NR_syslog, "syslog" , NULL, NULL, NULL }, +{ TARGET_NR_syslog, "syslog" , NULL, print_syslog, NULL }, #endif #ifdef TARGET_NR_sysmips { TARGET_NR_sysmips, "sysmips" , NULL, NULL, NULL },
linux-user/syscall.c +43 -6
57 lines not on this page · raw message
linux-user/syscall_defs.h +25 -0
@@ -2669,4 +2669,29 @@ struct target_user_cap_data { uint32_t inheritable; }; +/* from kernel's include/linux/syslog.h */ + +/* Close the log. Currently a NOP. */ +#define TARGET_SYSLOG_ACTION_CLOSE 0 +/* Open the log. Currently a NOP. */ +#define TARGET_SYSLOG_ACTION_OPEN 1 +/* Read from the log. */ +#define TARGET_SYSLOG_ACTION_READ 2 +/* Read all messages remaining in the ring buffer. */ +#define TARGET_SYSLOG_ACTION_READ_ALL 3 +/* Read and clear all messages remaining in the ring buffer */ +#define TARGET_SYSLOG_ACTION_READ_CLEAR 4 +/* Clear ring buffer. */ +#define TARGET_SYSLOG_ACTION_CLEAR 5 +/* Disable printk's to console */ +#define TARGET_SYSLOG_ACTION_CONSOLE_OFF 6 +/* Enable printk's to console */ +#define TARGET_SYSLOG_ACTION_CONSOLE_ON 7 +/* Set level of messages printed to console */ +#define TARGET_SYSLOG_ACTION_CONSOLE_LEVEL 8 +/* Return number of unread characters in the log buffer */ +#define TARGET_SYSLOG_ACTION_SIZE_UNREAD 9 +/* Return size of the log buffer */ +#define TARGET_SYSLOG_ACTION_SIZE_BUFFER 10 +#endif
Signature · 1 line
2.9.3
PATCH v6 10/10 linux-user: Remove a duplicate item from strace.list
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
There is a duplicate item in strace.list. It is benign, but it shouldn't be there, since it may lead to confusion and even bugs in the future. It is the only duplicate in strace.list. This patch removes it.
--- linux-user/strace.list | 3 --- 1 file changed, 3 deletions(-)
linux-user/strace.list +0 -3
@@ -1353,9 +1353,6 @@ #ifdef TARGET_NR_sync { TARGET_NR_sync, "sync" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_sync_file_range -{ TARGET_NR_sync_file_range, "sync_file_range" , NULL, NULL, NULL }, -#endif #ifdef TARGET_NR_syscall { TARGET_NR_syscall, "syscall" , NULL, NULL, NULL }, #endif
Signature · 1 line
2.9.3