Implement the write system call, w/ E

This commit is contained in:
sBubshait
2024-11-05 23:07:07 +00:00
parent b3e23eb1cc
commit 01933cb5de

View File

@@ -29,7 +29,7 @@ static void syscall_seek (int fd, unsigned position);
static unsigned syscall_tell (int fd);
static void syscall_close (int fd);
static void *validate_user_pointer (void *ptr, size_t size);
static void *validate_user_pointer (const void *ptr, size_t size);
/* A struct defining a syscall_function pointer along with its arity. */
typedef struct
@@ -157,10 +157,26 @@ syscall_read (int fd UNUSED, void *buffer UNUSED, unsigned size UNUSED)
}
static int
syscall_write (int fd UNUSED, const void *buffer UNUSED, unsigned size UNUSED)
syscall_write (int fd, const void *buffer, unsigned size)
{
//TODO
return 0;
/* Only console (fd = 1) or other files, not including STDIN, (fd > 1) are
allowed. */
if (fd <= 0)
return 0;
validate_user_pointer (buffer, size);
if (fd == STDOUT_FILENO)
{
/* Writing to the console. */
putbuf (buffer, size);
return size;
}
else
{
/* Writing to a file. */
return 0; // TODO: Implement Write to Files
}
}
static void
@@ -187,7 +203,7 @@ syscall_close (int fd UNUSED)
thread_exit) if the memory is invalid. Otherwise, returns the PTR given.
If the size is 0, the function does no checks and returns PTR.*/
static void *
validate_user_pointer (void *ptr, size_t size)
validate_user_pointer (const void *ptr, size_t size)
{
if (size > 0 && (ptr == NULL ||
!is_user_vaddr (ptr) ||