BuildSystem: Move all userpace libraries under the userspace directory
As the number of libraries is increasing, root directory starts to expand. This adds better organization for libraries
This commit is contained in:
36
userspace/libraries/LibC/sys/banan-os.cpp
Normal file
36
userspace/libraries/LibC/sys/banan-os.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <sys/banan-os.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int tty_ctrl(int fildes, int command, int flags)
|
||||
{
|
||||
return syscall(SYS_TTY_CTRL, fildes, command, flags);
|
||||
}
|
||||
|
||||
int poweroff(int command)
|
||||
{
|
||||
return syscall(SYS_POWEROFF, command);
|
||||
}
|
||||
|
||||
int load_keymap(const char* path)
|
||||
{
|
||||
return syscall(SYS_LOAD_KEYMAP, path);
|
||||
}
|
||||
|
||||
long smo_create(size_t size, int prot)
|
||||
{
|
||||
return syscall(SYS_SMO_CREATE, size, prot);
|
||||
}
|
||||
|
||||
int smo_delete(long key)
|
||||
{
|
||||
return syscall(SYS_SMO_DELETE, key);
|
||||
}
|
||||
|
||||
void* smo_map(long key)
|
||||
{
|
||||
long ret = syscall(SYS_SMO_MAP, key);
|
||||
if (ret < 0)
|
||||
return nullptr;
|
||||
return reinterpret_cast<void*>(ret);
|
||||
}
|
||||
29
userspace/libraries/LibC/sys/mman.cpp
Normal file
29
userspace/libraries/LibC/sys/mman.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void* mmap(void* addr, size_t len, int prot, int flags, int fildes, off_t off)
|
||||
{
|
||||
sys_mmap_t args {
|
||||
.addr = addr,
|
||||
.len = len,
|
||||
.prot = prot,
|
||||
.flags = flags,
|
||||
.fildes = fildes,
|
||||
.off = off
|
||||
};
|
||||
long ret = syscall(SYS_MMAP, &args);
|
||||
if (ret == -1)
|
||||
return MAP_FAILED;
|
||||
return (void*)ret;
|
||||
}
|
||||
|
||||
int munmap(void* addr, size_t len)
|
||||
{
|
||||
return syscall(SYS_MUNMAP, addr, len);
|
||||
}
|
||||
|
||||
int msync(void* addr, size_t len, int flags)
|
||||
{
|
||||
return syscall(SYS_MSYNC, addr, len, flags);
|
||||
}
|
||||
31
userspace/libraries/LibC/sys/select.cpp
Normal file
31
userspace/libraries/LibC/sys/select.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <sys/select.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int pselect(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, const struct timespec* __restrict timeout, const sigset_t* __restrict sigmask)
|
||||
{
|
||||
sys_pselect_t arguments {
|
||||
.nfds = nfds,
|
||||
.readfds = readfds,
|
||||
.writefds = writefds,
|
||||
.errorfds = errorfds,
|
||||
.timeout = timeout,
|
||||
.sigmask = sigmask
|
||||
};
|
||||
return syscall(SYS_PSELECT, &arguments);
|
||||
}
|
||||
|
||||
int select(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, struct timeval* __restrict timeout)
|
||||
{
|
||||
timespec* pts = nullptr;
|
||||
timespec ts;
|
||||
if (timeout)
|
||||
{
|
||||
ts.tv_sec = timeout->tv_sec;
|
||||
ts.tv_nsec = timeout->tv_usec * 1000;
|
||||
pts = &ts;
|
||||
}
|
||||
|
||||
// TODO: "select may update timeout", should we?
|
||||
return pselect(nfds, readfds, writefds, errorfds, pts, nullptr);
|
||||
}
|
||||
79
userspace/libraries/LibC/sys/socket.cpp
Normal file
79
userspace/libraries/LibC/sys/socket.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||
{
|
||||
return syscall(SYS_ACCEPT, socket, address, address_len);
|
||||
}
|
||||
|
||||
int bind(int socket, const struct sockaddr* address, socklen_t address_len)
|
||||
{
|
||||
return syscall(SYS_BIND, socket, address, address_len);
|
||||
}
|
||||
|
||||
int connect(int socket, const struct sockaddr* address, socklen_t address_len)
|
||||
{
|
||||
return syscall(SYS_CONNECT, socket, address, address_len);
|
||||
}
|
||||
|
||||
int listen(int socket, int backlog)
|
||||
{
|
||||
return syscall(SYS_LISTEN, socket, backlog);
|
||||
}
|
||||
|
||||
ssize_t recv(int socket, void* __restrict buffer, size_t length, int flags)
|
||||
{
|
||||
return recvfrom(socket, buffer, length, flags, nullptr, nullptr);
|
||||
}
|
||||
|
||||
ssize_t recvfrom(int socket, void* __restrict buffer, size_t length, int flags, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||
{
|
||||
sys_recvfrom_t arguments {
|
||||
.socket = socket,
|
||||
.buffer = buffer,
|
||||
.length = length,
|
||||
.flags = flags,
|
||||
.address = address,
|
||||
.address_len = address_len
|
||||
};
|
||||
return syscall(SYS_RECVFROM, &arguments);
|
||||
}
|
||||
|
||||
ssize_t send(int socket, const void* message, size_t length, int flags)
|
||||
{
|
||||
return sendto(socket, message, length, flags, nullptr, 0);
|
||||
}
|
||||
|
||||
ssize_t sendto(int socket, const void* message, size_t length, int flags, const struct sockaddr* dest_addr, socklen_t dest_len)
|
||||
{
|
||||
sys_sendto_t arguments {
|
||||
.socket = socket,
|
||||
.message = message,
|
||||
.length = length,
|
||||
.flags = flags,
|
||||
.dest_addr = dest_addr,
|
||||
.dest_len = dest_len
|
||||
};
|
||||
return syscall(SYS_SENDTO, &arguments);
|
||||
}
|
||||
|
||||
int socket(int domain, int type, int protocol)
|
||||
{
|
||||
return syscall(SYS_SOCKET, domain, type, protocol);
|
||||
}
|
||||
|
||||
int getsockname(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||
{
|
||||
return syscall(SYS_GETSOCKNAME, socket, address, address_len);
|
||||
}
|
||||
|
||||
int getsockopt(int socket, int level, int option_name, void* __restrict option_value, socklen_t* __restrict option_len)
|
||||
{
|
||||
return syscall(SYS_GETSOCKOPT, socket, level, option_name, option_value, option_len);
|
||||
}
|
||||
|
||||
int setsockopt(int socket, int level, int option_name, const void* option_value, socklen_t option_len)
|
||||
{
|
||||
return syscall(SYS_SETSOCKOPT, socket, level, option_name, option_value, option_len);
|
||||
}
|
||||
35
userspace/libraries/LibC/sys/stat.cpp
Normal file
35
userspace/libraries/LibC/sys/stat.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int chmod(const char* path, mode_t mode)
|
||||
{
|
||||
return syscall(SYS_CHMOD, path, mode);
|
||||
}
|
||||
|
||||
int fstat(int fildes, struct stat* buf)
|
||||
{
|
||||
return syscall(SYS_FSTAT, fildes, buf);
|
||||
}
|
||||
|
||||
int fstatat(int fd, const char* __restrict path, struct stat* __restrict buf, int flag)
|
||||
{
|
||||
return syscall(SYS_FSTATAT, fd, path, buf, flag);
|
||||
}
|
||||
|
||||
int lstat(const char* __restrict path, struct stat* __restrict buf)
|
||||
{
|
||||
return syscall(SYS_STAT, path, buf, AT_SYMLINK_NOFOLLOW);
|
||||
}
|
||||
|
||||
int stat(const char* __restrict path, struct stat* __restrict buf)
|
||||
{
|
||||
return syscall(SYS_STAT, path, buf, 0);
|
||||
}
|
||||
|
||||
int mkdir(const char* path, mode_t mode)
|
||||
{
|
||||
return syscall(SYS_CREATE_DIR, path, mode);
|
||||
}
|
||||
13
userspace/libraries/LibC/sys/wait.cpp
Normal file
13
userspace/libraries/LibC/sys/wait.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
pid_t wait(int* stat_loc)
|
||||
{
|
||||
return waitpid(-1, stat_loc, 0);
|
||||
}
|
||||
|
||||
pid_t waitpid(pid_t pid, int* stat_loc, int options)
|
||||
{
|
||||
return (pid_t)syscall(SYS_WAIT, pid, stat_loc, options);
|
||||
}
|
||||
Reference in New Issue
Block a user