-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9990cbf
commit 72f3c74
Showing
122 changed files
with
11,620 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src/libctypes_gen.rs | ||
include/ax_pthread_mutex.h | ||
build_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.