Print this page
3946 ::gcore
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   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 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 #include <stdarg.h>
  29 #include <string.h>
  30 #include "Pcontrol.h"
  31 
  32 /*
  33  * This file implements the process services declared in <proc_service.h>.
  34  * This enables libproc to be used in conjunction with libc_db and
  35  * librtld_db.  As most of these facilities are already provided by
  36  * (more elegant) interfaces in <libproc.h>, we can just call those.
  37  *
  38  * NOTE: We explicitly do *not* implement the functions ps_kill() and
  39  * ps_lrolltoaddr() in this library.  The very existence of these functions
  40  * causes libc_db to create an "agent thread" in the target process.
  41  * The only way to turn off this behavior is to omit these functions.
  42  */
  43 
  44 #pragma weak ps_pdread = ps_pread
  45 #pragma weak ps_ptread = ps_pread
  46 #pragma weak ps_pdwrite = ps_pwrite
  47 #pragma weak ps_ptwrite = ps_pwrite
  48 
  49 ps_err_e
  50 ps_pdmodel(struct ps_prochandle *P, int *modelp)
  51 {
  52         *modelp = P->status.pr_dmodel;
  53         return (PS_OK);
  54 }
  55 
  56 ps_err_e
  57 ps_pread(struct ps_prochandle *P, psaddr_t addr, void *buf, size_t size)
  58 {
  59         if (P->ops->p_pread(P, buf, size, addr) != size)
  60                 return (PS_BADADDR);
  61         return (PS_OK);
  62 }
  63 
  64 ps_err_e
  65 ps_pwrite(struct ps_prochandle *P, psaddr_t addr, const void *buf, size_t size)
  66 {
  67         if (P->ops->p_pwrite(P, buf, size, addr) != size)
  68                 return (PS_BADADDR);
  69         return (PS_OK);
  70 }
  71 
  72 /*
  73  * libc_db calls matched pairs of ps_pstop()/ps_pcontinue()
  74  * in the belief that the client may have left the process
  75  * running while calling in to the libc_db interfaces.
  76  *
  77  * We interpret the meaning of these functions to be an inquiry
  78  * as to whether the process is stopped, not an action to be
  79  * performed to make it stopped.  For similar reasons, we also
  80  * return PS_OK for core files in order to allow libc_db to
  81  * operate on these as well.
  82  */
  83 ps_err_e
  84 ps_pstop(struct ps_prochandle *P)
  85 {
  86         if (P->state != PS_STOP && P->state != PS_DEAD)
  87                 return (PS_ERR);




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   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
  51 ps_pdmodel(struct ps_prochandle *P, int *modelp)
  52 {
  53         *modelp = P->status.pr_dmodel;
  54         return (PS_OK);
  55 }
  56 
  57 ps_err_e
  58 ps_pread(struct ps_prochandle *P, psaddr_t addr, void *buf, size_t size)
  59 {
  60         if (P->ops.pop_pread(P, buf, size, addr, P->data) != size)
  61                 return (PS_BADADDR);
  62         return (PS_OK);
  63 }
  64 
  65 ps_err_e
  66 ps_pwrite(struct ps_prochandle *P, psaddr_t addr, const void *buf, size_t size)
  67 {
  68         if (P->ops.pop_pwrite(P, buf, size, addr, P->data) != size)
  69                 return (PS_BADADDR);
  70         return (PS_OK);
  71 }
  72 
  73 /*
  74  * libc_db calls matched pairs of ps_pstop()/ps_pcontinue()
  75  * in the belief that the client may have left the process
  76  * running while calling in to the libc_db interfaces.
  77  *
  78  * We interpret the meaning of these functions to be an inquiry
  79  * as to whether the process is stopped, not an action to be
  80  * performed to make it stopped.  For similar reasons, we also
  81  * return PS_OK for core files in order to allow libc_db to
  82  * operate on these as well.
  83  */
  84 ps_err_e
  85 ps_pstop(struct ps_prochandle *P)
  86 {
  87         if (P->state != PS_STOP && P->state != PS_DEAD)
  88                 return (PS_ERR);