2 * Check decoding of s390_guarded_storage syscall.
4 * Copyright (c) 2018 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <asm/unistd.h>
33 #if defined __NR_s390_guarded_storage && defined HAVE_ASM_GUARDED_STORAGE_H
35 # include <inttypes.h>
41 # include <asm/guarded_storage.h>
48 gs_no_arg(kernel_ulong_t val, const char *val_str)
50 static const kernel_ulong_t bogus_addr =
51 (kernel_ulong_t) 0xcaffeedadeadbed5ULL;
52 static const kernel_ulong_t bogus_cmd_mask =
53 (kernel_ulong_t) 0xbadc0ded00000000ULL;
56 rc = syscall(__NR_s390_guarded_storage, val | bogus_cmd_mask,
58 printf("s390_guarded_storage(%s) = %s\n", val_str, sprintrc(rc));
62 gs_print_epl(uint64_t addr, bool valid, const char *str)
68 printf("%#" PRIx64, addr);
73 struct gs_epl *gsepl = (struct gs_epl *) (uintptr_t) addr;
79 printf("pad1=%#02x, ", gsepl->pad1);
81 printf("gs_eam=%#02x /* extended addressing mode: %u, "
82 "basic addressing mode: %u */"
83 ", gs_eci=%#02x /* CPU in TX: %u, CPU in CX: %u, "
85 ", gs_eai=%#02x /* DAT: %u, address space indication: %u, "
87 gsepl->gs_eam, gsepl->e, gsepl->b,
88 gsepl->gs_eci, gsepl->tx, gsepl->cx,
89 gsepl->in ? "LLGFGS": "LGG",
90 gsepl->gs_eai, gsepl->t, gsepl->as, gsepl->ar);
93 printf("pad2=%#08x, ", gsepl->pad2);
96 printf("gs_eha=%#llx, ", (unsigned long long) gsepl->gs_eha);
99 printf("gs_eia=%#llx, gs_eoa=%#llx, gs_eir=%#llx, gs_era=%#llx",
100 (unsigned long long) gsepl->gs_eia,
101 (unsigned long long) gsepl->gs_eoa,
102 (unsigned long long) gsepl->gs_eir,
103 (unsigned long long) gsepl->gs_era);
104 # else /* !VERBOSE */
106 # endif /* VERBOSE */
112 gs_set_cb(kernel_ulong_t addr, bool valid, bool epl_valid,
113 const char *bc_str, const char *epl_str)
115 static const kernel_ulong_t bogus_cmd_mask =
116 (kernel_ulong_t) 0xda7a105700000000ULL;
120 printf("s390_guarded_storage(GS_SET_BC_CB, ");
123 struct gs_cb *gscb = (struct gs_cb *) (uintptr_t) addr;
128 printf("reserved=%#016llx, ",
129 (unsigned long long) gscb->reserved);
131 printf("gsd=%#16llx",
132 (unsigned long long) gscb->gsd);
134 printf(" /* GS origin: ");
136 unsigned int gsc = gscb->gsd & 0x3F;
137 unsigned int gls = (gscb->gsd >> 8) & 7;
138 bool gsc_valid = gsc >= 25 && gsc <= 56;
141 uint64_t gls = gscb->gsd >> gsc;
142 int field_size = 2 + (67 - gsc) / 4;
144 printf("%#0*" PRIx64, field_size, gls);
149 printf(", guard load shift: %u, GS characteristic: %u */",
151 # endif /* VERBOSE */
153 printf(", gssm=%#016llx, gs_epl_a=",
154 (unsigned long long) gscb->gssm);
156 gs_print_epl(gscb->gs_epl_a, epl_valid, epl_str);
161 printf("%s", bc_str);
163 printf("%#llx", (unsigned long long) addr);
166 rc = syscall(__NR_s390_guarded_storage,
167 GS_SET_BC_CB | bogus_cmd_mask, addr);
168 printf(") = %s\n", sprintrc(rc));
174 static const kernel_ulong_t bogus_cmd =
175 (kernel_ulong_t) 0xdeafbeefdeadc0deULL;
176 static const kernel_ulong_t bogus_addr =
177 (kernel_ulong_t) 0xfacefeedac0ffeedULL;
179 struct gs_cb *gscb = tail_alloc(sizeof(*gscb));
180 struct gs_epl *gsepl = tail_alloc(sizeof(*gsepl));
184 rc = syscall(__NR_s390_guarded_storage, 5, 0);
185 printf("s390_guarded_storage(0x5 /* GS_??? */, NULL) = %s\n",
188 rc = syscall(__NR_s390_guarded_storage, bogus_cmd, bogus_addr);
189 printf("s390_guarded_storage(%#x /* GS_??? */, %#lx) = %s\n",
190 (unsigned) bogus_cmd, (unsigned long) bogus_addr, sprintrc(rc));
192 gs_no_arg(ARG_STR(GS_BROADCAST));
193 gs_no_arg(ARG_STR(GS_CLEAR_BC_CB));
194 gs_no_arg(ARG_STR(GS_DISABLE));
195 gs_no_arg(ARG_STR(GS_ENABLE));
197 fill_memory(gscb, sizeof(*gscb));
198 fill_memory_ex(gsepl, sizeof(*gsepl), 0xA5, 0x5A);
200 gs_set_cb(0, false, false, "NULL", NULL);
201 gs_set_cb((uintptr_t) (gscb + 1), false, false, NULL, NULL);
204 gs_set_cb((uintptr_t) gscb, true, false, NULL, "NULL");
206 fill_memory_ex(gscb, sizeof(*gscb), 0x5A, 0xA5);
207 gscb->gs_epl_a = (uintptr_t) (gsepl + 1) |
208 (sizeof(kernel_ulong_t) < sizeof(uint64_t) ?
209 0xc0debad000000000ULL : 0);
210 gs_set_cb((uintptr_t) gscb, true, false, NULL, NULL);
212 fill_memory_ex(gscb, sizeof(*gscb), 0xA7, 0xA5);
213 gscb->gs_epl_a = (uintptr_t) gsepl;
214 gs_set_cb((uintptr_t) gscb, true, true, NULL, NULL);
216 fill_memory_ex(gscb, sizeof(*gscb), 0x55, 0xAA);
217 fill_memory_ex(gsepl, sizeof(*gsepl), 0x5A, 0xA5);
218 gscb->gs_epl_a = (uintptr_t) gsepl;
219 gs_set_cb((uintptr_t) gscb, true, true, NULL, NULL);
221 puts("+++ exited with 0 +++");
227 SKIP_MAIN_UNDEFINED("__NR_s390_guarded_storage && HAVE_ASM_GUARDED_STORAGE_H")