From 9aaf88c0004f0d9856947aad7d618fb84d5dba40 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 5 Feb 2014 14:51:19 +0000 Subject: [PATCH] Enhance reboot decoding * linux/reboot.h: New file. * system.c (bootflags1, bootflags2, bootflags3, sys_reboot): Move... * reboot.c: ... here. (bootflags2, bootflags3): Update constants. * Makefile.am (strace_SOURCES): Add reboot.c. (EXTRA_DIST): Add linux/reboot.h. --- Makefile.am | 2 ++ linux/reboot.h | 39 +++++++++++++++++++++++++++++++++++++++ reboot.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ system.c | 40 ---------------------------------------- 4 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 linux/reboot.h create mode 100644 reboot.c diff --git a/Makefile.am b/Makefile.am index 55cd4ccd..5524293f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,6 +34,7 @@ strace_SOURCES = \ process.c \ ptp.c \ quota.c \ + reboot.c \ resource.c \ scsi.c \ signal.c \ @@ -137,6 +138,7 @@ EXTRA_DIST = \ linux/powerpc/syscallent.h \ linux/powerpc/syscallent1.h \ linux/ptp_clock.h \ + linux/reboot.h \ linux/s390/ioctlent.h.in \ linux/s390/syscallent.h \ linux/s390x/ioctlent.h.in \ diff --git a/linux/reboot.h b/linux/reboot.h new file mode 100644 index 00000000..aa336741 --- /dev/null +++ b/linux/reboot.h @@ -0,0 +1,39 @@ +#ifndef _LINUX_REBOOT_H +#define _LINUX_REBOOT_H + +/* + * Magic values required to use _reboot() system call. + */ + +#define LINUX_REBOOT_MAGIC1 0xfee1dead +#define LINUX_REBOOT_MAGIC2 672274793 +#define LINUX_REBOOT_MAGIC2A 85072278 +#define LINUX_REBOOT_MAGIC2B 369367448 +#define LINUX_REBOOT_MAGIC2C 537993216 + + +/* + * Commands accepted by the _reboot() system call. + * + * RESTART Restart system using default command and mode. + * HALT Stop OS and give system control to ROM monitor, if any. + * CAD_ON Ctrl-Alt-Del sequence causes RESTART command. + * CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task. + * POWER_OFF Stop OS and remove all power from system, if possible. + * RESTART2 Restart system using given command string. + * SW_SUSPEND Suspend system using software suspend if compiled in. + * KEXEC Restart system using a previously loaded Linux kernel + */ + +#define LINUX_REBOOT_CMD_RESTART 0x01234567 +#define LINUX_REBOOT_CMD_HALT 0xCDEF0123 +#define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF +#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000 +#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC +#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 +#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2 +#define LINUX_REBOOT_CMD_KEXEC 0x45584543 + + + +#endif /* _LINUX_REBOOT_H */ diff --git a/reboot.c b/reboot.c new file mode 100644 index 00000000..f8c3de7a --- /dev/null +++ b/reboot.c @@ -0,0 +1,45 @@ +#include "defs.h" +#include + +static const struct xlat bootflags1[] = { + XLAT(LINUX_REBOOT_MAGIC1), + XLAT_END +}; + +static const struct xlat bootflags2[] = { + XLAT(LINUX_REBOOT_MAGIC2), + XLAT(LINUX_REBOOT_MAGIC2A), + XLAT(LINUX_REBOOT_MAGIC2B), + XLAT(LINUX_REBOOT_MAGIC2C), + XLAT_END +}; + +static const struct xlat bootflags3[] = { + XLAT(LINUX_REBOOT_CMD_RESTART), + XLAT(LINUX_REBOOT_CMD_HALT), + XLAT(LINUX_REBOOT_CMD_CAD_ON), + XLAT(LINUX_REBOOT_CMD_CAD_OFF), + XLAT(LINUX_REBOOT_CMD_POWER_OFF), + XLAT(LINUX_REBOOT_CMD_RESTART2), + XLAT(LINUX_REBOOT_CMD_SW_SUSPEND), + XLAT(LINUX_REBOOT_CMD_KEXEC), + XLAT_END +}; + +int +sys_reboot(struct tcb *tcp) +{ + if (exiting(tcp)) + return 0; + + printflags(bootflags1, tcp->u_arg[0], "LINUX_REBOOT_MAGIC_???"); + tprints(", "); + printflags(bootflags2, tcp->u_arg[1], "LINUX_REBOOT_MAGIC_???"); + tprints(", "); + printflags(bootflags3, tcp->u_arg[2], "LINUX_REBOOT_CMD_???"); + if (tcp->u_arg[2] == LINUX_REBOOT_CMD_RESTART2) { + tprints(", "); + printstr(tcp, tcp->u_arg[3], -1); + } + return 0; +} diff --git a/system.c b/system.c index b4e1896a..604988b5 100644 --- a/system.c +++ b/system.c @@ -275,46 +275,6 @@ sys_syslog(struct tcb *tcp) return 0; } -#include -static const struct xlat bootflags1[] = { - XLAT(LINUX_REBOOT_MAGIC1), - XLAT_END -}; - -static const struct xlat bootflags2[] = { - XLAT(LINUX_REBOOT_MAGIC2), - XLAT(LINUX_REBOOT_MAGIC2A), - XLAT(LINUX_REBOOT_MAGIC2B), - XLAT_END -}; - -static const struct xlat bootflags3[] = { - XLAT(LINUX_REBOOT_CMD_CAD_OFF), - XLAT(LINUX_REBOOT_CMD_RESTART), - XLAT(LINUX_REBOOT_CMD_HALT), - XLAT(LINUX_REBOOT_CMD_CAD_ON), - XLAT(LINUX_REBOOT_CMD_POWER_OFF), - XLAT(LINUX_REBOOT_CMD_RESTART2), - XLAT_END -}; - -int -sys_reboot(struct tcb *tcp) -{ - if (entering(tcp)) { - printflags(bootflags1, tcp->u_arg[0], "LINUX_REBOOT_MAGIC_???"); - tprints(", "); - printflags(bootflags2, tcp->u_arg[1], "LINUX_REBOOT_MAGIC_???"); - tprints(", "); - printflags(bootflags3, tcp->u_arg[2], "LINUX_REBOOT_CMD_???"); - if (tcp->u_arg[2] == LINUX_REBOOT_CMD_RESTART2) { - tprints(", "); - printstr(tcp, tcp->u_arg[3], -1); - } - } - return 0; -} - #ifdef M68K static const struct xlat cacheflush_scope[] = { #ifdef FLUSH_SCOPE_LINE