Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org> |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018 The strace developers. |
Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame] | 4 | * 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 29 | #include "defs.h" |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 30 | |
Dmitry V. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 31 | #include "xlat/kexec_load_flags.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 32 | #include "xlat/kexec_arch_values.h" |
Dmitry V. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 33 | |
| 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 40 | |
Dmitry V. Levin | ba4a4c6 | 2016-05-07 22:59:05 +0000 | [diff] [blame] | 41 | static bool |
| 42 | print_seg(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data) |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 43 | { |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 44 | const kernel_ulong_t *seg; |
| 45 | kernel_ulong_t seg_buf[4]; |
Dmitry V. Levin | ba4a4c6 | 2016-05-07 22:59:05 +0000 | [diff] [blame] | 46 | |
Elliott Hughes | dc75b01 | 2017-07-05 13:54:44 -0700 | [diff] [blame] | 47 | if (elem_size < sizeof(seg_buf)) { |
Dmitry V. Levin | ba4a4c6 | 2016-05-07 22:59:05 +0000 | [diff] [blame] | 48 | 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 Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 57 | tprints("{buf="); |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 58 | printaddr(seg[0]); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 59 | tprintf(", bufsz=%" PRI_klu ", mem=", seg[1]); |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 60 | printaddr(seg[2]); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 61 | tprintf(", memsz=%" PRI_klu "}", seg[3]); |
Dmitry V. Levin | ba4a4c6 | 2016-05-07 22:59:05 +0000 | [diff] [blame] | 62 | |
| 63 | return true; |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static void |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 67 | print_kexec_segments(struct tcb *const tcp, const kernel_ulong_t addr, |
| 68 | const kernel_ulong_t len) |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 69 | { |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 70 | if (len > KEXEC_SEGMENT_MAX) { |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 71 | printaddr(addr); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 72 | return; |
| 73 | } |
| 74 | |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 75 | kernel_ulong_t seg[4]; |
Dmitry V. Levin | ba4a4c6 | 2016-05-07 22:59:05 +0000 | [diff] [blame] | 76 | const size_t sizeof_seg = ARRAY_SIZE(seg) * current_wordsize; |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 77 | |
Dmitry V. Levin | ba4a4c6 | 2016-05-07 22:59:05 +0000 | [diff] [blame] | 78 | print_array(tcp, addr, len, seg, sizeof_seg, |
Elliott Hughes | 03a418e | 2018-06-15 13:11:40 -0700 | [diff] [blame] | 79 | tfetch_mem, print_seg, 0); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 82 | SYS_FUNC(kexec_load) |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 83 | { |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 84 | /* entry, nr_segments */ |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 85 | printaddr(tcp->u_arg[0]); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 86 | tprintf(", %" PRI_klu ", ", tcp->u_arg[1]); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 87 | |
| 88 | /* segments */ |
| 89 | print_kexec_segments(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 90 | tprints(", "); |
| 91 | |
| 92 | /* flags */ |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 93 | 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 96 | if (n) { |
| 97 | tprints("|"); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 98 | printflags64(kexec_load_flags, n, "KEXEC_???"); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 101 | return RVAL_DECODED; |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 102 | } |
Dmitry V. Levin | ea19705 | 2015-11-22 18:51:05 +0000 | [diff] [blame] | 103 | |
| 104 | #include "xlat/kexec_file_load_flags.h" |
| 105 | |
| 106 | SYS_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 Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 115 | tprintf("%" PRI_klu ", ", tcp->u_arg[2]); |
Dmitry V. Levin | ea19705 | 2015-11-22 18:51:05 +0000 | [diff] [blame] | 116 | /* cmdline */ |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 117 | printstrn(tcp, tcp->u_arg[3], tcp->u_arg[2]); |
Dmitry V. Levin | ea19705 | 2015-11-22 18:51:05 +0000 | [diff] [blame] | 118 | tprints(", "); |
| 119 | /* flags */ |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 120 | printflags64(kexec_file_load_flags, tcp->u_arg[4], "KEXEC_FILE_???"); |
Dmitry V. Levin | ea19705 | 2015-11-22 18:51:05 +0000 | [diff] [blame] | 121 | |
| 122 | return RVAL_DECODED; |
| 123 | } |