blob: 02d6a57b4e2a5229ed88c070b1c495da66e346fb [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
2 * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000028#include "defs.h"
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000029
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +000030#include "xlat/kexec_load_flags.h"
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000031#include "xlat/kexec_arch_values.h"
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +000032
33#ifndef KEXEC_ARCH_MASK
34# define KEXEC_ARCH_MASK 0xffff0000
35#endif
36#ifndef KEXEC_SEGMENT_MAX
37# define KEXEC_SEGMENT_MAX 16
38#endif
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000039
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000040static bool
41print_seg(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000042{
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000043 const unsigned long *seg;
44 unsigned long seg_buf[4];
45
46 if (elem_size < sizeof(seg_buf)) {
47 unsigned int i;
48
49 for (i = 0; i < ARRAY_SIZE(seg_buf); ++i)
50 seg_buf[i] = ((unsigned int *) elem_buf)[i];
51 seg = seg_buf;
52 } else {
53 seg = elem_buf;
54 }
55
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000056 tprints("{");
Dmitry V. Levinb172a942015-09-15 02:17:32 +000057 printaddr(seg[0]);
58 tprintf(", %lu, ", seg[1]);
59 printaddr(seg[2]);
60 tprintf(", %lu}", seg[3]);
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000061
62 return true;
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000063}
64
65static void
66print_kexec_segments(struct tcb *tcp, const unsigned long addr,
67 const unsigned long len)
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000068{
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000069 if (len > KEXEC_SEGMENT_MAX) {
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000070 printaddr(addr);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000071 return;
72 }
73
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000074 unsigned long seg[4];
75 const size_t sizeof_seg = ARRAY_SIZE(seg) * current_wordsize;
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000076
Dmitry V. Levinba4a4c62016-05-07 22:59:05 +000077 print_array(tcp, addr, len, seg, sizeof_seg,
78 umoven_or_printaddr, print_seg, 0);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000079}
80
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000081SYS_FUNC(kexec_load)
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000082{
83 unsigned long n;
84
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000085 /* entry, nr_segments */
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +000086 printaddr(tcp->u_arg[0]);
87 tprintf(", %lu, ", tcp->u_arg[1]);
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +000088
89 /* segments */
90 print_kexec_segments(tcp, tcp->u_arg[2], tcp->u_arg[1]);
91 tprints(", ");
92
93 /* flags */
94 n = tcp->u_arg[3];
95 printxval(kexec_arch_values, n & KEXEC_ARCH_MASK, "KEXEC_ARCH_???");
96 n &= ~KEXEC_ARCH_MASK;
97 if (n) {
98 tprints("|");
Dmitry V. Levinff6a55d2015-02-19 21:16:45 +000099 printflags(kexec_load_flags, n, "KEXEC_???");
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +0000100 }
101
Dmitry V. Levin2f444dc2015-07-20 01:20:44 +0000102 return RVAL_DECODED;
Dmitry V. Levin90aa9f42014-02-05 13:48:26 +0000103}
Dmitry V. Levinea197052015-11-22 18:51:05 +0000104
105#include "xlat/kexec_file_load_flags.h"
106
107SYS_FUNC(kexec_file_load)
108{
109 /* kernel_fd */
110 printfd(tcp, tcp->u_arg[0]);
111 tprints(", ");
112 /* initrd_fd */
113 printfd(tcp, tcp->u_arg[1]);
114 tprints(", ");
115 /* cmdline_len */
116 tprintf("%lu, ", tcp->u_arg[2]);
117 /* cmdline */
118 printstr(tcp, tcp->u_arg[3], tcp->u_arg[2]);
119 tprints(", ");
120 /* flags */
121 printflags(kexec_file_load_flags, tcp->u_arg[4], "KEXEC_FILE_???");
122
123 return RVAL_DECODED;
124}