Deleted Added
full compact
i386-linux.c (100357) i386-linux.c (101282)
1/*
2 * Copryight 1997 Sean Eric Fagan
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef lint
33static const char rcsid[] =
1/*
2 * Copryight 1997 Sean Eric Fagan
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef lint
33static const char rcsid[] =
34 "$FreeBSD: head/usr.bin/truss/i386-linux.c 100357 2002-07-19 13:49:37Z markm $";
34 "$FreeBSD: head/usr.bin/truss/i386-linux.c 101282 2002-08-04 00:46:48Z mdodd $";
35#endif /* not lint */
36
37/*
38 * Linux/i386-specific system call handling. Given how much of this code
39 * is taken from the freebsd equivalent, I can probably put even more of
40 * it in support routines that can be used by any personality support.
41 */
42

--- 7 unchanged lines hidden (view full) ---

50#include <errno.h>
51#include <fcntl.h>
52#include <signal.h>
53#include <stdio.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
57
35#endif /* not lint */
36
37/*
38 * Linux/i386-specific system call handling. Given how much of this code
39 * is taken from the freebsd equivalent, I can probably put even more of
40 * it in support routines that can be used by any personality support.
41 */
42

--- 7 unchanged lines hidden (view full) ---

50#include <errno.h>
51#include <fcntl.h>
52#include <signal.h>
53#include <stdio.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
57
58#include "truss.h"
58#include "extern.h"
59#include "syscall.h"
60
61static int fd = -1;
62static int cpid = -1;
63extern int Procfd;
64
59#include "extern.h"
60#include "syscall.h"
61
62static int fd = -1;
63static int cpid = -1;
64extern int Procfd;
65
65extern FILE *outfile;
66#include "linux_syscalls.h"
67
68static int nsyscalls =
69 sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]);
70
71/* See the comment in i386-fbsd.c about this structure. */
72static struct linux_syscall {
73 struct syscall *sc;

--- 12 unchanged lines hidden (view full) ---

86 if (lsc.s_args[i])
87 free(lsc.s_args[i]);
88 free(lsc.s_args);
89 }
90 memset(&lsc, 0, sizeof(lsc));
91}
92
93void
66#include "linux_syscalls.h"
67
68static int nsyscalls =
69 sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]);
70
71/* See the comment in i386-fbsd.c about this structure. */
72static struct linux_syscall {
73 struct syscall *sc;

--- 12 unchanged lines hidden (view full) ---

86 if (lsc.s_args[i])
87 free(lsc.s_args[i]);
88 free(lsc.s_args);
89 }
90 memset(&lsc, 0, sizeof(lsc));
91}
92
93void
94i386_linux_syscall_entry(int pid, int nargs) {
94i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
95 char buf[32];
96 struct reg regs = { 0 };
97 int syscall;
98 int i;
99 struct syscall *sc;
100
95 char buf[32];
96 struct reg regs = { 0 };
97 int syscall;
98 int i;
99 struct syscall *sc;
100
101 if (fd == -1 || pid != cpid) {
102 sprintf(buf, "/proc/%d/regs", pid);
101 if (fd == -1 || trussinfo->pid != cpid) {
102 sprintf(buf, "/proc/%d/regs", trussinfo->pid);
103 fd = open(buf, O_RDWR);
104 if (fd == -1) {
103 fd = open(buf, O_RDWR);
104 if (fd == -1) {
105 fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
105 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
106 return;
107 }
106 return;
107 }
108 cpid = pid;
108 cpid = trussinfo->pid;
109 }
110
111 clear_lsc();
112 lseek(fd, 0L, 0);
113 i = read(fd, &regs, sizeof(regs));
114 syscall = regs.r_eax;
115
116 lsc.number = syscall;
117 lsc.name =
118 (syscall < 0 || syscall > nsyscalls) ? NULL : linux_syscallnames[syscall];
119 if (!lsc.name) {
109 }
110
111 clear_lsc();
112 lseek(fd, 0L, 0);
113 i = read(fd, &regs, sizeof(regs));
114 syscall = regs.r_eax;
115
116 lsc.number = syscall;
117 lsc.name =
118 (syscall < 0 || syscall > nsyscalls) ? NULL : linux_syscallnames[syscall];
119 if (!lsc.name) {
120 fprintf (outfile, "-- UNKNOWN SYSCALL %d\n", syscall);
120 fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d\n", syscall);
121 }
122
123 if (nargs == 0)
124 return;
125
126 /*
127 * Linux passes syscall arguments in registers, not
128 * on the stack. Fortunately, we've got access to the

--- 8 unchanged lines hidden (view full) ---

137 lsc.args[3] = regs.r_esi;
138 lsc.args[4] = regs.r_edi;
139
140 sc = get_syscall(lsc.name);
141 if (sc) {
142 lsc.nargs = sc->nargs;
143 } else {
144#ifdef DEBUG
121 }
122
123 if (nargs == 0)
124 return;
125
126 /*
127 * Linux passes syscall arguments in registers, not
128 * on the stack. Fortunately, we've got access to the

--- 8 unchanged lines hidden (view full) ---

137 lsc.args[3] = regs.r_esi;
138 lsc.args[4] = regs.r_edi;
139
140 sc = get_syscall(lsc.name);
141 if (sc) {
142 lsc.nargs = sc->nargs;
143 } else {
144#ifdef DEBUG
145 fprintf(outfile, "unknown syscall %s -- setting args to %d\n",
145 fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
146 lsc.name, nargs);
147#endif
148 lsc.nargs = nargs;
149 }
150
151 lsc.s_args = malloc((1+lsc.nargs) * sizeof(char*));
152 memset(lsc.s_args, 0, lsc.nargs * sizeof(char*));
153 lsc.sc = sc;

--- 16 unchanged lines hidden (view full) ---

170 }
171 }
172#ifdef DEBUG
173 fprintf(stderr, ")\n");
174#endif
175 }
176
177 if (!strcmp(lsc.name, "linux_execve") || !strcmp(lsc.name, "exit")) {
146 lsc.name, nargs);
147#endif
148 lsc.nargs = nargs;
149 }
150
151 lsc.s_args = malloc((1+lsc.nargs) * sizeof(char*));
152 memset(lsc.s_args, 0, lsc.nargs * sizeof(char*));
153 lsc.sc = sc;

--- 16 unchanged lines hidden (view full) ---

170 }
171 }
172#ifdef DEBUG
173 fprintf(stderr, ")\n");
174#endif
175 }
176
177 if (!strcmp(lsc.name, "linux_execve") || !strcmp(lsc.name, "exit")) {
178 print_syscall(outfile, lsc.name, lsc.nargs, lsc.s_args);
178 print_syscall(trussinfo, lsc.name, lsc.nargs, lsc.s_args);
179 }
180
181 return;
182}
183
184/*
185 * Linux syscalls return negative errno's, we do positive and map them
186 */

--- 4 unchanged lines hidden (view full) ---

191 -30, -31, -32, -33, -34, -11,-115,-114, -88, -89,
192 -90, -91, -92, -93, -94, -95, -96, -97, -98, -99,
193 -100,-101,-102,-103,-104,-105,-106,-107,-108,-109,
194 -110,-111, -40, -36,-112,-113, -39, -11, -87,-122,
195 -116, -66, -6, -6, -6, -6, -6, -37, -38, -9,
196 -6,
197};
198
179 }
180
181 return;
182}
183
184/*
185 * Linux syscalls return negative errno's, we do positive and map them
186 */

--- 4 unchanged lines hidden (view full) ---

191 -30, -31, -32, -33, -34, -11,-115,-114, -88, -89,
192 -90, -91, -92, -93, -94, -95, -96, -97, -98, -99,
193 -100,-101,-102,-103,-104,-105,-106,-107,-108,-109,
194 -110,-111, -40, -36,-112,-113, -39, -11, -87,-122,
195 -116, -66, -6, -6, -6, -6, -6, -37, -38, -9,
196 -6,
197};
198
199void
200i386_linux_syscall_exit(int pid, int syscall) {
199int
200i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
201 char buf[32];
202 struct reg regs;
203 int retval;
204 int i;
205 int errorp;
206 struct syscall *sc;
207
201 char buf[32];
202 struct reg regs;
203 int retval;
204 int i;
205 int errorp;
206 struct syscall *sc;
207
208 if (fd == -1 || pid != cpid) {
209 sprintf(buf, "/proc/%d/regs", pid);
208 if (fd == -1 || trussinfo->pid != cpid) {
209 sprintf(buf, "/proc/%d/regs", trussinfo->pid);
210 fd = open(buf, O_RDONLY);
211 if (fd == -1) {
210 fd = open(buf, O_RDONLY);
211 if (fd == -1) {
212 fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
212 fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
213 return;
214 }
213 return;
214 }
215 cpid = pid;
215 cpid = trussinfo->pid;
216 }
217
218 lseek(fd, 0L, 0);
216 }
217
218 lseek(fd, 0L, 0);
219 if (read(fd, ®s, sizeof(regs)) != sizeof(regs))
219 if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
220 fprintf(trussinfo->outfile, "\n");
220 return;
221 return;
221
222 }
222 retval = regs.r_eax;
223 errorp = !!(regs.r_eflags & PSL_C);
224
225 sc = lsc.sc;
226 if (!sc) {
227 for (i = 0; i < lsc.nargs; i++) {
228 lsc.s_args[i] = malloc(12);
229 sprintf(lsc.s_args[i], "0x%lx", lsc.args[i]);

--- 12 unchanged lines hidden (view full) ---

242 }
243 }
244 }
245 if (errorp) {
246 for (i = 0; i < sizeof(bsd_to_linux_errno) / sizeof(int); i++)
247 if (retval == bsd_to_linux_errno[i])
248 break;
249 }
223 retval = regs.r_eax;
224 errorp = !!(regs.r_eflags & PSL_C);
225
226 sc = lsc.sc;
227 if (!sc) {
228 for (i = 0; i < lsc.nargs; i++) {
229 lsc.s_args[i] = malloc(12);
230 sprintf(lsc.s_args[i], "0x%lx", lsc.args[i]);

--- 12 unchanged lines hidden (view full) ---

243 }
244 }
245 }
246 if (errorp) {
247 for (i = 0; i < sizeof(bsd_to_linux_errno) / sizeof(int); i++)
248 if (retval == bsd_to_linux_errno[i])
249 break;
250 }
250 print_syscall_ret(outfile, lsc.name, lsc.nargs, lsc.s_args, errorp,
251 errorp ? i : retval);
251 print_syscall_ret(trussinfo, lsc.name, lsc.nargs, lsc.s_args, errorp,
252 errorp ? i : retval);
252 clear_lsc();
253 clear_lsc();
253 return;
254
255 return (retval);
254}
256}