Print this page
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/os-tests/tests/xsave/proc_xregs_set.c
+++ new/usr/src/test/os-tests/tests/xsave/proc_xregs_set.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 13 * Copyright 2023 Oxide Computer Company
14 14 */
15 15
16 16 /*
17 17 * This program pairs with the xregs_dump.32 and xregs_dump.64 program. It's
18 18 * main purpose is to use /proc to overwrite the FPU contents right before our
19 19 * target program calls xsu_getfpu().
20 20 *
21 21 * To accomplish this we end up using libproc for some mischief via support
22 22 * routines. In particular we go through the following to logically accomplish
23 23 * this:
24 24 *
25 25 * o Generate the target FPU contents that we'll write (seeded from the CLI)
26 26 * o Explicitly create the process, which will be stopped.
27 27 * o Set it to be killed if we die.
28 28 * o Find the xsu_getfpu() symbol in the target and set a breakpoint.
29 29 * o Resume execution of the process.
30 30 * o When the break point hits, use libproc to set the FPU.
31 31 * o Delete the breakpoint and resume the process, which will print the FPU
32 32 * regs to a designated file.
33 33 * o Verify the process successfully terminates and returns 0.
34 34 *
35 35 * A critical assumption here is that our hardware support is not going to
36 36 * change between processes (something that may be mucked around with via
37 37 * environment variables for rtld).
38 38 */
39 39
40 40 #include <err.h>
41 41 #include <stdlib.h>
42 42 #include <errno.h>
43 43 #include <sys/types.h>
44 44 #include <sys/wait.h>
45 45 #include <string.h>
46 46
47 47 #include "xsave_util.h"
48 48
49 49 static xsu_fpu_t fpu;
50 50
51 51 int
52 52 main(int argc, char *argv[])
53 53 {
54 54 uint32_t seed, hwsup;
55 55 unsigned long ul;
56 56 char *eptr;
57 57 prxregset_t *prx;
58 58 size_t prx_len;
59 59 xsu_proc_t xp;
60 60
61 61 if (argc != 5) {
62 62 errx(EXIT_FAILURE, "missing args: <prog> <output file> "
63 63 "<seed> <func>");
64 64 }
65 65
66 66 errno = 0;
67 67 ul = strtoul(argv[3], &eptr, 0);
68 68 if (errno != 0 || *eptr != '\0') {
69 69 errx(EXIT_FAILURE, "seed value is bad: %s", argv[3]);
70 70 }
71 71
72 72 #if defined(_LP64)
73 73 if (ul > UINT32_MAX) {
74 74 errx(EXIT_FAILURE, "seed %s, exceeds [0, UINT32_MAX]", argv[3]);
75 75 }
76 76 #endif
77 77
78 78 seed = (uint32_t)ul;
79 79 hwsup = xsu_hwsupport();
80 80 xsu_fill(&fpu, hwsup, seed);
81 81 xsu_fpu_to_xregs(&fpu, hwsup, &prx, &prx_len);
82 82
83 83 (void) memset(&xp, 0, sizeof (xsu_proc_t));
84 84 xp.xp_prog = argv[1];
85 85 xp.xp_arg = argv[2];
86 86 xp.xp_object = "a.out";
87 87 xp.xp_symname = argv[4];
88 88
89 89 xsu_proc_bkpt(&xp);
90 90 /* We know that libc always creates a default thread with id of 1 */
91 91 if (Plwp_setxregs(xp.xp_proc, 1, prx, prx_len) != 0) {
92 92 err(EXIT_FAILURE, "failed to set target's xregs");
93 93 }
94 94
95 95 xsu_proc_finish(&xp);
96 96
97 97 if (WEXITSTATUS(xp.xp_wait) != EXIT_SUCCESS) {
98 98 errx(EXIT_FAILURE, "our target process didn't exit non-zero, "
99 99 "got %d", WEXITSTATUS(xp.xp_wait));
100 100 }
101 101
102 102 return (EXIT_SUCCESS);
103 103 }
|
↓ open down ↓ |
103 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX