Changeset View
Standalone View
usr.bin/truss/syscalls.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#include <sys/ioccom.h> | #include <sys/ioccom.h> | ||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/mount.h> | #include <sys/mount.h> | ||||
#include <sys/ptrace.h> | #include <sys/ptrace.h> | ||||
#include <sys/resource.h> | #include <sys/resource.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#define _WANT_FREEBSD11_STAT | #define _WANT_FREEBSD11_STAT | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/sysctl.h> | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <sys/un.h> | #include <sys/un.h> | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <netinet/sctp.h> | #include <netinet/sctp.h> | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
▲ Show 20 Lines • Show All 439 Lines • ▼ Show 20 Lines | static struct syscall decoded_syscalls[] = { | ||||
{ .name = "statfs", .ret_type = 1, .nargs = 2, | { .name = "statfs", .ret_type = 1, .nargs = 2, | ||||
.args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } }, | .args = { { Name | IN, 0 }, { StatFs | OUT, 1 } } }, | ||||
{ .name = "symlink", .ret_type = 1, .nargs = 2, | { .name = "symlink", .ret_type = 1, .nargs = 2, | ||||
.args = { { Name, 0 }, { Name, 1 } } }, | .args = { { Name, 0 }, { Name, 1 } } }, | ||||
{ .name = "symlinkat", .ret_type = 1, .nargs = 3, | { .name = "symlinkat", .ret_type = 1, .nargs = 3, | ||||
.args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } }, | .args = { { Name, 0 }, { Atfd, 1 }, { Name, 2 } } }, | ||||
{ .name = "sysarch", .ret_type = 1, .nargs = 2, | { .name = "sysarch", .ret_type = 1, .nargs = 2, | ||||
.args = { { Sysarch, 0 }, { Ptr, 1 } } }, | .args = { { Sysarch, 0 }, { Ptr, 1 } } }, | ||||
{ .name = "__sysctl", .ret_type = 1, .nargs = 6, | |||||
.args = { { Sysctl, 0 }, { Int, 1 }, { Ptr, 2 }, { Ptr, 3 }, | |||||
{ Ptr, 4 }, { Int, 5 } } }, | |||||
{ .name = "__sysctlbyname", .ret_type = 1, .nargs = 6, | |||||
.args = { { Name, 0 }, { Int, 1 }, { Ptr, 2 }, { Ptr, 3 }, | |||||
{ Ptr, 4}, { Int, 5 } } }, | |||||
kib: The types of the second and fifth args are size_t, not int. It practically matters on 64bit… | |||||
{ .name = "thr_kill", .ret_type = 1, .nargs = 2, | { .name = "thr_kill", .ret_type = 1, .nargs = 2, | ||||
.args = { { Long, 0 }, { Signal, 1 } } }, | .args = { { Long, 0 }, { Signal, 1 } } }, | ||||
{ .name = "thr_self", .ret_type = 1, .nargs = 1, | { .name = "thr_self", .ret_type = 1, .nargs = 1, | ||||
.args = { { Ptr, 0 } } }, | .args = { { Ptr, 0 } } }, | ||||
{ .name = "thr_set_name", .ret_type = 1, .nargs = 2, | { .name = "thr_set_name", .ret_type = 1, .nargs = 2, | ||||
.args = { { Long, 0 }, { Name, 1 } } }, | .args = { { Long, 0 }, { Name, 1 } } }, | ||||
{ .name = "truncate", .ret_type = 1, .nargs = 2, | { .name = "truncate", .ret_type = 1, .nargs = 2, | ||||
.args = { { Name | IN, 0 }, { QuadHex | IN, 1 } } }, | .args = { { Name | IN, 0 }, { QuadHex | IN, 1 } } }, | ||||
▲ Show 20 Lines • Show All 1,745 Lines • ▼ Show 20 Lines | case Atflags: | ||||
break; | break; | ||||
case Accessmode: | case Accessmode: | ||||
print_mask_arg(sysdecode_access_mode, fp, args[sc->offset]); | print_mask_arg(sysdecode_access_mode, fp, args[sc->offset]); | ||||
break; | break; | ||||
case Sysarch: | case Sysarch: | ||||
print_integer_arg(sysdecode_sysarch_number, fp, | print_integer_arg(sysdecode_sysarch_number, fp, | ||||
args[sc->offset]); | args[sc->offset]); | ||||
break; | break; | ||||
case Sysctl: { | |||||
char name[BUFSIZ]; | |||||
int oid[CTL_MAXNAME], qoid[CTL_MAXNAME+2]; | |||||
Not Done Inline Actionsjust a note: int oid[CTL_MAXNAME] is correct (an OID can have CTL_MAXNAME levels in the kernel) but it is useless because the "undocumented interface" can handle up to "CTL__MAXNAME - 2" levels (except 0.3 name2oid), CTL_MAXNAME + 2 for qoid does not solve (unfortunately this false solution is quite widespread) asiciliano: just a note: int oid[CTL_MAXNAME] is correct (an OID can have CTL_MAXNAME levels in the… | |||||
Done Inline ActionsI couldn't find any obvious CTL_MAXNAME - 2 (apart of libjail, TBC) so if there is a truncation, it's probably because one of the in-kernel functions doesn't use CTL_MAXNAME + 2. I'll take a look at this but it's out of scope for this review anyway. kaktus: I couldn't find any obvious CTL_MAXNAME - 2 (apart of libjail, TBC) so if there is a truncation… | |||||
kibUnsubmitted Not Done Inline ActionsSpaces around '+'. kib: Spaces around '+'. | |||||
size_t i; | |||||
int len; | |||||
memset(name, 0, sizeof(name)); | |||||
len = args[sc->offset + 1]; | |||||
if (get_struct(pid, (void *)args[sc->offset], oid, | |||||
len * sizeof(oid[0])) != -1) { | |||||
if (oid[0] == CTL_SYSCTL) { | |||||
fprintf(fp, "\"sysctl."); | |||||
switch (oid[1]) { | |||||
case CTL_SYSCTL_DEBUG: | |||||
Not Done Inline ActionsAre these available as symbolic constrants ? No, it seems. Then it is time to add them to sys/sysctl.h and get rid of the numbers in the definition of sysctls from kern_sysctl.c and e.g. libc sysctlnametonib. kib: Are these available as symbolic constrants ? No, it seems.
Then it is time to add them to… | |||||
fprintf(fp, "debug"); | |||||
break; | |||||
case CTL_SYSCTL_NAME: | |||||
fprintf(fp, "name"); | |||||
Not Done Inline ActionsI would wait to document the magical nodes yet, https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=240390 asiciliano: I would wait to document the magical nodes yet, https://bugs.freebsd.org/bugzilla/show_bug.cgi? | |||||
Done Inline ActionsI matched the names with the names functions responsible as used by kern/kern_sysctl.c Hope that helps. kaktus: I matched the names with the names functions responsible as used by kern/kern_sysctl.c Hope… | |||||
kibUnsubmitted Not Done Inline ActionsI suggest to print the rest of the input mib in numeric format. kib: I suggest to print the rest of the input mib in numeric format. | |||||
break; | |||||
case CTL_SYSCTL_NEXT: | |||||
Not Done Inline ActionsSpaces around '+' and '-', there and till the end of the chunk. kib: Spaces around '+' and '-', there and till the end of the chunk. | |||||
fprintf(fp, "next"); | |||||
break; | |||||
case CTL_SYSCTL_NAME2OID: | |||||
fprintf(fp, "name2oid"); | |||||
break; | |||||
case CTL_SYSCTL_OIDFMT: | |||||
fprintf(fp, "oidfmt"); | |||||
break; | |||||
case CTL_SYSCTL_OIDDESCR: | |||||
fprintf(fp, "oiddescr"); | |||||
break; | |||||
case CTL_SYSCTL_OIDLABEL: | |||||
fprintf(fp, "oidlabel"); | |||||
break; | |||||
default: | |||||
fprintf(fp, "unknown"); | |||||
kibUnsubmitted Not Done Inline Actionsprint numeric value as well kib: print numeric value as well | |||||
} | |||||
fprintf(fp,"\""); | |||||
} else { | |||||
qoid[0] = CTL_SYSCTL; | |||||
qoid[1] = CTL_SYSCTL_NAME; | |||||
memcpy(qoid+2, oid, len * sizeof(int)); | |||||
Not Done Inline Actionsspaces around '*' kib: spaces around '*' | |||||
i = sizeof(name); | |||||
if (sysctl(qoid, len + 2, name, &i, 0, 0) == -1) | |||||
Not Done Inline Actionshere the problem (from the comment above), len + 2 could be 26 > CTL_MAXNAME asiciliano: here the problem (from the comment above), len + 2 could be 26 > CTL_MAXNAME | |||||
fprintf(fp, "%p", | |||||
(void *)args[sc->offset]); | |||||
kibUnsubmitted Not Done Inline ActionsWhy not print the mib in <num>.<num>... format, esp. since you already fetched it ? The pointer as useless as it can be. kib: Why not print the mib in <num>.<num>... format, esp. since you already fetched it ? The… | |||||
else | |||||
fprintf(fp, "\"%s\"", name); | |||||
} | |||||
} | |||||
break; | |||||
} | |||||
case PipeFds: | case PipeFds: | ||||
/* | /* | ||||
* The pipe() system call in the kernel returns its | * The pipe() system call in the kernel returns its | ||||
* two file descriptors via return values. However, | * two file descriptors via return values. However, | ||||
* the interface exposed by libc is that pipe() | * the interface exposed by libc is that pipe() | ||||
* accepts a pointer to an array of descriptors. | * accepts a pointer to an array of descriptors. | ||||
* Format the output to match the libc API by printing | * Format the output to match the libc API by printing | ||||
* the returned file descriptors as a fake argument. | * the returned file descriptors as a fake argument. | ||||
▲ Show 20 Lines • Show All 453 Lines • Show Last 20 Lines |
The types of the second and fifth args are size_t, not int. It practically matters on 64bit big-endian hosts.