mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: fix for os-test
This commit is contained in:
@@ -94,6 +94,7 @@ typedef struct {
|
||||
#define MSG_CMSG_CLOEXEC 0x40000000
|
||||
#define MSG_CTRUNC 0x8
|
||||
#define MSG_PEEK 2
|
||||
#define MSG_DONTWAIT 0x40
|
||||
#define MSG_WAITALL 0x100
|
||||
#define MSG_NOSIGNAL 0x4000
|
||||
|
||||
|
||||
@@ -28,6 +28,11 @@ syscallret_t syscall_accept(context_t *, int oldfd, abisockaddr_t *abisockaddr,
|
||||
|
||||
socket_t *server = SOCKFS_SOCKET_FROM_NODE(oldfile->vnode);
|
||||
|
||||
if (server->ops->accept == NULL) {
|
||||
ret.errno = ENOTSUP;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
socket_t *client = socket_create(server->type);
|
||||
if (client == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
|
||||
@@ -254,7 +254,9 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
|
||||
if (ret.errno)
|
||||
goto error;
|
||||
|
||||
__assert(interpinterp == NULL);
|
||||
if (interpinterp)
|
||||
free(interpinterp);
|
||||
|
||||
VOP_RELEASE(interpnode);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,13 @@ syscallret_t syscall_getpgid(context_t *ctx, pid_t pid) {
|
||||
.errno = 0
|
||||
};
|
||||
|
||||
__assert(pid == 0);
|
||||
if (pid != 0) {
|
||||
printf("getpgid: unsupported pid %d\n", pid);
|
||||
ret.errno = EOPNOTSUPP;
|
||||
ret.ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.ret = jobctl_getpgid(current_thread()->proc);
|
||||
return ret;
|
||||
}
|
||||
@@ -34,7 +40,13 @@ syscallret_t syscall_getsid(context_t *ctx, pid_t pid) {
|
||||
.errno = 0
|
||||
};
|
||||
|
||||
__assert(pid == 0);
|
||||
if (pid != 0) {
|
||||
printf("getpgid: unsupported pid %d\n", pid);
|
||||
ret.errno = EOPNOTSUPP;
|
||||
ret.ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.ret = jobctl_getsid(current_thread()->proc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,18 @@ syscallret_t syscall_mmap(context_t *context, void *hint, size_t len, int prot,
|
||||
};
|
||||
|
||||
if ((~KNOWN_FLAGS & flags))
|
||||
printf("%x\n", flags);
|
||||
printf("mmap: unknown flags: %x\n", flags);
|
||||
|
||||
__assert((~KNOWN_FLAGS & flags) == 0);
|
||||
__assert((~KNOWN_PROT & prot) == 0);
|
||||
__assert(!((flags & MAP_PRIVATE) && (flags & MAP_SHARED)));
|
||||
if ((~KNOWN_PROT & prot)) {
|
||||
printf("mmap: bad prot: %x\n", prot);
|
||||
ret.errno = EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((flags & MAP_PRIVATE) && (flags & MAP_SHARED)) {
|
||||
ret.errno = EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// check alignment
|
||||
if (len == 0 || (uintptr_t)hint % PAGE_SIZE) {
|
||||
|
||||
@@ -19,7 +19,9 @@ syscallret_t syscall_mount(context_t *context, char *ubacking, char *umountpoint
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
__assert(flags == 0);
|
||||
|
||||
if (flags != 0)
|
||||
printf("mount: unknown %x\n", flags);
|
||||
|
||||
size_t mountpointlen, fslen;
|
||||
|
||||
|
||||
@@ -16,7 +16,10 @@ syscallret_t syscall_mprotect(context_t *context, void *address, size_t len, int
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
__assert((~KNOWN_PROT & prot) == 0);
|
||||
if (prot & ~KNOWN_PROT) {
|
||||
ret.errno = EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// check alignment
|
||||
if (len == 0 || (uintptr_t)address % PAGE_SIZE || address > USERSPACE_END) {
|
||||
|
||||
@@ -17,11 +17,13 @@ static void open(file_t *file, vnode_t *node, int flags) {
|
||||
}
|
||||
|
||||
syscallret_t syscall_pipe2(context_t *, int flags) {
|
||||
__assert((flags & ~(O_CLOEXEC | O_NONBLOCK)) == 0);
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
if (flags & ~(O_CLOEXEC | O_NONBLOCK))
|
||||
printf("pipe2: unknown %x\n", flags);
|
||||
|
||||
vnode_t *node = NULL;
|
||||
int readfd, writefd;
|
||||
file_t *readfile = NULL;
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
#include <kernel/file.h>
|
||||
#include <kernel/alloc.h>
|
||||
|
||||
#define KNOWN_FLAGS (MSG_PEEK | MSG_WAITALL | MSG_CMSG_CLOEXEC)
|
||||
#define KNOWN_FLAGS (MSG_PEEK | MSG_WAITALL | MSG_CMSG_CLOEXEC | MSG_DONTWAIT)
|
||||
|
||||
syscallret_t syscall_recvmsg(context_t *, int fd, msghdr_t *umsghdr, int flags) {
|
||||
__assert((flags & ~KNOWN_FLAGS) == 0);
|
||||
if (flags & ~KNOWN_FLAGS)
|
||||
printf("recvmsg: unknown %x\n", flags);
|
||||
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
@@ -55,6 +57,9 @@ syscallret_t syscall_recvmsg(context_t *, int fd, msghdr_t *umsghdr, int flags)
|
||||
if (flags & MSG_WAITALL)
|
||||
recvflags |= SOCKET_RECV_FLAGS_WAITALL;
|
||||
|
||||
if (flags & MSG_DONTWAIT)
|
||||
recvflags |= V_FFLAGS_NONBLOCKING;
|
||||
|
||||
if (flags & MSG_CMSG_CLOEXEC)
|
||||
recvflags |= SOCKET_RECV_FLAGS_CLOEXEC_CTRL;
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ syscallret_t syscall_renameat(context_t *context, int olddirfd, char *uoldpath,
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
__assert(flags == 0);
|
||||
if (flags)
|
||||
printf("renameat: unknown %x\n", flags);
|
||||
|
||||
size_t oldpathlen;
|
||||
size_t newpathlen;
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
#include <kernel/alloc.h>
|
||||
|
||||
syscallret_t syscall_sendmsg(context_t *, int fd, msghdr_t *umsghdr, int flags) {
|
||||
__assert((flags & ~MSG_NOSIGNAL) == 0);
|
||||
syscallret_t ret;
|
||||
|
||||
if (flags & ~MSG_NOSIGNAL)
|
||||
printf("sendmsg: unknown %x\n", flags);
|
||||
|
||||
msghdr_t msghdr;
|
||||
ret.errno = sock_copymsghdr(&msghdr, umsghdr);
|
||||
if (ret.errno)
|
||||
|
||||
@@ -29,7 +29,11 @@ syscallret_t syscall_getitimer(context_t *context, int which, itimerval_t *value
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
__assert(which == ITIMER_REAL);
|
||||
if (which != ITIMER_REAL) {
|
||||
ret.errno = EOPNOTSUPP;
|
||||
return ret;
|
||||
}
|
||||
|
||||
itimer_t *itimer = selectitimer(which);
|
||||
if (itimer == NULL) {
|
||||
ret.errno = EINVAL;
|
||||
@@ -61,7 +65,10 @@ syscallret_t syscall_setitimer(context_t *context, int which, itimerval_t *unew,
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
__assert(which == ITIMER_REAL);
|
||||
if (which != ITIMER_REAL) {
|
||||
ret.errno = EOPNOTSUPP;
|
||||
return ret;
|
||||
}
|
||||
|
||||
itimer_t *itimer = selectitimer(which);
|
||||
if (itimer == NULL) {
|
||||
|
||||
@@ -15,9 +15,14 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
__assert((options & ~KNOWN_FLAGS) == 0);
|
||||
// TODO implement these
|
||||
__assert(pid == -1 || pid > 0);
|
||||
if (options & ~KNOWN_FLAGS)
|
||||
printf("waitpid: unknown %x\n", options);
|
||||
|
||||
if (pid < -1 || pid == 0) {
|
||||
printf("waitpid: unhandled pid %d\n", pid);
|
||||
ret.errno = EOPNOTSUPP;
|
||||
return ret;
|
||||
}
|
||||
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread->proc;
|
||||
|
||||
Reference in New Issue
Block a user