diff options
author | Benji Dial <benji6283@gmail.com> | 2021-06-21 17:47:13 -0400 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-06-21 17:47:13 -0400 |
commit | f57e2eabe0a10c9732c83532e01654a499fb8dcf (patch) | |
tree | cbf91a23fcdd65e0ea7ed55b0940ca7042d59bef /src/kernel/idt.c | |
parent | 83835306d57461205a7bcfef9f4c3e06bc504006 (diff) | |
download | portland-os-f57e2eabe0a10c9732c83532e01654a499fb8dcf.tar.gz |
many, many changes; settings is broken
Diffstat (limited to 'src/kernel/idt.c')
-rw-r--r-- | src/kernel/idt.c | 111 |
1 files changed, 76 insertions, 35 deletions
diff --git a/src/kernel/idt.c b/src/kernel/idt.c index 8de5448..61966e0 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -34,60 +34,95 @@ struct { .start = (uint32_t)idt }; -//file handles as (drive_number << 8) + file_id_t +bool verify_file_handle(uint32_t handle, struct drive **d, uint32_t *f) { + *d = drives + (handle >> 24); + *f = handle & 0x00ffffff; -uint32_t sc_open_file(uint32_t drive_number, char *path) { - return (drive_number << 8) + drives[drive_number].get_file(drives + drive_number, path); + if (!*f || (*d >= drives + n_drives)) { + logf(LOG_WARN, "syscall with file handle 0x%h", handle); + return false; + } + else + return true; +} + +uint32_t sc_open_file(const char *path) { + struct drive *did; + const char *sub; + map_path(path, &did, &sub); + if (!did) + return 0; + + const file_id_t fid = did->get_file(did, sub); + return fid ? ((did - drives) << 24) + fid : 0; } void sc_close_file(uint32_t handle) { - if (!handle) - return; - drives[handle >> 8].free_file(drives + (handle >> 8), handle & 0xff); + struct drive *d; + uint32_t f; + if (verify_file_handle(handle, &d, &f)) + d->free_file(d, f); } uint32_t sc_file_get_size(uint32_t handle) { - if (!handle) + struct drive *d; + uint32_t f; + if (verify_file_handle(handle, &d, &f)) + return d->get_file_length(d, f); + else return 0; - return drives[handle >> 8].get_file_length(drives + (handle >> 8), handle & 0xff); } void sc_file_set_size(uint32_t handle, uint32_t new_size) { - if (!handle) - return; - drives[handle >> 8].set_file_length(drives + (handle >> 8), handle & 0xff, new_size); + struct drive *d; + uint32_t f; + if (verify_file_handle(handle, &d, &f)) + d->set_file_length(d, f, new_size); } uint32_t sc_file_read(uint32_t handle, uint32_t file_offset, uint32_t count, void *buffer) { - if (!handle) + struct drive *d; + uint32_t f; + if (verify_file_handle(handle, &d, &f)) { + const uint32_t l = d->get_file_length(d, f); + if (file_offset >= l) + return 0; + if (file_offset + count > l) + count = l - file_offset; + fmcpy(buffer, d, f, file_offset, count); + return count; + } + else return 0; - uint32_t len = sc_file_get_size(handle); - if (file_offset + count > len) - count = len - file_offset; - fmcpy(buffer, drives + (handle >> 8), handle & 0xff, file_offset, count); - return count; } uint32_t sc_file_write(uint32_t handle, uint32_t file_offset, uint32_t count, void *buffer) { - if (!handle) + struct drive *d; + uint32_t f; + if (verify_file_handle(handle, &d, &f)) { + if (!d->is_writable(d, f)) + return 0; + const uint32_t l = d->get_file_length(d, f); + if (file_offset >= l) + return 0; + if (file_offset + count > l) + count = l - file_offset; + mfcpy(d, f, file_offset, buffer, count); + return l; + } + else return 0; - const struct drive *const d = drives + (handle >> 8); - const fs_id_t fid = handle & 0xff; +} - if (!d->is_writable(d, fid)) +uint32_t sc_start_task(char *path, const char *pass, uint32_t io_task) { + struct drive *d; + const char *f; + map_path(path, &d, &f); + if (!d) return 0; - const uint32_t l = d->get_file_length(d, fid); - if (file_offset + count > l) - count = l - file_offset; - - mfcpy(d, fid, file_offset, buffer, count); - return count; -} - -uint32_t sc_start_task(uint32_t drive_number, char *path, const char *pass, uint32_t io_task) { switch_to_kernel_cr3(); - uint32_t process_id = try_elf_run(drives + drive_number, vma_to_pma(active_task->page_directory, path), pass, io_task); + uint32_t process_id = try_elf_run(d, vma_to_pma(active_task->page_directory, f), pass, io_task); switch_to_task_cr3(); return process_id; } @@ -126,12 +161,18 @@ void sc_wait_for_task(uint32_t handle) { add_wait((struct wait){.mode = PROCESS_END, .task = tasks + handle - 1}); } -uint32_t sc_enumerate_dir(uint32_t drive_number, const char *path, struct directory_content_info *buffer, uint32_t max_entries) { //not static to ensure sysv abi - return drives[drive_number].enumerate_dir(drives + drive_number, path, buffer, max_entries); +uint32_t sc_enumerate_dir(const char *path, struct directory_content_info *buffer, uint32_t max_entries) { //not static to ensure sysv abi + struct drive *d; + const char *f; + map_path(path, &d, &f); + return d ? d->enumerate_dir(d, f, buffer, max_entries) : 0; } -uint32_t sc_count_of_dir(uint32_t drive_number, const char *path) { - return drives[drive_number].n_dir_entries(drives + drive_number, path); +uint32_t sc_count_of_dir(const char *path) { + struct drive *d; + const char *f; + map_path(path, &d, &f); + return d ? d->n_dir_entries(d, f) : 0; } void sc_get_next_window_action(struct window *w, struct window_action *action) { |