Blob


1 .TH MACH-FILE 3
2 .SH NAME
3 crackhdr, uncrackhdr, mapfile, mapproc, detachproc, ctlproc,
4 procnotes \- machine-independent access to exectuable files and running processes
5 .SH SYNOPSIS
6 .B #include <u.h>
7 .br
8 .B #include <libc.h>
9 .br
10 .B #include <mach.h>
11 .PP
12 .ft B
13 .ta \w'\fBxxxxxx'u +\w'xxxxxx'u
14 int crackhdr(int fd, Fhdr *hdr)
15 .br
16 void uncrackhdr(Fhdr *hdr)
17 .PP
18 .ft B
19 int mapfile(Map *map, ulong base, Fhdr *hdr)
20 .br
21 int mapproc(Map *map, int pid)
22 .br
23 int detachproc(int pid)
24 .br
25 int ctlproc(int pid, char *msg)
26 .br
27 int procnotes(int pid, char ***notes)
28 .SH DESCRIPTION
29 These functions parse executable files and
30 provide access to those files and to running processes.
31 .PP
32 .I Crackhdr
33 opens and parses the named executable file.
34 The returned data structure
35 .I hdr
36 is initialized with a machine-independent description
37 of the header information. The following fields are the
38 most commonly used:
39 .TP
40 .B mach
41 a pointer to the
42 .B Mach
43 structure for the target architecture
44 .TP
45 .B mname
46 the name of the target architecture
47 .TP
48 .B fname
49 a description of the kind of file
50 (e.g., executable, core dump)
51 .TP
52 .B aname
53 a description of the application binary interface
54 this file uses; typically it is the name of an operating system
55 .PD
56 If the global variable
57 .I mach
58 is nil,
59 .I crackhdr
60 points it to the same
61 .B Mach
62 structure.
63 .PP
64 .I Mapfile
65 adds the segments found in
66 .I hdr
67 to
68 .IR map .
69 If
70 .I hdr
71 is an executable file, there are typically three segments:
72 .IR text ,
73 .IR data ,
74 and a zero-backed
75 .IR bss .
76 If
77 .I hdr
78 is a dynamic shared library, its segments are relocated by
79 .I base
80 before being mapping.
81 .PP
82 If
83 .I hdr
84 is a core file, there is one segment named
85 .I core
86 for each contiguous section of memory recorded in the core file.
87 There are often quite a few of these, as most operating systems
88 omit clean memory pages when writing core files
89 (Mac OS X is the only exception among the supported systems).
90 Because core files have such holes, it is typically necessary to
91 construct the core map by calling
92 .I mapfile
93 on the executable and then calling it again on the core file.
94 Newly-added segments are mapped on top of existing segments,
95 so this arrangement will use the core file for the segments it contains
96 but fall back to the executable for the rest.
97 .PP
98 .I Mapproc
99 attaches to a running program and adds its segments to the given map.
100 It adds one segment for each contiguous section of
101 mapped memory.
102 On systems where this information cannot be determined, it adds
103 a single segment covering the entire address space.
104 Accessing areas of this segment that are actually not mapped
105 in the process address space will cause the get/put routines to return errors.
106 .I Detachproc
107 detaches from a previously-attached program.
108 .PP
109 .I Ctlproc
110 manipulates the process with id
111 .I pid
112 according to the message
113 .IR msg .
114 Valid messages include:
115 .TP
116 .B kill
117 terminate the process
118 .TP
119 .B startstop
120 start the process and wait for it to stop
121 .TP
122 .B sysstop
123 arrange for the process to stop at its next system call,
124 start the process, and then wait for it to stop
125 .TP
126 .B waitstop
127 wait for the process to stop
128 .TP
129 .B start
130 start the process
131 .PD
132 .PP
133 .I Procnotes
134 fills
135 .BI * notes
136 with a pointer to an array of strings
137 representing pending notes waiting
138 for the process.
139 (On Unix, these notes are textual descriptions
140 of any pending signals.)
141 .I Procnotes
142 returns the number of pending notes.
143 The memory at
144 .BI * notes
145 should be freed via
146 .IR free (3)
147 when no longer needed.
148 .SH SOURCE
149 .B /sys/src/libmach
150 .SH "SEE ALSO"
151 .IR mach (3),
152 .IR mach-map (3)