Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions so3/arch/arm32/include/asm/syscall_number.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2025 Clement Dieperink <clement.dieperink@heig-vd.ch>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#ifndef ARCH_ARM32_SYSCALL_NUMBER_H
#define ARCH_ARM32_SYSCALL_NUMBER_H

/*
* Syscall number definition
*/

#define SYSCALL_EXIT 1
#define SYSCALL_EXECVE 2
#define SYSCALL_WAITPID 3
#define SYSCALL_READ 4
#define SYSCALL_WRITE 5
#define SYSCALL_FORK 7
#define SYSCALL_PTRACE 8
#define SYSCALL_READDIR 9
#define SYSCALL_OPEN 14
#define SYSCALL_CLOSE 15
#define SYSCALL_THREAD_CREATE 16
#define SYSCALL_THREAD_JOIN 17
#define SYSCALL_THREAD_EXIT 18
#define SYSCALL_PIPE 19
#define SYSCALL_IOCTL 20
#define SYSCALL_FCNTL 21
#define SYSCALL_DUP 22
#define SYSCALL_DUP2 23

#define SYSCALL_SOCKET 26
#define SYSCALL_BIND 27
#define SYSCALL_LISTEN 28
#define SYSCALL_ACCEPT 29
#define SYSCALL_CONNECT 30
#define SYSCALL_RECV 31
#define SYSCALL_SEND 32
#define SYSCALL_SENDTO 33

#define SYSCALL_STAT 34
#define SYSCALL_MMAP 35
#define SYSCALL_GETPID 37

#define SYSCALL_GETTIMEOFDAY 38
#define SYSCALL_SETTIMEOFDAY 39
#define SYSCALL_CLOCK_GETTIME 40

#define SYSCALL_THREAD_YIELD 43

#define SYSCALL_SBRK 45
#define SYSCALL_SIGACTION 46
#define SYSCALL_KILL 47
#define SYSCALL_SIGRETURN 48

#define SYSCALL_LSEEK 50

#define SYSCALL_MUTEX_LOCK 60
#define SYSCALL_MUTEX_UNLOCK 61

#define SYSCALL_NANOSLEEP 70

#define SYSCALL_SYSINFO 99

#define SYSCALL_SETSOCKOPT 110
#define SYSCALL_RECVFROM 111

#endif /* ARCH_ARM32_SYSCALL_NUMBER_H */
81 changes: 81 additions & 0 deletions so3/arch/arm64/include/asm/syscall_number.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2025 Clement Dieperink <clement.dieperink@heig-vd.ch>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

#ifndef ARCH_ARM64_SYSCALL_NUMBER_H
#define ARCH_ARM64_SYSCALL_NUMBER_H

/*
* Syscall number definition
*/

#define SYSCALL_EXIT 1
#define SYSCALL_EXECVE 2
#define SYSCALL_WAITPID 3
#define SYSCALL_READ 4
#define SYSCALL_WRITE 5
#define SYSCALL_FORK 7
#define SYSCALL_PTRACE 8
#define SYSCALL_READDIR 9
#define SYSCALL_OPEN 14
#define SYSCALL_CLOSE 15
#define SYSCALL_THREAD_CREATE 16
#define SYSCALL_THREAD_JOIN 17
#define SYSCALL_THREAD_EXIT 18
#define SYSCALL_PIPE 19
#define SYSCALL_IOCTL 20
#define SYSCALL_FCNTL 21
#define SYSCALL_DUP 22
#define SYSCALL_DUP2 23

#define SYSCALL_SOCKET 26
#define SYSCALL_BIND 27
#define SYSCALL_LISTEN 28
#define SYSCALL_ACCEPT 29
#define SYSCALL_CONNECT 30
#define SYSCALL_RECV 31
#define SYSCALL_SEND 32
#define SYSCALL_SENDTO 33

#define SYSCALL_STAT 34
#define SYSCALL_MMAP 35
#define SYSCALL_GETPID 37

#define SYSCALL_GETTIMEOFDAY 38
#define SYSCALL_SETTIMEOFDAY 39
#define SYSCALL_CLOCK_GETTIME 40

#define SYSCALL_THREAD_YIELD 43

#define SYSCALL_SBRK 45
#define SYSCALL_SIGACTION 46
#define SYSCALL_KILL 47
#define SYSCALL_SIGRETURN 48

#define SYSCALL_LSEEK 50

#define SYSCALL_MUTEX_LOCK 60
#define SYSCALL_MUTEX_UNLOCK 61

#define SYSCALL_NANOSLEEP 70

#define SYSCALL_SYSINFO 99

#define SYSCALL_SETSOCKOPT 110
#define SYSCALL_RECVFROM 111

#endif /* ARCH_ARM64_SYSCALL_NUMBER_H */
40 changes: 21 additions & 19 deletions so3/fs/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ int vfs_clone_fd(int *fd_src, int *fd_dst)

/**************************** Syscall implementation ****************************/

int do_read(int fd, void *buffer, int count)
SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count)
{
int gfd;
int ret;
Expand Down Expand Up @@ -427,7 +427,7 @@ int do_read(int fd, void *buffer, int count)
/**
* @brief This function writes a REGULAR FILE/FOLDER. It only support regular file, dirs and pipes
*/
int do_write(int fd, const void *buffer, int count)
SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count)
{
int gfd;
int ret;
Expand Down Expand Up @@ -474,7 +474,7 @@ int do_write(int fd, const void *buffer, int count)
/**
* @brief This function opens a file. Not all file types are supported.
*/
int do_open(const char *filename, int flags)
SYSCALL_DEFINE2(open, const char *, filename, int, flags)
{
int fd, gfd, ret = -1;
uint32_t type;
Expand Down Expand Up @@ -542,7 +542,7 @@ int do_open(const char *filename, int flags)
* @brief readdir read a directory entry which will be stored in a struct dirent entry
* @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace.
*/
int do_readdir(int fd, char *buf, int len)
SYSCALL_DEFINE3(readdir, int, fd, char *, buf, int, len)
{
struct dirent *dirent;
int gfd;
Expand Down Expand Up @@ -588,13 +588,13 @@ int do_readdir(int fd, char *buf, int len)
* only when refcount is equal to zero (no more reference on the gfd).
* @param fd This is the local fd from the process' table.
*/
void do_close(int fd)
SYSCALL_DEFINE1(close, int, fd)
{
pcb_t *pcb = current()->pcb;
int gfd;

if ((!pcb) || (fd < 0))
return;
return 0;

mutex_lock(&vfs_lock);

Expand All @@ -604,12 +604,12 @@ void do_close(int fd)
if (gfd < 0) {
LOG_DEBUG("Was already freed\n");
mutex_unlock(&vfs_lock);
return;
return 0;
}

if (!open_fds[gfd]) {
mutex_unlock(&vfs_lock);
return;
return 0;
}

/* Decrement reference counter to keep track of open fds */
Expand Down Expand Up @@ -640,13 +640,15 @@ void do_close(int fd)
}

mutex_unlock(&vfs_lock);

return 0;
}

/**
* @brief dup2 creates a synonym of oldfd on newfd
*
*/
int do_dup2(int oldfd, int newfd)
SYSCALL_DEFINE2(dup2, int, oldfd, int, newfd)
{
if ((newfd < 0) || (newfd > MAX_FDS))
return -EBADF;
Expand Down Expand Up @@ -680,7 +682,7 @@ int do_dup2(int oldfd, int newfd)
* @param File descriptor to copy.
* @return A copy of the file descriptor.
*/
int do_dup(int oldfd)
SYSCALL_DEFINE1(dup, int, oldfd)
{
#ifdef CONFIG_PROC_ENV
int newfd;
Expand Down Expand Up @@ -708,7 +710,7 @@ int do_dup(int oldfd)
#endif
}

int do_stat(const char *path, struct stat *st)
SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st)
{
int ret;

Expand Down Expand Up @@ -737,7 +739,7 @@ int do_stat(const char *path, struct stat *st)
/**
* An mmap() implementation in VFS.
*/
void *do_mmap(addr_t start, size_t length, int prot, int fd, off_t offset)
SYSCALL_DEFINE5(mmap, addr_t, start, size_t, length, int, prot, int, fd, off_t, offset)
{
int gfd;
uint32_t page_count;
Expand All @@ -749,7 +751,7 @@ void *do_mmap(addr_t start, size_t length, int prot, int fd, off_t offset)
if (-1 == gfd) {
printk("%s: could not get global fd.\n", __func__);
set_errno(EBADF);
return MAP_FAILED;
return (long) MAP_FAILED;
}

mutex_lock(&vfs_lock);
Expand All @@ -758,7 +760,7 @@ void *do_mmap(addr_t start, size_t length, int prot, int fd, off_t offset)
printk("%s: could not get device fops.\n", __func__);
mutex_unlock(&vfs_lock);
set_errno(EBADF);
return MAP_FAILED;
return (long) MAP_FAILED;
}

mutex_unlock(&vfs_lock);
Expand All @@ -772,14 +774,14 @@ void *do_mmap(addr_t start, size_t length, int prot, int fd, off_t offset)
if (!fops->mmap) {
printk("%s: device doesn't support mmap.\n", __func__);
set_errno(EACCES);
return MAP_FAILED;
return (long) MAP_FAILED;
}

/* Call the mmap fops that will do the actual mapping. */
return fops->mmap(fd, start, page_count, offset);
return (long) fops->mmap(fd, start, page_count, offset);
}

int do_ioctl(int fd, unsigned long cmd, unsigned long args)
SYSCALL_DEFINE3(ioctl, int, fd, unsigned long, cmd, unsigned long, args)
{
int rc, gfd;
mutex_lock(&vfs_lock);
Expand Down Expand Up @@ -808,7 +810,7 @@ int do_ioctl(int fd, unsigned long cmd, unsigned long args)
* Implementation of standard lseek() syscall. It depends on the underlying
* device operations.
*/
off_t do_lseek(int fd, off_t off, int whence)
SYSCALL_DEFINE3(lseek, int, fd, off_t, off, int, whence)
{
int rc, gfd;
mutex_lock(&vfs_lock);
Expand All @@ -834,7 +836,7 @@ off_t do_lseek(int fd, off_t off, int whence)
/*
* Implementation of the fcntl syscall
*/
int do_fcntl(int fd, unsigned long cmd, unsigned long args)
SYSCALL_DEFINE3(fcntl, int, fd, unsigned long, cmd, unsigned long, args)
{
/* Not yet implemented */

Expand Down
7 changes: 4 additions & 3 deletions so3/include/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <list.h>
#include <spinlock.h>
#include <thread.h>
#include <syscall.h>

#include <asm/atomic.h>

Expand Down Expand Up @@ -58,8 +59,8 @@ void mutex_lock(struct mutex *lock);
void mutex_unlock(struct mutex *lock);
void mutex_init(struct mutex *lock);

int do_mutex_init(void);
int do_mutex_lock(unsigned long number);
int do_mutex_unlock(unsigned long number);
SYSCALL_DECLARE(mutex_init, void);
SYSCALL_DECLARE(mutex_lock, unsigned long number);
SYSCALL_DECLARE(mutex_unlock, unsigned long number);

#endif /* MUTEX_H */
21 changes: 11 additions & 10 deletions so3/include/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define NET_H

#include <vfs.h>
#include <syscall.h>

#include <net/lwip/sockets.h>

Expand Down Expand Up @@ -67,15 +68,15 @@

void net_init(void);

int do_socket(int domain, int type, int protocol);
int do_connect(int sockfd, const struct sockaddr *name, socklen_t namelen);
int do_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int do_listen(int sockfd, int backlog);
int do_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int do_recv(int sockfd, void *mem, size_t len, int flags);
int do_recvfrom(int sockfd, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
int do_send(int sockfd, const void *dataptr, size_t size, int flags);
int do_sendto(int sockfd, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen);
int do_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
SYSCALL_DECLARE(socket, int domain, int type, int protocol);
SYSCALL_DECLARE(connect, int sockfd, const struct sockaddr *name, socklen_t namelen);
SYSCALL_DECLARE(bind, int sockfd, const struct sockaddr *addr, socklen_t addrlen);
SYSCALL_DECLARE(listen, int sockfd, int backlog);
SYSCALL_DECLARE(accept, int sockfd, struct sockaddr *addr, socklen_t *addrlen);
SYSCALL_DECLARE(recv, int sockfd, void *mem, size_t len, int flags);
SYSCALL_DECLARE(recvfrom, int sockfd, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
SYSCALL_DECLARE(send, int sockfd, const void *dataptr, size_t size, int flags);
SYSCALL_DECLARE(sendto, int sockfd, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen);
SYSCALL_DECLARE(setsockopt, int sockfd, int level, int optname, const void *optval, socklen_t optlen);

#endif /* NET_H */
3 changes: 2 additions & 1 deletion so3/include/pipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <memory.h>
#include <mutex.h>
#include <completion.h>
#include <syscall.h>

#define PIPE_READER 0
#define PIPE_WRITER 0
Expand Down Expand Up @@ -52,6 +53,6 @@ struct pipe_desc {
};
typedef struct pipe_desc pipe_desc_t;

int do_pipe(int pipefd[2]);
SYSCALL_DECLARE(pipe, int *pipefd);

#endif /* PIPE_H */
Loading
Loading