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


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright (c) 2013 by Delphix. All rights reserved.

  27  */
  28 
  29 #include <stdarg.h>
  30 #include <string.h>

  31 #include "Pcontrol.h"
  32 
  33 /*
  34  * This file implements the process services declared in <proc_service.h>.
  35  * This enables libproc to be used in conjunction with libc_db and
  36  * librtld_db.  As most of these facilities are already provided by
  37  * (more elegant) interfaces in <libproc.h>, we can just call those.
  38  *
  39  * NOTE: We explicitly do *not* implement the functions ps_kill() and
  40  * ps_lrolltoaddr() in this library.  The very existence of these functions
  41  * causes libc_db to create an "agent thread" in the target process.
  42  * The only way to turn off this behavior is to omit these functions.
  43  */
  44 
  45 #pragma weak ps_pdread = ps_pread
  46 #pragma weak ps_ptread = ps_pread
  47 #pragma weak ps_pdwrite = ps_pwrite
  48 #pragma weak ps_ptwrite = ps_pwrite
  49 
  50 ps_err_e


 150                 return (PS_ERR);
 151 
 152         if (Plwp_getfpregs(P, lwpid, regs) == 0)
 153                 return (PS_OK);
 154 
 155         return (PS_BADLID);
 156 }
 157 
 158 ps_err_e
 159 ps_lsetfpregs(struct ps_prochandle *P, lwpid_t lwpid, const prfpregset_t *regs)
 160 {
 161         if (P->state != PS_STOP)
 162                 return (PS_ERR);
 163 
 164         if (Plwp_setfpregs(P, lwpid, regs) == 0)
 165                 return (PS_OK);
 166 
 167         return (PS_BADLID);
 168 }
 169 
 170 #if defined(sparc) || defined(__sparc)
 171 
 172 ps_err_e
 173 ps_lgetxregsize(struct ps_prochandle *P, lwpid_t lwpid, int *xrsize)
 174 {
 175         char fname[PATH_MAX];
 176         struct stat statb;
 177 
 178         if (P->state == PS_DEAD) {
 179                 core_info_t *core = P->data;
 180                 lwp_info_t *lwp;
 181 
 182                 for (lwp = list_head(&core->core_lwp_head); lwp != NULL;
 183                     lwp = list_next(&core->core_lwp_head, lwp)) {
 184                         if (lwp->lwp_id == lwpid) {
 185                                 if (lwp->lwp_xregs != NULL)
 186                                         *xrsize = sizeof (prxregset_t);
 187                                 else





 188                                         *xrsize = 0;

 189                                 return (PS_OK);
 190                         }
 191                 }
 192 
 193                 return (PS_BADLID);
 194         }
 195 
 196         (void) snprintf(fname, sizeof (fname), "%s/%d/lwp/%d/xregs",
 197             procfs_path, (int)P->status.pr_pid, (int)lwpid);
 198 
 199         if (stat(fname, &statb) != 0)
 200                 return (PS_BADLID);
 201 



 202         *xrsize = (int)statb.st_size;
 203         return (PS_OK);
 204 }
 205 
 206 ps_err_e
 207 ps_lgetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
 208 {



 209         if (P->state != PS_STOP && P->state != PS_DEAD)
 210                 return (PS_ERR);
 211 
 212         /* LINTED - alignment */
 213         if (Plwp_getxregs(P, lwpid, (prxregset_t *)xregs) == 0)

 214                 return (PS_OK);

 215 



 216         return (PS_BADLID);
 217 }
 218 
 219 ps_err_e
 220 ps_lsetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)






























 221 {
 222         if (P->state != PS_STOP)
 223                 return (PS_ERR);
 224 
 225         /* LINTED - alignment */
 226         if (Plwp_setxregs(P, lwpid, (prxregset_t *)xregs) == 0)
 227                 return (PS_OK);
 228 
 229         return (PS_BADLID);
 230 }
 231 
 232 #endif  /* sparc */
 233 
 234 #if defined(__i386) || defined(__amd64)
 235 
 236 ps_err_e
 237 ps_lgetLDT(struct ps_prochandle *P, lwpid_t lwpid, struct ssd *ldt)
 238 {
 239 #if defined(__amd64) && defined(_LP64)
 240         if (P->status.pr_dmodel != PR_MODEL_NATIVE) {




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright (c) 2013 by Delphix. All rights reserved.
  27  * Copyright 2023 Oxide Computer Company
  28  */
  29 
  30 #include <stdarg.h>
  31 #include <string.h>
  32 #include <errno.h>
  33 #include "Pcontrol.h"
  34 
  35 /*
  36  * This file implements the process services declared in <proc_service.h>.
  37  * This enables libproc to be used in conjunction with libc_db and
  38  * librtld_db.  As most of these facilities are already provided by
  39  * (more elegant) interfaces in <libproc.h>, we can just call those.
  40  *
  41  * NOTE: We explicitly do *not* implement the functions ps_kill() and
  42  * ps_lrolltoaddr() in this library.  The very existence of these functions
  43  * causes libc_db to create an "agent thread" in the target process.
  44  * The only way to turn off this behavior is to omit these functions.
  45  */
  46 
  47 #pragma weak ps_pdread = ps_pread
  48 #pragma weak ps_ptread = ps_pread
  49 #pragma weak ps_pdwrite = ps_pwrite
  50 #pragma weak ps_ptwrite = ps_pwrite
  51 
  52 ps_err_e


 152                 return (PS_ERR);
 153 
 154         if (Plwp_getfpregs(P, lwpid, regs) == 0)
 155                 return (PS_OK);
 156 
 157         return (PS_BADLID);
 158 }
 159 
 160 ps_err_e
 161 ps_lsetfpregs(struct ps_prochandle *P, lwpid_t lwpid, const prfpregset_t *regs)
 162 {
 163         if (P->state != PS_STOP)
 164                 return (PS_ERR);
 165 
 166         if (Plwp_setfpregs(P, lwpid, regs) == 0)
 167                 return (PS_OK);
 168 
 169         return (PS_BADLID);
 170 }
 171 


 172 ps_err_e
 173 ps_lgetxregsize(struct ps_prochandle *P, lwpid_t lwpid, int *xrsize)
 174 {
 175         char fname[PATH_MAX];
 176         struct stat statb;
 177 
 178         if (P->state == PS_DEAD) {
 179                 core_info_t *core = P->data;
 180                 lwp_info_t *lwp;
 181 
 182                 for (lwp = list_head(&core->core_lwp_head); lwp != NULL;
 183                     lwp = list_next(&core->core_lwp_head, lwp)) {
 184                         if (lwp->lwp_id == lwpid) {
 185                                 if (lwp->lwp_xregs != NULL &&
 186                                     lwp->lwp_xregsize > 0) {
 187                                         if (lwp->lwp_xregsize >= INT_MAX) {
 188                                                 return (PS_ERR);
 189                                         }
 190 
 191                                         *xrsize = (int)lwp->lwp_xregsize;
 192                                 } else {
 193                                         *xrsize = 0;
 194                                 }
 195                                 return (PS_OK);
 196                         }
 197                 }
 198 
 199                 return (PS_BADLID);
 200         }
 201 
 202         (void) snprintf(fname, sizeof (fname), "%s/%d/lwp/%d/xregs",
 203             procfs_path, (int)P->status.pr_pid, (int)lwpid);
 204 
 205         if (stat(fname, &statb) != 0)
 206                 return (PS_BADLID);
 207 
 208         if (statb.st_size > INT_MAX)
 209                 return (PS_ERR);
 210 
 211         *xrsize = (int)statb.st_size;
 212         return (PS_OK);
 213 }
 214 
 215 ps_err_e
 216 ps_lgetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
 217 {
 218         size_t xregsize;
 219         prxregset_t *prx;
 220 
 221         if (P->state != PS_STOP && P->state != PS_DEAD)
 222                 return (PS_ERR);
 223 
 224         if (Plwp_getxregs(P, lwpid, &prx, &xregsize) == 0) {
 225                 (void) memcpy(xregs, prx, xregsize);
 226                 Plwp_freexregs(P, prx, xregsize);
 227                 return (PS_OK);
 228         }
 229 
 230         if (errno == ENODATA)
 231                 return (PS_NOXREGS);
 232 
 233         return (PS_BADLID);
 234 }
 235 
 236 ps_err_e
 237 ps_lsetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
 238 {
 239         size_t xregsize = 0;
 240 
 241         if (P->state != PS_STOP)
 242                 return (PS_ERR);
 243 
 244         /*
 245          * libproc asks the caller for the size of the extended register set.
 246          * Unfortunately, right now we aren't given the actual size of this
 247          * ourselves and we don't want to break the ABI that folks have used
 248          * historically. Therefore, we reach in and ask the structure in a
 249          * platform-specific way about what this should be. Sorry, this is a bit
 250          * unfortunate. This really shouldn't be a platform-specific #ifdef.
 251          */
 252 #if defined(__i386) || defined(__amd64)
 253         prxregset_hdr_t *hdr = (prxregset_hdr_t *)xregs;
 254         xregsize = hdr->pr_size;
 255 #endif
 256         if (xregsize == 0)
 257                 return (PS_ERR);
 258 
 259         if (Plwp_setxregs(P, lwpid, (prxregset_t *)xregs, xregsize) == 0)
 260                 return (PS_OK);
 261 
 262         return (PS_BADLID);
 263 }
 264 
 265 #if defined(sparc) || defined(__sparc)
 266 ps_err_e
 267 ps_lsetxregs(struct ps_prochandle *P, lwpid_t lwpid, caddr_t xregs)
 268 {
 269         if (P->state != PS_STOP)
 270                 return (PS_ERR);
 271 
 272         /* LINTED - alignment */
 273         if (Plwp_setxregs(P, lwpid, (prxregset_t *)xregs) == 0)
 274                 return (PS_OK);
 275 
 276         return (PS_BADLID);
 277 }
 278 
 279 #endif  /* sparc */
 280 
 281 #if defined(__i386) || defined(__amd64)
 282 
 283 ps_err_e
 284 ps_lgetLDT(struct ps_prochandle *P, lwpid_t lwpid, struct ssd *ldt)
 285 {
 286 #if defined(__amd64) && defined(_LP64)
 287         if (P->status.pr_dmodel != PR_MODEL_NATIVE) {