11#include <bits/posix/iovec.h>
34#define DEFINE_SYSCALL(ret, name) \
35 MOS_STATIC_ASSERT(SYSCALL_DEFINED(name)); \
36 ret define_syscall(name)
40#define POWEROFF_MAGIC MOS_FOURCC('G', 'B', 'y', 'e')
43 mos_warn(
"poweroff syscall called with wrong magic number (0x%x)", magic);
54 mos_warn(
"reboot is not implemented yet");
90 pr_warn(
"io_write called with invalid arguments (fd=%d, buf=%p, count=%zd)", fd, buf, count);
97 pr_warn(
"io_write called with invalid fd %d", fd);
205 if (IS_ERR(client_io))
206 return PTR_ERR(client_io);
226 return vfs_mount(device, mountpoint, fs_type, options);
270 case F_DUPFD_CLOEXEC:
305 case F_GETOWNER_UIDS:
322 return (
void *) result;
335 return (
void *) result;
363 return io_seek(io, offset, whence);
410 if (!fds || nfds == 0)
413 for (nfds_t i = 0; i < nfds; i++)
417 pr_info2(
"io_poll: fd=%d, events=%d", fds[i].fd, fds[i].events);
420 pr_emerg(
"io_poll is not implemented yet\n");
426#define FD_CLR(__fd, __set) (__set->fds_bits[__fd / 8] &= ~(1 << (__fd % 8)))
430#define FD_ISSET(__fd, __set) (__set->fds_bits[__fd / 8] & (1 << (__fd % 8)))
434#define FD_SET(__fd, __set) (__set->fds_bits[__fd / 8] |= 1 << (__fd % 8))
438#define FD_ZERO(__set) memset(__set->fds_bits, 0, sizeof(fd_set))
441DEFINE_SYSCALL(
int,
io_pselect)(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout,
const sigset_t *sigmask)
446 for (
int i = 0; i < nfds; i++)
448 if (readfds &&
FD_ISSET(i, readfds))
452 if (writefds &&
FD_ISSET(i, writefds))
456 if (exceptfds &&
FD_ISSET(i, exceptfds))
532 return PTR_ERR(
pipe);
552 for (
int i = 0; i < iovcnt; i++)
554 if (iov[i].iov_base ==
NULL)
560 for (
int i = 0; i < iovcnt; i++)
562 size_t ret =
io_read(io, iov[i].iov_base, iov[i].iov_len);
568 if (ret != iov[i].iov_len)
630 return io_pread(io, buf, count, offset);
654 char *ptr = (
char *) set;
656 for (
size_t i = 0; i <
sizeof(sigset_t); i++)
662 char *ptr = (
char *) set;
664 for (
size_t i = 0; i <
sizeof(sigset_t); i++)
668 default:
return -EINVAL;
#define mos_warn(fmt,...)
pfn_t dmabuf_allocate(size_t n_pages, ptr_t *pages)
Allocate DMA pages.
process_t * elf_create_process(const char *path, process_t *parent, const char *const argv[], const char *const envp[], const stdio_t *ios)
long signal_send_to_process(process_t *target, signal_t signal)
Send a signal to a process, an arbitrary thread will be chosen to receive the signal.
long signal_send_to_thread(thread_t *target, signal_t signal)
Send a signal to a thread.
MOSAPI char * strdup(const char *src)
MOSAPI char * strncpy(char *__restrict dest, const char *__restrict src, size_t n)
MOSAPI void(1, 2) fatal_abort(const char *fmt
long define_syscall vfs_chdirat(fd_t dirfd, const char *path)
Change the current working directory.
long define_syscall vfs_symlink(const char *target, const char *linkpath)
Create a symbolic link.
long define_syscall vfs_unmount(const char *path)
Unmount a filesystem at a given path.
ssize_t define_syscall vfs_getcwd(char *buf, size_t size)
Get the current working directory.
long define_syscall vfs_unlinkat(fd_t dirfd, const char *path)
Remove the name of a file, and possibly the file itself.
long define_syscall vfs_mount(const char *device, const char *mountpoint, const char *fs_type, const char *options)
Mount a filesystem at a given existing path.
long define_syscall vfs_mkdir(const char *path)
Create a directory.
long define_syscall vfs_fchmodat(fd_t dirfd, const char *path, int mode, int flags)
Change the permissions of a file.
ssize_t define_syscall vfs_readlinkat(fd_t dirfd, const char *path, char *buf, size_t buflen)
Read a symbolic link.
bool define_syscall vm_protect(void *addr, size_t size, mem_perm_t perm)
long define_syscall vfs_fsync(fd_t fd, bool data_only)
void *define_syscall mmap_anonymous(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t flags)
ssize_t define_syscall thread_getname(tid_t tid, char *buf, size_t buflen)
long define_syscall vfs_fstatat(fd_t fd, const char *path, file_stat_t *stat_buf, fstatat_flags flags)
bool define_syscall signal_register(signal_t sig, const sigaction_t *action)
fd_t define_syscall memfd_create(const char *name, u32 flags)
#define FD_ISSET(__fd, __set)
fd_t define_syscall io_dup(fd_t fd)
off_t define_syscall io_seek(fd_t fd, off_t offset, io_seek_whence_t whence)
fd_t define_syscall ipc_accept(fd_t listen_fd)
fd_t define_syscall io_dup2(fd_t oldfd, fd_t newfd)
long define_syscall clock_msleep(u64 ms)
long define_syscall signal_thread(tid_t tid, signal_t sig)
pid_t define_syscall wait_for_process(pid_t pid, u32 *exit_code, u32 flags)
long define_syscall signal_process(pid_t pid, signal_t sig)
off_t define_syscall io_tell(fd_t fd)
void define_syscall thread_exit(void)
void define_syscall poweroff(bool reboot, u32 magic)
pid_t define_syscall get_parent_pid(void)
long define_syscall fd_manipulate(fd_t fd, u64 op, void *arg)
int define_syscall io_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
bool define_syscall munmap(void *addr, size_t size)
fd_t define_syscall ipc_connect(const char *server, size_t buffer_size)
Connect to an IPC servers.
bool define_syscall dmabuf_free(ptr_t vaddr, ptr_t paddr)
void define_syscall exit(u32 exit_code)
void define_syscall yield_cpu(void)
bool define_syscall wait_for_thread(tid_t tid)
long define_syscall io_pread(fd_t fd, void *buf, size_t count, off_t offset)
long define_syscall signal_mask_op(int how, const sigset_t *set, sigset_t *oldset)
size_t define_syscall vfs_list_dir(fd_t fd, char *buffer, size_t buffer_size)
size_t define_syscall io_read(fd_t fd, void *buf, size_t count)
ssize_t define_syscall io_readv(fd_t fd, const struct iovec *iov, int iovcnt)
void *define_syscall mmap_file(ptr_t hint_addr, size_t size, mem_perm_t perm, mmap_flags_t mmap_flags, fd_t fd, off_t offset)
bool define_syscall dmabuf_alloc(size_t n_pages, ptr_t *phys, ptr_t *virt)
bool define_syscall dmabuf_unshare(ptr_t phys, size_t size, void *buf)
long define_syscall pipe(fd_t *reader, fd_t *writer, fd_flags_t flags)
pid_t define_syscall get_pid(void)
u64 define_syscall arch_syscall(u64 syscall, u64 arg1, u64 arg2, u64 arg3, u64 arg4)
pid_t define_syscall spawn(const char *path, const char *const argv[], const char *const envp[])
int define_syscall io_poll(struct pollfd *fds, nfds_t nfds, int timeout)
fd_t define_syscall vfs_openat(fd_t dirfd, const char *path, open_flags flags)
long define_syscall execveat(fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], u32 flags)
tid_t define_syscall get_tid(void)
fd_t define_syscall ipc_create(const char *name, size_t max_pending_connections)
Create a new IPC server.
tid_t define_syscall create_thread(const char *name, thread_entry_t entry, void *arg, size_t stack_size, void *stack)
void define_syscall signal_return(void *sp)
#define DEFINE_SYSCALL(ret, name)
size_t define_syscall io_write(fd_t fd, const void *buf, size_t count)
bool define_syscall dmabuf_share(void *buffer, size_t size, ptr_t *phyaddr)
long define_syscall thread_setname(tid_t tid, const char *name)
long define_syscall clock_gettimeofday(struct timespec *ts)
bool define_syscall io_close(fd_t fd)
pid_t define_syscall fork(void)
#define ALIGN_UP_TO_PAGE(addr)
#define futex_wake(futex, val)
#define futex_wait(futex, val)
pipeio_t * pipeio_create(pipe_t *pipe)
pipe_t * pipe_create(size_t bufsize)
void power_shutdown(void)
Shutdown the system.
#define pr_info2(fmt,...)
#define pr_emerg(fmt,...)
fd_t process_attach_ref_fd(process_t *process, io_t *file, fd_flags_t flags)
pid_t process_wait_for_pid(pid_t pid, u32 *exit_code, u32 flags)
bool process_register_signal_handler(process_t *process, signal_t sig, const sigaction_t *sigaction)
long process_do_execveat(process_t *process, fd_t dirfd, const char *path, const char *const argv[], const char *const envp[], int flags)
process_t * process_get(pid_t pid)
should_inline stdio_t current_stdio(void)
void process_exit(process_t *process, u8 exit_code, signal_t signal)
io_t * process_get_fd(process_t *process, fd_t fd)
process_t * process_do_fork(process_t *process)
bool process_detach_fd(process_t *process, fd_t fd)
void reschedule(void)
reschedule.
void scheduler_add_thread(thread_t *thread)
Add a thread to the scheduler, so that it can be scheduled.
#define spinlock_acquire(lock)
A wrapper type for the standard I/O streams.
thread_t * thread_get(tid_t id)
bool thread_wait_for_tid(tid_t tid)
thread_t * thread_complete_init(thread_t *thread)
thread_t * thread_new(process_t *owner, thread_mode mode, const char *name, size_t stack_size, void *stack)
long timer_msleep(u64 ms)
void(* thread_entry_t)(void *arg)