Cleaned up sysdeps

This commit is contained in:
fido2020 2020-02-15 21:29:20 +11:00
parent c4917449d2
commit 74c303724d
6 changed files with 75 additions and 111 deletions

View file

@ -20,6 +20,7 @@ rtdl_deps = [ ]
headers_only = get_option('headers_only')
no_headers = get_option('mlibc_no_headers')
static = get_option('static')
disable_ansi_option = false
disable_posix_option = false
disable_linux_option = false
@ -136,7 +137,6 @@ internal_sources = [
if host_machine.system() != 'lemon'
internal_sources += [
'options/internal/gcc-extra/mlibc_crtbegin.S',
'options/internal/gcc-extra/mlibc_crtend.S',
]
@ -180,30 +180,58 @@ subdir('options/glibc')
subdir('options/linux')
if not headers_only
ldso_lib = shared_library('ld', rtdl_sources,
name_prefix: '',
cpp_args: ['-fvisibility=hidden', '-DMLIBC_BUILDING_RTDL', '-DFRIGG_HAVE_LIBC'],
include_directories: rtdl_include_dirs,
dependencies: rtdl_deps,
install: true)
if not static
ldso_lib = shared_library('ld', rtdl_sources,
name_prefix: '',
cpp_args: ['-fvisibility=hidden', '-DMLIBC_BUILDING_RTDL', '-DFRIGG_HAVE_LIBC'],
include_directories: rtdl_include_dirs,
dependencies: rtdl_deps,
install: true)
shared_library('c',
[
libc_sources,
internal_sources,
ansi_sources,
lsb_sources,
],
cpp_args: ['-DFRIGG_HAVE_LIBC'],
include_directories: libc_include_dirs,
dependencies: libc_deps,
link_with: [ldso_lib],
link_whole: libc_sublibs,
install: true)
shared_library('c',
[
libc_sources,
internal_sources,
ansi_sources,
lsb_sources,
],
cpp_args: ['-DFRIGG_HAVE_LIBC'],
include_directories: libc_include_dirs,
dependencies: libc_deps,
link_with: [ldso_lib],
link_whole: libc_sublibs,
install: true)
shared_library('dl', 'libdl/src/dummy.cpp', install: true)
shared_library('pthread', 'libpthread/src/dummy.cpp', install: true)
shared_library('rt', 'librt/src/dummy.cpp', install: true)
shared_library('util', 'libutil/src/dummy.cpp', install: true)
shared_library('m', 'libm/src/dummy.cpp', install: true)
static_library('dl', 'libdl/src/dummy.cpp', install: true)
static_library('pthread', 'libpthread/src/dummy.cpp', install: true)
static_library('rt', 'librt/src/dummy.cpp', install: true)
static_library('util', 'libutil/src/dummy.cpp', install: true)
static_library('m', 'libm/src/dummy.cpp', install: true)
else
ldso_lib = static_library('ld', rtdl_sources,
name_prefix: '',
cpp_args: ['-fvisibility=hidden', '-DMLIBC_BUILDING_RTDL', '-DFRIGG_HAVE_LIBC'],
include_directories: rtdl_include_dirs,
dependencies: rtdl_deps,
install: true)
static_library('c',
[
libc_sources,
internal_sources,
ansi_sources,
],
cpp_args: ['-DFRIGG_HAVE_LIBC'],
include_directories: libc_include_dirs,
dependencies: libc_deps,
link_with: [ldso_lib],
link_whole: libc_sublibs,
install: true)
static_library('dl', 'libdl/src/dummy.cpp', install: true)
static_library('pthread', 'libpthread/src/dummy.cpp', install: true)
static_library('rt', 'librt/src/dummy.cpp', install: true)
static_library('util', 'libutil/src/dummy.cpp', install: true)
static_library('m', 'libm/src/dummy.cpp', install: true)
endif
endif

View file

@ -1,2 +1,3 @@
option('headers_only', type : 'boolean', value : false)
option('mlibc_no_headers', type : 'boolean', value : false)
option('static', type : 'boolean', value : true)

View file

@ -1,37 +0,0 @@
#include <lemon/syscall.h>
#include <stddef.h>
#include <lemon/filesystem.h>
int lemon_open(const char* filename, int flags){
int fd;
syscall(SYS_OPEN, filename, &fd, 0, 0, 0);
return fd;
}
void lemon_close(int fd){
syscall(SYS_CLOSE, fd, 0, 0, 0, 0);
}
int lemon_read(int fd, void* buffer, size_t count){
int ret;
syscall(SYS_READ, fd, buffer, count, &ret, 0);
return ret;
}
int lemon_write(int fd, const void* buffer, size_t count){
int ret;
syscall(SYS_WRITE, fd, buffer, count, &ret, 0);
return ret;
}
off_t lemon_seek(int fd, off_t offset, int whence){
uint64_t ret;
syscall(SYS_LSEEK, fd, offset, whence, &ret, 0);
return ret;
}
int lemon_readdir(int fd, uint64_t count, lemon_dirent_t* dirent){
uint64_t ret;
syscall(SYS_READDIR, fd, dirent, count, &ret, 0);
return ret;
}

View file

@ -1,22 +1,27 @@
#include <lemon/filesystem.h>
#include <lemon/syscall.h>
#include <sys/types.h>
namespace mlibc{
int sys_write(int fd, const void* buffer, size_t count, ssize_t* written){
ssize_t _written = lemon_write(fd, buffer, count);
if(_written == -1)
int ret;
syscall(SYS_WRITE, fd, (uintptr_t)buffer, count, (uintptr_t)&ret, 0);
*written = ret;
if(*written == -1)
return -1;
*written = _written;
return 0;
}
int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read) {
ssize_t ret;
int ret;
int sys_errno;
ret = lemon_read(fd, buf, count);
syscall(SYS_READ, fd, (uintptr_t)buf, count, (uintptr_t)&ret, 0);
if (ret == -1)
return -1;
@ -29,7 +34,10 @@ namespace mlibc{
off_t off;
int sys_errno;
off = lemon_seek(fd, offset, whence);
uint64_t ret;
syscall(SYS_LSEEK, fd, offset, whence, (uintptr_t)&ret, 0);
off = ret;
if (off == -1)
return -1;
@ -40,7 +48,8 @@ namespace mlibc{
int sys_open(const char* filename, int flags, int* fd){
int _fd = lemon_open(filename, flags);
int _fd;
syscall(SYS_OPEN, (uintptr_t)filename, (uintptr_t)&_fd, 0, 0, 0);
if(!fd)
return -1;
@ -50,15 +59,16 @@ namespace mlibc{
}
int sys_close(int fd){
lemon_close(fd);
syscall(SYS_CLOSE, fd, 0, 0, 0, 0);
return 0;
}
int sys_access(const char* filename, int mode){
int ret = lemon_open(filename, 0);
int ret;
sys_open(filename, mode, &ret);
if(ret) {
lemon_close(ret);
sys_close(ret);
return 0;
} else return 1;
}

View file

@ -1,36 +0,0 @@
#ifndef FS_H
#define FS_H
#include <stddef.h>
#include <sys/types.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"{
#endif
#define FS_NODE_FILE 0x1
#define FS_NODE_DIRECTORY 0x2
#define FS_NODE_BLKDEVICE 0x3
#define FS_NODE_SYMLINK 0x4
#define FS_NODE_CHARDEVICE 0x5
#define FS_NODE_MOUNTPOINT 0x8
typedef struct lemon_dirent {
uint32_t inode; // Inode number
char name[128]; // Filename
uint32_t type;
} lemon_dirent_t;
int lemon_open(const char* filename, int flags);
void lemon_close(int fd);
int lemon_read(int fd, void* buffer, size_t count);
int lemon_write(int fd, const void* buffer, size_t count);
off_t lemon_seek(int fd, off_t offset, int whence);
int lemon_readdir(int fd, uint64_t count, lemon_dirent_t* dirent);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -3,7 +3,6 @@ rtdl_sources += files(
)
libc_sources += files(
'generic/filesystem.c',
'generic/filesystem.cpp',
'generic/syscall.c',
'generic/lemon.cpp',
@ -18,7 +17,6 @@ if not no_headers
subdir: 'abi-bits'
)
install_headers(
'include/lemon/filesystem.h',
'include/lemon/syscall.h',
'include/lemon/spawn.h',
subdir: 'lemon'