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