diff --git a/api/arceos_posix_api/src/imp/fd_ops.rs b/api/arceos_posix_api/src/imp/fd_ops.rs index bfe261ac8..e46283fa4 100644 --- a/api/arceos_posix_api/src/imp/fd_ops.rs +++ b/api/arceos_posix_api/src/imp/fd_ops.rs @@ -99,7 +99,6 @@ pub fn sys_dup2(old_fd: c_int, new_fd: c_int) -> c_int { if new_fd as usize >= AX_FILE_LIMIT { return Err(LinuxError::EBADF); } - let _ = close_file_like(new_fd).map(|_| 0); let f = get_file_like(old_fd)?; FD_TABLE diff --git a/apps/c/nginx/axbuild.mk b/apps/c/nginx/axbuild.mk index eb8845a89..f6b80f62d 100755 --- a/apps/c/nginx/axbuild.mk +++ b/apps/c/nginx/axbuild.mk @@ -18,10 +18,17 @@ ifneq ($(V),) nginx-build-args += V=$(V) endif +ifeq ($(V9P),y) + DISK_ARG = 9p +else + DISK_ARG = no_9p +endif + + disk.img: ls echo "nginx makefile create_nginx_img" - ./$(APP)/create_nginx_img.sh + ./$(APP)/create_nginx_img.sh $(DISK_ARG) $(nginx-dir): git clone https://github.com/lhw2002426/nginx-app.git $(APP)/nginx-app diff --git a/apps/c/nginx/create_nginx_img.sh b/apps/c/nginx/create_nginx_img.sh index 941aac2bb..05f08071f 100755 --- a/apps/c/nginx/create_nginx_img.sh +++ b/apps/c/nginx/create_nginx_img.sh @@ -1,11 +1,18 @@ #!/bin/bash # From https://github.com/rafalh/rust-fatfs/blob/master/scripts/create-test-img.sh - -CUR_DIR=`dirname $0` +CUR_DIR=$(dirname $0) echo $OUT_DIR +if [ $# -lt 1 ]; then + CONF = "$CUR_DIR/nginx.conf" +elif [ "$arg1" = "9p" ]; then + CONF = "$CUR_DIR/nginx_9p.conf" +else + CONF = "$CUR_DIR/nginx.conf" +fi + create_test_img() { local name=$1 local blkcount=$2 @@ -21,7 +28,7 @@ create_test_img() { echo "root:x:0:" >> "mnt/etc/group" # echo "" >> "mnt/nginx/logs/error.log" mkdir -p "mnt/nginx/conf" - cp "$CUR_DIR/nginx.conf" "mnt/nginx/conf/nginx.conf" + cp "$CONF" "mnt/nginx/conf/nginx.conf" cp "$CUR_DIR/mime.types" "mnt/nginx/conf/mime.types" mkdir -p "mnt/html" cp -r "$CUR_DIR/html" "mnt/" diff --git a/apps/c/nginx/features.txt b/apps/c/nginx/features.txt index 50b26cd31..a5feb489e 100755 --- a/apps/c/nginx/features.txt +++ b/apps/c/nginx/features.txt @@ -10,4 +10,5 @@ pipe epoll poll select -virtio-9p \ No newline at end of file +virtio-9p +rtc \ No newline at end of file diff --git a/apps/c/nginx/mnt/etc/group b/apps/c/nginx/mnt/etc/group new file mode 100644 index 000000000..235fd15fe --- /dev/null +++ b/apps/c/nginx/mnt/etc/group @@ -0,0 +1,10 @@ +root:x:0: +root:x:0: +root:x:0: +root:x:0: +root:x:0: +root:x:0: +root:x:0: +root:x:0: +root:x:0: +root:x:0: diff --git a/apps/c/nginx/mnt/etc/localtime b/apps/c/nginx/mnt/etc/localtime new file mode 100644 index 000000000..584ba8795 --- /dev/null +++ b/apps/c/nginx/mnt/etc/localtime @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/apps/c/nginx/mnt/etc/passwd b/apps/c/nginx/mnt/etc/passwd new file mode 100644 index 000000000..e03277f87 --- /dev/null +++ b/apps/c/nginx/mnt/etc/passwd @@ -0,0 +1,10 @@ +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash +root:x:0:0:root:/root:/bin/bash diff --git a/apps/c/nginx/nginx_9p.conf b/apps/c/nginx/nginx_9p.conf new file mode 100755 index 000000000..3eb65b1e5 --- /dev/null +++ b/apps/c/nginx/nginx_9p.conf @@ -0,0 +1,40 @@ +worker_processes 1; +daemon off; +master_process off; + +error_log logs/error.log debug; + +events { + worker_connections 32; +} + +http { + include mime.types; + default_type application/octet-stream; + + keepalive_timeout 65; + + server { + listen 5555; + server_name localhost; + + index index.html; + + root /v9fs; + + location / { + try_files $uri $uri/ /404.html; + } + + error_page 404 /404.html; + location = /404.html { + root /v9fs; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /v9fs; + } + + } +} \ No newline at end of file diff --git a/ulib/axlibc/c/fcntl.c b/ulib/axlibc/c/fcntl.c index 61f8e979b..3dd463053 100644 --- a/ulib/axlibc/c/fcntl.c +++ b/ulib/axlibc/c/fcntl.c @@ -62,4 +62,10 @@ int sync_file_range(int fd, off_t pos, off_t len, unsigned flags) return 0; } +int openat(int dirfd, const char *pathname, int flags, ...) +{ + unimplemented(); + return 0; +} + #endif // AX_CONFIG_FS diff --git a/ulib/axlibc/c/grp.c b/ulib/axlibc/c/grp.c new file mode 100644 index 000000000..ada2073ac --- /dev/null +++ b/ulib/axlibc/c/grp.c @@ -0,0 +1,46 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include +#include +#include +#include +#include + +/* Group members */ +static char *g_members__[] = { AX_DEFAULT_USER, NULL }; + +/* Default group */ +static struct group g__ = { + .gr_name = AX_DEFAULT_GROUP, + .gr_passwd = AX_DEFAULT_PASS, + .gr_gid = AX_DEFAULT_GID, + .gr_mem = g_members__, +}; + +// TODO +int initgroups(const char *user, gid_t group) +{ + unimplemented(); + return 0; +} + +struct group *getgrnam(const char *name) +{ + struct group *res; + + if (name && !strcmp(name, g__.gr_name)) + res = &g__; + else { + res = NULL; + errno = ENOENT; + } + + return res; +} \ No newline at end of file diff --git a/ulib/axlibc/c/ioctl.c b/ulib/axlibc/c/ioctl.c index 9c961bb76..11ee86c3d 100644 --- a/ulib/axlibc/c/ioctl.c +++ b/ulib/axlibc/c/ioctl.c @@ -9,10 +9,18 @@ #include #include +#include + +int ax_ioctl(int fd, int cmd, size_t arg); // TODO -int ioctl(int __fd, int __request, ...) +int ioctl(int fd, int request, ...) { - unimplemented(); - return 0; + unsigned long arg; + va_list ap; + va_start(ap, request); + arg = va_arg(ap, unsigned long); + va_end(ap); + + return ax_ioctl(fd, request, arg); } diff --git a/ulib/axlibc/c/mmap.c b/ulib/axlibc/c/mmap.c index a9786dba9..682dd9c8f 100644 --- a/ulib/axlibc/c/mmap.c +++ b/ulib/axlibc/c/mmap.c @@ -14,14 +14,21 @@ // TODO: void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) { - unimplemented(); - return MAP_FAILED; + //unimplemented(); + //return MAP_FAILED; + int *res = malloc(len); + if (res == NULL) { + return NULL; + } + printf("use malloc imp mmap: addr: %p len: %d res: %p\n",addr,len,res); + printf("if i can acess res: %d",*res); + return res; } // TODO: int munmap(void *addr, size_t length) { - unimplemented(); + free(addr); return 0; } diff --git a/ulib/axlibc/c/netdb.c b/ulib/axlibc/c/netdb.c new file mode 100644 index 000000000..a2638457f --- /dev/null +++ b/ulib/axlibc/c/netdb.c @@ -0,0 +1,19 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include +#include + + +// TODO +struct hostent *gethostbyname(const char *name) +{ + unimplemented(); + return 0; +} \ No newline at end of file diff --git a/ulib/axlibc/c/nscd.h b/ulib/axlibc/c/nscd.h new file mode 100644 index 000000000..b0ee655ee --- /dev/null +++ b/ulib/axlibc/c/nscd.h @@ -0,0 +1,44 @@ +#ifndef NSCD_H +#define NSCD_H + +#include + +#define NSCDVERSION 2 +#define GETPWBYNAME 0 +#define GETPWBYUID 1 +#define GETGRBYNAME 2 +#define GETGRBYGID 3 +#define GETINITGR 15 + +#define REQVERSION 0 +#define REQTYPE 1 +#define REQKEYLEN 2 +#define REQ_LEN 3 + +#define PWVERSION 0 +#define PWFOUND 1 +#define PWNAMELEN 2 +#define PWPASSWDLEN 3 +#define PWUID 4 +#define PWGID 5 +#define PWGECOSLEN 6 +#define PWDIRLEN 7 +#define PWSHELLLEN 8 +#define PW_LEN 9 + +#define GRVERSION 0 +#define GRFOUND 1 +#define GRNAMELEN 2 +#define GRPASSWDLEN 3 +#define GRGID 4 +#define GRMEMCNT 5 +#define GR_LEN 6 + +#define INITGRVERSION 0 +#define INITGRFOUND 1 +#define INITGRNGRPS 2 +#define INITGR_LEN 3 + +FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *swap); + +#endif \ No newline at end of file diff --git a/ulib/axlibc/c/nscd_query.c b/ulib/axlibc/c/nscd_query.c new file mode 100644 index 000000000..5770e500b --- /dev/null +++ b/ulib/axlibc/c/nscd_query.c @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include +#include +#include "nscd.h" +#include + +static const struct { + short sun_family; + char sun_path[21]; +} addr = { + AF_UNIX, + "/var/run/nscd/socket" +}; + +FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *swap) +{ + size_t i; + int fd; + FILE *f = 0; + int32_t req_buf[REQ_LEN] = { + NSCDVERSION, + req, + strnlen(key,LOGIN_NAME_MAX)+1 + }; + struct msghdr msg = { + .msg_iov = (struct iovec[]){ + {&req_buf, sizeof(req_buf)}, + {(char*)key, strlen(key)+1} + }, + .msg_iovlen = 2 + }; + int errno_save = errno; + + *swap = 0; +retry: + memset(buf, 0, len); + buf[0] = NSCDVERSION; + + fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + if (fd < 0) { + if (errno == EAFNOSUPPORT) { + f = fopen("/dev/null", "re"); + if (f) + errno = errno_save; + return f; + } + return 0; + } + + if(!(f = fdopen(fd, "r"))) { + close(fd); + return 0; + } + + if (req_buf[2] > LOGIN_NAME_MAX) + return f; + + if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { + /* If there isn't a running nscd we simulate a "not found" + * result and the caller is responsible for calling + * fclose on the (unconnected) socket. The value of + * errno must be left unchanged in this case. */ + if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) { + errno = errno_save; + return f; + } + goto error; + } + + if (sendmsg(fd, &msg, MSG_NOSIGNAL) < 0) + goto error; + + if (!fread(buf, len, 1, f)) { + /* If the VERSION entry mismatches nscd will disconnect. The + * most likely cause is that the endianness mismatched. So, we + * byteswap and try once more. (if we already swapped, just + * fail out) + */ + if (ferror(f)) goto error; + if (!*swap) { + fclose(f); + for (i = 0; i < sizeof(req_buf)/sizeof(req_buf[0]); i++) { + req_buf[i] = bswap_32(req_buf[i]); + } + *swap = 1; + goto retry; + } else { + errno = EIO; + goto error; + } + } + + if (*swap) { + for (i = 0; i < len/sizeof(buf[0]); i++) { + buf[i] = bswap_32(buf[i]); + } + } + + /* The first entry in every nscd response is the version number. This + * really shouldn't happen, and is evidence of some form of malformed + * response. + */ + if(buf[0] != NSCDVERSION) { + errno = EIO; + goto error; + } + + return f; +error: + fclose(f); + return 0; +} \ No newline at end of file diff --git a/ulib/axlibc/c/prctl.c b/ulib/axlibc/c/prctl.c new file mode 100644 index 000000000..6a9a19bc2 --- /dev/null +++ b/ulib/axlibc/c/prctl.c @@ -0,0 +1,18 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include +#include + +// TODO +int prctl(int option, ...) +{ + unimplemented(); + return 0; +} \ No newline at end of file diff --git a/ulib/axlibc/c/pwd.c b/ulib/axlibc/c/pwd.c index 3beb91cb3..d47810904 100644 --- a/ulib/axlibc/c/pwd.c +++ b/ulib/axlibc/c/pwd.c @@ -9,6 +9,19 @@ #include #include +#include +#include +#include + +static struct passwd pw__ = { + .pw_name = AX_DEFAULT_USER, + .pw_passwd = AX_DEFAULT_PASS, + .pw_uid = AX_DEFAULT_UID, + .pw_gid = AX_DEFAULT_GID, + .pw_gecos = AX_DEFAULT_USER, + .pw_dir = "/", + .pw_shell = "", +}; int getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size, struct passwd **res) { @@ -21,3 +34,17 @@ int getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size, struct pass unimplemented(); return 0; } + +struct passwd *getpwnam(const char *name) +{ + struct passwd *pwd; + + if (name && !strcmp(name, pw__.pw_name)) + pwd = &pw__; + else { + pwd = NULL; + errno = ENOENT; + } + + return pwd; +} diff --git a/ulib/axlibc/c/resource.c b/ulib/axlibc/c/resource.c index c008a7200..2378006ef 100644 --- a/ulib/axlibc/c/resource.c +++ b/ulib/axlibc/c/resource.c @@ -17,3 +17,9 @@ int getrusage(int __who, struct rusage *__usage) unimplemented(); return 0; } + +int setpriority(int which, id_t who, int prio) +{ + unimplemented(); + return 0; +} diff --git a/ulib/axlibc/c/sched.c b/ulib/axlibc/c/sched.c index 7910af645..8380a1274 100644 --- a/ulib/axlibc/c/sched.c +++ b/ulib/axlibc/c/sched.c @@ -16,3 +16,9 @@ int sched_setaffinity(pid_t __pid, size_t __cpusetsize, const cpu_set_t *__cpuse unimplemented(); return 0; } + +int sched_yield(void) +{ + unimplemented(); + return 0; +} diff --git a/ulib/axlibc/c/select.c b/ulib/axlibc/c/select.c index b8103434e..5ef483bb2 100644 --- a/ulib/axlibc/c/select.c +++ b/ulib/axlibc/c/select.c @@ -23,4 +23,11 @@ int pselect(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restric return 0; } +int select(int n, fd_set *__restrict rfds, fd_set *__restrict wfds, fd_set *__restrict efds, + struct timeval *__restrict tv) +{ + unimplemented(); + return 0; +} + #endif // AX_CONFIG_SELECT diff --git a/ulib/axlibc/c/semaphore.c b/ulib/axlibc/c/semaphore.c new file mode 100644 index 000000000..301216aa2 --- /dev/null +++ b/ulib/axlibc/c/semaphore.c @@ -0,0 +1,39 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include +#include + +// TODO +int sem_destroy(sem_t *sem) +{ + unimplemented(); + return 0; +} + +// TODO +int sem_init(sem_t *sem, int pshared, unsigned int value) +{ + unimplemented(); + return 0; +} + +// TODO +int sem_post(sem_t *sem) +{ + unimplemented(); + return 0; +} + +// TODO +int sem_wait(sem_t *sem) +{ + unimplemented(); + return 0; +} \ No newline at end of file diff --git a/ulib/axlibc/c/sendfile.c b/ulib/axlibc/c/sendfile.c new file mode 100644 index 000000000..a4a86654f --- /dev/null +++ b/ulib/axlibc/c/sendfile.c @@ -0,0 +1,16 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include +#include + +ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count){ + unimplemented(); + return 0; +} \ No newline at end of file diff --git a/ulib/axlibc/c/signal.c b/ulib/axlibc/c/signal.c index 961ad99f8..f5f8af4d7 100644 --- a/ulib/axlibc/c/signal.c +++ b/ulib/axlibc/c/signal.c @@ -76,6 +76,18 @@ int pthread_sigmask(int __how, const sigset_t *restrict __newmask, sigset_t *res return 0; } +// TODO +int sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict oldset) +{ + unimplemented(); + return 0; +} +int sigsuspend(const sigset_t *mask) +{ + unimplemented(); + return 0; +} + #ifdef AX_CONFIG_MULTITASK // TODO int pthread_kill(pthread_t t, int sig) diff --git a/ulib/axlibc/c/socket.c b/ulib/axlibc/c/socket.c index b2b4d10e1..e7f8f0bbb 100644 --- a/ulib/axlibc/c/socket.c +++ b/ulib/axlibc/c/socket.c @@ -77,4 +77,18 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) return ax_sendmsg(fd, msg, flags); } +// TODO +ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) +{ + unimplemented(); + return 0; +} + +// TODO +int socketpair(int domain, int type, int protocol, int sv[2]) +{ + unimplemented(); + return 0; +} + #endif // AX_CONFIG_NET diff --git a/ulib/axlibc/c/statfs.c b/ulib/axlibc/c/statfs.c new file mode 100644 index 000000000..36d3b7e57 --- /dev/null +++ b/ulib/axlibc/c/statfs.c @@ -0,0 +1,18 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include +#include + +// TODO +int statfs(const char *path, struct statfs *buf) +{ + unimplemented(); + return 0; +} \ No newline at end of file diff --git a/ulib/axlibc/c/stdlib.c b/ulib/axlibc/c/stdlib.c index 7a98cb34c..78bc32dc0 100644 --- a/ulib/axlibc/c/stdlib.c +++ b/ulib/axlibc/c/stdlib.c @@ -615,3 +615,103 @@ int system(const char *cmd) unimplemented(); return 0; } + +// TODO +char *realpath(const char *restrict path, char *restrict resolved_path) +{ + unimplemented(); + return 0; +} + +#define SIZE_ALIGN (4*sizeof(size_t)) +#define SIZE_MASK (-SIZE_ALIGN) +#define OVERHEAD (2*sizeof(size_t)) +#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) +#define DONTCARE 16 +#define RECLAIM 163840 + +#define CHUNK_SIZE(c) ((c)->csize & -2) +#define CHUNK_PSIZE(c) ((c)->psize & -2) +#define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) +#define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) +#define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) +#define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD) +#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) + +#define C_INUSE ((size_t)1) + +#define IS_MMAPPED(c) !((c)->csize & (C_INUSE)) + +struct chunk { + size_t psize, csize; + struct chunk *next, *prev; +}; + +void __bin_chunk(struct chunk *) +{ + unimplemented(); + return; +} + +void *aligned_alloc(size_t align, size_t len) +{ + unsigned char *mem, *new; + + if ((align & -align) != align) { + errno = EINVAL; + return 0; + } + + /*if (len > SIZE_MAX - align || + (__malloc_replaced && !__aligned_alloc_replaced)) { + errno = ENOMEM; + return 0; + }*/ + if (len > SIZE_MAX - align) { + errno = ENOMEM; + return 0; + } + + if (align <= SIZE_ALIGN) + return malloc(len); + + if (!(mem = malloc(len + align-1))) + return 0; + + new = (void *)((uintptr_t)mem + align-1 & -align); + if (new == mem) return mem; + + struct chunk *c = MEM_TO_CHUNK(mem); + struct chunk *n = MEM_TO_CHUNK(new); + + if (IS_MMAPPED(c)) { + /* Apply difference between aligned and original + * address to the "extra" field of mmapped chunk. */ + n->psize = c->psize + (new-mem); + n->csize = c->csize - (new-mem); + return new; + } + + struct chunk *t = NEXT_CHUNK(c); + + /* Split the allocated chunk into two chunks. The aligned part + * that will be used has the size in its footer reduced by the + * difference between the aligned and original addresses, and + * the resulting size copied to its header. A new header and + * footer are written for the split-off part to be freed. */ + n->psize = c->csize = C_INUSE | (new-mem); + n->csize = t->psize -= new-mem; + + __bin_chunk(c); + return new; +} + +// TODO +int posix_memalign(void **res, size_t align, size_t len) +{ + if (align < sizeof(void *)) return EINVAL; + void *mem = aligned_alloc(align, len); + if (!mem) return errno; + *res = mem; + return 0; +} diff --git a/ulib/axlibc/c/uio.c b/ulib/axlibc/c/uio.c new file mode 100644 index 000000000..19575ad7c --- /dev/null +++ b/ulib/axlibc/c/uio.c @@ -0,0 +1,32 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#include +#include + +// TODO +ssize_t readv(int fd, const struct iovec *iov, int iovcnt) +{ + unimplemented(); + return 0; +} + +// TODO +ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) +{ + unimplemented(); + return 0; +} + +// TODO +ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) +{ + unimplemented(); + return 0; +} \ No newline at end of file diff --git a/ulib/axlibc/c/unistd.c b/ulib/axlibc/c/unistd.c index 2bf7ea047..c4c9754be 100644 --- a/ulib/axlibc/c/unistd.c +++ b/ulib/axlibc/c/unistd.c @@ -14,6 +14,14 @@ #include #include #include +#include + +// TODO: +pid_t getppid(void) +{ + unimplemented(); + return 0; +} // TODO: uid_t geteuid(void) @@ -29,6 +37,13 @@ uid_t getuid(void) return 0; } +// TODO +int setuid (uid_t __uid) +{ + unimplemented(); + return 0; +} + // TODO pid_t setsid(void) { @@ -36,6 +51,13 @@ pid_t setsid(void) return 0; } +// TODO +int setgid(gid_t gid) +{ + unimplemented(); + return 0; +} + // TODO int isatty(int fd) { @@ -43,6 +65,46 @@ int isatty(int fd) return 0; } +// TODO +int getpagesize(void) +{ + unimplemented(); + return 0; +} + +// TODO +ssize_t pread(int fd, void *buf, size_t count, off_t offset) +{ + unimplemented(); + return 0; +} + +// TODO +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) +{ + unimplemented(); + return 0; +} + +// TODO +int gethostname(char *name, size_t len) +{ + size_t i; + struct utsname uts; + if (uname(&uts)) return -1; + if (len > sizeof uts.nodename) len = sizeof uts.nodename; + for (i=0; i +#include + +static __inline uint16_t __bswap_16(uint16_t __x) +{ + return __x<<8 | __x>>8; +} + +static __inline uint32_t __bswap_32(uint32_t __x) +{ + return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; +} + +static __inline uint64_t __bswap_64(uint64_t __x) +{ + return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32); +} + +#define bswap_16(x) __bswap_16(x) +#define bswap_32(x) __bswap_32(x) +#define bswap_64(x) __bswap_64(x) + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/byteswap.h b/ulib/axlibc/include/byteswap.h new file mode 100644 index 000000000..165f2d619 --- /dev/null +++ b/ulib/axlibc/include/byteswap.h @@ -0,0 +1,26 @@ +#ifndef _BYTESWAP_H +#define _BYTESWAP_H + +#include +#include + +static __inline uint16_t __bswap_16(uint16_t __x) +{ + return __x<<8 | __x>>8; +} + +static __inline uint32_t __bswap_32(uint32_t __x) +{ + return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; +} + +static __inline uint64_t __bswap_64(uint64_t __x) +{ + return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32); +} + +#define bswap_16(x) __bswap_16(x) +#define bswap_32(x) __bswap_32(x) +#define bswap_64(x) __bswap_64(x) + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/crypt.h b/ulib/axlibc/include/crypt.h new file mode 100644 index 000000000..65196e692 --- /dev/null +++ b/ulib/axlibc/include/crypt.h @@ -0,0 +1,20 @@ +#ifndef _CRYPT_H +#define _CRYPT_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct crypt_data { + int initialized; + char __buf[256]; +}; + +char *crypt(const char *, const char *); +char *crypt_r(const char *, const char *, struct crypt_data *); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/fcntl.h b/ulib/axlibc/include/fcntl.h index 2f693d004..0f35dc227 100644 --- a/ulib/axlibc/include/fcntl.h +++ b/ulib/axlibc/include/fcntl.h @@ -12,6 +12,7 @@ #include +#define AT_SYMLINK_NOFOLLOW 0x100 #define O_CREAT 0100 #define O_EXCL 0200 #define O_NOCTTY 0400 @@ -129,5 +130,6 @@ int posix_fadvise(int __fd, unsigned long __offset, unsigned long __len, int __a int sync_file_range(int, off_t, off_t, unsigned); int open(const char *filename, int flags, ...); +int openat(int, const char *, int, ...); #endif diff --git a/ulib/axlibc/include/grp.h b/ulib/axlibc/include/grp.h new file mode 100644 index 000000000..207972981 --- /dev/null +++ b/ulib/axlibc/include/grp.h @@ -0,0 +1,53 @@ +#ifndef _GRP_H +#define _GRP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define __NEED_size_t +#define __NEED_gid_t + +#ifdef _GNU_SOURCE +#define __NEED_FILE +#endif + +#include + +struct group { + char *gr_name; + char *gr_passwd; + gid_t gr_gid; + char **gr_mem; +}; + +struct group *getgrgid(gid_t); +struct group *getgrnam(const char *); + +int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); +int getgrnam_r(const char *, struct group *, char *, size_t, struct group **); + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +struct group *getgrent(void); +void endgrent(void); +void setgrent(void); +#endif + +#ifdef _GNU_SOURCE +struct group *fgetgrent(FILE *); +int putgrent(const struct group *, FILE *); +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +int getgrouplist(const char *, gid_t, gid_t *, int *); +int setgroups(size_t, const gid_t *); +int initgroups(const char *, gid_t); +#endif + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/malloc.h b/ulib/axlibc/include/malloc.h new file mode 100644 index 000000000..b4969fb77 --- /dev/null +++ b/ulib/axlibc/include/malloc.h @@ -0,0 +1,25 @@ +#ifndef _MALLOC_H +#define _MALLOC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define __NEED_size_t + +#include + +//void *malloc (size_t); +//void *calloc (size_t, size_t); +//void *realloc (void *, size_t); +void free (void *); +void *valloc (size_t); +void *memalign(size_t, size_t); + +size_t malloc_usable_size(void *); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/netdb.h b/ulib/axlibc/include/netdb.h index 315c59f6c..5e10a18bb 100644 --- a/ulib/axlibc/include/netdb.h +++ b/ulib/axlibc/include/netdb.h @@ -89,6 +89,39 @@ int getaddrinfo(const char *, const char *, const struct addrinfo *, struct addr void freeaddrinfo(struct addrinfo *); const char *gai_strerror(int __ecode); +/* Legacy functions follow (marked OBsolete in SUS) */ + +struct netent { + char *n_name; + char **n_aliases; + int n_addrtype; + uint32_t n_net; +}; + +struct hostent { + char *h_name; + char **h_aliases; + int h_addrtype; + int h_length; + char **h_addr_list; +}; +#define h_addr h_addr_list[0] + +struct servent { + char *s_name; + char **s_aliases; + int s_port; + char *s_proto; +}; + +struct protoent { + char *p_name; + char **p_aliases; + int p_proto; +}; + +struct hostent *gethostbyname (const char *); + #endif // AX_CONFIG_NET #endif // _NETDB_H diff --git a/ulib/axlibc/include/netinet/in.h b/ulib/axlibc/include/netinet/in.h index 48684aafb..dc0219a95 100644 --- a/ulib/axlibc/include/netinet/in.h +++ b/ulib/axlibc/include/netinet/in.h @@ -15,6 +15,11 @@ #define INET_ADDRSTRLEN 16 #define INET6_ADDRSTRLEN 46 +#define INADDR_ANY ((in_addr_t) 0x00000000) +#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) +#define INADDR_NONE ((in_addr_t) 0xffffffff) +#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) + uint32_t htonl(uint32_t); uint16_t htons(uint16_t); uint32_t ntohl(uint32_t); diff --git a/ulib/axlibc/include/pwd.h b/ulib/axlibc/include/pwd.h index 6d6c647ef..809a46daf 100644 --- a/ulib/axlibc/include/pwd.h +++ b/ulib/axlibc/include/pwd.h @@ -38,6 +38,12 @@ #define REQKEYLEN 2 #define REQ_LEN 3 +#define AX_DEFAULT_USER "root" +#define AX_DEFAULT_GROUP "root" +#define AX_DEFAULT_PASS "" +#define AX_DEFAULT_UID 0 +#define AX_DEFAULT_GID 0 + struct passwd { char *pw_name; char *pw_passwd; @@ -51,4 +57,6 @@ struct passwd { int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **); int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **); +struct passwd *getpwnam (const char *); + #endif // _PWD_H diff --git a/ulib/axlibc/include/sched.h b/ulib/axlibc/include/sched.h index b98ef7a30..4f09cfeb5 100644 --- a/ulib/axlibc/include/sched.h +++ b/ulib/axlibc/include/sched.h @@ -57,4 +57,6 @@ typedef struct cpu_set_t { int sched_setaffinity(pid_t, size_t, const cpu_set_t *); +int sched_yield(void); + #endif // _SCHED_H diff --git a/ulib/axlibc/include/semaphore.h b/ulib/axlibc/include/semaphore.h new file mode 100644 index 000000000..f204b0472 --- /dev/null +++ b/ulib/axlibc/include/semaphore.h @@ -0,0 +1,40 @@ +#ifndef _SEMAPHORE_H +#define _SEMAPHORE_H +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define __NEED_time_t +#define __NEED_struct_timespec +#include + +#include +#include + +#define SEM_FAILED ((sem_t *)0) + +typedef struct { + volatile int __val[4*sizeof(long)/sizeof(int)]; +} sem_t; + +int sem_close(sem_t *); +int sem_destroy(sem_t *); +int sem_getvalue(sem_t *__restrict, int *__restrict); +int sem_init(sem_t *, int, unsigned); +sem_t *sem_open(const char *, int, ...); +int sem_post(sem_t *); +int sem_timedwait(sem_t *__restrict, const struct timespec *__restrict); +int sem_trywait(sem_t *); +int sem_unlink(const char *); +int sem_wait(sem_t *); + +#if _REDIR_TIME64 +__REDIR(sem_timedwait, __sem_timedwait_time64); +#endif + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/signal.h b/ulib/axlibc/include/signal.h index cda590492..343ae6973 100644 --- a/ulib/axlibc/include/signal.h +++ b/ulib/axlibc/include/signal.h @@ -176,6 +176,8 @@ struct sigaction { #define sa_handler __sa_handler.sa_handler #define sa_sigaction __sa_handler.sa_sigaction +int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); +int sigsuspend(const sigset_t *); void (*signal(int, void (*)(int)))(int); int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); int sigemptyset(sigset_t *); diff --git a/ulib/axlibc/include/stdlib.h b/ulib/axlibc/include/stdlib.h index 284863044..2bb2bac4e 100644 --- a/ulib/axlibc/include/stdlib.h +++ b/ulib/axlibc/include/stdlib.h @@ -23,6 +23,9 @@ #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 +int posix_memalign (void **, size_t, size_t); +char *realpath (const char *__restrict, char *__restrict); + long long atoll(const char *nptr); float strtof(const char *__restrict, char **__restrict); diff --git a/ulib/axlibc/include/sys/eventfd.h b/ulib/axlibc/include/sys/eventfd.h new file mode 100644 index 000000000..be766ae27 --- /dev/null +++ b/ulib/axlibc/include/sys/eventfd.h @@ -0,0 +1,26 @@ +#ifndef _SYS_EVENTFD_H +#define _SYS_EVENTFD_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef uint64_t eventfd_t; + +#define EFD_SEMAPHORE 1 +#define EFD_CLOEXEC O_CLOEXEC +#define EFD_NONBLOCK O_NONBLOCK + +int eventfd(unsigned int, int); +int eventfd_read(int, eventfd_t *); +int eventfd_write(int, eventfd_t); + + +#ifdef __cplusplus +} +#endif + +#endif /* sys/eventfd.h */ \ No newline at end of file diff --git a/ulib/axlibc/include/sys/ioctl.h b/ulib/axlibc/include/sys/ioctl.h index 374b8215b..458b52335 100644 --- a/ulib/axlibc/include/sys/ioctl.h +++ b/ulib/axlibc/include/sys/ioctl.h @@ -10,6 +10,8 @@ #ifndef __SYS_IOCTL_H__ #define __SYS_IOCTL_H__ +#define FIOASYNC 0x5452 + #define TCGETS 0x5401 #define TCSETS 0x5402 #define TCSETSW 0x5403 diff --git a/ulib/axlibc/include/sys/prctl.h b/ulib/axlibc/include/sys/prctl.h index 98ad279aa..df3f4c8b4 100644 --- a/ulib/axlibc/include/sys/prctl.h +++ b/ulib/axlibc/include/sys/prctl.h @@ -10,4 +10,8 @@ #ifndef _SYS_PRCTL_H #define _SYS_PRCTL_H +#define PR_SET_DUMPABLE 4 + +int prctl (int, ...); + #endif // _SYS_PRCTL_H diff --git a/ulib/axlibc/include/sys/resource.h b/ulib/axlibc/include/sys/resource.h index f0709f98b..905c162bf 100644 --- a/ulib/axlibc/include/sys/resource.h +++ b/ulib/axlibc/include/sys/resource.h @@ -10,7 +10,9 @@ #ifndef _SYS_RESOURCE_H #define _SYS_RESOURCE_H +#define __NEED_id_t #include +#include typedef unsigned long long rlim_t; @@ -19,6 +21,10 @@ struct rlimit { rlim_t rlim_max; }; +#define PRIO_PROCESS 0 +#define PRIO_PGRP 1 +#define PRIO_USER 2 + #define RLIMIT_CPU 0 #define RLIMIT_FSIZE 1 #define RLIMIT_DATA 2 @@ -69,4 +75,6 @@ int getrlimit(int __resource, struct rlimit *__rlimits); int getrusage(int __who, struct rusage *__usage); +int setpriority (int, id_t, int); + #endif diff --git a/ulib/axlibc/include/sys/sendfile.h b/ulib/axlibc/include/sys/sendfile.h new file mode 100644 index 000000000..643ab6e84 --- /dev/null +++ b/ulib/axlibc/include/sys/sendfile.h @@ -0,0 +1,22 @@ +#ifndef _SYS_SENDFILE_H +#define _SYS_SENDFILE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +ssize_t sendfile(int, int, off_t *, size_t); + +#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) +#define sendfile64 sendfile +#define off64_t off_t +#endif + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/sys/socket.h b/ulib/axlibc/include/sys/socket.h index e558c6307..2f9c45fa3 100644 --- a/ulib/axlibc/include/sys/socket.h +++ b/ulib/axlibc/include/sys/socket.h @@ -77,6 +77,7 @@ ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_ ssize_t recvfrom(int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); ssize_t sendmsg(int, const struct msghdr *, int); +ssize_t recvmsg (int, struct msghdr *, int); int getsockopt(int, int, int, void *__restrict, socklen_t *__restrict); int setsockopt(int, int, int, const void *, socklen_t); @@ -84,6 +85,18 @@ int setsockopt(int, int, int, const void *, socklen_t); int getsockname(int sockfd, struct sockaddr *restrict addr, socklen_t *restrict addrlen); int getpeername(int sockfd, struct sockaddr *restrict addr, socklen_t *restrict addrlen); +int socketpair (int, int, int, int [2]); + +#define SCM_RIGHTS 0x01 +#define SCM_CREDENTIALS 0x02 + +#define MSG_OOB 0x0001 +#define MSG_PEEK 0x0002 +#define MSG_DONTROUTE 0x0004 +#define MSG_CTRUNC 0x0008 +#define MSG_PROXY 0x0010 +#define MSG_TRUNC 0x0020 + #define SO_BINDTODEVICE 25 #define SO_ATTACH_FILTER 26 #define SO_DETACH_FILTER 27 @@ -329,4 +342,9 @@ int getpeername(int sockfd, struct sockaddr *restrict addr, socklen_t *restrict #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) #define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) + +struct linger { + int l_onoff; + int l_linger; +}; #endif // __SOCKET_H__ diff --git a/ulib/axlibc/include/sys/stat.h b/ulib/axlibc/include/sys/stat.h index f73d2a3fd..a062629c3 100644 --- a/ulib/axlibc/include/sys/stat.h +++ b/ulib/axlibc/include/sys/stat.h @@ -25,9 +25,9 @@ struct stat { off_t st_size; /* total size, in bytes*/ blksize_t st_blksize; /* blocksize for filesystem I/O*/ blkcnt_t st_blocks; /* number of blocks allocated*/ - struct timespec st_atime; /* time of last access*/ - struct timespec st_mtime; /* time of last modification*/ - struct timespec st_ctime; /* time of last status change*/ + struct timespec st_atim; /* time of last access*/ + struct timespec st_mtim; /* time of last modification*/ + struct timespec st_ctim; /* time of last status change*/ }; #if defined(__aarch64__) diff --git a/ulib/axlibc/include/sys/statfs.h b/ulib/axlibc/include/sys/statfs.h new file mode 100644 index 000000000..cdc9e5419 --- /dev/null +++ b/ulib/axlibc/include/sys/statfs.h @@ -0,0 +1,32 @@ +#ifndef _SYS_STATFS_H +#define _SYS_STATFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +typedef struct __fsid_t { + int __val[2]; +} fsid_t; + +#include + +int statfs (const char *, struct statfs *); +int fstatfs (int, struct statfs *); + +#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) +#define statfs64 statfs +#define fstatfs64 fstatfs +#define fsblkcnt64_t fsblkcnt_t +#define fsfilcnt64_t fsfilcnt_t +#endif + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/sys/statvfs.h b/ulib/axlibc/include/sys/statvfs.h new file mode 100644 index 000000000..0da838f1e --- /dev/null +++ b/ulib/axlibc/include/sys/statvfs.h @@ -0,0 +1,56 @@ +#ifndef _SYS_STATVFS_H +#define _SYS_STATVFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define __NEED_fsblkcnt_t +#define __NEED_fsfilcnt_t +#include + +struct statvfs { + unsigned long f_bsize, f_frsize; + fsblkcnt_t f_blocks, f_bfree, f_bavail; + fsfilcnt_t f_files, f_ffree, f_favail; +#if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned long f_fsid; + unsigned :8*(2*sizeof(int)-sizeof(long)); +#else + unsigned :8*(2*sizeof(int)-sizeof(long)); + unsigned long f_fsid; +#endif + unsigned long f_flag, f_namemax; + int __reserved[6]; +}; + +int statvfs (const char *__restrict, struct statvfs *__restrict); +int fstatvfs (int, struct statvfs *); + +#define ST_RDONLY 1 +#define ST_NOSUID 2 +#define ST_NODEV 4 +#define ST_NOEXEC 8 +#define ST_SYNCHRONOUS 16 +#define ST_MANDLOCK 64 +#define ST_WRITE 128 +#define ST_APPEND 256 +#define ST_IMMUTABLE 512 +#define ST_NOATIME 1024 +#define ST_NODIRATIME 2048 +#define ST_RELATIME 4096 + +#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) +#define statvfs64 statvfs +#define fstatvfs64 fstatvfs +#define fsblkcnt64_t fsblkcnt_t +#define fsfilcnt64_t fsfilcnt_t +#endif + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/sys/syscall.h b/ulib/axlibc/include/sys/syscall.h new file mode 100644 index 000000000..280614bcb --- /dev/null +++ b/ulib/axlibc/include/sys/syscall.h @@ -0,0 +1,6 @@ +#ifndef _SYS_SYSCALL_H +#define _SYS_SYSCALL_H + +#include + +#endif \ No newline at end of file diff --git a/ulib/axlibc/include/sys/types.h b/ulib/axlibc/include/sys/types.h index 1020f1cfe..658306afa 100644 --- a/ulib/axlibc/include/sys/types.h +++ b/ulib/axlibc/include/sys/types.h @@ -12,7 +12,11 @@ #include +typedef char *caddr_t; typedef unsigned char u_char; +typedef unsigned short u_short, ushort; +typedef unsigned u_int, uint; +typedef unsigned long u_long, ulong; typedef unsigned mode_t; typedef uint32_t nlink_t; diff --git a/ulib/axlibc/include/sys/uio.h b/ulib/axlibc/include/sys/uio.h index 27a0a0902..66d837253 100644 --- a/ulib/axlibc/include/sys/uio.h +++ b/ulib/axlibc/include/sys/uio.h @@ -18,5 +18,6 @@ struct iovec { }; ssize_t writev(int, const struct iovec *, int); +ssize_t readv (int, const struct iovec *, int); #endif diff --git a/ulib/axlibc/include/sys/vfs.h b/ulib/axlibc/include/sys/vfs.h new file mode 100644 index 000000000..31991ede6 --- /dev/null +++ b/ulib/axlibc/include/sys/vfs.h @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/ulib/axlibc/include/time.h b/ulib/axlibc/include/time.h index 3103f3893..42be6c067 100644 --- a/ulib/axlibc/include/time.h +++ b/ulib/axlibc/include/time.h @@ -18,6 +18,8 @@ #define CLOCK_MONOTONIC 1 #define CLOCKS_PER_SEC 1000000L +#define __tm_gmtoff tm_gmtoff + struct tm { int tm_sec; /* seconds of minute */ int tm_min; /* minutes of hour */ diff --git a/ulib/axlibc/include/unistd.h b/ulib/axlibc/include/unistd.h index 288f4a91b..235a8285c 100644 --- a/ulib/axlibc/include/unistd.h +++ b/ulib/axlibc/include/unistd.h @@ -24,6 +24,9 @@ #define SEEK_DATA 3 #define SEEK_HOLE 4 +int getpagesize(void); +int gethostname(char *, size_t); + int pipe(int[2]); int pipe2(int[2], int); int close(int); diff --git a/ulib/axlibc/src/io.rs b/ulib/axlibc/src/io.rs index f3bdfd7cf..a21825f19 100644 --- a/ulib/axlibc/src/io.rs +++ b/ulib/axlibc/src/io.rs @@ -16,6 +16,8 @@ use crate::{ctypes, utils::e}; /// Read data from the file indicated by `fd`. /// /// Return the read size if success. +#[cfg(feature = "fd")] +use arceos_posix_api::sys_ioctl; #[no_mangle] pub unsafe extern "C" fn read(fd: c_int, buf: *mut c_void, count: usize) -> ctypes::ssize_t { e(sys_read(fd, buf, count) as _) as _ @@ -39,3 +41,12 @@ pub unsafe extern "C" fn writev( ) -> ctypes::ssize_t { e(sys_writev(fd, iov, iocnt) as _) as _ } + +/// Manipulate file descriptor. +/// +/// TODO: `SET/GET` command is ignored +#[cfg(feature = "fd")] +#[no_mangle] +pub unsafe extern "C" fn ax_ioctl(fd: c_int, req: c_int, arg: usize) -> c_int { + e(sys_ioctl(fd, req.try_into().unwrap(), arg)) +}