diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-10 17:18:13 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-10 17:18:13 +0100 |
commit | ef50c1c0de9e992db9144571e7f08e5badbb9720 (patch) | |
tree | 26c34719e0a93e6f1831aaf14efdb436bc4b9077 | |
parent | 1b9ea946b8ec8c71a2bad9a7b2ce253145dcd97c (diff) | |
download | kogata-ef50c1c0de9e992db9144571e7f08e5badbb9720.tar.gz kogata-ef50c1c0de9e992db9144571e7f08e5badbb9720.zip |
Add mk_shm syscall ; replace get_mode by fctl.
-rw-r--r-- | src/common/include/proto/syscall.h | 12 | ||||
-rw-r--r-- | src/kernel/Makefile | 2 | ||||
-rw-r--r-- | src/kernel/include/vfs.h | 1 | ||||
-rw-r--r-- | src/kernel/user/elf.c | 2 | ||||
-rw-r--r-- | src/kernel/user/process.c | 4 | ||||
-rw-r--r-- | src/kernel/user/syscall.c | 29 | ||||
-rw-r--r-- | src/kernel/user/vfs.c | 4 | ||||
-rw-r--r-- | src/lib/include/syscall.h | 3 | ||||
-rw-r--r-- | src/lib/libkogata/syscall.c | 7 |
9 files changed, 46 insertions, 18 deletions
diff --git a/src/common/include/proto/syscall.h b/src/common/include/proto/syscall.h index a671c65..dfb9e2e 100644 --- a/src/common/include/proto/syscall.h +++ b/src/common/include/proto/syscall.h @@ -31,12 +31,13 @@ typedef struct { fd_t a, b; } fd_pair_t; #define SC_READDIR 34 // args: fd, ent_no, out dirent_t *data #define SC_STAT_OPEN 35 // args: fd, out stat_t *data -- stat on open file handle #define SC_IOCTL 36 // args: fd, command, out void* data -#define SC_GET_MODE 37 // args: fd -- get mode for open file handle +#define SC_FCTL 37 // args: fd, command, out void* data #define SC_SELECT 38 // args: sel_fd_t*, count, timeout #define SC_MK_CHANNEL 40 // args: blocking?, (int, int)* -#define SC_GEN_TOKEN 41 // args: fd, token_t* -#define SC_USE_TOKEN 42 // args: token_t* +#define SC_MK_SHM 41 // args: size +#define SC_GEN_TOKEN 42 // args: fd, token_t* +#define SC_USE_TOKEN 43 // args: token_t* #define SC_MAKE_FS 50 // args: sc_make_fs_args_t #define SC_FS_ADD_SRC 51 // args: fs_name, fs_name_strlen, fd, opts, opts_strlen @@ -56,6 +57,11 @@ typedef struct { fd_t a, b; } fd_pair_t; #define INVALID_PID 0 // do a wait with this PID to wayt for any child +// operations for fctl +#define FC_GET_MODE 1 +#define FC_SET_BLOCKING 2 +#define FC_SET_NONBLOCKING 3 + typedef struct { const char* driver; size_t driver_strlen; diff --git a/src/kernel/Makefile b/src/kernel/Makefile index cee3e20..78aa057 100644 --- a/src/kernel/Makefile +++ b/src/kernel/Makefile @@ -9,7 +9,7 @@ OBJ = core/loader.o core/dbglog.o \ LIB = ../common/libc/libc.lib ../common/libkogata/libkogata.lib ../common/libalgo/libalgo.lib -CFLAGS = -I ./include -I ../common/include -DPRNG_INIT_ENTROPY=$(shell date +%N) +CFLAGS = -I ./include -I ../common/include -DPRNG_INIT_ENTROPY=1$(shell date +%N) LDFLAGS = -T linker.ld -Xlinker -Map=kernel.map diff --git a/src/kernel/include/vfs.h b/src/kernel/include/vfs.h index be35726..226f962 100644 --- a/src/kernel/include/vfs.h +++ b/src/kernel/include/vfs.h @@ -175,7 +175,6 @@ fs_handle_t* fs_open(fs_t *fs, const char* file, int mode); void ref_file(fs_handle_t *file); void unref_file(fs_handle_t *file); -int file_get_mode(fs_handle_t *f); bool file_stat(fs_handle_t *f, stat_t *st); size_t file_read(fs_handle_t *f, size_t offset, size_t len, char* buf); 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; diff --git a/src/lib/include/syscall.h b/src/lib/include/syscall.h index f66b759..07defdb 100644 --- a/src/lib/include/syscall.h +++ b/src/lib/include/syscall.h @@ -37,10 +37,11 @@ size_t write(fd_t file, size_t offset, size_t len, const char* buf); bool readdir(fd_t file, size_t ent_no, dirent_t *d); bool stat_open(fd_t file, stat_t *s); int ioctl(fd_t file, int command, void* data); -int get_mode(fd_t file); +int fctl(fd_t file, int command, void* data); bool select(sel_fd_t* fds, size_t nfds, int timeout); fd_pair_t make_channel(bool blocking); +fd_t make_shm(size_t size); bool gen_token(fd_t file, token_t *tok); fd_t use_token(token_t *tok); diff --git a/src/lib/libkogata/syscall.c b/src/lib/libkogata/syscall.c index b724e69..67f95fd 100644 --- a/src/lib/libkogata/syscall.c +++ b/src/lib/libkogata/syscall.c @@ -94,8 +94,8 @@ bool stat_open(fd_t file, stat_t *s) { int ioctl(fd_t file, int command, void* data) { return call(SC_IOCTL, file, command, (uint32_t)data, 0, 0); } -int get_mode(fd_t file) { - return call(SC_GET_MODE, file, 0, 0, 0, 0); +int fctl(fd_t file, int command, void *data) { + return call(SC_FCTL, file, command, (uint32_t)data, 0, 0); } bool select(sel_fd_t* fds, size_t nfds, int timeout) { return call(SC_SELECT, (uint32_t)fds, nfds, timeout, 0, 0); @@ -106,6 +106,9 @@ fd_pair_t make_channel(bool blocking) { call(SC_MK_CHANNEL, blocking, (uint32_t)&ret, 0, 0, 0); return ret; } +fd_t make_shm(size_t s) { + return call(SC_MK_SHM, s, 0, 0, 0, 0); +} bool gen_token(fd_t file, token_t *tok) { return call(SC_GEN_TOKEN, file, (uint32_t)tok, 0, 0, 0); } |