linux-user: Add support for adjtimex() syscall

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.

Signed-off-by: Aleksandar Rikalo <aleksandar.rikalo@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
This commit is contained in:
Aleksandar Markovic 2016-09-22 18:56:50 +02:00 committed by Riku Voipio
parent da158a86c4
commit 19f59bcef9
4 changed files with 162 additions and 2 deletions

View file

@ -577,6 +577,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),