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> |
| 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 28 | #include "defs.h" |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 29 | |
Dmitry V. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 30 | #include "xlat/kexec_load_flags.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 31 | #include "xlat/kexec_arch_values.h" |
Dmitry V. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 32 | |
| 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. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 39 | |
| 40 | static void |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 41 | print_seg(const unsigned long *seg) |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 42 | { |
| 43 | tprints("{"); |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 44 | printaddr(seg[0]); |
| 45 | tprintf(", %lu, ", seg[1]); |
| 46 | printaddr(seg[2]); |
| 47 | tprintf(", %lu}", seg[3]); |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void |
| 51 | print_kexec_segments(struct tcb *tcp, const unsigned long addr, |
| 52 | const unsigned long len) |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 53 | { |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 54 | unsigned long seg[4]; |
| 55 | const size_t sizeof_seg = ARRAY_SIZE(seg) * current_wordsize; |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 56 | unsigned int i; |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 57 | |
| 58 | if (!len) { |
| 59 | tprints("[]"); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if (len > KEXEC_SEGMENT_MAX) { |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 64 | printaddr(addr); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 68 | if (umove_ulong_array_or_printaddr(tcp, addr, seg, ARRAY_SIZE(seg))) |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 69 | return; |
| 70 | |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 71 | tprints("["); |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 72 | print_seg(seg); |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 73 | |
| 74 | for (i = 1; i < len; ++i) { |
| 75 | tprints(", "); |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 76 | if (umove_ulong_array_or_printaddr(tcp, |
| 77 | addr + i * sizeof_seg, |
| 78 | seg, ARRAY_SIZE(seg))) |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 79 | break; |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame] | 80 | print_seg(seg); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 81 | } |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 82 | |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 83 | tprints("]"); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 86 | SYS_FUNC(kexec_load) |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 87 | { |
| 88 | unsigned long n; |
| 89 | |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 90 | /* entry, nr_segments */ |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 91 | printaddr(tcp->u_arg[0]); |
| 92 | tprintf(", %lu, ", tcp->u_arg[1]); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 93 | |
| 94 | /* segments */ |
| 95 | print_kexec_segments(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
| 96 | tprints(", "); |
| 97 | |
| 98 | /* flags */ |
| 99 | n = tcp->u_arg[3]; |
| 100 | printxval(kexec_arch_values, n & KEXEC_ARCH_MASK, "KEXEC_ARCH_???"); |
| 101 | n &= ~KEXEC_ARCH_MASK; |
| 102 | if (n) { |
| 103 | tprints("|"); |
Dmitry V. Levin | ff6a55d | 2015-02-19 21:16:45 +0000 | [diff] [blame] | 104 | printflags(kexec_load_flags, n, "KEXEC_???"); |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Dmitry V. Levin | 2f444dc | 2015-07-20 01:20:44 +0000 | [diff] [blame] | 107 | return RVAL_DECODED; |
Dmitry V. Levin | 90aa9f4 | 2014-02-05 13:48:26 +0000 | [diff] [blame] | 108 | } |
Dmitry V. Levin | ea19705 | 2015-11-22 18:51:05 +0000 | [diff] [blame] | 109 | |
| 110 | #include "xlat/kexec_file_load_flags.h" |
| 111 | |
| 112 | SYS_FUNC(kexec_file_load) |
| 113 | { |
| 114 | /* kernel_fd */ |
| 115 | printfd(tcp, tcp->u_arg[0]); |
| 116 | tprints(", "); |
| 117 | /* initrd_fd */ |
| 118 | printfd(tcp, tcp->u_arg[1]); |
| 119 | tprints(", "); |
| 120 | /* cmdline_len */ |
| 121 | tprintf("%lu, ", tcp->u_arg[2]); |
| 122 | /* cmdline */ |
| 123 | printstr(tcp, tcp->u_arg[3], tcp->u_arg[2]); |
| 124 | tprints(", "); |
| 125 | /* flags */ |
| 126 | printflags(kexec_file_load_flags, tcp->u_arg[4], "KEXEC_FILE_???"); |
| 127 | |
| 128 | return RVAL_DECODED; |
| 129 | } |