Skip to content

Commit

Permalink
✨ add write syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
froz42 committed Oct 11, 2023
1 parent 9ccb472 commit ab127af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions srcs/syscall/param_log/param_log_memseg.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
void log_MEMSEG(uint64_t value, syscall_log_param_t *context)
{
int64_t buffer_size = (int64_t)registers_get_return(context->regs, context->type);
if (buffer_size < 0 && context->after_syscall)
if (buffer_size < 0)
{
ft_dprintf(STDERR_FILENO, "%p", (void *)value);
return;
if (context->after_syscall)
{
ft_dprintf(STDERR_FILENO, "%p", (void *)value);
return;
}
buffer_size = registers_get_param(context->regs, context->type, context->arg_index + 1);
}
size_t to_read = buffer_size > MAX_PRINT_SIZE ? MAX_PRINT_SIZE : buffer_size;
char *buffer = malloc(to_read);
Expand Down
3 changes: 2 additions & 1 deletion srcs/syscall/syscall_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
/* [SYSCALL_NO] = { "SYSCALL_NAME", RETURN_TYPE, { ARG_TYPE1, ARG_TYPE2,
* ARG_TYPE3, ARG_TYPE4, ARG_TYPE5, ARG_TYPE6 } } */
static const syscall_description_t x86_64_syscalls[] = {
[0] = {"read", SIGNED_INT, {-SIGNED_INT, MEMSEG, INT, NONE}}};
[0] = {"read", SIGNED_INT, {-SIGNED_INT, MEMSEG, INT, NONE}},
[1] = {"write", SIGNED_INT, {-SIGNED_INT, -MEMSEG, -INT, NONE}}};
1 change: 1 addition & 0 deletions srcs/syscall/syscall_log_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void syscall_log_return(pid_t pid, user_regs_t *regs, register_type_t regs_type)
.arg_index = -1,
.regs = regs,
.type = regs_type,
.after_syscall = true,
};
log_functions[return_type](return_value, &param);
}

0 comments on commit ab127af

Please sign in to comment.