-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
396 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,45 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <ft_printf.h> | ||
#include <macros.h> | ||
|
||
typedef struct { | ||
uint64_t flag; | ||
const char *str; | ||
} flag_str_t; | ||
|
||
#define FLAG_STR(flag) {flag, #flag} | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
|
||
static const flag_str_t flags[] = { | ||
FLAG_STR(O_RDONLY), | ||
FLAG_STR(O_WRONLY), | ||
FLAG_STR(O_RDWR), | ||
FLAG_STR(O_CREAT), | ||
FLAG_STR(O_EXCL), | ||
FLAG_STR(O_NOCTTY), | ||
FLAG_STR(O_TRUNC), | ||
FLAG_STR(O_APPEND), | ||
FLAG_STR(O_NONBLOCK), | ||
FLAG_STR(O_DSYNC), | ||
FLAG_STR(O_ASYNC), | ||
FLAG_STR(O_DIRECT), | ||
FLAG_STR(O_LARGEFILE), | ||
FLAG_STR(O_DIRECTORY), | ||
FLAG_STR(O_NOFOLLOW), | ||
FLAG_STR(O_NOATIME), | ||
FLAG_STR(O_CLOEXEC), | ||
FLAG_STR(O_PATH), | ||
FLAG_STR(O_TMPFILE), | ||
FLAG_STR(O_RDONLY), FLAG_STR(O_WRONLY), FLAG_STR(O_RDWR), FLAG_STR(O_CREAT), | ||
FLAG_STR(O_EXCL), FLAG_STR(O_NOCTTY), FLAG_STR(O_TRUNC), FLAG_STR(O_APPEND), | ||
FLAG_STR(O_NONBLOCK), FLAG_STR(O_DSYNC), FLAG_STR(O_ASYNC), FLAG_STR(O_DIRECT), | ||
FLAG_STR(O_LARGEFILE), FLAG_STR(O_DIRECTORY), FLAG_STR(O_NOFOLLOW), FLAG_STR(O_NOATIME), | ||
FLAG_STR(O_CLOEXEC), FLAG_STR(O_PATH), FLAG_STR(O_TMPFILE), | ||
}; | ||
|
||
/** | ||
* @brief Log open flags | ||
* | ||
* | ||
* @param value the value to log | ||
*/ | ||
int log_OPEN_FLAGS(uint64_t value) | ||
{ | ||
int size_written = 0; | ||
bool_t first = true; | ||
for (size_t i = 0; i < ELEM_COUNT(flags); i++) | ||
{ | ||
if (value & flags[i].flag) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%s", flags[i].str); | ||
first = false; | ||
value &= ~flags[i].flag; | ||
} | ||
} | ||
if (value) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%#llx", value); | ||
} | ||
return size_written; | ||
int size_written = 0; | ||
bool_t first = true; | ||
for (size_t i = 0; i < ELEM_COUNT(flags); i++) | ||
{ | ||
if (value & flags[i].flag) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%s", flags[i].str); | ||
first = false; | ||
value &= ~flags[i].flag; | ||
} | ||
} | ||
if (value) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%#llx", value); | ||
} | ||
return size_written; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <ft_strace_utils.h> | ||
#include <macros.h> | ||
#include <registers.h> | ||
#include <sys/poll.h> | ||
#include <sys/uio.h> | ||
|
||
static const flag_str_t flags[] = { | ||
FLAG_STR(POLLIN), FLAG_STR(POLLPRI), FLAG_STR(POLLOUT), FLAG_STR(POLLRDHUP), | ||
FLAG_STR(POLLERR), FLAG_STR(POLLHUP), FLAG_STR(POLLNVAL), FLAG_STR(POLLRDNORM), | ||
FLAG_STR(POLLRDBAND), FLAG_STR(POLLWRNORM), FLAG_STR(POLLWRBAND), | ||
}; | ||
|
||
static int log_poll_fd(struct pollfd *fds, size_t i) | ||
{ | ||
size_t size_written = 0; | ||
if (i != 0) | ||
size_written += ft_dprintf(STDERR_FILENO, ", "); | ||
size_written += ft_dprintf(STDERR_FILENO, "{fd=%d, events=", fds[i].fd); | ||
if (fds[i].events == 0) | ||
{ | ||
size_written += ft_dprintf(STDERR_FILENO, "0"); | ||
return size_written; | ||
} | ||
bool_t first = true; | ||
for (size_t j = 0; j < ELEM_COUNT(flags); j++) | ||
{ | ||
if (fds[i].events & flags[j].flag) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%s", flags[j].str); | ||
first = false; | ||
fds[i].events &= ~flags[j].flag; | ||
} | ||
} | ||
if (fds[i].events != 0) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%#x", fds[i].events); | ||
} | ||
size_written += ft_dprintf(STDERR_FILENO, "}"); | ||
return size_written; | ||
} | ||
|
||
/** | ||
* @brief Log poll fds | ||
* | ||
* @param value | ||
* @param context | ||
* @return int | ||
*/ | ||
int log_POLL_FDS(uint64_t value, syscall_log_param_t *context) | ||
{ | ||
if (value == 0) | ||
return ft_dprintf(STDERR_FILENO, "NULL"); | ||
uint64_t fd_count = registers_get_param(context->regs, context->type, context->arg_index + 1); | ||
if (fd_count == 0) | ||
return ft_dprintf(STDERR_FILENO, "[]"); | ||
struct pollfd *fds = malloc(sizeof(struct pollfd) * fd_count); | ||
if (!fds) | ||
{ | ||
log_error("log_POLL_FDS", "malloc failed", true); | ||
return 0; | ||
} | ||
struct iovec local = { | ||
.iov_base = fds, | ||
.iov_len = sizeof(struct pollfd) * fd_count, | ||
}; | ||
struct iovec remote = { | ||
.iov_base = (void *)value, | ||
.iov_len = sizeof(struct pollfd) * fd_count, | ||
}; | ||
if (process_vm_readv(context->pid, &local, 1, &remote, 1, 0) < 0) | ||
{ | ||
log_error("log_POLL_FDS", "process_vm_readv failed", true); | ||
free(fds); | ||
return 0; | ||
} | ||
int size_written = 0; | ||
size_written += ft_dprintf(STDERR_FILENO, "["); | ||
for (uint64_t i = 0; i < fd_count; i++) | ||
size_written += log_poll_fd(fds, i); | ||
size_written += ft_dprintf(STDERR_FILENO, "]"); | ||
free(fds); | ||
return size_written; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <ft_strace_utils.h> | ||
#include <macros.h> | ||
#include <registers.h> | ||
#include <sys/poll.h> | ||
#include <sys/uio.h> | ||
|
||
static const flag_str_t flags[] = { | ||
FLAG_STR(POLLIN), FLAG_STR(POLLPRI), FLAG_STR(POLLOUT), FLAG_STR(POLLRDHUP), | ||
FLAG_STR(POLLERR), FLAG_STR(POLLHUP), FLAG_STR(POLLNVAL), FLAG_STR(POLLRDNORM), | ||
FLAG_STR(POLLRDBAND), FLAG_STR(POLLWRNORM), FLAG_STR(POLLWRBAND), | ||
}; | ||
|
||
static int log_poll_fd(struct pollfd *fds, size_t i) | ||
{ | ||
size_t size_written = 0; | ||
if (fds[i].revents == 0) | ||
return size_written; | ||
if (i != 0) | ||
size_written += ft_dprintf(STDERR_FILENO, ", "); | ||
size_written += ft_dprintf(STDERR_FILENO, "{fd=%d, revents=", fds[i].fd); | ||
bool_t first = true; | ||
for (size_t j = 0; j < ELEM_COUNT(flags); j++) | ||
{ | ||
if (fds[i].revents & flags[j].flag) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%s", flags[j].str); | ||
first = false; | ||
fds[i].revents &= ~flags[j].flag; | ||
} | ||
} | ||
if (fds[i].revents != 0) | ||
{ | ||
if (!first) | ||
size_written += ft_dprintf(STDERR_FILENO, "|"); | ||
size_written += ft_dprintf(STDERR_FILENO, "%#x", fds[i].revents); | ||
} | ||
size_written += ft_dprintf(STDERR_FILENO, "}"); | ||
return size_written; | ||
} | ||
|
||
/** | ||
* @brief Log poll fds | ||
* | ||
* @param value | ||
* @param context | ||
* @return int | ||
*/ | ||
int log_POLL_FDS_AFTER(uint64_t value, syscall_log_param_t *context) | ||
{ | ||
int size_written = 0; | ||
size_written += ft_dprintf(STDERR_FILENO, "%d", (int)value); | ||
if (value == 0) | ||
{ | ||
size_written += ft_dprintf(STDERR_FILENO, " (Timeout)"); | ||
return size_written; | ||
} | ||
struct pollfd *fds = malloc(sizeof(struct pollfd) * value); | ||
if (!fds) | ||
{ | ||
log_error("log_POLL_FDS_AFTER", "malloc failed", true); | ||
return 0; | ||
} | ||
unsigned int fd_count = registers_get_param(context->regs, context->type, 1); | ||
struct iovec local = { | ||
.iov_base = fds, | ||
.iov_len = sizeof(struct pollfd) * fd_count, | ||
}; | ||
struct iovec remote = { | ||
.iov_base = (void *)registers_get_param(context->regs, context->type, 0), | ||
.iov_len = sizeof(struct pollfd) * fd_count, | ||
}; | ||
if (process_vm_readv(context->pid, &local, 1, &remote, 1, 0) < 0) | ||
{ | ||
log_error("log_POLL_FDS_AFTER", "process_vm_readv failed", true); | ||
free(fds); | ||
return 0; | ||
} | ||
size_written += ft_dprintf(STDERR_FILENO, " [{"); | ||
for (size_t i = 0; i < fd_count; i++) | ||
size_written += log_poll_fd(fds, i); | ||
size_written += ft_dprintf(STDERR_FILENO, "}]"); | ||
free(fds); | ||
return size_written; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "param_log.h" | ||
#include <ft_printf.h> | ||
#include <macros.h> | ||
|
||
static const flag_str_t flags[] = { | ||
FLAG_STR(SEEK_SET), | ||
FLAG_STR(SEEK_CUR), | ||
FLAG_STR(SEEK_END), | ||
}; | ||
|
||
/** | ||
* @brief Log whence | ||
* | ||
* @param value the value to log | ||
* @return int the number of bytes written | ||
*/ | ||
int log_SEEK_WHENCE(uint64_t value) | ||
{ | ||
for (size_t i = 0; i < ELEM_COUNT(flags); i++) | ||
{ | ||
if (value == flags[i].flag) | ||
return ft_dprintf(STDERR_FILENO, "%s", flags[i].str); | ||
} | ||
return ft_dprintf(STDERR_FILENO, "%#llx", value); | ||
} |
Oops, something went wrong.