Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/kdump/kdump.c
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#ifdef HAVE_LIBCAPSICUM | #ifdef HAVE_LIBCAPSICUM | ||||
#include <sys/nv.h> | #include <sys/nv.h> | ||||
#endif | #endif | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <dlfcn.h> | |||||
#include <err.h> | #include <err.h> | ||||
#include <grp.h> | #include <grp.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#ifdef HAVE_LIBCAPSICUM | #ifdef HAVE_LIBCAPSICUM | ||||
#include <libcapsicum.h> | #include <libcapsicum.h> | ||||
#include <libcapsicum_grp.h> | #include <libcapsicum_grp.h> | ||||
#include <libcapsicum_pwd.h> | #include <libcapsicum_pwd.h> | ||||
#include <libcapsicum_service.h> | #include <libcapsicum_service.h> | ||||
Show All 33 Lines | |||||
void ktrstat(struct stat *); | void ktrstat(struct stat *); | ||||
void ktrstruct(char *, size_t); | void ktrstruct(char *, size_t); | ||||
void ktrcapfail(struct ktr_cap_fail *); | void ktrcapfail(struct ktr_cap_fail *); | ||||
void ktrfault(struct ktr_fault *); | void ktrfault(struct ktr_fault *); | ||||
void ktrfaultend(struct ktr_faultend *); | void ktrfaultend(struct ktr_faultend *); | ||||
void limitfd(int fd); | void limitfd(int fd); | ||||
void usage(void); | void usage(void); | ||||
void ioctlname(unsigned long, int); | void ioctlname(unsigned long, int); | ||||
int kdump_print_utrace(FILE *, void *, size_t, int); | |||||
#define TIMESTAMP_NONE 0x0 | #define TIMESTAMP_NONE 0x0 | ||||
#define TIMESTAMP_ABSOLUTE 0x1 | #define TIMESTAMP_ABSOLUTE 0x1 | ||||
#define TIMESTAMP_ELAPSED 0x2 | #define TIMESTAMP_ELAPSED 0x2 | ||||
#define TIMESTAMP_RELATIVE 0x4 | #define TIMESTAMP_RELATIVE 0x4 | ||||
extern const char *signames[], *syscallnames[]; | extern const char *signames[], *syscallnames[]; | ||||
extern int nsyscalls; | extern int nsyscalls; | ||||
▲ Show 20 Lines • Show All 1,403 Lines • ▼ Show 20 Lines | |||||
void | void | ||||
ktrcsw(struct ktr_csw *cs) | ktrcsw(struct ktr_csw *cs) | ||||
{ | { | ||||
printf("%s %s \"%s\"\n", cs->out ? "stop" : "resume", | printf("%s %s \"%s\"\n", cs->out ? "stop" : "resume", | ||||
cs->user ? "user" : "kernel", cs->wmesg); | cs->user ? "user" : "kernel", cs->wmesg); | ||||
} | } | ||||
#define UTRACE_DLOPEN_START 1 | |||||
#define UTRACE_DLOPEN_STOP 2 | |||||
#define UTRACE_DLCLOSE_START 3 | |||||
#define UTRACE_DLCLOSE_STOP 4 | |||||
#define UTRACE_LOAD_OBJECT 5 | |||||
#define UTRACE_UNLOAD_OBJECT 6 | |||||
#define UTRACE_ADD_RUNDEP 7 | |||||
#define UTRACE_PRELOAD_FINISHED 8 | |||||
#define UTRACE_INIT_CALL 9 | |||||
#define UTRACE_FINI_CALL 10 | |||||
#define UTRACE_DLSYM_START 11 | |||||
#define UTRACE_DLSYM_STOP 12 | |||||
struct utrace_rtld { | |||||
char sig[4]; /* 'RTLD' */ | |||||
int event; | |||||
void *handle; | |||||
void *mapbase; | |||||
size_t mapsize; | |||||
int refcnt; | |||||
char name[MAXPATHLEN]; | |||||
}; | |||||
void | void | ||||
ktruser_rtld(int len, void *p) | |||||
{ | |||||
struct utrace_rtld *ut = p; | |||||
unsigned char *cp; | |||||
void *parent; | |||||
int mode; | |||||
switch (ut->event) { | |||||
case UTRACE_DLOPEN_START: | |||||
mode = ut->refcnt; | |||||
printf("dlopen(%s, ", ut->name); | |||||
switch (mode & RTLD_MODEMASK) { | |||||
case RTLD_NOW: | |||||
printf("RTLD_NOW"); | |||||
break; | |||||
case RTLD_LAZY: | |||||
printf("RTLD_LAZY"); | |||||
break; | |||||
default: | |||||
printf("%#x", mode & RTLD_MODEMASK); | |||||
} | |||||
if (mode & RTLD_GLOBAL) | |||||
printf(" | RTLD_GLOBAL"); | |||||
if (mode & RTLD_TRACE) | |||||
printf(" | RTLD_TRACE"); | |||||
if (mode & ~(RTLD_MODEMASK | RTLD_GLOBAL | RTLD_TRACE)) | |||||
printf(" | %#x", mode & | |||||
~(RTLD_MODEMASK | RTLD_GLOBAL | RTLD_TRACE)); | |||||
printf(")\n"); | |||||
break; | |||||
case UTRACE_DLOPEN_STOP: | |||||
printf("%p = dlopen(%s) ref %d\n", ut->handle, ut->name, | |||||
ut->refcnt); | |||||
break; | |||||
case UTRACE_DLCLOSE_START: | |||||
printf("dlclose(%p) (%s, %d)\n", ut->handle, ut->name, | |||||
ut->refcnt); | |||||
break; | |||||
case UTRACE_DLCLOSE_STOP: | |||||
printf("dlclose(%p) finished\n", ut->handle); | |||||
break; | |||||
case UTRACE_LOAD_OBJECT: | |||||
printf("RTLD: loaded %p @ %p - %p (%s)\n", ut->handle, | |||||
ut->mapbase, (char *)ut->mapbase + ut->mapsize - 1, | |||||
ut->name); | |||||
break; | |||||
case UTRACE_UNLOAD_OBJECT: | |||||
printf("RTLD: unloaded %p @ %p - %p (%s)\n", ut->handle, | |||||
ut->mapbase, (char *)ut->mapbase + ut->mapsize - 1, | |||||
ut->name); | |||||
break; | |||||
case UTRACE_ADD_RUNDEP: | |||||
parent = ut->mapbase; | |||||
printf("RTLD: %p now depends on %p (%s, %d)\n", parent, | |||||
ut->handle, ut->name, ut->refcnt); | |||||
break; | |||||
case UTRACE_PRELOAD_FINISHED: | |||||
printf("RTLD: LD_PRELOAD finished\n"); | |||||
break; | |||||
case UTRACE_INIT_CALL: | |||||
printf("RTLD: init %p for %p (%s)\n", ut->mapbase, ut->handle, | |||||
ut->name); | |||||
break; | |||||
case UTRACE_FINI_CALL: | |||||
printf("RTLD: fini %p for %p (%s)\n", ut->mapbase, ut->handle, | |||||
ut->name); | |||||
break; | |||||
case UTRACE_DLSYM_START: | |||||
printf("RTLD: dlsym(%p, %s)\n", ut->handle, ut->name); | |||||
break; | |||||
case UTRACE_DLSYM_STOP: | |||||
printf("RTLD: %p = dlsym(%p, %s)\n", ut->mapbase, ut->handle, | |||||
ut->name); | |||||
break; | |||||
default: | |||||
cp = p; | |||||
cp += 4; | |||||
len -= 4; | |||||
printf("RTLD: %d ", len); | |||||
while (len--) | |||||
if (decimal) | |||||
printf(" %d", *cp++); | |||||
else | |||||
printf(" %02x", *cp++); | |||||
printf("\n"); | |||||
} | |||||
} | |||||
struct utrace_malloc { | |||||
void *p; | |||||
size_t s; | |||||
void *r; | |||||
}; | |||||
void | |||||
ktruser_malloc(void *p) | |||||
{ | |||||
struct utrace_malloc *ut = p; | |||||
if (ut->p == (void *)(intptr_t)(-1)) | |||||
printf("malloc_init()\n"); | |||||
else if (ut->s == 0) | |||||
printf("free(%p)\n", ut->p); | |||||
else if (ut->p == NULL) | |||||
printf("%p = malloc(%zu)\n", ut->r, ut->s); | |||||
else | |||||
printf("%p = realloc(%p, %zu)\n", ut->r, ut->p, ut->s); | |||||
} | |||||
void | |||||
ktruser(int len, void *p) | ktruser(int len, void *p) | ||||
{ | { | ||||
unsigned char *cp; | unsigned char *cp; | ||||
if (len >= 8 && bcmp(p, "RTLD", 4) == 0) { | if (kdump_print_utrace(stdout, p, len, decimal)) { | ||||
ktruser_rtld(len, p); | printf("\n"); | ||||
return; | |||||
} | |||||
if (len == sizeof(struct utrace_malloc)) { | |||||
ktruser_malloc(p); | |||||
return; | return; | ||||
} | } | ||||
printf("%d ", len); | printf("%d ", len); | ||||
cp = p; | cp = p; | ||||
while (len--) | while (len--) | ||||
if (decimal) | if (decimal) | ||||
printf(" %d", *cp++); | printf(" %d", *cp++); | ||||
▲ Show 20 Lines • Show All 373 Lines • Show Last 20 Lines |