Skip to content

Commit

Permalink
feat: add axlibc to root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed May 1, 2024
1 parent 9990cbf commit 72f3c74
Show file tree
Hide file tree
Showing 122 changed files with 11,620 additions and 26 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
actual.out
qemu.log
rusty-tags.vi
/testcases/riscv64-linux-musl-native.tgz
/testcases/gcc/riscv64-lnux-musl-native
/testcases/ZLM/MediaServer
.idea/
arceos-fada.bin.gz
arceos-fada.itb
.tmp_its
!tools/rk3588/ramdisk.img
!tools/axlibc
linker_*
testcases/
45 changes: 23 additions & 22 deletions build_img.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,29 @@ while [ -n "$1" ]; do
ext4)
fs=ext4
;;
sdcard)
FILE=sdcard
riscv64_linux_musl)
FILE=riscv64_linux_musl
;;
gcc)
FILE=gcc
riscv64_gcc)
FILE=riscv64_gcc
;;
redis)
FILE=redis
riscv64_redis)
FILE=riscv64_redis
;;
testsuits-x86_64-linux-musl)
FILE=testsuits-x86_64-linux-musl
x86_64_linux_musl)
FILE=x86_64_linux_musl
;;
ZLM)
FILE=ZLM
x86_64_ZLM)
FILE=x86_64_ZLM
;;
libc-dynamic)
FILE=libc-dynamic
riscv64_libctest_dynamic)
FILE=riscv64_libctest_dynamic
;;
libc-static)
FILE=libc-static
riscv64_libctest_static)
FILE=riscv64_libctest_static
;;
aarch64-linux-musl)
FILE=aarch64-linux-musl
;;
*)
display_help
Expand All @@ -78,21 +81,19 @@ done

if [ -z "$FILE" ]; then # use default testcases
if [ "$arch" = "riscv64" ]; then
FILE=sdcard
FILE=riscv64_linux_musl
elif [ "$arch" = "x86_64" ]; then
FILE=testsuits-x86_64-linux-musl
FILE=x86_64_linux_musl
elif [ "$arch" = "aarch64" ]; then
FILE=aarch64
FILE=aarch64-linux-musl
else
exit 1
fi
fi

if [ "$FILE" = "testsuits-x86_64-linux-musl" ] && [ ! -e testcases/$FILE ]; then # auto download
wget https://github.com/oscomp/testsuits-for-oskernel/releases/download/final-x86_64/$FILE.tgz
tar zxvf $FILE.tgz
mv $FILE testcases/$FILE -f
rm $FILE.tgz
# 如果 testcases 下对应测例不存在,执行 submodules 拉取
if [ ! -d "./testcases/$FILE" ]; then
git submodule update --init --recursive
fi

rm -f disk.img
Expand Down
3 changes: 3 additions & 0 deletions tools/axlibc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/libctypes_gen.rs
include/ax_pthread_mutex.h
build_*
58 changes: 58 additions & 0 deletions tools/axlibc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[package]
name = "axlibc"
version = "0.1.0"
edition = "2021"
authors = [
"Yuekai Jia <equation618@gmail.com>",
"yanjuguang <coolyanjg@163.com>",
"wudashuai <wu-ds20@mails.tsinghua.edu.cn>",
"yfblock <321353225@qq.com>",
"scPointer <bhy18@mails.tsinghua.edu.cn>",
"Shiping Yuan <robert_yuan@pku.edu.com>",
]
description = "ArceOS user program library for C apps"
license = "GPL-3.0-or-later OR Apache-2.0"
homepage = "https://github.com/rcore-os/arceos"
repository = "https://github.com/rcore-os/arceos/tree/main/ulib/axlibc"
documentation = "https://rcore-os.github.io/arceos/axlibc/index.html"

[lib]
crate-type = ["lib", "staticlib"]

[features]
default = []

# Multicore
smp = ["arceos_posix_api/smp"]

# Floating point/SIMD
fp_simd = ["axfeat/fp_simd"]

# Memory
alloc = ["arceos_posix_api/alloc"]
tls = ["alloc", "axfeat/tls"]

# Multi-task
multitask = ["arceos_posix_api/multitask"]

# File system
fs = ["arceos_posix_api/fs", "fd"]

# Networking
net = ["arceos_posix_api/net", "fd"]

# Libc features
fd = []
pipe = ["arceos_posix_api/pipe"]
select = ["arceos_posix_api/select"]
epoll = ["arceos_posix_api/epoll"]

[dependencies]
axfeat = { git = "https://github.com/Starry-OS/axfeat.git" }
arceos_posix_api = { git = "https://github.com/Starry-OS/arceos_posix_api.git" }
axio = { git = "https://github.com/Starry-OS/axio.git" }
axerrno = { git = "https://github.com/Starry-OS/axerrno.git" }
arch_boot = { git = "https://github.com/Starry-OS/arch_boot.git" }

[build-dependencies]
bindgen ={ version = "0.66" }
24 changes: 24 additions & 0 deletions tools/axlibc/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
fn main() {
fn gen_c_to_rust_bindings(in_file: &str, out_file: &str) {
println!("cargo:rerun-if-changed={in_file}");

let allow_types = ["tm", "jmp_buf"];
let mut builder = bindgen::Builder::default()
.header(in_file)
.clang_arg("-I./include")
.derive_default(true)
.size_t_is_usize(false)
.use_core();
for ty in allow_types {
builder = builder.allowlist_type(ty);
}

builder
.generate()
.expect("Unable to generate c->rust bindings")
.write_to_file(out_file)
.expect("Couldn't write bindings!");
}

gen_c_to_rust_bindings("ctypes.h", "src/libctypes_gen.rs");
}
8 changes: 8 additions & 0 deletions tools/axlibc/c/assert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>

_Noreturn void __assert_fail(const char *expr, const char *file, int line, const char *func)
{
fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line);
abort();
}
17 changes: 17 additions & 0 deletions tools/axlibc/c/ctype.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <ctype.h>
#include <stdio.h>
#include <string.h>

int tolower(int c)
{
if (isupper(c))
return c | 32;
return c;
}

int toupper(int c)
{
if (islower(c))
return c & 0x5f;
return c;
}
98 changes: 98 additions & 0 deletions tools/axlibc/c/dirent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#ifdef AX_CONFIG_FS

#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

int closedir(DIR *dir)
{
int ret = close(dir->fd);
free(dir);
return ret;
}

DIR *fdopendir(int fd)
{
DIR *dir;
struct stat st;

if (fstat(fd, &st) < 0) {
return 0;
}
if (fcntl(fd, F_GETFL) & O_PATH) {
errno = EBADF;
return 0;
}
if (!S_ISDIR(st.st_mode)) {
errno = ENOTDIR;
return 0;
}
if (!(dir = calloc(1, sizeof(*dir)))) {
return 0;
}

fcntl(fd, F_SETFD, FD_CLOEXEC);
dir->fd = fd;
return dir;
}

int dirfd(DIR *d)
{
return d->fd;
}

// TODO
DIR *opendir(const char *__name)
{
unimplemented();
return NULL;
}

// TODO
struct dirent *readdir(DIR *__dirp)
{
unimplemented();
return NULL;
}

// TODO
int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result)
{
struct dirent *de;
int errno_save = errno;
int ret;

// LOCK(dir->lock);
errno = 0;
de = readdir(dir);
if ((ret = errno)) {
// UNLOCK(dir->lock);
return ret;
}
errno = errno_save;
if (de)
memcpy(buf, de, de->d_reclen);
else
buf = NULL;

// UNLOCK(dir->lock);
*result = buf;
return 0;
}

// TODO
void rewinddir(DIR *dir)
{
// LOCK(dir->lock);
lseek(dir->fd, 0, SEEK_SET);
dir->buf_pos = dir->buf_end = 0;
dir->tell = 0;
// UNLOCK(dir->lock);
}

#endif // AX_CONFIG_FS
39 changes: 39 additions & 0 deletions tools/axlibc/c/dlfcn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>

// TODO
int dladdr(const void *__address, Dl_info *__info)
{
unimplemented();
return 0;
}

// TODO
void *dlopen(const char *__file, int __mode)
{
unimplemented();
return NULL;
}

// TODO
char *dlerror()
{
unimplemented();
return NULL;
}

// TODO
void *dlsym(void *__restrict__ __handle, const char *__restrict__ __name)
{

unimplemented();
return NULL;
}

// TODO
int dlclose(void *p)
{
unimplemented();
return 0;
}
31 changes: 31 additions & 0 deletions tools/axlibc/c/env.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

char *environ_[2] = {"dummy", NULL};
char **environ = (char **)environ_;

char *getenv(const char *name)
{
size_t l = strchrnul(name, '=') - name;
if (l && !name[l] && environ)
for (char **e = environ; *e; e++)
if (!strncmp(name, *e, l) && l[*e] == '=')
return *e + l + 1;
return 0;
}

// TODO
int setenv(const char *__name, const char *__value, int __replace)
{
unimplemented();
return 0;
}

// TODO
int unsetenv(const char *__name)
{
unimplemented();
return 0;
}
Loading

0 comments on commit 72f3c74

Please sign in to comment.