Fix argument passing and cleanup sysctl

This commit is contained in:
Ali Mashtizadeh 2023-08-21 16:57:54 -04:00
parent 765bde0c82
commit 1a67c4841b
2 changed files with 65 additions and 66 deletions

View File

@ -98,8 +98,8 @@ Syscall_Spawn(uint64_t user_path, uint64_t user_argv)
}
/* Copy each argument in */
char *argstart = arg+sizeof(uintptr_t)*1;
for (int i = 3; i < 8; i++) {
char *argstart = arg+sizeof(uintptr_t)*8;
for (int i = 1; i < 8; i++) {
uintptr_t *str = (uintptr_t *)(arg+sizeof(uintptr_t)*i);
if (*str == 0)
break;
@ -169,7 +169,7 @@ Syscall_Spawn(uint64_t user_path, uint64_t user_argv)
Loader_Load(thr, file, pg, 1024);
/* Translate mapping for stack page */
argstart = (char *)DMPA2VA(PMap_Translate(thr->space, MEM_USERSPACE_STKTOP-PGSIZE));
argstart = (char *)DMPA2VA(PMap_Translate(thr->space, MEM_USERSPACE_STKTOP - PGSIZE));
argstart += sizeof(uintptr_t)*8;
uintptr_t offset = sizeof(uintptr_t)*8;
@ -193,7 +193,7 @@ Syscall_Spawn(uint64_t user_path, uint64_t user_argv)
}
/* Copy the argument pointer array */
argstart = (char *)DMPA2VA(PMap_Translate(thr->space, MEM_USERSPACE_STKTOP-PGSIZE));
argstart = (char *)DMPA2VA(PMap_Translate(thr->space, MEM_USERSPACE_STKTOP - PGSIZE));
memcpy(argstart, arg, sizeof(uintptr_t)*8);
VFS_Close(file);
@ -619,7 +619,7 @@ Syscall_SysCtl(uint64_t user_node, uint64_t user_oldval, uint64_t user_newval)
status = Copy_StrIn(user_node, &node, sizeof(node));
if (status != 0) {
return status;
return SYSCALL_PACK(status, 0);
}
uint64_t scType = SysCtl_GetType(node);
@ -627,69 +627,69 @@ Syscall_SysCtl(uint64_t user_node, uint64_t user_oldval, uint64_t user_newval)
return SYSCALL_PACK(ENOENT, 0);
}
switch (scType) {
case SYSCTL_TYPE_STR: {
SysCtlString *scStr = SysCtl_GetObject(node);
status = Copy_Out(scStr, user_oldval, sizeof(*scStr));
break;
}
case SYSCTL_TYPE_INT: {
SysCtlInt *scInt = SysCtl_GetObject(node);
status = Copy_Out(scInt, user_oldval, sizeof(*scInt));
break;
}
case SYSCTL_TYPE_BOOL: {
SysCtlBool *scBool = SysCtl_GetObject(node);
status = Copy_Out(scBool, user_oldval, sizeof(scBool));
break;
}
default: {
status = SYSCALL_PACK(ENOENT, 0);
}
}
if (status != 0) {
return status;
}
if (user_newval == 0) {
return 0;
}
switch (scType) {
case SYSCTL_TYPE_STR: {
SysCtlString scStr;
status = Copy_In(user_newval, &scStr, sizeof(scStr));
if (status != 0) {
return status;
if (user_oldval != 0) {
switch (scType) {
case SYSCTL_TYPE_STR: {
SysCtlString *scStr = SysCtl_GetObject(node);
status = Copy_Out(scStr, user_oldval, sizeof(*scStr));
break;
}
status = SysCtl_SetObject(node, (void *)&scStr);
break;
}
case SYSCTL_TYPE_INT: {
SysCtlInt scInt;
status = Copy_In(user_newval, &scInt, sizeof(scInt));
if (status != 0) {
return status;
case SYSCTL_TYPE_INT: {
SysCtlInt *scInt = SysCtl_GetObject(node);
status = Copy_Out(scInt, user_oldval, sizeof(*scInt));
break;
}
status = SysCtl_SetObject(node, (void *)&scInt);
break;
}
case SYSCTL_TYPE_BOOL: {
SysCtlBool scBool;
status = Copy_In(user_newval, &scBool, sizeof(scBool));
if (status != 0) {
return status;
case SYSCTL_TYPE_BOOL: {
SysCtlBool *scBool = SysCtl_GetObject(node);
status = Copy_Out(scBool, user_oldval, sizeof(scBool));
break;
}
default: {
status = EINVAL;
}
status = SysCtl_SetObject(node, (void *)&scBool);
break;
}
default: {
status = SYSCALL_PACK(ENOENT, 0);
if (status != 0) {
return SYSCALL_PACK(status, 0);
}
}
return status;
if (user_newval != 0) {
switch (scType) {
case SYSCTL_TYPE_STR: {
SysCtlString scStr;
status = Copy_In(user_newval, &scStr, sizeof(scStr));
if (status != 0) {
return SYSCALL_PACK(status, 0);
}
status = SysCtl_SetObject(node, (void *)&scStr);
break;
}
case SYSCTL_TYPE_INT: {
SysCtlInt scInt;
status = Copy_In(user_newval, &scInt, sizeof(scInt));
if (status != 0) {
return SYSCALL_PACK(status, 0);
}
status = SysCtl_SetObject(node, (void *)&scInt);
break;
}
case SYSCTL_TYPE_BOOL: {
SysCtlBool scBool;
status = Copy_In(user_newval, &scBool, sizeof(scBool));
if (status != 0) {
return SYSCALL_PACK(status, 0);
}
status = SysCtl_SetObject(node, (void *)&scBool);
break;
}
default: {
status = EINVAL;
}
}
}
return SYSCALL_PACK(status, 0);
}
uint64_t
@ -775,7 +775,7 @@ Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2,
case SYSCALL_FSINFO:
return Syscall_FSInfo(a1, a2);
default:
return (uint64_t)-1;
return SYSCALL_PACK(ENOSYS, 0);
}
}

View File

@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/kassert.h>
#include <sys/kdebug.h>
@ -80,14 +81,12 @@ SysCtl_SetObject(const char *node, void *obj)
{
int i = SysCtl_Lookup(node);
if (i == -1) {
return -1;
return ENOENT;
}
// Validate inputs
if (SYSCTLTable[i].flags == SYSCTL_FLAG_RO) {
kprintf("Sysctl node is read-only!\n");
return -1;
return EACCES;
}
switch (SYSCTLTable[i].type) {