syscalls: make more system calls use ustring functions

This commit is contained in:
Matheus
2022-12-23 21:37:14 -03:00
parent 1ead72d897
commit f882b1ad10
7 changed files with 55 additions and 33 deletions
+11 -2
View File
@@ -7,6 +7,7 @@
#include <arch/interrupt.h>
#include <arch/timekeeper.h>
#include <time.h>
#include <kernel/ustring.h>
#define MAXNFDS 4096
@@ -35,6 +36,13 @@ syscallret syscall_poll(pollfd *fds, size_t nfds, int timeoutms){
return retv;
}
retv.errno = u_memcpy(ilist, fds, nfds*sizeof(pollfd));
if(retv.errno){
free(ilist);
return retv;
}
for(size_t fd = 0; fd < nfds; ++fd){
ilist[fd].fd = fds[fd].fd;
ilist[fd].events = fds[fd].events;
@@ -115,8 +123,9 @@ syscallret syscall_poll(pollfd *fds, size_t nfds, int timeoutms){
if(ilist[i].fd < 0)
continue;
fds[i].revents = ilist[i].revents;
if(u_memcpy(&fds[i].revents, &ilist[i].revents, sizeof(ilist[i].revents)))
continue;
if(ilist[i].revents)
++eventcount;
+5 -7
View File
@@ -45,15 +45,13 @@ syscallret syscall_read(int ifd, void* buff, size_t count){
return retv;
}
fd->offset += readc;
retv.errno = u_memcpy(buff, kbuff, readc);
retv.ret = retv.errno ? (uint64_t)-1 : readc;
if(retv.errno == 0)
fd->offset += readc;
fd_release(fd);
memcpy(buff, kbuff, count); // XXX user version for safety
retv.errno = 0;
retv.ret = readc;
free(kbuff);
return retv;
+4 -1
View File
@@ -84,7 +84,10 @@ syscallret syscall_recvmsg(int ifd, msghdr *msg, int flags){
size_t iovlen = msg->msg_iov[i].iov_len;
void* iovbuf = msg->msg_iov[i].iov_base;
memcpy(iovbuf, buffptr, iovlen);
retv.errno = u_memcpy(iovbuf, buffptr, iovlen);
if(retv.errno)
goto _return;
buffptr += iovlen;
}
+19 -17
View File
@@ -7,6 +7,7 @@
#include <arch/cls.h>
#include <kernel/alloc.h>
#include <string.h>
#include <kernel/ustring.h>
syscallret syscall_stat(const char* path, stat* st){
syscallret retv;
@@ -16,37 +17,38 @@ syscallret syscall_stat(const char* path, stat* st){
retv.errno = EFAULT;
return retv;
}
char* kpath = alloc(strlen(path)+1); // XXX use proper user strlen func
if(!kpath){
retv.errno = ENOMEM;
return retv;
}
size_t len;
strcpy(kpath, path); // XXX use user strcpy func
retv.errno = u_strlen(path, &len);
if(retv.errno)
return retv;
char kpath[len+1];
retv.errno = u_strcpy(kpath, path);
if(retv.errno)
return retv;
vnode_t* file;
proc_t* proc = arch_getcls()->thread->proc;
int ret = vfs_open(&file, *kpath == '/' ? proc->root : proc->cwd, kpath);
retv.errno = vfs_open(&file, *kpath == '/' ? proc->root : proc->cwd, kpath);
if(ret){
retv.errno = ret;
goto _ret;
}
if(retv.errno)
return retv;
stat stbuff = file->st;
vfs_close(file);
memcpy(st, &stbuff, sizeof(stat)); // XXX use user memcpy
retv.errno = u_memcpy(st, &stbuff, sizeof(stat));
retv.ret = retv.errno ? -1 : 0;
retv.ret = 0;
retv.errno = 0;
_ret:
free(kpath);
return retv;
}
+9 -3
View File
@@ -9,6 +9,7 @@
#include <arch/spinlock.h>
#include <kernel/alloc.h>
#include <arch/interrupt.h>
#include <kernel/ustring.h>
#define UNSUPPORTED "astral: waitpid: Unsupported waitpid options!\n"
#define UNSUPPORTED_PG "astral: waitpid: Process group waits are not supported yet.\n"
@@ -94,9 +95,14 @@ syscallret syscall_waitpid(pid_t pid, int *status, int options){
proc->child = child->sibling;
}
if(status)
*status = child->status; // XXX safer way of doing this
if(status){
retv.errno = u_memcpy(status, &child->status, sizeof(*status));
if(retv.errno)
return retv;
}
int threadc = proc->threadcount;
// free all the threads
+5 -1
View File
@@ -39,7 +39,11 @@ syscallret syscall_write(int ifd, void* buff, size_t count){
return retv;
}
memcpy(kbuff, buff, count); // XXX use a more proper user copy
retv.errno = u_memcpy(kbuff, buff, count);
if(retv.errno)
goto _ret;
if(fd->flags & O_APPEND)
fd->offset = fd->node->st.st_size;
+2 -2
View File
@@ -33,9 +33,9 @@ int u_memcpy(void* dest, const void* src, size_t len){
}
extern void arch_u_strcpy_cont();
extern int arch_u_strcpy(void* dest, const void* src);
extern int arch_u_strcpy(char* dest, const char* src);
int u_strcpy(void* dest, const void* src){
int u_strcpy(char* dest, const char* src){
arch_getcls()->thread->umemopfailaddr = arch_u_strcpy_cont;