1.\" 2.\" This file and its contents are supplied under the terms of the 3.\" Common Development and Distribution License ("CDDL"), version 1.0. 4.\" You may only use this file in accordance with the terms of version 5.\" 1.0 of the CDDL. 6.\" 7.\" A full copy of the text of the CDDL should have accompanied this 8.\" source. A copy of the CDDL is also available via the Internet at 9.\" http://www.illumos.org/license/CDDL. 10.\" 11.\" 12.\" Copyright 2015 Joyent, Inc. 13.\" 14.Dd June 06, 2016 15.Dt LIBPROC 3LIB 16.Os 17.Sh NAME 18.Nm libproc 19.Nd process control library 20.Sh SYNOPSIS 21.Lb libproc 22.In libproc.h 23.Sh DESCRIPTION 24The 25.Nm 26library provides consumers a general series of interfaces to inspect 27and control both live processes and core files. 28It is intended for introspection tools such as debuggers by providing a 29high-level interface to the /proc file system 30.Pf ( Xr proc 4 ) . 31.Pp 32The 33.Nm 34library provides interfaces that focus on: 35.Bl -bullet -offset indent 36.It 37Creating and attaching to live process, core files, and arbitrary ELF 38objects. 39.It 40Interrogating the state of a process or core file. 41.It 42Manipulating the current state of a process or thread. 43.It 44Interrogating the state of threads of a process or core file. 45.It 46Running system calls in the context of another process. 47.It 48Various utilities for iterating process and core file file descriptors, 49mappings, symbols, and more. 50.It 51Various utilities to support debugging tools. 52.El 53.Ss Live Processes 54The 55.Nm 56library can be used to manipulate running processes and to create new 57ones. 58To manipulate an existing process first 59.Em grab 60it with the 61.Em Pgrab 62function. 63A process is generally stopped as a side effect of grabbing it. 64Callers must exercise caution, as if they do not use the library correctly, or 65they terminate unexpectedly, a process may remain stopped. 66.Pp 67Unprivileged users may only grab their own processes. 68Users with the privilege 69.Sy PRIV_PROC_OWNER 70may manipulate processes that they do not own; however, additional 71restrictions as described in 72.Xr privileges 5 73apply. 74.Pp 75In addition, the 76.Fn Pcreate 77and 78.Fn Pxcreate 79functions may be used to create processes which are always controlled by 80the library. 81.Ss Core Files 82The 83.Nm 84library has the ability to open and interpret core files produced by 85processes on the system. 86Process core dump generation is controlled by the 87.Xr coreadm 1M 88command. 89In addition, the library has the ability to understand and interpret core dumps 90generated by Linux kernel and can provide a subset of its functionality on such 91core files, provided the original binary is also present. 92.Pp 93Not all functions in the 94.Nm 95library are valid for core files. 96In general, none of the commands which manipulate the current state of a process 97or thread or that try to force system calls on a victim process will work. 98Furthermore several of the information and iteration interfaces are limited 99based on the data that is available in the core file. 100For example, if the core file is of a process that omits the frame pointer, the 101ability to iterate the stack will be limited. 102.Pp 103Use the 104.Fn Pgrab_core 105or 106.Fn Pfgrab_core 107function to open a core file. 108Use the 109.Fn Pgrab_file 110function to open an ELF object file. 111This is useful for obtaining information stored in ELF headers and 112sections. 113.Ss Debug Information 114Many of the operations in the library rely on debug information being 115present in a process and its associated libraries. 116The library leverages symbol table information, CTF data 117.Pf ( Xr CTF 4 ) 118sections, and frame unwinding information based on the use of an ABI 119defined frame pointer, eg. 120.Sy %ebp 121and 122.Sy %rbp 123on x86 systems. 124.Pp 125Some software providers strip programs of this information or build 126their executables such that the information will not be present in a 127core dump. 128To deal with this fact, the library is able to consume information that is not 129present in the core file or the running process. 130It can both consume it from the underlying executable and it also supports 131finding it from related ELF objects that are linked to it via the 132.Sy .gnu_debuglink 133and the 134.Sy .note.gnu.build-id 135ELF sections. 136.Ss Iteration Interfaces 137The 138.Nm 139library provides the ability to iterate over the following aspects of a 140process or core file: 141.Bl -bullet -offset indent 142.It 143Active threads 144.It 145Active and zombie threads 146.It 147All non-system processes 148.It 149All process mappings 150.It 151All objects in a process 152.It 153The environment 154.It 155The symbol table 156.It 157Stack frames 158.It 159File Descriptors 160.El 161.Ss System Call Injection 162The 163.Nm 164library allows the caller to force system calls to be executed in the 165context of the running process. 166This can be used both as a tool for introspection, allowing one to get 167information outside its current context as well as performing modifications to a 168process. 169.Pp 170These functions run in the context of the calling process. 171This is often an easier way of getting non-exported information about a 172process from the system. 173For example, the 174.Xr pfiles 1 175command uses this interface to get more detailed information about a 176process's open file descriptors, which it would not have access to 177otherwise. 178.Sh INTERFACES 179The shared object 180.Sy libproc.so.1 181provides the public interfaces defined below. 182See 183.Xr Intro 3 184for additional information on shared object interfaces. 185Functions are organized into categories that describe their purpose. 186Individual functions are documented in their own manual pages. 187.Ss Creation, Grabbing, and Releasing 188The following routines are related to creating library handles, 189grabbing cores, processes, and threads, and releasing those resources. 190.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 191.It Sy Lfree Ta Sy Lgrab 192.It Sy Lgrab_error Ta Sy Pcreate 193.It Sy Pcreate_agent Ta Sy Pcreate_callback 194.It Sy Pcreate_error Ta Sy Pdestroy_agent 195.It Sy Pfgrab_core Ta Sy Pfree 196.It Sy Pgrab Ta Sy Pgrab_core 197.It Sy Pgrab_error Ta Sy Pgrab_file 198.It Sy Pgrab_ops Ta Sy Prelease 199.It Sy Preopen Ta Sy Pxcreate 200.El 201.Ss Process interrogation and manipulation 202The following routines obtain information about a process and allow 203manipulation of the process itself. 204.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 205.It Sy Paddr_to_ctf Ta Sy Paddr_to_loadobj 206.It Sy Paddr_to_map Ta Sy Paddr_to_text_map 207.It Sy Pasfd Ta Sy Pclearfault 208.It Sy Pclearsig Ta Sy Pcontent 209.It Sy Pcred Ta Sy Pctlfd 210.It Sy Pdelbkpt Ta Sy Pdelwapt 211.It Sy Pdstop Ta Sy Pexecname 212.It Sy Pfault Ta Sy Pfgcore 213.It Sy Pgcore Ta Sy Pgetareg 214.It Sy Pgetauxval Ta Sy Pgetauxvec 215.It Sy Pgetenv Ta Sy Pisprocdir 216.It Sy Pissyscall_prev Ta Sy Plmid 217.It Sy Plmid_to_loadobj Ta Sy Plmid_to_map 218.It Sy Plookup_by_addr Ta Sy Plookup_by_name 219.It Sy Plwp_alt_stack Ta Sy Plwp_getfpregs 220.It Sy Plwp_getpsinfo Ta Sy Plwp_getregs 221.It Sy Plwp_getspymaster Ta Sy Plwp_main_stack 222.It Sy Plwp_setfpregs Ta Sy Plwp_setregs 223.It Sy Plwp_stack Ta Sy Pname_to_ctf 224.It Sy Pname_to_loadobj Ta Sy Pname_to_map 225.It Sy Pobjname Ta Sy Pobjname_resolved 226.It Sy Pplatform Ta Sy Ppltdest 227.It Sy Ppriv Ta Sy Ppsinfo 228.It Sy Pputareg Ta Sy Prd_agent 229.It Sy Pread Ta Sy Pread_string 230.It Sy Preset_maps Ta Sy Psetbkpt 231.It Sy Psecflags Ta Sy Psetcred 232.It Sy Psetfault Ta Sy Psetflags 233.It Sy Psetpriv Ta Sy Psetrun 234.It Sy Psetsignal Ta Sy Psetsysentry 235.It Sy Psetsysexit Ta Sy Psetwapt 236.It Sy Psetzoneid Ta Sy Psignal 237.It Sy Pstate Ta Sy Pstatus 238.It Sy Pstop Ta Sy Pstopstatus 239.It Sy Psync Ta Sy Psysentry 240.It Sy Psysexit Ta Sy Puname 241.It Sy Punsetflags Ta Sy Pupdate_maps 242.It Sy Pupdate_syms Ta Sy Pwait 243.It Sy Pwrite Ta Sy Pxecbkpt 244.It Sy Pxecwapt Ta Sy Pxlookup_by_addr 245.It Sy Pxlookup_by_addr_resolved Ta Sy Pxlookup_by_name 246.It Sy Pzonename Ta Sy Pzonepath 247.It Sy Pzoneroot Ta 248.El 249.Ss Thread interrogation and manipulation 250The following routines obtain information about a thread and allow 251manipulation of the thread itself. 252.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 253.It Sy Lalt_stack Ta Sy Lclearfault 254.It Sy Lclearsig Ta Sy Lctlfd 255.It Sy Ldstop Ta Sy Lgetareg 256.It Sy Lmain_stack Ta Sy Lprochandle 257.It Sy Lpsinfo Ta Sy Lputareg 258.It Sy Lsetrun Ta Sy Lstack 259.It Sy Lstate Ta Sy Lstatus 260.It Sy Lstop Ta Sy Lsync 261.It Sy Lwait Ta Sy Lxecbkpt 262.It Sy Lxecwapt Ta "" 263.El 264.Ss System Call Injection 265The following routines are used to inject specific system calls and have 266them run in the context of a process. 267.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 268.It Sy pr_access Ta Sy pr_close 269.It Sy pr_creat Ta Sy pr_door_info 270.It Sy pr_exit Ta Sy pr_fcntl 271.It Sy pr_fstat Ta Sy pr_fstat64 272.It Sy pr_fstatvfs Ta Sy pr_getitimer 273.It Sy pr_getpeername Ta Sy pr_getpeerucred 274.It Sy pr_getprojid Ta Sy pr_getrctl 275.It Sy pr_getrlimit Ta Sy pr_getrlimit64 276.It Sy pr_getsockname Ta Sy pr_getsockopt 277.It Sy pr_gettaskid Ta Sy pr_getzoneid 278.It Sy pr_ioctl Ta Sy pr_link 279.It Sy pr_llseek Ta Sy pr_lseek 280.It Sy pr_lstat Ta Sy pr_lstat64 281.It Sy pr_memcntl Ta Sy pr_meminfo 282.It Sy pr_mmap Ta Sy pr_munmap 283.It Sy pr_open Ta Sy pr_processor_bind 284.It Sy pr_rename Ta Sy pr_setitimer 285.It Sy pr_setrctl Ta Sy pr_setrlimit 286.It Sy pr_setrlimit64 Ta Sy pr_settaskid 287.It Sy pr_sigaction Ta Sy pr_stat 288.It Sy pr_stat64 Ta Sy pr_statvfs 289.It Sy pr_unlink Ta Sy pr_waitid 290.El 291.Ss Iteration routines 292These routines are used to iterate over the contents of a process. 293.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 294.It Sy Penv_iter Ta Sy Plwp_iter 295.It Sy Plwp_iter_all Ta Sy Pmapping_iter 296.It Sy Pmapping_iter_resolved Ta Sy Pobject_iter 297.It Sy Pobject_iter_resolved Ta Sy Pstack_iter 298.It Sy Psymbol_iter Ta Sy Psymbol_iter_by_addr 299.It Sy Psymbol_iter_by_lmid Ta Sy Psymbol_iter_by_name 300.It Sy Pxsymbol_iter Ta Sy Pfdinfo_iter 301.El 302.Ss Utility routines 303The following routines are utilities that are useful to consumers of the 304library. 305.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 306.It Sy Perror_printf Ta Sy proc_arg_grab 307.It Sy proc_arg_psinfo Ta Sy proc_arg_xgrab 308.It Sy proc_arg_xpsinfo Ta Sy proc_content2str 309.It Sy proc_finistdio Ta Sy proc_fltname 310.It Sy proc_fltset2str Ta Sy proc_flushstdio 311.It Sy proc_get_auxv Ta Sy proc_get_cred 312.It Sy proc_get_priv Ta Sy proc_get_psinfo 313.It Sy proc_get_status Ta Sy proc_initstdio 314.It Sy proc_lwp_in_set Ta Sy proc_lwp_range_valid 315.It Sy proc_signame Ta Sy proc_sigset2str 316.It Sy proc_str2content Ta Sy proc_str2flt 317.It Sy proc_str2fltset Ta Sy proc_str2sig 318.It Sy proc_str2sigset Ta Sy proc_str2sys 319.It Sy proc_str2sysset Ta Sy proc_sysname 320.It Sy proc_sysset2str Ta Sy proc_unctrl_psinfo 321.It Sy proc_walk Ta "" 322.El 323.Ss x86 Specific Routines 324The following routines are specific to the x86, 32-bit and 64-bit, 325versions of the 326.Nm 327library. 328.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 329.It Sy Pldt Ta Sy proc_get_ldt 330.El 331.Ss SPARC specific Routines 332The following functions are specific to the SPARC, 32-bit and 64-bit, 333versions of the 334.Nm 335library. 336.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 337.It Sy Plwp_getgwindows Ta Sy Plwp_getxregs 338.It Sy Plwp_setxregs Ta Sy "" 339.El 340.Pp 341The following functions are specific to the 64-bit SPARC version of the 342.Nm 343library. 344.Bl -column -offset indent ".Sy Pmapping_iter_resolved" ".Sy Psymbol_iter_by_addr" 345.It Sy Plwp_getasrs Ta Sy Plwp_setasrs 346.El 347.Sh PROCESS STATES 348Every process handle that exists in 349.Nm 350has a state. 351In some cases, such as for core files, these states are static. 352In other cases, such as handles that correspond to a running process or a 353created process, these states are dynamic and change based on actions taken in 354the library. 355The state can be obtained with the 356.Xr Pstate 3PROC 357function. 358.Pp 359The various states are: 360.Bl -tag -width Dv -offset indent 361.It Dv PS_RUN 362An actively running process. 363This may be a process that was obtained by creating it with functions such as 364.Xr Pcreate 3PROC 365or by grabbing an existing process such as 366.Xr Pgrab 3PROC . 367.It Dv PS_STOP 368An active process that is no longer executing. 369A process may stop for many reasons such as an explicit stop request (through 370.Xr pstop 1 371for example) or if a tracing event is hit. 372.Pp 373The reason a process is stopped may be obtained through the thread's 374.Sy lwpstatus_t 375structure read directly from /proc or obtained through the 376.Xr Lstatus 3PROC 377function. 378.It Dv PS_LOST 379Control over the process has been lost. 380This may happen when the process executes a new image requiring a different set 381of privileges. 382To resume control call 383.Xr Preopen 3PROC . 384For more information on losing control of a process, see 385.Xr proc 4 . 386.It DV PS_UNDEAD 387A zombie process. 388It has terminated, but it has not been cleaned up yet by its parent. 389For more on the conditions of becoming a zombie, see 390.Xr exec 2 . 391.It DV_PS_DEAD 392Processes in this state are always core files. 393See the earlier section 394.Sx Core Files 395for more information on working with core files. 396.It Dv PS_IDLE 397A process that has never been run. 398This is always the case for handles that refer to files as the files cannot be 399executed. 400Those process handles are obtained through calling 401.Xr Pgrab_file 3PROC . 402.El 403.Pp 404Many functions relating to tracing processes, for example 405.Xr Psignal 3PROC , 406.Xr Psetsignal 3PROC , 407.Xr Psetfault 3PROC , 408.Xr Psetentry 3PROC , 409and others, mention that they only act upon 410.Em Active Processes . 411This specifically refers to processes whose state are in 412.Dv PS_RUN 413and 414.Dv PS_STOP . 415Process handles in the other states have no notion of settable tracing 416flags, though core files 417.Pf ( type Dv PS_DEAD ) , 418======= 419may have a read-only snapshot of their tracing settings available. 420.Sh TYPES 421The 422.Nm 423library uses many types that come from the /proc file system 424.Pf ( Xr proc 4 ) 425and the ELF format 426.Pf ( Xr elf 3ELF ) . 427However, it also defines the following types: 428.Pp 429.Sy struct ps_prochandle 430.Pp 431The 432.Sy struct ps_prochandle 433is an opaque handle to the library and the core element of control for a 434process. 435Consumers obtain pointers to a handle through the use of the 436.Fn Pcreate , 437.Fn Pgrab , 438and related functions. 439When a caller is done with a handle, then it should call one of the 440.Fn Pfree 441and 442.Fn Prelease 443functions to relinquish the handle, release associated resources, and 444potentially set the process to run again. 445.Pp 446.Sy struct ps_lwphandle 447.Pp 448The 449.Sy struct ps_lwphandle 450is analogous to the 451.Sy struct ps_prochandle , 452but it represents the control of an individual thread, rather than a 453process. 454Consumers obtain pointers to a handle through the 455.Fn Lgrab 456function and relinquish it with the 457.Fn Lfree 458function. 459.Pp 460.Sy core_content_t 461.Pp 462The 463.Sy core_content_t 464is a value which describes the various content types of core files. 465These are used in functions such as 466.Xr Pcontent 3PROC 467and 468.Xr Pgcore 3PROC 469to describe and control the types of content that get included. 470Various content types may be included together through a bitwise-inclusive-OR. 471The default system core contents are controlled with the 472.Xr coreadm 1M 473tool. 474The following table lists the current set of core contents in the system, though 475the set may increase over time. 476The string after the macro is the human readable string that corresponds with 477the constant and is used by 478.Xr coreadm 1M , 479.Xr proc_content2str 3PROC , 480and 481.Xr proc_str2content 3PROC . 482.Bl -tag -offset indent -width indent 483.It Dv CC_CONTENT_STACK ("stack") 484The contents include the process stack. 485Note, this only covers the main thread's stack. 486The stack of other threads is covered by 487.Dv CC_CONTENT_ANON . 488.It Dv CC_CONTENT_HEAP ("heap") 489The contents include the process heap. 490.It Dv CC_CONTENT_SHFILE ("shfile") 491The contents include shared mappings that are backed by files (e.g. 492mapped through 493.Xr mmap 2 494with the 495.Dv MAP_SHARED 496flag). 497.It Dv CC_CONTENT_SHANNON ("shannon") 498The contents include shared mappings that are backed by anonymous memory 499(e.g. mapped through 500.Xr mmap 2 501with the 502.Dv MAP_SHARED 503and 504.Dv MAP_ANON 505flags). 506.It Dv CC_CONTENT_RODATA ("rodata") 507The contents include private read-only file mappings, such as shared 508library text. 509.It Dv CC_CONTENT_ANON ("anon") 510The contents include private anonymous mappings. 511This includes the stacks of threads which are not the main thread. 512.It Dv CC_CONTENT_SHM ("shm") 513The contents include system V shared memory. 514.It Dv CC_CONTENT_ISM ("ism") 515The contents include ISM (intimate shared memory) mappings. 516.It Dv CC_CONTENT_DISM ("dism") 517The contents include DISM (dynamic shared memory) mappings. 518.It Dv CC_CONTENT_CTF ("ctf") 519The contents include 520.Xr ctf 4 521(Compact C Type Format) information. 522Note, not all objects in the process may have CTF information available. 523.It Dv CC_CONTENT_SYMTAB ("symtab") 524The contents include the symbol table. 525Note, not all objects in the process may have a symbol table available. 526.It Dv CC_CONTENT_ALL ("all") 527This value indicates that all of the above content values are present. 528Note that additional values may be added in the future, in which case 529the value of the symbol will be updated to include them. 530Comparisons with 531.Dv CC_CONTENT_ALL 532should validate all the expected bits are set by an expression such as 533.Li (c & CC_CONTENT_ALL) == CC_CONTENT_ALL . 534.It Dv CC_CONTENT_NONE ("none") 535This value indicates that there is no content present. 536.It Dv CC_CONTENT_DEFAULT ("default") 537The content includes the following set of default values: 538.Dv CC_CONTENT_STACK , 539.Dv CC_CONTENT_HEAP , 540.Dv CC_CONTENT_ISM , 541.Dv CC_CONTENT_DISM , 542.Dv CC_CONTENT_SHM , 543.Dv CC_CONTENT_SHANON , 544.Dv CC_CONTENT_TEXT , 545.Dv CC_CONTENT_DATA , 546.Dv CC_CONTENT_RODATA , 547.Dv CC_CONTENT_ANON , 548.Dv CC_CONTENT_CTF , 549and 550.Dv CC_CONTENT_SYMTAB. 551Note that the default may change. 552Comparisons with CC_CONTENT_DEFAULT should validate that all of the expected 553bits are set with an expression such as 554.Li (c\ &\ CC_CONTENT_DEFAULT)\ ==\ CC_CONTENT_DEFAULT. 555.It Dv CC_CONTENT_INVALID 556This indicates that the contents are invalid. 557.El 558.Pp 559.Sy prfdinfo_t 560.Pp 561The 562.Sy prfdinfo_t 563structure is used with the 564.Fn Pfdinfo_iter 565function which describes information about a file descriptor. 566The structure is defined as follows: 567.Bd -literal 568typedef struct prfdinfo { 569 int pr_fd; 570 mode_t pr_mode; 571 uid_t pr_uid; 572 gid_t pr_gid; 573 major_t pr_major; /* think stat.st_dev */ 574 minor_t pr_minor; 575 major_t pr_rmajor; /* think stat.st_rdev */ 576 minor_t pr_rminor; 577 ino64_t pr_ino; 578 off64_t pr_offset; 579 off64_t pr_size; 580 int pr_fileflags; /* fcntl(F_GETXFL), etc */ 581 int pr_fdflags; /* fcntl(F_GETFD), etc. */ 582 char pr_path[MAXPATHLEN]; 583} prfdinfo_t; 584.Ed 585.Pp 586The structure has similar information to that found in the 587.Sy stat 588structure that's used as part of the stat family of system calls, 589defined in 590.Xr stat 2 . 591The member 592.Sy pr_fd 593contains the number of the file descriptor of the file. 594The members 595.Sy pr_mode , 596.Sy pr_uid , 597.Sy pr_gid , 598.Sy pr_ino , 599and 600.Sy pr_size 601are the same as the members 602.Sy st_mode , 603.Sy st_uid , 604.Sy st_gid , 605.Sy st_ino , 606and 607.Sy st_size 608in the 609.Sy stat 610structure. 611.Pp 612The 613.Sy pr_major 614and 615.Sy pr_minor 616members contain the major and minor numbers of the device containing the 617directory for this file. 618This is similar to the 619.Sy st_dev 620member of the 621.Sy stat 622structure, except that it is broken out into its major and minor components. 623The 624.Sy pr_rmajor 625and 626.Sy pr_rminor 627members are similar in spirit to 628.Sy pr_major 629and 630.Sy pr_minor ; 631however, they are equivalent to the 632.Sy st_rdev 633member of the 634.Sy stat 635structure and thus have meaning for special character and block files. 636.Pp 637The 638.Sy pr_offset 639member contains the current seek offset of the file descriptor. 640The 641.Sy pr_fileflags 642and 643.Sy pr_fdflags 644members contain the flags that would have been returned by a call to 645.Xr fcntl 2 646with the arguments 647.Dv F_GETXFL 648and 649.Dv F_GETFD 650respectively. 651.Pp 652.Sy prsyminfo_t 653.Pp 654The 655.Sy prsyminfo_t 656structure is used with the various symbol look up functions 657.Fn Pxlookup_by_name , 658.Fn Pxlookup_by_addr , 659and 660.Fn Pxlookup_by_addr_resolved 661which describes additional information about a symbol. 662The structure is defined as follows: 663.Bd -literal 664typedef struct prsyminfo { 665 const char *prs_object; /* object name */ 666 const char *prs_name; /* symbol name */ 667 Lmid_t prs_lmid; /* link map id */ 668 uint_t prs_id; /* symbol id */ 669 uint_t prs_table; /* symbol table id */ 670} prsyminfo_t; 671.Ed 672.Pp 673The member 674.Sy prs_object 675points to a string that contains the name of the object file, if known, 676that the symbol comes from. 677The member 678.Sy prs_name 679points to the name of the symbol, if known. 680This may be unknown due to a stripped binary that contains no symbol table. 681The member 682.Sy prs_lmid 683indicates the link map identifier that the symbol was found on. 684For more information on link map identifiers refer to the 685.Em Linker and Libraries Guide 686and 687.Xr dlopen 3C . 688.Pp 689The members 690.Sy prs_id 691and 692.Sy prs_table 693can be used to determine both the symbol table that the entry came from 694and which entry in the table it corresponds to. 695If the value of 696.Sy prs_table 697is 698.Dv PR_SYMTAB 699then it came from the ELF standard symbol table. 700However, if it is instead 701.Dv PR_DYNSYM , 702then that indicates that it comes from the process's dynamic section. 703.Pp 704.Sy proc_lwp_f 705.Pp 706The 707.Sy proc_lwp_f 708is a function pointer type that is used with the 709.Fn Plwp_iter 710function. 711It is defined as 712.Sy typedef 713.Ft int 714.Fo proc_lwp_f 715.Fa "void *" 716.Fa "const lwpstatus_t *" 717.Fc . 718The first argument is a pointer to an argument that the user specifies, 719while the second has the thread's status information and is defined in 720.Xr proc 4 . 721For additional information on using this type, see 722.Xr Plwp_iter 3PROC . 723.Pp 724.Sy proc_lwp_all_f 725.Pp 726The 727.Sy proc_lwp_all_f 728is a function pointer type that is used with the 729.Fn Plwp_iter_all 730function. 731It is defined as 732.Sy typedef 733.Ft int 734.Fo proc_lwp_all_f 735.Fa "void *" 736.Fa "const lwpstatus_t *" 737.Fa "const lwpsinfo_t *" 738.Fc . 739The first argument is a pointer to an argument that the user specifies. 740The second and third arguments contain the thread's status and 741thread-specific 742.Xr ps 1 743information respectively. 744Both structures are defined in 745.Xr proc 4 . 746For additional information on using this type, see 747.Xr Plwp_iter_all 3PROC . 748.Pp 749.Sy proc_walk_f 750.Pp 751The 752.Sy proc_walk_f 753is a function pointer type that is used with the 754.Fn proc_walk 755function. 756It is defined as 757.Sy typedef 758.Ft int 759.Fo proc_walk_f 760.Fa "psinfo_t *" 761.Fa "lwpsinfo_t *" 762.Fa "void *" 763.Fc . 764The first argument contains the process 765.Xr ps 1 766information and the second argument contains the representative thread's 767.Xr ps 1 768information. 769Both structures are defined in 770.Xr proc 4 . 771The final argument is a pointer to an argument that the user specifies. 772For more information on using this, see 773.Xr proc_walk 3PROC . 774.Pp 775.Sy proc_map_f 776.Pp 777The 778.Sy proc_map_f 779is a function pointer type that is used with the 780.Fn Pmapping_iter , 781.Fn Pmapping_iter_resolved , 782.Fn Pobject_iter , 783and 784.Fn Pobject_iter_resolved 785functions. 786It is defined as 787.Sy typedef 788.Ft int 789.Fo proc_map_f 790.Fa "void *" 791.Fa "const prmap_t *" 792.Fa "const char *" 793.Fc . 794The first argument is a pointer to an argument that the user specifies. 795The second argument is describes the mapping information and is defined 796in 797.Xr proc 4 . 798The final argument contains the name of the mapping or object file in 799question. 800For additional information on using this type, see 801.Xr Pmapping_iter 3PROC . 802.Pp 803.Sy proc_env_f 804.Pp 805The 806.Sy proc_env_f 807is a function pointer type that is used with the 808.Fn Penv_iter 809function. 810It is defined as 811.Sy typedef 812.Ft int 813.Fo proc_env_f 814.Fa "void *" 815.Fa "struct ps_prochandle *" 816.Fa "uintptr_t" 817.Fa "const char *" 818.Fc . 819The first argument is a pointer to an argument that the user specifies. 820The second argument is a pointer to the 821.Sy struct ps_prochandle 822that the callback was passed to. 823The third argument is the address of the environment variable in the process. 824The fourth argument is the environment variable. 825Values in the environment follow the convention of the form 826.Em variable=value . 827For more information on environment variables see 828.Xr exec 2 829and 830.Xr environ 5 . 831For additional information on using this type, see 832.Xr Penv_iter 3PROC . 833.Pp 834.Sy proc_sym_f 835.Pp 836The 837.Sy proc_sym_f 838is a function pointer type that is used with the 839.Fn Psmbol_iter , 840.Fn Psymbol_iter_by_addr , 841.Fn Psymbol_iter_by_name , 842and 843.Fn Psymbol_iter_by_lmid 844functions. 845It is defined as 846.Sy typedef 847.Ft int 848.Fo proc_sym_f 849.Fa "void *" 850.Fa "const GElf_Sym *" 851.Fa "const char *" 852.Fc . 853The first argument is a pointer to an argument that the user supplies. 854The second argument is a pointer to the ELF symbol information in a 85532-bit and 64-bit neutral form. 856See 857.Xr elf 3ELF 858and 859.Xr gelf 3ELF 860for more information on it. 861The final argument points to a character string that has the name of the symbol. 862For additional information on using this type, see 863.Xr Psymbol_iter 3PROC , 864.Xr Psymbol_iter_by_addr 3PROC , 865.Xr Psymbol_iter_by_name 3PROC , 866and 867.Xr Psymbol_iter_by_lmid 3PROC . 868.Pp 869.Sy proc_xsym_f 870.Pp 871The 872.Sy proc_xsym_f 873is a function pointer type that is used with the 874.Fn Pxsymbol_iter 875function. 876It is defined as 877.Sy typedef 878.Ft int 879.Fo proc_xsym_f 880.Fa "void *" 881.Fa "const GElf_Sym *" 882.Fa "const char *" 883.Fa "const prsyminfo_t *" 884.Fc . 885The first three arguments are identical to those of 886.Sy proc_sym_f . 887The final argument contains additional information about the symbol 888itself. 889The members of the 890.Sy prsyminfo_t 891are defined earlier in this section. 892For additional information on using this type, see 893.Xr Pxsymbol_iter 3PROC . 894.Pp 895.Sy proc_stack_f 896.Pp 897The 898.Sy proc_stack_f 899is a function pointer type that is used with the 900.Fn Pstack_iter 901function. 902It is defined as 903.Sy typedef 904.Ft int 905.Fo proc_stack_f 906.Fa "void *" 907.Fa "prgregset_t" 908.Fa "uint_t" 909.Fa "const long *" 910.Fc . 911The first argument is a pointer to an argument that the user specifies. 912The second argument's contents are platform specific. 913The registers that contain stack information, usually the stack pointer and 914frame pointer, will be filled in to point to an entry. 915The 916.Sy prgregset_t 917is defined in 918.Xr proc 4 . 919.Pp 920The third argument contains the number of arguments to the current stack 921frame and the fourth argument contains an array of addresses that 922correspond to the arguments to that stack function. 923The value of the third argument dictates the number of entries in the fourth 924argument. 925For additional information on using this type, see 926.Xr Pstack_iter 3PROC . 927.Pp 928.Sy proc_fdinfo_f 929.Pp 930The 931.Sy proc_fdinfo_f 932is a function pointer type that is used with the 933.Fn Pfdinfo_iter 934function. 935It is defined as 936.Sy typedef 937.Ft int 938.Fo proc_fdinfo_f 939.Fa "void *" 940.Fa "prfdinfo_t *" 941.Fc . 942The first argument is a pointer to an argument that the user specifies. 943The second argument contains information about an open file descriptor. 944The members of the 945.Sy prfdinfo_t 946are defined earlier in this section. 947For additional information on using this type, see 948.Xr Pfdinfo_iter 3PROC . 949.Sh PROGRAMMING NOTES 950When working with live processes, whether from the 951.Xr Pgrab 3PROC 952or 953.Xr Pcreate 3PROC 954family of functions, there are some additional considerations. 955Importantly, if a process calls any of the 956.Xr exec 2 957suite of functions, much of the state information that is obtained, 958particularly that about mappings in the process will be invalid. 959Callers must ensure that they call 960.Xr Preset_maps 3PROC 961when they hold a process handle across an exec. 962In addition, users of the library should familiarize themselves with the 963.Sy PROGRAMMING NOTES 964section of the 965.Xr proc 4 966manual page, which discusses issues of privileges and security. 967.Sh DEBUGGING 968The library provides a means for obtaining additional debugging 969information. 970The output itself is not part of the 971.Nm 972library's stable interface. 973Setting the environment variable 974.Ev LIBPROC_DEBUG 975to some value will print information to standard error. 976For example, 977.Ev LIBPROC_DEUBG Ns = Ns Em please . 978.Sh LOCKING 979Most functions operate on a handle to a process in the form of a 980.Vt "struct ps_prochandle *" . 981Unless otherwise indicated, the library does not provide any 982synchronization for different routines that are operating on the 983.Sy same 984.Nm 985library handle. 986It is up to the caller to ensure that only a single thread is using a handle at 987any given time. 988Multiple threads may call 989.Nm 990library routines at the same time as long as each thread is using a 991different handle. 992.Pp 993Each individual function notes its 994.Sy MT-Level 995section. 996The MT-Level of a routine that matches the above description will refer to this 997manual page. 998If it does not, then it refers to the standard attributes in 999.Xr attributes 5 . 1000.Sh INTERFACE STABILITY 1001.Sy Uncommitted 1002.Pp 1003While the library is considered an uncommitted interface, and is still 1004evolving, changes that break compatibility have been uncommon and this 1005trend is expected to continue. 1006It is documented to allow consumers, whether part of illumos or outside of it, 1007to understand the libarary and make use of it with the understanding that 1008changes may occur which break both source and binary compatibility. 1009.Sh SEE ALSO 1010.Xr gcore 1 , 1011.Xr mdb 1 , 1012.Xr proc 1 , 1013.Xr ps 1 , 1014.Xr coreadm 1M , 1015.Xr exec 2 , 1016.Xr fcntl 2 , 1017.Xr stat 2 , 1018.Xr Intro 3 , 1019.Xr dlopen 3C , 1020.Xr elf 3ELF , 1021.Xr ctf 4 , 1022.Xr proc 4 , 1023.Xr attributes 5 , 1024.Xr environ 5 , 1025.Xr privileges 5 1026.Pp 1027.Rs 1028.%T Linkers and Libraries Guide 1029.Re 1030.Pp 1031.Xr Lfree 3PROC , 1032.Xr Lgrab 3PROC , 1033.Xr Lgrab_error 3PROC , 1034.Xr Pcreate 3PROC , 1035.Xr Pcreate_agent 3PROC , 1036.Xr Pcreate_callback 3PROC , 1037.Xr Pcreate_error 3PROC , 1038.Xr Pdestroy_agent 3PROC , 1039.Xr Pfgrab_core 3PROC , 1040.Xr Pfree 3PROC , 1041.Xr Pgrab 3PROC , 1042.Xr Pgrab_core 3PROC , 1043.Xr Pgrab_error 3PROC , 1044.Xr Pgrab_file 3PROC , 1045.Xr Pgrab_ops 3PROC , 1046.Xr Prelease 3PROC , 1047.Xr Preopen 3PROC , 1048.Xr Pxcreate 3PROC 1049.Pp 1050.Xr Paddr_to_ctf 3PROC , 1051.Xr Paddr_to_loadobj 3PROC , 1052.Xr Paddr_to_map 3PROC , 1053.Xr Paddr_to_text_map 3PROC , 1054.Xr Pasfd 3PROC , 1055.Xr Pclearfault 3PROC , 1056.Xr Pclearsig 3PROC , 1057.Xr Pcontent 3PROC , 1058.Xr Pcred 3PROC , 1059.Xr Pctlfd 3PROC , 1060.Xr Pdelbkpt 3PROC , 1061.Xr Pdelwapt 3PROC , 1062.Xr Pdstop 3PROC , 1063.Xr Pexecname 3PROC , 1064.Xr Pfault 3PROC , 1065.Xr Pfgcore 3PROC , 1066.Xr Pgcore 3PROC , 1067.Xr Pgetareg 3PROC , 1068.Xr Pgetauxval 3PROC , 1069.Xr Pgetauxvec 3PROC , 1070.Xr Pgetenv 3PROC , 1071.Xr Pisprocdir 3PROC , 1072.Xr Pissyscall_prev 3PROC , 1073.Xr Plmid 3PROC , 1074.Xr Plmid_to_loadobj 3PROC , 1075.Xr Plmid_to_map 3PROC , 1076.Xr Plookup_by_addr 3PROC , 1077.Xr Plookup_by_name 3PROC , 1078.Xr Plwp_alt_stack 3PROC , 1079.Xr Plwp_getfpregs 3PROC , 1080.Xr Plwp_getpsinfo 3PROC , 1081.Xr Plwp_getregs 3PROC , 1082.Xr Plwp_getspymaster 3PROC , 1083.Xr Plwp_main_stack 3PROC , 1084.Xr Plwp_setfpregs 3PROC , 1085.Xr Plwp_setregs 3PROC , 1086.Xr Plwp_stack 3PROC , 1087.Xr Pname_to_ctf 3PROC , 1088.Xr Pname_to_loadobj 3PROC , 1089.Xr Pname_to_map 3PROC , 1090.Xr Pobjname 3PROC , 1091.Xr Pobjname_resolved 3PROC , 1092.Xr Pplatform 3PROC , 1093.Xr Ppltdest 3PROC , 1094.Xr Ppriv 3PROC , 1095.Xr Ppsinfo 3PROC , 1096.Xr Pputareg 3PROC , 1097.Xr Prd_agent 3PROC , 1098.Xr Pread 3PROC , 1099.Xr Pread_string 3PROC , 1100.Xr Preset_maps 3PROC , 1101.Xr Psecflags 3PROC , 1102.Xr Psetbkpt 3PROC , 1103.Xr Psetcred 3PROC , 1104.Xr Psetfault 3PROC , 1105.Xr Psetflags 3PROC , 1106.Xr Psetpriv 3PROC , 1107.Xr Psetrun 3PROC , 1108.Xr Psetsignal 3PROC , 1109.Xr Psetsysentry 3PROC , 1110.Xr Psetsysexit 3PROC , 1111.Xr Psetwapt 3PROC , 1112.Xr Psetzoneid 3PROC , 1113.Xr Psignal 3PROC , 1114.Xr Pstate 3PROC , 1115.Xr Pstatus 3PROC , 1116.Xr Pstop 3PROC , 1117.Xr Pstopstatus 3PROC , 1118.Xr Psync 3PROC , 1119.Xr Psysentry 3PROC , 1120.Xr Psysexit 3PROC , 1121.Xr Puname 3PROC , 1122.Xr Punsetflags 3PROC , 1123.Xr Pupdate_maps 3PROC , 1124.Xr Pupdate_syms 3PROC , 1125.Xr Pwait 3PROC , 1126.Xr Pwrite 3PROC , 1127.Xr Pxecbkpt 3PROC , 1128.Xr Pxecwapt 3PROC , 1129.Xr Pxlookup_by_addr 3PROC , 1130.Xr Pxlookup_by_addr_resolved 3PROC , 1131.Xr Pxlookup_by_name 3PROC , 1132.Xr Pzonename 3PROC , 1133.Xr Pzonepath 3PROC , 1134.Xr Pzoneroot 3PROC 1135.Pp 1136.Xr Lalt_stack 3PROC , 1137.Xr Lclearfault 3PROC , 1138.Xr Lclearsig 3PROC , 1139.Xr Lctlfd 3PROC , 1140.Xr Ldstop 3PROC , 1141.Xr Lgetareg 3PROC , 1142.Xr Lmain_stack 3PROC , 1143.Xr Lprochandle 3PROC , 1144.Xr Lpsinfo 3PROC , 1145.Xr Lputareg 3PROC , 1146.Xr Lsetrun 3PROC , 1147.Xr Lstack 3PROC , 1148.Xr Lstate 3PROC , 1149.Xr Lstatus 3PROC , 1150.Xr Lstop 3PROC , 1151.Xr Lsync 3PROC , 1152.Xr Lwait 3PROC , 1153.Xr Lxecbkpt 3PROC , 1154.Xr Lxecwapt 3PROC 1155.Pp 1156.Xr pr_access 3PROC , 1157.Xr pr_close 3PROC , 1158.Xr pr_creat 3PROC , 1159.Xr pr_door_info 3PROC , 1160.Xr pr_exit 3PROC , 1161.Xr pr_fcntl 3PROC , 1162.Xr pr_fstat 3PROC , 1163.Xr pr_fstat64 3PROC , 1164.Xr pr_fstatvfs 3PROC , 1165.Xr pr_getitimer 3PROC , 1166.Xr pr_getpeername 3PROC , 1167.Xr pr_getpeerucred 3PROC , 1168.Xr pr_getprojid 3PROC , 1169.Xr pr_getrctl 3PROC , 1170.Xr pr_getrlimit 3PROC , 1171.Xr pr_getrlimit64 3PROC , 1172.Xr pr_getsockname 3PROC , 1173.Xr pr_getsockopt 3PROC , 1174.Xr pr_gettaskid 3PROC , 1175.Xr pr_getzoneid 3PROC , 1176.Xr pr_ioctl 3PROC , 1177.Xr pr_link 3PROC , 1178.Xr pr_llseek 3PROC , 1179.Xr pr_lseek 3PROC , 1180.Xr pr_lstat 3PROC , 1181.Xr pr_lstat64 3PROC , 1182.Xr pr_memcntl 3PROC , 1183.Xr pr_meminfo 3PROC , 1184.Xr pr_mmap 3PROC , 1185.Xr pr_munmap 3PROC , 1186.Xr pr_open 3PROC , 1187.Xr pr_processor_bind 3PROC , 1188.Xr pr_rename 3PROC , 1189.Xr pr_setitimer 3PROC , 1190.Xr pr_setrctl 3PROC , 1191.Xr pr_setrlimit 3PROC , 1192.Xr pr_setrlimit64 3PROC , 1193.Xr pr_settaskid 3PROC , 1194.Xr pr_sigaction 3PROC , 1195.Xr pr_stat 3PROC , 1196.Xr pr_stat64 3PROC , 1197.Xr pr_statvfs 3PROC , 1198.Xr pr_unlink 3PROC , 1199.Xr pr_waitid 3PROC , 1200.Pp 1201.Xr Penv_iter 3PROC , 1202.Xr Plwp_iter 3PROC , 1203.Xr Plwp_iter_all 3PROC , 1204.Xr Pmapping_iter 3PROC , 1205.Xr Pmapping_iter_resolved 3PROC , 1206.Xr Pobject_iter 3PROC , 1207.Xr Pobject_iter_resolved 3PROC , 1208.Xr Pstack_iter 3PROC , 1209.Xr Psymbol_iter 3PROC , 1210.Xr Psymbol_iter_by_addr 3PROC , 1211.Xr Psymbol_iter_by_lmid 3PROC , 1212.Xr Psymbol_iter_by_name 3PROC , 1213.Xr Pxsymbol_iter 3PROC , 1214.Xr Pfdinfo_iter 3PROC 1215.Pp 1216.Xr Perror_printf 3PROC , 1217.Xr proc_arg_grab 3PROC , 1218.Xr proc_arg_psinfo 3PROC , 1219.Xr proc_arg_xgrab 3PROC , 1220.Xr proc_arg_xpsinfo 3PROC , 1221.Xr proc_content2str 3PROC , 1222.Xr proc_finistdio 3PROC , 1223.Xr proc_fltname 3PROC , 1224.Xr proc_fltset2str 3PROC , 1225.Xr proc_flushstdio 3PROC , 1226.Xr proc_get_auxv 3PROC , 1227.Xr proc_get_cred 3PROC , 1228.Xr proc_get_priv 3PROC , 1229.Xr proc_get_psinfo 3PROC , 1230.Xr proc_get_status 3PROC , 1231.Xr proc_initstdio 3PROC , 1232.Xr proc_lwp_in_set 3PROC , 1233.Xr proc_lwp_range_valid 3PROC , 1234.Xr proc_signame 3PROC , 1235.Xr proc_sigset2str 3PROC , 1236.Xr proc_str2content 3PROC , 1237.Xr proc_str2flt 3PROC , 1238.Xr proc_str2fltset 3PROC , 1239.Xr proc_str2sig 3PROC , 1240.Xr proc_str2sigset 3PROC , 1241.Xr proc_str2sys 3PROC , 1242.Xr proc_str2sysset 3PROC , 1243.Xr proc_sysname 3PROC , 1244.Xr proc_sysset2str 3PROC , 1245.Xr proc_unctrl_psinfo 3PROC , 1246.Xr proc_walk 3PROC 1247.Pp 1248.Xr Pldt 3PROC , 1249.Xr proc_get_ldt 3PROC , 1250.Pp 1251.Xr Plwp_getgwindows 3PROC , 1252.Xr Plwp_getxregs 3PROC , 1253.Xr Plwp_setxregs 3PROC , 1254.Pp 1255.Xr Plwp_getasrs 3PROC , 1256.Xr Plwp_setasrs 3PROC 1257