blob: 22acaa3a7b460b4e9f98e20c1564af734dfab3dc [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
2 * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
Elliott Hughes03a418e2018-06-15 13:11:40 -07003 * Copyright (c) 2014-2018 The strace developers.
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000029#include "defs.h"
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000030
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +000031#include "xlat/kexec_load_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000032#include "xlat/kexec_arch_values.h"
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +000033
34#ifndef KEXEC_ARCH_MASK
35# define KEXEC_ARCH_MASK 0xffff0000
36#endif
37#ifndef KEXEC_SEGMENT_MAX
38# define KEXEC_SEGMENT_MAX 16
39#endif
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000040
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000041static bool
42print_seg(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000043{
Elliott Hughesd35df492017-02-15 15:19:05 -080044 const kernel_ulong_t *seg;
45 kernel_ulong_t seg_buf[4];
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000046
Elliott Hughesdc75b012017-07-05 13:54:44 -070047 if (elem_size < sizeof(seg_buf)) {
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000048 unsigned int i;
49
50 for (i = 0; i < ARRAY_SIZE(seg_buf); ++i)
51 seg_buf[i] = ((unsigned int *) elem_buf)[i];
52 seg = seg_buf;
53 } else {
54 seg = elem_buf;
55 }
56
Elliott Hughesd35df492017-02-15 15:19:05 -080057 tprints("{buf=");
Dmitry V. Levinb172a942015-09-15 02:17:32 +000058 printaddr(seg[0]);
Elliott Hughesd35df492017-02-15 15:19:05 -080059 tprintf(", bufsz=%" PRI_klu ", mem=", seg[1]);
Dmitry V. Levinb172a942015-09-15 02:17:32 +000060 printaddr(seg[2]);
Elliott Hughesd35df492017-02-15 15:19:05 -080061 tprintf(", memsz=%" PRI_klu "}", seg[3]);
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000062
63 return true;
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000064}
65
66static void
Elliott Hughesd35df492017-02-15 15:19:05 -080067print_kexec_segments(struct tcb *const tcp, const kernel_ulong_t addr,
68 const kernel_ulong_t len)
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000069{
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000070 if (len > KEXEC_SEGMENT_MAX) {
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000071 printaddr(addr);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000072 return;
73 }
74
Elliott Hughesd35df492017-02-15 15:19:05 -080075 kernel_ulong_t seg[4];
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000076 const size_t sizeof_seg = ARRAY_SIZE(seg) * current_wordsize;
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000077
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000078 print_array(tcp, addr, len, seg, sizeof_seg,
Elliott Hughes03a418e2018-06-15 13:11:40 -070079 tfetch_mem, print_seg, 0);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000080}
81
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000082SYS_FUNC(kexec_load)
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000083{
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000084 /* entry, nr_segments */
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000085 printaddr(tcp->u_arg[0]);
Elliott Hughesd35df492017-02-15 15:19:05 -080086 tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000087
88 /* segments */
89 print_kexec_segments(tcp, tcp->u_arg[2], tcp->u_arg[1]);
90 tprints(", ");
91
92 /* flags */
Elliott Hughesd35df492017-02-15 15:19:05 -080093 kernel_ulong_t n = tcp->u_arg[3];
94 printxval64(kexec_arch_values, n & KEXEC_ARCH_MASK, "KEXEC_ARCH_???");
95 n &= ~(kernel_ulong_t) KEXEC_ARCH_MASK;
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000096 if (n) {
97 tprints("|");
Elliott Hughesd35df492017-02-15 15:19:05 -080098 printflags64(kexec_load_flags, n, "KEXEC_???");
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000099 }
100
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +0000101 return RVAL_DECODED;
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +0000102}
Dmitry V. Levinea197052015-11-22 18:51:05 +0000103
104#include "xlat/kexec_file_load_flags.h"
105
106SYS_FUNC(kexec_file_load)
107{
108 /* kernel_fd */
109 printfd(tcp, tcp->u_arg[0]);
110 tprints(", ");
111 /* initrd_fd */
112 printfd(tcp, tcp->u_arg[1]);
113 tprints(", ");
114 /* cmdline_len */
Elliott Hughesd35df492017-02-15 15:19:05 -0800115 tprintf("%" PRI_klu ", ", tcp->u_arg[2]);
Dmitry V. Levinea197052015-11-22 18:51:05 +0000116 /* cmdline */
Elliott Hughesd35df492017-02-15 15:19:05 -0800117 printstrn(tcp, tcp->u_arg[3], tcp->u_arg[2]);
Dmitry V. Levinea197052015-11-22 18:51:05 +0000118 tprints(", ");
119 /* flags */
Elliott Hughesd35df492017-02-15 15:19:05 -0800120 printflags64(kexec_file_load_flags, tcp->u_arg[4], "KEXEC_FILE_???");
Dmitry V. Levinea197052015-11-22 18:51:05 +0000121
122 return RVAL_DECODED;
123}