aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/user')
-rw-r--r--src/kernel/user/elf.c2
-rw-r--r--src/kernel/user/process.c4
-rw-r--r--src/kernel/user/syscall.c29
-rw-r--r--src/kernel/user/vfs.c4
4 files changed, 29 insertions, 10 deletions
diff --git a/src/kernel/user/elf.c b/src/kernel/user/elf.c
index ed9d3c4..2fcc915 100644
--- a/src/kernel/user/elf.c
+++ b/src/kernel/user/elf.c
@@ -34,7 +34,7 @@ proc_entry_t elf_load(fs_handle_t *f, process_t* process) {
if (read_phdr_r != sizeof(elf_phdr_t)) goto error;
if (phdr.p_type == PT_LOAD) {
- if ((phdr.p_flags & PF_W) || !(file_get_mode(f) & FM_MMAP)) {
+ if ((phdr.p_flags & PF_W) || !(f->mode & FM_MMAP)) {
bool mmap_ok = mmap(process, (void*)phdr.p_vaddr, phdr.p_memsz,
((phdr.p_flags & PF_R) ? MM_READ : 0) | MM_WRITE);
if (!mmap_ok) goto error;
diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c
index 85530ca..18b4255 100644
--- a/src/kernel/user/process.c
+++ b/src/kernel/user/process.c
@@ -529,7 +529,7 @@ bool mmap_file(process_t *proc, fs_handle_t *h, size_t offset, void* addr, size_
if ((uint32_t)addr & (~PAGE_MASK)) return false;
if ((uint32_t)offset & (~PAGE_MASK)) return false;
- int fmode = file_get_mode(h);
+ int fmode = h->mode;
if (!(fmode & FM_MMAP) || !(fmode & FM_READ)) return false;
if ((mode & MM_WRITE) && !(fmode & FM_WRITE)) return false;
@@ -573,7 +573,7 @@ bool mchmap(process_t *proc, void* addr, int mode) {
if (r == 0) return false;
if (r->file != 0) {
- if ((mode & MM_WRITE) && !(file_get_mode(r->file) & FM_WRITE)) return false;
+ if ((mode & MM_WRITE) && !(r->file->mode & FM_WRITE)) return false;
}
r->mode = mode;
diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c
index 67ed317..15b0851 100644
--- a/src/kernel/user/syscall.c
+++ b/src/kernel/user/syscall.c
@@ -276,11 +276,21 @@ static uint32_t ioctl_sc(sc_args_t args) {
return file_ioctl(h, args.b, data);
}
-static uint32_t get_mode_sc(sc_args_t args) {
+static uint32_t fctl_sc(sc_args_t args) {
fs_handle_t *h = proc_read_fd(current_process(), args.a);
if (h == 0) return 0;
- return file_get_mode(h);
+ if (args.b == FC_GET_MODE) {
+ return h->mode;
+ } else if (args.b == FC_SET_BLOCKING) {
+ h->mode |= FM_BLOCKING;
+ return 1;
+ } else if (args.b == FC_SET_NONBLOCKING) {
+ h->mode &= ~FM_BLOCKING;
+ return 1;
+ } else {
+ return 0;
+ }
}
static uint32_t select_sc(sc_args_t args) {
@@ -375,6 +385,19 @@ error:
return false;
}
+static uint32_t make_shm_sc(sc_args_t args) {
+ fs_handle_t *h = make_shm(args.a);
+ if (h == 0) return 0;
+
+ int fd = proc_add_fd(current_process(), h);
+ if (fd == 0) {
+ unref_file(h);
+ return 0;
+ }
+
+ return fd;
+}
+
static uint32_t gen_token_sc(sc_args_t args) {
fs_handle_t *h = proc_read_fd(current_process(), args.a);
if (h == 0) return false;
@@ -694,7 +717,7 @@ void setup_syscall_table() {
sc_handlers[SC_READDIR] = readdir_sc;
sc_handlers[SC_STAT_OPEN] = stat_open_sc;
sc_handlers[SC_IOCTL] = ioctl_sc;
- sc_handlers[SC_GET_MODE] = get_mode_sc;
+ sc_handlers[SC_FCTL] = fctl_sc;
sc_handlers[SC_SELECT] = select_sc;
sc_handlers[SC_MK_CHANNEL] = make_channel_sc;
diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c
index 6df0a25..a967f70 100644
--- a/src/kernel/user/vfs.c
+++ b/src/kernel/user/vfs.c
@@ -462,10 +462,6 @@ void unref_file(fs_handle_t *file) {
}
}
-int file_get_mode(fs_handle_t *f) {
- return f->mode;
-}
-
size_t file_read(fs_handle_t *f, size_t offset, size_t len, char* buf) {
if (!(f->mode & FM_READ)) return 0;