Compare commits
3 Commits
90084652fa
...
347fe0a49d
| Author | SHA1 | Date | |
|---|---|---|---|
| 347fe0a49d | |||
| 21ff32de54 | |||
| 71522e4df5 |
@@ -606,8 +606,8 @@ static void execute_redir(struct ast_redir* redir, struct context* context) {
|
||||
}
|
||||
|
||||
size_t chunk_size = 1024;
|
||||
size_t chunks = (context->strbuf.count - 1) / chunk_size;
|
||||
size_t rem = (context->strbuf.count - 1) % chunk_size;
|
||||
size_t chunks = context->strbuf.count / chunk_size;
|
||||
size_t rem = context->strbuf.count % chunk_size;
|
||||
|
||||
for (size_t chunk = 0; chunk < chunks; chunk++) {
|
||||
if ((ret = filewriter_write(&fw, (uint8_t*)&context->strbuf.items[chunk * chunk_size],
|
||||
|
||||
@@ -114,7 +114,7 @@ void proc_cleanup(struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
|
||||
struct proc* suspended_proc = sq_entry->proc;
|
||||
|
||||
proc_sq_resume(suspended_proc, sq_entry, rctx);
|
||||
proc_sq_resume(suspended_proc, sq_entry, rctx, (uintptr_t)proc->pid);
|
||||
}
|
||||
|
||||
proc_sqs_cleanup(proc);
|
||||
@@ -125,7 +125,6 @@ void proc_cleanup(struct proc* proc, struct reschedule_ctx* rctx) {
|
||||
|
||||
procgroup_detach(proc->procgroup, proc, rctx);
|
||||
|
||||
vfs_volume_close(proc, proc->cwv, rctx);
|
||||
proc_free_pid(proc->pid);
|
||||
/* clean the process */
|
||||
free(proc);
|
||||
@@ -158,3 +157,5 @@ void proc_init_tls(struct proc* proc) {
|
||||
proc->pdata.fs_base = utcb;
|
||||
proc->pdata.tls_vaddr = tls_vaddr;
|
||||
}
|
||||
|
||||
void proc_set_syscall_value(struct proc* proc, uintptr_t value) { proc->pdata.regs.rax = value; }
|
||||
|
||||
@@ -154,17 +154,19 @@ static void ps2kb_irq(void* arg, void* regs, bool user, struct reschedule_ctx* r
|
||||
if (keycode <= 0 || keycode == 0xFA)
|
||||
return;
|
||||
|
||||
ringbuffer_push(uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
|
||||
|
||||
struct list_node_link* node = ps2kb_sq.proc_list;
|
||||
|
||||
if (node != NULL) {
|
||||
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
|
||||
struct proc* resumed_proc = sq_entry->proc;
|
||||
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx);
|
||||
*(uint8_t*)sq_entry->udata = (uint8_t)keycode;
|
||||
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx, ST_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
ringbuffer_push(uint8_t, &ps2kb_ringbuffer, (uint8_t)keycode);
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_OP(ps2kb_read_key) {
|
||||
@@ -173,25 +175,13 @@ DEFINE_DEVICE_OP(ps2kb_read_key) {
|
||||
if (chbuf == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
size_t prev_count = ps2kb_ringbuffer.count;
|
||||
|
||||
ringbuffer_pop(uint8_t, &ps2kb_ringbuffer, chbuf);
|
||||
|
||||
size_t new_count = ps2kb_ringbuffer.count;
|
||||
|
||||
/* didn't pop anything */
|
||||
if (prev_count == new_count) {
|
||||
struct list_node_link* node = ps2kb_sq.proc_list;
|
||||
|
||||
if (node != NULL) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
proc_sq_suspend(proc, &ps2kb_sq, rctx, NULL, NULL);
|
||||
|
||||
if (ps2kb_ringbuffer.count == 0) {
|
||||
proc_sq_suspend(proc, &ps2kb_sq, rctx, chbuf, NULL);
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
ringbuffer_pop(uint8_t, &ps2kb_ringbuffer, chbuf);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,10 +164,6 @@ int vfs_volume_delete(const char* key) {
|
||||
return -ST_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (volume->locked) {
|
||||
return -ST_TRY_AGAIN;
|
||||
}
|
||||
|
||||
hash_delete(&volume_table, key, strlen_null(key), hash, lengthof(volume_table.volume_buckets),
|
||||
volume_buckets, struct vfs_volume, volume_table_link, key, found_link);
|
||||
|
||||
@@ -178,61 +174,12 @@ int vfs_volume_delete(const char* key) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_volume_open(struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) {
|
||||
struct vfs_volume* volume = vfs_find_volume(volume_name);
|
||||
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (!volume->locked) {
|
||||
volume->locked = true;
|
||||
volume->owner = proc;
|
||||
return ST_OK;
|
||||
} else {
|
||||
proc_sq_suspend(proc, &volume->sq, rctx, NULL, NULL);
|
||||
return ST_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int vfs_volume_close(struct proc* proc, const char* volume_name, struct reschedule_ctx* rctx) {
|
||||
struct vfs_volume* volume = vfs_find_volume(volume_name);
|
||||
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
struct list_node_link* node = volume->sq.proc_list;
|
||||
|
||||
if (node) {
|
||||
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
|
||||
struct proc* resumed_proc = sq_entry->proc;
|
||||
|
||||
volume->owner = resumed_proc;
|
||||
volume->locked = true;
|
||||
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx);
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
volume->locked = false;
|
||||
volume->owner = NULL;
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name) {
|
||||
struct vfs_volume* volume = vfs_find_volume(volume_name);
|
||||
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.format(volume, proc, rctx);
|
||||
}
|
||||
|
||||
@@ -243,10 +190,6 @@ int vfs_read_file(struct proc* proc, struct reschedule_ctx* rctx, const char* vo
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.read_file(volume, proc, rctx, path, buffer, off, size);
|
||||
}
|
||||
|
||||
@@ -257,10 +200,6 @@ int vfs_write_file(struct proc* proc, struct reschedule_ctx* rctx, const char* v
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.write_file(volume, proc, rctx, path, buffer, off, size, flags);
|
||||
}
|
||||
|
||||
@@ -271,10 +210,6 @@ int vfs_create_file(struct proc* proc, struct reschedule_ctx* rctx, const char*
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.create_file(volume, proc, rctx, path);
|
||||
}
|
||||
|
||||
@@ -285,10 +220,6 @@ int vfs_describe(struct proc* proc, struct reschedule_ctx* rctx, const char* vol
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.describe(volume, proc, rctx, path, desc);
|
||||
}
|
||||
|
||||
@@ -299,10 +230,6 @@ int vfs_read_dir_entry(struct proc* proc, struct reschedule_ctx* rctx, const cha
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.read_dir_entry(volume, proc, rctx, path, entry, entry_num);
|
||||
}
|
||||
|
||||
@@ -313,10 +240,6 @@ int vfs_create_dir(struct proc* proc, struct reschedule_ctx* rctx, const char* v
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.create_dir(volume, proc, rctx, path);
|
||||
}
|
||||
|
||||
@@ -327,10 +250,6 @@ int vfs_remove(struct proc* proc, struct reschedule_ctx* rctx, const char* volum
|
||||
if (volume == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
|
||||
if (volume->locked && volume->owner != proc) {
|
||||
return -ST_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
return volume->driver_ops.remove(volume, proc, rctx, path);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,6 @@ struct vfs_volume {
|
||||
char key[VOLUME_MAX];
|
||||
struct hash_node_link volume_table_link;
|
||||
int fs_type;
|
||||
struct proc* owner;
|
||||
bool locked;
|
||||
struct proc_suspension_q sq;
|
||||
struct {
|
||||
int (*mount)(struct vfs_volume* volume, struct proc* proc, struct reschedule_ctx* rctx,
|
||||
bool format);
|
||||
@@ -68,10 +65,6 @@ int vfs_create_volume(struct proc* proc, struct reschedule_ctx* rctx, const char
|
||||
|
||||
int vfs_volume_delete(const char* key);
|
||||
|
||||
int vfs_volume_open(struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
|
||||
|
||||
int vfs_volume_close(struct proc* proc, const char* volume, struct reschedule_ctx* rctx);
|
||||
|
||||
int vfs_format(struct proc* proc, struct reschedule_ctx* rctx, const char* volume_name);
|
||||
|
||||
int vfs_read_file(struct proc* proc, struct reschedule_ctx* rctx, const char* volume,
|
||||
|
||||
@@ -20,7 +20,7 @@ void proc_cleanup_resource_mail(struct proc_resource* resource, struct reschedul
|
||||
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
|
||||
struct proc* suspended_proc = sq_entry->proc;
|
||||
|
||||
proc_sq_resume(suspended_proc, sq_entry, rctx);
|
||||
proc_sq_resume(suspended_proc, sq_entry, rctx, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ void proc_mail_send(struct proc* proc, struct proc_mail* mail, struct reschedule
|
||||
size_t copy_size = min(data_size, saved_buffer->size);
|
||||
memcpy(saved_buffer->buffer, data, copy_size);
|
||||
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx);
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx, copy_size);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,8 @@ void proc_mail_receive(struct proc* proc, struct proc_mail* mail, struct resched
|
||||
list_remove(mail->packets, &packet->packets_link);
|
||||
mail->packets_count--;
|
||||
|
||||
memcpy(recv_buffer, packet->packet_buffer, min(recv_size, packet->packet_size));
|
||||
size_t copy_size = min(recv_size, packet->packet_size);
|
||||
memcpy(recv_buffer, packet->packet_buffer, copy_size);
|
||||
free(packet->packet_buffer);
|
||||
free(packet);
|
||||
|
||||
@@ -90,7 +91,7 @@ void proc_mail_receive(struct proc* proc, struct proc_mail* mail, struct resched
|
||||
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
|
||||
struct proc* resumed_proc = sq_entry->proc;
|
||||
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx);
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx, copy_size);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ void proc_cleanup_resource_mutex(struct proc_resource* resource, struct reschedu
|
||||
struct proc_sq_entry* sq_entry = list_entry(node, struct proc_sq_entry, sq_link);
|
||||
struct proc* suspended_proc = sq_entry->proc;
|
||||
|
||||
proc_sq_resume(suspended_proc, sq_entry, rctx);
|
||||
proc_sq_resume(suspended_proc, sq_entry, rctx, 0);
|
||||
}
|
||||
|
||||
mutex->locked = false;
|
||||
@@ -74,7 +74,7 @@ void proc_mutex_unlock(struct proc* proc, struct proc_mutex* mutex, struct resch
|
||||
mutex->owner = resumed_proc;
|
||||
mutex->locked = true;
|
||||
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx);
|
||||
proc_sq_resume(resumed_proc, sq_entry, rctx, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,34 +173,25 @@ struct proc* proc_from_file(struct proc* proc1, const char* volume, const char*
|
||||
struct desc desc;
|
||||
int ret;
|
||||
|
||||
if ((ret = vfs_volume_open(proc1, volume, rctx)) < 0)
|
||||
return NULL;
|
||||
|
||||
if ((ret = vfs_describe(proc1, rctx, volume, path, &desc)) < 0) {
|
||||
vfs_volume_close(proc1, volume, rctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (desc.type != FS_FILE) {
|
||||
vfs_volume_close(proc1, volume, rctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t* temp_buffer = malloc(desc.size);
|
||||
|
||||
if (temp_buffer == NULL) {
|
||||
vfs_volume_close(proc1, volume, rctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((ret = vfs_read_file(proc1, rctx, volume, path, temp_buffer, 0, desc.size)) < 0) {
|
||||
free(temp_buffer);
|
||||
vfs_volume_close(proc1, volume, rctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs_volume_close(proc1, volume, rctx);
|
||||
|
||||
if (!proc_check_elf(temp_buffer)) {
|
||||
free(temp_buffer);
|
||||
return NULL;
|
||||
|
||||
@@ -44,9 +44,9 @@ struct proc {
|
||||
struct cpu* cpu;
|
||||
int state;
|
||||
uintptr_t uvaddr_argument;
|
||||
char cwv[VOLUME_MAX];
|
||||
struct proc_suspension_q done_sq;
|
||||
char name[PATH_MAX + VOLUME_MAX];
|
||||
char cwv[VOLUME_MAX];
|
||||
};
|
||||
|
||||
void proc_sched(bool user);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <proc/suspension_q.h>
|
||||
#include <status.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/spin_lock.h>
|
||||
|
||||
@@ -41,7 +42,8 @@ int proc_sq_suspend(struct proc* proc, struct proc_suspension_q* sq, struct resc
|
||||
return state;
|
||||
}
|
||||
|
||||
int proc_sq_resume(struct proc* proc, struct proc_sq_entry* sq_entry, struct reschedule_ctx* rctx) {
|
||||
int proc_sq_resume(struct proc* proc, struct proc_sq_entry* sq_entry, struct reschedule_ctx* rctx,
|
||||
uintptr_t value) {
|
||||
struct cpu* cpu = cpu_find_lightest();
|
||||
struct proc_suspension_q* sq = sq_entry->sq;
|
||||
|
||||
@@ -52,6 +54,7 @@ int proc_sq_resume(struct proc* proc, struct proc_sq_entry* sq_entry, struct res
|
||||
list_remove(proc->sq_entries, &sq_entry->proc_link);
|
||||
|
||||
proc->cpu = cpu;
|
||||
proc_set_syscall_value(proc, value);
|
||||
|
||||
if (proc->sq_entries == NULL)
|
||||
proc->state = PROC_READY;
|
||||
|
||||
@@ -28,6 +28,7 @@ void proc_sqs_cleanup(struct proc* proc);
|
||||
int proc_sq_suspend(struct proc* proc, struct proc_suspension_q* sq, struct reschedule_ctx* rctx,
|
||||
void* udata, sq_entry_free_udata_func_t free_func);
|
||||
|
||||
int proc_sq_resume(struct proc* proc, struct proc_sq_entry* sq_entry, struct reschedule_ctx* rctx);
|
||||
int proc_sq_resume(struct proc* proc, struct proc_sq_entry* sq_entry, struct reschedule_ctx* rctx,
|
||||
uintptr_t value);
|
||||
|
||||
#endif // _KERNEL_PROC_SUSPENTION_Q_H
|
||||
|
||||
@@ -16,4 +16,6 @@ void proc_cleanup(struct proc* proc, struct reschedule_ctx* rctx);
|
||||
|
||||
void proc_init_tls(struct proc* proc);
|
||||
|
||||
void proc_set_syscall_value(struct proc* proc, uintptr_t value);
|
||||
|
||||
#endif // _KERNEL_SYS_PROC_H
|
||||
|
||||
@@ -415,11 +415,6 @@ DEFINE_SYSCALL(sys_volume_open) {
|
||||
|
||||
const char* volume = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||
|
||||
int ret = vfs_volume_open(proc, volume, rctx);
|
||||
|
||||
if (ret < 0)
|
||||
return SYSRESULT(ret);
|
||||
|
||||
strncpy(proc->cwv, volume, VOLUME_MAX);
|
||||
|
||||
return SYSRESULT(ST_OK);
|
||||
@@ -427,16 +422,9 @@ DEFINE_SYSCALL(sys_volume_open) {
|
||||
|
||||
/* int volume_close (void) */
|
||||
DEFINE_SYSCALL(sys_volume_close) {
|
||||
char cwv[VOLUME_MAX];
|
||||
memcpy(cwv, proc->cwv, sizeof(proc->cwv));
|
||||
memset(proc->cwv, 0, sizeof(proc->cwv));
|
||||
|
||||
int ret = vfs_volume_close(proc, cwv, rctx);
|
||||
|
||||
if (ret == ST_OK) {
|
||||
memset(proc->cwv, 0, sizeof(proc->cwv));
|
||||
}
|
||||
|
||||
return SYSRESULT(ret);
|
||||
return SYSRESULT(ST_OK);
|
||||
}
|
||||
|
||||
/* int read_file (char* path, size_t off, uint8_t* buffer, size_t size) */
|
||||
|
||||
Reference in New Issue
Block a user