Print this page
15254 %ymm registers not restored after signal handler
15367 x86 getfpregs() summons corrupting %xmm ghosts
15333 want x86 /proc xregs support (libc_db, libproc, mdb, etc.)
15336 want libc functions for extended ucontext_t
15334 want ps_lwphandle-specific reg routines
15328 FPU_CW_INIT mistreats reserved bit
15335 i86pc fpu_subr.c isn't really platform-specific
15332 setcontext(2) isn't actually noreturn
15331 need <sys/stdalign.h>
Change-Id: I7060aa86042dfb989f77fc3323c065ea2eafa9ad
Conflicts:
usr/src/uts/common/fs/proc/prcontrol.c
usr/src/uts/intel/os/archdep.c
usr/src/uts/intel/sys/ucontext.h
usr/src/uts/intel/syscall/getcontext.c
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libc/amd64/gen/makectxt.c
+++ new/usr/src/lib/libc/amd64/gen/makectxt.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /* Copyright (c) 1988 AT&T */
28 -/* All Rights Reserved */
28 +/* All Rights Reserved */
29 29
30 +/*
31 + * Copyright 2023 Oxide Computer Company
32 + */
33 +
30 34 #pragma weak _makecontext = makecontext
31 35
32 36 #include "lint.h"
33 37 #include <stdarg.h>
34 38 #include <ucontext.h>
35 39 #include <sys/stack.h>
40 +#include <sys/auxv.h>
41 +#include <errno.h>
42 +#include "libc.h"
36 43
37 44 /*
38 45 * The ucontext_t that the user passes in must have been primed with a
39 46 * call to getcontext(2), have the uc_stack member set to reflect the
40 47 * stack which this context will use, and have the uc_link member set
41 48 * to the context which should be resumed when this context returns.
42 49 * When makecontext() returns, the ucontext_t will be set to run the
43 50 * given function with the given parameters on the stack specified by
44 51 * uc_stack, and which will return to the ucontext_t specified by uc_link.
45 52 */
46 53
47 54 static void resumecontext(void);
48 55
49 56 void
50 57 makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
51 58 {
52 59 long *sp;
53 60 long *tsp;
54 61 va_list ap;
55 62 size_t size;
56 63 int pusharg = (argc > 6 ? argc - 6 : 0);
57 64 greg_t tmp;
58 65 int i;
59 66
60 67 ucp->uc_mcontext.gregs[REG_PC] = (greg_t)func;
61 68
62 69 size = sizeof (long) * (pusharg + 1);
63 70
64 71 /*
65 72 * Calculate new value for %rsp. On entry to a function,
66 73 * %rsp must be STACK_ENTRY_ALIGNed but not STACK_ALIGNed.
67 74 * This is because the pushq %rbp will correct the alignment.
68 75 */
69 76
70 77 sp = (long *)(((uintptr_t)ucp->uc_stack.ss_sp +
71 78 ucp->uc_stack.ss_size - size) & ~(STACK_ENTRY_ALIGN - 1));
72 79
73 80 if (((uintptr_t)sp & (STACK_ALIGN - 1ul)) == 0)
74 81 sp -= STACK_ENTRY_ALIGN / sizeof (*sp);
75 82
76 83 tsp = sp + 1;
77 84
78 85 va_start(ap, argc);
79 86
80 87 for (i = 0; i < argc; i++) {
81 88 tmp = va_arg(ap, long);
82 89 switch (i) {
83 90 case 0:
84 91 ucp->uc_mcontext.gregs[REG_RDI] = tmp;
85 92 break;
86 93 case 1:
87 94 ucp->uc_mcontext.gregs[REG_RSI] = tmp;
88 95 break;
89 96 case 2:
90 97 ucp->uc_mcontext.gregs[REG_RDX] = tmp;
91 98 break;
92 99 case 3:
93 100 ucp->uc_mcontext.gregs[REG_RCX] = tmp;
94 101 break;
95 102 case 4:
96 103 ucp->uc_mcontext.gregs[REG_R8] = tmp;
97 104 break;
98 105 case 5:
99 106 ucp->uc_mcontext.gregs[REG_R9] = tmp;
100 107 break;
101 108 default:
102 109 *tsp++ = tmp;
103 110 break;
104 111 }
105 112 }
106 113
107 114 va_end(ap);
108 115
109 116 *sp = (long)resumecontext; /* return address */
110 117
111 118 ucp->uc_mcontext.gregs[REG_SP] = (greg_t)sp;
|
↓ open down ↓ |
66 lines elided |
↑ open up ↑ |
112 119 }
113 120
114 121
115 122 static void
116 123 resumecontext(void)
117 124 {
118 125 ucontext_t uc;
119 126
120 127 (void) getcontext(&uc);
121 128 (void) setcontext(uc.uc_link);
129 +}
130 +
131 +/*
132 + * This is the ISA-specific allocation logic for allocating and setting up an
133 + * extended ucontext_t. In particular, right now we need to allocate and add
134 + * space for the UC_XSAVE member if we have the appropriate hardware support.
135 + * The i386 / amd64 versions could be consolidated in a single x86 impl, but we
136 + * don't have that right now.
137 + */
138 +ucontext_t *
139 +ucontext_alloc(uint32_t flags)
140 +{
141 + boolean_t do_xsave = B_FALSE;
142 + size_t to_alloc = sizeof (ucontext_t);
143 + ucontext_t *ucp;
144 +
145 + if (flags != 0) {
146 + errno = EINVAL;
147 + return (NULL);
148 + }
149 +
150 + /*
151 + * This value isn't really 100% accurate. The xsave size is basically
152 + * the worst case that we can have. The XMM / xsave structures aren't
153 + * included in here, but are going to be enough to cover this. We can
154 + * probably try to do a little better and should consider asking the
155 + * kernel for something more accurate. In particular, the problem with
156 + * this is that it doesn't account for the right size of future-looking
157 + * dynamic things, but then again neither does rtld. We'll deal with
158 + * this when we have support for the xfd MSR and actually use it. For
159 + * more information see uts/intel/os/fpu.c's big theory statement.
160 + */
161 + switch (___getauxval(AT_SUN_FPTYPE)) {
162 + case AT_386_FPINFO_XSAVE:
163 + case AT_386_FPINFO_XSAVE_AMD:
164 + do_xsave = B_TRUE;
165 + to_alloc += ___getauxval(AT_SUN_FPSIZE);
166 + break;
167 + default:
168 + break;
169 + }
170 +
171 + ucp = calloc(1, to_alloc);
172 + if (ucp == NULL) {
173 + return (NULL);
174 + }
175 +
176 + if (do_xsave) {
177 + uintptr_t addr = (uintptr_t)ucp;
178 + ucp->uc_xsave = addr + sizeof (ucontext_t);
179 + }
180 +
181 + return (ucp);
182 +}
183 +
184 +void
185 +ucontext_free(ucontext_t *ucp)
186 +{
187 + free(ucp);
122 188 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX