kernel: usercopy functions

This commit is contained in:
Matheus
2024-06-09 19:31:26 -03:00
parent 429f56aced
commit 50b4b45d00
53 changed files with 712 additions and 260 deletions
+13 -6
View File
@@ -5,25 +5,32 @@
#include <arch/cpu.h>
#include <string.h>
syscallret_t syscall_unlinkat(context_t *, int dirfd, const char *upath, int flags) {
syscallret_t syscall_unlinkat(context_t *, int dirfd, char *upath, int flags) {
syscallret_t ret = {
.ret = -1
};
size_t pathlen = strlen(upath) + 1;
char *path = alloc(pathlen);
size_t pathlen;
ret.errno = usercopy_strlen(upath, &pathlen);
if (ret.errno)
return ret;
char *path = alloc(pathlen + 1);
if (path == NULL) {
ret.errno = ENOMEM;
return ret;
}
// TODO safe strcopy
strcpy(path, upath);
ret.errno = usercopy_fromuser(path, upath, pathlen);
if (ret.errno) {
free(path);
return ret;
}
vnode_t *dirnode = NULL;
file_t *file = NULL;
char *component = alloc(pathlen);
char *component = alloc(pathlen + 1);
if (component == NULL) {
ret.errno = ENOMEM;
goto cleanup;