mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-11 17:04:19 +01:00
Various cleanups of truss:
1) Missing include. 2) Constness. 3) ANSIfication. 4) Avoid some shadowing. 5) Add/clarify some error messages. 6) Some int functions were using return without a value. 7) Mark some parameters as unused. 8) Cast a value we know is non-negative to a size_t before comparing.
This commit is contained in:
parent
967706f308
commit
eb9741e47d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=106713
@ -63,6 +63,7 @@ static const char rcsid[] =
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
@ -83,7 +84,7 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
|
||||
*/
|
||||
static struct freebsd_syscall {
|
||||
struct syscall *sc;
|
||||
char *name;
|
||||
const char *name;
|
||||
int number;
|
||||
unsigned long *args;
|
||||
int nargs; /* number of arguments -- *not* number of words! */
|
||||
@ -92,7 +93,7 @@ static struct freebsd_syscall {
|
||||
|
||||
/* Clear up and free parts of the fsc structure. */
|
||||
static __inline void
|
||||
clear_fsc() {
|
||||
clear_fsc(void) {
|
||||
if (fsc.args) {
|
||||
free(fsc.args);
|
||||
}
|
||||
@ -116,8 +117,8 @@ clear_fsc() {
|
||||
void
|
||||
alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { { 0 } };
|
||||
int syscall;
|
||||
struct reg regs;
|
||||
int syscall_num;
|
||||
int i;
|
||||
unsigned int parm_offset;
|
||||
struct syscall *sc;
|
||||
@ -127,7 +128,7 @@ alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
@ -135,7 +136,10 @@ alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
|
||||
clear_fsc();
|
||||
lseek(fd, 0L, 0);
|
||||
i = read(fd, ®s, sizeof(regs));
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
parm_offset = regs.r_regs[R_SP] + sizeof(int);
|
||||
|
||||
/*
|
||||
@ -143,17 +147,17 @@ alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
* SYS_syscall, and SYS___syscall. The former is the old syscall()
|
||||
* routine, basicly; the latter is for quad-aligned arguments.
|
||||
*/
|
||||
syscall = regs.r_regs[R_V0];
|
||||
if (syscall == SYS_syscall || syscall == SYS___syscall) {
|
||||
syscall_num = regs.r_regs[R_V0];
|
||||
if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) {
|
||||
indir = 1;
|
||||
syscall = regs.r_regs[R_A0];
|
||||
syscall_num = regs.r_regs[R_A0];
|
||||
}
|
||||
|
||||
fsc.number = syscall;
|
||||
fsc.number = syscall_num;
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall];
|
||||
(syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
|
||||
if (!fsc.name) {
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
|
||||
}
|
||||
|
||||
if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
|
||||
@ -288,7 +292,7 @@ alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
*/
|
||||
|
||||
int
|
||||
alpha_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -300,8 +304,8 @@ alpha_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
@ -309,7 +313,7 @@ alpha_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
return (-1);
|
||||
}
|
||||
retval = regs.r_regs[R_V0];
|
||||
errorp = !!(regs.r_regs[R_A3]);
|
||||
|
@ -61,6 +61,7 @@ static const char rcsid[] =
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
@ -81,7 +82,7 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
|
||||
*/
|
||||
static struct freebsd_syscall {
|
||||
struct syscall *sc;
|
||||
char *name;
|
||||
const char *name;
|
||||
int number;
|
||||
unsigned long *args;
|
||||
int nargs; /* number of arguments -- *not* number of words! */
|
||||
@ -90,7 +91,7 @@ static struct freebsd_syscall {
|
||||
|
||||
/* Clear up and free parts of the fsc structure. */
|
||||
static __inline void
|
||||
clear_fsc() {
|
||||
clear_fsc(void) {
|
||||
if (fsc.args) {
|
||||
free(fsc.args);
|
||||
}
|
||||
@ -114,8 +115,8 @@ clear_fsc() {
|
||||
void
|
||||
i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
struct reg regs;
|
||||
int syscall_num;
|
||||
int i;
|
||||
unsigned int parm_offset;
|
||||
struct syscall *sc;
|
||||
@ -124,7 +125,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
@ -132,7 +133,10 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
|
||||
clear_fsc();
|
||||
lseek(fd, 0L, 0);
|
||||
i = read(fd, ®s, sizeof(regs));
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
parm_offset = regs.r_esp + sizeof(int);
|
||||
|
||||
/*
|
||||
@ -140,25 +144,25 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
* SYS_syscall, and SYS___syscall. The former is the old syscall()
|
||||
* routine, basicly; the latter is for quad-aligned arguments.
|
||||
*/
|
||||
syscall = regs.r_eax;
|
||||
switch (syscall) {
|
||||
syscall_num = regs.r_eax;
|
||||
switch (syscall_num) {
|
||||
case SYS_syscall:
|
||||
lseek(Procfd, parm_offset, SEEK_SET);
|
||||
read(Procfd, &syscall, sizeof(int));
|
||||
read(Procfd, &syscall_num, sizeof(int));
|
||||
parm_offset += sizeof(int);
|
||||
break;
|
||||
case SYS___syscall:
|
||||
lseek(Procfd, parm_offset, SEEK_SET);
|
||||
read(Procfd, &syscall, sizeof(int));
|
||||
read(Procfd, &syscall_num, sizeof(int));
|
||||
parm_offset += sizeof(quad_t);
|
||||
break;
|
||||
}
|
||||
|
||||
fsc.number = syscall;
|
||||
fsc.number = syscall_num;
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall];
|
||||
(syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
|
||||
if (!fsc.name) {
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
|
||||
}
|
||||
|
||||
if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
|
||||
@ -267,7 +271,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
*/
|
||||
|
||||
int
|
||||
i386_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -279,16 +283,16 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
|
@ -58,6 +58,7 @@ static const char rcsid[] =
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
@ -79,7 +80,7 @@ static int nsyscalls =
|
||||
*/
|
||||
static struct linux_syscall {
|
||||
struct syscall *sc;
|
||||
char *name;
|
||||
const char *name;
|
||||
int number;
|
||||
unsigned long args[5];
|
||||
int nargs; /* number of arguments -- *not* number of words! */
|
||||
@ -88,7 +89,7 @@ static struct linux_syscall {
|
||||
|
||||
/* Clear up and free parts of the fsc structure. */
|
||||
static __inline void
|
||||
clear_fsc() {
|
||||
clear_fsc(void) {
|
||||
if (fsc.s_args) {
|
||||
int i;
|
||||
for (i = 0; i < fsc.nargs; i++)
|
||||
@ -109,8 +110,8 @@ clear_fsc() {
|
||||
void
|
||||
i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
struct reg regs;
|
||||
int syscall_num;
|
||||
int i;
|
||||
struct syscall *sc;
|
||||
|
||||
@ -118,7 +119,7 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
@ -126,14 +127,17 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
|
||||
clear_fsc();
|
||||
lseek(fd, 0L, 0);
|
||||
i = read(fd, ®s, sizeof(regs));
|
||||
syscall = regs.r_eax;
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
syscall_num = regs.r_eax;
|
||||
|
||||
fsc.number = syscall;
|
||||
fsc.number = syscall_num;
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : linux_syscallnames[syscall];
|
||||
(syscall_num < 0 || syscall_num > nsyscalls) ? NULL : linux_syscallnames[syscall_num];
|
||||
if (!fsc.name) {
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
|
||||
}
|
||||
|
||||
if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
|
||||
@ -258,7 +262,7 @@ const int bsd_to_linux_errno[] = {
|
||||
};
|
||||
|
||||
int
|
||||
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -270,8 +274,8 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
@ -279,7 +283,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
return (-1);
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
@ -323,7 +327,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
* but that complicates things considerably.
|
||||
*/
|
||||
if (errorp) {
|
||||
for (i = 0; i < sizeof(bsd_to_linux_errno) / sizeof(int); i++)
|
||||
for (i = 0; (size_t)i < sizeof(bsd_to_linux_errno) / sizeof(int); i++)
|
||||
if (retval == bsd_to_linux_errno[i])
|
||||
break;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ static const char rcsid[] =
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
@ -81,7 +82,7 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
|
||||
*/
|
||||
static struct freebsd_syscall {
|
||||
struct syscall *sc;
|
||||
char *name;
|
||||
const char *name;
|
||||
int number;
|
||||
unsigned long *args;
|
||||
int nargs; /* number of arguments -- *not* number of words! */
|
||||
@ -90,7 +91,7 @@ static struct freebsd_syscall {
|
||||
|
||||
/* Clear up and free parts of the fsc structure. */
|
||||
static __inline void
|
||||
clear_fsc() {
|
||||
clear_fsc(void) {
|
||||
if (fsc.args) {
|
||||
free(fsc.args);
|
||||
}
|
||||
@ -114,8 +115,8 @@ clear_fsc() {
|
||||
void
|
||||
i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
struct reg regs;
|
||||
int syscall_num;
|
||||
int i;
|
||||
unsigned int parm_offset;
|
||||
struct syscall *sc;
|
||||
@ -124,7 +125,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
@ -132,7 +133,10 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
|
||||
clear_fsc();
|
||||
lseek(fd, 0L, 0);
|
||||
i = read(fd, ®s, sizeof(regs));
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
parm_offset = regs.r_esp + sizeof(int);
|
||||
|
||||
/*
|
||||
@ -140,25 +144,25 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
* SYS_syscall, and SYS___syscall. The former is the old syscall()
|
||||
* routine, basicly; the latter is for quad-aligned arguments.
|
||||
*/
|
||||
syscall = regs.r_eax;
|
||||
switch (syscall) {
|
||||
syscall_num = regs.r_eax;
|
||||
switch (syscall_num) {
|
||||
case SYS_syscall:
|
||||
lseek(Procfd, parm_offset, SEEK_SET);
|
||||
read(Procfd, &syscall, sizeof(int));
|
||||
read(Procfd, &syscall_num, sizeof(int));
|
||||
parm_offset += sizeof(int);
|
||||
break;
|
||||
case SYS___syscall:
|
||||
lseek(Procfd, parm_offset, SEEK_SET);
|
||||
read(Procfd, &syscall, sizeof(int));
|
||||
read(Procfd, &syscall_num, sizeof(int));
|
||||
parm_offset += sizeof(quad_t);
|
||||
break;
|
||||
}
|
||||
|
||||
fsc.number = syscall;
|
||||
fsc.number = syscall_num;
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall];
|
||||
(syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
|
||||
if (!fsc.name) {
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
|
||||
}
|
||||
|
||||
if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
|
||||
@ -267,7 +271,7 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
*/
|
||||
|
||||
int
|
||||
i386_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -279,16 +283,16 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
|
@ -58,6 +58,7 @@ static const char rcsid[] =
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
@ -79,7 +80,7 @@ static int nsyscalls =
|
||||
*/
|
||||
static struct linux_syscall {
|
||||
struct syscall *sc;
|
||||
char *name;
|
||||
const char *name;
|
||||
int number;
|
||||
unsigned long args[5];
|
||||
int nargs; /* number of arguments -- *not* number of words! */
|
||||
@ -88,7 +89,7 @@ static struct linux_syscall {
|
||||
|
||||
/* Clear up and free parts of the fsc structure. */
|
||||
static __inline void
|
||||
clear_fsc() {
|
||||
clear_fsc(void) {
|
||||
if (fsc.s_args) {
|
||||
int i;
|
||||
for (i = 0; i < fsc.nargs; i++)
|
||||
@ -109,8 +110,8 @@ clear_fsc() {
|
||||
void
|
||||
i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
struct reg regs;
|
||||
int syscall_num;
|
||||
int i;
|
||||
struct syscall *sc;
|
||||
|
||||
@ -118,7 +119,7 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
@ -126,14 +127,17 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
|
||||
clear_fsc();
|
||||
lseek(fd, 0L, 0);
|
||||
i = read(fd, ®s, sizeof(regs));
|
||||
syscall = regs.r_eax;
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
syscall_num = regs.r_eax;
|
||||
|
||||
fsc.number = syscall;
|
||||
fsc.number = syscall_num;
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : linux_syscallnames[syscall];
|
||||
(syscall_num < 0 || syscall_num > nsyscalls) ? NULL : linux_syscallnames[syscall_num];
|
||||
if (!fsc.name) {
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
|
||||
}
|
||||
|
||||
if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
|
||||
@ -258,7 +262,7 @@ const int bsd_to_linux_errno[] = {
|
||||
};
|
||||
|
||||
int
|
||||
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -270,8 +274,8 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
@ -279,7 +283,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
return (-1);
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
@ -323,7 +327,7 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
* but that complicates things considerably.
|
||||
*/
|
||||
if (errorp) {
|
||||
for (i = 0; i < sizeof(bsd_to_linux_errno) / sizeof(int); i++)
|
||||
for (i = 0; (size_t)i < sizeof(bsd_to_linux_errno) / sizeof(int); i++)
|
||||
if (retval == bsd_to_linux_errno[i])
|
||||
break;
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ static const char rcsid[] =
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
@ -86,7 +87,7 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
|
||||
*/
|
||||
static struct freebsd_syscall {
|
||||
struct syscall *sc;
|
||||
char *name;
|
||||
const char *name;
|
||||
int number;
|
||||
unsigned long *args;
|
||||
int nargs; /* number of arguments -- *not* number of words! */
|
||||
@ -95,7 +96,7 @@ static struct freebsd_syscall {
|
||||
|
||||
/* Clear up and free parts of the fsc structure. */
|
||||
static __inline void
|
||||
clear_fsc() {
|
||||
clear_fsc(void) {
|
||||
if (fsc.args) {
|
||||
free(fsc.args);
|
||||
}
|
||||
@ -120,7 +121,7 @@ void
|
||||
sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int syscall;
|
||||
int syscall_num;
|
||||
int i;
|
||||
struct syscall *sc;
|
||||
int indir = 0; /* indirect system call */
|
||||
@ -129,7 +130,7 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
@ -137,24 +138,27 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
|
||||
clear_fsc();
|
||||
lseek(fd, 0L, 0);
|
||||
i = read(fd, ®s, sizeof(regs));
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* FreeBSD has two special kinds of system call redirctions --
|
||||
* SYS_syscall, and SYS___syscall. The former is the old syscall()
|
||||
* routine, basicly; the latter is for quad-aligned arguments.
|
||||
*/
|
||||
syscall = regs.r_global[1];
|
||||
if (syscall == SYS_syscall || syscall == SYS___syscall) {
|
||||
syscall_num = regs.r_global[1];
|
||||
if (syscall_num == SYS_syscall || syscall_num == SYS___syscall) {
|
||||
indir = 1;
|
||||
syscall = regs.r_out[0];
|
||||
syscall_num = regs.r_out[0];
|
||||
}
|
||||
|
||||
fsc.number = syscall;
|
||||
fsc.number = syscall_num;
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall];
|
||||
(syscall_num < 0 || syscall_num > nsyscalls) ? NULL : syscallnames[syscall_num];
|
||||
if (!fsc.name) {
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall_num);
|
||||
}
|
||||
|
||||
if (fsc.name && (trussinfo->flags & FOLLOWFORKS)
|
||||
@ -290,7 +294,7 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
*/
|
||||
|
||||
int
|
||||
sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -302,8 +306,8 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
|
||||
return (-1);
|
||||
}
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
@ -311,7 +315,7 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
return (-1);
|
||||
}
|
||||
retval = regs.r_out[0];
|
||||
errorp = !!(regs.r_tstate & TSTATE_XCC_C);
|
||||
|
Loading…
Reference in New Issue
Block a user