Compare commits
No commits in common. "770286a19d7f52be1cceed347356107289a34792" and "d48d0efb07f7b3fbd8cffc87e7b9495ca97d3fb0" have entirely different histories.
770286a19d
...
d48d0efb07
@ -74,6 +74,8 @@ target_link_libraries(moon luna-freestanding)
|
||||
|
||||
target_compile_definitions(moon PRIVATE IN_MOON)
|
||||
|
||||
target_compile_options(moon PRIVATE -Os)
|
||||
|
||||
target_compile_options(moon PRIVATE -Wall -Wextra -Werror -Wvla -Wsign-conversion)
|
||||
target_compile_options(moon PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self)
|
||||
target_compile_options(moon PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
|
||||
@ -92,8 +94,6 @@ if(MOON_DEBUG_SYMBOLS)
|
||||
message(STATUS "Building Moon with debug symbols")
|
||||
target_compile_options(moon PRIVATE -ggdb)
|
||||
include(debug.cmake)
|
||||
else()
|
||||
target_compile_options(moon PRIVATE -Os)
|
||||
endif()
|
||||
|
||||
target_link_options(moon PRIVATE -lgcc -Wl,--build-id=none -z max-page-size=0x1000 -mcmodel=kernel)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "thread/Scheduler.h"
|
||||
#include "thread/ThreadImage.h"
|
||||
#include <bits/modes.h>
|
||||
#include <bits/open-flags.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/ScopeGuard.h>
|
||||
#include <luna/Vector.h>
|
||||
@ -77,16 +76,12 @@ Result<u64> sys_exec(Registers* regs, SyscallArgs args)
|
||||
|
||||
guard.deactivate();
|
||||
|
||||
for (int i = 0; i < FD_MAX; i++)
|
||||
{
|
||||
auto& descriptor = current->fd_table[i];
|
||||
if (!descriptor.has_value()) continue;
|
||||
if (descriptor->flags & O_CLOEXEC) descriptor = {};
|
||||
}
|
||||
// FIXME: Close O_CLOEXEC file descriptors.
|
||||
// for (int i = 0; i < FD_MAX; i++) { current->fd_table[i] = {}; }
|
||||
|
||||
MMU::delete_userspace_page_directory(current->directory);
|
||||
|
||||
current->name = path.chars();
|
||||
current->name = argv[0].chars();
|
||||
|
||||
image->apply(current);
|
||||
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "sys/Syscall.h"
|
||||
#include "thread/Scheduler.h"
|
||||
#include <bits/fcntl.h>
|
||||
#include <bits/open-flags.h>
|
||||
#include <bits/seek.h>
|
||||
#include <luna/SafeArithmetic.h>
|
||||
#include <sys/types.h>
|
||||
@ -86,33 +84,3 @@ Result<u64> sys_lseek(Registers*, SyscallArgs args)
|
||||
|
||||
return (u64)new_offset;
|
||||
}
|
||||
|
||||
Result<u64> sys_fcntl(Registers*, SyscallArgs args)
|
||||
{
|
||||
int fd = (int)args[0];
|
||||
int cmd = (int)args[1];
|
||||
|
||||
Thread* current = Scheduler::current();
|
||||
|
||||
auto& descriptor = *TRY(current->resolve_fd(fd));
|
||||
|
||||
bool is_cloexec = true;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case F_DUPFD: is_cloexec = false; [[fallthrough]];
|
||||
case F_DUPFD_CLOEXEC: {
|
||||
int arg = (int)args[2];
|
||||
int new_fd = TRY(current->allocate_fd(arg));
|
||||
|
||||
current->fd_table[new_fd] = descriptor;
|
||||
|
||||
if (is_cloexec) current->fd_table[new_fd]->flags |= O_CLOEXEC;
|
||||
else
|
||||
current->fd_table[new_fd]->flags &= ~O_CLOEXEC;
|
||||
|
||||
return (u64)new_fd;
|
||||
}
|
||||
default: return err(EINVAL);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <bits/open-flags.h>
|
||||
|
||||
// These flags are needed after open(), the rest only affect open().
|
||||
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK | O_CLOEXEC;
|
||||
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK;
|
||||
|
||||
Result<u64> sys_open(Registers*, SyscallArgs args)
|
||||
{
|
||||
|
@ -1,9 +0,0 @@
|
||||
/* bits/fcntl.h: File control flags. */
|
||||
|
||||
#ifndef _BITS_FCNTL_H
|
||||
#define _BITS_FCNTL_H
|
||||
|
||||
#define F_DUPFD 0
|
||||
#define F_DUPFD_CLOEXEC 1
|
||||
|
||||
#endif
|
@ -11,6 +11,5 @@
|
||||
#define O_EXCL 16
|
||||
#define O_TRUNC 32
|
||||
#define O_NONBLOCK 64
|
||||
#define O_CLOEXEC 128
|
||||
|
||||
#endif
|
||||
|
@ -3,7 +3,6 @@
|
||||
#ifndef _FCNTL_H
|
||||
#define _FCNTL_H
|
||||
|
||||
#include <bits/fcntl.h>
|
||||
#include <bits/open-flags.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@ -18,9 +17,6 @@ extern "C"
|
||||
/* Create a file and return a file descriptor to it. */
|
||||
int creat(const char* path, mode_t mode);
|
||||
|
||||
/* Perform a file control operation. */
|
||||
int fcntl(int fd, int cmd, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -55,9 +55,6 @@ extern "C"
|
||||
/* Modify a file descriptor's offset. */
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
|
||||
/* Duplicate a file descriptor. */
|
||||
int dup(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -23,17 +23,4 @@ extern "C"
|
||||
{
|
||||
return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, cmd);
|
||||
|
||||
uintptr_t arg = (uintptr_t)va_arg(ap, uintptr_t);
|
||||
|
||||
long rc = syscall(SYS_fcntl, fd, cmd, arg);
|
||||
|
||||
va_end(ap);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <bits/errno-return.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/syscall.h>
|
||||
@ -84,9 +83,4 @@ extern "C"
|
||||
long rc = syscall(SYS_lseek, fd, offset, whence);
|
||||
__errno_return(rc, off_t);
|
||||
}
|
||||
|
||||
int dup(int fd)
|
||||
{
|
||||
return fcntl(fd, F_DUPFD, 0);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#define enumerate_syscalls(_e) \
|
||||
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
|
||||
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl)
|
||||
_e(lseek) _e(mkdir) _e(exec) _e(mknod) _e(fork) _e(waitpid) _e(getppid)
|
||||
|
||||
enum Syscalls
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user