From 00b31986fb658ebd9a4693214544ad743e5fff0f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 7 Oct 2025 13:51:51 +0200 Subject: [PATCH 01/69] Add 'writev' syscall Signed-off-by: Jean-Pierre Miceli --- so3/arch/arm32/include/asm/syscall_number.h | 2 + so3/arch/arm64/include/asm/syscall_number.h | 2 + so3/devices/serial/pl011.c | 2 +- so3/fs/elf.c | 8 +-- so3/fs/vfs.c | 69 ++++++++++++++------- so3/include/net/lwip/sockets.h | 12 ++-- so3/include/syscall.h | 10 +-- so3/include/vfs.h | 6 ++ so3/kernel/process.c | 4 +- so3/kernel/syscalls.c | 1 + so3/kernel/thread.c | 2 +- so3/net/net.c | 4 +- 12 files changed, 80 insertions(+), 42 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 7474f8f2e..3a5167332 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -78,4 +78,6 @@ #define SYSCALL_SETSOCKOPT 110 #define SYSCALL_RECVFROM 111 +#define SYSCALL_WRITEV 146 + #endif /* ARCH_ARM32_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index d81a0858a..c443e2fae 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -71,6 +71,8 @@ #define SYSCALL_MUTEX_LOCK 60 #define SYSCALL_MUTEX_UNLOCK 61 +#define SYSCALL_WRITEV 66 + #define SYSCALL_NANOSLEEP 70 #define SYSCALL_SYSINFO 99 diff --git a/so3/devices/serial/pl011.c b/so3/devices/serial/pl011.c index 6bd6bee18..4e3f101bd 100644 --- a/so3/devices/serial/pl011.c +++ b/so3/devices/serial/pl011.c @@ -119,7 +119,7 @@ static irq_return_t pl011_int(int irq, void *dummy) #ifdef CONFIG_IPC_SIGNAL if (current()->pcb != NULL) - do_kill(current()->pcb->pid, SIGINT); + __do_kill(current()->pcb->pid, SIGINT); #endif } diff --git a/so3/fs/elf.c b/so3/fs/elf.c index dce824587..cc2965c2c 100644 --- a/so3/fs/elf.c +++ b/so3/fs/elf.c @@ -35,12 +35,12 @@ uint8_t *elf_load_buffer(const char *filename) struct stat st; /* open and read file */ - fd = do_open(filename, O_RDONLY); + fd = __do_open(filename, O_RDONLY); if (fd < 0) return NULL; - if (do_stat(filename, &st)) + if (__do_stat(filename, &st)) return NULL; if (!st.st_size) @@ -52,9 +52,9 @@ uint8_t *elf_load_buffer(const char *filename) return NULL; } - do_read(fd, buffer, st.st_size); + __do_read(fd, buffer, st.st_size); - do_close(fd); + __do_close(fd); return buffer; } diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 3f1ac96a2..fc06f015b 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -380,7 +380,8 @@ int vfs_clone_fd(int *fd_src, int *fd_dst) /**************************** Syscall implementation ****************************/ -SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) +/* Low Level write */ +static int do_write(int fd, const void *buffer, int count) { int gfd; int ret; @@ -395,6 +396,11 @@ SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) gfd = vfs_get_gfd(fd); + if (!vfs_is_valid_gfd(gfd)) { + mutex_unlock(&vfs_lock); + return -EINVAL; + } + /* FIXME: As for now the do_read/do_open only * support regular file VFS_TYPE_FILE, VFS_TYPE_IO and pipes */ @@ -403,28 +409,19 @@ SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) return -EISDIR; } - if (!vfs_is_valid_gfd(gfd)) { - mutex_unlock(&vfs_lock); - return -EINVAL; - } - - if (!open_fds[gfd]->fops->read) { - LOG_ERROR("No fops read\n"); + if (!open_fds[gfd]->fops->write) { mutex_unlock(&vfs_lock); return -EBADF; } mutex_unlock(&vfs_lock); - ret = open_fds[gfd]->fops->read(gfd, buffer, count); + ret = open_fds[gfd]->fops->write(gfd, buffer, count); return ret; } -/** - * @brief This function writes a REGULAR FILE/FOLDER. It only support regular file, dirs and pipes - */ -SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) +SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) { int gfd; int ret; @@ -439,11 +436,6 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) gfd = vfs_get_gfd(fd); - if (!vfs_is_valid_gfd(gfd)) { - mutex_unlock(&vfs_lock); - return -EINVAL; - } - /* FIXME: As for now the do_read/do_open only * support regular file VFS_TYPE_FILE, VFS_TYPE_IO and pipes */ @@ -452,18 +444,32 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) return -EISDIR; } - if (!open_fds[gfd]->fops->write) { + if (!vfs_is_valid_gfd(gfd)) { + mutex_unlock(&vfs_lock); + return -EINVAL; + } + + if (!open_fds[gfd]->fops->read) { + LOG_ERROR("No fops read\n"); mutex_unlock(&vfs_lock); return -EBADF; } mutex_unlock(&vfs_lock); - ret = open_fds[gfd]->fops->write(gfd, buffer, count); + ret = open_fds[gfd]->fops->read(gfd, buffer, count); return ret; } +/** + * @brief This function writes a REGULAR FILE/FOLDER. It only support regular file, dirs and pipes + */ +SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) +{ + return do_write(fd, buffer, count); +} + /** * @brief This function opens a file. Not all file types are supported. */ @@ -655,7 +661,7 @@ SYSCALL_DEFINE2(dup2, int, oldfd, int, newfd) } if (vfs_get_gfd(oldfd) != vfs_get_gfd(newfd)) - do_close(newfd); + __do_close(newfd); vfs_link_fd(newfd, vfs_get_gfd(oldfd)); @@ -824,6 +830,27 @@ SYSCALL_DEFINE3(fcntl, int, fd, unsigned long, cmd, unsigned long, args) return 0; } +/* + * Implementation of the writev syscall + */ +SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned long, vlen) +{ + int i; + int ret = -1; + int total = 0; + + for (i = 0; i < vlen; i++) { + ret = do_write(fd, (const void *)vec[i].iov_base, vec[i].iov_len); + if (ret < 0) + break; + + total += ret; + } + + return total; +} + + static void vfs_gfd_init(void) { memset(open_fds, 0, MAX_FDS * sizeof(struct fd *)); diff --git a/so3/include/net/lwip/sockets.h b/so3/include/net/lwip/sockets.h index afe097b42..5ea356ca8 100644 --- a/so3/include/net/lwip/sockets.h +++ b/so3/include/net/lwip/sockets.h @@ -123,12 +123,12 @@ typedef u32_t socklen_t; #error "IOV_MAX larger than supported by LwIP" #endif /* IOV_MAX */ -#if !defined(iovec) -struct iovec { - void *iov_base; - size_t iov_len; -}; -#endif +// #if !defined(iovec) +// struct iovec { +// void *iov_base; +// size_t iov_len; +// }; +// #endif typedef int msg_iovlen_t; diff --git a/so3/include/syscall.h b/so3/include/syscall.h index eaf3ed73b..68231865e 100644 --- a/so3/include/syscall.h +++ b/so3/include/syscall.h @@ -90,14 +90,14 @@ */ #define SYSCALL_DECLARE(name, ...) \ long __sys_##name(syscall_args_t *args); \ - inline long do_##name(__VA_ARGS__); + inline long __do_##name(__VA_ARGS__); #define SYSCALL_DEFINE0(name) \ long __sys_##name(syscall_args_t *unused) \ { \ - return do_##name(); \ + return __do_##name(); \ } \ - inline long do_##name(void) + inline long __do_##name(void) #define SYSCALL_DEFINE1(...) __SYSCALL_DEFINEx(1, __VA_ARGS__) #define SYSCALL_DEFINE2(...) __SYSCALL_DEFINEx(2, __VA_ARGS__) #define SYSCALL_DEFINE3(...) __SYSCALL_DEFINEx(3, __VA_ARGS__) @@ -108,9 +108,9 @@ #define __SYSCALL_DEFINEx(x, name, ...) \ long __sys_##name(syscall_args_t *args) \ { \ - return do_##name(__MAP_ARGS(x, args->args, __VA_ARGS__)); \ + return __do_##name(__MAP_ARGS(x, args->args, __VA_ARGS__)); \ } \ - inline long do_##name(__MAP(x, __M_DECL, __VA_ARGS__)) + inline long __do_##name(__MAP(x, __M_DECL, __VA_ARGS__)) typedef struct { unsigned long args[6]; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index a6956db23..e30837a3b 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -103,6 +103,11 @@ #include +struct iovec { + void *iov_base; + size_t iov_len; +}; + struct file_operations { int (*open)(int fd, const char *path); int (*close)(int fd); @@ -162,6 +167,7 @@ SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int fd, off_t offse SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(fcntl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); +SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); /* VFS common interface */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index bc065224a..a5e4d471a 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -925,7 +925,7 @@ SYSCALL_DEFINE1(exit, int, exit_status) * locking in the low layers. */ for (i = 0; i < FD_MAX; i++) - do_close(i); + __do_close(i); local_irq_disable(); @@ -944,7 +944,7 @@ SYSCALL_DEFINE1(exit, int, exit_status) #ifdef CONFIG_IPC_SIGNAL /* Send the SIGCHLD signal to the parent */ - do_kill(pcb->parent->pid, SIGCHLD); + __do_kill(pcb->parent->pid, SIGCHLD); #endif /* CONFIG_IPC_SIGNAL */ diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 4c61b0b16..7367092f4 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -60,6 +60,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_IOCTL] = __sys_ioctl, [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, + [SYSCALL_WRITEV] = __sys_writev, #ifdef CONFIG_IPC_PIPE [SYSCALL_PIPE] = __sys_pipe, #endif diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 868c31835..17faefed0 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -272,7 +272,7 @@ void thread_exit(int *exit_status) remove_tcb_from_pcb(current()); #ifdef CONFIG_PROC_ENV - do_exit(0); + __do_exit(0); #endif } else { diff --git a/so3/net/net.c b/so3/net/net.c index 7ca28cb3f..19c006efb 100644 --- a/so3/net/net.c +++ b/so3/net/net.c @@ -413,7 +413,7 @@ SYSCALL_DEFINE3(socket, int, domain, int, type, int, protocol) lwip_fd = lwip_socket(domain, type, protocol); if (lwip_fd < 0) { - do_close(fd); + __do_close(fd); return lwip_return(lwip_fd); } @@ -505,7 +505,7 @@ SYSCALL_DEFINE3(accept, int, sockfd, struct sockaddr *, addr, socklen_t *, addrl lwip_bind_fd = lwip_accept(lwip_fd, addr_ptr, addrlen); if (lwip_bind_fd < 0) { - do_close(fd); + __do_close(fd); return lwip_return(lwip_bind_fd); } From cdaaf6d28d15964205555dd51bf008248229a69b Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 7 Oct 2025 14:14:48 +0200 Subject: [PATCH 02/69] writev - Fix error in error case Signed-off-by: Jean-Pierre Miceli --- so3/fs/vfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index fc06f015b..2d3d364e9 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -836,13 +836,17 @@ SYSCALL_DEFINE3(fcntl, int, fd, unsigned long, cmd, unsigned long, args) SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned long, vlen) { int i; - int ret = -1; + int ret; int total = 0; for (i = 0; i < vlen; i++) { ret = do_write(fd, (const void *)vec[i].iov_base, vec[i].iov_len); - if (ret < 0) + if (ret < 0) { + /* Error on the fist loop --> return error code */ + if (i == 0) + total = -1; break; + } total += ret; } @@ -850,7 +854,6 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned l return total; } - static void vfs_gfd_init(void) { memset(open_fds, 0, MAX_FDS * sizeof(struct fd *)); From 99a14299e688d4780cdb36af4f81955fa9e591c7 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 7 Oct 2025 17:51:57 +0200 Subject: [PATCH 03/69] Add 'readv' syscall Signed-off-by: Jean-Pierre Miceli --- so3/arch/arm32/include/asm/syscall_number.h | 1 + so3/arch/arm64/include/asm/syscall_number.h | 1 + so3/fs/vfs.c | 66 +++++++++++++++++++++ so3/include/vfs.h | 1 + 4 files changed, 69 insertions(+) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 3a5167332..1da6a2f71 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -78,6 +78,7 @@ #define SYSCALL_SETSOCKOPT 110 #define SYSCALL_RECVFROM 111 +#define SYSCALL_READV 145 #define SYSCALL_WRITEV 146 #endif /* ARCH_ARM32_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index c443e2fae..a91dd9e65 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -71,6 +71,7 @@ #define SYSCALL_MUTEX_LOCK 60 #define SYSCALL_MUTEX_UNLOCK 61 +#define SYSCALL_READV 66 #define SYSCALL_WRITEV 66 #define SYSCALL_NANOSLEEP 70 diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 2d3d364e9..772ec6207 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -380,6 +380,50 @@ int vfs_clone_fd(int *fd_src, int *fd_dst) /**************************** Syscall implementation ****************************/ +/* Low Level read */ +static int do_read(int fd, void *buffer, int count) +{ + int gfd; + int ret; + + /* FIXME Max size of buffer */ + if (!buffer || count < 0) { + LOG_ERROR("Invalid inputs\n"); + return -EINVAL; + } + + mutex_lock(&vfs_lock); + + gfd = vfs_get_gfd(fd); + + /* FIXME: As for now the do_read/do_open only + * support regular file VFS_TYPE_FILE, VFS_TYPE_IO and pipes + */ + if (open_fds[gfd]->type == VFS_TYPE_DIR) { + mutex_unlock(&vfs_lock); + return -EISDIR; + } + + if (!vfs_is_valid_gfd(gfd)) { + mutex_unlock(&vfs_lock); + return -EINVAL; + } + + if (!open_fds[gfd]->fops->read) { + LOG_ERROR("No fops read\n"); + mutex_unlock(&vfs_lock); + return -EBADF; + } + + mutex_unlock(&vfs_lock); + + ret = open_fds[gfd]->fops->read(gfd, buffer, count); + + return ret; +} + + + /* Low Level write */ static int do_write(int fd, const void *buffer, int count) { @@ -854,6 +898,28 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned l return total; } +SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec *, vec, + unsigned long, vlen) +{ + int i; + int ret; + int total = 0; + + for (i = 0; i < vlen; i++) { + ret = do_read(fd, vec[i].iov_base, vec[i].iov_len); + if (ret < 0) { + /* Error on the fist loop --> return error code */ + if (i == 0) + total = -1; + break; + } + + total += ret; + } + + return total; +} + static void vfs_gfd_init(void) { memset(open_fds, 0, MAX_FDS * sizeof(struct fd *)); diff --git a/so3/include/vfs.h b/so3/include/vfs.h index e30837a3b..745dd7335 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -168,6 +168,7 @@ SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(fcntl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); +SYSCALL_DECLARE(readv, unsigned long fd, const struct iovec *vec, unsigned long vlen); /* VFS common interface */ From 291932167931ea421f07f5ecfd9ac5dc0512643e Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 8 Oct 2025 16:16:08 +0200 Subject: [PATCH 04/69] [syscall] Update readv & writev from comments in MR #207 Signed-off-by: Jean-Pierre Miceli --- so3/arch/arm64/include/asm/syscall_number.h | 2 +- so3/devices/serial/pl011.c | 2 +- so3/fs/elf.c | 8 +-- so3/fs/vfs.c | 63 ++++++--------------- so3/include/net/lwip/sockets.h | 12 ++-- so3/include/syscall.h | 12 ++-- so3/include/vfs.h | 3 + so3/kernel/process.c | 4 +- so3/kernel/syscalls.c | 1 + so3/kernel/thread.c | 2 +- so3/net/net.c | 4 +- 11 files changed, 44 insertions(+), 69 deletions(-) diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index a91dd9e65..2cbbea82d 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -71,7 +71,7 @@ #define SYSCALL_MUTEX_LOCK 60 #define SYSCALL_MUTEX_UNLOCK 61 -#define SYSCALL_READV 66 +#define SYSCALL_READV 65 #define SYSCALL_WRITEV 66 #define SYSCALL_NANOSLEEP 70 diff --git a/so3/devices/serial/pl011.c b/so3/devices/serial/pl011.c index 4e3f101bd..601be88f2 100644 --- a/so3/devices/serial/pl011.c +++ b/so3/devices/serial/pl011.c @@ -119,7 +119,7 @@ static irq_return_t pl011_int(int irq, void *dummy) #ifdef CONFIG_IPC_SIGNAL if (current()->pcb != NULL) - __do_kill(current()->pcb->pid, SIGINT); + sys_do_kill(current()->pcb->pid, SIGINT); #endif } diff --git a/so3/fs/elf.c b/so3/fs/elf.c index cc2965c2c..0489e7de5 100644 --- a/so3/fs/elf.c +++ b/so3/fs/elf.c @@ -35,12 +35,12 @@ uint8_t *elf_load_buffer(const char *filename) struct stat st; /* open and read file */ - fd = __do_open(filename, O_RDONLY); + fd = sys_do_open(filename, O_RDONLY); if (fd < 0) return NULL; - if (__do_stat(filename, &st)) + if (sys_do_stat(filename, &st)) return NULL; if (!st.st_size) @@ -52,9 +52,9 @@ uint8_t *elf_load_buffer(const char *filename) return NULL; } - __do_read(fd, buffer, st.st_size); + sys_do_read(fd, buffer, st.st_size); - __do_close(fd); + sys_do_close(fd); return buffer; } diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 772ec6207..2f5343e20 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -467,43 +467,7 @@ static int do_write(int fd, const void *buffer, int count) SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) { - int gfd; - int ret; - - /* FIXME Max size of buffer */ - if (!buffer || count < 0) { - LOG_ERROR("Invalid inputs\n"); - return -EINVAL; - } - - mutex_lock(&vfs_lock); - - gfd = vfs_get_gfd(fd); - - /* FIXME: As for now the do_read/do_open only - * support regular file VFS_TYPE_FILE, VFS_TYPE_IO and pipes - */ - if (open_fds[gfd]->type == VFS_TYPE_DIR) { - mutex_unlock(&vfs_lock); - return -EISDIR; - } - - if (!vfs_is_valid_gfd(gfd)) { - mutex_unlock(&vfs_lock); - return -EINVAL; - } - - if (!open_fds[gfd]->fops->read) { - LOG_ERROR("No fops read\n"); - mutex_unlock(&vfs_lock); - return -EBADF; - } - - mutex_unlock(&vfs_lock); - - ret = open_fds[gfd]->fops->read(gfd, buffer, count); - - return ret; + return do_read(fd, buffer, count); } /** @@ -705,7 +669,7 @@ SYSCALL_DEFINE2(dup2, int, oldfd, int, newfd) } if (vfs_get_gfd(oldfd) != vfs_get_gfd(newfd)) - __do_close(newfd); + sys_do_close(newfd); vfs_link_fd(newfd, vfs_get_gfd(oldfd)); @@ -885,17 +849,21 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned l for (i = 0; i < vlen; i++) { ret = do_write(fd, (const void *)vec[i].iov_base, vec[i].iov_len); + ret = do_read(fd, vec[i].iov_base, vec[i].iov_len); if (ret < 0) { - /* Error on the fist loop --> return error code */ - if (i == 0) - total = -1; + break; + } else if ((ret >= 0) && (ret < vec[i].iov_len)) { + total += ret; break; } total += ret; } - return total; + if (total == 0) + return ret; + else + return total; } SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec *, vec, @@ -908,16 +876,19 @@ SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec *, vec, for (i = 0; i < vlen; i++) { ret = do_read(fd, vec[i].iov_base, vec[i].iov_len); if (ret < 0) { - /* Error on the fist loop --> return error code */ - if (i == 0) - total = -1; + break; + } else if ((ret >= 0) && (ret < vec[i].iov_len)) { + total += ret; break; } total += ret; } - return total; + if (total == 0) + return ret; + else + return total; } static void vfs_gfd_init(void) diff --git a/so3/include/net/lwip/sockets.h b/so3/include/net/lwip/sockets.h index 5ea356ca8..afe097b42 100644 --- a/so3/include/net/lwip/sockets.h +++ b/so3/include/net/lwip/sockets.h @@ -123,12 +123,12 @@ typedef u32_t socklen_t; #error "IOV_MAX larger than supported by LwIP" #endif /* IOV_MAX */ -// #if !defined(iovec) -// struct iovec { -// void *iov_base; -// size_t iov_len; -// }; -// #endif +#if !defined(iovec) +struct iovec { + void *iov_base; + size_t iov_len; +}; +#endif typedef int msg_iovlen_t; diff --git a/so3/include/syscall.h b/so3/include/syscall.h index 68231865e..2ddfbd18e 100644 --- a/so3/include/syscall.h +++ b/so3/include/syscall.h @@ -84,20 +84,20 @@ * __sys_SYSCALL_NAME taking syscall_args_t as arguments allowing for * a common interface between all syscall to put them in an array. * - * do_SYSCALL_NAME actual function with the syscall implementation with + * sys_do_SYSCALL_NAME actual function with the syscall implementation with * arguments define like a normal function. That function is automatically * called by __sys_SYCALL_NAME with the correct argument number and cast. */ #define SYSCALL_DECLARE(name, ...) \ long __sys_##name(syscall_args_t *args); \ - inline long __do_##name(__VA_ARGS__); + inline long sys_do_##name(__VA_ARGS__); #define SYSCALL_DEFINE0(name) \ long __sys_##name(syscall_args_t *unused) \ { \ - return __do_##name(); \ + return sys_do_##name(); \ } \ - inline long __do_##name(void) + inline long sys_do_##name(void) #define SYSCALL_DEFINE1(...) __SYSCALL_DEFINEx(1, __VA_ARGS__) #define SYSCALL_DEFINE2(...) __SYSCALL_DEFINEx(2, __VA_ARGS__) #define SYSCALL_DEFINE3(...) __SYSCALL_DEFINEx(3, __VA_ARGS__) @@ -108,9 +108,9 @@ #define __SYSCALL_DEFINEx(x, name, ...) \ long __sys_##name(syscall_args_t *args) \ { \ - return __do_##name(__MAP_ARGS(x, args->args, __VA_ARGS__)); \ + return sys_do_##name(__MAP_ARGS(x, args->args, __VA_ARGS__)); \ } \ - inline long __do_##name(__MAP(x, __M_DECL, __VA_ARGS__)) + inline long sys_do_##name(__MAP(x, __M_DECL, __VA_ARGS__)) typedef struct { unsigned long args[6]; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 745dd7335..671f80001 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -108,6 +108,9 @@ struct iovec { size_t iov_len; }; +#define iovec iovec + + struct file_operations { int (*open)(int fd, const char *path); int (*close)(int fd); diff --git a/so3/kernel/process.c b/so3/kernel/process.c index a5e4d471a..ff283bc79 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -925,7 +925,7 @@ SYSCALL_DEFINE1(exit, int, exit_status) * locking in the low layers. */ for (i = 0; i < FD_MAX; i++) - __do_close(i); + sys_do_close(i); local_irq_disable(); @@ -944,7 +944,7 @@ SYSCALL_DEFINE1(exit, int, exit_status) #ifdef CONFIG_IPC_SIGNAL /* Send the SIGCHLD signal to the parent */ - __do_kill(pcb->parent->pid, SIGCHLD); + sys_do_kill(pcb->parent->pid, SIGCHLD); #endif /* CONFIG_IPC_SIGNAL */ diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 7367092f4..68e15083f 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -60,6 +60,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_IOCTL] = __sys_ioctl, [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, + [SYSCALL_READV] = __sys_readv, [SYSCALL_WRITEV] = __sys_writev, #ifdef CONFIG_IPC_PIPE [SYSCALL_PIPE] = __sys_pipe, diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 17faefed0..363ec1520 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -272,7 +272,7 @@ void thread_exit(int *exit_status) remove_tcb_from_pcb(current()); #ifdef CONFIG_PROC_ENV - __do_exit(0); + sys_do_exit(0); #endif } else { diff --git a/so3/net/net.c b/so3/net/net.c index 19c006efb..d638f0797 100644 --- a/so3/net/net.c +++ b/so3/net/net.c @@ -413,7 +413,7 @@ SYSCALL_DEFINE3(socket, int, domain, int, type, int, protocol) lwip_fd = lwip_socket(domain, type, protocol); if (lwip_fd < 0) { - __do_close(fd); + sys_do_close(fd); return lwip_return(lwip_fd); } @@ -505,7 +505,7 @@ SYSCALL_DEFINE3(accept, int, sockfd, struct sockaddr *, addr, socklen_t *, addrl lwip_bind_fd = lwip_accept(lwip_fd, addr_ptr, addrlen); if (lwip_bind_fd < 0) { - __do_close(fd); + sys_do_close(fd); return lwip_return(lwip_bind_fd); } From 580e00fa5e6351328d6a8e6228b3e9bf777e6aba Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 9 Oct 2025 08:18:33 +0200 Subject: [PATCH 05/69] [syscall] readv & writev clean-up - MR #207 Signed-off-by: Jean-Pierre Miceli --- so3/fs/vfs.c | 12 ++++-------- so3/include/syscall.h | 10 +++++----- so3/include/vfs.h | 1 - 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 2f5343e20..1ba8de20f 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -422,8 +422,6 @@ static int do_read(int fd, void *buffer, int count) return ret; } - - /* Low Level write */ static int do_write(int fd, const void *buffer, int count) { @@ -844,12 +842,11 @@ SYSCALL_DEFINE3(fcntl, int, fd, unsigned long, cmd, unsigned long, args) SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned long, vlen) { int i; - int ret; + int ret = 0; int total = 0; for (i = 0; i < vlen; i++) { - ret = do_write(fd, (const void *)vec[i].iov_base, vec[i].iov_len); - ret = do_read(fd, vec[i].iov_base, vec[i].iov_len); + ret = do_write(fd, (const void *) vec[i].iov_base, vec[i].iov_len); if (ret < 0) { break; } else if ((ret >= 0) && (ret < vec[i].iov_len)) { @@ -866,11 +863,10 @@ SYSCALL_DEFINE3(writev, unsigned long, fd, const struct iovec *, vec, unsigned l return total; } -SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec *, vec, - unsigned long, vlen) +SYSCALL_DEFINE3(readv, unsigned long, fd, const struct iovec *, vec, unsigned long, vlen) { int i; - int ret; + int ret = 0; int total = 0; for (i = 0; i < vlen; i++) { diff --git a/so3/include/syscall.h b/so3/include/syscall.h index 2ddfbd18e..1c1031576 100644 --- a/so3/include/syscall.h +++ b/so3/include/syscall.h @@ -95,7 +95,7 @@ #define SYSCALL_DEFINE0(name) \ long __sys_##name(syscall_args_t *unused) \ { \ - return sys_do_##name(); \ + return sys_do_##name(); \ } \ inline long sys_do_##name(void) #define SYSCALL_DEFINE1(...) __SYSCALL_DEFINEx(1, __VA_ARGS__) @@ -105,11 +105,11 @@ #define SYSCALL_DEFINE5(...) __SYSCALL_DEFINEx(5, __VA_ARGS__) #define SYSCALL_DEFINE6(...) __SYSCALL_DEFINEx(6, __VA_ARGS__) -#define __SYSCALL_DEFINEx(x, name, ...) \ - long __sys_##name(syscall_args_t *args) \ - { \ +#define __SYSCALL_DEFINEx(x, name, ...) \ + long __sys_##name(syscall_args_t *args) \ + { \ return sys_do_##name(__MAP_ARGS(x, args->args, __VA_ARGS__)); \ - } \ + } \ inline long sys_do_##name(__MAP(x, __M_DECL, __VA_ARGS__)) typedef struct { diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 671f80001..b75836586 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -110,7 +110,6 @@ struct iovec { #define iovec iovec - struct file_operations { int (*open)(int fd, const char *path); int (*close)(int fd); From 0c97a7f604c61c56a9c86d9473e660ca62d9be2a Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 9 Oct 2025 08:21:26 +0200 Subject: [PATCH 06/69] Run format checking for branch 144-support-musl Signed-off-by: Jean-Pierre Miceli --- .github/workflows/style.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 770233583..3268b2146 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -10,7 +10,7 @@ on: push: branches: ["main"] pull_request: - branches: ["main"] + branches: ["main", "144-support-musl"] jobs: formatting-check: From 361ac6eb7550ad72f0e05e10263eb30972340aca Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 9 Oct 2025 11:34:34 +0200 Subject: [PATCH 07/69] [syscall] mmap: Add support for ANONYMOUS flag Signed-off-by: Jean-Pierre Miceli --- so3/arch/arm64/include/asm/mmu.h | 3 + so3/fs/vfs.c | 103 ++++++++++++++++++++++--------- so3/include/process.h | 3 + so3/include/vfs.h | 5 +- so3/kernel/process.c | 2 + 5 files changed, 87 insertions(+), 29 deletions(-) diff --git a/so3/arch/arm64/include/asm/mmu.h b/so3/arch/arm64/include/asm/mmu.h index e6e4d0ddb..337570160 100644 --- a/so3/arch/arm64/include/asm/mmu.h +++ b/so3/arch/arm64/include/asm/mmu.h @@ -35,6 +35,9 @@ /* Fixmap page used for temporary mapping */ #define FIXMAP_MAPPING UL(0xffffb00000000000) +/* Anonymous start virtual address */ +#define USER_ANONYMOUS_VADDR UL(0x0000000100000000) + /* The user space can be up to bits [47:0] and uses ttbr0_el1 * as main L0 page table. */ diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 1ba8de20f..54635bc34 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -463,6 +463,76 @@ static int do_write(int fd, const void *buffer, int count) return ret; } +/* Low Level mmap */ +static int do_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) +{ + int gfd; + struct file_operations *fops; + + /* Get the fops associated to the file descriptor. */ + gfd = vfs_get_gfd(fd); + if (-1 == gfd) { + printk("%s: could not get global fd.\n", __func__); + return -EBADF; + } + + mutex_lock(&vfs_lock); + fops = vfs_get_fops(gfd); + if (!fops) { + printk("%s: could not get device fops.\n", __func__); + mutex_unlock(&vfs_lock); + return -EBADF; + } + + mutex_unlock(&vfs_lock); + + if (!fops->mmap) { + printk("%s: device doesn't support mmap.\n", __func__); + return -EACCES; + } + + /* Call the mmap fops that will do the actual mapping. */ + return (long) fops->mmap(fd, virt_addr, page_count, offset); +} + + +/* Low Level mmap - Anonymous case */ +static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) +{ + uint32_t page; + pcb_t *pcb; + int i; + + if (offset != 0) { + printk("%s: Offset should be 0 with MAP_ANONYMOUS flag\n", __func__); + return -EINVAL; + } + + pcb = current()->pcb; + + /* Start is smaller or NULL than initial virt_addr pointer */ + if (virt_addr < pcb->next_anon_start) + virt_addr = pcb->next_anon_start; + + for (i = 0; i < page_count; i++) { + page = get_free_page(); + BUG_ON(!page); + + create_mapping(pcb->pgtable, virt_addr + (i * PAGE_SIZE), page, PAGE_SIZE, false); + add_page_to_proc(pcb, phys_to_page(page)); + } + + memset((void *)virt_addr, 0, page_count * PAGE_SIZE); + + /* WARNIMG - This is a simple/basic way to set the start virtual address: + It only increment the start address after each mmap call, no algorithm + to search for available spaces. + */ + pcb->next_anon_start = virt_addr + (page_count * PAGE_SIZE); + + return virt_addr; +} + SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) { return do_read(fd, buffer, count); @@ -738,29 +808,9 @@ SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st) /** * An mmap() implementation in VFS. */ -SYSCALL_DEFINE5(mmap, addr_t, start, size_t, length, int, prot, int, fd, off_t, offset) +SYSCALL_DEFINE6(mmap, addr_t, start, size_t, length, int, prot, int, flags, int, fd, off_t, offset) { - int gfd; uint32_t page_count; - struct file_operations *fops; - - /* Get the fops associated to the file descriptor. */ - - gfd = vfs_get_gfd(fd); - if (-1 == gfd) { - printk("%s: could not get global fd.\n", __func__); - return -EBADF; - } - - mutex_lock(&vfs_lock); - fops = vfs_get_fops(gfd); - if (!fops) { - printk("%s: could not get device fops.\n", __func__); - mutex_unlock(&vfs_lock); - return -EBADF; - } - - mutex_unlock(&vfs_lock); /* Page count to allocate to the current process to be able to map the desired region. */ page_count = length / PAGE_SIZE; @@ -768,13 +818,10 @@ SYSCALL_DEFINE5(mmap, addr_t, start, size_t, length, int, prot, int, fd, off_t, page_count++; } - if (!fops->mmap) { - printk("%s: device doesn't support mmap.\n", __func__); - return -EACCES; - } - - /* Call the mmap fops that will do the actual mapping. */ - return (long) fops->mmap(fd, start, page_count, offset); + if (flags & MAP_ANONYMOUS) + return do_mmap_anon(fd, start, page_count, offset); + else + return do_mmap(fd, start, page_count, offset); } SYSCALL_DEFINE3(ioctl, int, fd, unsigned long, cmd, unsigned long, args) diff --git a/so3/include/process.h b/so3/include/process.h index 1623daa1b..83fceefe7 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -76,6 +76,9 @@ struct pcb { /* current position of the heap pointer */ addr_t heap_pointer; + /* next anonymous start pointer */ + addr_t next_anon_start; + /* Number of pages required by this process (including binary image) */ size_t page_count; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index b75836586..d2d128bdc 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -91,6 +91,9 @@ #define DT_LNK 10 /* Symbolic link */ #define DT_SOCK 12 /* Socket device */ +/* mmap flags options */ +#define MAP_ANONYMOUS 0x10 /* don't use a file */ + /* Return error values */ #define MAP_FAILED ((void *) -1) /* mmap fail */ @@ -165,7 +168,7 @@ SYSCALL_DECLARE(close, int fd); SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); SYSCALL_DECLARE(stat, const char *path, struct stat *st); -SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int fd, off_t offset); +SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(fcntl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); diff --git a/so3/kernel/process.c b/so3/kernel/process.c index ff283bc79..21a21f628 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -185,6 +185,8 @@ pcb_t *new_process(void) pcb->state = PROC_STATE_NEW; + pcb->next_anon_start = USER_ANONYMOUS_VADDR; + /* Reset the ptrace request indicator */ pcb->ptrace_pending_req = PTRACE_NO_REQUEST; From 4972c2b67aabd1d87d55333244f261373e45bf5a Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 9 Oct 2025 16:37:22 +0200 Subject: [PATCH 08/69] [syscall] mmap: Define USER_ANONYMOUS_VADDR for 39bits case Signed-off-by: Jean-Pierre Miceli --- so3/arch/arm64/include/asm/mmu.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/so3/arch/arm64/include/asm/mmu.h b/so3/arch/arm64/include/asm/mmu.h index 337570160..34c913043 100644 --- a/so3/arch/arm64/include/asm/mmu.h +++ b/so3/arch/arm64/include/asm/mmu.h @@ -48,6 +48,9 @@ /* Fixmap page used for temporary mapping */ #define FIXMAP_MAPPING UL(0xffffffd800000000) +/* Anonymous start virtual address */ +#define USER_ANONYMOUS_VADDR UL(0x0000000100000000) + /* The user space can be up to bits [38:0] and uses ttbr0_el1 * as main L0 page table. */ From 2ec20660313b555c9008a4dbc8a89e2d033408a8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Fri, 10 Oct 2025 08:21:32 +0200 Subject: [PATCH 09/69] [syscall] mmap: Define USER_ANONYMOUS_VADDR for arm32b Signed-off-by: Jean-Pierre Miceli --- so3/arch/arm32/include/asm/mmu.h | 3 +++ so3/fs/vfs.c | 3 +-- so3/include/vfs.h | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/so3/arch/arm32/include/asm/mmu.h b/so3/arch/arm32/include/asm/mmu.h index 1593b94fb..0817a0fcc 100644 --- a/so3/arch/arm32/include/asm/mmu.h +++ b/so3/arch/arm32/include/asm/mmu.h @@ -39,6 +39,9 @@ #define USER_SPACE_VADDR 0x1000ul +/* Anonymous start virtual address */ +#define USER_ANONYMOUS_VADDR UL(CONFIG_KERNEL_VADDR / 2) + /* Memory space all I/O mapped registers and additional mappings */ #define IO_MAPPING_BASE 0xe0000000 diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 54635bc34..7c0ee97bb 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -495,7 +495,6 @@ static int do_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) return (long) fops->mmap(fd, virt_addr, page_count, offset); } - /* Low Level mmap - Anonymous case */ static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t offset) { @@ -522,7 +521,7 @@ static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t off add_page_to_proc(pcb, phys_to_page(page)); } - memset((void *)virt_addr, 0, page_count * PAGE_SIZE); + memset((void *) virt_addr, 0, page_count * PAGE_SIZE); /* WARNIMG - This is a simple/basic way to set the start virtual address: It only increment the start address after each mmap call, no algorithm diff --git a/so3/include/vfs.h b/so3/include/vfs.h index d2d128bdc..89430c6c4 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -92,7 +92,7 @@ #define DT_SOCK 12 /* Socket device */ /* mmap flags options */ -#define MAP_ANONYMOUS 0x10 /* don't use a file */ +#define MAP_ANONYMOUS 0x10 /* don't use a file */ /* Return error values */ #define MAP_FAILED ((void *) -1) /* mmap fail */ From 09a9518b9b73c0255fbc9193951c6dc7c1275fba Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 28 Aug 2025 16:55:52 +0200 Subject: [PATCH 10/69] change syscall number to correct ones --- so3/arch/arm32/include/asm/syscall_number.h | 106 ++++++++++--------- so3/arch/arm64/include/asm/syscall_number.h | 108 +++++++++++--------- 2 files changed, 119 insertions(+), 95 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 1da6a2f71..a3349efc2 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -24,61 +24,75 @@ */ #define SYSCALL_EXIT 1 -#define SYSCALL_EXECVE 2 -#define SYSCALL_WAITPID 3 -#define SYSCALL_READ 4 -#define SYSCALL_WRITE 5 -#define SYSCALL_FORK 7 -#define SYSCALL_PTRACE 8 -#define SYSCALL_READDIR 9 -#define SYSCALL_OPEN 14 -#define SYSCALL_CLOSE 15 -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_PIPE 19 -#define SYSCALL_IOCTL 20 -#define SYSCALL_FCNTL 21 -#define SYSCALL_DUP 22 -#define SYSCALL_DUP2 23 - -#define SYSCALL_SOCKET 26 -#define SYSCALL_BIND 27 -#define SYSCALL_LISTEN 28 -#define SYSCALL_ACCEPT 29 -#define SYSCALL_CONNECT 30 -#define SYSCALL_RECV 31 -#define SYSCALL_SEND 32 -#define SYSCALL_SENDTO 33 - -#define SYSCALL_STAT 34 -#define SYSCALL_MMAP 35 -#define SYSCALL_GETPID 37 - -#define SYSCALL_GETTIMEOFDAY 38 -#define SYSCALL_SETTIMEOFDAY 39 -#define SYSCALL_CLOCK_GETTIME 40 +#define SYSCALL_FORK 2 +#define SYSCALL_READ 3 +#define SYSCALL_WRITE 4 +#define SYSCALL_OPEN 5 // Add mode +#define SYSCALL_CLOSE 6 -#define SYSCALL_THREAD_YIELD 43 +#define SYSCALL_EXECVE 11 -#define SYSCALL_SBRK 45 -#define SYSCALL_SIGACTION 46 -#define SYSCALL_KILL 47 -#define SYSCALL_SIGRETURN 48 +#define SYSCALL_LSEEK 19 +#define SYSCALL_GETPID 20 -#define SYSCALL_LSEEK 50 +#define SYSCALL_PTRACE 26 -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 +#define SYSCALL_KILL 37 + +#define SYSCALL_DUP 41 -#define SYSCALL_NANOSLEEP 70 +#define SYSCALL_SBRK 45 // => brk +#define SYSCALL_PIPE 46 -#define SYSCALL_SYSINFO 99 +#define SYSCALL_IOCTL 54 +#define SYSCALL_FCNTL 55 // fcntl64? -#define SYSCALL_SETSOCKOPT 110 -#define SYSCALL_RECVFROM 111 +#define SYSCALL_DUP2 63 +#define SYSCALL_SIGACTION 67 + +#define SYSCALL_GETTIMEOFDAY 78 // Add _time32 +#define SYSCALL_SETTIMEOFDAY 79 // Implement? + +#define SYSCALL_STAT 106 + +#define SYSCALL_SYSINFO 116 // => struct sysinfo + +#define SYSCALL_SIGRETURN 119 #define SYSCALL_READV 145 #define SYSCALL_WRITEV 146 +#define SYSCALL_NANOSLEEP 162 + +#define SYSCALL_CLOCK_GETTIME 263 // 32 and 64 + +#define SYSCALL_SOCKET 281 +#define SYSCALL_BIND 282 +#define SYSCALL_CONNECT 283 +#define SYSCALL_LISTEN 284 +#define SYSCALL_ACCEPT 285 + +#define SYSCALL_SEND 289 +#define SYSCALL_SENDTO 290 + +#define SYSCALL_RECV 291 +#define SYSCALL_RECVFROM 292 + +#define SYSCALL_SETSOCKOPT 294 + +// Does not exist +#define SYSCALL_WAITPID 3 // => wait4? +#define SYSCALL_READDIR 9 // getdents + 64? +#define SYSCALL_MMAP 222 // => mmap2 + +// => pthread +#define SYSCALL_THREAD_CREATE 16 +#define SYSCALL_THREAD_JOIN 17 +#define SYSCALL_THREAD_EXIT 18 +#define SYSCALL_THREAD_YIELD 43 + +// => ??? +#define SYSCALL_MUTEX_LOCK 60 +#define SYSCALL_MUTEX_UNLOCK 61 + #endif /* ARCH_ARM32_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 2cbbea82d..c2b8f9e86 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -22,63 +22,73 @@ /* * Syscall number definition */ +#define SYSCALL_DUP 23 -#define SYSCALL_EXIT 1 -#define SYSCALL_EXECVE 2 -#define SYSCALL_WAITPID 3 -#define SYSCALL_READ 4 -#define SYSCALL_WRITE 5 -#define SYSCALL_FORK 7 -#define SYSCALL_PTRACE 8 -#define SYSCALL_READDIR 9 -#define SYSCALL_OPEN 14 -#define SYSCALL_CLOSE 15 -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_PIPE 19 -#define SYSCALL_IOCTL 20 -#define SYSCALL_FCNTL 21 -#define SYSCALL_DUP 22 -#define SYSCALL_DUP2 23 - -#define SYSCALL_SOCKET 26 -#define SYSCALL_BIND 27 -#define SYSCALL_LISTEN 28 -#define SYSCALL_ACCEPT 29 -#define SYSCALL_CONNECT 30 -#define SYSCALL_RECV 31 -#define SYSCALL_SEND 32 -#define SYSCALL_SENDTO 33 - -#define SYSCALL_STAT 34 -#define SYSCALL_MMAP 35 -#define SYSCALL_GETPID 37 - -#define SYSCALL_GETTIMEOFDAY 38 -#define SYSCALL_SETTIMEOFDAY 39 -#define SYSCALL_CLOCK_GETTIME 40 +#define SYSCALL_FCNTL 25 -#define SYSCALL_THREAD_YIELD 43 +#define SYSCALL_IOCTL 29 -#define SYSCALL_SBRK 45 -#define SYSCALL_SIGACTION 46 -#define SYSCALL_KILL 47 -#define SYSCALL_SIGRETURN 48 - -#define SYSCALL_LSEEK 50 - -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 +#define SYSCALL_CLOSE 57 +#define SYSCALL_LSEEK 62 +#define SYSCALL_READ 63 +#define SYSCALL_WRITE 64 #define SYSCALL_READV 65 #define SYSCALL_WRITEV 66 -#define SYSCALL_NANOSLEEP 70 +#define SYSCALL_EXIT 93 + +#define SYSCALL_NANOSLEEP 101 + +#define SYSCALL_CLOCK_GETTIME 113 + +#define SYSCALL_PTRACE 117 + +#define SYSCALL_KILL 129 + +#define SYSCALL_GETTIMEOFDAY 169 // Add timezone +#define SYSCALL_SETTIMEOFDAY 170 // Implement? + +#define SYSCALL_GETPID 172 -#define SYSCALL_SYSINFO 99 +#define SYSCALL_SYSINFO 179 // => struct sysinfo -#define SYSCALL_SETSOCKOPT 110 -#define SYSCALL_RECVFROM 111 +#define SYSCALL_SOCKET 198 + +#define SYSCALL_BIND 200 +#define SYSCALL_LISTEN 201 +#define SYSCALL_ACCEPT 202 +#define SYSCALL_CONNECT 203 + +#define SYSCALL_SENDTO 206 +#define SYSCALL_RECVFROM 207 +#define SYSCALL_SETSOCKOPT 208 + +#define SYSCALL_SBRK 214 // => brk + +#define SYSCALL_EXECVE 221 +#define SYSCALL_MMAP 222 + +// Does not exist +#define SYSCALL_WAITPID 3 // => wait4? +#define SYSCALL_FORK 7 // => clone +#define SYSCALL_READDIR 9 // getdents64 +#define SYSCALL_OPEN 5 // => openat +#define SYSCALL_PIPE 19 // => pipe2 +#define SYSCALL_DUP2 23 // => dup3 +#define SYSCALL_SEND 32 // => sendto +#define SYSCALL_SIGACTION 46 // => rt_sigaction + +#define SYSCALL_STAT 34 // ???? +#define SYSCALL_SIGRETURN 48 // ????? + +#define SYSCALL_THREAD_CREATE 16 +#define SYSCALL_THREAD_JOIN 17 +#define SYSCALL_THREAD_EXIT 18 +#define SYSCALL_THREAD_YIELD 43 + +// => ??? +#define SYSCALL_MUTEX_LOCK 60 +#define SYSCALL_MUTEX_UNLOCK 61 #endif /* ARCH_ARM64_SYSCALL_NUMBER_H */ From cc2016feaadc7b623118557876f0484260cad81c Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 28 Aug 2025 17:29:24 +0200 Subject: [PATCH 11/69] rename sbrk to brk --- so3/arch/arm32/include/asm/syscall_number.h | 2 +- so3/arch/arm64/include/asm/syscall_number.h | 2 +- so3/include/process.h | 2 +- so3/kernel/process.c | 2 +- so3/kernel/syscalls.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index a3349efc2..6c0aa8779 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -41,7 +41,7 @@ #define SYSCALL_DUP 41 -#define SYSCALL_SBRK 45 // => brk +#define SYSCALL_BRK 45 #define SYSCALL_PIPE 46 #define SYSCALL_IOCTL 54 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index c2b8f9e86..aca168114 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -64,7 +64,7 @@ #define SYSCALL_RECVFROM 207 #define SYSCALL_SETSOCKOPT 208 -#define SYSCALL_SBRK 214 // => brk +#define SYSCALL_BRK 214 #define SYSCALL_EXECVE 221 #define SYSCALL_MMAP 222 diff --git a/so3/include/process.h b/so3/include/process.h index 83fceefe7..368d67b00 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -153,6 +153,6 @@ void dump_proc(void); extern int __exec(const char *file); extern int __write(int fd, char *buffer, int count); -SYSCALL_DECLARE(sbrk, int increment); +SYSCALL_DECLARE(brk, int increment); #endif /* PROCESS_H */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 21a21f628..52a9d7596 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -1088,7 +1088,7 @@ SYSCALL_DEFINE3(waitpid, int, pid, uint32_t *, wstatus, uint32_t, options) * @return This function will the position of the end of the heap / program *break before increment */ -SYSCALL_DEFINE1(sbrk, int, increment) +SYSCALL_DEFINE1(brk, int, increment) { pcb_t *pcb = current()->pcb; int ret_pointer; diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 68e15083f..c46b81a83 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -71,7 +71,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_MMAP] = __sys_mmap, [SYSCALL_NANOSLEEP] = __sys_nanosleep, #ifdef CONFIG_PROC_ENV - [SYSCALL_SBRK] = __sys_sbrk, + [SYSCALL_BRK] = __sys_brk, #endif [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, From 0a7427622b4e3ad972b842db1f31a02fe7fd265d Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 28 Aug 2025 17:42:32 +0200 Subject: [PATCH 12/69] add dup3 simple implementation --- so3/arch/arm32/include/asm/syscall_number.h | 2 ++ so3/arch/arm64/include/asm/syscall_number.h | 2 +- so3/fs/vfs.c | 14 ++++++++++++++ so3/include/vfs.h | 1 + so3/kernel/syscalls.c | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 6c0aa8779..ed56d1dfc 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -80,6 +80,8 @@ #define SYSCALL_SETSOCKOPT 294 +#define SYSCALL_DUP3 358 + // Does not exist #define SYSCALL_WAITPID 3 // => wait4? #define SYSCALL_READDIR 9 // getdents + 64? diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index aca168114..8b5a29a9c 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -23,6 +23,7 @@ * Syscall number definition */ #define SYSCALL_DUP 23 +#define SYSCALL_DUP3 24 #define SYSCALL_FCNTL 25 @@ -75,7 +76,6 @@ #define SYSCALL_READDIR 9 // getdents64 #define SYSCALL_OPEN 5 // => openat #define SYSCALL_PIPE 19 // => pipe2 -#define SYSCALL_DUP2 23 // => dup3 #define SYSCALL_SEND 32 // => sendto #define SYSCALL_SIGACTION 46 // => rt_sigaction diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 7c0ee97bb..d032d3e96 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -715,6 +715,20 @@ SYSCALL_DEFINE1(close, int, fd) return 0; } +SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) +{ + if (oldfd == newfd) { + set_errno(EINVAL); + return -1; + } + + if (flags != 0) { + LOG_WARNING("Flags not supported.\n"); + } + + return do_dup2(oldfd, newfd); +} + /** * @brief dup2 creates a synonym of oldfd on newfd * diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 89430c6c4..99d5a68ac 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -167,6 +167,7 @@ SYSCALL_DECLARE(readdir, int fd, char *buf, int len); SYSCALL_DECLARE(close, int fd); SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); +SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); SYSCALL_DECLARE(stat, const char *path, struct stat *st); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index c46b81a83..cf82d60e5 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -66,7 +66,10 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_PIPE] = __sys_pipe, #endif [SYSCALL_DUP] = __sys_dup, +#ifdef SYSCALL_DUP2 [SYSCALL_DUP2] = __sys_dup2, +#endif + [SYSCALL_DUP3] = __sys_dup3, [SYSCALL_STAT] = __sys_stat, [SYSCALL_MMAP] = __sys_mmap, [SYSCALL_NANOSLEEP] = __sys_nanosleep, From 0759ba5d3cbf4b10862f1ac225b87b7f47a81307 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 2 Sep 2025 13:49:40 +0200 Subject: [PATCH 13/69] implement time32 version for clock_gettime and gettimeofday --- so3/arch/arm32/include/asm/syscall_number.h | 10 +++--- so3/arch/arm64/include/asm/syscall_number.h | 6 ++-- so3/include/device/timer.h | 10 ++++++ so3/include/timer.h | 4 ++- so3/include/types.h | 1 + so3/kernel/timer.c | 38 +++++++++++++++++++-- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index ed56d1dfc..20f2965aa 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -50,12 +50,12 @@ #define SYSCALL_DUP2 63 #define SYSCALL_SIGACTION 67 -#define SYSCALL_GETTIMEOFDAY 78 // Add _time32 -#define SYSCALL_SETTIMEOFDAY 79 // Implement? +#define SYSCALL_GETTIMEOFDAY_TIME32 78 +// #define SYSCALL_SETTIMEOFDAY 79 // Implement? #define SYSCALL_STAT 106 -#define SYSCALL_SYSINFO 116 // => struct sysinfo +// #define SYSCALL_SYSINFO 116 // => struct sysinfo #define SYSCALL_SIGRETURN 119 @@ -64,7 +64,7 @@ #define SYSCALL_NANOSLEEP 162 -#define SYSCALL_CLOCK_GETTIME 263 // 32 and 64 +#define SYSCALL_CLOCK_GETTIME32 263 #define SYSCALL_SOCKET 281 #define SYSCALL_BIND 282 @@ -82,6 +82,8 @@ #define SYSCALL_DUP3 358 +#define SYSCALL_CLOCK_GETTIME64 403 + // Does not exist #define SYSCALL_WAITPID 3 // => wait4? #define SYSCALL_READDIR 9 // getdents + 64? diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 8b5a29a9c..f8b0eb35e 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -47,12 +47,12 @@ #define SYSCALL_KILL 129 -#define SYSCALL_GETTIMEOFDAY 169 // Add timezone -#define SYSCALL_SETTIMEOFDAY 170 // Implement? +#define SYSCALL_GETTIMEOFDAY 169 +// #define SYSCALL_SETTIMEOFDAY 170 // Implement? #define SYSCALL_GETPID 172 -#define SYSCALL_SYSINFO 179 // => struct sysinfo +// #define SYSCALL_SYSINFO 179 // => struct sysinfo #define SYSCALL_SOCKET 198 diff --git a/so3/include/device/timer.h b/so3/include/device/timer.h index d159e6bb1..e8c213cb6 100644 --- a/so3/include/device/timer.h +++ b/so3/include/device/timer.h @@ -27,11 +27,21 @@ /* Time conversion units */ +struct timespec32 { + time32_t tv_sec; /* seconds */ + time32_t tv_nsec; /* nanoseconds */ +}; + struct timespec { time_t tv_sec; /* seconds */ time_t tv_nsec; /* nanoseconds */ }; +struct timeval32 { + time32_t tv_sec; /* seconds */ + time32_t tv_usec; /* microseconds */ +}; + struct timeval { time_t tv_sec; /* seconds */ time_t tv_usec; /* microseconds */ diff --git a/so3/include/timer.h b/so3/include/timer.h index bb125c666..8905046a0 100644 --- a/so3/include/timer.h +++ b/so3/include/timer.h @@ -128,7 +128,9 @@ void clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 maxsec) SYSCALL_DECLARE(nanosleep, const struct timespec *req, struct timespec *rem); -SYSCALL_DECLARE(gettimeofday, struct timespec *tv); +SYSCALL_DECLARE(gettimeofday_time32, struct timeval32 *tv, void *tz); +SYSCALL_DECLARE(gettimeofday, struct timeval *tv, void *tz); +SYSCALL_DECLARE(clock_gettime32, int clk_id, struct timespec32 *ts); SYSCALL_DECLARE(clock_gettime, int clk_id, struct timespec *ts); #ifdef CONFIG_AVZ diff --git a/so3/include/types.h b/so3/include/types.h index b128206fe..b12fad6fd 100644 --- a/so3/include/types.h +++ b/so3/include/types.h @@ -116,6 +116,7 @@ typedef __u32 __bitwise __wsum; typedef unsigned __bitwise__ gfp_t; +typedef u32 time32_t; typedef u64 time_t; #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) diff --git a/so3/kernel/timer.c b/so3/kernel/timer.c index 3c2173ca4..7ff452d1e 100644 --- a/so3/kernel/timer.c +++ b/so3/kernel/timer.c @@ -405,10 +405,28 @@ void timer_init(void) #endif } +SYSCALL_DEFINE2(gettimeofday_time32, struct timeval32 *, ts, void *, tz) +{ + struct timeval time64; + + long ret = do_gettimeofday(&time64, NULL); + + if (ret < 0) { + return ret; + } + + ts->tv_sec = (time32_t) time64.tv_sec; + ts->tv_usec = (time32_t) time64.tv_usec; + + return 0; +} + /* * This function gets the current time and put it in the parameter tv + * + * Timezone (tz) is ignored */ -SYSCALL_DEFINE1(gettimeofday, struct timespec *, ts) +SYSCALL_DEFINE2(gettimeofday, struct timeval *, ts, void *, tz) { u64 time; @@ -419,7 +437,23 @@ SYSCALL_DEFINE1(gettimeofday, struct timespec *, ts) time = NOW(); ts->tv_sec = time / (time_t) 1000000000; - ts->tv_nsec = time; + ts->tv_usec = time / (time_t) 1000; + + return 0; +} + +SYSCALL_DEFINE2(clock_gettime32, int, clk_id, struct timespec32 *, ts) +{ + struct timespec time64; + + long ret = do_clock_gettime(clk_id, &time64); + + if (ret < 0) { + return ret; + } + + ts->tv_sec = (time32_t) time64.tv_sec; + ts->tv_nsec = (time32_t) time64.tv_nsec; return 0; } From 41b182a80483fd7ed67d5a536fe392b3691fd38c Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 2 Sep 2025 15:44:03 +0200 Subject: [PATCH 14/69] wait4 and getdents --- so3/arch/arm32/include/asm/syscall_number.h | 6 ++++-- so3/arch/arm64/include/asm/syscall_number.h | 4 ++-- so3/fs/vfs.c | 2 +- so3/include/process.h | 2 +- so3/include/vfs.h | 2 +- so3/kernel/process.c | 6 ++++-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 20f2965aa..bff2e042d 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -64,6 +64,10 @@ #define SYSCALL_NANOSLEEP 162 +#define SYSCALL_GETDENTS64 217 + +#define SYSCALL_WAIT4 260 + #define SYSCALL_CLOCK_GETTIME32 263 #define SYSCALL_SOCKET 281 @@ -85,8 +89,6 @@ #define SYSCALL_CLOCK_GETTIME64 403 // Does not exist -#define SYSCALL_WAITPID 3 // => wait4? -#define SYSCALL_READDIR 9 // getdents + 64? #define SYSCALL_MMAP 222 // => mmap2 // => pthread diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index f8b0eb35e..f706f59ed 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -31,6 +31,7 @@ #define SYSCALL_CLOSE 57 +#define SYSCALL_GETDENTS64 61 #define SYSCALL_LSEEK 62 #define SYSCALL_READ 63 #define SYSCALL_WRITE 64 @@ -42,6 +43,7 @@ #define SYSCALL_NANOSLEEP 101 #define SYSCALL_CLOCK_GETTIME 113 +#define SYSCALL_WAIT4 114 #define SYSCALL_PTRACE 117 @@ -71,9 +73,7 @@ #define SYSCALL_MMAP 222 // Does not exist -#define SYSCALL_WAITPID 3 // => wait4? #define SYSCALL_FORK 7 // => clone -#define SYSCALL_READDIR 9 // getdents64 #define SYSCALL_OPEN 5 // => openat #define SYSCALL_PIPE 19 // => pipe2 #define SYSCALL_SEND 32 // => sendto diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index d032d3e96..0345502bf 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -616,7 +616,7 @@ SYSCALL_DEFINE2(open, const char *, filename, int, flags) * @brief readdir read a directory entry which will be stored in a struct dirent entry * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. */ -SYSCALL_DEFINE3(readdir, int, fd, char *, buf, int, len) +SYSCALL_DEFINE3(getdents64, int, fd, char *, buf, size_t, len) { struct dirent *dirent; int gfd; diff --git a/so3/include/process.h b/so3/include/process.h index 368d67b00..62f2273f3 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -142,7 +142,7 @@ SYSCALL_DECLARE(getpid, void); SYSCALL_DECLARE(execve, const char *filename, char **argv, char **envp); SYSCALL_DECLARE(fork, void); SYSCALL_DECLARE(exit, int exit_status); -SYSCALL_DECLARE(waitpid, int pid, uint32_t *wstatus, uint32_t options); +SYSCALL_DECLARE(wait4, int pid, uint32_t *wstatus, uint32_t options, void *rusage); pcb_t *find_proc_by_pid(uint32_t pid); diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 99d5a68ac..af96bedbf 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -163,7 +163,7 @@ typedef enum { SYSCALL_DECLARE(open, const char *filename, int flags); SYSCALL_DECLARE(read, int fd, void *buffer, int count); SYSCALL_DECLARE(write, int fd, const void *buffer, int count); -SYSCALL_DECLARE(readdir, int fd, char *buf, int len); +SYSCALL_DECLARE(getdents64, int fd, char *buf, size_t count); SYSCALL_DECLARE(close, int fd); SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 52a9d7596..ed4bb838a 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -969,7 +969,7 @@ SYSCALL_DEFINE0(getpid) } /* - * Waitpid implementation - do_waitpid() does the following operations: + * Waitpid implementation via wait4 - do_wait4() does the following operations: * - Suspend the current process until the child process finished its execution * (exit()) If the pid argument is -1, waitpid() looks for a possible terminated * process and performs the operation. If no process is finished (in zombie @@ -977,8 +977,10 @@ SYSCALL_DEFINE0(getpid) * - Get the exit code from the child PCB * - Clean the PCB and page tables * - Return the pid if successful operation + * + * rusage is ignored */ -SYSCALL_DEFINE3(waitpid, int, pid, uint32_t *, wstatus, uint32_t, options) +SYSCALL_DEFINE4(wait4, int, pid, uint32_t *, wstatus, uint32_t, options, void *, rusage) { pcb_t *child; unsigned long flags; From 81c4c7cb9082a15d36a3da3888b62c772ad3c3bd Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 2 Sep 2025 16:56:04 +0200 Subject: [PATCH 15/69] add mmap2 and openat --- so3/arch/arm32/include/asm/syscall_number.h | 9 +++---- so3/arch/arm64/include/asm/syscall_number.h | 2 +- so3/fs/vfs.c | 26 ++++++++++++++++++++- so3/include/vfs.h | 10 ++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index bff2e042d..28be697bc 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -27,7 +27,7 @@ #define SYSCALL_FORK 2 #define SYSCALL_READ 3 #define SYSCALL_WRITE 4 -#define SYSCALL_OPEN 5 // Add mode +#define SYSCALL_OPEN 5 #define SYSCALL_CLOSE 6 #define SYSCALL_EXECVE 11 @@ -64,6 +64,8 @@ #define SYSCALL_NANOSLEEP 162 +#define SYSCALL_MMAP2 192 + #define SYSCALL_GETDENTS64 217 #define SYSCALL_WAIT4 260 @@ -84,13 +86,12 @@ #define SYSCALL_SETSOCKOPT 294 +#define SYSCALL_OPENAT 322 + #define SYSCALL_DUP3 358 #define SYSCALL_CLOCK_GETTIME64 403 -// Does not exist -#define SYSCALL_MMAP 222 // => mmap2 - // => pthread #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index f706f59ed..36ba15f3c 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -29,6 +29,7 @@ #define SYSCALL_IOCTL 29 +#define SYSCALL_OPENAT 56 #define SYSCALL_CLOSE 57 #define SYSCALL_GETDENTS64 61 @@ -74,7 +75,6 @@ // Does not exist #define SYSCALL_FORK 7 // => clone -#define SYSCALL_OPEN 5 // => openat #define SYSCALL_PIPE 19 // => pipe2 #define SYSCALL_SEND 32 // => sendto #define SYSCALL_SIGACTION 46 // => rt_sigaction diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 0345502bf..023816c57 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -548,12 +548,16 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) /** * @brief This function opens a file. Not all file types are supported. */ -SYSCALL_DEFINE2(open, const char *, filename, int, flags) +SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) { int fd, gfd, ret = -1; uint32_t type; struct file_operations *fops; + if (mode != 0) { + LOG_WARNING("mode parameters isn't supported\n"); + } + mutex_lock(&vfs_lock); /* @@ -612,6 +616,18 @@ SYSCALL_DEFINE2(open, const char *, filename, int, flags) return ret; } +/** + * dirfd is currently ignored. + */ +SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned short, mode) +{ + if (dirfd != AT_FDCWD) { + LOG_WARNING("dirfd parameters isn't supported\n"); + } + + return do_open(filename, flags, mode); +} + /* * @brief readdir read a directory entry which will be stored in a struct dirent entry * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. @@ -837,6 +853,14 @@ SYSCALL_DEFINE6(mmap, addr_t, start, size_t, length, int, prot, int, flags, int, return do_mmap(fd, start, page_count, offset); } +/** + * Works like mmap, but with the given offset been in page count. + */ +SYSCALL_DEFINE6(mmap2, addr_t, start, size_t, length, int, prot, int, flags, int, fd, off_t, pgoffset) +{ + return sys_do_mmap(start, length, prot, flags, fd, pgoffset * PAGE_SIZE); +} + SYSCALL_DEFINE3(ioctl, int, fd, unsigned long, cmd, unsigned long, args) { int rc, gfd; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index af96bedbf..ab6641dd4 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2014-2019 Daniel Rossier * Copyright (C) 2017 Xavier Ruppen - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -94,6 +94,10 @@ /* mmap flags options */ #define MAP_ANONYMOUS 0x10 /* don't use a file */ +/* Special value for dirfd used to indicate openat + should use the current working directory. */ +#define AT_FDCWD (-100) + /* Return error values */ #define MAP_FAILED ((void *) -1) /* mmap fail */ @@ -160,7 +164,8 @@ typedef enum { /* Syscall accessible from userspace */ -SYSCALL_DECLARE(open, const char *filename, int flags); +SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, unsigned short mode) +SYSCALL_DECLARE(open, const char *filename, int flags, unsigned short mode); SYSCALL_DECLARE(read, int fd, void *buffer, int count); SYSCALL_DECLARE(write, int fd, const void *buffer, int count); SYSCALL_DECLARE(getdents64, int fd, char *buf, size_t count); @@ -170,6 +175,7 @@ SYSCALL_DECLARE(dup2, int oldfd, int newfd); SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); SYSCALL_DECLARE(stat, const char *path, struct stat *st); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); +SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(fcntl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); From fff4b8ffde92d4fa9b7cb82373c59cfad00dac70 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 25 Sep 2025 09:18:19 +0200 Subject: [PATCH 16/69] remove support for sysinfo --- so3/arch/arm32/include/asm/syscall_number.h | 2 -- so3/arch/arm64/include/asm/syscall_number.h | 3 --- so3/include/syscall.h | 8 ------ so3/kernel/syscalls.c | 30 --------------------- usr/lib/libc/crt0.S | 1 - usr/lib/libc/include/syscall.h | 8 ------ 6 files changed, 52 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 28be697bc..88428e2ad 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -55,8 +55,6 @@ #define SYSCALL_STAT 106 -// #define SYSCALL_SYSINFO 116 // => struct sysinfo - #define SYSCALL_SIGRETURN 119 #define SYSCALL_READV 145 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 36ba15f3c..029eb665b 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -51,12 +51,9 @@ #define SYSCALL_KILL 129 #define SYSCALL_GETTIMEOFDAY 169 -// #define SYSCALL_SETTIMEOFDAY 170 // Implement? #define SYSCALL_GETPID 172 -// #define SYSCALL_SYSINFO 179 // => struct sysinfo - #define SYSCALL_SOCKET 198 #define SYSCALL_BIND 200 diff --git a/so3/include/syscall.h b/so3/include/syscall.h index 1c1031576..711b84145 100644 --- a/so3/include/syscall.h +++ b/so3/include/syscall.h @@ -21,12 +21,6 @@ #ifndef ASM_ARM_SYSCALL_H #define ASM_ARM_SYSCALL_H -#define SYSINFO_DUMP_HEAP 0 -#define SYSINFO_DUMP_SCHED 1 -#define SYSINFO_TEST_MALLOC 2 -#define SYSINFO_PRINTK 3 -#define SYSINFO_DUMP_PROC 4 - #include #ifndef __ASSEMBLY__ @@ -120,8 +114,6 @@ typedef long (*syscall_fn_t)(syscall_args_t *); long syscall_handle(syscall_args_t *); -SYSCALL_DECLARE(sysinfo, unsigned long info_number, char *text); - #endif /* __ASSEMBLY__ */ #endif /* ASM_ARM_SYSCALL_H */ diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index cf82d60e5..a2be6e803 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -95,38 +95,8 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, #endif - [SYSCALL_SYSINFO] = __sys_sysinfo, }; -SYSCALL_DEFINE2(sysinfo, unsigned long, info_number, char *, text) -{ - switch (info_number) { - case SYSINFO_DUMP_HEAP: - dump_heap("Heap info asked from user.\n"); - break; - - case SYSINFO_DUMP_SCHED: - dump_sched(); - break; - -#ifdef CONFIG_MMU - case SYSINFO_DUMP_PROC: - dump_proc(); - break; -#endif - -#ifdef CONFIG_APP_TEST_MALLOC - case SYSINFO_TEST_MALLOC: - test_malloc(a->args[1]); - break; -#endif - case SYSINFO_PRINTK: - printk("%s", (char *) text); - break; - } - return 0; -} - /* * Process syscalls according to the syscall number passed in r7 on ARM and x8 on ARM64. * According to SO3 ABI, the syscall arguments are passed in r0-r5 on ARM and x0-x5 on ARM64. diff --git a/usr/lib/libc/crt0.S b/usr/lib/libc/crt0.S index 22ba5aeda..f8f1ea080 100755 --- a/usr/lib/libc/crt0.S +++ b/usr/lib/libc/crt0.S @@ -164,7 +164,6 @@ SYSCALLSTUB sys_settimeofday, syscallSetTimeOfDay 2 SYSCALLSTUB sys_clock_gettime, syscallClockGetTime 2 SYSCALLSTUB sys_sbrk, syscallSbrk 1 -SYSCALLSTUB sys_info, syscallSysinfo 2 SYSCALLSTUB sys_lseek, syscallLseek 3 diff --git a/usr/lib/libc/include/syscall.h b/usr/lib/libc/include/syscall.h index 2426d2bd4..65299ad58 100644 --- a/usr/lib/libc/include/syscall.h +++ b/usr/lib/libc/include/syscall.h @@ -88,17 +88,9 @@ #define syscallNanosleep 70 -#define syscallSysinfo 99 - #define syscallSetsockopt 110 #define syscallRecvfrom 111 - -#define SYSINFO_DUMP_HEAP 0 -#define SYSINFO_DUMP_SCHED 1 -#define SYSINFO_TEST_MALLOC 2 -#define SYSINFO_PRINTK 3 - #ifndef __ASSEMBLY__ #include From d420d5bca9477cf0d343d32fb969687efde6d368 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 30 Sep 2025 13:13:12 +0200 Subject: [PATCH 17/69] add pipe2 --- so3/arch/arm32/include/asm/syscall_number.h | 1 + so3/arch/arm64/include/asm/syscall_number.h | 3 ++- so3/fs/vfs.c | 10 +++++++--- so3/include/pipe.h | 1 + so3/ipc/pipe.c | 13 +++++++++++++ so3/kernel/syscalls.c | 9 +++++++++ 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 88428e2ad..1a3915b1c 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -87,6 +87,7 @@ #define SYSCALL_OPENAT 322 #define SYSCALL_DUP3 358 +#define SYSCALL_PIPE2 359 #define SYSCALL_CLOCK_GETTIME64 403 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 029eb665b..1c994cf8c 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -32,6 +32,8 @@ #define SYSCALL_OPENAT 56 #define SYSCALL_CLOSE 57 +#define SYSCALL_PIPE2 59 + #define SYSCALL_GETDENTS64 61 #define SYSCALL_LSEEK 62 #define SYSCALL_READ 63 @@ -72,7 +74,6 @@ // Does not exist #define SYSCALL_FORK 7 // => clone -#define SYSCALL_PIPE 19 // => pipe2 #define SYSCALL_SEND 32 // => sendto #define SYSCALL_SIGACTION 46 // => rt_sigaction diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 023816c57..771aaef38 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -617,12 +617,13 @@ SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) } /** - * dirfd is currently ignored. + * Simple openat implementation ignoring dirfd for aarch64. */ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned short, mode) { if (dirfd != AT_FDCWD) { LOG_WARNING("dirfd parameters isn't supported\n"); + return -ENOSYS; } return do_open(filename, flags, mode); @@ -731,15 +732,18 @@ SYSCALL_DEFINE1(close, int, fd) return 0; } +/** + * Simple dup3 implementation ignoring flags for aarch64. + */ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) { if (oldfd == newfd) { - set_errno(EINVAL); - return -1; + return -EINVAL; } if (flags != 0) { LOG_WARNING("Flags not supported.\n"); + return -ENOSYS; } return do_dup2(oldfd, newfd); diff --git a/so3/include/pipe.h b/so3/include/pipe.h index 961f0b4c9..2f8f24101 100644 --- a/so3/include/pipe.h +++ b/so3/include/pipe.h @@ -54,5 +54,6 @@ struct pipe_desc { typedef struct pipe_desc pipe_desc_t; SYSCALL_DECLARE(pipe, int *pipefd); +SYSCALL_DECLARE(pipe2, int *pipefd, int flags); #endif /* PIPE_H */ diff --git a/so3/ipc/pipe.c b/so3/ipc/pipe.c index e649bdff3..d40f62bb5 100644 --- a/so3/ipc/pipe.c +++ b/so3/ipc/pipe.c @@ -308,3 +308,16 @@ SYSCALL_DEFINE1(pipe, int *, pipefd) return 0; } + +/** + * Simple pipe2 implementation ignoring flags for aarch64. + */ +SYSCALL_DEFINE2(pipe2, int *, pipefd, int, flags) +{ + if (flags != 0) { + LOG_WARNING("Flags not supported.\n"); + return -ENOSYS; + } + + return do_pipe(pipefd); +} diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index a2be6e803..462f83a08 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -45,12 +45,18 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_EXIT] = __sys_exit, [SYSCALL_EXECVE] = __sys_execve, [SYSCALL_FORK] = __sys_fork, +#ifdef SYSCALL_WAITPID [SYSCALL_WAITPID] = __sys_waitpid, +#endif + [SYSCALL_WAIT4] = __sys_wait4, [SYSCALL_PTRACE] = __sys_ptrace, #endif [SYSCALL_READ] = __sys_read, [SYSCALL_WRITE] = __sys_write, +#ifdef SYSCALL_OPEN [SYSCALL_OPEN] = __sys_open, +#endif + [SYSCALL_OPENAT] = __sys_openat, [SYSCALL_CLOSE] = __sys_close, [SYSCALL_THREAD_CREATE] = __sys_thread_create, [SYSCALL_THREAD_JOIN] = __sys_thread_join, @@ -63,7 +69,10 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_READV] = __sys_readv, [SYSCALL_WRITEV] = __sys_writev, #ifdef CONFIG_IPC_PIPE +#ifdef SYSCALL_PIPE [SYSCALL_PIPE] = __sys_pipe, +#endif + [SYSCALL_PIPE2] = __sys_pipe2, #endif [SYSCALL_DUP] = __sys_dup, #ifdef SYSCALL_DUP2 From e0bcb8aff81183fe0be2e7eba6d6e6375ea7439c Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Tue, 30 Sep 2025 16:14:15 +0200 Subject: [PATCH 18/69] add rt_sig, fstatat and correct syscall table --- so3/arch/arm32/include/asm/syscall_number.h | 5 ++ so3/arch/arm64/exception.S | 2 +- so3/arch/arm64/include/asm/syscall_number.h | 11 +++-- so3/fs/elf.c | 2 +- so3/fs/fat/fat.c | 3 +- so3/fs/vfs.c | 39 +++++++++++++++ so3/include/signal.h | 2 + so3/include/stat.h | 54 ++++++++++++++++----- so3/include/vfs.h | 1 + so3/ipc/signal.c | 20 +++++++- so3/kernel/syscalls.c | 30 +++++++++++- 11 files changed, 147 insertions(+), 22 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 1a3915b1c..11330a050 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -62,6 +62,9 @@ #define SYSCALL_NANOSLEEP 162 +#define SYSCALL_RT_SIGRETURN 173 +#define SYSCALL_RT_SIGACTION 174 + #define SYSCALL_MMAP2 192 #define SYSCALL_GETDENTS64 217 @@ -86,6 +89,8 @@ #define SYSCALL_OPENAT 322 +#define SYSCALL_FSTATAT 327 + #define SYSCALL_DUP3 358 #define SYSCALL_PIPE2 359 diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index bde52f61b..cf58242bc 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -557,7 +557,7 @@ el01_sync_handler: // Check if sigreturn has been called. In this case, we // clean the stack frame which has been used to manage the user handler. - cmp x8, #SYSCALL_SIGRETURN + cmp x8, #SYSCALL_RT_SIGRETURN bne __ret_from_fork // Reset the stack frame by removing the one issued from sigreturn diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 1c994cf8c..2c318f7ba 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -41,6 +41,8 @@ #define SYSCALL_READV 65 #define SYSCALL_WRITEV 66 +#define SYSCALL_FSTATAT 79 + #define SYSCALL_EXIT 93 #define SYSCALL_NANOSLEEP 101 @@ -52,6 +54,10 @@ #define SYSCALL_KILL 129 +#define SYSCALL_RT_SIGACTION 134 + +#define SYSCALL_RT_SIGRETURN 139 + #define SYSCALL_GETTIMEOFDAY 169 #define SYSCALL_GETPID 172 @@ -74,11 +80,6 @@ // Does not exist #define SYSCALL_FORK 7 // => clone -#define SYSCALL_SEND 32 // => sendto -#define SYSCALL_SIGACTION 46 // => rt_sigaction - -#define SYSCALL_STAT 34 // ???? -#define SYSCALL_SIGRETURN 48 // ????? #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 diff --git a/so3/fs/elf.c b/so3/fs/elf.c index 0489e7de5..a06d77fa1 100644 --- a/so3/fs/elf.c +++ b/so3/fs/elf.c @@ -35,7 +35,7 @@ uint8_t *elf_load_buffer(const char *filename) struct stat st; /* open and read file */ - fd = sys_do_open(filename, O_RDONLY); + fd = sys_do_open(filename, O_RDONLY, 0); if (fd < 0) return NULL; diff --git a/so3/fs/fat/fat.c b/so3/fs/fat/fat.c index 4a41b514f..551454488 100644 --- a/so3/fs/fat/fat.c +++ b/so3/fs/fat/fat.c @@ -415,8 +415,7 @@ int fat_stat(const char *path, struct stat *st) } time_fat_fat2so3(finfo.fdate, finfo.ftime, &tm); - st->st_mtim = tm.tv_sec; - strcpy(st->st_name, path); + st->st_mtime = tm.tv_sec; st->st_size = finfo.fsize; return 0; diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 771aaef38..cac94cd2c 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -818,6 +818,8 @@ SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st) { int ret; + memset(st, 0, sizeof(*st)); + mutex_lock(&vfs_lock); /* FIXME Find the correct mount point with the path */ @@ -838,6 +840,43 @@ SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st) return ret; } +SYSCALL_DEFINE3(fstatat, const char *, path, struct stat64 *, st, int, flags) +{ + struct stat stat32; + int ret; + if (flags != 0) { + LOG_WARNING("Flags not supported\n"); + return -ENOSYS; + } + + ret = do_stat(path, &stat32); + if (ret < 0) { + return ret; + } + + memset(st, 0, sizeof(*st)); + + // Copy with extension from 32 bits to 64 bits + st->st_dev = stat32.st_dev; + st->st_ino = stat32.st_ino; + st->st_mode = stat32.st_mode; + st->st_nlink = stat32.st_nlink; + st->st_uid = stat32.st_uid; + st->st_gid = stat32.st_gid; + st->st_rdev = stat32.st_rdev; + st->st_size = stat32.st_size; + st->st_blksize = stat32.st_blksize; + st->st_blocks = stat32.st_blocks; + st->st_atime = stat32.st_atime; + st->st_atime_nsec = stat32.st_atime_nsec; + st->st_mtime = stat32.st_mtime; + st->st_mtime_nsec = stat32.st_mtime_nsec; + st->st_ctime = stat32.st_ctime; + st->st_ctime_nsec = stat32.st_ctime_nsec; + + return 0; +} + /** * An mmap() implementation in VFS. */ diff --git a/so3/include/signal.h b/so3/include/signal.h index b4f8156a8..0969ad23e 100644 --- a/so3/include/signal.h +++ b/so3/include/signal.h @@ -95,7 +95,9 @@ typedef struct __sigaction { } __sigaction_t; SYSCALL_DECLARE(sigaction, int signum, const sigaction_t *action, sigaction_t *old_action); +SYSCALL_DECLARE(rt_sigaction, int signum, const sigaction_t *action, sigaction_t *old_action, size_t sigsize); SYSCALL_DECLARE(kill, int pid, int sig); SYSCALL_DECLARE(sigreturn, void); +SYSCALL_DECLARE(rt_sigreturn, void); #endif /* SIGNAL_H */ diff --git a/so3/include/stat.h b/so3/include/stat.h index 6571c90a1..03cd9694c 100644 --- a/so3/include/stat.h +++ b/so3/include/stat.h @@ -20,18 +20,50 @@ #ifndef STAT_H #define STAT_H -#include - -#define FILENAME_SIZE 256 - -typedef uint32_t mode_t; - struct stat { - char st_name[FILENAME_SIZE]; /* Filename */ - unsigned long st_size; /* Size of file */ - time_t st_mtim; /* Time of last modification in sec*/ - unsigned char st_flags; /* Regular file flag (not supported on fat) */ - mode_t st_mode; /* Protection not used (not supported on fat) */ + unsigned long st_dev; /* Device. */ + unsigned long st_ino; /* File serial number. */ + unsigned int st_mode; /* File mode. */ + unsigned int st_nlink; /* Link count. */ + unsigned int st_uid; /* User ID of the file's owner. */ + unsigned int st_gid; /* Group ID of the file's group. */ + unsigned long st_rdev; /* Device number, if device. */ + unsigned long __pad1; + long st_size; /* Size of file, in bytes. */ + int st_blksize; /* Optimal block size for I/O. */ + int __pad2; + long st_blocks; /* Number 512-byte blocks allocated. */ + long st_atime; /* Time of last access. */ + unsigned long st_atime_nsec; + long st_mtime; /* Time of last modification. */ + unsigned long st_mtime_nsec; + long st_ctime; /* Time of last status change. */ + unsigned long st_ctime_nsec; + unsigned int __unused4; + unsigned int __unused5; +}; + +struct stat64 { + unsigned long long st_dev; /* Device. */ + unsigned long long st_ino; /* File serial number. */ + unsigned int st_mode; /* File mode. */ + unsigned int st_nlink; /* Link count. */ + unsigned int st_uid; /* User ID of the file's owner. */ + unsigned int st_gid; /* Group ID of the file's group. */ + unsigned long long st_rdev; /* Device number, if device. */ + unsigned long long __pad1; + long long st_size; /* Size of file, in bytes. */ + int st_blksize; /* Optimal block size for I/O. */ + int __pad2; + long long st_blocks; /* Number 512-byte blocks allocated. */ + int st_atime; /* Time of last access. */ + unsigned int st_atime_nsec; + int st_mtime; /* Time of last modification. */ + unsigned int st_mtime_nsec; + int st_ctime; /* Time of last status change. */ + unsigned int st_ctime_nsec; + unsigned int __unused4; + unsigned int __unused5; }; #endif /* STAT_H */ diff --git a/so3/include/vfs.h b/so3/include/vfs.h index ab6641dd4..c460745a4 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -174,6 +174,7 @@ SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); SYSCALL_DECLARE(stat, const char *path, struct stat *st); +SYSCALL_DECLARE(fstatat, const char *path, struct stat64 *st, int flags); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); diff --git a/so3/ipc/signal.c b/so3/ipc/signal.c index c610b2ad9..4fa2347df 100644 --- a/so3/ipc/signal.c +++ b/so3/ipc/signal.c @@ -44,6 +44,14 @@ SYSCALL_DEFINE0(sigreturn) return 0; } +/** + * rt_sigreturn isn't different from sigreturn for SO3 use case. + */ +SYSCALL_DEFINE0(rt_sigreturn) +{ + return do_sigreturn(); +} + /** * Checks if signals were set and executes their handlers if so. */ @@ -107,7 +115,7 @@ SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t { if (signum < 0 || signum >= _NSIG) { LOG_ERROR("signum not valid!\n"); - return -1; + return -EINVAL; } if (old_action != NULL) @@ -124,6 +132,16 @@ SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t return 0; } +SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_actionm, size_t, sigsize) +{ + if (sigsize != sizeof(sigset_t)) { + LOG_WARNING("Invalid sigset size\n"); + return -EINVAL; + } + + return do_sigaction(signum, action, old_actionm); +} + SYSCALL_DEFINE2(kill, int, pid, int, sig) { pcb_t *proc; diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 462f83a08..50fe271b2 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -40,8 +40,18 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { #ifdef CONFIG_MMU [SYSCALL_GETPID] = __sys_getpid, +#ifdef SYSCALL_GETTIMEOFDAY [SYSCALL_GETTIMEOFDAY] = __sys_gettimeofday, +#endif +#ifdef SYSCALL_GETTIMEOFDAY_TIME32 + [SYSCALL_GETTIMEOFDAY_TIME32] = __sys_gettimeofday_time32, +#endif +#ifdef SYSCALL_CLOCK_GETTIME [SYSCALL_CLOCK_GETTIME] = __sys_clock_gettime, +#endif +#ifdef SYSCALL_CLOCK_GETTIME32 + [SYSCALL_CLOCK_GETTIME32] = __sys_clock_gettime32, +#endif [SYSCALL_EXIT] = __sys_exit, [SYSCALL_EXECVE] = __sys_execve, [SYSCALL_FORK] = __sys_fork, @@ -62,7 +72,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_THREAD_JOIN] = __sys_thread_join, [SYSCALL_THREAD_EXIT] = __sys_thread_exit, [SYSCALL_THREAD_YIELD] = __sys_thread_yield, - [SYSCALL_READDIR] = __sys_readdir, + [SYSCALL_GETDENTS64] = __sys_getdents64, [SYSCALL_IOCTL] = __sys_ioctl, [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, @@ -79,8 +89,16 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_DUP2] = __sys_dup2, #endif [SYSCALL_DUP3] = __sys_dup3, +#ifdef SYSCALL_STAT [SYSCALL_STAT] = __sys_stat, +#endif + [SYSCALL_FSTATAT] = __sys_fstatat, +#ifdef SYSCALL_MMAP [SYSCALL_MMAP] = __sys_mmap, +#endif +#ifdef SYSCALL_MMAP2 + [SYSCALL_MMAP2] = __sys_mmap2, +#endif [SYSCALL_NANOSLEEP] = __sys_nanosleep, #ifdef CONFIG_PROC_ENV [SYSCALL_BRK] = __sys_brk, @@ -88,9 +106,15 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, #ifdef CONFIG_IPC_SIGNAL +#ifdef SYSCALL_SIGACTION [SYSCALL_SIGACTION] = __sys_sigaction, +#endif + [SYSCALL_RT_SIGACTION] = __sys_rt_sigaction, [SYSCALL_KILL] = __sys_kill, +#ifdef SYSCALL_SIGRETURN [SYSCALL_SIGRETURN] = __sys_sigreturn, +#endif + [SYSCALL_RT_SIGRETURN] = __sys_rt_sigreturn, #endif #ifdef CONFIG_NET [SYSCALL_SOCKET] = __sys_socket, @@ -98,8 +122,12 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_LISTEN] = __sys_listen, [SYSCALL_ACCEPT] = __sys_accept, [SYSCALL_CONNECT] = __sys_connect, +#ifdef SYSCALL_RECV [SYSCALL_RECV] = __sys_recv, +#endif +#ifdef SYSCALL_SEND [SYSCALL_SEND] = __sys_send, +#endif [SYSCALL_SENDTO] = __sys_sendto, [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, From 089075023bda3ded645c50f5e5396eab881eb502 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Fri, 10 Oct 2025 15:04:31 +0200 Subject: [PATCH 19/69] correction after rebase --- so3/fs/vfs.c | 6 +++--- so3/ipc/pipe.c | 4 ++-- so3/ipc/signal.c | 4 ++-- so3/kernel/process.c | 2 +- so3/kernel/thread.c | 4 ++-- so3/kernel/timer.c | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index cac94cd2c..13fd99662 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -626,7 +626,7 @@ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned return -ENOSYS; } - return do_open(filename, flags, mode); + return sys_do_open(filename, flags, mode); } /* @@ -746,7 +746,7 @@ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) return -ENOSYS; } - return do_dup2(oldfd, newfd); + return sys_do_dup2(oldfd, newfd); } /** @@ -849,7 +849,7 @@ SYSCALL_DEFINE3(fstatat, const char *, path, struct stat64 *, st, int, flags) return -ENOSYS; } - ret = do_stat(path, &stat32); + ret = sys_do_stat(path, &stat32); if (ret < 0) { return ret; } diff --git a/so3/ipc/pipe.c b/so3/ipc/pipe.c index d40f62bb5..8efe9c7ca 100644 --- a/so3/ipc/pipe.c +++ b/so3/ipc/pipe.c @@ -19,8 +19,8 @@ #include #include -#include #include +#include #include #include #include @@ -319,5 +319,5 @@ SYSCALL_DEFINE2(pipe2, int *, pipefd, int, flags) return -ENOSYS; } - return do_pipe(pipefd); + return sys_do_pipe(pipefd); } diff --git a/so3/ipc/signal.c b/so3/ipc/signal.c index 4fa2347df..20371e85c 100644 --- a/so3/ipc/signal.c +++ b/so3/ipc/signal.c @@ -49,7 +49,7 @@ SYSCALL_DEFINE0(sigreturn) */ SYSCALL_DEFINE0(rt_sigreturn) { - return do_sigreturn(); + return sys_do_sigreturn(); } /** @@ -139,7 +139,7 @@ SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigactio return -EINVAL; } - return do_sigaction(signum, action, old_actionm); + return sys_do_sigaction(signum, action, old_actionm); } SYSCALL_DEFINE2(kill, int, pid, int, sig) diff --git a/so3/kernel/process.c b/so3/kernel/process.c index ed4bb838a..ba91a16e6 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -969,7 +969,7 @@ SYSCALL_DEFINE0(getpid) } /* - * Waitpid implementation via wait4 - do_wait4() does the following operations: + * Waitpid implementation via wait4 - sys_do_wait4() does the following operations: * - Suspend the current process until the child process finished its execution * (exit()) If the pid argument is -1, waitpid() looks for a possible terminated * process and performs the operation. If no process is finished (in zombie diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 363ec1520..51062add5 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -255,9 +255,9 @@ void thread_exit(int *exit_status) * According to the thread which is calling thread_exit(), the behaviour may differ. * Typically, if it is the main thread of the process, we have to wait until all * running threads (belonging to the process) are completed, and we pursue with - * do_exit(). + * sys_do_exit(). * - * - If pcb->state == PROC_STATE_ZOMBIE, it means we are called from do_exit() + * - If pcb->state == PROC_STATE_ZOMBIE, it means we are called from sys_do_exit() */ pcb = current()->pcb; diff --git a/so3/kernel/timer.c b/so3/kernel/timer.c index 7ff452d1e..075b39c70 100644 --- a/so3/kernel/timer.c +++ b/so3/kernel/timer.c @@ -409,7 +409,7 @@ SYSCALL_DEFINE2(gettimeofday_time32, struct timeval32 *, ts, void *, tz) { struct timeval time64; - long ret = do_gettimeofday(&time64, NULL); + long ret = sys_do_gettimeofday(&time64, NULL); if (ret < 0) { return ret; @@ -446,7 +446,7 @@ SYSCALL_DEFINE2(clock_gettime32, int, clk_id, struct timespec32 *, ts) { struct timespec time64; - long ret = do_clock_gettime(clk_id, &time64); + long ret = sys_do_clock_gettime(clk_id, &time64); if (ret < 0) { return ret; From b91c3661f8b1f58fa139fb1b5695c6c2816df8bc Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Fri, 10 Oct 2025 16:04:25 +0200 Subject: [PATCH 20/69] remove unwanted comment in syscall_number --- so3/arch/arm32/include/asm/syscall_number.h | 5 +---- so3/arch/arm64/include/asm/syscall_number.h | 5 +---- so3/fs/vfs.c | 10 ---------- so3/include/vfs.h | 1 - 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 11330a050..733c4ef9e 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -45,13 +45,11 @@ #define SYSCALL_PIPE 46 #define SYSCALL_IOCTL 54 -#define SYSCALL_FCNTL 55 // fcntl64? #define SYSCALL_DUP2 63 #define SYSCALL_SIGACTION 67 #define SYSCALL_GETTIMEOFDAY_TIME32 78 -// #define SYSCALL_SETTIMEOFDAY 79 // Implement? #define SYSCALL_STAT 106 @@ -96,13 +94,12 @@ #define SYSCALL_CLOCK_GETTIME64 403 -// => pthread +/* Following syscalls stills need to be align */ #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 #define SYSCALL_THREAD_EXIT 18 #define SYSCALL_THREAD_YIELD 43 -// => ??? #define SYSCALL_MUTEX_LOCK 60 #define SYSCALL_MUTEX_UNLOCK 61 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 2c318f7ba..302e27afe 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -25,8 +25,6 @@ #define SYSCALL_DUP 23 #define SYSCALL_DUP3 24 -#define SYSCALL_FCNTL 25 - #define SYSCALL_IOCTL 29 #define SYSCALL_OPENAT 56 @@ -78,7 +76,7 @@ #define SYSCALL_EXECVE 221 #define SYSCALL_MMAP 222 -// Does not exist +/* Following syscalls stills need to be align */ #define SYSCALL_FORK 7 // => clone #define SYSCALL_THREAD_CREATE 16 @@ -86,7 +84,6 @@ #define SYSCALL_THREAD_EXIT 18 #define SYSCALL_THREAD_YIELD 43 -// => ??? #define SYSCALL_MUTEX_LOCK 60 #define SYSCALL_MUTEX_UNLOCK 61 diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 13fd99662..c84b6c806 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -953,16 +953,6 @@ SYSCALL_DEFINE3(lseek, int, fd, off_t, off, int, whence) return rc; } -/* - * Implementation of the fcntl syscall - */ -SYSCALL_DEFINE3(fcntl, int, fd, unsigned long, cmd, unsigned long, args) -{ - /* Not yet implemented */ - - return 0; -} - /* * Implementation of the writev syscall */ diff --git a/so3/include/vfs.h b/so3/include/vfs.h index c460745a4..1dbaf4381 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -178,7 +178,6 @@ SYSCALL_DECLARE(fstatat, const char *path, struct stat64 *st, int flags); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); -SYSCALL_DECLARE(fcntl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); SYSCALL_DECLARE(readv, unsigned long fd, const struct iovec *vec, unsigned long vlen); From c9ca020479a788b5313f478f3bb5142b0d9a2700 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Fri, 10 Oct 2025 19:53:10 +0200 Subject: [PATCH 21/69] correct syscall arguments and numbers --- so3/arch/arm32/include/asm/syscall_number.h | 13 +- so3/arch/arm64/include/asm/syscall_number.h | 7 +- so3/fs/elf.c | 2 +- so3/fs/vfs.c | 148 +++++++++++++------- so3/include/dirent.h | 2 +- so3/include/net.h | 19 ++- so3/include/process.h | 2 +- so3/include/ptrace.h | 2 +- so3/include/signal.h | 1 - so3/include/stat.h | 44 +++--- so3/include/types.h | 4 +- so3/include/vfs.h | 17 ++- so3/ipc/signal.c | 17 +-- so3/kernel/process.c | 2 +- so3/kernel/ptrace.c | 2 +- so3/kernel/syscalls.c | 5 +- so3/net/net.c | 44 +++--- 17 files changed, 192 insertions(+), 139 deletions(-) diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h index 733c4ef9e..9f6552805 100644 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ b/so3/arch/arm32/include/asm/syscall_number.h @@ -40,18 +40,17 @@ #define SYSCALL_KILL 37 #define SYSCALL_DUP 41 +#define SYSCALL_PIPE 42 #define SYSCALL_BRK 45 -#define SYSCALL_PIPE 46 #define SYSCALL_IOCTL 54 #define SYSCALL_DUP2 63 -#define SYSCALL_SIGACTION 67 #define SYSCALL_GETTIMEOFDAY_TIME32 78 -#define SYSCALL_STAT 106 +#define SYSCALL_WAIT4 114 #define SYSCALL_SIGRETURN 119 @@ -65,9 +64,9 @@ #define SYSCALL_MMAP2 192 -#define SYSCALL_GETDENTS64 217 +#define SYSCALL_STAT64 195 -#define SYSCALL_WAIT4 260 +#define SYSCALL_GETDENTS64 217 #define SYSCALL_CLOCK_GETTIME32 263 @@ -87,14 +86,14 @@ #define SYSCALL_OPENAT 322 -#define SYSCALL_FSTATAT 327 +#define SYSCALL_FSTATAT64 327 #define SYSCALL_DUP3 358 #define SYSCALL_PIPE2 359 #define SYSCALL_CLOCK_GETTIME64 403 -/* Following syscalls stills need to be align */ +/* Following syscalls still need to be aligned */ #define SYSCALL_THREAD_CREATE 16 #define SYSCALL_THREAD_JOIN 17 #define SYSCALL_THREAD_EXIT 18 diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h index 302e27afe..be298b5f0 100644 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ b/so3/arch/arm64/include/asm/syscall_number.h @@ -39,14 +39,13 @@ #define SYSCALL_READV 65 #define SYSCALL_WRITEV 66 -#define SYSCALL_FSTATAT 79 +#define SYSCALL_NEWFSTATAT 79 #define SYSCALL_EXIT 93 #define SYSCALL_NANOSLEEP 101 #define SYSCALL_CLOCK_GETTIME 113 -#define SYSCALL_WAIT4 114 #define SYSCALL_PTRACE 117 @@ -76,7 +75,9 @@ #define SYSCALL_EXECVE 221 #define SYSCALL_MMAP 222 -/* Following syscalls stills need to be align */ +#define SYSCALL_WAIT4 260 + +/* Following syscalls still need to be aligned */ #define SYSCALL_FORK 7 // => clone #define SYSCALL_THREAD_CREATE 16 diff --git a/so3/fs/elf.c b/so3/fs/elf.c index a06d77fa1..c05309a6b 100644 --- a/so3/fs/elf.c +++ b/so3/fs/elf.c @@ -40,7 +40,7 @@ uint8_t *elf_load_buffer(const char *filename) if (fd < 0) return NULL; - if (sys_do_stat(filename, &st)) + if (sys_do_newfstatat(AT_FDCWD, filename, &st, 0)) return NULL; if (!st.st_size) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index c84b6c806..c1edd8ee1 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -33,6 +33,9 @@ #include #include +#include +#include + /* The VFS abstract subsystem manages a table of open file descriptors where indexes are known as gfd (global file descriptor). * Every process has its own file descriptor table. A local file descriptor (belonging to a process) must be linked to a global file descriptor * according to the fd type. @@ -381,7 +384,7 @@ int vfs_clone_fd(int *fd_src, int *fd_dst) /**************************** Syscall implementation ****************************/ /* Low Level read */ -static int do_read(int fd, void *buffer, int count) +static int do_read(int fd, void *buffer, size_t count) { int gfd; int ret; @@ -423,7 +426,7 @@ static int do_read(int fd, void *buffer, int count) } /* Low Level write */ -static int do_write(int fd, const void *buffer, int count) +static int do_write(int fd, const void *buffer, size_t count) { int gfd; int ret; @@ -532,7 +535,56 @@ static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t off return virt_addr; } -SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) +static long do_stat(const char *path, struct stat *st) +{ + int ret; + + memset(st, 0, sizeof(*st)); + + mutex_lock(&vfs_lock); + + /* FIXME Find the correct mount point with the path */ + if (!registered_fs_ops[FS_FAT]) { + mutex_unlock(&vfs_lock); + return -ENOENT; + } + + if (!registered_fs_ops[FS_FAT]->stat) { + mutex_unlock(&vfs_lock); + return -ENOENT; + } + + ret = registered_fs_ops[FS_FAT]->stat(path, st); + + mutex_unlock(&vfs_lock); + + return ret; +} + +static struct stat64 stat_to_stat64(struct stat *st) +{ + return (struct stat64) { + .st_dev = st->st_dev, + .__st_ino = st->st_ino, + .st_mode = st->st_mode, + .st_nlink = st->st_nlink, + .st_uid = st->st_uid, + .st_gid = st->st_gid, + .st_rdev = st->st_rdev, + .st_size = st->st_size, + .st_blksize = st->st_blksize, + .st_blocks = st->st_blocks, + .st_atime = st->st_atime, + .st_atime_nsec = st->st_atime_nsec, + .st_mtime = st->st_mtime, + .st_mtime_nsec = st->st_mtime_nsec, + .st_ctime = st->st_ctime, + .st_ctime_nsec = st->st_ctime_nsec, + .st_ino = st->st_ino, + }; +} + +SYSCALL_DEFINE3(read, int, fd, void *, buffer, size_t, count) { return do_read(fd, buffer, count); } @@ -540,7 +592,7 @@ SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count) /** * @brief This function writes a REGULAR FILE/FOLDER. It only support regular file, dirs and pipes */ -SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) +SYSCALL_DEFINE3(write, int, fd, const void *, buffer, size_t, count) { return do_write(fd, buffer, count); } @@ -548,7 +600,7 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count) /** * @brief This function opens a file. Not all file types are supported. */ -SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) +SYSCALL_DEFINE3(open, const char *, filename, int, flags, umode_t, mode) { int fd, gfd, ret = -1; uint32_t type; @@ -619,7 +671,7 @@ SYSCALL_DEFINE3(open, const char *, filename, int, flags, unsigned short, mode) /** * Simple openat implementation ignoring dirfd for aarch64. */ -SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned short, mode) +SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, umode_t, mode) { if (dirfd != AT_FDCWD) { LOG_WARNING("dirfd parameters isn't supported\n"); @@ -630,14 +682,20 @@ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, unsigned } /* - * @brief readdir read a directory entry which will be stored in a struct dirent entry + * @brief gedetens64 read a directory entry which will be stored in a struct dirent entry * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. */ -SYSCALL_DEFINE3(getdents64, int, fd, char *, buf, size_t, len) +SYSCALL_DEFINE3(getdents64, int, fd, struct dirent *, buf, size_t, count) { struct dirent *dirent; int gfd; + /* Dirent d_name should be a flexible array, which is not the case here. + So ensure that the given dirent can actually our full dirent. */ + if (count < sizeof(struct dirent)) { + return -EINVAL; + } + mutex_lock(&vfs_lock); gfd = vfs_get_gfd(fd); @@ -814,67 +872,57 @@ SYSCALL_DEFINE1(dup, int, oldfd) #endif } -SYSCALL_DEFINE2(stat, const char *, path, struct stat *, st) +SYSCALL_DEFINE2(stat64, const char *, path, struct stat64 *, st) { - int ret; + struct stat stat; + long ret = 0; - memset(st, 0, sizeof(*st)); + ret = do_stat(path, &stat); - mutex_lock(&vfs_lock); - - /* FIXME Find the correct mount point with the path */ - if (!registered_fs_ops[FS_FAT]) { - mutex_unlock(&vfs_lock); - return -ENOENT; + if (ret >= 0) { + *st = stat_to_stat64(&stat); } - if (!registered_fs_ops[FS_FAT]->stat) { - mutex_unlock(&vfs_lock); - return -ENOENT; - } - - ret = registered_fs_ops[FS_FAT]->stat(path, st); - - mutex_unlock(&vfs_lock); - return ret; } -SYSCALL_DEFINE3(fstatat, const char *, path, struct stat64 *, st, int, flags) +SYSCALL_DEFINE4(fstatat64, int, fd, const char *, path, struct stat64 *, st, int, flags) { - struct stat stat32; + struct stat stat; int ret; + + if (fd != AT_FDCWD) { + LOG_WARNING("fd parameters isn't supported\n"); + return -ENOSYS; + } + if (flags != 0) { LOG_WARNING("Flags not supported\n"); return -ENOSYS; } - ret = sys_do_stat(path, &stat32); - if (ret < 0) { - return ret; + ret = do_stat(path, &stat); + + if (ret >= 0) { + *st = stat_to_stat64(&stat); } - memset(st, 0, sizeof(*st)); + return ret; +} + +SYSCALL_DEFINE4(newfstatat, int, fd, const char *, path, struct stat *, st, int, flags) +{ + if (fd != AT_FDCWD) { + LOG_WARNING("fd parameters isn't supported\n"); + return -ENOSYS; + } - // Copy with extension from 32 bits to 64 bits - st->st_dev = stat32.st_dev; - st->st_ino = stat32.st_ino; - st->st_mode = stat32.st_mode; - st->st_nlink = stat32.st_nlink; - st->st_uid = stat32.st_uid; - st->st_gid = stat32.st_gid; - st->st_rdev = stat32.st_rdev; - st->st_size = stat32.st_size; - st->st_blksize = stat32.st_blksize; - st->st_blocks = stat32.st_blocks; - st->st_atime = stat32.st_atime; - st->st_atime_nsec = stat32.st_atime_nsec; - st->st_mtime = stat32.st_mtime; - st->st_mtime_nsec = stat32.st_mtime_nsec; - st->st_ctime = stat32.st_ctime; - st->st_ctime_nsec = stat32.st_ctime_nsec; + if (flags != 0) { + LOG_WARNING("Flags not supported\n"); + return -ENOSYS; + } - return 0; + return do_stat(path, st); } /** diff --git a/so3/include/dirent.h b/so3/include/dirent.h index c480e80b5..6c63cee25 100644 --- a/so3/include/dirent.h +++ b/so3/include/dirent.h @@ -22,7 +22,7 @@ #define DIRENT_H_ typedef uint64_t ino_t; -typedef uint32_t off_t; +typedef int64_t off_t; struct dirent { ino_t d_ino; diff --git a/so3/include/net.h b/so3/include/net.h index 52a97f27c..b527ddf8a 100644 --- a/so3/include/net.h +++ b/so3/include/net.h @@ -66,17 +66,26 @@ #define SIOCSIFHWBROADCAST 0x8937 #define SIOCGIFCOUNT 0x8938 +/* network address struct used by the userspace */ +struct usr_sockaddr_in { + u16 sin_family; + in_port_t sin_port; + struct in_addr sin_addr; + uint8_t sin_zero[8]; +}; + void net_init(void); SYSCALL_DECLARE(socket, int domain, int type, int protocol); -SYSCALL_DECLARE(connect, int sockfd, const struct sockaddr *name, socklen_t namelen); -SYSCALL_DECLARE(bind, int sockfd, const struct sockaddr *addr, socklen_t addrlen); +SYSCALL_DECLARE(connect, int sockfd, const struct usr_sockaddr_in *name, socklen_t namelen); +SYSCALL_DECLARE(bind, int sockfd, const struct usr_sockaddr_in *addr, socklen_t addrlen); SYSCALL_DECLARE(listen, int sockfd, int backlog); -SYSCALL_DECLARE(accept, int sockfd, struct sockaddr *addr, socklen_t *addrlen); +SYSCALL_DECLARE(accept, int sockfd, struct usr_sockaddr_in *addr, socklen_t *addrlen); SYSCALL_DECLARE(recv, int sockfd, void *mem, size_t len, int flags); -SYSCALL_DECLARE(recvfrom, int sockfd, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); +SYSCALL_DECLARE(recvfrom, int sockfd, void *mem, size_t len, int flags, struct usr_sockaddr_in *from, socklen_t *fromlen); SYSCALL_DECLARE(send, int sockfd, const void *dataptr, size_t size, int flags); -SYSCALL_DECLARE(sendto, int sockfd, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen); +SYSCALL_DECLARE(sendto, int sockfd, const void *dataptr, size_t size, int flags, const struct usr_sockaddr_in *to, + socklen_t tolen); SYSCALL_DECLARE(setsockopt, int sockfd, int level, int optname, const void *optval, socklen_t optlen); #endif /* NET_H */ diff --git a/so3/include/process.h b/so3/include/process.h index 62f2273f3..5b444deab 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -153,6 +153,6 @@ void dump_proc(void); extern int __exec(const char *file); extern int __write(int fd, char *buffer, int count); -SYSCALL_DECLARE(brk, int increment); +SYSCALL_DECLARE(brk, long increment); #endif /* PROCESS_H */ diff --git a/so3/include/ptrace.h b/so3/include/ptrace.h index e2b828721..b77dfa09d 100644 --- a/so3/include/ptrace.h +++ b/so3/include/ptrace.h @@ -208,7 +208,7 @@ struct ptrace_peeksiginfo_args { int32_t nr; }; -SYSCALL_DECLARE(ptrace, enum __ptrace_request request, uint32_t pid, void *addr, void *data); +SYSCALL_DECLARE(ptrace, enum __ptrace_request request, int pid, void *addr, void *data); struct pcb; struct user; diff --git a/so3/include/signal.h b/so3/include/signal.h index 0969ad23e..1feb49783 100644 --- a/so3/include/signal.h +++ b/so3/include/signal.h @@ -94,7 +94,6 @@ typedef struct __sigaction { sigaction_t *sa; } __sigaction_t; -SYSCALL_DECLARE(sigaction, int signum, const sigaction_t *action, sigaction_t *old_action); SYSCALL_DECLARE(rt_sigaction, int signum, const sigaction_t *action, sigaction_t *old_action, size_t sigsize); SYSCALL_DECLARE(kill, int pid, int sig); SYSCALL_DECLARE(sigreturn, void); diff --git a/so3/include/stat.h b/so3/include/stat.h index 03cd9694c..6aea97153 100644 --- a/so3/include/stat.h +++ b/so3/include/stat.h @@ -20,6 +20,9 @@ #ifndef STAT_H #define STAT_H +#include + +/* Stat structure copied from Linux include/uapi/asm-generic/stat.h */ struct stat { unsigned long st_dev; /* Device. */ unsigned long st_ino; /* File serial number. */ @@ -43,27 +46,28 @@ struct stat { unsigned int __unused5; }; +/* This is for ARM32 compatibility on ARM64 as 64bits version of stat will be called. + Adapted from arch/arm64/include/asm/stat.h */ struct stat64 { - unsigned long long st_dev; /* Device. */ - unsigned long long st_ino; /* File serial number. */ - unsigned int st_mode; /* File mode. */ - unsigned int st_nlink; /* Link count. */ - unsigned int st_uid; /* User ID of the file's owner. */ - unsigned int st_gid; /* Group ID of the file's group. */ - unsigned long long st_rdev; /* Device number, if device. */ - unsigned long long __pad1; - long long st_size; /* Size of file, in bytes. */ - int st_blksize; /* Optimal block size for I/O. */ - int __pad2; - long long st_blocks; /* Number 512-byte blocks allocated. */ - int st_atime; /* Time of last access. */ - unsigned int st_atime_nsec; - int st_mtime; /* Time of last modification. */ - unsigned int st_mtime_nsec; - int st_ctime; /* Time of last status change. */ - unsigned int st_ctime_nsec; - unsigned int __unused4; - unsigned int __unused5; + u64 st_dev; /* Device. */ + unsigned char __pad0[4]; + u32 __st_ino; /* File serial number. */ + u32 st_mode; /* File mode. */ + u32 st_nlink; /* Link count. */ + u32 st_uid; /* User ID of the file's owner. */ + u32 st_gid; /* Group ID of the file's group. */ + u64 st_rdev; /* Device number, if device. */ + unsigned char __pad3[4]; + s64 st_size; /* Size of file, in bytes. */ + u32 st_blksize; /* Optimal block size for I/O. */ + u64 st_blocks; /* Number 512-byte blocks allocated. */ + u32 st_atime; /* Time of last access. */ + u32 st_atime_nsec; + u32 st_mtime; /* Time of last modification. */ + u32 st_mtime_nsec; + u32 st_ctime; /* Time of last status change. */ + u32 st_ctime_nsec; + u64 st_ino; }; #endif /* STAT_H */ diff --git a/so3/include/types.h b/so3/include/types.h index b12fad6fd..75efc09fc 100644 --- a/so3/include/types.h +++ b/so3/include/types.h @@ -116,8 +116,8 @@ typedef __u32 __bitwise __wsum; typedef unsigned __bitwise__ gfp_t; -typedef u32 time32_t; -typedef u64 time_t; +typedef long time32_t; +typedef s64 time_t; #define ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1)) diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 1dbaf4381..7496a4054 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -108,8 +108,6 @@ #include #include -#include - struct iovec { void *iov_base; size_t iov_len; @@ -164,17 +162,18 @@ typedef enum { /* Syscall accessible from userspace */ -SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, unsigned short mode) -SYSCALL_DECLARE(open, const char *filename, int flags, unsigned short mode); -SYSCALL_DECLARE(read, int fd, void *buffer, int count); -SYSCALL_DECLARE(write, int fd, const void *buffer, int count); -SYSCALL_DECLARE(getdents64, int fd, char *buf, size_t count); +SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, umode_t mode) +SYSCALL_DECLARE(open, const char *filename, int flags, umode_t mode); +SYSCALL_DECLARE(read, int fd, void *buffer, size_t count); +SYSCALL_DECLARE(write, int fd, const void *buffer, size_t count); +SYSCALL_DECLARE(getdents64, int fd, struct dirent *buf, size_t count); SYSCALL_DECLARE(close, int fd); SYSCALL_DECLARE(dup, int oldfd); SYSCALL_DECLARE(dup2, int oldfd, int newfd); SYSCALL_DECLARE(dup3, int oldfd, int newfd, int flags); -SYSCALL_DECLARE(stat, const char *path, struct stat *st); -SYSCALL_DECLARE(fstatat, const char *path, struct stat64 *st, int flags); +SYSCALL_DECLARE(stat64, const char *path, struct stat64 *st); +SYSCALL_DECLARE(fstatat64, int fd, const char *filename, struct stat64 *statbuf, int flag); +SYSCALL_DECLARE(newfstatat, int fd, const char *filename, struct stat *statbuf, int flag); SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, off_t offset); SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); diff --git a/so3/ipc/signal.c b/so3/ipc/signal.c index 20371e85c..24de966a5 100644 --- a/so3/ipc/signal.c +++ b/so3/ipc/signal.c @@ -111,8 +111,13 @@ void __mem(int a, char *adr, int log) { } #endif /* 0 */ -SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_action) +SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_action, size_t, sigsize) { + if (sigsize != sizeof(sigset_t)) { + LOG_WARNING("Invalid sigset size\n"); + return -EINVAL; + } + if (signum < 0 || signum >= _NSIG) { LOG_ERROR("signum not valid!\n"); return -EINVAL; @@ -132,16 +137,6 @@ SYSCALL_DEFINE3(sigaction, int, signum, const sigaction_t *, action, sigaction_t return 0; } -SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigaction_t *, old_actionm, size_t, sigsize) -{ - if (sigsize != sizeof(sigset_t)) { - LOG_WARNING("Invalid sigset size\n"); - return -EINVAL; - } - - return sys_do_sigaction(signum, action, old_actionm); -} - SYSCALL_DEFINE2(kill, int, pid, int, sig) { pcb_t *proc; diff --git a/so3/kernel/process.c b/so3/kernel/process.c index ba91a16e6..13ec54092 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -1090,7 +1090,7 @@ SYSCALL_DEFINE4(wait4, int, pid, uint32_t *, wstatus, uint32_t, options, void *, * @return This function will the position of the end of the heap / program *break before increment */ -SYSCALL_DEFINE1(brk, int, increment) +SYSCALL_DEFINE1(brk, long, increment) { pcb_t *pcb = current()->pcb; int ret_pointer; diff --git a/so3/kernel/ptrace.c b/so3/kernel/ptrace.c index 8750f6667..3a30ef729 100644 --- a/so3/kernel/ptrace.c +++ b/so3/kernel/ptrace.c @@ -64,7 +64,7 @@ void __check_ptrace_syscall(void) /* * Implementation of ptrace syscall */ -SYSCALL_DEFINE4(ptrace, enum __ptrace_request, request, uint32_t, pid, void *, addr, void *, data) +SYSCALL_DEFINE4(ptrace, enum __ptrace_request, request, int, pid, void *, addr, void *, data) { pcb_t *pcb; diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 50fe271b2..2d3f2acdf 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -35,9 +35,10 @@ extern uint32_t __get_syscall_stack_arg(uint32_t nr); extern void test_malloc(int test_no); +#warning Not updated, a rework is needed to avoid having a big array because of #ifdef ... static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [0 ... NR_SYSCALLS - 1] = NULL, - + /* #ifdef CONFIG_MMU [SYSCALL_GETPID] = __sys_getpid, #ifdef SYSCALL_GETTIMEOFDAY @@ -74,7 +75,6 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_THREAD_YIELD] = __sys_thread_yield, [SYSCALL_GETDENTS64] = __sys_getdents64, [SYSCALL_IOCTL] = __sys_ioctl, - [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, [SYSCALL_READV] = __sys_readv, [SYSCALL_WRITEV] = __sys_writev, @@ -132,6 +132,7 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, #endif +*/ }; /* diff --git a/so3/net/net.c b/so3/net/net.c index d638f0797..21effb26c 100644 --- a/so3/net/net.c +++ b/so3/net/net.c @@ -134,29 +134,21 @@ struct ifreq2 { } ifr_ifru; }; -/* network address struct used by the userspace */ -struct sockaddr_in_usr { - u16 sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - uint8_t sin_zero[8]; -}; - /** * Adapt a userspace sockaddr to a lwip one. * Iwip sockaddr have a sa_len field as first byte * @param usr * @param lwip */ -struct sockaddr *user_to_lwip_sockadd(struct sockaddr_in_usr *usr, struct sockaddr_in *lwip) +struct sockaddr *user_to_lwip_sockadd(const struct usr_sockaddr_in *usr, struct sockaddr_in *lwip) { if (usr == NULL) { return NULL; } - memset(lwip, 0, sizeof(struct sockaddr)); + memset(lwip, 0, sizeof(struct sockaddr_in)); - lwip->sin_len = sizeof(struct sockaddr); + lwip->sin_len = sizeof(struct sockaddr_in); lwip->sin_family = usr->sin_family; lwip->sin_port = usr->sin_port; lwip->sin_addr = usr->sin_addr; @@ -424,7 +416,7 @@ SYSCALL_DEFINE3(socket, int, domain, int, type, int, protocol) return fd; } -SYSCALL_DEFINE3(connect, int, sockfd, const struct sockaddr *, addr, socklen_t, namelen) +SYSCALL_DEFINE3(connect, int, sockfd, const struct usr_sockaddr_in *, addr, socklen_t, namelen) { int ret; struct sockaddr_in addr_lwip; @@ -436,13 +428,13 @@ SYSCALL_DEFINE3(connect, int, sockfd, const struct sockaddr *, addr, socklen_t, return -EBADF; } - addr_ptr = user_to_lwip_sockadd((struct sockaddr_in_usr *) addr, &addr_lwip); + addr_ptr = user_to_lwip_sockadd(addr, &addr_lwip); ret = lwip_connect(lwip_fd, addr_ptr, namelen); return lwip_return(ret); } -SYSCALL_DEFINE3(bind, int, sockfd, const struct sockaddr *, addr, socklen_t, addrlen) +SYSCALL_DEFINE3(bind, int, sockfd, const struct usr_sockaddr_in *, addr, socklen_t, addrlen) { int ret; struct sockaddr_in addr_lwip; @@ -454,7 +446,7 @@ SYSCALL_DEFINE3(bind, int, sockfd, const struct sockaddr *, addr, socklen_t, add return -EBADF; } - addr_ptr = user_to_lwip_sockadd((struct sockaddr_in_usr *) addr, &addr_lwip); + addr_ptr = user_to_lwip_sockadd(addr, &addr_lwip); ret = lwip_bind(lwip_fd, addr_ptr, addrlen); return lwip_return(ret); @@ -473,7 +465,7 @@ SYSCALL_DEFINE2(listen, int, sockfd, int, backlog) return lwip_return(ret); } -SYSCALL_DEFINE3(accept, int, sockfd, struct sockaddr *, addr, socklen_t *, addrlen) +SYSCALL_DEFINE3(accept, int, sockfd, struct usr_sockaddr_in *, addr, socklen_t *, addrlen) { int fd, gfd, lwip_fd, lwip_bind_fd; struct file_operations *fops; @@ -485,7 +477,7 @@ SYSCALL_DEFINE3(accept, int, sockfd, struct sockaddr *, addr, socklen_t *, addrl return -EBADF; } - addr_ptr = user_to_lwip_sockadd((struct sockaddr_in_usr *) addr, &addr_lwip); + addr_ptr = user_to_lwip_sockadd(addr, &addr_lwip); fops = register_sock(); @@ -532,16 +524,21 @@ SYSCALL_DEFINE4(recv, int, sockfd, void *, mem, size_t, len, int, flags) return lwip_return(ret); } -SYSCALL_DEFINE6(recvfrom, int, sockfd, void *, mem, size_t, len, int, flags, struct sockaddr *, from, socklen_t *, fromlen) +SYSCALL_DEFINE6(recvfrom, int, sockfd, void *, mem, size_t, len, int, flags, struct usr_sockaddr_in *, from, socklen_t *, + fromlen) { int ret; + struct sockaddr_in from_lwip; + struct sockaddr *from_ptr; int lwip_fd = get_lwip_fd(sockfd); if (lwip_fd < 0) { return -EBADF; } - ret = lwip_recvfrom(lwip_fd, mem, len, flags, from, fromlen); + from_ptr = user_to_lwip_sockadd(from, &from_lwip); + + ret = lwip_recvfrom(lwip_fd, mem, len, flags, from_ptr, fromlen); return lwip_return(ret); } @@ -558,20 +555,21 @@ SYSCALL_DEFINE4(send, int, sockfd, const void *, dataptr, size_t, size, int, fla return lwip_return(ret); } -SYSCALL_DEFINE6(sendto, int, sockfd, const void *, dataptr, size_t, size, int, flags, const struct sockaddr *, to, socklen_t, - tolen) +SYSCALL_DEFINE6(sendto, int, sockfd, const void *, dataptr, size_t, size, int, flags, const struct usr_sockaddr_in *, to, + socklen_t, tolen) { int ret; struct sockaddr_in to_lwip; + struct sockaddr *to_ptr; int lwip_fd = get_lwip_fd(sockfd); if (lwip_fd < 0) { return -EBADF; } - user_to_lwip_sockadd((struct sockaddr_in_usr *) to, &to_lwip); + to_ptr = user_to_lwip_sockadd(to, &to_lwip); - ret = lwip_sendto(lwip_fd, dataptr, size, flags, (struct sockaddr *) &to_lwip, tolen); + ret = lwip_sendto(lwip_fd, dataptr, size, flags, to_ptr, tolen); return lwip_return(ret); } From a50e08ce5ef5d1a07f581f22ade88d9de270f5e2 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 13 Oct 2025 11:45:41 +0200 Subject: [PATCH 22/69] cleanups --- so3/fs/vfs.c | 46 +++++++++++++++++++++++++++----- so3/include/device/timer.h | 22 +++++++++------- so3/include/stat.h | 48 +++++++++++++++++----------------- so3/include/vfs.h | 9 ++++--- so3/kernel/syscalls.c | 46 +++----------------------------- usr/lib/libc/crt0.S | 1 + usr/lib/libc/include/syscall.h | 8 ++++++ 7 files changed, 95 insertions(+), 85 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index c1edd8ee1..485eb4f12 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -535,6 +535,9 @@ static int do_mmap_anon(int fd, addr_t virt_addr, uint32_t page_count, off_t off return virt_addr; } +/** + * @brief Low level stat implementation. + */ static long do_stat(const char *path, struct stat *st) { int ret; @@ -561,6 +564,9 @@ static long do_stat(const char *path, struct stat *st) return ret; } +/** + * @brief Function to convert stat to stat64 for ARM32 compatibility. + */ static struct stat64 stat_to_stat64(struct stat *st) { return (struct stat64) { @@ -600,7 +606,7 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, size_t, count) /** * @brief This function opens a file. Not all file types are supported. */ -SYSCALL_DEFINE3(open, const char *, filename, int, flags, umode_t, mode) +SYSCALL_DEFINE3(open, const char *, filename, int, flags, mode_t, mode) { int fd, gfd, ret = -1; uint32_t type; @@ -669,9 +675,9 @@ SYSCALL_DEFINE3(open, const char *, filename, int, flags, umode_t, mode) } /** - * Simple openat implementation ignoring dirfd for aarch64. + * @brief Simple openat implementation ignoring dirfd for aarch64. */ -SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, umode_t, mode) +SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, mode_t, mode) { if (dirfd != AT_FDCWD) { LOG_WARNING("dirfd parameters isn't supported\n"); @@ -682,7 +688,8 @@ SYSCALL_DEFINE4(openat, int, dirfd, const char *, filename, int, flags, umode_t, } /* - * @brief gedetens64 read a directory entry which will be stored in a struct dirent entry + * @brief gedetens64 read a directory entry which will be stored in a struct dirent entry. + * This is used for readdir on userspace. * @param fd This is the file descriptor provided as (DIR *) when doing opendir in the userspace. */ SYSCALL_DEFINE3(getdents64, int, fd, struct dirent *, buf, size_t, count) @@ -791,7 +798,7 @@ SYSCALL_DEFINE1(close, int, fd) } /** - * Simple dup3 implementation ignoring flags for aarch64. + * @brief Simple dup3 implementation ignoring flags for aarch64. */ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) { @@ -809,7 +816,6 @@ SYSCALL_DEFINE3(dup3, int, oldfd, int, newfd, int, flags) /** * @brief dup2 creates a synonym of oldfd on newfd - * */ SYSCALL_DEFINE2(dup2, int, oldfd, int, newfd) { @@ -872,6 +878,9 @@ SYSCALL_DEFINE1(dup, int, oldfd) #endif } +/** + * @brief On ARM32, stat64 syscall is called instead of stat. + */ SYSCALL_DEFINE2(stat64, const char *, path, struct stat64 *, st) { struct stat stat; @@ -886,6 +895,9 @@ SYSCALL_DEFINE2(stat64, const char *, path, struct stat64 *, st) return ret; } +/** + * @brief On ARM32, fstatat64 syscall is called instead of fstatat and stat in some condition. + */ SYSCALL_DEFINE4(fstatat64, int, fd, const char *, path, struct stat64 *, st, int, flags) { struct stat stat; @@ -910,6 +922,9 @@ SYSCALL_DEFINE4(fstatat64, int, fd, const char *, path, struct stat64 *, st, int return ret; } +/** + * @brief On aarch64, newfstatat syscall is called for stat. + */ SYSCALL_DEFINE4(newfstatat, int, fd, const char *, path, struct stat *, st, int, flags) { if (fd != AT_FDCWD) { @@ -1001,6 +1016,25 @@ SYSCALL_DEFINE3(lseek, int, fd, off_t, off, int, whence) return rc; } +/** + * @brief Implementation of llseek syscall for ARM32 which use it instead of lseek. + */ +SYSCALL_DEFINE5(llseek, int, fd, unsigned long, offset_high, unsigned long, offset_low, off_t *, result, unsigned, whence) +{ + off_t offset = ((off_t) offset_high << 32) | offset_low; + off_t ret; + + ret = sys_do_lseek(fd, offset, whence); + + if (ret >= 0) { + /* New offset is returned in the 64 bits of result. */ + *result = ret; + ret = 0; + } + + return ret; +} + /* * Implementation of the writev syscall */ diff --git a/so3/include/device/timer.h b/so3/include/device/timer.h index e8c213cb6..cdca9f822 100644 --- a/so3/include/device/timer.h +++ b/so3/include/device/timer.h @@ -27,26 +27,28 @@ /* Time conversion units */ -struct timespec32 { - time32_t tv_sec; /* seconds */ - time32_t tv_nsec; /* nanoseconds */ -}; - struct timespec { time_t tv_sec; /* seconds */ time_t tv_nsec; /* nanoseconds */ }; -struct timeval32 { - time32_t tv_sec; /* seconds */ - time32_t tv_usec; /* microseconds */ -}; - struct timeval { time_t tv_sec; /* seconds */ time_t tv_usec; /* microseconds */ }; +/* Time conversion units - ARM32 compatibility. */ + +struct timespec32 { + time32_t tv_sec; /* seconds */ + time32_t tv_nsec; /* nanoseconds */ +}; + +struct timeval32 { + time32_t tv_sec; /* seconds */ + time32_t tv_usec; /* microseconds */ +}; + /* All timing information below must be express in nanoseconds. The underlying hardware is responsible * to perform the necessary alignment on 64 bits. */ diff --git a/so3/include/stat.h b/so3/include/stat.h index 6aea97153..835b7d896 100644 --- a/so3/include/stat.h +++ b/so3/include/stat.h @@ -24,48 +24,48 @@ /* Stat structure copied from Linux include/uapi/asm-generic/stat.h */ struct stat { - unsigned long st_dev; /* Device. */ - unsigned long st_ino; /* File serial number. */ - unsigned int st_mode; /* File mode. */ - unsigned int st_nlink; /* Link count. */ - unsigned int st_uid; /* User ID of the file's owner. */ + unsigned long st_dev; /* Device. */ + unsigned long st_ino; /* File serial number. */ + unsigned int st_mode; /* File mode. */ + unsigned int st_nlink; /* Link count. */ + unsigned int st_uid; /* User ID of the file's owner. */ unsigned int st_gid; /* Group ID of the file's group. */ - unsigned long st_rdev; /* Device number, if device. */ + unsigned long st_rdev; /* Device number, if device. */ unsigned long __pad1; - long st_size; /* Size of file, in bytes. */ - int st_blksize; /* Optimal block size for I/O. */ + long st_size; /* Size of file, in bytes. */ + int st_blksize; /* Optimal block size for I/O. */ int __pad2; long st_blocks; /* Number 512-byte blocks allocated. */ - long st_atime; /* Time of last access. */ + long st_atime; /* Time of last access. */ unsigned long st_atime_nsec; - long st_mtime; /* Time of last modification. */ + long st_mtime; /* Time of last modification. */ unsigned long st_mtime_nsec; - long st_ctime; /* Time of last status change. */ + long st_ctime; /* Time of last status change. */ unsigned long st_ctime_nsec; unsigned int __unused4; unsigned int __unused5; }; -/* This is for ARM32 compatibility on ARM64 as 64bits version of stat will be called. - Adapted from arch/arm64/include/asm/stat.h */ +/* This is for ARM32 compatibility as 64bits version of stat will be called. + Adapted from arch/arm64/include/asm/stat.h on Linux */ struct stat64 { - u64 st_dev; /* Device. */ + u64 st_dev; /* Device. */ unsigned char __pad0[4]; - u32 __st_ino; /* File serial number. */ - u32 st_mode; /* File mode. */ - u32 st_nlink; /* Link count. */ - u32 st_uid; /* User ID of the file's owner. */ + u32 __st_ino; /* File serial number. */ + u32 st_mode; /* File mode. */ + u32 st_nlink; /* Link count. */ + u32 st_uid; /* User ID of the file's owner. */ u32 st_gid; /* Group ID of the file's group. */ - u64 st_rdev; /* Device number, if device. */ + u64 st_rdev; /* Device number, if device. */ unsigned char __pad3[4]; - s64 st_size; /* Size of file, in bytes. */ - u32 st_blksize; /* Optimal block size for I/O. */ + s64 st_size; /* Size of file, in bytes. */ + u32 st_blksize; /* Optimal block size for I/O. */ u64 st_blocks; /* Number 512-byte blocks allocated. */ - u32 st_atime; /* Time of last access. */ + u32 st_atime; /* Time of last access. */ u32 st_atime_nsec; - u32 st_mtime; /* Time of last modification. */ + u32 st_mtime; /* Time of last modification. */ u32 st_mtime_nsec; - u32 st_ctime; /* Time of last status change. */ + u32 st_ctime; /* Time of last status change. */ u32 st_ctime_nsec; u64 st_ino; }; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index 7496a4054..e67bde3d6 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -1,7 +1,7 @@ /* * Copyright (C) 2014-2019 Daniel Rossier * Copyright (C) 2017 Xavier Ruppen - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -108,6 +108,8 @@ #include #include +typedef uint32_t mode_t; + struct iovec { void *iov_base; size_t iov_len; @@ -162,8 +164,8 @@ typedef enum { /* Syscall accessible from userspace */ -SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, umode_t mode) -SYSCALL_DECLARE(open, const char *filename, int flags, umode_t mode); +SYSCALL_DECLARE(openat, int dirfd, const char *filename, int flags, mode_t mode) +SYSCALL_DECLARE(open, const char *filename, int flags, mode_t mode); SYSCALL_DECLARE(read, int fd, void *buffer, size_t count); SYSCALL_DECLARE(write, int fd, const void *buffer, size_t count); SYSCALL_DECLARE(getdents64, int fd, struct dirent *buf, size_t count); @@ -178,6 +180,7 @@ SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); +SYSCALL_DECLARE(llseek, int fd, unsigned long offset_high, unsigned long offset_low, off_t *result, unsigned whence); SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); SYSCALL_DECLARE(readv, unsigned long fd, const struct iovec *vec, unsigned long vlen); diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index 2d3f2acdf..d87c60098 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -41,80 +41,45 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { /* #ifdef CONFIG_MMU [SYSCALL_GETPID] = __sys_getpid, -#ifdef SYSCALL_GETTIMEOFDAY [SYSCALL_GETTIMEOFDAY] = __sys_gettimeofday, -#endif -#ifdef SYSCALL_GETTIMEOFDAY_TIME32 - [SYSCALL_GETTIMEOFDAY_TIME32] = __sys_gettimeofday_time32, -#endif -#ifdef SYSCALL_CLOCK_GETTIME [SYSCALL_CLOCK_GETTIME] = __sys_clock_gettime, -#endif -#ifdef SYSCALL_CLOCK_GETTIME32 - [SYSCALL_CLOCK_GETTIME32] = __sys_clock_gettime32, -#endif [SYSCALL_EXIT] = __sys_exit, [SYSCALL_EXECVE] = __sys_execve, [SYSCALL_FORK] = __sys_fork, -#ifdef SYSCALL_WAITPID [SYSCALL_WAITPID] = __sys_waitpid, -#endif - [SYSCALL_WAIT4] = __sys_wait4, [SYSCALL_PTRACE] = __sys_ptrace, #endif [SYSCALL_READ] = __sys_read, [SYSCALL_WRITE] = __sys_write, -#ifdef SYSCALL_OPEN [SYSCALL_OPEN] = __sys_open, -#endif - [SYSCALL_OPENAT] = __sys_openat, [SYSCALL_CLOSE] = __sys_close, [SYSCALL_THREAD_CREATE] = __sys_thread_create, [SYSCALL_THREAD_JOIN] = __sys_thread_join, [SYSCALL_THREAD_EXIT] = __sys_thread_exit, [SYSCALL_THREAD_YIELD] = __sys_thread_yield, - [SYSCALL_GETDENTS64] = __sys_getdents64, + [SYSCALL_READDIR] = __sys_readdir, [SYSCALL_IOCTL] = __sys_ioctl, + [SYSCALL_FCNTL] = __sys_fcntl, [SYSCALL_LSEEK] = __sys_lseek, [SYSCALL_READV] = __sys_readv, [SYSCALL_WRITEV] = __sys_writev, #ifdef CONFIG_IPC_PIPE -#ifdef SYSCALL_PIPE [SYSCALL_PIPE] = __sys_pipe, -#endif - [SYSCALL_PIPE2] = __sys_pipe2, #endif [SYSCALL_DUP] = __sys_dup, -#ifdef SYSCALL_DUP2 [SYSCALL_DUP2] = __sys_dup2, -#endif - [SYSCALL_DUP3] = __sys_dup3, -#ifdef SYSCALL_STAT [SYSCALL_STAT] = __sys_stat, -#endif - [SYSCALL_FSTATAT] = __sys_fstatat, -#ifdef SYSCALL_MMAP [SYSCALL_MMAP] = __sys_mmap, -#endif -#ifdef SYSCALL_MMAP2 - [SYSCALL_MMAP2] = __sys_mmap2, -#endif [SYSCALL_NANOSLEEP] = __sys_nanosleep, #ifdef CONFIG_PROC_ENV - [SYSCALL_BRK] = __sys_brk, + [SYSCALL_SBRK] = __sys_sbrk, #endif [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, #ifdef CONFIG_IPC_SIGNAL -#ifdef SYSCALL_SIGACTION [SYSCALL_SIGACTION] = __sys_sigaction, -#endif - [SYSCALL_RT_SIGACTION] = __sys_rt_sigaction, [SYSCALL_KILL] = __sys_kill, -#ifdef SYSCALL_SIGRETURN [SYSCALL_SIGRETURN] = __sys_sigreturn, -#endif - [SYSCALL_RT_SIGRETURN] = __sys_rt_sigreturn, #endif #ifdef CONFIG_NET [SYSCALL_SOCKET] = __sys_socket, @@ -122,16 +87,13 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [SYSCALL_LISTEN] = __sys_listen, [SYSCALL_ACCEPT] = __sys_accept, [SYSCALL_CONNECT] = __sys_connect, -#ifdef SYSCALL_RECV [SYSCALL_RECV] = __sys_recv, -#endif -#ifdef SYSCALL_SEND [SYSCALL_SEND] = __sys_send, -#endif [SYSCALL_SENDTO] = __sys_sendto, [SYSCALL_SETSOCKOPT] = __sys_setsockopt, [SYSCALL_RECVFROM] = __sys_recvfrom, #endif + [SYSCALL_SYSINFO] = __sys_sysinfo, */ }; diff --git a/usr/lib/libc/crt0.S b/usr/lib/libc/crt0.S index f8f1ea080..22ba5aeda 100755 --- a/usr/lib/libc/crt0.S +++ b/usr/lib/libc/crt0.S @@ -164,6 +164,7 @@ SYSCALLSTUB sys_settimeofday, syscallSetTimeOfDay 2 SYSCALLSTUB sys_clock_gettime, syscallClockGetTime 2 SYSCALLSTUB sys_sbrk, syscallSbrk 1 +SYSCALLSTUB sys_info, syscallSysinfo 2 SYSCALLSTUB sys_lseek, syscallLseek 3 diff --git a/usr/lib/libc/include/syscall.h b/usr/lib/libc/include/syscall.h index 65299ad58..2426d2bd4 100644 --- a/usr/lib/libc/include/syscall.h +++ b/usr/lib/libc/include/syscall.h @@ -88,9 +88,17 @@ #define syscallNanosleep 70 +#define syscallSysinfo 99 + #define syscallSetsockopt 110 #define syscallRecvfrom 111 + +#define SYSINFO_DUMP_HEAP 0 +#define SYSINFO_DUMP_SCHED 1 +#define SYSINFO_TEST_MALLOC 2 +#define SYSINFO_PRINTK 3 + #ifndef __ASSEMBLY__ #include From 9d8fd89a7cf64e7c505b0969b82a40b73d0e37e0 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 13 Oct 2025 19:05:38 +0200 Subject: [PATCH 23/69] rename llseek to _llseek --- so3/fs/vfs.c | 2 +- so3/include/vfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/so3/fs/vfs.c b/so3/fs/vfs.c index 485eb4f12..5f7f76dff 100644 --- a/so3/fs/vfs.c +++ b/so3/fs/vfs.c @@ -1019,7 +1019,7 @@ SYSCALL_DEFINE3(lseek, int, fd, off_t, off, int, whence) /** * @brief Implementation of llseek syscall for ARM32 which use it instead of lseek. */ -SYSCALL_DEFINE5(llseek, int, fd, unsigned long, offset_high, unsigned long, offset_low, off_t *, result, unsigned, whence) +SYSCALL_DEFINE5(_llseek, int, fd, unsigned long, offset_high, unsigned long, offset_low, off_t *, result, unsigned, whence) { off_t offset = ((off_t) offset_high << 32) | offset_low; off_t ret; diff --git a/so3/include/vfs.h b/so3/include/vfs.h index e67bde3d6..5c72e7208 100644 --- a/so3/include/vfs.h +++ b/so3/include/vfs.h @@ -180,7 +180,7 @@ SYSCALL_DECLARE(mmap, addr_t start, size_t length, int prot, int flags, int fd, SYSCALL_DECLARE(mmap2, addr_t start, size_t length, int prot, int flags, int fd, off_t pgoffset); SYSCALL_DECLARE(ioctl, int fd, unsigned long cmd, unsigned long args); SYSCALL_DECLARE(lseek, int fd, off_t off, int whence); -SYSCALL_DECLARE(llseek, int fd, unsigned long offset_high, unsigned long offset_low, off_t *result, unsigned whence); +SYSCALL_DECLARE(_llseek, int fd, unsigned long offset_high, unsigned long offset_low, off_t *result, unsigned whence); SYSCALL_DECLARE(writev, unsigned long fd, const struct iovec *vec, unsigned long vlen); SYSCALL_DECLARE(readv, unsigned long fd, const struct iovec *vec, unsigned long vlen); From d0a7017beef04771a1c0b44b5ca9fb5884ff611e Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 13 Oct 2025 18:38:31 +0200 Subject: [PATCH 24/69] autogenerate syscall table --- so3/Kbuild | 27 +- so3/arch/arm32/context.S | 4 +- so3/arch/arm32/exception.S | 6 +- so3/arch/arm32/include/asm/syscall_number.h | 105 ----- so3/arch/arm32/syscall.h.in | 420 ++++++++++++++++++++ so3/arch/arm64/context.S | 6 +- so3/arch/arm64/exception.S | 2 +- so3/arch/arm64/include/asm/syscall_number.h | 91 ----- so3/arch/arm64/syscall.h.in | 312 +++++++++++++++ so3/include/syscall.h | 2 +- so3/kernel/syscalls.c | 65 +-- so3/scripts/syscall_gen.sh | 115 ++++++ so3/syscall.tbl | 66 +++ 13 files changed, 947 insertions(+), 274 deletions(-) delete mode 100644 so3/arch/arm32/include/asm/syscall_number.h create mode 100644 so3/arch/arm32/syscall.h.in delete mode 100644 so3/arch/arm64/include/asm/syscall_number.h create mode 100644 so3/arch/arm64/syscall.h.in create mode 100755 so3/scripts/syscall_gen.sh create mode 100644 so3/syscall.tbl diff --git a/so3/Kbuild b/so3/Kbuild index c809513d1..fcea8718a 100644 --- a/so3/Kbuild +++ b/so3/Kbuild @@ -2,15 +2,31 @@ # Kbuild for top-level directory of the kernel # This file takes care of the following: -# Generate asm-offsets.h +# Generate syscall_table.h.in and syscall_number.h + +syscall-files = include/generated/syscall_table.h.in +syscall-files += include/generated/syscall_number.h +syscall-script = scripts/syscall_gen.sh +syscall-src = syscall.tbl arch/$(SRCARCH)/syscall.h.in + +quiet_cmd_syscall_gen = GEN $@ + cmd_syscall_gen = $(syscall-script) $(syscall-src) $(syscall-files) + +$(syscall-files) &: $(syscall-script) $(syscall-src) Kbuild FORCE + $(call if_changed,syscall_gen) + +always := $(syscall-files) +targets := $(syscall-files) + +# Generate asm-offsets.h # offsets-file := include/generated/asm-offsets.h -always := $(offsets-file) -targets := $(offsets-file) +always += $(offsets-file) +targets += $(offsets-file) targets += arch/$(SRCARCH)/asm-offsets.s - + # Default sed regexp - multiline due to syntax constraints define sed-y "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}" @@ -34,10 +50,9 @@ define cmd_offsets endef # We use internal kbuild rules to avoid the "is up to date" message from make -arch/$(SRCARCH)/asm-offsets.s: $(srctree)/arch/$(SRCARCH)/asm-offsets.c FORCE +arch/$(SRCARCH)/asm-offsets.s: $(srctree)/arch/$(SRCARCH)/asm-offsets.c include/generated/syscall_number.h FORCE $(Q)mkdir -p $(dir $@) $(call if_changed_dep,cc_s_c) $(offsets-file): arch/$(SRCARCH)/asm-offsets.s Kbuild $(call cmd,offsets) - diff --git a/so3/arch/arm32/context.S b/so3/arch/arm32/context.S index 3b20ef879..5e4f3b0a6 100644 --- a/so3/arch/arm32/context.S +++ b/so3/arch/arm32/context.S @@ -272,7 +272,7 @@ ENTRY(__root_proc) mov r0, #STDOUT adr r1, .LC_welcome mov r2, #welcome_len - mov r7, #SYSCALL_WRITE + mov r7, #SYSCALL_write @ Invoke the syscall - kernel side svc 0 @@ -282,6 +282,6 @@ ENTRY(__root_proc) mov r1, #0 mov r2, #0 - mov r7, #SYSCALL_EXECVE + mov r7, #SYSCALL_execve svc 0 diff --git a/so3/arch/arm32/exception.S b/so3/arch/arm32/exception.S index 02d03537b..6f7ac347a 100644 --- a/so3/arch/arm32/exception.S +++ b/so3/arch/arm32/exception.S @@ -199,7 +199,7 @@ syscall_interrupt: add lr, sp, #OFFSET_SP_USR stmia lr, {sp, lr}^ - cmp r7, #SYSCALL_SIGRETURN + cmp r7, #SYSCALL_sigreturn beq __after_push_sp_usr ldr r0, [sp, #OFFSET_SP_USR] @@ -228,7 +228,7 @@ __after_push_sp_usr: @ Check if sigreturn has been called. In this case, we @ clean the stack frame which has been used to manage the user handler. - cmp r7, #SYSCALL_SIGRETURN + cmp r7, #SYSCALL_sigreturn bne __no_sigreturn @ Reset the stack frame by removing the one issued from sigreturn @@ -246,7 +246,7 @@ __no_sigreturn: __ret_from_fork: @ Store the return value on the stack frame - cmp r7, #SYSCALL_SIGRETURN + cmp r7, #SYSCALL_sigreturn strne r0, [sp, #OFFSET_R0] #ifdef CONFIG_IPC_SIGNAL diff --git a/so3/arch/arm32/include/asm/syscall_number.h b/so3/arch/arm32/include/asm/syscall_number.h deleted file mode 100644 index 9f6552805..000000000 --- a/so3/arch/arm32/include/asm/syscall_number.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2025 Clement Dieperink - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef ARCH_ARM32_SYSCALL_NUMBER_H -#define ARCH_ARM32_SYSCALL_NUMBER_H - -/* - * Syscall number definition - */ - -#define SYSCALL_EXIT 1 -#define SYSCALL_FORK 2 -#define SYSCALL_READ 3 -#define SYSCALL_WRITE 4 -#define SYSCALL_OPEN 5 -#define SYSCALL_CLOSE 6 - -#define SYSCALL_EXECVE 11 - -#define SYSCALL_LSEEK 19 -#define SYSCALL_GETPID 20 - -#define SYSCALL_PTRACE 26 - -#define SYSCALL_KILL 37 - -#define SYSCALL_DUP 41 -#define SYSCALL_PIPE 42 - -#define SYSCALL_BRK 45 - -#define SYSCALL_IOCTL 54 - -#define SYSCALL_DUP2 63 - -#define SYSCALL_GETTIMEOFDAY_TIME32 78 - -#define SYSCALL_WAIT4 114 - -#define SYSCALL_SIGRETURN 119 - -#define SYSCALL_READV 145 -#define SYSCALL_WRITEV 146 - -#define SYSCALL_NANOSLEEP 162 - -#define SYSCALL_RT_SIGRETURN 173 -#define SYSCALL_RT_SIGACTION 174 - -#define SYSCALL_MMAP2 192 - -#define SYSCALL_STAT64 195 - -#define SYSCALL_GETDENTS64 217 - -#define SYSCALL_CLOCK_GETTIME32 263 - -#define SYSCALL_SOCKET 281 -#define SYSCALL_BIND 282 -#define SYSCALL_CONNECT 283 -#define SYSCALL_LISTEN 284 -#define SYSCALL_ACCEPT 285 - -#define SYSCALL_SEND 289 -#define SYSCALL_SENDTO 290 - -#define SYSCALL_RECV 291 -#define SYSCALL_RECVFROM 292 - -#define SYSCALL_SETSOCKOPT 294 - -#define SYSCALL_OPENAT 322 - -#define SYSCALL_FSTATAT64 327 - -#define SYSCALL_DUP3 358 -#define SYSCALL_PIPE2 359 - -#define SYSCALL_CLOCK_GETTIME64 403 - -/* Following syscalls still need to be aligned */ -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_THREAD_YIELD 43 - -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 - -#endif /* ARCH_ARM32_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm32/syscall.h.in b/so3/arch/arm32/syscall.h.in new file mode 100644 index 000000000..54cd3b01c --- /dev/null +++ b/so3/arch/arm32/syscall.h.in @@ -0,0 +1,420 @@ +/* + * This files is copied from musl library and should not be included. + * Include generated/syscall_number.h instead. + * + * Original file from musl 1.2.5: arch/arm32/bits/syscall.h.in + */ +#define __NR_restart_syscall 0 +#define __NR_exit 1 +#define __NR_fork 2 +#define __NR_read 3 +#define __NR_write 4 +#define __NR_open 5 +#define __NR_close 6 +#define __NR_creat 8 +#define __NR_link 9 +#define __NR_unlink 10 +#define __NR_execve 11 +#define __NR_chdir 12 +#define __NR_mknod 14 +#define __NR_chmod 15 +#define __NR_lchown 16 +#define __NR_lseek 19 +#define __NR_getpid 20 +#define __NR_mount 21 +#define __NR_setuid 23 +#define __NR_getuid 24 +#define __NR_ptrace 26 +#define __NR_pause 29 +#define __NR_access 33 +#define __NR_nice 34 +#define __NR_sync 36 +#define __NR_kill 37 +#define __NR_rename 38 +#define __NR_mkdir 39 +#define __NR_rmdir 40 +#define __NR_dup 41 +#define __NR_pipe 42 +#define __NR_times 43 +#define __NR_brk 45 +#define __NR_setgid 46 +#define __NR_getgid 47 +#define __NR_geteuid 49 +#define __NR_getegid 50 +#define __NR_acct 51 +#define __NR_umount2 52 +#define __NR_ioctl 54 +#define __NR_fcntl 55 +#define __NR_setpgid 57 +#define __NR_umask 60 +#define __NR_chroot 61 +#define __NR_ustat 62 +#define __NR_dup2 63 +#define __NR_getppid 64 +#define __NR_getpgrp 65 +#define __NR_setsid 66 +#define __NR_sigaction 67 +#define __NR_setreuid 70 +#define __NR_setregid 71 +#define __NR_sigsuspend 72 +#define __NR_sigpending 73 +#define __NR_sethostname 74 +#define __NR_setrlimit 75 +#define __NR_getrusage 77 +#define __NR_gettimeofday_time32 78 +#define __NR_settimeofday_time32 79 +#define __NR_getgroups 80 +#define __NR_setgroups 81 +#define __NR_symlink 83 +#define __NR_readlink 85 +#define __NR_uselib 86 +#define __NR_swapon 87 +#define __NR_reboot 88 +#define __NR_munmap 91 +#define __NR_truncate 92 +#define __NR_ftruncate 93 +#define __NR_fchmod 94 +#define __NR_fchown 95 +#define __NR_getpriority 96 +#define __NR_setpriority 97 +#define __NR_statfs 99 +#define __NR_fstatfs 100 +#define __NR_syslog 103 +#define __NR_setitimer 104 +#define __NR_getitimer 105 +#define __NR_stat 106 +#define __NR_lstat 107 +#define __NR_fstat 108 +#define __NR_vhangup 111 +#define __NR_wait4 114 +#define __NR_swapoff 115 +#define __NR_sysinfo 116 +#define __NR_fsync 118 +#define __NR_sigreturn 119 +#define __NR_clone 120 +#define __NR_setdomainname 121 +#define __NR_uname 122 +#define __NR_adjtimex 124 +#define __NR_mprotect 125 +#define __NR_sigprocmask 126 +#define __NR_init_module 128 +#define __NR_delete_module 129 +#define __NR_quotactl 131 +#define __NR_getpgid 132 +#define __NR_fchdir 133 +#define __NR_bdflush 134 +#define __NR_sysfs 135 +#define __NR_personality 136 +#define __NR_setfsuid 138 +#define __NR_setfsgid 139 +#define __NR__llseek 140 +#define __NR_getdents 141 +#define __NR__newselect 142 +#define __NR_flock 143 +#define __NR_msync 144 +#define __NR_readv 145 +#define __NR_writev 146 +#define __NR_getsid 147 +#define __NR_fdatasync 148 +#define __NR__sysctl 149 +#define __NR_mlock 150 +#define __NR_munlock 151 +#define __NR_mlockall 152 +#define __NR_munlockall 153 +#define __NR_sched_setparam 154 +#define __NR_sched_getparam 155 +#define __NR_sched_setscheduler 156 +#define __NR_sched_getscheduler 157 +#define __NR_sched_yield 158 +#define __NR_sched_get_priority_max 159 +#define __NR_sched_get_priority_min 160 +#define __NR_sched_rr_get_interval 161 +#define __NR_nanosleep 162 +#define __NR_mremap 163 +#define __NR_setresuid 164 +#define __NR_getresuid 165 +#define __NR_poll 168 +#define __NR_nfsservctl 169 +#define __NR_setresgid 170 +#define __NR_getresgid 171 +#define __NR_prctl 172 +#define __NR_rt_sigreturn 173 +#define __NR_rt_sigaction 174 +#define __NR_rt_sigprocmask 175 +#define __NR_rt_sigpending 176 +#define __NR_rt_sigtimedwait 177 +#define __NR_rt_sigqueueinfo 178 +#define __NR_rt_sigsuspend 179 +#define __NR_pread64 180 +#define __NR_pwrite64 181 +#define __NR_chown 182 +#define __NR_getcwd 183 +#define __NR_capget 184 +#define __NR_capset 185 +#define __NR_sigaltstack 186 +#define __NR_sendfile 187 +#define __NR_vfork 190 +#define __NR_ugetrlimit 191 +#define __NR_mmap2 192 +#define __NR_truncate64 193 +#define __NR_ftruncate64 194 +#define __NR_stat64 195 +#define __NR_lstat64 196 +#define __NR_fstat64 197 +#define __NR_lchown32 198 +#define __NR_getuid32 199 +#define __NR_getgid32 200 +#define __NR_geteuid32 201 +#define __NR_getegid32 202 +#define __NR_setreuid32 203 +#define __NR_setregid32 204 +#define __NR_getgroups32 205 +#define __NR_setgroups32 206 +#define __NR_fchown32 207 +#define __NR_setresuid32 208 +#define __NR_getresuid32 209 +#define __NR_setresgid32 210 +#define __NR_getresgid32 211 +#define __NR_chown32 212 +#define __NR_setuid32 213 +#define __NR_setgid32 214 +#define __NR_setfsuid32 215 +#define __NR_setfsgid32 216 +#define __NR_getdents64 217 +#define __NR_pivot_root 218 +#define __NR_mincore 219 +#define __NR_madvise 220 +#define __NR_fcntl64 221 +#define __NR_gettid 224 +#define __NR_readahead 225 +#define __NR_setxattr 226 +#define __NR_lsetxattr 227 +#define __NR_fsetxattr 228 +#define __NR_getxattr 229 +#define __NR_lgetxattr 230 +#define __NR_fgetxattr 231 +#define __NR_listxattr 232 +#define __NR_llistxattr 233 +#define __NR_flistxattr 234 +#define __NR_removexattr 235 +#define __NR_lremovexattr 236 +#define __NR_fremovexattr 237 +#define __NR_tkill 238 +#define __NR_sendfile64 239 +#define __NR_futex 240 +#define __NR_sched_setaffinity 241 +#define __NR_sched_getaffinity 242 +#define __NR_io_setup 243 +#define __NR_io_destroy 244 +#define __NR_io_getevents 245 +#define __NR_io_submit 246 +#define __NR_io_cancel 247 +#define __NR_exit_group 248 +#define __NR_lookup_dcookie 249 +#define __NR_epoll_create 250 +#define __NR_epoll_ctl 251 +#define __NR_epoll_wait 252 +#define __NR_remap_file_pages 253 +#define __NR_set_tid_address 256 +#define __NR_timer_create 257 +#define __NR_timer_settime32 258 +#define __NR_timer_gettime32 259 +#define __NR_timer_getoverrun 260 +#define __NR_timer_delete 261 +#define __NR_clock_settime32 262 +#define __NR_clock_gettime32 263 +#define __NR_clock_getres_time32 264 +#define __NR_clock_nanosleep_time32 265 +#define __NR_statfs64 266 +#define __NR_fstatfs64 267 +#define __NR_tgkill 268 +#define __NR_utimes 269 +#define __NR_fadvise64_64 270 +#define __NR_arm_fadvise64_64 270 +#define __NR_pciconfig_iobase 271 +#define __NR_pciconfig_read 272 +#define __NR_pciconfig_write 273 +#define __NR_mq_open 274 +#define __NR_mq_unlink 275 +#define __NR_mq_timedsend 276 +#define __NR_mq_timedreceive 277 +#define __NR_mq_notify 278 +#define __NR_mq_getsetattr 279 +#define __NR_waitid 280 +#define __NR_socket 281 +#define __NR_bind 282 +#define __NR_connect 283 +#define __NR_listen 284 +#define __NR_accept 285 +#define __NR_getsockname 286 +#define __NR_getpeername 287 +#define __NR_socketpair 288 +#define __NR_send 289 +#define __NR_sendto 290 +#define __NR_recv 291 +#define __NR_recvfrom 292 +#define __NR_shutdown 293 +#define __NR_setsockopt 294 +#define __NR_getsockopt 295 +#define __NR_sendmsg 296 +#define __NR_recvmsg 297 +#define __NR_semop 298 +#define __NR_semget 299 +#define __NR_semctl 300 +#define __NR_msgsnd 301 +#define __NR_msgrcv 302 +#define __NR_msgget 303 +#define __NR_msgctl 304 +#define __NR_shmat 305 +#define __NR_shmdt 306 +#define __NR_shmget 307 +#define __NR_shmctl 308 +#define __NR_add_key 309 +#define __NR_request_key 310 +#define __NR_keyctl 311 +#define __NR_semtimedop 312 +#define __NR_vserver 313 +#define __NR_ioprio_set 314 +#define __NR_ioprio_get 315 +#define __NR_inotify_init 316 +#define __NR_inotify_add_watch 317 +#define __NR_inotify_rm_watch 318 +#define __NR_mbind 319 +#define __NR_get_mempolicy 320 +#define __NR_set_mempolicy 321 +#define __NR_openat 322 +#define __NR_mkdirat 323 +#define __NR_mknodat 324 +#define __NR_fchownat 325 +#define __NR_futimesat 326 +#define __NR_fstatat64 327 +#define __NR_unlinkat 328 +#define __NR_renameat 329 +#define __NR_linkat 330 +#define __NR_symlinkat 331 +#define __NR_readlinkat 332 +#define __NR_fchmodat 333 +#define __NR_faccessat 334 +#define __NR_pselect6 335 +#define __NR_ppoll 336 +#define __NR_unshare 337 +#define __NR_set_robust_list 338 +#define __NR_get_robust_list 339 +#define __NR_splice 340 +#define __NR_sync_file_range2 341 +#define __NR_arm_sync_file_range 341 +#define __NR_tee 342 +#define __NR_vmsplice 343 +#define __NR_move_pages 344 +#define __NR_getcpu 345 +#define __NR_epoll_pwait 346 +#define __NR_kexec_load 347 +#define __NR_utimensat 348 +#define __NR_signalfd 349 +#define __NR_timerfd_create 350 +#define __NR_eventfd 351 +#define __NR_fallocate 352 +#define __NR_timerfd_settime32 353 +#define __NR_timerfd_gettime32 354 +#define __NR_signalfd4 355 +#define __NR_eventfd2 356 +#define __NR_epoll_create1 357 +#define __NR_dup3 358 +#define __NR_pipe2 359 +#define __NR_inotify_init1 360 +#define __NR_preadv 361 +#define __NR_pwritev 362 +#define __NR_rt_tgsigqueueinfo 363 +#define __NR_perf_event_open 364 +#define __NR_recvmmsg 365 +#define __NR_accept4 366 +#define __NR_fanotify_init 367 +#define __NR_fanotify_mark 368 +#define __NR_prlimit64 369 +#define __NR_name_to_handle_at 370 +#define __NR_open_by_handle_at 371 +#define __NR_clock_adjtime 372 +#define __NR_syncfs 373 +#define __NR_sendmmsg 374 +#define __NR_setns 375 +#define __NR_process_vm_readv 376 +#define __NR_process_vm_writev 377 +#define __NR_kcmp 378 +#define __NR_finit_module 379 +#define __NR_sched_setattr 380 +#define __NR_sched_getattr 381 +#define __NR_renameat2 382 +#define __NR_seccomp 383 +#define __NR_getrandom 384 +#define __NR_memfd_create 385 +#define __NR_bpf 386 +#define __NR_execveat 387 +#define __NR_userfaultfd 388 +#define __NR_membarrier 389 +#define __NR_mlock2 390 +#define __NR_copy_file_range 391 +#define __NR_preadv2 392 +#define __NR_pwritev2 393 +#define __NR_pkey_mprotect 394 +#define __NR_pkey_alloc 395 +#define __NR_pkey_free 396 +#define __NR_statx 397 +#define __NR_rseq 398 +#define __NR_io_pgetevents 399 +#define __NR_migrate_pages 400 +#define __NR_kexec_file_load 401 +#define __NR_clock_gettime64 403 +#define __NR_clock_settime64 404 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres_time64 406 +#define __NR_clock_nanosleep_time64 407 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime64 409 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime64 411 +#define __NR_utimensat_time64 412 +#define __NR_pselect6_time64 413 +#define __NR_ppoll_time64 414 +#define __NR_io_pgetevents_time64 416 +#define __NR_recvmmsg_time64 417 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_timedreceive_time64 419 +#define __NR_semtimedop_time64 420 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_futex_time64 422 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433 +#define __NR_pidfd_open 434 +#define __NR_clone3 435 +#define __NR_close_range 436 +#define __NR_openat2 437 +#define __NR_pidfd_getfd 438 +#define __NR_faccessat2 439 +#define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_restrict_self 446 +#define __NR_process_mrelease 448 +#define __NR_futex_waitv 449 +#define __NR_set_mempolicy_home_node 450 +#define __NR_cachestat 451 +#define __NR_fchmodat2 452 + +#define __ARM_NR_breakpoint 0x0f0001 +#define __ARM_NR_cacheflush 0x0f0002 +#define __ARM_NR_usr26 0x0f0003 +#define __ARM_NR_usr32 0x0f0004 +#define __ARM_NR_set_tls 0x0f0005 +#define __ARM_NR_get_tls 0x0f0006 + diff --git a/so3/arch/arm64/context.S b/so3/arch/arm64/context.S index 25a351731..02dadb14e 100644 --- a/so3/arch/arm64/context.S +++ b/so3/arch/arm64/context.S @@ -293,7 +293,7 @@ ENTRY(__root_proc) mov x0, #STDOUT adr x1, .LC_welcome mov x2, welcome_len - mov x8, #SYSCALL_WRITE + mov x8, #SYSCALL_write // Invoke the syscall - kernel side svc 0 @@ -306,7 +306,7 @@ ENTRY(__root_proc) mov x1, xzr mov x2, xzr - mov x8, #SYSCALL_EXECVE + mov x8, #SYSCALL_execve svc 0 @@ -315,7 +315,7 @@ ENTRY(__root_proc) mov x0, #STDOUT adr x1, .LCnoshell mov x2, noshell_len - mov x8, #SYSCALL_WRITE + mov x8, #SYSCALL_write svc 0 diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index cf58242bc..4d8cd4a7f 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -557,7 +557,7 @@ el01_sync_handler: // Check if sigreturn has been called. In this case, we // clean the stack frame which has been used to manage the user handler. - cmp x8, #SYSCALL_RT_SIGRETURN + cmp x8, #SYSCALL_rt_sigreturn bne __ret_from_fork // Reset the stack frame by removing the one issued from sigreturn diff --git a/so3/arch/arm64/include/asm/syscall_number.h b/so3/arch/arm64/include/asm/syscall_number.h deleted file mode 100644 index be298b5f0..000000000 --- a/so3/arch/arm64/include/asm/syscall_number.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2025 Clement Dieperink - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef ARCH_ARM64_SYSCALL_NUMBER_H -#define ARCH_ARM64_SYSCALL_NUMBER_H - -/* - * Syscall number definition - */ -#define SYSCALL_DUP 23 -#define SYSCALL_DUP3 24 - -#define SYSCALL_IOCTL 29 - -#define SYSCALL_OPENAT 56 -#define SYSCALL_CLOSE 57 - -#define SYSCALL_PIPE2 59 - -#define SYSCALL_GETDENTS64 61 -#define SYSCALL_LSEEK 62 -#define SYSCALL_READ 63 -#define SYSCALL_WRITE 64 -#define SYSCALL_READV 65 -#define SYSCALL_WRITEV 66 - -#define SYSCALL_NEWFSTATAT 79 - -#define SYSCALL_EXIT 93 - -#define SYSCALL_NANOSLEEP 101 - -#define SYSCALL_CLOCK_GETTIME 113 - -#define SYSCALL_PTRACE 117 - -#define SYSCALL_KILL 129 - -#define SYSCALL_RT_SIGACTION 134 - -#define SYSCALL_RT_SIGRETURN 139 - -#define SYSCALL_GETTIMEOFDAY 169 - -#define SYSCALL_GETPID 172 - -#define SYSCALL_SOCKET 198 - -#define SYSCALL_BIND 200 -#define SYSCALL_LISTEN 201 -#define SYSCALL_ACCEPT 202 -#define SYSCALL_CONNECT 203 - -#define SYSCALL_SENDTO 206 -#define SYSCALL_RECVFROM 207 -#define SYSCALL_SETSOCKOPT 208 - -#define SYSCALL_BRK 214 - -#define SYSCALL_EXECVE 221 -#define SYSCALL_MMAP 222 - -#define SYSCALL_WAIT4 260 - -/* Following syscalls still need to be aligned */ -#define SYSCALL_FORK 7 // => clone - -#define SYSCALL_THREAD_CREATE 16 -#define SYSCALL_THREAD_JOIN 17 -#define SYSCALL_THREAD_EXIT 18 -#define SYSCALL_THREAD_YIELD 43 - -#define SYSCALL_MUTEX_LOCK 60 -#define SYSCALL_MUTEX_UNLOCK 61 - -#endif /* ARCH_ARM64_SYSCALL_NUMBER_H */ diff --git a/so3/arch/arm64/syscall.h.in b/so3/arch/arm64/syscall.h.in new file mode 100644 index 000000000..87755c024 --- /dev/null +++ b/so3/arch/arm64/syscall.h.in @@ -0,0 +1,312 @@ +/* + * This files is copied from musl library and should not be included. + * Include generated/syscall_number.h instead. + * + * Original file from musl 1.2.5: arch/aarch64/bits/syscall.h.in + */ +#define __NR_io_setup 0 +#define __NR_io_destroy 1 +#define __NR_io_submit 2 +#define __NR_io_cancel 3 +#define __NR_io_getevents 4 +#define __NR_setxattr 5 +#define __NR_lsetxattr 6 +#define __NR_fsetxattr 7 +#define __NR_getxattr 8 +#define __NR_lgetxattr 9 +#define __NR_fgetxattr 10 +#define __NR_listxattr 11 +#define __NR_llistxattr 12 +#define __NR_flistxattr 13 +#define __NR_removexattr 14 +#define __NR_lremovexattr 15 +#define __NR_fremovexattr 16 +#define __NR_getcwd 17 +#define __NR_lookup_dcookie 18 +#define __NR_eventfd2 19 +#define __NR_epoll_create1 20 +#define __NR_epoll_ctl 21 +#define __NR_epoll_pwait 22 +#define __NR_dup 23 +#define __NR_dup3 24 +#define __NR_fcntl 25 +#define __NR_inotify_init1 26 +#define __NR_inotify_add_watch 27 +#define __NR_inotify_rm_watch 28 +#define __NR_ioctl 29 +#define __NR_ioprio_set 30 +#define __NR_ioprio_get 31 +#define __NR_flock 32 +#define __NR_mknodat 33 +#define __NR_mkdirat 34 +#define __NR_unlinkat 35 +#define __NR_symlinkat 36 +#define __NR_linkat 37 +#define __NR_renameat 38 +#define __NR_umount2 39 +#define __NR_mount 40 +#define __NR_pivot_root 41 +#define __NR_nfsservctl 42 +#define __NR_statfs 43 +#define __NR_fstatfs 44 +#define __NR_truncate 45 +#define __NR_ftruncate 46 +#define __NR_fallocate 47 +#define __NR_faccessat 48 +#define __NR_chdir 49 +#define __NR_fchdir 50 +#define __NR_chroot 51 +#define __NR_fchmod 52 +#define __NR_fchmodat 53 +#define __NR_fchownat 54 +#define __NR_fchown 55 +#define __NR_openat 56 +#define __NR_close 57 +#define __NR_vhangup 58 +#define __NR_pipe2 59 +#define __NR_quotactl 60 +#define __NR_getdents64 61 +#define __NR_lseek 62 +#define __NR_read 63 +#define __NR_write 64 +#define __NR_readv 65 +#define __NR_writev 66 +#define __NR_pread64 67 +#define __NR_pwrite64 68 +#define __NR_preadv 69 +#define __NR_pwritev 70 +#define __NR_sendfile 71 +#define __NR_pselect6 72 +#define __NR_ppoll 73 +#define __NR_signalfd4 74 +#define __NR_vmsplice 75 +#define __NR_splice 76 +#define __NR_tee 77 +#define __NR_readlinkat 78 +#define __NR_newfstatat 79 +#define __NR_fstat 80 +#define __NR_sync 81 +#define __NR_fsync 82 +#define __NR_fdatasync 83 +#define __NR_sync_file_range 84 +#define __NR_timerfd_create 85 +#define __NR_timerfd_settime 86 +#define __NR_timerfd_gettime 87 +#define __NR_utimensat 88 +#define __NR_acct 89 +#define __NR_capget 90 +#define __NR_capset 91 +#define __NR_personality 92 +#define __NR_exit 93 +#define __NR_exit_group 94 +#define __NR_waitid 95 +#define __NR_set_tid_address 96 +#define __NR_unshare 97 +#define __NR_futex 98 +#define __NR_set_robust_list 99 +#define __NR_get_robust_list 100 +#define __NR_nanosleep 101 +#define __NR_getitimer 102 +#define __NR_setitimer 103 +#define __NR_kexec_load 104 +#define __NR_init_module 105 +#define __NR_delete_module 106 +#define __NR_timer_create 107 +#define __NR_timer_gettime 108 +#define __NR_timer_getoverrun 109 +#define __NR_timer_settime 110 +#define __NR_timer_delete 111 +#define __NR_clock_settime 112 +#define __NR_clock_gettime 113 +#define __NR_clock_getres 114 +#define __NR_clock_nanosleep 115 +#define __NR_syslog 116 +#define __NR_ptrace 117 +#define __NR_sched_setparam 118 +#define __NR_sched_setscheduler 119 +#define __NR_sched_getscheduler 120 +#define __NR_sched_getparam 121 +#define __NR_sched_setaffinity 122 +#define __NR_sched_getaffinity 123 +#define __NR_sched_yield 124 +#define __NR_sched_get_priority_max 125 +#define __NR_sched_get_priority_min 126 +#define __NR_sched_rr_get_interval 127 +#define __NR_restart_syscall 128 +#define __NR_kill 129 +#define __NR_tkill 130 +#define __NR_tgkill 131 +#define __NR_sigaltstack 132 +#define __NR_rt_sigsuspend 133 +#define __NR_rt_sigaction 134 +#define __NR_rt_sigprocmask 135 +#define __NR_rt_sigpending 136 +#define __NR_rt_sigtimedwait 137 +#define __NR_rt_sigqueueinfo 138 +#define __NR_rt_sigreturn 139 +#define __NR_setpriority 140 +#define __NR_getpriority 141 +#define __NR_reboot 142 +#define __NR_setregid 143 +#define __NR_setgid 144 +#define __NR_setreuid 145 +#define __NR_setuid 146 +#define __NR_setresuid 147 +#define __NR_getresuid 148 +#define __NR_setresgid 149 +#define __NR_getresgid 150 +#define __NR_setfsuid 151 +#define __NR_setfsgid 152 +#define __NR_times 153 +#define __NR_setpgid 154 +#define __NR_getpgid 155 +#define __NR_getsid 156 +#define __NR_setsid 157 +#define __NR_getgroups 158 +#define __NR_setgroups 159 +#define __NR_uname 160 +#define __NR_sethostname 161 +#define __NR_setdomainname 162 +#define __NR_getrlimit 163 +#define __NR_setrlimit 164 +#define __NR_getrusage 165 +#define __NR_umask 166 +#define __NR_prctl 167 +#define __NR_getcpu 168 +#define __NR_gettimeofday 169 +#define __NR_settimeofday 170 +#define __NR_adjtimex 171 +#define __NR_getpid 172 +#define __NR_getppid 173 +#define __NR_getuid 174 +#define __NR_geteuid 175 +#define __NR_getgid 176 +#define __NR_getegid 177 +#define __NR_gettid 178 +#define __NR_sysinfo 179 +#define __NR_mq_open 180 +#define __NR_mq_unlink 181 +#define __NR_mq_timedsend 182 +#define __NR_mq_timedreceive 183 +#define __NR_mq_notify 184 +#define __NR_mq_getsetattr 185 +#define __NR_msgget 186 +#define __NR_msgctl 187 +#define __NR_msgrcv 188 +#define __NR_msgsnd 189 +#define __NR_semget 190 +#define __NR_semctl 191 +#define __NR_semtimedop 192 +#define __NR_semop 193 +#define __NR_shmget 194 +#define __NR_shmctl 195 +#define __NR_shmat 196 +#define __NR_shmdt 197 +#define __NR_socket 198 +#define __NR_socketpair 199 +#define __NR_bind 200 +#define __NR_listen 201 +#define __NR_accept 202 +#define __NR_connect 203 +#define __NR_getsockname 204 +#define __NR_getpeername 205 +#define __NR_sendto 206 +#define __NR_recvfrom 207 +#define __NR_setsockopt 208 +#define __NR_getsockopt 209 +#define __NR_shutdown 210 +#define __NR_sendmsg 211 +#define __NR_recvmsg 212 +#define __NR_readahead 213 +#define __NR_brk 214 +#define __NR_munmap 215 +#define __NR_mremap 216 +#define __NR_add_key 217 +#define __NR_request_key 218 +#define __NR_keyctl 219 +#define __NR_clone 220 +#define __NR_execve 221 +#define __NR_mmap 222 +#define __NR_fadvise64 223 +#define __NR_swapon 224 +#define __NR_swapoff 225 +#define __NR_mprotect 226 +#define __NR_msync 227 +#define __NR_mlock 228 +#define __NR_munlock 229 +#define __NR_mlockall 230 +#define __NR_munlockall 231 +#define __NR_mincore 232 +#define __NR_madvise 233 +#define __NR_remap_file_pages 234 +#define __NR_mbind 235 +#define __NR_get_mempolicy 236 +#define __NR_set_mempolicy 237 +#define __NR_migrate_pages 238 +#define __NR_move_pages 239 +#define __NR_rt_tgsigqueueinfo 240 +#define __NR_perf_event_open 241 +#define __NR_accept4 242 +#define __NR_recvmmsg 243 +#define __NR_wait4 260 +#define __NR_prlimit64 261 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 +#define __NR_name_to_handle_at 264 +#define __NR_open_by_handle_at 265 +#define __NR_clock_adjtime 266 +#define __NR_syncfs 267 +#define __NR_setns 268 +#define __NR_sendmmsg 269 +#define __NR_process_vm_readv 270 +#define __NR_process_vm_writev 271 +#define __NR_kcmp 272 +#define __NR_finit_module 273 +#define __NR_sched_setattr 274 +#define __NR_sched_getattr 275 +#define __NR_renameat2 276 +#define __NR_seccomp 277 +#define __NR_getrandom 278 +#define __NR_memfd_create 279 +#define __NR_bpf 280 +#define __NR_execveat 281 +#define __NR_userfaultfd 282 +#define __NR_membarrier 283 +#define __NR_mlock2 284 +#define __NR_copy_file_range 285 +#define __NR_preadv2 286 +#define __NR_pwritev2 287 +#define __NR_pkey_mprotect 288 +#define __NR_pkey_alloc 289 +#define __NR_pkey_free 290 +#define __NR_statx 291 +#define __NR_io_pgetevents 292 +#define __NR_rseq 293 +#define __NR_kexec_file_load 294 +#define __NR_pidfd_send_signal 424 +#define __NR_io_uring_setup 425 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_open_tree 428 +#define __NR_move_mount 429 +#define __NR_fsopen 430 +#define __NR_fsconfig 431 +#define __NR_fsmount 432 +#define __NR_fspick 433 +#define __NR_pidfd_open 434 +#define __NR_clone3 435 +#define __NR_close_range 436 +#define __NR_openat2 437 +#define __NR_pidfd_getfd 438 +#define __NR_faccessat2 439 +#define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 +#define __NR_mount_setattr 442 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_restrict_self 446 +#define __NR_process_mrelease 448 +#define __NR_futex_waitv 449 +#define __NR_set_mempolicy_home_node 450 +#define __NR_cachestat 451 +#define __NR_fchmodat2 452 diff --git a/so3/include/syscall.h b/so3/include/syscall.h index 711b84145..ada2870db 100644 --- a/so3/include/syscall.h +++ b/so3/include/syscall.h @@ -21,7 +21,7 @@ #ifndef ASM_ARM_SYSCALL_H #define ASM_ARM_SYSCALL_H -#include +#include #ifndef __ASSEMBLY__ diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index d87c60098..b87cc486d 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -35,66 +35,10 @@ extern uint32_t __get_syscall_stack_arg(uint32_t nr); extern void test_malloc(int test_no); -#warning Not updated, a rework is needed to avoid having a big array because of #ifdef ... static const syscall_fn_t syscall_table[NR_SYSCALLS] = { [0 ... NR_SYSCALLS - 1] = NULL, - /* -#ifdef CONFIG_MMU - [SYSCALL_GETPID] = __sys_getpid, - [SYSCALL_GETTIMEOFDAY] = __sys_gettimeofday, - [SYSCALL_CLOCK_GETTIME] = __sys_clock_gettime, - [SYSCALL_EXIT] = __sys_exit, - [SYSCALL_EXECVE] = __sys_execve, - [SYSCALL_FORK] = __sys_fork, - [SYSCALL_WAITPID] = __sys_waitpid, - [SYSCALL_PTRACE] = __sys_ptrace, -#endif - [SYSCALL_READ] = __sys_read, - [SYSCALL_WRITE] = __sys_write, - [SYSCALL_OPEN] = __sys_open, - [SYSCALL_CLOSE] = __sys_close, - [SYSCALL_THREAD_CREATE] = __sys_thread_create, - [SYSCALL_THREAD_JOIN] = __sys_thread_join, - [SYSCALL_THREAD_EXIT] = __sys_thread_exit, - [SYSCALL_THREAD_YIELD] = __sys_thread_yield, - [SYSCALL_READDIR] = __sys_readdir, - [SYSCALL_IOCTL] = __sys_ioctl, - [SYSCALL_FCNTL] = __sys_fcntl, - [SYSCALL_LSEEK] = __sys_lseek, - [SYSCALL_READV] = __sys_readv, - [SYSCALL_WRITEV] = __sys_writev, -#ifdef CONFIG_IPC_PIPE - [SYSCALL_PIPE] = __sys_pipe, -#endif - [SYSCALL_DUP] = __sys_dup, - [SYSCALL_DUP2] = __sys_dup2, - [SYSCALL_STAT] = __sys_stat, - [SYSCALL_MMAP] = __sys_mmap, - [SYSCALL_NANOSLEEP] = __sys_nanosleep, -#ifdef CONFIG_PROC_ENV - [SYSCALL_SBRK] = __sys_sbrk, -#endif - [SYSCALL_MUTEX_LOCK] = __sys_mutex_lock, - [SYSCALL_MUTEX_UNLOCK] = __sys_mutex_unlock, -#ifdef CONFIG_IPC_SIGNAL - [SYSCALL_SIGACTION] = __sys_sigaction, - [SYSCALL_KILL] = __sys_kill, - [SYSCALL_SIGRETURN] = __sys_sigreturn, -#endif -#ifdef CONFIG_NET - [SYSCALL_SOCKET] = __sys_socket, - [SYSCALL_BIND] = __sys_bind, - [SYSCALL_LISTEN] = __sys_listen, - [SYSCALL_ACCEPT] = __sys_accept, - [SYSCALL_CONNECT] = __sys_connect, - [SYSCALL_RECV] = __sys_recv, - [SYSCALL_SEND] = __sys_send, - [SYSCALL_SENDTO] = __sys_sendto, - [SYSCALL_SETSOCKOPT] = __sys_setsockopt, - [SYSCALL_RECVFROM] = __sys_recvfrom, -#endif - [SYSCALL_SYSINFO] = __sys_sysinfo, -*/ +/* Generated file with table element matching number to functions. */ +#include }; /* @@ -104,7 +48,6 @@ static const syscall_fn_t syscall_table[NR_SYSCALLS] = { long syscall_handle(syscall_args_t *syscall_args) { - long result = -1; uint32_t syscall_no; /* Get addtional args of the syscall according to the ARM & SO3 ABI */ @@ -113,11 +56,9 @@ long syscall_handle(syscall_args_t *syscall_args) if ((syscall_no >= NR_SYSCALLS) || (syscall_table[syscall_no] == NULL)) { printk("%s: unhandled syscall: %d\n", __func__, syscall_no); return -ENOSYS; - } else { - return syscall_table[syscall_no](syscall_args); } #warning do_softirq? - return result; + return syscall_table[syscall_no](syscall_args); } diff --git a/so3/scripts/syscall_gen.sh b/so3/scripts/syscall_gen.sh new file mode 100755 index 000000000..e625e152b --- /dev/null +++ b/so3/scripts/syscall_gen.sh @@ -0,0 +1,115 @@ +#!/bin/sh + +# Copyright (C) 2025 Clément Dieperink +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# +# This script generates two header for syscall number and table based on two +# inputs files. +# +# The input files are: +# +# - syscall.tbl: Declares all syscalls available on SO3 without taking into +# account the CPU arch. This also provides configuration +# requirement for a given syscall. +# - syscall.h.in: Contains all syscall number which are necessary implemented +# in SO3. This is a copy of the same file from musl library. +# +# Output files are: +# +# - syscall_number.h: Defines all available on arch SYSCALL_xxx with +# corresponding number and dependent on the configuration. +# - syscall_table.h.in: Table definition with elements of array definition to +# match syscall number to syscall functions. This file +# must be included inside a C table definition. + +set -e + +usage() { + echo >&2 "usage: $0 in_table in_number out_table out_number" >&2 + echo >&2 + echo >&2 " in_table input syscall table common for all arch" + echo >&2 " in_number input syscall number arch dependent" + echo >&2 " out_table output syscall callback table" + echo >&2 " out_number output syscall number conditional" + exit 1 +} + +file_header() { + echo "#ifndef $1" + echo "#define $1" + echo "/*" + echo " * DO NOT MODIFY." + echo " *" + echo " * This file was generated by $(realpath "$0")" + echo " */" + echo "" +} + +file_footer() { + echo "" + echo "#endif" +} + +if [ $# -ne 4 ]; then + usage +fi + +infile_table="$1" +infile_number="$2" +outfile_table="$3" +outfile_number="$4" + +declare -Ag sys_cond=() + +# Generate syscall_table.h.in file and save available syscall +# and there configuration requirement. +file_header "__SYSCALL_TABLE_H__" > "$outfile_table" + +valid_syscalls="$(grep -E "^[^#]" "$infile_table")" +while read name requirement; do + sys_cond["$name"]="$requirement" + + echo "#ifdef SYSCALL_$name" + echo -e "\t[SYSCALL_$name] = &__sys_$name," + echo "#endif" +done < <(echo "$valid_syscalls") >> "$outfile_table" + +file_footer >> "$outfile_table" + +# Generate syscall_number.h +grep -E "^#define " "$infile_number" | sed "s/^#define __NR_//" | { + file_header "__SYSCALL_NUMBER_H__" + echo "#include " + echo "" + + while read name number; do + if ! [ -v sys_cond[$name] ]; then + continue + fi + + if [ -n "${sys_cond[$name]}" ]; then + echo "#ifdef CONFIG_${sys_cond[$name]}" + fi + + echo "#define SYSCALL_$name $number" + + if [ -n "${sys_cond[$name]}" ]; then + echo "#endif" + fi + done + + file_footer +} > "$outfile_number" diff --git a/so3/syscall.tbl b/so3/syscall.tbl new file mode 100644 index 000000000..1a3921119 --- /dev/null +++ b/so3/syscall.tbl @@ -0,0 +1,66 @@ +# Copyright (C) 2025 Clément Dieperink +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# This file declare all syscalls available on SO3, without taking into account +# of CPU arch. See scripts/syscall_gen.sh for more information. +# +# Syscall name Configuration requirement +read +readv +write +writev +open +openat +close +lseek +_llseek +ioctl +dup +dup2 +dup3 +getdents64 +stat64 +fstatat64 +newfstatat +mmap +mmap2 +nanosleep +pipe IPC_PIPE +pipe2 IPC_PIPE +rt_sigaction IPC_SIGNAL +rt_kill IPC_SIGNAL +sigreturn IPC_SIGNAL +rt_sigreturn IPC_SIGNAL +getpid MMU +execve MMU +fork MMU +exit MMU +wait4 MMU +ptrace MMU +gettimeofday MMU +gettimeofday_time32 MMU +clock_gettime MMU +clock_gettime32 MMU +socket NET +connect NET +bind NET +listen NET +accept NET +recv NET +recvfrom NET +send NET +sendto NET +setsockopt NET +brk PROC_ENV From baaab350a294b1382827030b00b4d252897358be Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Thu, 30 Oct 2025 09:12:50 +0100 Subject: [PATCH 25/69] fix sh to bash in script --- .github/workflows/build.yml | 3 +-- so3/scripts/syscall_gen.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb9e0ac0e..5b9406796 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,8 +5,7 @@ on: branches: - main pull_request: - branches: - - main + branches: ["main", "144-support-musl"] jobs: build-so3: diff --git a/so3/scripts/syscall_gen.sh b/so3/scripts/syscall_gen.sh index e625e152b..8adec6935 100755 --- a/so3/scripts/syscall_gen.sh +++ b/so3/scripts/syscall_gen.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Copyright (C) 2025 Clément Dieperink # From fb05db6d06bb6a32bb4fd6c3002670f1c1d08ec0 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 3 Nov 2025 08:55:59 +0100 Subject: [PATCH 26/69] Add template for futex syscall Signed-off-by: Jean-Pierre Miceli --- so3/include/futex.h | 45 +++++++++++++++++++++++++++++++++++++++++++ so3/kernel/Makefile | 1 + so3/kernel/futex.c | 44 ++++++++++++++++++++++++++++++++++++++++++ so3/kernel/syscalls.c | 1 + so3/syscall.tbl | 1 + 5 files changed, 92 insertions(+) create mode 100644 so3/include/futex.h create mode 100644 so3/kernel/futex.c diff --git a/so3/include/futex.h b/so3/include/futex.h new file mode 100644 index 000000000..0cd6afe4c --- /dev/null +++ b/so3/include/futex.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014-2018 Daniel Rossier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef FUTEX_H +#define FUTEX_H + +#include +#include + +/* Commands */ +#define FUTEX_WAIT 0 +#define FUTEX_WAKE 1 +#define FUTEX_FD 2 +#define FUTEX_REQUEUE 3 +#define FUTEX_CMP_REQUEUE 4 +#define FUTEX_WAKE_OP 5 +#define FUTEX_LOCK_PI 6 +#define FUTEX_UNLOCK_PI 7 +#define FUTEX_TRYLOCK_PI 8 +#define FUTEX_WAIT_BITSET 9 + +#define FUTEX_PRIVATE_FLAG 128 +#define FUTEX_CLOCK_REALTIME 256 +#define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) + + +SYSCALL_DECLARE(futex, u32 *uaddr, int op, u32 val, const struct timespec * utime, + u32 *uaddr2, u32 val3) + +#endif /* FUTEX_H */ diff --git a/so3/kernel/Makefile b/so3/kernel/Makefile index 8b9900a3d..71f68a103 100644 --- a/so3/kernel/Makefile +++ b/so3/kernel/Makefile @@ -8,6 +8,7 @@ obj-y += main.o \ thread.o \ schedule.o \ mutex.o \ + futex.o \ spinlock.o \ syscalls.o \ softirq.o \ diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c new file mode 100644 index 000000000..7d30e36ba --- /dev/null +++ b/so3/kernel/futex.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2025 Jean-Pierre Miceli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include + +SYSCALL_DEFINE6(futex, u32 *, uaddr, int, op, u32, val, + const struct timespec *, utime, + u32 *, uaddr2, u32, val3) +{ + + // unsigned int flags = futex_to_flags(op); + int cmd = op & FUTEX_CMD_MASK; + + switch (cmd) { + case FUTEX_WAIT: + break; + case FUTEX_WAKE: + break; + default: + printk("Futex cmd '%d' not supported !\n"); + return -EINVAL; + } + + return -ENOSYS; +} + + + diff --git a/so3/kernel/syscalls.c b/so3/kernel/syscalls.c index b87cc486d..251dc1430 100644 --- a/so3/kernel/syscalls.c +++ b/so3/kernel/syscalls.c @@ -28,6 +28,7 @@ #include #include #include +#include #include extern void __get_syscall_args_ext(uint32_t *syscall_no); diff --git a/so3/syscall.tbl b/so3/syscall.tbl index 1a3921119..a5b247c27 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -37,6 +37,7 @@ newfstatat mmap mmap2 nanosleep +futex pipe IPC_PIPE pipe2 IPC_PIPE rt_sigaction IPC_SIGNAL From f991130c425e827de0c3d7e62949552523d88c87 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 4 Nov 2025 14:35:08 +0100 Subject: [PATCH 27/69] [futex] Initial implementation of FUTEX_WAIT cmd The implementation uses lists Signed-off-by: Jean-Pierre Miceli --- so3/include/futex.h | 42 ++++++++++++++++++++++++++ so3/include/process.h | 6 ++++ so3/kernel/futex.c | 70 +++++++++++++++++++++++++++++++++++++++++-- so3/kernel/process.c | 7 +++++ 4 files changed, 122 insertions(+), 3 deletions(-) diff --git a/so3/include/futex.h b/so3/include/futex.h index 0cd6afe4c..c51a9bd2d 100644 --- a/so3/include/futex.h +++ b/so3/include/futex.h @@ -20,6 +20,9 @@ #define FUTEX_H #include +#include +#include +#include #include /* Commands */ @@ -38,6 +41,45 @@ #define FUTEX_CLOCK_REALTIME 256 #define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) +/* + * Hash buckets are shared by all the futex_keys that hash to the same + * location. Each key may have multiple futex_q structures, one for each task + * waiting on a futex. + */ +// struct futex_hash_bucket { +// atomic_t waiters; +// spinlock_t lock; +// struct plist_head chain; +// }; + +typedef struct futex_el { + struct list_head list; + tcb_t *tcb; +} futex_el_t; + +typedef struct futex { + struct list_head list; + struct list_head f_element; + uintptr_t key; +} futex_t; + + +/** + * struct futex_q - The hashed futex queue entry, one per waiting task + * + * @list: priority-sorted list of tasks waiting on this futex + * @lock_ptr: the hash bucket lock + * @key: the key the futex is hashed on + * @task: the task waiting on the futex + */ +// struct futex_q { +// struct plist_node list; +// struct futex_hash_bucket *lock_ptr; +// struct futex_key key; +// struct task_struct *task; // the sleeping thread +// }; + + SYSCALL_DECLARE(futex, u32 *uaddr, int op, u32 val, const struct timespec * utime, u32 *uaddr2, u32 val3) diff --git a/so3/include/process.h b/so3/include/process.h index 5b444deab..1fdb04a95 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include @@ -82,6 +84,10 @@ struct pcb { /* Number of pages required by this process (including binary image) */ size_t page_count; + /* List of futexes */ + struct list_head futex; + spinlock_t futex_lock; + /* List of frames (physical pages) belonging to this process */ struct list_head page_list; diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c index 7d30e36ba..2d8d8beb7 100644 --- a/so3/kernel/futex.c +++ b/so3/kernel/futex.c @@ -16,12 +16,70 @@ * */ +#include +#include #include #include -SYSCALL_DEFINE6(futex, u32 *, uaddr, int, op, u32, val, +/** + * do_futex_wait - + * + * @param futex_w + */ +static int do_futex_wait(uint32_t *futex_w, uint32_t val) +{ + unsigned long flags; + pcb_t *pcb = current()->pcb; + spinlock_t f_lock = pcb->futex_lock; + struct list_head *pos; + futex_t *futex; + futex_el_t *f_element; + + flags = spin_lock_irqsave(&f_lock); + + if (*futex_w != val) + return -EAGAIN; + + /* look if a futex_w already exists */ + list_for_each(pos, &pcb->futex) { + futex = list_entry(pos, futex_t, list); + + if ((uintptr_t)futex_w == futex->key) + break; + } + + if (pos == &pcb->futex) { + /* no futex on futex_w */ + futex = (futex_t *)calloc(1, sizeof(futex_t)); + if (futex == NULL) + BUG(); + + list_add_tail(&futex->list, &pcb->futex); + } + + /* Add the thread in the futex_element list */ + f_element = (futex_el_t *)calloc(1, sizeof(futex_el_t)); + if (f_element == NULL) + BUG(); + + f_element->tcb = current(); + + list_add_tail(&f_element->list, &futex->f_element); + + /* go to sleep. */ + spin_unlock(&f_lock); + waiting(); + + BUG_ON(local_irq_is_enabled()); + + spin_unlock_irqrestore(&f_lock, flags); + + return 0; +} + +SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, const struct timespec *, utime, - u32 *, uaddr2, u32, val3) + uint32_t *, uaddr2, uint32_t, val3) { // unsigned int flags = futex_to_flags(op); @@ -29,7 +87,7 @@ SYSCALL_DEFINE6(futex, u32 *, uaddr, int, op, u32, val, switch (cmd) { case FUTEX_WAIT: - break; + return do_futex_wait(uaddr, val); case FUTEX_WAKE: break; default: @@ -41,4 +99,10 @@ SYSCALL_DEFINE6(futex, u32 *, uaddr, int, op, u32, val, } +void futex_init(void) +{ + +} + + diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 13ec54092..3e0eff200 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -205,6 +205,10 @@ pcb_t *new_process(void) /* Init the list of pages */ INIT_LIST_HEAD(&pcb->page_list); + /* Init the futex */ + INIT_LIST_HEAD(&pcb->futex); + spin_lock_init(&pcb->futex_lock); + pcb->pid = pid_current++; for (i = 0; i < PROC_MAX_THREADS; i++) @@ -213,6 +217,9 @@ pcb_t *new_process(void) /* Init the list of child threads */ INIT_LIST_HEAD(&pcb->threads); + /* Init the 'futex' list */ + INIT_LIST_HEAD(&pcb->futex); + /* Process-related memory management */ /* Create the 1st level page table */ From 756f5cf437897c737ce778f153b775f6c95a5f2c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 4 Nov 2025 15:51:16 +0100 Subject: [PATCH 28/69] [futex] Initial implementation of FUTEX_WAKE cmd Signed-off-by: Jean-Pierre Miceli --- so3/kernel/futex.c | 54 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c index 2d8d8beb7..157c54015 100644 --- a/so3/kernel/futex.c +++ b/so3/kernel/futex.c @@ -30,12 +30,11 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) { unsigned long flags; pcb_t *pcb = current()->pcb; - spinlock_t f_lock = pcb->futex_lock; struct list_head *pos; futex_t *futex; futex_el_t *f_element; - flags = spin_lock_irqsave(&f_lock); + flags = spin_lock_irqsave(&pcb->futex_lock); if (*futex_w != val) return -EAGAIN; @@ -54,6 +53,8 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) if (futex == NULL) BUG(); + futex->key = (uintptr_t)futex_w; + list_add_tail(&futex->list, &pcb->futex); } @@ -67,16 +68,59 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) list_add_tail(&f_element->list, &futex->f_element); /* go to sleep. */ - spin_unlock(&f_lock); + spin_unlock(&pcb->futex_lock); waiting(); BUG_ON(local_irq_is_enabled()); - spin_unlock_irqrestore(&f_lock, flags); + spin_unlock_irqrestore(&pcb->futex_lock, flags); return 0; } +static int do_futex_wake(uint32_t *futex_w, uint32_t val) +{ + unsigned long flags; + pcb_t *pcb = current()->pcb; + struct list_head *pos, *p; + futex_t *futex; + futex_el_t *f_element; + unsigned idx = 0; + + flags = spin_lock_irqsave(&pcb->futex_lock); + + /* Search for the futex element with futex_w as key */ + list_for_each(pos, &pcb->futex) { + futex = list_entry(pos, futex_t, list); + + if ((uintptr_t)futex_w == futex->key) + break; + } + + if (pos == &pcb->futex) + /* key does not exists in futex - Error */ + BUG(); + + /* wakes at most val of the waiters that are waiting */ + list_for_each_safe(pos, p, &futex->list) { + f_element = list_entry(pos, futex_el_t, list); + + if (idx == val) + break; + + list_del(&f_element->list); + ready(f_element->tcb); + + idx++; + } + + spin_unlock_irqrestore(&pcb->futex_lock, flags); + + return 0; + +} + + SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, const struct timespec *, utime, uint32_t *, uaddr2, uint32_t, val3) @@ -89,7 +133,7 @@ SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, case FUTEX_WAIT: return do_futex_wait(uaddr, val); case FUTEX_WAKE: - break; + return do_futex_wake(uaddr, val); default: printk("Futex cmd '%d' not supported !\n"); return -EINVAL; From 7a1e5c77b56f493d9d31dfb772bdcff6f083995b Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 3 Nov 2025 18:37:53 +0100 Subject: [PATCH 29/69] rework thread creation to match pthread --- so3/arch/arm32/asm-offsets.c | 1 + so3/arch/arm32/context.S | 68 -------- so3/arch/arm32/exception.S | 28 ++- so3/arch/arm32/include/asm/processor.h | 5 +- so3/arch/arm32/thread.c | 77 ++++++++- so3/arch/arm64/asm-offsets.c | 1 + so3/arch/arm64/context.S | 73 +------- so3/arch/arm64/exception.S | 43 +++-- so3/arch/arm64/include/asm/processor.h | 22 ++- so3/arch/arm64/thread.c | 77 ++++++++- so3/include/process.h | 38 +++- so3/include/thread.h | 50 ++++-- so3/kernel/process.c | 196 +++++++++++---------- so3/kernel/thread.c | 229 +++++++------------------ so3/syscall.tbl | 2 + 15 files changed, 446 insertions(+), 464 deletions(-) diff --git a/so3/arch/arm32/asm-offsets.c b/so3/arch/arm32/asm-offsets.c index 6f57cecef..2a542dec4 100644 --- a/so3/arch/arm32/asm-offsets.c +++ b/so3/arch/arm32/asm-offsets.c @@ -78,6 +78,7 @@ int main(void) DEFINE(OFFSET_PSR, offsetof(cpu_regs_t, psr)); DEFINE(OFFSET_SP_USR, offsetof(cpu_regs_t, sp_usr)); DEFINE(OFFSET_LR_USR, offsetof(cpu_regs_t, lr_usr)); + DEFINE(OFFSET_TLS_USR, offsetof(cpu_regs_t, tls_usr)); BLANK(); diff --git a/so3/arch/arm32/context.S b/so3/arch/arm32/context.S index 5e4f3b0a6..0234098bd 100644 --- a/so3/arch/arm32/context.S +++ b/so3/arch/arm32/context.S @@ -31,9 +31,7 @@ .global __switch_context .global __thread_prologue_kernel -.global __thread_prologue_user .global __exec_prologue_user -.global __thread_prologue_user_pre_launch .globl __get_syscall_args_ext .globl __get_syscall_arg @@ -41,7 +39,6 @@ .global __mmu_switch_ttbr0 .global __exec .global __write -.global __save_context .global __enable_vfp @@ -51,7 +48,6 @@ #ifdef CONFIG_MMU .extern __check_ptrace_traceme -.extern ret_from_fork .extern pre_launch_proc #endif @@ -84,39 +80,6 @@ __thread_prologue_kernel: bl thread_prologue -@ User thread initial entry point -@ Called once per thread -@ r4: th_fn, r5: th_arg, r6: user stack -__thread_prologue_user: - - @ Prepare to jump into C code - mov r0, r4 @ tcb->th_fn - mov r1, r5 @ tcb->th_arg - -#ifdef CONFIG_MMU - @ Check if the thread must stopped because of ptrace/tracee - stmfd sp!, {r0, r1} - bl __check_ptrace_traceme - ldmfd sp!, {r0, r1} -#endif - - @ IRQ enabling - must be done in SVC mode of course ;-) - @ We should take care about protecting against signal receipt: - @ since the stack is not initialized yet, the signal processing should be kept disabled. - cpsie i - - @ Switch into user mode - mrs r4, cpsr - bic r4, r4, #PSR_MODE_MASK - orr r4, r4, #PSR_USR_MODE - msr cpsr, r4 - - @ User stack initialisation - mov sp, r6 - - bl thread_prologue - - #ifdef CONFIG_AVZ ENTRY(cpu_do_idle) @@ -208,37 +171,6 @@ __mmu_switch_ttbr0: nop nop -@ Store the current registers into a cpu_regs structure passed in r0 (as first argument) -__save_context: - - @ Adjust the kernel stack pointer so that we can proceed with ret_from_fork - @ SVC_STACK_FRAME_SIZE/4 registers are preserved when at the syscall vector entry point - - @ Adjust the sp which is stored on the stack. Make sure - @ it refers to this stack and not the one issue from the copy - @ as during fork(). - - str r1, [r1, #(OFFSET_SP-SVC_STACK_FRAME_SIZE)] - - sub r2, r1, #SVC_STACK_FRAME_SIZE - - @ Prepare to configure sp during the context switch. - str r2, [r0, #(OFFSET_TCB_CPU_REGS + OFFSET_SP)] - - @ Prepare the lr to branch to ret_from_fork - ldr r1, .LCret_from_fork - str r1, [r0, #(OFFSET_TCB_CPU_REGS + OFFSET_LR)] - - @ Preserve r7 which contains the syscall number (used to compare against SIG_RETURN) - str r7, [r0, #(OFFSET_TCB_CPU_REGS + OFFSET_R7)] - - @ The other registers are not important. - - mov pc, lr - -.LCret_from_fork: - .word ret_from_fork - .LCcurrent: .word current_thread diff --git a/so3/arch/arm32/exception.S b/so3/arch/arm32/exception.S index 6f7ac347a..0c44feced 100644 --- a/so3/arch/arm32/exception.S +++ b/so3/arch/arm32/exception.S @@ -118,6 +118,10 @@ __prepare_sig_handler: tst sp, #0x7 @ 8-bytes aligned bne __stack_alignment_fault + @ Copy TLS to the new stack frame + ldr r0, [sp, #OFFSET_TLS_USR] + str r0, [sp, #(-SVC_STACK_FRAME_SIZE + OFFSET_TLS_USR)] + str sp, [sp, #(-SVC_STACK_FRAME_SIZE + OFFSET_SP)] @ save sp @ Build a new stack frame based on the current @@ -169,7 +173,7 @@ __prepare_sig_handler: @ ARM EABI: the syscall nr is stored in r7 .align 5 syscall_interrupt: - + @ At the exception entry, the stack must be 8-byte aligned. @ If it is not the case (gcc might not respect the AAPCS convention for optimization purposes), @ sp will be adjusted. The original sp is preserved and will be correctly restored at the exit. @@ -199,9 +203,13 @@ syscall_interrupt: add lr, sp, #OFFSET_SP_USR stmia lr, {sp, lr}^ + @ Save user space TLS context + mrc p15, 0, r0, c13, c0, 0 + str r0, [sp, #OFFSET_TLS_USR] + cmp r7, #SYSCALL_sigreturn beq __after_push_sp_usr - + ldr r0, [sp, #OFFSET_SP_USR] ldr r1, .LCcurrent ldr r1, [r1] @@ -254,6 +262,10 @@ __ret_from_fork: check_pending_signal #endif /* CONFIG_IPC_SIGNAL */ + @ Restore user space TLS context + ldr lr, [sp, #OFFSET_TLS_USR] + mcr p15, 0, lr, c13, c0, 0 + @ get the saved spsr and adjust the stack pointer ldr lr, [sp, #OFFSET_PSR] msr spsr, lr @@ -270,14 +282,14 @@ __ret_from_fork: ldmia sp, {sp, lr, pc}^ - + @ Used at entry point of a fork'd process (setting the return value to 0) ret_from_fork: mov r0, #0 b __ret_from_fork - + .align 5 prefetch_abort: @@ -363,6 +375,10 @@ irq: addeq lr, sp, #OFFSET_SP_USR stmeqia lr, {sp, lr}^ + @ Save user space TLS context + mrc p15, 0, r0, c13, c0, 0 + str r0, [sp, #OFFSET_TLS_USR] + @ Retrieve the lr_irq to set the pc out of this routine ldr lr, [r0, #4] @ retrieve lr_irq to set lr_svc sub lr, lr, #4 @ Adjust the lr since it is automatically set from pc (in advance of 2 instructions due to the pipeline) @@ -388,6 +404,10 @@ irq: check_pending_signal #endif /* CONFIG_IPC_SIGNAL */ + @ Restore user space TLS context + ldr lr, [sp, #OFFSET_TLS_USR] + mcr p15, 0, lr, c13, c0, 0 + ldr lr, [sp, #OFFSET_PSR] @ get the saved spsr and adjust the stack pointer msr spsr, lr diff --git a/so3/arch/arm32/include/asm/processor.h b/so3/arch/arm32/include/asm/processor.h index a651835c7..56b082d31 100644 --- a/so3/arch/arm32/include/asm/processor.h +++ b/so3/arch/arm32/include/asm/processor.h @@ -349,9 +349,10 @@ typedef struct cpu_regs { __u32 lr; __u32 pc; __u32 psr; - __u32 sp_usr; + __u32 sp_usr; __u32 lr_usr; - __u32 padding; /* padding to keep 8-bytes alignment */ + __u32 tls_usr; + /* Already aligned to 8-bytes, no padding required */ } cpu_regs_t; #define cpu_relax() wfe() diff --git a/so3/arch/arm32/thread.c b/so3/arch/arm32/thread.c index 577a327c8..596f8d882 100644 --- a/so3/arch/arm32/thread.c +++ b/so3/arch/arm32/thread.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2022 Daniel Rossier - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -16,21 +16,74 @@ * */ +#include #include #include /** * Set the CPU registers with thread related information * - * @param tcb + * @param tcb Thread to set registers. + * @param args Clone arguments with values to set to registers. */ -void arch_prepare_cpu_regs(tcb_t *tcb) +void arch_prepare_cpu_regs(tcb_t *tcb, clone_args_t *args) { - tcb->cpu_regs.r4 = (unsigned long) tcb->th_fn; - tcb->cpu_regs.r5 = (unsigned long) tcb->th_arg; /* First argument */ + cpu_regs_t *user_regs; + + if (args->pcb == NULL) { + /* Kernel thread must have a function to call */ + BUG_ON(args->fn == NULL); + tcb->cpu_regs.r4 = (unsigned long) args->fn; + tcb->cpu_regs.r5 = (unsigned long) args->fn_arg; + + tcb->cpu_regs.lr = (unsigned long) __thread_prologue_kernel; + tcb->cpu_regs.sp = get_kernel_stack_top(tcb->stack_slotID); + } else { + user_regs = (cpu_regs_t *) arch_get_kernel_stack_frame(tcb); + + if (args->fn) { + /* Special userspace case to start root process. */ + BUG_ON(args->stack == 0); + arch_restart_user_thread(tcb, args->fn, args->stack); + } else { + /* Normal userspace that will copy userspace registers */ + if (args->stack) { + user_regs->sp_usr = args->stack; + } + + if (args->flags & CLONE_SETTLS) { + user_regs->tls_usr = args->tls; + } - if (tcb->pcb) - tcb->cpu_regs.r6 = get_user_stack_top(tcb->pcb, tcb->pcb_stack_slotID); + /* Copy userspace registers */ + *user_regs = *(cpu_regs_t *) arch_get_kernel_stack_frame(current()); + } + + tcb->cpu_regs.lr = (unsigned long) ret_from_fork; + /* Take into account the user registers frame on the kernel stack */ + tcb->cpu_regs.sp = (addr_t) user_regs; + } +} + +/** + * Restart a user thread by reseting all registers to 0 and settings entry point and stack. + * + * @param tcb Thread to restart. + * @param fn_entry Userspace entry point of the thread. + * @param stack_top New top address of the userspace stack. + */ +void arch_restart_user_thread(tcb_t *tcb, th_fn_t fn_entry, addr_t stack_top) +{ + cpu_regs_t *user_regs = (cpu_regs_t *) arch_get_kernel_stack_frame(tcb); + + /* Reset all user's registers to zero except for PC, PSTATE and SP + * which needs to be set to the properly start the thread. + */ + *user_regs = (cpu_regs_t) { + .pc = (u32) fn_entry, + .psr = PSR_USR_MODE, + .sp_usr = stack_top, + }; } /** @@ -41,3 +94,13 @@ addr_t arch_get_args_base(void) { return (CONFIG_KERNEL_VADDR - PAGE_SIZE); } + +/** + * Get the top address of the kernel stack of a user thread with space for registers values. + * + * @param tcb Thread to get the stack address. + */ +addr_t arch_get_kernel_stack_frame(tcb_t *tcb) +{ + return get_kernel_stack_top(tcb->stack_slotID) - SVC_STACK_FRAME_SIZE; +} diff --git a/so3/arch/arm64/asm-offsets.c b/so3/arch/arm64/asm-offsets.c index da4117c0a..7eee77e69 100644 --- a/so3/arch/arm64/asm-offsets.c +++ b/so3/arch/arm64/asm-offsets.c @@ -85,6 +85,7 @@ int main(void) DEFINE(OFFSET_SP, offsetof(struct cpu_regs, sp)); DEFINE(OFFSET_PC, offsetof(struct cpu_regs, pc)); DEFINE(OFFSET_PSTATE, offsetof(struct cpu_regs, pstate)); + DEFINE(OFFSET_TLS_USR, offsetof(struct cpu_regs, tls_usr)); BLANK(); diff --git a/so3/arch/arm64/context.S b/so3/arch/arm64/context.S index 02dadb14e..30e6d8850 100644 --- a/so3/arch/arm64/context.S +++ b/so3/arch/arm64/context.S @@ -28,7 +28,6 @@ .global __switch_context .global __thread_prologue_kernel -.global __thread_prologue_user .global __exec_prologue_user .globl __get_syscall_args_ext @@ -37,7 +36,6 @@ .global __mmu_switch .global __exec .global __write -.global __save_context .global __root_proc .extern thread_prologue @@ -46,7 +44,6 @@ .global __enable_vfp .extern __check_ptrace_traceme -.extern ret_from_fork #ifdef CONFIG_AVZ @@ -67,7 +64,7 @@ ____switch_to: save_ctx: // store callee-saved registers - stp x19, x20, [x8], #16 + stp x19, x20, [x8], #16 stp x21, x22, [x8], #16 stp x23, x24, [x8], #16 stp x25, x26, [x8], #16 @@ -83,7 +80,7 @@ load_ctx: add x8, x1, x10 // restore callee-saved registers - ldp x19, x20, [x8], #16 + ldp x19, x20, [x8], #16 ldp x21, x22, [x8], #16 ldp x23, x24, [x8], #16 ldp x25, x26, [x8], #16 @@ -141,7 +138,7 @@ ENTRY(__mmu_switch_ttbr1) isb msr ttbr1_el1, x0 - + tlbi alle1 isb @@ -163,7 +160,7 @@ ENTRY(__mmu_switch_vttbr) tlbi alle2 dsb nsh - + ret ENTRY(cpu_do_idle) @@ -197,68 +194,6 @@ __thread_prologue_kernel: bl thread_prologue // Never reached -// User thread initial entry point -// Called once per thread -// x19: th_fn, x20: th_arg, x21: user stack - -__thread_prologue_user: - - msr elr_el1, x19 - - msr sp_el0, x21 - - mov x0, #PSR_MODE_EL0t - - msr spsr_el1, x0 - - // Prepare to jump into C code - mov x0, x20 - -#if 0 - at s1e0r, x19 - isb - mrs x0, par_el1 -#endif - - eret -#if 0 -#ifdef CONFIG_MMU - // Check if the thread must stopped because of ptrace/tracee - stmfd sp!, {r0, r1} - bl __check_ptrace_traceme - ldmfd sp!, {r0, r1} -#endif -#endif - -// Store the current registers into a cpu_regs structure passed in r0 (as first argument) -__save_context: - - // Adjust the kernel stack pointer so that we can proceed with ret_from_fork. - // S_FRAME_SIZE/8 registers are preserved when at the syscall vector entry point - - // Adjust the sp which is stored on the stack. Make sure - // it refers to this stack and not the one issue from the copy - // as during fork(). - - sub x1, x1, #S_FRAME_SIZE - - // Prepare to configure sp during the context switch - str x1, [x0, #(OFFSET_TCB_CPU_REGS + OFFSET_SP)] - - // Prepare the lr to branch to ret_from_fork - ldr x1, .LCret_from_fork - str x1, [x0, #(OFFSET_TCB_CPU_REGS + OFFSET_LR)] - - // Preserve x8 which contains the syscall number (used to compare against SIG_RETURN) - str x8, [x0, #(OFFSET_TCB_CPU_REGS + OFFSET_X8)] - - // The other registers are not important. - - ret - -.LCret_from_fork: - .quad ret_from_fork - .LCcurrent: .quad current_thread diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index 4d8cd4a7f..a1d6a0c58 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -124,7 +124,7 @@ ENTRY(__vectors) // Current EL with SPx / Synchronous .align 7 - + mov x0, lr b trap_handle_error @@ -158,9 +158,9 @@ ENTRY(__vectors) #ifdef CONFIG_AVZ b el12_sync_handler -#else +#else b el01_sync_handler -#endif +#endif // Lower EL using AArch64 / IRQ .align 7 @@ -206,7 +206,7 @@ ENTRY(__vectors) mov x0, lr b trap_handle_error - + #ifdef CONFIG_CPU_SPIN_TABLE @@ -317,7 +317,7 @@ ENTRY(pre_ret_to_el1) .endm -// Exit macro at the end of an exception routine +// Exit macro at the end of an exception routine // It restores the sp_el0 as well. .macro prepare_to_exit_to_el1 ldr x0, [sp, #OFFSET_PC] @@ -375,7 +375,7 @@ cpu_entrypoint: __prepare_to_sig_el1_handler: - /* Preserve the SP_EL2 in the new stack frame used by + /* Preserve the SP_EL2 in the new stack frame used by * the signal handler. */ @@ -387,7 +387,7 @@ __prepare_to_sig_el1_handler: // Build a new stack frame based on the current sub sp, sp, #S_FRAME_SIZE - + // Set the handler to the PC str x21, [sp, #OFFSET_PC] @@ -438,7 +438,7 @@ ENTRY(pre_ret_to_user) ldr x2, [sp, #OFFSET_LR] // Entry point of the guest msr elr_el2, x2 - /* + /* * The MMU must be disabled so that the guest can keep its initial boot code. * Make sure CPU EL1 has MMU disabled. */ @@ -455,7 +455,7 @@ ENTRY(pre_ret_to_user) msr spsr_el2, x2 kernel_exit - + // Ready to jump into the domain... eret @@ -476,23 +476,26 @@ ENTRY(pre_ret_to_user) __prepare_sig_handler: - /* Preserve the SP_EL1 in the new stack frame used by - * the signal handler + /* Preserve the SP_EL1 and the TLS in the new stack frame used + * by the signal handler */ ldr x2, [sp, #OFFSET_SP_USR] str x2, [sp, #(OFFSET_SP_USR - S_FRAME_SIZE)] + ldr x2, [sp, #OFFSET_TLS_USR] + str x2, [sp, #(OFFSET_TLS_USR - S_FRAME_SIZE)] + // Build a new stack frame based on the current sub sp, sp, #S_FRAME_SIZE mov x2, #PSR_MODE_EL0t bic x2, x2, #PSR_I_BIT str x2, [sp, #OFFSET_PSTATE] - + ldr x1, [x0, #OFFSET_SYS_SIGNUM] str x1, [sp, #OFFSET_X0] - + ldr x1, [x0, #OFFSET_SYS_SA] ldr x2, [x1, #OFFSET_SA_HANDLER] str x2, [sp, #OFFSET_X1] @@ -526,12 +529,15 @@ __prepare_sig_handler: mrs x0, sp_el0 str x0, [sp, #OFFSET_SP_USR] + mrs x0, tpidr_el0 + str x0, [sp, #OFFSET_TLS_USR] + mrs x0, spsr_el1 str x0, [sp, #OFFSET_PSTATE] .endm -// Exit macro at the end of an exception routine +// Exit macro at the end of an exception routine // It restores the sp_el0 as well. .macro prepare_to_exit_to_el0 ldr x0, [sp, #OFFSET_PC] @@ -540,6 +546,9 @@ __prepare_sig_handler: ldr x0, [sp, #OFFSET_SP_USR] msr sp_el0, x0 + ldr x0, [sp, #OFFSET_TLS_USR] + msr tpidr_el0, x0 + ldr x0, [sp, #OFFSET_PSTATE] msr spsr_el1, x0 .endm @@ -559,11 +568,11 @@ el01_sync_handler: // clean the stack frame which has been used to manage the user handler. cmp x8, #SYSCALL_rt_sigreturn bne __ret_from_fork - + // Reset the stack frame by removing the one issued from sigreturn add sp, sp, #S_FRAME_SIZE - + __ret_from_fork: #ifdef CONFIG_IPC_SIGNAL @@ -610,7 +619,7 @@ ret_from_fork: ldmfd sp!, {r0-r4} #endif #endif - + #if !defined(CONFIG_AVZ) && defined(CONFIG_SOO) diff --git a/so3/arch/arm64/include/asm/processor.h b/so3/arch/arm64/include/asm/processor.h index 5dfbcef17..b04e79589 100644 --- a/so3/arch/arm64/include/asm/processor.h +++ b/so3/arch/arm64/include/asm/processor.h @@ -1091,7 +1091,7 @@ enum trap_return { * addressed by index */ typedef struct __attribute__((packed, aligned(8))) cpu_regs { - u64 x0; + u64 x0; u64 x1; u64 x2; u64 x3; @@ -1127,8 +1127,12 @@ typedef struct __attribute__((packed, aligned(8))) cpu_regs { u64 pstate; /* is used to keep track of the sp at the higher EL - used for signal-like handler */ - u64 sp_usr; - u64 padding; + u64 sp_usr; + + /* TLS is used by userspace to store thread context */ + u64 tls_usr; + + /* Already aligned on 16 bytes no padding required */ } cpu_regs_t; #ifdef CONFIG_AVZ @@ -1138,12 +1142,12 @@ typedef struct vcpu { cpu_regs_t regs; /* All CPU registers */ /* System registers at EL1 */ - u64 sctlr_el1; - u64 vbar_el1; - u64 ttbr0_el1; - u64 ttbr1_el1; - u64 tcr_el1; - u64 mair_el1; + u64 sctlr_el1; + u64 vbar_el1; + u64 ttbr0_el1; + u64 ttbr1_el1; + u64 tcr_el1; + u64 mair_el1; } vcpu_t; diff --git a/so3/arch/arm64/thread.c b/so3/arch/arm64/thread.c index e3c73425a..80a23493d 100644 --- a/so3/arch/arm64/thread.c +++ b/so3/arch/arm64/thread.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2022 Daniel Rossier - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -16,20 +16,73 @@ * */ +#include #include /** * Set the CPU registers with thread related information * - * @param tcb + * @param tcb Thread to set registers. + * @param args Clone arguments with values to set to registers. */ -void arch_prepare_cpu_regs(tcb_t *tcb) +void arch_prepare_cpu_regs(tcb_t *tcb, clone_args_t *args) { - tcb->cpu_regs.x19 = (unsigned long) tcb->th_fn; - tcb->cpu_regs.x20 = (unsigned long) tcb->th_arg; /* First argument */ + cpu_regs_t *user_regs; + + if (args->pcb == NULL) { + /* Kernel thread must have a function to call */ + BUG_ON(args->fn == NULL); + tcb->cpu_regs.x19 = (unsigned long) args->fn; + tcb->cpu_regs.x20 = (unsigned long) args->fn_arg; + + tcb->cpu_regs.lr = (unsigned long) __thread_prologue_kernel; + tcb->cpu_regs.sp = get_kernel_stack_top(tcb->stack_slotID); + } else { + user_regs = (cpu_regs_t *) arch_get_kernel_stack_frame(tcb); + + if (args->fn) { + /* Special userspace case to start root process. */ + BUG_ON(args->stack == 0); + arch_restart_user_thread(tcb, args->fn, args->stack); + } else { + /* Normal userspace that will copy userspace registers */ + if (args->stack) { + user_regs->sp_usr = args->stack; + } + + if (args->flags & CLONE_SETTLS) { + user_regs->tls_usr = args->tls; + } - if (tcb->pcb) - tcb->cpu_regs.x21 = get_user_stack_top(tcb->pcb, tcb->pcb_stack_slotID); + /* Copy userspace registers */ + *user_regs = *(cpu_regs_t *) arch_get_kernel_stack_frame(current()); + } + + tcb->cpu_regs.lr = (unsigned long) ret_from_fork; + /* Take into account the user registers frame on the kernel stack */ + tcb->cpu_regs.sp = (addr_t) user_regs; + } +} + +/** + * Restart a user thread by reseting all registers to 0 and settings entry point and stack. + * + * @param tcb Thread to restart. + * @param fn_entry Userspace entry point of the thread. + * @param stack_top New top address of the userspace stack. + */ +void arch_restart_user_thread(tcb_t *tcb, th_fn_t fn_entry, addr_t stack_top) +{ + cpu_regs_t *user_regs = (cpu_regs_t *) arch_get_kernel_stack_frame(tcb); + + /* Reset all user's registers to zero except for PC, PSTATE and SP + * which needs to be set to the properly start the program + */ + *user_regs = (cpu_regs_t) { + .pc = (u64) fn_entry, + .pstate = PSR_MODE_EL0t, + .sp_usr = stack_top, + }; } /** @@ -44,3 +97,13 @@ addr_t arch_get_args_base(void) { return (addr_t) (USER_STACK_TOP_VADDR - PAGE_SIZE); } + +/** + * Get the top address of the kernel stack of a user thread with space for registers values. + * + * @param tcb Thread to get the stack address. + */ +addr_t arch_get_kernel_stack_frame(tcb_t *tcb) +{ + return get_kernel_stack_top(tcb->stack_slotID) - S_FRAME_SIZE; +} diff --git a/so3/include/process.h b/so3/include/process.h index 5b444deab..faf1335cd 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -36,7 +36,7 @@ #define PROC_MAX_THREADS CONFIG_MAX_THREADS /* Maximum stack size for a process, including all thread stacks */ -#define PROC_STACK_SIZE (PROC_MAX_THREADS * CONFIG_THREAD_STACK_SIZE_KB * SZ_1K) +#define INITIAL_STACK_SIZE (CONFIG_THREAD_STACK_SIZE_KB * SZ_1K) #define FD_MAX 64 #define N_MUTEX 5 @@ -46,6 +46,33 @@ typedef unsigned int thread_t; #define PROC_NAME_LEN 80 +/* Clone flags */ +#define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ +#define CLONE_VM 0x00000100 /* set if VM shared between processes */ +#define CLONE_FS 0x00000200 /* set if fs info shared between processes */ +#define CLONE_FILES 0x00000400 /* set if open files shared between processes */ +#define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */ +#define CLONE_PIDFD 0x00001000 /* set if a pidfd should be placed in parent */ +#define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ +#define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ +#define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ +#define CLONE_THREAD 0x00010000 /* Same thread group? */ +#define CLONE_NEWNS 0x00020000 /* New mount namespace group */ +#define CLONE_SYSVSEM 0x00040000 /* share system V SEM_UNDO semantics */ +#define CLONE_SETTLS 0x00080000 /* create a new TLS for the child */ +#define CLONE_PARENT_SETTID 0x00100000 /* set the TID in the parent */ +#define CLONE_CHILD_CLEARTID 0x00200000 /* clear the TID in the child */ +#define CLONE_DETACHED 0x00400000 /* Unused, ignored */ +#define CLONE_UNTRACED 0x00800000 /* set if the tracing process can't force CLONE_PTRACE on this clone */ +#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */ +#define CLONE_NEWCGROUP 0x02000000 /* New cgroup namespace */ +#define CLONE_NEWUTS 0x04000000 /* New utsname namespace */ +#define CLONE_NEWIPC 0x08000000 /* New ipc namespace */ +#define CLONE_NEWUSER 0x10000000 /* New user namespace */ +#define CLONE_NEWPID 0x20000000 /* New pid namespace */ +#define CLONE_NEWNET 0x40000000 /* New network namespace */ +#define CLONE_IO 0x80000000 /* Clone io context */ + /* A page might be linked to several processes, hence this type */ typedef struct { struct list_head list; @@ -67,9 +94,6 @@ struct pcb { /* Full descending stack - refers to a "full" word */ addr_t stack_top; - /* Thread stack slots */ - bool stack_slotID[PROC_MAX_THREADS]; - /* Heap management */ addr_t heap_base; @@ -130,9 +154,6 @@ typedef struct pcb pcb_t; extern struct list_head proc_list; -int get_user_stack_slot(pcb_t *pcb); -void free_user_stack_slot(pcb_t *pcb, int slotID); - void add_page_to_proc(pcb_t *pcb, page_t *page); void create_root_process(void); @@ -141,7 +162,8 @@ SYSCALL_DECLARE(getpid, void); SYSCALL_DECLARE(execve, const char *filename, char **argv, char **envp); SYSCALL_DECLARE(fork, void); -SYSCALL_DECLARE(exit, int exit_status); +SYSCALL_DECLARE(clone, unsigned long flags, unsigned long newsp, int *parent_tid, unsigned long tls, int *child_tid); +SYSCALL_DECLARE(exit_group, int exit_status); SYSCALL_DECLARE(wait4, int pid, uint32_t *wstatus, uint32_t options, void *rusage); pcb_t *find_proc_by_pid(uint32_t pid); diff --git a/so3/include/thread.h b/so3/include/thread.h index 32721149e..7c53b09d4 100644 --- a/so3/include/thread.h +++ b/so3/include/thread.h @@ -73,18 +73,14 @@ struct tcb { #endif /* CONFIG_SCHED_PRIO_DYN */ - /* Threaded function */ - th_fn_t th_fn; - void *th_arg; - thread_t state; int stack_slotID; /* Thread kernel slot ID */ /* Reference to the process, if any - typically NULL for kernel threads */ pcb_t *pcb; - int pcb_stack_slotID; /* This is the user space stack slot ID (for user threads) */ - int *exit_status; + int exit_status; + addr_t child_clear_tid; struct list_head list; /* List of threads belonging to a process */ @@ -95,19 +91,40 @@ struct tcb { }; typedef struct tcb tcb_t; -addr_t get_user_stack_top(pcb_t *pcb, uint32_t slotID); +typedef struct { + /* Clone flags to create/copy the current thread */ + uint64_t flags; + const char *name; + + pcb_t *pcb; + + uint32_t prio; + + /* Userspace stack and TLS address */ + addr_t stack; + addr_t tls; + + /* Pointer to userspace parent/child tid to use depending on flags */ + int *parent_tid; + int *child_tid; + + /* Function to call for kernel thread or root user process */ + th_fn_t fn; + + /* Arguments passed to the kernel thread function. For userspace thread, this is ignored + * and arguments must put on top of the stack */ + void *fn_arg; +} clone_args_t; void threads_init(void); -SYSCALL_DECLARE(thread_create, uint32_t *pthread_id, addr_t attr_p, addr_t thread_fn, addr_t arg_p); -SYSCALL_DECLARE(thread_join, uint32_t pthread_id, int **value_p); -SYSCALL_DECLARE(thread_exit, int *exit_status); +SYSCALL_DECLARE(exit, int exit_status); tcb_t *kernel_thread(th_fn_t start_routine, const char *name, void *arg, uint32_t prio); -tcb_t *user_thread(th_fn_t start_routine, const char *name, void *arg, pcb_t *pcb); +tcb_t *user_thread(clone_args_t *args); -int *thread_join(tcb_t *tcb); -void thread_exit(int *exit_status); +int thread_join(tcb_t *tcb); +void thread_exit(int exit_status); void clean_thread(tcb_t *tcb); SYSCALL_DECLARE(thread_yield, void); @@ -117,15 +134,16 @@ addr_t get_kernel_stack_top(uint32_t slotID); extern void __switch_context(tcb_t *prev, tcb_t *next); extern void __thread_prologue_kernel(void); -extern void __thread_prologue_user(void); -extern void __thread_prologue_user_pre_launch(void); +extern void ret_from_fork(void); char *print_state(struct tcb *tcb); void *app_thread_main(void *args); -void arch_prepare_cpu_regs(tcb_t *tcb); +void arch_prepare_cpu_regs(tcb_t *tcb, clone_args_t *args); +void arch_restart_user_thread(tcb_t *tcb, th_fn_t fn_entry, addr_t stack); addr_t arch_get_args_base(void); +addr_t arch_get_kernel_stack_frame(tcb_t *tcb); #endif /* __ASSEMBLY__ */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 13ec54092..15521d8a6 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -62,9 +62,6 @@ char *proc_state_str(proc_state_t state) static uint32_t pid_current = 1; static pcb_t *root_process = NULL; /* root process */ -/* Used to update regs during fork */ -extern void __save_context(tcb_t *newproc, addr_t stack_addr); - /* only the following sections are supported */ #define SUPPORTED_SECTION_COUNT 6 static const char *supported_section_names[SUPPORTED_SECTION_COUNT] = { @@ -207,9 +204,6 @@ pcb_t *new_process(void) pcb->pid = pid_current++; - for (i = 0; i < PROC_MAX_THREADS; i++) - pcb->stack_slotID[i] = false; - /* Init the list of child threads */ INIT_LIST_HEAD(&pcb->threads); @@ -245,7 +239,7 @@ pcb_t *new_process(void) void reset_process_stack(pcb_t *pcb) { /* Set up the main process stack (including all thread stacks) */ - pcb->page_count = ALIGN_UP(PROC_STACK_SIZE, PAGE_SIZE) >> PAGE_SHIFT; + pcb->page_count = ALIGN_UP(INITIAL_STACK_SIZE, PAGE_SIZE) >> PAGE_SHIFT; /* * The stack virtual top is under the page of arguments, from the top @@ -316,6 +310,7 @@ void create_root_process(void) { pcb_t *pcb; int i; + clone_args_t thread_args; local_irq_disable(); @@ -336,9 +331,14 @@ void create_root_process(void) create_mapping(pcb->pgtable, USER_SPACE_VADDR, __pa(__root_proc_start), (void *) __root_proc_end - (void *) __root_proc_start, false); - /* Start main thread of the thread is not used in this context. - */ - pcb->main_thread = user_thread((th_fn_t) USER_SPACE_VADDR, "root_proc", NULL, pcb); + /* Start main user thread. */ + thread_args = (clone_args_t) { + .name = "root_proc", + .pcb = pcb, + .stack = pcb->stack_top, + .fn = (th_fn_t) USER_SPACE_VADDR, + }; + pcb->main_thread = user_thread(&thread_args); /* init process? */ if (!root_process) @@ -701,7 +701,6 @@ SYSCALL_DEFINE3(execve, const char *, filename, char **, argv, char **, envp) pcb_t *pcb; unsigned long flags; th_fn_t start_routine; - queue_thread_t *cur; int ret, argc; /* Count the number of arguments */ @@ -751,42 +750,16 @@ SYSCALL_DEFINE3(execve, const char *, filename, char **, argv, char **, envp) /* Release the kernel buffer used to store the ELF binary image */ elf_clean_image(&elf_img_info); - /* Now, we need to create the main user thread associated to this binary - * image. */ - /* start main thread */ + /* Now, we need to restart the user thread from the new program starting address */ start_routine = (th_fn_t) pcb->bin_image_entry; - /* We start the new thread */ - pcb->main_thread = user_thread(start_routine, pcb->name, (void *) arch_get_args_base(), pcb); - - /* Transfer the waiting thread if any */ - - /* Make sure it is the main thread of the dying thread, i.e. another - * process is waiting on it (the parent) */ - if (!list_empty(¤t()->joinQueue)) { - cur = list_entry(current()->joinQueue.next, queue_thread_t, list); - - ASSERT(cur->tcb->pcb == current()->pcb->parent); - - /* Migrate the entry to the new main thread */ - list_move(&cur->list, &pcb->main_thread->joinQueue); - } - - /* Now, make sure there is no other waiting threads on the dying thread - */ - ASSERT(list_empty(¤t()->joinQueue)); - - /* We detach the thread from its pcb so that thread_exit() can - * distinguish between this kind of (replaced) thread and a standard - * thread which will be stay in zombie state. - */ - current()->pcb = NULL; + /* Rename thread to inlcude new PCB name */ + snprintf(pcb->main_thread->name, THREAD_NAME_LEN, "%s_%d", pcb->name, pcb->main_thread->tid); - /* Finishing the running thread. The final clean_thread() function will - * be called in thread_exit(). */ - thread_exit(0); + /* Arguments base is used as stack address and arguments will be retrieved from it by MUSL. */ + arch_restart_user_thread(pcb->main_thread, start_routine, arch_get_args_base()); - /* IRQs never restored here... */ + local_irq_restore(flags); return 0; } @@ -812,10 +785,6 @@ pcb_t *duplicate_process(pcb_t *parent) pcb->heap_base = parent->heap_base; pcb->heap_pointer = parent->heap_pointer; - /* Duplicate the array of allocated stack slots dedicated to user - * threads */ - memcpy(pcb->stack_slotID, parent->stack_slotID, sizeof(parent->stack_slotID)); - /* Clone all file descriptors */ if (vfs_clone_fd(parent->fd_array, pcb->fd_array)) { LOG_CRITICAL("!! Error while cloning fds\n"); @@ -825,70 +794,109 @@ pcb_t *duplicate_process(pcb_t *parent) return pcb; } -/* - * For a new process from the current running process. - */ -SYSCALL_DEFINE0(fork) +static long do_clone(clone_args_t *args) { - pcb_t *newp, *parent; + /* Flags used by pthread_create in MUSL, only those are supported. */ + static const unsigned long THREAD_FLAGS = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | + CLONE_SYSVSEM | CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | + CLONE_DETACHED; + unsigned long flags; + long ret; + pcb_t *new_pcb, *current_pcb; + tcb_t *new_tcb; flags = local_irq_save(); + current_pcb = current()->pcb; - parent = current()->pcb; + if (args->flags & CLONE_THREAD) { + if (args->flags != THREAD_FLAGS) { + LOG_WARNING("Only pthread_create clone flags are supported for thread\n"); + ret = -EINVAL; + goto error; + } - /* For the time being, we *only* authorize to fork() from the main - * thread */ - if (current() != parent->main_thread) { - LOG_WARNING("%s: forking from a thread other than the main thread " - "is not allowed so far ...\n", - __func__); - return -1; - } + /* Don't need to create a new PCB, use current as "new" PCB to create the thread. */ + new_pcb = current_pcb; + } else { + if (args->flags != 0) { + LOG_WARNING("Clone flags not support for forking\n"); + ret = -EINVAL; + goto error; + } - /* Duplicate the elements of the parent process into the child */ - newp = duplicate_process(parent); + /* For the time being, we *only* authorize to fork() from the main + * thread */ + if (current() != current_pcb->main_thread) { + LOG_WARNING("%s: forking from a thread other than the main thread " + "is not allowed so far ...\n", + __func__); + ret = -EINVAL; + goto error; + } - /* Copy the user space area of the parent process */ - duplicate_user_space(parent, newp); + /* Duplicate the elements of the parent process into the child */ + new_pcb = duplicate_process(current_pcb); - /* At the moment, we spawn the main_thread only in the child. In the - * future, we will have to create a thread for each existing threads in - * the parent process. - */ - sprintf(newp->name, "%s_child_%d", parent->name, newp->pid); + /* Copy the user space area of the parent process */ + duplicate_user_space(current_pcb, new_pcb); - newp->main_thread = user_thread(NULL, newp->name, (void *) arch_get_args_base(), newp); + /* At the moment, we spawn the main_thread only in the child. In the + * future, we will have to create a thread for each existing threads in + * the parent process. + */ + snprintf(new_pcb->name, PROC_NAME_LEN, "%s_child_%d", current_pcb->name, new_pcb->pid); + } + args->pcb = new_pcb; - /* Copy the kernel stack of the main thread */ - memcpy((void *) get_kernel_stack_top(newp->main_thread->stack_slotID) - CONFIG_THREAD_STACK_SIZE_KB * SZ_1K, - (void *) get_kernel_stack_top(parent->main_thread->stack_slotID) - CONFIG_THREAD_STACK_SIZE_KB * SZ_1K, - CONFIG_THREAD_STACK_SIZE_KB * SZ_1K); + /* Use PCB name as thread name. The TID will be appended to it. */ + args->name = new_pcb->name; - /* - * Preserve the current value of all registers concerned by this - * execution so that the new thread will be able to pursue its execution - * once scheduled. - */ + new_tcb = user_thread(args); - __save_context(newp->main_thread, get_kernel_stack_top(newp->main_thread->stack_slotID)); + /* Child thread will return in ret_from_fork and so only parent thread reachs this */ + ret = new_tcb->tid; - /* The main process thread is ready to be scheduled for its execution.*/ - newp->state = PROC_STATE_READY; + if (!(args->flags & CLONE_THREAD)) { + /* The main process thread is ready to be scheduled for its execution.*/ + new_pcb->state = PROC_STATE_READY; - BUG_ON(!local_irq_is_disabled()); + BUG_ON(!local_irq_is_disabled()); - /* Prepare to perform scheduling to check if a context switch is - * required. */ - raise_softirq(SCHEDULE_SOFTIRQ); + /* Prepare to perform scheduling to check if a context switch is + * required. */ + raise_softirq(SCHEDULE_SOFTIRQ); + /* Process clone should return the PID instead of the TID. */ + ret = new_pcb->pid; + } + +error: local_irq_restore(flags); + return ret; +} - /* Return the PID of the child process. The child will do not execute - * this code, since it jumps to the ret_from_fork in context.S - */ +/* + * For a new process from the current running process. + */ +SYSCALL_DEFINE0(fork) +{ + clone_args_t args = {}; - return newp->pid; + return do_clone(&args); +} + +SYSCALL_DEFINE5(clone, unsigned long, flags, unsigned long, newsp, int *, parent_tid, unsigned long, tls, int *, child_tid) +{ + clone_args_t args = { + .flags = flags & ~CSIGNAL, + .stack = newsp, + .parent_tid = parent_tid, + .tls = tls, + .child_tid = child_tid, + }; + + return do_clone(&args); } /* @@ -896,7 +904,7 @@ SYSCALL_DEFINE0(fork) * All allocated resources should be released except its PCB which still * contains the exit code. */ -SYSCALL_DEFINE1(exit, int, exit_status) +SYSCALL_DEFINE1(exit_group, int, exit_status) { pcb_t *pcb; unsigned i; @@ -955,7 +963,7 @@ SYSCALL_DEFINE1(exit, int, exit_status) * will lead to the wake up of the parent. */ - thread_exit(NULL); + thread_exit(0); return 0; } @@ -1121,7 +1129,7 @@ SYSCALL_DEFINE1(brk, long, increment) pcb->page_count += 1; allocate_page(pcb, pcb->heap_base, page_count); pcb->heap_pointer = pcb->heap_base + PAGE_SIZE; - } + } return -1; } diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 51062add5..7c53ddb76 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2014-2019 Daniel Rossier * Copyright (C) 2017 Xavier Ruppen - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -138,7 +138,7 @@ bool kernel_stack_slot[CONFIG_MAX_THREADS]; * Get the kernel stack (top), full descending - The kernel stack is divided into small stack areas * used for individual kernel *and* user threads (in SVC mode). * - * The first stack area is the initial system stack. + * The first stack area is the initial system stack. * The first thread stack slot ID #0 starts right after the initial system stack. */ addr_t get_kernel_stack_top(uint32_t slotID) @@ -187,41 +187,6 @@ void free_kernel_stack_slot(int slotID) kernel_stack_slot[slotID] = false; } -/* Process thread stack management */ - -/* Get the kernel stack (top), full descending */ -addr_t get_user_stack_top(pcb_t *pcb, uint32_t slotID) -{ - return (addr_t) ((void *) pcb->stack_top - slotID * CONFIG_THREAD_STACK_SIZE_KB * SZ_1K); -} - -/* - * Reserve a (user space) stack slot dedicated to a user thread. - */ -int get_user_stack_slot(pcb_t *pcb) -{ - unsigned int i; - - for (i = 0; i < PROC_MAX_THREADS; i++) { - if (!pcb->stack_slotID[i]) { - pcb->stack_slotID[i] = true; - - return i; - } - } - - /* No free stack slot */ - return -1; -} - -/* - * Release the user space stack slot. - */ -void free_user_stack_slot(pcb_t *pcb, int slotID) -{ - pcb->stack_slotID[slotID] = false; -} - #warning free_queue_thread() unused at the moment... void free_queue_thread(struct list_head *aList) { @@ -239,7 +204,7 @@ void free_queue_thread(struct list_head *aList) /* * Thread exit routine */ -void thread_exit(int *exit_status) +void thread_exit(int exit_status) { queue_thread_t *cur; struct list_head *pos, *q; @@ -272,7 +237,7 @@ void thread_exit(int *exit_status) remove_tcb_from_pcb(current()); #ifdef CONFIG_PROC_ENV - sys_do_exit(0); + sys_do_exit_group(0); #endif } else { @@ -306,6 +271,7 @@ void thread_exit(int *exit_status) * (This is currently a limitation: kernel threads can not join other threads). */ #warning Kernel threads cannot join other threads! +#warning TODO: check for clear_child_tid usage if (current()->pcb != NULL) zombie(); @@ -335,7 +301,7 @@ void thread_prologue(void (*th_fn)(void *arg), void *arg) * If we reach this point, it means that a kernel thread has finished its execution. */ - thread_exit(NULL); + thread_exit(0); } /* @@ -377,16 +343,12 @@ void set_thread_registers(tcb_t *thread, cpu_regs_t *regs) memcpy(&thread->cpu_regs, regs, sizeof(cpu_regs_t)); } -/* +/** * Thread creation routine * - * @start_routine: function to be threaded; if NULL, it means we are along a fork() processing. - * @name: name of the thread. Warning ! The caller must foresee a concatenation of the tid to the string. - * @arg: pointer to possible args - * @pcb: NULL means it is a pure kernel thread, otherwise is is a user thread. - * @prio: 0 means the default priority, otherwise set to the thread to the corresponding priority + * @param args Aguments to create the thread */ -tcb_t *thread_create(th_fn_t start_routine, const char *name, void *arg, pcb_t *pcb, uint32_t prio) +tcb_t *thread_create(clone_args_t *args) { tcb_t *tcb; unsigned long flags; @@ -405,18 +367,15 @@ tcb_t *thread_create(th_fn_t start_routine, const char *name, void *arg, pcb_t * tcb->tid = tid_next++; /* We append the tid to the thread name */ - snprintf(tcb->name, THREAD_NAME_LEN, "%s_%d", name, tcb->tid); - - tcb->th_fn = start_routine; - tcb->th_arg = arg; + snprintf(tcb->name, THREAD_NAME_LEN, "%s_%d", args->name, tcb->tid); - if (prio) - tcb->prio = prio; + if (args->prio) + tcb->prio = args->prio; else tcb->prio = THREAD_PRIO_DEFAULT; tcb->state = THREAD_STATE_NEW; - tcb->pcb = pcb; + tcb->pcb = args->pcb; /* Init the thread kernel stack (svc mode) for both kernel and user thread. */ tcb->stack_slotID = get_kernel_stack_slot(); @@ -426,57 +385,75 @@ tcb_t *thread_create(th_fn_t start_routine, const char *name, void *arg, pcb_t * kernel_panic(); } - /* Prepare the user stack if any related PCB */ - if (tcb->pcb) { - /* Prepare the user stack */ - tcb->pcb_stack_slotID = get_user_stack_slot(tcb->pcb); - if (tcb->pcb_stack_slotID < 0) { - printk("No available user stack for a new thread\n"); - kernel_panic(); - } - } - /* Prepare registers for future restore in switch_context() */ - arch_prepare_cpu_regs(tcb); - - /* Quite common registers on various architectures */ - tcb->cpu_regs.sp = get_kernel_stack_top(tcb->stack_slotID); - - if (tcb->pcb) - tcb->cpu_regs.lr = (unsigned long) __thread_prologue_user; - else - tcb->cpu_regs.lr = (unsigned long) __thread_prologue_kernel; + arch_prepare_cpu_regs(tcb, args); /* Initialize the join queue associated to this thread */ INIT_LIST_HEAD(&tcb->joinQueue); /* We do not want to have the idle thread as a "ready" thread */ - if (start_routine != thread_idle) + if (args->fn != thread_idle) ready(tcb); + if (args->flags & CLONE_PARENT_SETTID) { + /* Return the TID of the child thread. The child will not execute + * this code, since it jumps to the ret_from_fork in context.S + */ + *args->parent_tid = tcb->tid; + } + + if (args->flags & CLONE_CHILD_CLEARTID) { + tcb->child_clear_tid = (addr_t) args->child_tid; + } + local_irq_restore(flags); return tcb; } +/** + * Create a new kernel thread. + * + * @param start_routine Kernel function to call in the thread. + * @param name Name of the thread. + * @param arg Arguments passed to the function called by the thread. + * @param prio The thread scheduling priority. + */ tcb_t *kernel_thread(th_fn_t start_routine, const char *name, void *arg, uint32_t prio) { - return thread_create(start_routine, name, arg, NULL, prio); + clone_args_t args = { + .name = name, + .fn = start_routine, + .fn_arg = arg, + .prio = prio, + }; + + return thread_create(&args); } /** - * Should not be called directly. - * Called by create_process() or create_child_thread() instead. + * Create a new user thread based on given arguments. * - * @param start_routine Address ot the thread routine - * @param name Name of the thread - * @param arg Argument of the thread - * @param pcb PCB which the thread belongs to - * @return Address of the corresponding TCB + * @param args + * @return Address of the corresponding TCB */ -tcb_t *user_thread(th_fn_t start_routine, const char *name, void *arg, pcb_t *pcb) +tcb_t *user_thread(clone_args_t *args) { - return thread_create(start_routine, name, arg, pcb, (pcb->main_thread ? pcb->main_thread->prio : 0)); + tcb_t *tcb; + + args->prio = (args->flags & CLONE_THREAD) ? args->pcb->main_thread->prio : 0; + + tcb = thread_create(args); + + if (args->flags & CLONE_THREAD) { + /* Insert the newly thread to the thread list of this process */ + list_add_tail(&tcb->list, &args->pcb->threads); + } else { + BUG_ON(args->pcb->main_thread != NULL); + args->pcb->main_thread = tcb; + } + + return tcb; } /* @@ -505,10 +482,10 @@ void clean_thread(tcb_t *tcb) * The target thread which we are trying to join will be definitively removed * from the system when no other threads are joining it too. */ -int *thread_join(tcb_t *tcb) +int thread_join(tcb_t *tcb) { queue_thread_t *cur; - int *exit_status; + int exit_status; tcb_t *_tcb; struct list_head *pos, *q; unsigned long flags; @@ -565,14 +542,14 @@ int *thread_join(tcb_t *tcb) /* Check if the child is a tracee (and therefore we have a tracer on it) */ if ((tcb != NULL) && (tcb->pcb->ptrace_pending_req != PTRACE_NO_REQUEST)) { - exit_status = NULL; + exit_status = 0; } else { /* The joined thread *must* be in zombie */ ASSERT(tcb->state == THREAD_STATE_ZOMBIE); if (is_main_thread) - exit_status = (void *) ((unsigned long) tcb->pcb->exit_status); + exit_status = tcb->pcb->exit_status; else exit_status = tcb->exit_status; @@ -597,86 +574,12 @@ int *thread_join(tcb_t *tcb) return exit_status; } -/* - * do_thread_create is the syscall implementation behind the pthread_create() called in the libc. - * - * @pthread_p refers to the address of the resulting pthread_t id - * @attr_p refers to the address of pthread attributes - * @thread_fn refers to the threaded function in the user space - * @arg_p refers to the arguments passed to the threaded function - * - * The function returns 0 if successful. - */ - -SYSCALL_DEFINE4(thread_create, uint32_t *, pthread_id, addr_t, attr_p, addr_t, thread_fn, addr_t, arg_p) -{ - unsigned long flags; - tcb_t *tcb; - char *name; - - flags = local_irq_save(); - - /* Create a child thread for the running process */ - - /* Temporary name for this thread */ - name = (char *) malloc(THREAD_NAME_LEN); - if (!name) { - printk("%s: heap overflow...\n", __func__); - kernel_panic(); - } - snprintf(name, THREAD_NAME_LEN, "thread_p%d", current()->pcb->pid); - - tcb = user_thread((th_fn_t) thread_fn, name, (void *) arg_p, current()->pcb); - - /* The name has been copied in thread creation */ - free(name); - - /* Insert the newly thread to the thread list of this process */ - list_add_tail(&tcb->list, ¤t()->pcb->threads); - - *pthread_id = tcb->tid; - - local_irq_restore(flags); - - return 0; -} - -/* - * Join an existing thread - */ -SYSCALL_DEFINE2(thread_join, uint32_t, pthread_id, int **, value_p) -{ - tcb_t *tcb; - int *ret; - unsigned long flags; - - flags = local_irq_save(); - - tcb = find_thread_by_tid(current()->pcb, pthread_id); - - if (tcb == NULL) { - return -EINVAL; - } - - ret = thread_join(tcb); - - if (value_p != NULL) - *value_p = ret; - - local_irq_restore(flags); - - return 0; -} - /* * do_thread_exit() is called when pthread_exit() is executed. */ -SYSCALL_DEFINE1(thread_exit, int *, exit_status) +SYSCALL_DEFINE1(exit, int, exit_status) { /* Unallocate the user space stack slot if it is not the main thread */ - if (current() != current()->pcb->main_thread) - free_user_stack_slot(current()->pcb, current()->pcb_stack_slotID); - thread_exit(exit_status); return 0; diff --git a/so3/syscall.tbl b/so3/syscall.tbl index 1a3921119..b90fa3a58 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -46,7 +46,9 @@ rt_sigreturn IPC_SIGNAL getpid MMU execve MMU fork MMU +clone MMU exit MMU +exit_group MMU wait4 MMU ptrace MMU gettimeofday MMU From 539a7ed2b95ce2d9e5bd267033e0da231b2636f1 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Fri, 7 Nov 2025 11:41:32 +0100 Subject: [PATCH 30/69] [futex] Clean-up Signed-off-by: Jean-Pierre Miceli --- so3/include/futex.h | 38 +++++++++----------------------------- so3/kernel/futex.c | 44 ++++++++++++++++++++++++++++++-------------- so3/kernel/process.c | 6 +----- 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/so3/include/futex.h b/so3/include/futex.h index c51a9bd2d..426da9673 100644 --- a/so3/include/futex.h +++ b/so3/include/futex.h @@ -41,47 +41,27 @@ #define FUTEX_CLOCK_REALTIME 256 #define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) -/* - * Hash buckets are shared by all the futex_keys that hash to the same - * location. Each key may have multiple futex_q structures, one for each task - * waiting on a futex. +/** + * list of thread (waiter) waiting on a futex */ -// struct futex_hash_bucket { -// atomic_t waiters; -// spinlock_t lock; -// struct plist_head chain; -// }; - typedef struct futex_el { struct list_head list; - tcb_t *tcb; + tcb_t *waiter; } futex_el_t; +/** + * list of futexes + */ typedef struct futex { struct list_head list; struct list_head f_element; uintptr_t key; } futex_t; - -/** - * struct futex_q - The hashed futex queue entry, one per waiting task - * - * @list: priority-sorted list of tasks waiting on this futex - * @lock_ptr: the hash bucket lock - * @key: the key the futex is hashed on - * @task: the task waiting on the futex - */ -// struct futex_q { -// struct plist_node list; -// struct futex_hash_bucket *lock_ptr; -// struct futex_key key; -// struct task_struct *task; // the sleeping thread -// }; - - - SYSCALL_DECLARE(futex, u32 *uaddr, int op, u32 val, const struct timespec * utime, u32 *uaddr2, u32 val3) + +void futex_init(pcb_t *pcb); + #endif /* FUTEX_H */ diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c index 157c54015..d3f6ac876 100644 --- a/so3/kernel/futex.c +++ b/so3/kernel/futex.c @@ -22,9 +22,11 @@ #include /** - * do_futex_wait - + * do_futex_wait - block on futex_w * - * @param futex_w + * @param futex_w address of the futex word + * @param val expected value of the futex word + * @return 0 on success or error value */ static int do_futex_wait(uint32_t *futex_w, uint32_t val) { @@ -55,6 +57,7 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) futex->key = (uintptr_t)futex_w; + INIT_LIST_HEAD(&futex->f_element); list_add_tail(&futex->list, &pcb->futex); } @@ -63,7 +66,7 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) if (f_element == NULL) BUG(); - f_element->tcb = current(); + f_element->waiter = current(); list_add_tail(&f_element->list, &futex->f_element); @@ -78,7 +81,13 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) return 0; } -static int do_futex_wake(uint32_t *futex_w, uint32_t val) +/** + * do_futex_wake - wake one or more tasks blocked on uaddr + * + * @nr_wake wake up to this many tasks + * @return the number of waiters that were woken up + */ +static int do_futex_wake(uint32_t *futex_w, uint32_t nr_wake) { unsigned long flags; pcb_t *pcb = current()->pcb; @@ -101,15 +110,15 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t val) /* key does not exists in futex - Error */ BUG(); - /* wakes at most val of the waiters that are waiting */ + /* wakes at most nr_wake of the waiters that are waiting */ list_for_each_safe(pos, p, &futex->list) { f_element = list_entry(pos, futex_el_t, list); - if (idx == val) + if (idx == nr_wake) break; list_del(&f_element->list); - ready(f_element->tcb); + ready(f_element->waiter); idx++; } @@ -120,13 +129,10 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t val) } - SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, const struct timespec *, utime, uint32_t *, uaddr2, uint32_t, val3) { - - // unsigned int flags = futex_to_flags(op); int cmd = op & FUTEX_CMD_MASK; switch (cmd) { @@ -134,7 +140,14 @@ SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, return do_futex_wait(uaddr, val); case FUTEX_WAKE: return do_futex_wake(uaddr, val); - default: + case FUTEX_FD: + case FUTEX_REQUEUE: + case FUTEX_CMP_REQUEUE: + case FUTEX_WAKE_OP: + case FUTEX_LOCK_PI: + case FUTEX_UNLOCK_PI: + case FUTEX_TRYLOCK_PI: + case FUTEX_WAIT_BITSET: printk("Futex cmd '%d' not supported !\n"); return -EINVAL; } @@ -142,10 +155,13 @@ SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, return -ENOSYS; } - -void futex_init(void) +/** + * futex_init - Futex initialization + */ +void futex_init(pcb_t *pcb) { - + INIT_LIST_HEAD(&pcb->futex); + spin_lock_init(&pcb->futex_lock); } diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 3e0eff200..41cf33917 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -206,8 +206,7 @@ pcb_t *new_process(void) INIT_LIST_HEAD(&pcb->page_list); /* Init the futex */ - INIT_LIST_HEAD(&pcb->futex); - spin_lock_init(&pcb->futex_lock); + futex_init(pcb); pcb->pid = pid_current++; @@ -217,9 +216,6 @@ pcb_t *new_process(void) /* Init the list of child threads */ INIT_LIST_HEAD(&pcb->threads); - /* Init the 'futex' list */ - INIT_LIST_HEAD(&pcb->futex); - /* Process-related memory management */ /* Create the 1st level page table */ From d53c4e7b252231eeae9f84ab2d611f74fa2be44b Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Fri, 7 Nov 2025 11:54:12 +0100 Subject: [PATCH 31/69] [futex] fix clang-format Signed-off-by: Jean-Pierre Miceli --- so3/include/futex.h | 28 +++++++++++++--------------- so3/kernel/futex.c | 19 +++++++------------ 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/so3/include/futex.h b/so3/include/futex.h index 426da9673..5777e29b7 100644 --- a/so3/include/futex.h +++ b/so3/include/futex.h @@ -26,20 +26,20 @@ #include /* Commands */ -#define FUTEX_WAIT 0 -#define FUTEX_WAKE 1 -#define FUTEX_FD 2 -#define FUTEX_REQUEUE 3 -#define FUTEX_CMP_REQUEUE 4 -#define FUTEX_WAKE_OP 5 -#define FUTEX_LOCK_PI 6 -#define FUTEX_UNLOCK_PI 7 -#define FUTEX_TRYLOCK_PI 8 -#define FUTEX_WAIT_BITSET 9 +#define FUTEX_WAIT 0 +#define FUTEX_WAKE 1 +#define FUTEX_FD 2 +#define FUTEX_REQUEUE 3 +#define FUTEX_CMP_REQUEUE 4 +#define FUTEX_WAKE_OP 5 +#define FUTEX_LOCK_PI 6 +#define FUTEX_UNLOCK_PI 7 +#define FUTEX_TRYLOCK_PI 8 +#define FUTEX_WAIT_BITSET 9 #define FUTEX_PRIVATE_FLAG 128 -#define FUTEX_CLOCK_REALTIME 256 -#define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) +#define FUTEX_CLOCK_REALTIME 256 +#define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) /** * list of thread (waiter) waiting on a futex @@ -58,9 +58,7 @@ typedef struct futex { uintptr_t key; } futex_t; -SYSCALL_DECLARE(futex, u32 *uaddr, int op, u32 val, const struct timespec * utime, - u32 *uaddr2, u32 val3) - +SYSCALL_DECLARE(futex, u32 *uaddr, int op, u32 val, const struct timespec *utime, u32 *uaddr2, u32 val3) void futex_init(pcb_t *pcb); diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c index d3f6ac876..819e72d7e 100644 --- a/so3/kernel/futex.c +++ b/so3/kernel/futex.c @@ -45,24 +45,24 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) list_for_each(pos, &pcb->futex) { futex = list_entry(pos, futex_t, list); - if ((uintptr_t)futex_w == futex->key) + if ((uintptr_t) futex_w == futex->key) break; } if (pos == &pcb->futex) { /* no futex on futex_w */ - futex = (futex_t *)calloc(1, sizeof(futex_t)); + futex = (futex_t *) calloc(1, sizeof(futex_t)); if (futex == NULL) BUG(); - futex->key = (uintptr_t)futex_w; + futex->key = (uintptr_t) futex_w; INIT_LIST_HEAD(&futex->f_element); list_add_tail(&futex->list, &pcb->futex); } /* Add the thread in the futex_element list */ - f_element = (futex_el_t *)calloc(1, sizeof(futex_el_t)); + f_element = (futex_el_t *) calloc(1, sizeof(futex_el_t)); if (f_element == NULL) BUG(); @@ -102,7 +102,7 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t nr_wake) list_for_each(pos, &pcb->futex) { futex = list_entry(pos, futex_t, list); - if ((uintptr_t)futex_w == futex->key) + if ((uintptr_t) futex_w == futex->key) break; } @@ -126,12 +126,10 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t nr_wake) spin_unlock_irqrestore(&pcb->futex_lock, flags); return 0; - } -SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, - const struct timespec *, utime, - uint32_t *, uaddr2, uint32_t, val3) +SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, const struct timespec *, utime, uint32_t *, uaddr2, uint32_t, + val3) { int cmd = op & FUTEX_CMD_MASK; @@ -163,6 +161,3 @@ void futex_init(pcb_t *pcb) INIT_LIST_HEAD(&pcb->futex); spin_lock_init(&pcb->futex_lock); } - - - From 5746fa60eb6f189966403b510169cea0a764a4d9 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 10 Nov 2025 08:31:38 +0100 Subject: [PATCH 32/69] Remove "mutex" syscalls Signed-off-by: Jean-Pierre Miceli --- so3/include/mutex.h | 4 ---- so3/kernel/mutex.c | 21 --------------------- 2 files changed, 25 deletions(-) diff --git a/so3/include/mutex.h b/so3/include/mutex.h index 49f3847c9..2e8f2d63a 100644 --- a/so3/include/mutex.h +++ b/so3/include/mutex.h @@ -59,8 +59,4 @@ void mutex_lock(struct mutex *lock); void mutex_unlock(struct mutex *lock); void mutex_init(struct mutex *lock); -SYSCALL_DECLARE(mutex_init, void); -SYSCALL_DECLARE(mutex_lock, unsigned long number); -SYSCALL_DECLARE(mutex_unlock, unsigned long number); - #endif /* MUTEX_H */ diff --git a/so3/kernel/mutex.c b/so3/kernel/mutex.c index 7915cef27..4714292e9 100644 --- a/so3/kernel/mutex.c +++ b/so3/kernel/mutex.c @@ -146,27 +146,6 @@ void mutex_unlock(struct mutex *lock) schedule(); } -/* - * The following syscall implementation are a first attempt, mainly used for debugging kernel mutexes. - */ -SYSCALL_DEFINE1(mutex_lock, unsigned long, number) -{ - if (number >= N_MUTEX) { - return -EINVAL; - } - mutex_lock(¤t()->pcb->lock[number]); - return 0; -} - -SYSCALL_DEFINE1(mutex_unlock, unsigned long, number) -{ - if (number >= N_MUTEX) { - return -EINVAL; - } - mutex_unlock(¤t()->pcb->lock[number]); - return 0; -} - void mutex_init(struct mutex *lock) { memset(lock, 0, sizeof(struct mutex)); From 7bf11399ca7bc91cc0ef47639656653f12ce0096 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 10 Nov 2025 08:45:46 +0100 Subject: [PATCH 33/69] fix style and missing comments --- so3/arch/arm32/thread.c | 6 ++---- so3/arch/arm64/thread.c | 6 ++---- so3/kernel/thread.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/so3/arch/arm32/thread.c b/so3/arch/arm32/thread.c index 596f8d882..ba2ad7973 100644 --- a/so3/arch/arm32/thread.c +++ b/so3/arch/arm32/thread.c @@ -47,13 +47,11 @@ void arch_prepare_cpu_regs(tcb_t *tcb, clone_args_t *args) arch_restart_user_thread(tcb, args->fn, args->stack); } else { /* Normal userspace that will copy userspace registers */ - if (args->stack) { + if (args->stack) user_regs->sp_usr = args->stack; - } - if (args->flags & CLONE_SETTLS) { + if (args->flags & CLONE_SETTLS) user_regs->tls_usr = args->tls; - } /* Copy userspace registers */ *user_regs = *(cpu_regs_t *) arch_get_kernel_stack_frame(current()); diff --git a/so3/arch/arm64/thread.c b/so3/arch/arm64/thread.c index 80a23493d..e9416929f 100644 --- a/so3/arch/arm64/thread.c +++ b/so3/arch/arm64/thread.c @@ -46,13 +46,11 @@ void arch_prepare_cpu_regs(tcb_t *tcb, clone_args_t *args) arch_restart_user_thread(tcb, args->fn, args->stack); } else { /* Normal userspace that will copy userspace registers */ - if (args->stack) { + if (args->stack) user_regs->sp_usr = args->stack; - } - if (args->flags & CLONE_SETTLS) { + if (args->flags & CLONE_SETTLS) user_regs->tls_usr = args->tls; - } /* Copy userspace registers */ *user_regs = *(cpu_regs_t *) arch_get_kernel_stack_frame(current()); diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 7c53ddb76..86efae402 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -347,6 +347,8 @@ void set_thread_registers(tcb_t *thread, cpu_regs_t *regs) * Thread creation routine * * @param args Aguments to create the thread + * + * @return TCB of the newly created thread. */ tcb_t *thread_create(clone_args_t *args) { @@ -402,9 +404,8 @@ tcb_t *thread_create(clone_args_t *args) *args->parent_tid = tcb->tid; } - if (args->flags & CLONE_CHILD_CLEARTID) { + if (args->flags & CLONE_CHILD_CLEARTID) tcb->child_clear_tid = (addr_t) args->child_tid; - } local_irq_restore(flags); @@ -418,6 +419,8 @@ tcb_t *thread_create(clone_args_t *args) * @param name Name of the thread. * @param arg Arguments passed to the function called by the thread. * @param prio The thread scheduling priority. + * + * @return TCB of the newly created thread. */ tcb_t *kernel_thread(th_fn_t start_routine, const char *name, void *arg, uint32_t prio) { @@ -434,8 +437,9 @@ tcb_t *kernel_thread(th_fn_t start_routine, const char *name, void *arg, uint32_ /** * Create a new user thread based on given arguments. * - * @param args - * @return Address of the corresponding TCB + * @param args Aguments to create the user thread + * + * @return TCB of the newly created thread. */ tcb_t *user_thread(clone_args_t *args) { From fde2c2c01a2373582d26017697f00d190ca20015 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 10 Nov 2025 11:51:58 +0100 Subject: [PATCH 34/69] [usr] Use musl as libc - It does not compile ! Signed-off-by: Jean-Pierre Miceli --- usr/CMakeLists.txt | 4 +--- usr/aarch64-linux-musl.cmake | 30 ++++++++++++++++++++++++++++++ usr/build.sh | 2 +- usr/lib/CMakeLists.txt | 1 - usr/src/CMakeLists.txt | 22 +++++++++++----------- 5 files changed, 43 insertions(+), 16 deletions(-) create mode 100644 usr/aarch64-linux-musl.cmake diff --git a/usr/CMakeLists.txt b/usr/CMakeLists.txt index 0433beb7c..5fedd4609 100644 --- a/usr/CMakeLists.txt +++ b/usr/CMakeLists.txt @@ -18,7 +18,6 @@ option(MICROPYTHON "Support for micro-python apps" OFF) include_directories( src lib - lib/libc/include lib/lvgl lib/lvgl/src lib/slv @@ -47,8 +46,7 @@ add_link_options(-T ${CMAKE_SOURCE_DIR}/lib/libc/arm.lds -N -warn-common elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") -add_link_options(-T ${CMAKE_SOURCE_DIR}/lib/libc/aarch64.lds -N -warn-common - -warn-constructors -warn-multiple-gp -L ${libgcc_path} -lgcc +add_link_options(-N -Wl,--warn-common ) endif() diff --git a/usr/aarch64-linux-musl.cmake b/usr/aarch64-linux-musl.cmake new file mode 100644 index 000000000..ea136c856 --- /dev/null +++ b/usr/aarch64-linux-musl.cmake @@ -0,0 +1,30 @@ +# +# CMake toolchain information for SO3 build +# Inspired from buildroot generated toolchain.cmake +# +# Target musl libc + +set(CMAKE_SYSTEM_NAME SO3_usr) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS") +set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release CFLAGS") + +set(CMAKE_BUILD_TYPE Release CACHE STRING "SO3 user applications build system") + +set(CMAKE_INSTALL_SO_NO_EXE 0) + +set(CMAKE_C_COMPILER "aarch64-linux-musl-gcc") +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +set(CMAKE_CXX_COMPILER "aarch64-linux-musl-g++") +# set(CMAKE_C_LINK_EXECUTABLE "aarch64-linux-musl-ld -o ") +set(CMAKE_ASM_COMPILER "aarch64-linux-musl-gcc") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D__ARM64__ -fno-common") + +set(CMAKE_ASM_FLAGS "-D__ARM64__ -D__ASSEMBLY__") + +#set(CMAKE_LINKER "aarch64-none-elf-ld") + +set(CMAKE_EXE_LINKER_FLAGS "-Os -static" CACHE STRING "SO3 usr LDFLAGS for executables") \ No newline at end of file diff --git a/usr/build.sh b/usr/build.sh index 7c1556e35..61e645813 100755 --- a/usr/build.sh +++ b/usr/build.sh @@ -87,7 +87,7 @@ cd $SCRIPTPATH/build if [ "$PLATFORM" = "virt32" -o "$PLATFORM" = "vexpress" -o "$PLATFORM" = "rpi4" ]; then default_toolchain="arm_toolchain.cmake" elif [ "$PLATFORM" = "virt64" -o "$PLATFORM" = "rpi4_64" ]; then - default_toolchain="aarch64_toolchain.cmake" + default_toolchain="aarch64-linux-musl.cmake" elif [ -z "$USR_BUILD_TOOLCHAIN_FILE" ]; then # Only fail if no custom toolchain is provided echo "Unsupported PLATFORM ($PLATFORM) and no TOOLCHAIN_FILE specified" diff --git a/usr/lib/CMakeLists.txt b/usr/lib/CMakeLists.txt index 3fa009bf1..9a323dbe0 100644 --- a/usr/lib/CMakeLists.txt +++ b/usr/lib/CMakeLists.txt @@ -2,7 +2,6 @@ set(ORIGINAL_C_FLAGS "${CMAKE_C_FLAGS}") string(REPLACE "-Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -add_subdirectory(libc) set(LV_BUILD_CONF_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Directory containing lv_conf.h") diff --git a/usr/src/CMakeLists.txt b/usr/src/CMakeLists.txt index 9042b761d..f388b89b1 100644 --- a/usr/src/CMakeLists.txt +++ b/usr/src/CMakeLists.txt @@ -11,17 +11,17 @@ add_executable(lvgl_perf.elf lvgl_perf.c) add_executable(lvgl_benchmark.elf lvgl_benchmark.c) add_executable(logs_example.elf logs_example.c) -target_link_libraries(init.elf c) -target_link_libraries(sh.elf c) -target_link_libraries(ls.elf c) -target_link_libraries(more.elf c) -target_link_libraries(time.elf c) -target_link_libraries(ping.elf c) -target_link_libraries(mydev_test.elf c) -target_link_libraries(lvgl_demo.elf c slv lvgl lvgl_demos) -target_link_libraries(lvgl_perf.elf c slv lvgl lvgl_demos) -target_link_libraries(lvgl_benchmark.elf c slv lvgl lvgl_demos) -target_link_libraries(logs_example.elf c capsule_logs) +target_link_libraries(init.elf) +target_link_libraries(sh.elf) +target_link_libraries(ls.elf) +target_link_libraries(more.elf) +target_link_libraries(time.elf) +target_link_libraries(ping.elf) +target_link_libraries(mydev_test.elf) +target_link_libraries(lvgl_demo.elf slv lvgl lvgl_demos) +target_link_libraries(lvgl_perf.elf slv lvgl lvgl_demos) +target_link_libraries(lvgl_benchmark.elf slv lvgl lvgl_demos) +target_link_libraries(logs_example.elf capsule_logs) if (MICROPYTHON AND (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")) message("== Building uPython") From ab43bbcde2ea6ac84e6c43b392d8d0a89584d028 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 10 Nov 2025 16:27:33 +0100 Subject: [PATCH 35/69] [futex] clean-up based on code review Signed-off-by: Jean-Pierre Miceli --- so3/include/futex.h | 13 ++----------- so3/kernel/futex.c | 44 ++++++++++++++++++++------------------------ so3/kernel/process.c | 3 ++- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/so3/include/futex.h b/so3/include/futex.h index 5777e29b7..688bc56f9 100644 --- a/so3/include/futex.h +++ b/so3/include/futex.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2014-2018 Daniel Rossier + * Copyright (C) 2014-2025 Daniel Rossier + * Copyright (C) 2025 Jean-Pierre Miceli * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -41,14 +42,6 @@ #define FUTEX_CLOCK_REALTIME 256 #define FUTEX_CMD_MASK ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME) -/** - * list of thread (waiter) waiting on a futex - */ -typedef struct futex_el { - struct list_head list; - tcb_t *waiter; -} futex_el_t; - /** * list of futexes */ @@ -60,6 +53,4 @@ typedef struct futex { SYSCALL_DECLARE(futex, u32 *uaddr, int op, u32 val, const struct timespec *utime, u32 *uaddr2, u32 val3) -void futex_init(pcb_t *pcb); - #endif /* FUTEX_H */ diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c index 819e72d7e..346f4ec30 100644 --- a/so3/kernel/futex.c +++ b/so3/kernel/futex.c @@ -34,12 +34,14 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) pcb_t *pcb = current()->pcb; struct list_head *pos; futex_t *futex; - futex_el_t *f_element; + queue_thread_t f_element; flags = spin_lock_irqsave(&pcb->futex_lock); - if (*futex_w != val) + if (*futex_w != val) { + spin_unlock_irqrestore(&pcb->futex_lock, flags); return -EAGAIN; + } /* look if a futex_w already exists */ list_for_each(pos, &pcb->futex) { @@ -61,19 +63,17 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) list_add_tail(&futex->list, &pcb->futex); } - /* Add the thread in the futex_element list */ - f_element = (futex_el_t *) calloc(1, sizeof(futex_el_t)); - if (f_element == NULL) - BUG(); - - f_element->waiter = current(); + f_element.tcb = current(); - list_add_tail(&f_element->list, &futex->f_element); + list_add_tail(&f_element.list, &futex->f_element); /* go to sleep. */ spin_unlock(&pcb->futex_lock); waiting(); + if (list_empty(&futex->f_element)) + free(futex); + BUG_ON(local_irq_is_enabled()); spin_unlock_irqrestore(&pcb->futex_lock, flags); @@ -93,7 +93,7 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t nr_wake) pcb_t *pcb = current()->pcb; struct list_head *pos, *p; futex_t *futex; - futex_el_t *f_element; + queue_thread_t *f_element; unsigned idx = 0; flags = spin_lock_irqsave(&pcb->futex_lock); @@ -106,26 +106,28 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t nr_wake) break; } - if (pos == &pcb->futex) + if (pos == &pcb->futex) { /* key does not exists in futex - Error */ - BUG(); + spin_unlock_irqrestore(&pcb->futex_lock, flags); + return -EINVAL(); + } /* wakes at most nr_wake of the waiters that are waiting */ list_for_each_safe(pos, p, &futex->list) { - f_element = list_entry(pos, futex_el_t, list); + f_element = list_entry(pos, queue_thread_t, list); if (idx == nr_wake) break; list_del(&f_element->list); - ready(f_element->waiter); + ready(f_element->tcb); idx++; } spin_unlock_irqrestore(&pcb->futex_lock, flags); - return 0; + return idx; } SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, const struct timespec *, utime, uint32_t *, uaddr2, uint32_t, @@ -133,6 +135,9 @@ SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, const struct t { int cmd = op & FUTEX_CMD_MASK; + if (utime) + printk("[futex] utime parameter is not used in current implementation\n"); + switch (cmd) { case FUTEX_WAIT: return do_futex_wait(uaddr, val); @@ -152,12 +157,3 @@ SYSCALL_DEFINE6(futex, uint32_t *, uaddr, int, op, uint32_t, val, const struct t return -ENOSYS; } - -/** - * futex_init - Futex initialization - */ -void futex_init(pcb_t *pcb) -{ - INIT_LIST_HEAD(&pcb->futex); - spin_lock_init(&pcb->futex_lock); -} diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 41cf33917..e9ade4316 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -206,7 +206,8 @@ pcb_t *new_process(void) INIT_LIST_HEAD(&pcb->page_list); /* Init the futex */ - futex_init(pcb); + INIT_LIST_HEAD(&pcb->futex); + spin_lock_init(&pcb->futex_lock); pcb->pid = pid_current++; From 9c09570d1117098b4c572b5ae0ff5318b4d92748 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 10 Nov 2025 16:54:07 +0100 Subject: [PATCH 36/69] [musl] Fix build errors & warnings when building so3/usr Signed-off-by: Jean-Pierre Miceli --- usr/aarch64-linux-musl.cmake | 2 +- usr/lib/slv/slv.c | 2 +- usr/lib/slv/slv_fb.c | 1 + usr/src/lvgl_perf.c | 2 +- usr/src/ping.c | 6 +++--- usr/src/sh.c | 6 ++++-- usr/src/time.c | 2 +- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/usr/aarch64-linux-musl.cmake b/usr/aarch64-linux-musl.cmake index ea136c856..9f273b7e7 100644 --- a/usr/aarch64-linux-musl.cmake +++ b/usr/aarch64-linux-musl.cmake @@ -21,7 +21,7 @@ set(CMAKE_CXX_COMPILER "aarch64-linux-musl-g++") # set(CMAKE_C_LINK_EXECUTABLE "aarch64-linux-musl-ld -o ") set(CMAKE_ASM_COMPILER "aarch64-linux-musl-gcc") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D__ARM64__ -fno-common") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D_GNU_SOURCE -D__ARM64__ -fno-common") set(CMAKE_ASM_FLAGS "-D__ARM64__ -D__ASSEMBLY__") diff --git a/usr/lib/slv/slv.c b/usr/lib/slv/slv.c index 2f3a9fcc2..42a85b3cb 100644 --- a/usr/lib/slv/slv.c +++ b/usr/lib/slv/slv.c @@ -91,7 +91,7 @@ void slv_terminate(slv_t *slv) slv->terminate = true; pthread_join(slv->tick_thread, NULL); if (slv->has_loop_thread) { - pthread_join(slv->has_loop_thread, NULL); + pthread_join(slv->loop_thread, NULL); } lv_deinit(); diff --git a/usr/lib/slv/slv_fb.c b/usr/lib/slv/slv_fb.c index 06c6e79e8..58258502f 100644 --- a/usr/lib/slv/slv_fb.c +++ b/usr/lib/slv/slv_fb.c @@ -25,6 +25,7 @@ #include #include #include +#include #include diff --git a/usr/src/lvgl_perf.c b/usr/src/lvgl_perf.c index 026686c07..66b83cf9f 100644 --- a/usr/src/lvgl_perf.c +++ b/usr/src/lvgl_perf.c @@ -54,7 +54,7 @@ int main(int argc, char **argv) uint64_t delta = tv_end.tv_usec - tv_start.tv_usec; printf("Performance test result:\n\n"); - printf("# Elapsed time of lv_timer_handler() function: %lld microseconds.\n", delta); + printf("# Elapsed time of lv_timer_handler() function: %ld microseconds.\n", delta); printf("\n***************************************************************************\n"); slv_terminate(&slv); diff --git a/usr/src/ping.c b/usr/src/ping.c index 2d2b5e82f..350b31ecb 100644 --- a/usr/src/ping.c +++ b/usr/src/ping.c @@ -234,7 +234,7 @@ int main(int argc, char **argv) if (!(packet.hdr.type == 69 && packet.hdr.code == 0)) { printf("Error... Packet received with ICMP type %d code %d\n", packet.hdr.type, packet.hdr.code); } else { - printf("%d bytes from %s: icmp_seq=%d ttl=%d time=%Lf ms\n", PING_PKT_LEN, ip, msg_count, ttl, rtt); + printf("%d bytes from %s: icmp_seq=%d ttl=%d time=%f ms\n", PING_PKT_LEN, ip, msg_count, ttl, rtt); rtt_max = fmaxf(rtt_max, rtt); rtt_min = fminf(rtt_min, rtt); @@ -245,11 +245,11 @@ int main(int argc, char **argv) } printf("\n--- %s ping statistics ---\n", destination); - printf("%d packets transmitted, %d received, %d%% packet loss\n", msg_count, msg_count_succeed, + printf("%d packets transmitted, %d received, %f%% packet loss\n", msg_count, msg_count_succeed, (1.0 - msg_count_succeed / (float) msg_count) * 100); if (msg_count_succeed > 0) - printf("rtt min/avg/max = %Lf/%Lf/%Lf ms\n", rtt_min, rtt_total / msg_count_succeed, rtt_max); + printf("rtt min/avg/max = %f/%f/%f ms\n", rtt_min, rtt_total / msg_count_succeed, rtt_max); return 0; diff --git a/usr/src/sh.c b/usr/src/sh.c index cd5b1557d..d53b60f93 100644 --- a/usr/src/sh.c +++ b/usr/src/sh.c @@ -129,6 +129,7 @@ void process_cmd(void) int pipe_on = 0; int pipe_fd[2]; +#if 0 /* MICOFE - sys_info is not a valid syscall - code needs to be updated */ if (!strcmp(tokens[0], "dumpsched")) { sys_info(1, 0); return; @@ -138,6 +139,7 @@ void process_cmd(void) sys_info(4, 0); return; } +#endif if (!strcmp(tokens[0], "exit")) { if (getpid() == 1) { @@ -167,8 +169,8 @@ void process_cmd(void) /* env */ if (!strcmp(tokens[0], "env")) { /* This function print the environment vars */ - for (i = 0; __environ[i] != NULL; i++) - printf("%s\n", __environ[i]); + for (i = 0; environ[i] != NULL; i++) + printf("%s\n", environ[i]); return; } diff --git a/usr/src/time.c b/usr/src/time.c index f64e8550f..a45acbf40 100644 --- a/usr/src/time.c +++ b/usr/src/time.c @@ -16,6 +16,6 @@ int main(int argc, char *argv[]) time(&t); - printf("# time(s) : %llu time(us) : %llu\n", t, tv.tv_usec); + printf("# time(s) : %lu time(us) : %lu\n", t, tv.tv_usec); } } From 027d7b5259e9c8bfd3f7e33399b93b41ebb5e88f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 10 Nov 2025 16:57:21 +0100 Subject: [PATCH 37/69] [futex] Fix typo introduced in previous commit Signed-off-by: Jean-Pierre Miceli --- so3/kernel/futex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c index 346f4ec30..b2406ffc9 100644 --- a/so3/kernel/futex.c +++ b/so3/kernel/futex.c @@ -109,7 +109,7 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t nr_wake) if (pos == &pcb->futex) { /* key does not exists in futex - Error */ spin_unlock_irqrestore(&pcb->futex_lock, flags); - return -EINVAL(); + return -EINVAL; } /* wakes at most nr_wake of the waiters that are waiting */ From 8be034c63591a6561ece883c0c176fd2029a2817 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 11 Nov 2025 17:11:09 +0100 Subject: [PATCH 38/69] [futex] make clearer the search of key in lists Signed-off-by: Jean-Pierre Miceli --- so3/include/list.h | 10 ++++++++++ so3/kernel/futex.c | 11 +++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/so3/include/list.h b/so3/include/list.h index c6790da98..164a9ea20 100644 --- a/so3/include/list.h +++ b/so3/include/list.h @@ -169,6 +169,16 @@ static inline int list_is_last(const struct list_head *list, const struct list_h return list->next == head; } +/** + * list_is_head - tests whether @list is the list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_head(const struct list_head *list, const struct list_head *head) +{ + return list == head; +} + /** * list_empty - tests whether a list is empty * @head: the list to test. diff --git a/so3/kernel/futex.c b/so3/kernel/futex.c index b2406ffc9..0672ef76e 100644 --- a/so3/kernel/futex.c +++ b/so3/kernel/futex.c @@ -51,7 +51,7 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) break; } - if (pos == &pcb->futex) { + if (list_is_head(pos, &pcb->futex)) { /* no futex on futex_w */ futex = (futex_t *) calloc(1, sizeof(futex_t)); if (futex == NULL) @@ -71,11 +71,13 @@ static int do_futex_wait(uint32_t *futex_w, uint32_t val) spin_unlock(&pcb->futex_lock); waiting(); + BUG_ON(local_irq_is_enabled()); + + spin_lock(&pcb->futex_lock); + if (list_empty(&futex->f_element)) free(futex); - BUG_ON(local_irq_is_enabled()); - spin_unlock_irqrestore(&pcb->futex_lock, flags); return 0; @@ -106,7 +108,8 @@ static int do_futex_wake(uint32_t *futex_w, uint32_t nr_wake) break; } - if (pos == &pcb->futex) { + /* Check if the wanted key was found in the list */ + if (list_is_head(pos, &pcb->futex)) { /* key does not exists in futex - Error */ spin_unlock_irqrestore(&pcb->futex_lock, flags); return -EINVAL; From 47d95c7411437abac63cecd2cd3a504c1c6cdcc4 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 17 Nov 2025 11:06:58 +0100 Subject: [PATCH 39/69] [usr] arm32 - complile usr with MUSL lib Signed-off-by: Jean-Pierre Miceli --- usr/CMakeLists.txt | 3 +-- usr/aarch64-linux-musl.cmake | 3 +-- usr/arm-linux-musl.cmake | 30 ++++++++++++++++++++++++++++++ usr/build.sh | 2 +- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 usr/arm-linux-musl.cmake diff --git a/usr/CMakeLists.txt b/usr/CMakeLists.txt index 5fedd4609..c0bf2d1a5 100644 --- a/usr/CMakeLists.txt +++ b/usr/CMakeLists.txt @@ -40,8 +40,7 @@ execute_process( if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l") -add_link_options(-T ${CMAKE_SOURCE_DIR}/lib/libc/arm.lds -N -warn-common - -warn-constructors -warn-multiple-gp -L ${libgcc_path} -lgcc +add_link_options(-N -Wl,--warn-common ) elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") diff --git a/usr/aarch64-linux-musl.cmake b/usr/aarch64-linux-musl.cmake index 9f273b7e7..9589fe32d 100644 --- a/usr/aarch64-linux-musl.cmake +++ b/usr/aarch64-linux-musl.cmake @@ -18,7 +18,6 @@ set(CMAKE_INSTALL_SO_NO_EXE 0) set(CMAKE_C_COMPILER "aarch64-linux-musl-gcc") set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) set(CMAKE_CXX_COMPILER "aarch64-linux-musl-g++") -# set(CMAKE_C_LINK_EXECUTABLE "aarch64-linux-musl-ld -o ") set(CMAKE_ASM_COMPILER "aarch64-linux-musl-gcc") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D_GNU_SOURCE -D__ARM64__ -fno-common") @@ -27,4 +26,4 @@ set(CMAKE_ASM_FLAGS "-D__ARM64__ -D__ASSEMBLY__") #set(CMAKE_LINKER "aarch64-none-elf-ld") -set(CMAKE_EXE_LINKER_FLAGS "-Os -static" CACHE STRING "SO3 usr LDFLAGS for executables") \ No newline at end of file +set(CMAKE_EXE_LINKER_FLAGS "-Os -static" CACHE STRING "SO3 usr LDFLAGS for executables") diff --git a/usr/arm-linux-musl.cmake b/usr/arm-linux-musl.cmake new file mode 100644 index 000000000..4d38558df --- /dev/null +++ b/usr/arm-linux-musl.cmake @@ -0,0 +1,30 @@ +# +# CMake toolchain information for SO3 build +# Inspired from buildroot generated toolchain.cmake +# +# Target musl libc + +set(CMAKE_SYSTEM_NAME SO3_usr) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR armv7l) + +set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS") +set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release CFLAGS") + +set(CMAKE_BUILD_TYPE Release CACHE STRING "SO3 user applications build system") + +set(CMAKE_INSTALL_SO_NO_EXE 0) + +set(CMAKE_C_COMPILER "arm-linux-musleabihf-gcc") +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +set(CMAKE_CXX_COMPILER "arm-linux-musleabihf-g++") +set(CMAKE_ASM_COMPILER "arm-linux-musleabihf-gcc") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D_GNU_SOURCE -D__ARM__ -marm -mno-thumb-interwork -ffreestanding -fno-common") + +set(CMAKE_ASM_FLAGS "-D__ARM__ -D__ASSEMBLY__") + +set(CMAKE_LINKER "arm-linux-musleabihf-ld") + + +set(CMAKE_EXE_LINKER_FLAGS "-Os -static" CACHE STRING "SO3 usr LDFLAGS for executables") diff --git a/usr/build.sh b/usr/build.sh index 61e645813..747697471 100755 --- a/usr/build.sh +++ b/usr/build.sh @@ -85,7 +85,7 @@ mkdir -p $SCRIPTPATH/build cd $SCRIPTPATH/build if [ "$PLATFORM" = "virt32" -o "$PLATFORM" = "vexpress" -o "$PLATFORM" = "rpi4" ]; then - default_toolchain="arm_toolchain.cmake" + default_toolchain="arm-linux-musl.cmake" elif [ "$PLATFORM" = "virt64" -o "$PLATFORM" = "rpi4_64" ]; then default_toolchain="aarch64-linux-musl.cmake" elif [ -z "$USR_BUILD_TOOLCHAIN_FILE" ]; then From 4326e00ae0ef573c7b2b4ff9d68de8a62005381b Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Mon, 10 Nov 2025 13:22:07 +0100 Subject: [PATCH 40/69] remove ptrace support --- so3/arch/arm32/Makefile | 2 +- so3/arch/arm32/context.S | 1 - so3/arch/arm32/exception.S | 16 --- so3/arch/arm32/ptrace.c | 123 --------------------- so3/arch/arm64/Makefile | 6 +- so3/arch/arm64/context.S | 2 - so3/arch/arm64/exception.S | 12 -- so3/arch/arm64/ptrace.c | 50 --------- so3/avz/kernel/injector.c | 1 - so3/include/process.h | 9 -- so3/include/ptrace.h | 221 ------------------------------------- so3/kernel/Makefile | 4 +- so3/kernel/process.c | 74 +++---------- so3/kernel/ptrace.c | 111 ------------------- so3/kernel/thread.c | 44 ++++---- so3/syscall.tbl | 1 - 16 files changed, 39 insertions(+), 638 deletions(-) delete mode 100644 so3/arch/arm32/ptrace.c delete mode 100644 so3/arch/arm64/ptrace.c delete mode 100644 so3/include/ptrace.h delete mode 100644 so3/kernel/ptrace.c diff --git a/so3/arch/arm32/Makefile b/so3/arch/arm32/Makefile index 37b6356f6..a8d2bdbfe 100644 --- a/so3/arch/arm32/Makefile +++ b/so3/arch/arm32/Makefile @@ -2,7 +2,7 @@ obj-y += head.o obj-y += setup.o exception.o context.o fault.o obj-y += cache_v7_asm.o cache_v7.o cache-cp15.o -obj-y += thread.o ptrace.o +obj-y += thread.o obj-y += vfp.o obj-y += backtrace.o backtrace_asm.o obj-y += smccc-call.o diff --git a/so3/arch/arm32/context.S b/so3/arch/arm32/context.S index 0234098bd..d49488436 100644 --- a/so3/arch/arm32/context.S +++ b/so3/arch/arm32/context.S @@ -47,7 +47,6 @@ #ifdef CONFIG_MMU -.extern __check_ptrace_traceme .extern pre_launch_proc #endif diff --git a/so3/arch/arm32/exception.S b/so3/arch/arm32/exception.S index 0c44feced..37feef58a 100644 --- a/so3/arch/arm32/exception.S +++ b/so3/arch/arm32/exception.S @@ -47,7 +47,6 @@ .extern __data_abort .extern __undefined_instruction -.extern __check_ptrace_syscall .extern sig_check .extern __stack_alignment_fault @@ -221,13 +220,6 @@ __after_push_sp_usr: @ Restore r0-r2 ldmia sp, {r0-r2} -#ifdef CONFIG_MMU - @ Give a chance to a ptrace tracer to monitor us (before the syscall) - stmfd sp!, {r0-r4} - bl __check_ptrace_syscall - ldmfd sp!, {r0-r4} -#endif - mov r0, sp cpsie i @ Re-enable interrupts @@ -243,14 +235,6 @@ __after_push_sp_usr: add sp, sp, #SVC_STACK_FRAME_SIZE __no_sigreturn: - -#ifdef CONFIG_MMU - @ Give a chance to a ptrace tracer to monitor us (after the syscall) - stmfd sp!, {r0-r4} - bl __check_ptrace_syscall - ldmfd sp!, {r0-r4} -#endif - __ret_from_fork: @ Store the return value on the stack frame diff --git a/so3/arch/arm32/ptrace.c b/so3/arch/arm32/ptrace.c deleted file mode 100644 index b9a32d743..000000000 --- a/so3/arch/arm32/ptrace.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2014-2022 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include - -/* - * Can be used for debugging purposes. - * - */ -void __dump_regs(void *regs) -{ - unsigned long *cpuregs = (unsigned long *) regs; - - printk("r4: %x ", *cpuregs); - printk("r5: %x ", *(cpuregs + 1)); - printk("r6: %x ", *(cpuregs + 2)); - printk("r7: %x ", *(cpuregs + 3)); - printk("r8: %x ", *(cpuregs + 4)); - printk("r9: %x ", *(cpuregs + 5)); - printk("r10: %x ", *(cpuregs + 6)); - printk("fp: %x ", *(cpuregs + 7)); - printk("ip: %x ", *(cpuregs + 8)); - printk("sp: %x ", *(cpuregs + 9)); - printk("lr: %x ", *(cpuregs + 10)); - printk("pc: %x ", *(cpuregs + 11)); - printk("psr: %x ", *(cpuregs + 12)); - printk("\n"); -} - -/** - * Update the CPU registers of the TCB belonging - * to the current thread. - */ -void update_cpu_regs(void) -{ - register uint32_t __r0 asm("r0"); - register uint32_t __r1 asm("r1"); - register uint32_t __r2 asm("r2"); - register uint32_t __r3 asm("r3"); - register uint32_t __r4 asm("r4"); - register uint32_t __r5 asm("r5"); - register uint32_t __r6 asm("r6"); - register uint32_t __r7 asm("r7"); - register uint32_t __r8 asm("r8"); - register uint32_t __r9 asm("r9"); - register uint32_t __r10 asm("r10"); - register uint32_t __r11 asm("r11"); - register uint32_t __r12 asm("r12"); - register uint32_t __r13 asm("r13"); - register uint32_t __r14 asm("r14"); - - /* Keep the values permanent */ - uint32_t r0 = __r0; - uint32_t r1 = __r1; - uint32_t r2 = __r2; - uint32_t r3 = __r3; - uint32_t r4 = __r4; - uint32_t r5 = __r5; - uint32_t r6 = __r6; - uint32_t r7 = __r7; - uint32_t r8 = __r8; - uint32_t r9 = __r9; - uint32_t r10 = __r10; - uint32_t r11 = __r11; - uint32_t r12 = __r12; - uint32_t r13 = __r13; - uint32_t r14 = __r14; - - /* Finally update the tcb structure */ - tcb_t *tcb = current(); - - tcb->cpu_regs.r0 = r0; - tcb->cpu_regs.r1 = r1; - tcb->cpu_regs.r2 = r2; - tcb->cpu_regs.r3 = r3; - tcb->cpu_regs.r4 = r4; - tcb->cpu_regs.r5 = r5; - tcb->cpu_regs.r6 = r6; - tcb->cpu_regs.r7 = r7; - tcb->cpu_regs.r8 = r8; - tcb->cpu_regs.r9 = r9; - tcb->cpu_regs.r10 = r10; - tcb->cpu_regs.fp = r11; - tcb->cpu_regs.ip = r12; - tcb->cpu_regs.sp = r13; - tcb->cpu_regs.lr = r14; -} - -void retrieve_cpu_regs(struct user *uregs, pcb_t *pcb) -{ - uregs->regs.uregs[0] = pcb->main_thread->cpu_regs.r0; - uregs->regs.uregs[1] = pcb->main_thread->cpu_regs.r1; - uregs->regs.uregs[2] = pcb->main_thread->cpu_regs.r2; - uregs->regs.uregs[3] = pcb->main_thread->cpu_regs.r3; - uregs->regs.uregs[4] = pcb->main_thread->cpu_regs.r4; - uregs->regs.uregs[5] = pcb->main_thread->cpu_regs.r5; - uregs->regs.uregs[6] = pcb->main_thread->cpu_regs.r6; - uregs->regs.uregs[7] = pcb->main_thread->cpu_regs.r7; - uregs->regs.uregs[8] = pcb->main_thread->cpu_regs.r8; - uregs->regs.uregs[9] = pcb->main_thread->cpu_regs.r9; - uregs->regs.uregs[10] = pcb->main_thread->cpu_regs.r10; - uregs->regs.uregs[11] = pcb->main_thread->cpu_regs.fp; - uregs->regs.uregs[12] = pcb->main_thread->cpu_regs.ip; - uregs->regs.uregs[13] = pcb->main_thread->cpu_regs.sp; - uregs->regs.uregs[14] = pcb->main_thread->cpu_regs.lr; -} diff --git a/so3/arch/arm64/Makefile b/so3/arch/arm64/Makefile index e7159d159..ad63cc0cd 100644 --- a/so3/arch/arm64/Makefile +++ b/so3/arch/arm64/Makefile @@ -5,7 +5,7 @@ endif obj-y += head.o exception.o traps.o -obj-y += fault.o backtrace.o +obj-y += fault.o backtrace.o obj-y += backtrace.o backtrace_asm.o obj-y += cache_v8.o cache.o context.o obj-y += semihosting.o semicall.o @@ -14,7 +14,7 @@ obj-$(CONFIG_AVZ) += domain.o mmio.o obj-y += smccc-call.o -obj-y += thread.o ptrace.o +obj-y += thread.o obj-$(CONFIG_MMU) += mmu.o @@ -23,4 +23,4 @@ obj-$(CONFIG_ARM64VT) += #smmu.o obj-y += lib/ obj-y += $(TARGET)/ - + diff --git a/so3/arch/arm64/context.S b/so3/arch/arm64/context.S index 30e6d8850..05f34506c 100644 --- a/so3/arch/arm64/context.S +++ b/so3/arch/arm64/context.S @@ -43,8 +43,6 @@ .global __enable_vfp -.extern __check_ptrace_traceme - #ifdef CONFIG_AVZ // Switch from a domain to another diff --git a/so3/arch/arm64/exception.S b/so3/arch/arm64/exception.S index a1d6a0c58..b47e9f8e4 100644 --- a/so3/arch/arm64/exception.S +++ b/so3/arch/arm64/exception.S @@ -42,7 +42,6 @@ .extern current_thread .extern __sync_serror .extern do_exit -.extern __check_ptrace_syscall .extern sig_check .global __vectors @@ -610,17 +609,6 @@ ret_from_fork: str xzr, [sp, #OFFSET_X0] b __ret_from_fork - -#if 0 -#ifdef CONFIG_MMU - // Give a chance to a ptrace tracer to monitor us (after the syscall) - stmfd sp!, {r0-r4} - bl __check_ptrace_syscall - ldmfd sp!, {r0-r4} -#endif -#endif - - #if !defined(CONFIG_AVZ) && defined(CONFIG_SOO) .align 5 diff --git a/so3/arch/arm64/ptrace.c b/so3/arch/arm64/ptrace.c deleted file mode 100644 index d513b000a..000000000 --- a/so3/arch/arm64/ptrace.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2014-2022 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include - -/* - * Can be used for debugging purposes. - * - */ -void __dump_regs(void *regs) -{ - unsigned long *cpuregs = (unsigned long *) regs; - int i; - - printk("---------- CPU regs ----------\n"); - - for (i = 0; i <= 30; i++) - printk("x%d = %x\n", i, *(cpuregs + i)); - - printk("\n"); -} - -/** - * Update the CPU registers of the TCB belonging - * to the current thread. - */ -void update_cpu_regs(void) -{ -} - -void retrieve_cpu_regs(struct user *uregs, pcb_t *pcb) -{ -} diff --git a/so3/avz/kernel/injector.c b/so3/avz/kernel/injector.c index 7693b8135..ffd5207b6 100644 --- a/so3/avz/kernel/injector.c +++ b/so3/avz/kernel/injector.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/so3/include/process.h b/so3/include/process.h index ec94efe26..7c845a234 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -81,11 +80,6 @@ typedef struct { page_t *page; } page_list_t; -typedef struct { - bool tracee; - enum __ptrace_request req_in_progress; -} ptrace_info_t; - struct pcb { int pid; char name[PROC_NAME_LEN]; @@ -150,9 +144,6 @@ struct pcb { /* Bitmap of the signals set for this process */ sigset_t sigset_map; - /* The process might be under a ptrace activity, and hence becoming a tracer (parent) or tracee (child) */ - enum __ptrace_request ptrace_pending_req; - /* Mutex lock to be used in conjunction with the user space (very temporary) */ mutex_t *lock; }; diff --git a/so3/include/ptrace.h b/so3/include/ptrace.h deleted file mode 100644 index b77dfa09d..000000000 --- a/so3/include/ptrace.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2014-2019 Daniel Rossier - * Copyright (C) 2017-2018 Xavier Ruppen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef _SYS_PTRACE_H -#define _SYS_PTRACE_H - -#include -#include - -/* Type of the REQUEST argument to `ptrace.' */ -enum __ptrace_request { - /* Indicate that the process making this request should be traced. - All signals received by this process can be intercepted by its - parent, and its parent can use the other `ptrace' requests. */ - PTRACE_TRACEME = 0, -#define PT_TRACE_ME PTRACE_TRACEME - - /* Return the word in the process's text space at address ADDR. */ - PTRACE_PEEKTEXT = 1, -#define PT_READ_I PTRACE_PEEKTEXT - - /* Return the word in the process's data space at address ADDR. */ - PTRACE_PEEKDATA = 2, -#define PT_READ_D PTRACE_PEEKDATA - - /* Return the word in the process's user area at offset ADDR. */ - PTRACE_PEEKUSER = 3, -#define PT_READ_U PTRACE_PEEKUSER - - /* Write the word DATA into the process's text space at address ADDR. */ - PTRACE_POKETEXT = 4, -#define PT_WRITE_I PTRACE_POKETEXT - - /* Write the word DATA into the process's data space at address ADDR. */ - PTRACE_POKEDATA = 5, -#define PT_WRITE_D PTRACE_POKEDATA - - /* Write the word DATA into the process's user area at offset ADDR. */ - PTRACE_POKEUSER = 6, -#define PT_WRITE_U PTRACE_POKEUSER - - /* Continue the process. */ - PTRACE_CONT = 7, -#define PT_CONTINUE PTRACE_CONT - - /* Kill the process. */ - PTRACE_KILL = 8, -#define PT_KILL PTRACE_KILL - - /* Single step the process. */ - PTRACE_SINGLESTEP = 9, -#define PT_STEP PTRACE_SINGLESTEP - - /* Get all general purpose registers used by a processes. */ - PTRACE_GETREGS = 12, -#define PT_GETREGS PTRACE_GETREGS - - /* Set all general purpose registers used by a processes. */ - PTRACE_SETREGS = 13, -#define PT_SETREGS PTRACE_SETREGS - - /* Get all floating point registers used by a processes. */ - PTRACE_GETFPREGS = 14, -#define PT_GETFPREGS PTRACE_GETFPREGS - - /* Set all floating point registers used by a processes. */ - PTRACE_SETFPREGS = 15, -#define PT_SETFPREGS PTRACE_SETFPREGS - - /* Attach to a process that is already running. */ - PTRACE_ATTACH = 16, -#define PT_ATTACH PTRACE_ATTACH - - /* Detach from a process attached to with PTRACE_ATTACH. */ - PTRACE_DETACH = 17, -#define PT_DETACH PTRACE_DETACH - - /* Get all extended floating point registers used by a processes. */ - PTRACE_GETFPXREGS = 18, -#define PT_GETFPXREGS PTRACE_GETFPXREGS - - /* Set all extended floating point registers used by a processes. */ - PTRACE_SETFPXREGS = 19, -#define PT_SETFPXREGS PTRACE_SETFPXREGS - - /* Continue and stop at the next entry to or return from syscall. */ - PTRACE_SYSCALL = 24, -#define PT_SYSCALL PTRACE_SYSCALL - - /* Get a TLS entry in the GDT. */ - PTRACE_GET_THREAD_AREA = 25, -#define PT_GET_THREAD_AREA PTRACE_GET_THREAD_AREA - - /* Change a TLS entry in the GDT. */ - PTRACE_SET_THREAD_AREA = 26, -#define PT_SET_THREAD_AREA PTRACE_SET_THREAD_AREA - - /* Continue and stop at the next syscall, it will not be executed. */ - PTRACE_SYSEMU = 31, -#define PT_SYSEMU PTRACE_SYSEMU - - /* Single step the process, the next syscall will not be executed. */ - PTRACE_SYSEMU_SINGLESTEP = 32, -#define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP - - /* Execute process until next taken branch. */ - PTRACE_SINGLEBLOCK = 33, -#define PT_STEPBLOCK PTRACE_SINGLEBLOCK - - /* Set ptrace filter options. */ - PTRACE_SETOPTIONS = 0x4200, -#define PT_SETOPTIONS PTRACE_SETOPTIONS - - /* Get last ptrace message. */ - PTRACE_GETEVENTMSG = 0x4201, -#define PT_GETEVENTMSG PTRACE_GETEVENTMSG - - /* Get siginfo for process. */ - PTRACE_GETSIGINFO = 0x4202, -#define PT_GETSIGINFO PTRACE_GETSIGINFO - - /* Set new siginfo for process. */ - PTRACE_SETSIGINFO = 0x4203, -#define PT_SETSIGINFO PTRACE_SETSIGINFO - - /* Get register content. */ - PTRACE_GETREGSET = 0x4204, -#define PTRACE_GETREGSET PTRACE_GETREGSET - - /* Set register content. */ - PTRACE_SETREGSET = 0x4205, -#define PTRACE_SETREGSET PTRACE_SETREGSET - - /* Like PTRACE_ATTACH, but do not force tracee to trap and do not affect - signal or group stop state. */ - PTRACE_SEIZE = 0x4206, -#define PTRACE_SEIZE PTRACE_SEIZE - - /* Trap seized tracee. */ - PTRACE_INTERRUPT = 0x4207, -#define PTRACE_INTERRUPT PTRACE_INTERRUPT - - /* Wait for next group event. */ - PTRACE_LISTEN = 0x4208, -#define PTRACE_LISTEN PTRACE_LISTEN - - /* Retrieve siginfo_t structures without removing signals from a queue. */ - PTRACE_PEEKSIGINFO = 0x4209, -#define PTRACE_PEEKSIGINFO PTRACE_PEEKSIGINFO - - /* Get the mask of blocked signals. */ - PTRACE_GETSIGMASK = 0x420a, -#define PTRACE_GETSIGMASK PTRACE_GETSIGMASK - - /* Change the mask of blocked signals. */ - PTRACE_SETSIGMASK = 0x420b, -#define PTRACE_SETSIGMASK PTRACE_SETSIGMASK - - /* Get seccomp BPF filters. */ - PTRACE_SECCOMP_GET_FILTER = 0x420c, -#define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER - - /* Specific to SO3 to indicate that no ptrace request is pending. */ - PTRACE_NO_REQUEST = 0xffff -}; - -#define PTRACE_O_TRACESYSGOOD 0x00000001 -#define PTRACE_O_TRACEFORK 0x00000002 -#define PTRACE_O_TRACEVFORK 0x00000004 -#define PTRACE_O_TRACECLONE 0x00000008 -#define PTRACE_O_TRACEEXEC 0x00000010 -#define PTRACE_O_TRACEVFORKDONE 0x00000020 -#define PTRACE_O_TRACEEXIT 0x00000040 -#define PTRACE_O_TRACESECCOMP 0x00000080 -#define PTRACE_O_EXITKILL 0x00100000 -#define PTRACE_O_SUSPEND_SECCOMP 0x00200000 -#define PTRACE_O_MASK 0x003000ff - -#define PTRACE_EVENT_FORK 1 -#define PTRACE_EVENT_VFORK 2 -#define PTRACE_EVENT_CLONE 3 -#define PTRACE_EVENT_EXEC 4 -#define PTRACE_EVENT_VFORK_DONE 5 -#define PTRACE_EVENT_EXIT 6 -#define PTRACE_EVENT_SECCOMP 7 - -#define PTRACE_PEEKSIGINFO_SHARED 1 - -struct ptrace_peeksiginfo_args { - uint64_t off; - uint32_t flags; - int32_t nr; -}; - -SYSCALL_DECLARE(ptrace, enum __ptrace_request request, int pid, void *addr, void *data); - -struct pcb; -struct user; - -void update_cpu_regs(void); -void retrieve_cpu_regs(struct user *uregs, struct pcb *pcb); - -void __dump_regs(void *regs); - -#endif diff --git a/so3/kernel/Makefile b/so3/kernel/Makefile index 71f68a103..fee71be7c 100644 --- a/so3/kernel/Makefile +++ b/so3/kernel/Makefile @@ -12,7 +12,7 @@ obj-y += main.o \ spinlock.o \ syscalls.o \ softirq.o \ - timer.o + timer.o obj-$(CONFIG_CPU_PSCI) += psci_smp.o obj-$(CONFIG_CPU_SPIN_TABLE) += spin_table.o @@ -23,7 +23,7 @@ obj-y += bitmap.o obj-y += softirq.o obj-y += spinlock.o -obj-$(CONFIG_MMU) += process.o ptrace.o +obj-$(CONFIG_MMU) += process.o EXTRA_CFLAGS += -I$(srctree)/include/net diff --git a/so3/kernel/process.c b/so3/kernel/process.c index b1d2706d9..0caa26cf0 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -184,9 +183,6 @@ pcb_t *new_process(void) pcb->next_anon_start = USER_ANONYMOUS_VADDR; - /* Reset the ptrace request indicator */ - pcb->ptrace_pending_req = PTRACE_NO_REQUEST; - /* The spinlock inside the mutex must aligned in aarch64 */ pcb->lock = memalign(N_MUTEX * sizeof(mutex_t), 8); @@ -1022,69 +1018,27 @@ SYSCALL_DEFINE4(wait4, int, pid, uint32_t *, wstatus, uint32_t, options, void *, if (child->state != PROC_STATE_ZOMBIE) return 0; - /* Must the child be resumed after being stopped due to a ptrace request - * ? */ - if ((child->ptrace_pending_req != PTRACE_NO_REQUEST) && (child->ptrace_pending_req != PTRACE_TRACEME)) { - /* Resume the child process being stopped previously. */ - - child->state = PROC_STATE_READY; - ready(child->main_thread); - } - if (child->state != PROC_STATE_WAITING) /* Wait on the main_thread of this process */ thread_join(child->main_thread); - /* Before joining, we need to check the state of child because it could - * have been finished before this call. */ - if ((child->state == PROC_STATE_ZOMBIE) && (child->ptrace_pending_req == PTRACE_NO_REQUEST)) { - /* Free the page tables used for this process */ - reset_root_pgtable(child->pgtable, true); - - /* Get the exit code left in the PCB by the child */ - if (wstatus) { - *wstatus = ~0x7f; /* !WTERMSIG -> WIFEXITED true */ - *wstatus = ((char) child->exit_status) << 8; - } - - /* - * SO3 approach consists in avoiding having orphan process. - * The process will be removed from the system definitively only - * if it has no children. - */ - if (!find_proc_by_parent(child)) - remove_proc(child); - - } else { - if (child->ptrace_pending_req != PTRACE_NO_REQUEST) { - /* In this case, the child has been stopped in the - * context of the ptrace syscall */ - - /* Reset the ptrace request */ - child->ptrace_pending_req = PTRACE_NO_REQUEST; - - if (wstatus) { - *wstatus = 0x17f; /* WIFSTOPPED true */ - *wstatus |= ((char) child->exit_status) << 8; - } - } else { - /* Free the page tables used for this process */ - reset_root_pgtable(child->pgtable, true); + /* Free the page tables used for this process */ + reset_root_pgtable(child->pgtable, true); - /* Get the exit code left in the PCB by the child */ - if (wstatus) { - *wstatus = ~0x7f; /* !WTERMSIG -> WIFEXITED true */ - *wstatus |= ((char) child->exit_status) << 8; - } - - /* Finally remove the process from the system - * definitively as long as there is no children from - * there */ - if (!find_proc_by_parent(child)) - remove_proc(child); - } + /* Get the exit code left in the PCB by the child */ + if (wstatus) { + *wstatus = ~0x7f; /* !WTERMSIG -> WIFEXITED true */ + *wstatus |= ((char) child->exit_status) << 8; } + /* + * SO3 approach consists in avoiding having orphan process. + * The process will be removed from the system definitively only + * if it has no children. + */ + if (!find_proc_by_parent(child)) + remove_proc(child); + local_irq_restore(flags); return pid; diff --git a/so3/kernel/ptrace.c b/so3/kernel/ptrace.c deleted file mode 100644 index 3a30ef729..000000000 --- a/so3/kernel/ptrace.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2014-2019 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include -#include - -/* - * Stop the execution of the process, i.e. its main_thread and all other threads - * (used by a ptrace activity for example). - */ -void ptrace_process_stop(void) -{ - /* Wake up the tracer... */ - /* It may be the case that the parent did not have time to wait for us and is still in ready */ - if (current()->pcb->parent->main_thread->state != THREAD_STATE_READY) - ready(current()->pcb->parent->main_thread); - - /* The process is in waiting state */ - /* ... and wait on the tracer */ - - current()->pcb->state = PROC_STATE_WAITING; /* No further threads of this process may be running */ - - waiting(); -} - -void __check_ptrace_traceme(void) -{ - tcb_t *tcb = current(); - - /* Check if the process is a tracee and if this thread is the main thread, - * therefore we need to be stopped until the tracer executes waitpid() - */ - - if ((tcb->pcb != NULL) && (tcb == tcb->pcb->main_thread) && (tcb->pcb->ptrace_pending_req == PTRACE_TRACEME)) - ptrace_process_stop(); -} - -void __check_ptrace_syscall(void) -{ - /* Update the CPU regs of the TCB belonging to the current thread */ - update_cpu_regs(); - - if (current()->pcb->ptrace_pending_req == PTRACE_SYSCALL) - ptrace_process_stop(); -} - -/* - * Implementation of ptrace syscall - */ -SYSCALL_DEFINE4(ptrace, enum __ptrace_request, request, int, pid, void *, addr, void *, data) -{ - pcb_t *pcb; - - switch (request) { - case PTRACE_TRACEME: - /* pid not used here */ - current()->pcb->ptrace_pending_req = request; - break; - - case PTRACE_SYSCALL: - pcb = find_proc_by_pid(pid); - - /* To set a ptrace request within a child, it must be first waiting, being stopped some where - * by a previous ptrace request (the initial is typically PTRACE_TRACEME). - * Otherwise, the request is ignored. - */ - if (!pcb) { - return -ESRCH; - } - - if (pcb->state == PROC_STATE_WAITING) - pcb->ptrace_pending_req = request; - break; - - case PTRACE_GETREGS: - if (!data) { - return -EFAULT; - } - - pcb = find_proc_by_pid(pid); - - if (!pcb) { - return -ESRCH; - } - - retrieve_cpu_regs((struct user *) data, pcb); - break; - - default: - printk("%s: request %d not yet implemented\n.", __func__, request); - } - - return 0; -} diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 86efae402..07f84fbc3 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -544,34 +544,28 @@ int thread_join(tcb_t *tcb) } } - /* Check if the child is a tracee (and therefore we have a tracer on it) */ - if ((tcb != NULL) && (tcb->pcb->ptrace_pending_req != PTRACE_NO_REQUEST)) { - exit_status = 0; + /* The joined thread *must* be in zombie */ + ASSERT(tcb->state == THREAD_STATE_ZOMBIE); - } else { - /* The joined thread *must* be in zombie */ - ASSERT(tcb->state == THREAD_STATE_ZOMBIE); - - if (is_main_thread) - exit_status = tcb->pcb->exit_status; - else - exit_status = tcb->exit_status; + if (is_main_thread) + exit_status = tcb->pcb->exit_status; + else + exit_status = tcb->exit_status; - /* - * Now, if we are the last which is woken up, we can proceed with the tcb removal. - * If the join is done on a main_thread, it means the waiting parent is doing the join, and - * we can then clean the tcb (remember that the main_thread does not appear in the list - * of threads of the PCB; only created threads are in it. - */ + /* + * Now, if we are the last which is woken up, we can proceed with the tcb removal. + * If the join is done on a main_thread, it means the waiting parent is doing the join, and + * we can then clean the tcb (remember that the main_thread does not appear in the list + * of threads of the PCB; only created threads are in it. + */ - if (list_empty(&tcb->joinQueue)) { - if (is_main_thread) { - clean_thread(tcb); - tcb->pcb->main_thread = NULL; - } else - /* Remove the tcb from the list of threads owned by this process */ - remove_tcb_from_pcb(tcb); - } + if (list_empty(&tcb->joinQueue)) { + if (is_main_thread) { + clean_thread(tcb); + tcb->pcb->main_thread = NULL; + } else + /* Remove the tcb from the list of threads owned by this process */ + remove_tcb_from_pcb(tcb); } local_irq_restore(flags); diff --git a/so3/syscall.tbl b/so3/syscall.tbl index 97c9611bd..996b9ab1c 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -51,7 +51,6 @@ clone MMU exit MMU exit_group MMU wait4 MMU -ptrace MMU gettimeofday MMU gettimeofday_time32 MMU clock_gettime MMU From e3ca710df033ecae8131285c088109d854cd8778 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 5 Nov 2025 12:55:44 +0100 Subject: [PATCH 41/69] implement child tid behavior --- so3/include/thread.h | 3 ++- so3/kernel/thread.c | 19 ++++++++++++++++--- so3/syscall.tbl | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/so3/include/thread.h b/so3/include/thread.h index 7c53b09d4..8d1625eb3 100644 --- a/so3/include/thread.h +++ b/so3/include/thread.h @@ -80,7 +80,7 @@ struct tcb { pcb_t *pcb; int exit_status; - addr_t child_clear_tid; + int *clear_child_tid; struct list_head list; /* List of threads belonging to a process */ @@ -119,6 +119,7 @@ typedef struct { void threads_init(void); SYSCALL_DECLARE(exit, int exit_status); +SYSCALL_DECLARE(set_tid_address, int *tidptr); tcb_t *kernel_thread(th_fn_t start_routine, const char *name, void *arg, uint32_t prio); tcb_t *user_thread(clone_args_t *args); diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 86efae402..c5b27a19a 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -266,12 +266,19 @@ void thread_exit(int exit_status) complete(&pcb->threads_active); } + /* If clear child tid is set, inform waiting thread */ + if (pcb && current() != pcb->main_thread) { + if (current()->clear_child_tid) { + *(current()->clear_child_tid) = 0; + do_futex(current()->clear_child_tid, FUTEX_WAKE, 1, NULL, NULL, 0, 0); + } + } + /* Check if this is a kernel thread OR a main thread before a image replacement (during exec()). * In this case, we do not leave the thread in zombie since we assume that no other threads are joining on it. * (This is currently a limitation: kernel threads can not join other threads). */ #warning Kernel threads cannot join other threads! -#warning TODO: check for clear_child_tid usage if (current()->pcb != NULL) zombie(); @@ -359,7 +366,7 @@ tcb_t *thread_create(clone_args_t *args) flags = local_irq_save(); - tcb = (tcb_t *) malloc(sizeof(tcb_t)); + tcb = (tcb_t *) calloc(1, sizeof(tcb_t)); if (tcb == NULL) { printk("%s: failed to alloc memory.\n", __func__); @@ -405,7 +412,7 @@ tcb_t *thread_create(clone_args_t *args) } if (args->flags & CLONE_CHILD_CLEARTID) - tcb->child_clear_tid = (addr_t) args->child_tid; + tcb->clear_child_tid = args->child_tid; local_irq_restore(flags); @@ -589,6 +596,12 @@ SYSCALL_DEFINE1(exit, int, exit_status) return 0; } +SYSCALL_DEFINE1(set_tid_address, int *, tidptr) +{ + current()->clear_child_tid = tidptr; + return current()->tid; +} + void threads_init(void) { int i; diff --git a/so3/syscall.tbl b/so3/syscall.tbl index 97c9611bd..adc0dcc31 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -48,6 +48,7 @@ getpid MMU execve MMU fork MMU clone MMU +set_tid_address MMU exit MMU exit_group MMU wait4 MMU From c37164c8d395a453f93afaa15c8c1a2efa75a234 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Mon, 17 Nov 2025 17:10:59 +0100 Subject: [PATCH 42/69] [musl] Add script to generate arm & aarch64 MUSL toolchain Signed-off-by: Jean-Pierre Miceli --- toolchains/build-toolchain.sh | 64 +++++++++++++++++++++++++ toolchains/config.mak.aarch64 | 88 +++++++++++++++++++++++++++++++++++ toolchains/config.mak.arm | 88 +++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+) create mode 100755 toolchains/build-toolchain.sh create mode 100644 toolchains/config.mak.aarch64 create mode 100644 toolchains/config.mak.arm diff --git a/toolchains/build-toolchain.sh b/toolchains/build-toolchain.sh new file mode 100755 index 000000000..8582b851c --- /dev/null +++ b/toolchains/build-toolchain.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Copyright (C) 2025 Jean-Pierre Miceli +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +# This script build 'arm' & 'aarch64' MUSL toolchains + +SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" + +# output PATH - select where the toolchain will be installed +# +# The final path will be: +# * arm: /arm-linux-musleabihf +# * aarch64: /aarch64-linux-musl +# default: '/aarch64-linux-musl' and '/arm-linux-musleabihf' +#OUTPUT_PATH= + +GIT_COMMIT="3635262" + +AARCH64_PATH='aarch64-linux-musl' +ARM_PATH='arm-linux-musleabihf' + +cd $SCRIPTPATH + +if [[ -v $OUTPUT_PATH ]]; then + OUTPUT=$OUTPUT_PATH +else + OUTPUT=$SCRIPTPATH +fi + +echo "== base installation path is '$SCRIPTPATH'" + +# 1. Retrieve the repo +git clone https://github.com/richfelker/musl-cross-make +cd musl-cross-make +git checkout $GIT_COMMIT + +# Compile & install 'aarch64-linux-musl' +echo "== Compiling 'aarch64-linux-musl' (installation path: $OUTPUT/$AARCH64_PATH" +cp ../config.mak.aarch64 config.mak +echo "OUTPUT = $OUTPUT/$AARCH64_PATH" >> config.mak +make && sudo make install + +# Compile & install 'arm-linux-musleabihf' +echo "== Compiling 'arm-linux-musleabihf'" +make clean +cp ../config.mak.arm config.mak +echo "OUTPUT = $OUTPUT/$ARM_PATH" >> config.mak +make && sudo make install + +cd - diff --git a/toolchains/config.mak.aarch64 b/toolchains/config.mak.aarch64 new file mode 100644 index 000000000..a12e3a4a1 --- /dev/null +++ b/toolchains/config.mak.aarch64 @@ -0,0 +1,88 @@ +# +# config.mak.dist - sample musl-cross-make configuration +# +# Copy to config.mak and edit as desired. +# + +# There is no default TARGET; you must select one here or on the make +# command line. Some examples: + +# TARGET = i486-linux-musl +# TARGET = x86_64-linux-musl +# TARGET = arm-linux-musleabi +# TARGET = arm-linux-musleabihf +# TARGET = sh2eb-linux-muslfdpic +# ... +TARGET = aarch64-linux-musl + +# By default, cross compilers are installed to ./output under the top-level +# musl-cross-make directory and can later be moved wherever you want them. +# To install directly to a specific location, set it here. Multiple targets +# can safely be installed in the same location. Some examples: + +# OUTPUT = /opt/cross +# OUTPUT = /usr/local + +# By default, latest supported release versions of musl and the toolchain +# components are used. You can override those here, but the version selected +# must be supported (under hashes/ and patches/) to work. For musl, you +# can use "git-refname" (e.g. git-master) instead of a release. Setting a +# blank version for gmp, mpc, mpfr and isl will suppress download and +# in-tree build of these libraries and instead depend on pre-installed +# libraries when available (isl is optional and not set by default). +# Setting a blank version for linux will suppress installation of kernel +# headers, which are not needed unless compiling programs that use them. + +BINUTILS_VER = 2.44 +GCC_VER = 12.4.0 +# MUSL_VER = git-master +# GMP_VER = +# MPC_VER = +# MPFR_VER = +# ISL_VER = +# LINUX_VER = + +# By default source archives are downloaded with wget. curl is also an option. + +# DL_CMD = wget -c -O +# DL_CMD = curl -C - -L -o + +# Check sha-1 hashes of downloaded source archives. On gnu systems this is +# usually done with sha1sum. + +# SHA1_CMD = sha1sum -c +# SHA1_CMD = sha1 -c +# SHA1_CMD = shasum -a 1 -c + +# Something like the following can be used to produce a static-linked +# toolchain that's deployable to any system with matching arch, using +# an existing musl-targeted cross compiler. This only works if the +# system you build on can natively (or via binfmt_misc and qemu) run +# binaries produced by the existing toolchain (in this example, i486). + +# COMMON_CONFIG += CC="i486-linux-musl-gcc -static --static" CXX="i486-linux-musl-g++ -static --static" + +# Recommended options for smaller build for deploying binaries: + +COMMON_CONFIG += CFLAGS="-g -Os" CXXFLAGS="-g0 -Os" LDFLAGS="-s" + +# Options you can add for faster/simpler build at the expense of features: + +# COMMON_CONFIG += --disable-nls +# GCC_CONFIG += --disable-libquadmath --disable-decimal-float +# GCC_CONFIG += --disable-libitm +# GCC_CONFIG += --disable-fixed-point +# GCC_CONFIG += --disable-lto + +# By default C and C++ are the only languages enabled, and these are +# the only ones tested and known to be supported. You can uncomment the +# following and add other languages if you want to try getting them to +# work too. + +# GCC_CONFIG += --enable-languages=c,c++ + +# You can keep the local build path out of your toolchain binaries and +# target libraries with the following, but then gdb needs to be told +# where to look for source files. + +# COMMON_CONFIG += --with-debug-prefix-map=$(CURDIR)= diff --git a/toolchains/config.mak.arm b/toolchains/config.mak.arm new file mode 100644 index 000000000..04ba3f122 --- /dev/null +++ b/toolchains/config.mak.arm @@ -0,0 +1,88 @@ +# +# config.mak.dist - sample musl-cross-make configuration +# +# Copy to config.mak and edit as desired. +# + +# There is no default TARGET; you must select one here or on the make +# command line. Some examples: + +# TARGET = i486-linux-musl +# TARGET = x86_64-linux-musl +# TARGET = arm-linux-musleabi +# TARGET = arm-linux-musleabihf +# TARGET = sh2eb-linux-muslfdpic +# ... +TARGET = arm-linux-musleabihf + +# By default, cross compilers are installed to ./output under the top-level +# musl-cross-make directory and can later be moved wherever you want them. +# To install directly to a specific location, set it here. Multiple targets +# can safely be installed in the same location. Some examples: + +# OUTPUT = /opt/cross +# OUTPUT = /usr/local + +# By default, latest supported release versions of musl and the toolchain +# components are used. You can override those here, but the version selected +# must be supported (under hashes/ and patches/) to work. For musl, you +# can use "git-refname" (e.g. git-master) instead of a release. Setting a +# blank version for gmp, mpc, mpfr and isl will suppress download and +# in-tree build of these libraries and instead depend on pre-installed +# libraries when available (isl is optional and not set by default). +# Setting a blank version for linux will suppress installation of kernel +# headers, which are not needed unless compiling programs that use them. + +BINUTILS_VER = 2.44 +GCC_VER = 12.4.0 +# MUSL_VER = git-master +# GMP_VER = +# MPC_VER = +# MPFR_VER = +# ISL_VER = +# LINUX_VER = + +# By default source archives are downloaded with wget. curl is also an option. + +# DL_CMD = wget -c -O +# DL_CMD = curl -C - -L -o + +# Check sha-1 hashes of downloaded source archives. On gnu systems this is +# usually done with sha1sum. + +# SHA1_CMD = sha1sum -c +# SHA1_CMD = sha1 -c +# SHA1_CMD = shasum -a 1 -c + +# Something like the following can be used to produce a static-linked +# toolchain that's deployable to any system with matching arch, using +# an existing musl-targeted cross compiler. This only works if the +# system you build on can natively (or via binfmt_misc and qemu) run +# binaries produced by the existing toolchain (in this example, i486). + +# COMMON_CONFIG += CC="i486-linux-musl-gcc -static --static" CXX="i486-linux-musl-g++ -static --static" + +# Recommended options for smaller build for deploying binaries: + +COMMON_CONFIG += CFLAGS="-g -Os" CXXFLAGS="-g0 -Os" LDFLAGS="-s" + +# Options you can add for faster/simpler build at the expense of features: + +# COMMON_CONFIG += --disable-nls +# GCC_CONFIG += --disable-libquadmath --disable-decimal-float +# GCC_CONFIG += --disable-libitm +# GCC_CONFIG += --disable-fixed-point +# GCC_CONFIG += --disable-lto + +# By default C and C++ are the only languages enabled, and these are +# the only ones tested and known to be supported. You can uncomment the +# following and add other languages if you want to try getting them to +# work too. + +# GCC_CONFIG += --enable-languages=c,c++ + +# You can keep the local build path out of your toolchain binaries and +# target libraries with the following, but then gdb needs to be told +# where to look for source files. + +# COMMON_CONFIG += --with-debug-prefix-map=$(CURDIR)= From 22347aded5bac7388eef8fb8669e60f2357128db Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 18 Nov 2025 10:55:51 +0100 Subject: [PATCH 43/69] [musl] small clean-up in toolchain compilation script Signed-off-by: Jean-Pierre Miceli --- toolchains/build-toolchain.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/toolchains/build-toolchain.sh b/toolchains/build-toolchain.sh index 8582b851c..b81839bdf 100755 --- a/toolchains/build-toolchain.sh +++ b/toolchains/build-toolchain.sh @@ -33,7 +33,12 @@ GIT_COMMIT="3635262" AARCH64_PATH='aarch64-linux-musl' ARM_PATH='arm-linux-musleabihf' -cd $SCRIPTPATH +if [[ $EUID -ne 0 ]]; then + echo "Please run as root" + exit 1 +fi + +pushd $SCRIPTPATH if [[ -v $OUTPUT_PATH ]]; then OUTPUT=$OUTPUT_PATH @@ -61,4 +66,4 @@ cp ../config.mak.arm config.mak echo "OUTPUT = $OUTPUT/$ARM_PATH" >> config.mak make && sudo make install -cd - +popd From 9b7a41b63b6e1c7679845b9592dd90d9c51b7d6a Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 18 Nov 2025 16:57:36 +0100 Subject: [PATCH 44/69] [doc] Add info on how to build MUSL toolchain Signed-off-by: Jean-Pierre Miceli --- doc/source/user_guide.rst | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide.rst b/doc/source/user_guide.rst index eb941c622..357973109 100644 --- a/doc/source/user_guide.rst +++ b/doc/source/user_guide.rst @@ -67,8 +67,8 @@ SO3 root directory (main subdirs):: Build of the environment ************************ -About the toolchain -=================== +kernel toolchain +================ We use the ``arm-none-eabi`` toolchain which has no dependencies on a libc. @@ -78,6 +78,24 @@ The following package can be installed: apt install gcc-arm-none-eabi +usr-space toolchain +=================== + +The usr-space uses MUSL as libc. The Musl toolchains can be generated with +``toolchains/build-toolchain.sh`` script. + +.. code-block:: bash + + $ ./build-toolchain.sh + +By default, it generates ``aarch64-linux-musl`` and ``arm-linux-musleabihf`` +folder in the ``toolchains`` directory + +.. note:: + + The output directory (by default ``toolchains`` floder) can be changed by setting + the ``OUTPUT_PATH`` variable in the ``build-toolchain.sh`` script + Quick setup & early test ======================== From a4d7cc33e3f0316f07443e4ccfe4bf940e2df02a Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 18 Nov 2025 16:58:49 +0100 Subject: [PATCH 45/69] update CI with MUSL toolchains Signed-off-by: Jean-Pierre Miceli --- .github/workflows/build.yml | 4 ++-- docker/Dockerfile.env | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5b9406796..eeba71355 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,8 +31,8 @@ jobs: strategy: fail-fast: false matrix: - CMAKE_TOOLCHAIN_FILE: ['aarch64_toolchain.cmake', - 'arm_toolchain.cmake'] + CMAKE_TOOLCHAIN_FILE: ['aarch64-linux-musl.cmake', + 'arm-linux-musl.cmake'] BUILD_TYPE: ['Debug', 'Release'] steps: - name: Checkout repository diff --git a/docker/Dockerfile.env b/docker/Dockerfile.env index f86e5747f..2fdda4b8e 100644 --- a/docker/Dockerfile.env +++ b/docker/Dockerfile.env @@ -37,11 +37,18 @@ RUN rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz ENV PATH="$PATH:/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf/bin" -# Get current so3 so we can build qemu +# Get current so3 RUN wget https://github.com/smartobjectoriented/so3/archive/refs/heads/main.zip RUN unzip main.zip RUN rm main.zip RUN mv so3-* generated + +# Build Musl toolchains +RUN /generated/build-toolchain.sh +ENV PATH="$PATH:/generated/aarch64-linux-musl/bin" +ENV PATH="$PATH:/generated/arm-linux-musleabihf/bin" + +# Build qemu RUN cd /generated/qemu && ./fetch.sh && ./configure --target-list=arm-softmmu,aarch64-softmmu --disable-attr --disable-werror --disable-docs ENV PATH="$PATH:/generated/qemu/build" # Remove everything except qemu From 5f0c556e3a0dbe9ddb4413d09bf1a398a7f5a0d8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Tue, 18 Nov 2025 17:09:10 +0100 Subject: [PATCH 46/69] Generate updated Docker - needed to get MUSL toolchain Signed-off-by: Jean-Pierre Miceli --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 88ff00ce7..1f316894a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: Docker Image CI on: push: - branches: ["main"] + branches: ["main, 216-use-musl-toolchain-in-usr"] workflow_dispatch: env: From dfb33b8bc203aa9044fff6b7e0636b5254e63b90 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 19 Nov 2025 14:23:42 +0100 Subject: [PATCH 47/69] rework args/env setup to add aux values --- so3/arch/arm32/include/asm/hwcap.h | 64 ++++++++ so3/arch/arm64/include/asm/hwcap.h | 26 ++++ so3/include/elf.h | 4 + so3/include/uapi/linux/auxvec.h | 48 ++++++ so3/kernel/process.c | 237 +++++++++++++++-------------- 5 files changed, 268 insertions(+), 111 deletions(-) create mode 100644 so3/arch/arm32/include/asm/hwcap.h create mode 100644 so3/arch/arm64/include/asm/hwcap.h create mode 100644 so3/include/uapi/linux/auxvec.h diff --git a/so3/arch/arm32/include/asm/hwcap.h b/so3/arch/arm32/include/asm/hwcap.h new file mode 100644 index 000000000..0a19d90c1 --- /dev/null +++ b/so3/arch/arm32/include/asm/hwcap.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2025 Clément Dieperink + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef ASM_ARM_HWCAP_H +#define ASM_ARM_HWCAP_H + +/* + * Hardware capabilities flags - for AT_HWCAP + * Copied from Linux arch/arm/include/asm/procinfo.h + */ +#define HWCAP_SWP (1 << 0) +#define HWCAP_HALF (1 << 1) +#define HWCAP_THUMB (1 << 2) +#define HWCAP_26BIT (1 << 3) /* Play it safe */ +#define HWCAP_FAST_MULT (1 << 4) +#define HWCAP_FPA (1 << 5) +#define HWCAP_VFP (1 << 6) +#define HWCAP_EDSP (1 << 7) +#define HWCAP_JAVA (1 << 8) +#define HWCAP_IWMMXT (1 << 9) +#define HWCAP_CRUNCH (1 << 10) /* Obsolete */ +#define HWCAP_THUMBEE (1 << 11) +#define HWCAP_NEON (1 << 12) +#define HWCAP_VFPv3 (1 << 13) +#define HWCAP_VFPv3D16 (1 << 14) /* also set for VFPv4-D16 */ +#define HWCAP_TLS (1 << 15) +#define HWCAP_VFPv4 (1 << 16) +#define HWCAP_IDIVA (1 << 17) +#define HWCAP_IDIVT (1 << 18) +#define HWCAP_VFPD32 (1 << 19) /* set if VFP has 32 regs (not 16) */ +#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT) +#define HWCAP_LPAE (1 << 20) +#define HWCAP_EVTSTRM (1 << 21) +#define HWCAP_FPHP (1 << 22) +#define HWCAP_ASIMDHP (1 << 23) +#define HWCAP_ASIMDDP (1 << 24) +#define HWCAP_ASIMDFHM (1 << 25) +#define HWCAP_ASIMDBF16 (1 << 26) +#define HWCAP_I8MM (1 << 27) + +/* + * ARMv7 flags used by Linux, see arch/arm/mm/proc-v7.S, macro __v7_proc + */ +#define HWCAP_ELF (HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_FAST_MULT | HWCAP_EDSP | HWCAP_TLS) + +#endif /* ASM_ARM_HWCAP */ diff --git a/so3/arch/arm64/include/asm/hwcap.h b/so3/arch/arm64/include/asm/hwcap.h new file mode 100644 index 000000000..75e034c73 --- /dev/null +++ b/so3/arch/arm64/include/asm/hwcap.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2025 Clément Dieperink + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef ASM_ARM_HWCAP_H +#define ASM_ARM_HWCAP_H + +/* + * This isn't used be MUSL on AArch64, so simply let it to 0 for now. + */ +#define HWCAP_ELF 0 + +#endif /* ASM_ARM_HWCAP */ diff --git a/so3/include/elf.h b/so3/include/elf.h index 767ca1155..688bbb678 100644 --- a/so3/include/elf.h +++ b/so3/include/elf.h @@ -36,6 +36,8 @@ struct elf_img_info { uint32_t segment_page_count; }; +typedef Elf32_Off elf_addr_t; + #else struct elf_img_info { @@ -47,6 +49,8 @@ struct elf_img_info { uint64_t segment_page_count; }; +typedef Elf64_Off elf_addr_t; + #endif typedef struct elf_img_info elf_img_info_t; diff --git a/so3/include/uapi/linux/auxvec.h b/so3/include/uapi/linux/auxvec.h new file mode 100644 index 000000000..6e7a3f5eb --- /dev/null +++ b/so3/include/uapi/linux/auxvec.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_AUXVEC_H +#define _UAPI_LINUX_AUXVEC_H + +/* Maximum count of auxiliary values */ +#define AUX_CNT 38 + +/* Symbolic values for the entries in the auxiliary table + put on the initial stack */ +#define AT_NULL 0 /* end of vector */ +#define AT_IGNORE 1 /* entry should be ignored */ +#define AT_EXECFD 2 /* file descriptor of program */ +#define AT_PHDR 3 /* program headers for program */ +#define AT_PHENT 4 /* size of program header entry */ +#define AT_PHNUM 5 /* number of program headers */ +#define AT_PAGESZ 6 /* system page size */ +#define AT_BASE 7 /* base address of interpreter */ +#define AT_FLAGS 8 /* flags */ +#define AT_ENTRY 9 /* entry point of program */ +#define AT_NOTELF 10 /* program is not ELF */ +#define AT_UID 11 /* real uid */ +#define AT_EUID 12 /* effective uid */ +#define AT_GID 13 /* real gid */ +#define AT_EGID 14 /* effective gid */ +#define AT_PLATFORM 15 /* string identifying CPU for optimizations */ +#define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */ +#define AT_CLKTCK 17 /* frequency at which times() increments */ +/* AT_* values 18 through 22 are reserved */ +#define AT_SECURE 23 /* secure mode boolean */ +#define AT_BASE_PLATFORM 24 /* string identifying real platform, may + * differ from AT_PLATFORM. */ +#define AT_RANDOM 25 /* address of 16 random bytes */ +#define AT_HWCAP2 26 /* extension of AT_HWCAP */ +#define AT_RSEQ_FEATURE_SIZE 27 /* rseq supported feature size */ +#define AT_RSEQ_ALIGN 28 /* rseq allocation alignment */ +#define AT_HWCAP3 29 /* extension of AT_HWCAP */ +#define AT_HWCAP4 30 /* extension of AT_HWCAP */ + +#define AT_EXECFN 31 /* filename of program */ + +#ifndef AT_MINSIGSTKSZ +#define AT_MINSIGSTKSZ 51 /* minimal stack size for signal delivery */ +#endif + +/* Common from asm/auxvec.h of arm and arm64 */ +#define AT_SYSINFO_EHDR 33 + +#endif /* _UAPI_LINUX_AUXVEC_H */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 0caa26cf0..1b915e462 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -32,6 +32,9 @@ #include #include #include +#include + +#include #include @@ -39,10 +42,19 @@ #include #include #include +#include #ifndef CONFIG_ARCH_ARM32 #include #endif +/* Structure to temporary save exec args/env */ +typedef struct { + int argc; + int envc; + size_t strings_size; + char arg_env[PAGE_SIZE]; +} args_env_t; + static char *proc_state_strings[5] = { [PROC_STATE_NEW] = "NEW", [PROC_STATE_READY] = "READY", [PROC_STATE_RUNNING] = "RUNNING", [PROC_STATE_WAITING] = "WAITING", [PROC_STATE_ZOMBIE] = "ZOMBIE", @@ -390,150 +402,153 @@ static void release_proc_pages(pcb_t *pcb) */ addr_t preserve_args_and_env(int argc, char **argv, char **envp) { - char *args_p, *args_str_p; - void *args; - char **__args; + char *args_str_p; + size_t str_len; + args_env_t *saved; int i; if ((argc > 0) && (argv == NULL)) { return -EINVAL; } - /* Page storing the args & env strings - keeps a reference to it. - */ - args = malloc(PAGE_SIZE); - BUG_ON(args == NULL); - - memset(args, 0, PAGE_SIZE); - - args_p = (char *) args; - if (!argc) - i = 1; - else - i = argc; - - memcpy(args_p, &i, sizeof(int)); - - /* Number of args */ - args_p += sizeof(int); - - /* Store the array of strings for args & env */ - - /* The array starts right after argc (stored on 4 bytes). - * We find the addresses of the var strings followed by the addresses of - * env strings. The var strings come after followed by the env strings. - */ - - /* Manage the addresses of strings; determine the start of the first arg - * string. */ - - if (!argc) /* At least one arg containing the process name */ - args_p += sizeof(char *); - else - args_p += sizeof(char *) * argc; - - /* Environment string addresses */ - if (!envp) { - *((addr_t *) args_p) = 0; /* Keep array-end with NULL */ - args_p += sizeof(char *); - - } else { - i = 0; - do { - args_p = args_p + sizeof(char *); - } while (envp[i++] != NULL); - } + /* Allocate kernel memory to preserve the args/env */ + saved = malloc(sizeof(args_env_t)); + BUG_ON(saved == NULL); - /* Manage the arg strings */ + memset(saved->arg_env, 0, PAGE_SIZE); - args_str_p = args_p; - __args = (char **) (args + sizeof(int)); + args_str_p = (char *) saved->arg_env; - /* As said before, if argc is 0 (argv NULL), we put the process name (a - * kind of by-default argument) */ + /* Save args strings */ if (!argc) { - __args[0] = args_str_p; - strcpy(__args[0], current()->pcb->name); - - args_str_p += strlen(current()->pcb->name) + 1; - } - - /* Place the strings with their addresses - is the new address - * (definitive location). */ - - for (i = 0; i < argc; i++) { - __args[i] = args_str_p; - strcpy(__args[i], argv[i]); + /* If no arguments, add one with process name */ + saved->argc = 1; + strcpy(args_str_p, current()->pcb->name); + args_str_p += strlen(args_str_p) + 1; + } else { + /* Copy all arguments strings */ + saved->argc = argc; + for (i = 0; i < argc; i++) { + str_len = strlen(argv[i]) + 1; - args_str_p += strlen(argv[i]) + 1; + /* Ensure the newly copied string will not exceed the buffer size. */ + if ((addr_t) args_str_p - (addr_t) saved->arg_env + str_len > PAGE_SIZE) { + LOG_CRITICAL("Not enougth memory allocated\n"); - /* We check if the pointer do not exceed the page we - * allocated before */ - if (((addr_t) args_str_p - (addr_t) args) > PAGE_SIZE) { - LOG_CRITICAL("Not enougth memory allocated\n"); + free(saved); + return -ENOMEM; + } - free(args); - return -ENOMEM; + strcpy(args_str_p, argv[i]); + args_str_p += str_len; } } - /* Environment strings */ - - /* First env. variable */ - __args = (char **) (args + sizeof(int) + sizeof(char *) * (*((int *) args))); - - /* If the environment was passed */ + /* Save env strings and count how many there are */ + saved->envc = 0; if (envp) { - i = 0; - while (envp[i] != NULL) { - __args[i] = args_str_p; - strcpy(__args[i], envp[i]); - - args_str_p += strlen(envp[i]) + 1; + do { + str_len = strlen(envp[saved->envc]) + 1; - /* We check if pointer do not exceed the page we - * allocated before. */ - if (((addr_t) args_str_p - (addr_t) args) > PAGE_SIZE) { - LOG_ERROR("Not enough memory allocated\n"); + /* Ensure the newly copied string will not exceed the buffer size. */ + if ((addr_t) args_str_p - (addr_t) saved->arg_env + str_len > PAGE_SIZE) { + LOG_CRITICAL("Not enougth memory allocated\n"); - free(args); + free(saved); return -ENOMEM; } - i++; - } + + strcpy(args_str_p, envp[saved->envc]); + args_str_p += strlen(args_str_p) + 1; + } while (envp[saved->envc++]); } - return (addr_t) args; + /* Save total string size for easier copy to user. */ + saved->strings_size = (addr_t) args_str_p - (addr_t) saved->arg_env; + + return (addr_t) saved; } -void post_setup_image(void *args_env) +void post_setup_image(args_env_t *args_env, elf_img_info_t *elf_img_info) { - char **__args; + char **argv_p_base; + char *str_p; + char **env_p_base; char *args_base; - int argc, i; + int i; + elf_addr_t *aux_elf; args_base = (char *) arch_get_args_base(); - memcpy(args_base, args_env, PAGE_SIZE); + /* Save argc as first arguments */ + *((int *) args_base) = args_env->argc; + + /* Get the base address for the array of pointer for args, env and aux */ + argv_p_base = (char **) (args_base + sizeof(int)); + env_p_base = (char **) ((addr_t) argv_p_base + args_env->argc * sizeof(char *)); + /* Add one to account for the null termination of env */ + aux_elf = (elf_addr_t *) ((addr_t) env_p_base + (args_env->envc + 1) * sizeof(char *)); + + /* Adds auxiliary before args and env to get the starting address for the strings. + * Each auxiliary entry have an id and a value, the following temporary helper allows + * to easily add an entry without missing something, or adding unecessary functions. + * This is copied from linux/fs/binfmt_elf.c */ +#define NEW_AUX_ENT(id, val) \ + do { \ + *aux_elf++ = id; \ + *aux_elf++ = val; \ + } while (0) + + /* Adds up auxiliary array. */ + NEW_AUX_ENT(AT_PAGESZ, PAGE_SIZE); + NEW_AUX_ENT(AT_CLKTCK, clocksource_timer.rate); + NEW_AUX_ENT(AT_ENTRY, elf_img_info->header->e_entry); + + /* By default, MUSL will use argv[0], so this isn't required as it con */ + NEW_AUX_ENT(AT_EXECFN, 0); + + /* This should contains a bitmask of hardware capabilities */ + NEW_AUX_ENT(AT_HWCAP, HWCAP_ELF); + + /* Those value should come from elf_img_info->header, but as user application + * are compiled with linker option -N, the program header (PHDR) isn't in a PT_LOAD + * segment meaning it will not be copied in userspace. + * The main effect of this is that variable in thread local storage will not be possible. + * Those variable are *flaged* with __thread (i.e `__thread int n;`) and aren't used for now. + * This header is also used for dynamically linking, which isn't supported by SO3 anyway. + */ + NEW_AUX_ENT(AT_PHDR, 0); + NEW_AUX_ENT(AT_PHENT, 0); + NEW_AUX_ENT(AT_PHNUM, 0); - free(args_env); + /* NULL termination */ + NEW_AUX_ENT(AT_NULL, 0); - /* Now, readjust the address of the var and env strings */ + /* Remove the temporary helper. */ +#undef NEW_AUX_ENT - argc = *((int *) args_base); - __args = (char **) (args_base + sizeof(int)); + /* Copy all strings into their final destination and set pointers to them */ - /* We get the offset based on the current location and the start of the - * args_env page, then we adjust it to match our final destination. - */ - for (i = 0; i < argc; i++) - __args[i] = ((addr_t) __args[i] - (addr_t) args_env) + args_base; + /* Strings will be put just after aux */ + str_p = (char *) aux_elf; - /* Focus on the env addresses now */ - __args = (char **) (args_base + sizeof(int) + argc * sizeof(char *)); + memcpy(str_p, args_env->arg_env, args_env->strings_size); - for (i = 0; __args[i] != NULL; i++) - __args[i] = ((addr_t) __args[i] - (addr_t) args_env) + args_base; + /* Set the correct addresses into argv array */ + for (i = 0; i < args_env->argc; i++) { + argv_p_base[i] = str_p; + str_p += strlen(str_p) + 1; + } + + /* Set the correct addresses into env array */ + for (i = 0; i < args_env->envc; i++) { + env_p_base[i] = str_p; + str_p += strlen(str_p) + 1; + } + /* Ensure the NULL terminated list */ + env_p_base[args_env->envc] = NULL; + + free(args_env); } /* @@ -543,7 +558,7 @@ int setup_proc_image_replace(elf_img_info_t *elf_img_info, pcb_t *pcb, int argc, { uint32_t page_count; addr_t ret; - void *__args_env; + args_env_t *__args_env; /* FIXME: detect fragmented executable (error)? */ /* @@ -558,7 +573,7 @@ int setup_proc_image_replace(elf_img_info_t *elf_img_info, pcb_t *pcb, int argc, if (ret < 0) return ret; - __args_env = (void *) ret; + __args_env = (args_env_t *) ret; /* Reset the process stack and page count */ reset_process_stack(pcb); @@ -618,7 +633,7 @@ int setup_proc_image_replace(elf_img_info_t *elf_img_info, pcb_t *pcb, int argc, /* Prepare the arguments within the page reserved for this purpose. */ if (__args_env) - post_setup_image(__args_env); + post_setup_image(__args_env, elf_img_info); return 0; } From 3d0c2a760174c37bef0594bac3cff0a85c404c2a Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 19 Nov 2025 14:26:05 +0100 Subject: [PATCH 48/69] fix futex miss call --- so3/kernel/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 2f4208b52..14873b6ff 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -270,7 +270,7 @@ void thread_exit(int exit_status) if (pcb && current() != pcb->main_thread) { if (current()->clear_child_tid) { *(current()->clear_child_tid) = 0; - do_futex(current()->clear_child_tid, FUTEX_WAKE, 1, NULL, NULL, 0, 0); + sys_do_futex(current()->clear_child_tid, FUTEX_WAKE, 1, NULL, NULL, 0); } } From 6749de8f0c6411f151d95e514d19040a0c37f326 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 19 Nov 2025 14:47:51 +0100 Subject: [PATCH 49/69] small improvement --- so3/arch/arm32/include/asm/hwcap.h | 1 - so3/arch/arm64/include/asm/hwcap.h | 3 +-- so3/include/uapi/linux/auxvec.h | 26 ++++++++++++++++++++------ so3/kernel/process.c | 25 ++++++++++++------------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/so3/arch/arm32/include/asm/hwcap.h b/so3/arch/arm32/include/asm/hwcap.h index 0a19d90c1..43781a0d2 100644 --- a/so3/arch/arm32/include/asm/hwcap.h +++ b/so3/arch/arm32/include/asm/hwcap.h @@ -18,7 +18,6 @@ * along with this program. If not, see . */ - #ifndef ASM_ARM_HWCAP_H #define ASM_ARM_HWCAP_H diff --git a/so3/arch/arm64/include/asm/hwcap.h b/so3/arch/arm64/include/asm/hwcap.h index 75e034c73..0364a207f 100644 --- a/so3/arch/arm64/include/asm/hwcap.h +++ b/so3/arch/arm64/include/asm/hwcap.h @@ -14,12 +14,11 @@ * along with this program. If not, see . */ - #ifndef ASM_ARM_HWCAP_H #define ASM_ARM_HWCAP_H /* - * This isn't used be MUSL on AArch64, so simply let it to 0 for now. + * This isn't used by MUSL on AArch64, so simply let it to 0 for now. */ #define HWCAP_ELF 0 diff --git a/so3/include/uapi/linux/auxvec.h b/so3/include/uapi/linux/auxvec.h index 6e7a3f5eb..bf34d20f5 100644 --- a/so3/include/uapi/linux/auxvec.h +++ b/so3/include/uapi/linux/auxvec.h @@ -1,9 +1,23 @@ -/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#ifndef _UAPI_LINUX_AUXVEC_H -#define _UAPI_LINUX_AUXVEC_H +/* + * Copyright (C) 2025 Clément Dieperink + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ -/* Maximum count of auxiliary values */ -#define AUX_CNT 38 +#ifndef UAPI_LINUX_AUXVEC_H +#define UAPI_LINUX_AUXVEC_H + +/* Copied from linux/include/uapi/linux/auxvec.h */ /* Symbolic values for the entries in the auxiliary table put on the initial stack */ @@ -42,7 +56,7 @@ #define AT_MINSIGSTKSZ 51 /* minimal stack size for signal delivery */ #endif -/* Common from asm/auxvec.h of arm and arm64 */ +/* Common in asm/auxvec.h of arm and arm64 */ #define AT_SYSINFO_EHDR 33 #endif /* _UAPI_LINUX_AUXVEC_H */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 1b915e462..4cfac83bb 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -402,7 +402,6 @@ static void release_proc_pages(pcb_t *pcb) */ addr_t preserve_args_and_env(int argc, char **argv, char **envp) { - char *args_str_p; size_t str_len; args_env_t *saved; int i; @@ -417,14 +416,14 @@ addr_t preserve_args_and_env(int argc, char **argv, char **envp) memset(saved->arg_env, 0, PAGE_SIZE); - args_str_p = (char *) saved->arg_env; + saved->strings_size = 0; /* Save args strings */ if (!argc) { /* If no arguments, add one with process name */ saved->argc = 1; - strcpy(args_str_p, current()->pcb->name); - args_str_p += strlen(args_str_p) + 1; + strcpy(&saved->arg_env[saved->strings_size], current()->pcb->name); + saved->strings_size += strlen(current()->pcb->name) + 1; } else { /* Copy all arguments strings */ saved->argc = argc; @@ -432,15 +431,15 @@ addr_t preserve_args_and_env(int argc, char **argv, char **envp) str_len = strlen(argv[i]) + 1; /* Ensure the newly copied string will not exceed the buffer size. */ - if ((addr_t) args_str_p - (addr_t) saved->arg_env + str_len > PAGE_SIZE) { + if (saved->strings_size + str_len > PAGE_SIZE) { LOG_CRITICAL("Not enougth memory allocated\n"); free(saved); return -ENOMEM; } - strcpy(args_str_p, argv[i]); - args_str_p += str_len; + strcpy(&saved->arg_env[saved->strings_size], argv[i]); + saved->strings_size += str_len; } } @@ -451,21 +450,18 @@ addr_t preserve_args_and_env(int argc, char **argv, char **envp) str_len = strlen(envp[saved->envc]) + 1; /* Ensure the newly copied string will not exceed the buffer size. */ - if ((addr_t) args_str_p - (addr_t) saved->arg_env + str_len > PAGE_SIZE) { + if (saved->strings_size + str_len > PAGE_SIZE) { LOG_CRITICAL("Not enougth memory allocated\n"); free(saved); return -ENOMEM; } - strcpy(args_str_p, envp[saved->envc]); - args_str_p += strlen(args_str_p) + 1; + strcpy(&saved->arg_env[saved->strings_size], envp[saved->envc]); + saved->strings_size += str_len; } while (envp[saved->envc++]); } - /* Save total string size for easier copy to user. */ - saved->strings_size = (addr_t) args_str_p - (addr_t) saved->arg_env; - return (addr_t) saved; } @@ -532,6 +528,9 @@ void post_setup_image(args_env_t *args_env, elf_img_info_t *elf_img_info) /* Strings will be put just after aux */ str_p = (char *) aux_elf; + /* Ensure that the strings will not overflow */ + BUG_ON(args_env->strings_size + ((addr_t) str_p - (addr_t) args_base) > PAGE_SIZE); + memcpy(str_p, args_env->arg_env, args_env->strings_size); /* Set the correct addresses into argv array */ From 2fb170763280abb326f7275537f93b63ec67538b Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 19 Nov 2025 14:54:42 +0100 Subject: [PATCH 50/69] fix clang-format from copied files --- so3/arch/arm32/include/asm/hwcap.h | 4 ++++ so3/include/uapi/linux/auxvec.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/so3/arch/arm32/include/asm/hwcap.h b/so3/arch/arm32/include/asm/hwcap.h index 43781a0d2..cf63eb016 100644 --- a/so3/arch/arm32/include/asm/hwcap.h +++ b/so3/arch/arm32/include/asm/hwcap.h @@ -21,6 +21,8 @@ #ifndef ASM_ARM_HWCAP_H #define ASM_ARM_HWCAP_H +/* clang-format off */ + /* * Hardware capabilities flags - for AT_HWCAP * Copied from Linux arch/arm/include/asm/procinfo.h @@ -60,4 +62,6 @@ */ #define HWCAP_ELF (HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_FAST_MULT | HWCAP_EDSP | HWCAP_TLS) +/* clang-format on */ + #endif /* ASM_ARM_HWCAP */ diff --git a/so3/include/uapi/linux/auxvec.h b/so3/include/uapi/linux/auxvec.h index bf34d20f5..e23fed76e 100644 --- a/so3/include/uapi/linux/auxvec.h +++ b/so3/include/uapi/linux/auxvec.h @@ -17,6 +17,8 @@ #ifndef UAPI_LINUX_AUXVEC_H #define UAPI_LINUX_AUXVEC_H +/* clang-format off */ + /* Copied from linux/include/uapi/linux/auxvec.h */ /* Symbolic values for the entries in the auxiliary table @@ -59,4 +61,6 @@ /* Common in asm/auxvec.h of arm and arm64 */ #define AT_SYSINFO_EHDR 33 +/* clang-format on */ + #endif /* _UAPI_LINUX_AUXVEC_H */ From 26b9b8c079a5a3b91f107056be64344664b612c5 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 19 Nov 2025 15:47:13 +0100 Subject: [PATCH 51/69] fix brk implementation --- so3/include/process.h | 2 +- so3/kernel/process.c | 27 ++++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/so3/include/process.h b/so3/include/process.h index 7c845a234..03fb4dfb6 100644 --- a/so3/include/process.h +++ b/so3/include/process.h @@ -172,6 +172,6 @@ void dump_proc(void); extern int __exec(const char *file); extern int __write(int fd, char *buffer, int count); -SYSCALL_DECLARE(brk, long increment); +SYSCALL_DECLARE(brk, void *addr); #endif /* PROCESS_H */ diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 4cfac83bb..0f1be81bd 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -1063,35 +1063,28 @@ SYSCALL_DEFINE4(wait4, int, pid, uint32_t *, wstatus, uint32_t, options, void *, * increase the heap_pointer and make sure it does not * overflow the heap. If there is no memory left it will * return ENONMEM; - * @param increment the amount of data to increase < decrease. If the value is 0 - * function will return the current position of the program break - *(end of heap); + * @param addr New end address requested by userspace. * - * @return This function will the position of the end of the heap / program - *break before increment + * @return End address of the available heap. */ -SYSCALL_DEFINE1(brk, long, increment) +SYSCALL_DEFINE1(brk, void *, addr) { pcb_t *pcb = current()->pcb; - int ret_pointer; int req_sz = 0; - int cur_sz; - if (!pcb) { + if (!pcb) /* case there is no pcb context */ return -ESRCH; - } - ret_pointer = pcb->heap_pointer; + if (addr == NULL) + return pcb->heap_pointer; /* we make sure the future size of the heap is not overflowing / * underflowing*/ - cur_sz = pcb->heap_pointer - pcb->heap_base; - req_sz = cur_sz + increment; + req_sz = (addr_t) addr - pcb->heap_base; - if ((req_sz >= HEAP_SIZE) || (req_sz < 0)) { + if ((req_sz >= HEAP_SIZE) || (req_sz < 0)) return -ENOMEM; - } #if 0 /* This is the the code allocation will be done automatically*/ @@ -1122,8 +1115,8 @@ SYSCALL_DEFINE1(brk, long, increment) } #endif - pcb->heap_pointer = pcb->heap_pointer + increment; - return ret_pointer; + pcb->heap_pointer = (addr_t) addr; + return pcb->heap_pointer; } #ifdef CONFIG_PRIORITY_SCHEDULER From fa7e4a7590e95c21b726451c5041b931e1f20d5b Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 19 Nov 2025 16:30:27 +0100 Subject: [PATCH 52/69] change default heap base address to be after the program --- so3/kernel/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/so3/kernel/process.c b/so3/kernel/process.c index 0f1be81bd..b78c28a73 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -609,14 +609,14 @@ int setup_proc_image_replace(elf_img_info_t *elf_img_info, pcb_t *pcb, int argc, pcb->page_count += elf_img_info->segment_page_count; /* Map the elementary sections (text, data, bss) */ - allocate_page(pcb, (uint32_t) elf_img_info->header->e_entry, elf_img_info->segment_page_count, true); + allocate_page(pcb, (uint32_t) (elf_img_info->header->e_entry & PAGE_MASK), elf_img_info->segment_page_count, true); LOG_DEBUG("entry point: 0x%08x\n", elf_img_info->header->e_entry); LOG_DEBUG("page count: 0x%08x\n", pcb->page_count); /* Maximum heap size */ page_count = ALIGN_UP(HEAP_SIZE, PAGE_SIZE) >> PAGE_SHIFT; - pcb->heap_base = (pcb->page_count + 1) * PAGE_SIZE; + pcb->heap_base = (elf_img_info->header->e_entry & PAGE_MASK) + (pcb->page_count + 1) * PAGE_SIZE; pcb->heap_pointer = pcb->heap_base; pcb->page_count += page_count; From a6d9367e6eca609b3ffab4609b91e39caafbd048 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 3 Dec 2025 09:27:35 +0100 Subject: [PATCH 53/69] [CI] Test Signed-off-by: Jean-Pierre Miceli --- docker/Dockerfile.lvperf_64b | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docker/Dockerfile.lvperf_64b b/docker/Dockerfile.lvperf_64b index c8c2a851d..2db857e0e 100644 --- a/docker/Dockerfile.lvperf_64b +++ b/docker/Dockerfile.lvperf_64b @@ -49,6 +49,11 @@ COPY --from=builder /so3/u-boot/u-boot u-boot COPY u-boot/uEnv.d u-boot/uEnv.d +COPY toolchains /so3/toolchains +RUN toolchains/build-toolchain.sh && rm -rf toolchains/musl-cross-make +ENV PATH=$PATH:/so3/toolchains/aarch64-linux-musl/bin +ENV PATH=$PATH:/so3/toolchains/arm-linux-musleabihf/bin + RUN mkdir target RUN mkdir -p usr RUN mkdir -p docker/scripts From b39cc2bc50bc08e7a5a19b9b0eeaebbaf2483b47 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 3 Dec 2025 09:41:33 +0100 Subject: [PATCH 54/69] [ci] Add test branch Signed-off-by: Jean-Pierre Miceli --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1f316894a..ea0f9fb10 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,7 @@ name: Docker Image CI on: push: - branches: ["main, 216-use-musl-toolchain-in-usr"] + branches: ["main", "216-use-musl-toolchain-in-usr"] workflow_dispatch: env: From 3292b7677595abfafeb084506eaf8240e52cb8ff Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 3 Dec 2025 11:23:33 +0100 Subject: [PATCH 55/69] add rt_sigprocmask syscall --- so3/include/signal.h | 14 +++++-- so3/include/thread.h | 11 +++++ so3/ipc/signal.c | 95 ++++++++++++++++++++++++++++++++++++-------- so3/kernel/process.c | 5 +++ so3/kernel/thread.c | 4 ++ so3/syscall.tbl | 1 + 6 files changed, 111 insertions(+), 19 deletions(-) diff --git a/so3/include/signal.h b/so3/include/signal.h index 1feb49783..2895e86ea 100644 --- a/so3/include/signal.h +++ b/so3/include/signal.h @@ -22,7 +22,6 @@ #include #include -#include #define SIGHUP 1 #define SIGINT 2 @@ -59,14 +58,22 @@ #define SIGSYS 31 #define SIGUNUSED SIGSYS -#define _NSIG 65 +/* sigprocmaks behaviors */ +#define SIG_BLOCK 0 +#define SIG_UNBLOCK 1 +#define SIG_SETMASK 2 + +#define _NSIG 64 +/* Bits per sig map entry */ +#define _NSIG_BPE (8 * sizeof(unsigned long)) +#define _NSIG_NB_ENTRY (_NSIG / _NSIG_BPE) #define SIGMAP_CELLSIZE (sizeof(int)) typedef void (*__sighandler_t)(int); typedef struct { - uint32_t sigmap[_NSIG / (8 * sizeof(uint32_t))]; + unsigned long sigmap[_NSIG_NB_ENTRY]; } sigset_t; /* Fake signal functions. */ @@ -95,6 +102,7 @@ typedef struct __sigaction { } __sigaction_t; SYSCALL_DECLARE(rt_sigaction, int signum, const sigaction_t *action, sigaction_t *old_action, size_t sigsize); +SYSCALL_DECLARE(rt_sigprocmask, int how, const sigset_t *set, sigset_t *old, size_t sigsize); SYSCALL_DECLARE(kill, int pid, int sig); SYSCALL_DECLARE(sigreturn, void); SYSCALL_DECLARE(rt_sigreturn, void); diff --git a/so3/include/thread.h b/so3/include/thread.h index 8d1625eb3..78c7bdb8e 100644 --- a/so3/include/thread.h +++ b/so3/include/thread.h @@ -28,6 +28,7 @@ #include #include +#include #include typedef enum { @@ -82,6 +83,11 @@ struct tcb { int exit_status; int *clear_child_tid; +#ifdef CONFIG_IPC_SIGNAL + /* Mask for thread's disabled signals */ + sigset_t sig_mask; +#endif + struct list_head list; /* List of threads belonging to a process */ /* Join queue to handle threads waiting on it */ @@ -108,6 +114,11 @@ typedef struct { int *parent_tid; int *child_tid; +#ifdef CONFIG_IPC_SIGNAL + /* Starting mask for thread's disabled signals, should be the same as parent */ + sigset_t sig_mask; +#endif + /* Function to call for kernel thread or root user process */ th_fn_t fn; diff --git a/so3/ipc/signal.c b/so3/ipc/signal.c index 24de966a5..6dbdf5a34 100644 --- a/so3/ipc/signal.c +++ b/so3/ipc/signal.c @@ -58,27 +58,49 @@ SYSCALL_DEFINE0(rt_sigreturn) __sigaction_t *sig_check(void) { size_t i; + size_t sig_nr; + sigset_t *signal; + sigset_t *blocked; + unsigned long pending; + unsigned long bit_pos; if (!current() || (current()->pcb == NULL)) return NULL; - for (i = 1; i < _NSIG; i++) { - /* Check the signal bit for each signals */ - if (current()->pcb->sigset_map.sigmap[(i - 1) / (8 * sizeof(long))] & (1UL << (i - 1) % (8 * sizeof(long)))) { + signal = ¤t()->pcb->sigset_map; + blocked = ¤t()->sig_mask; + + for (i = 0; i < _NSIG_NB_ENTRY; i++) { + /* Find if any unmasked signal is pending */ + pending = signal->sigmap[i] & ~blocked->sigmap[i]; + + while (pending != 0) { + /* Get number of the next pending signal */ + bit_pos = find_first_bit(&pending, _NSIG_BPE); + sig_nr = bit_pos + (i * _NSIG_BPE) + 1; + + /* Reset pending state of the handled signal. */ + signal->sigmap[i] &= ~(1UL << bit_pos); + pending &= ~(1UL << bit_pos); + /* Check if a handler was specified for this signal */ + if (current()->pcb->sa[sig_nr].sa_handler == SIG_DFL) { + /* Default handler to terminate an application */ + if ((sig_nr == SIGINT) || (sig_nr == SIGTERM) || (sig_nr == SIGKILL)) + sys_do_exit_group(0); - if (current()->pcb->sa[i].sa_handler != NULL) { - current()->pcb->__sa[i].sa = ¤t()->pcb->sa[i]; - current()->pcb->__sa[i].signum = i; + continue; + } - current()->pcb->sigset_map.sigmap[(i - 1) / (8 * sizeof(long))] &= - ~(1UL << (i - 1) % (8 * sizeof(long))); + if (current()->pcb->sa[sig_nr].sa_handler != SIG_IGN) { + /* User set handler, let return in it */ + current()->pcb->__sa[sig_nr].sa = ¤t()->pcb->sa[sig_nr]; + current()->pcb->__sa[sig_nr].signum = sig_nr; - return ¤t()->pcb->__sa[i]; + return ¤t()->pcb->__sa[sig_nr]; } } } - return NULL; } @@ -123,15 +145,56 @@ SYSCALL_DEFINE4(rt_sigaction, int, signum, const sigaction_t *, action, sigactio return -EINVAL; } + if ((signum == SIGKILL) || (signum == SIGTERM)) { + LOG_ERROR("SIGKILL and SIGTERM can't be modified!\n"); + return -EINVAL; + } + if (old_action != NULL) *old_action = current()->pcb->sa[signum]; /* Copy action into the process sigaction_t array */ - if (action) { - if (action->sa_handler == SIG_IGN) - current()->pcb->sa[signum].sa_handler = NULL; - else - current()->pcb->sa[signum] = *action; + if (action) + current()->pcb->sa[signum] = *action; + + return 0; +} + +SYSCALL_DEFINE4(rt_sigprocmask, int, how, const sigset_t *, set, sigset_t *, old, size_t, sigsize) +{ + size_t i; + + if (sigsize != sizeof(sigset_t)) { + LOG_WARNING("Invalid sigset size\n"); + return -EINVAL; + } + + if (old != NULL) + *old = current()->sig_mask; + + if (set != NULL) { + switch (how) { + case SIG_BLOCK: + for (i = 0; i < _NSIG_NB_ENTRY; i++) { + current()->sig_mask.sigmap[i] |= set->sigmap[i]; + } + break; + case SIG_UNBLOCK: + for (i = 0; i < _NSIG_NB_ENTRY; i++) { + current()->sig_mask.sigmap[i] &= ~set->sigmap[i]; + } + break; + case SIG_SETMASK: + current()->sig_mask = *set; + break; + + default: + return -EINVAL; + } + + /* Ensure SIGKILL and SIGTERM are still active */ + current()->sig_mask.sigmap[(SIGKILL - 1) / _NSIG_BPE] &= ~(1UL << ((SIGKILL - 1) % _NSIG_BPE)); + current()->sig_mask.sigmap[(SIGTERM - 1) / _NSIG_BPE] &= ~(1UL << ((SIGTERM - 1) % _NSIG_BPE)); } return 0; @@ -159,7 +222,7 @@ SYSCALL_DEFINE2(kill, int, pid, int, sig) if (proc->state != PROC_STATE_ZOMBIE) { /* Set the corresponding bit in the pcb signals bitmap */ - proc->sigset_map.sigmap[(sig - 1) / (8 * sizeof(long))] |= 1UL << (sig - 1) % (8 * sizeof(long)); + proc->sigset_map.sigmap[(sig - 1) / _NSIG_BPE] |= 1UL << (sig - 1) % _NSIG_BPE; /* Depending on the scheduling policy, the signal handler will be processed soon. */ raise_softirq(SCHEDULE_SOFTIRQ); diff --git a/so3/kernel/process.c b/so3/kernel/process.c index b78c28a73..c05540775 100644 --- a/so3/kernel/process.c +++ b/so3/kernel/process.c @@ -866,6 +866,11 @@ static long do_clone(clone_args_t *args) /* Use PCB name as thread name. The TID will be appended to it. */ args->name = new_pcb->name; +#ifdef CONFIG_IPC_SIGNAL + /* Copy current signal mask to new threads */ + args->sig_mask = current()->sig_mask; +#endif + new_tcb = user_thread(args); /* Child thread will return in ret_from_fork and so only parent thread reachs this */ diff --git a/so3/kernel/thread.c b/so3/kernel/thread.c index 14873b6ff..3c449106b 100644 --- a/so3/kernel/thread.c +++ b/so3/kernel/thread.c @@ -386,6 +386,10 @@ tcb_t *thread_create(clone_args_t *args) tcb->state = THREAD_STATE_NEW; tcb->pcb = args->pcb; +#ifdef CONFIG_IPC_SIGNAL + tcb->sig_mask = args->sig_mask; +#endif + /* Init the thread kernel stack (svc mode) for both kernel and user thread. */ tcb->stack_slotID = get_kernel_stack_slot(); diff --git a/so3/syscall.tbl b/so3/syscall.tbl index 48e3ccf0f..b60972a7c 100644 --- a/so3/syscall.tbl +++ b/so3/syscall.tbl @@ -44,6 +44,7 @@ rt_sigaction IPC_SIGNAL rt_kill IPC_SIGNAL sigreturn IPC_SIGNAL rt_sigreturn IPC_SIGNAL +rt_sigprocmask IPC_SIGNAL getpid MMU execve MMU fork MMU From 8452e8ff015711e2979b900c6a03e92057fe8d54 Mon Sep 17 00:00:00 2001 From: Clement Dieperink Date: Wed, 3 Dec 2025 13:58:00 +0100 Subject: [PATCH 56/69] rework console to support simple cannon and raw mode --- so3/devices/console.c | 83 ++++++++++++++++-- so3/include/termios.h | 195 ++++++++++++++++++++++++++++++++++++++++++ usr/src/more.c | 39 ++++++++- 3 files changed, 310 insertions(+), 7 deletions(-) create mode 100644 so3/include/termios.h diff --git a/so3/devices/console.c b/so3/devices/console.c index 261913533..9aef2c41f 100644 --- a/so3/devices/console.c +++ b/so3/devices/console.c @@ -16,19 +16,77 @@ * */ +#include #include +/* Default termios flags that will be used by the console. */ +static termios_t termios = { + .c_iflag = INLCR, + .c_lflag = ECHO | ICANON, +}; + +static int console_write(int fd, const void *buffer, int count); + +static char console_get_next_c(void) +{ + char c = serial_getc(); + + /* Convert CR to LF if required */ + if (termios.c_iflag & INLCR) { + if (c == '\r') + c = '\n'; + } + + return c; +} + +static void icanon_handle_char(int fd, char c, char *buf, size_t *total) +{ + /* Backspace handle */ + if (c == 127) { + if (*total != 0) { + /* Delete last char from console and buffer */ + buf[*total] = '\0'; + (*total)--; + + if (termios.c_lflag & ECHO) + console_write(fd, "\b \b", 3); + } + + return; + } + + /* Generic handle */ + buf[*total] = c; + (*total)++; + + if (termios.c_lflag & ECHO) + console_write(fd, &c, 1); +} + /* Used to read from a serial (uart) console. We report only one byte when the byte is ready. */ -static int console_getc(int gfd, void *buffer, int count) +static int console_getc(int fd, void *buffer, int count) { - /* Read one byte from the UART console */ - *((uint8_t *) buffer) = serial_getc(); + char c; + char *c_buf = (char *) buffer; + size_t total = 0; - return 1; + if (termios.c_lflag & ICANON) { + do { + /* Read and handle next byte */ + c = console_get_next_c(); + icanon_handle_char(fd, c, c_buf, &total); + } while (c != '\n' && total < count); + } else { + *c_buf = console_get_next_c(); + total = 1; + } + + return total; } /* Send out to the serial console. */ -static int console_write(int gfd, const void *buffer, int count) +static int console_write(int fd, const void *buffer, int count) { int ret; @@ -43,6 +101,21 @@ static int console_ioctl(int fd, unsigned long cmd, unsigned long args) int rc; switch (cmd) { + case TCGETS: + *(struct termios *) args = termios; + rc = 0; + break; + + case TCSETS: + case TCSETSW: + case TCSETSF: + /* We should normally wait for all output to be trasmitted + and flush input depending on the IOCTL. But we will assumed + this will already by ok for now. */ + termios = *(struct termios *) args; + rc = 0; + break; + case TIOCGWINSZ: rc = serial_gwinsize((struct winsize *) args); break; diff --git a/so3/include/termios.h b/so3/include/termios.h new file mode 100644 index 000000000..6870ac377 --- /dev/null +++ b/so3/include/termios.h @@ -0,0 +1,195 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +/* Copied from Linux: + * - include/uapi/asm-generic/ioctls.h + * - include/uapi/asm-generic/termbits.h + * - include/uapi/asm-generic/termbits-common.h + */ + +#ifndef TERMIOS_H +#define TERMIOS_H + +/* clang-format off */ + +/* IOCTL for termios management */ +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 + +#define NCCS 19 + +typedef unsigned char cc_t; +typedef unsigned int speed_t; +typedef unsigned int tcflag_t; + +typedef struct termios { + tcflag_t c_iflag; + tcflag_t c_oflag; + tcflag_t c_cflag; + tcflag_t c_lflag; + cc_t c_line; + cc_t c_cc[NCCS]; + speed_t __c_ispeed; + speed_t __c_ospeed; +} termios_t; + +/* c_cc characters */ +#define VINTR 0 +#define VQUIT 1 +#define VERASE 2 +#define VKILL 3 +#define VEOF 4 +#define VTIME 5 +#define VMIN 6 +#define VSWTC 7 +#define VSTART 8 +#define VSTOP 9 +#define VSUSP 10 +#define VEOL 11 +#define VREPRINT 12 +#define VDISCARD 13 +#define VWERASE 14 +#define VLNEXT 15 +#define VEOL2 16 + +/* c_iflag bits */ +#define IGNBRK 0x001 /* Ignore break condition */ +#define BRKINT 0x002 /* Signal interrupt on break */ +#define IGNPAR 0x004 /* Ignore characters with parity errors */ +#define PARMRK 0x008 /* Mark parity and framing errors */ +#define INPCK 0x010 /* Enable input parity check */ +#define ISTRIP 0x020 /* Strip 8th bit off characters */ +#define INLCR 0x040 /* Map NL to CR on input */ +#define IGNCR 0x080 /* Ignore CR */ +#define ICRNL 0x100 /* Map CR to NL on input */ +#define IXANY 0x800 /* Any character will restart after stop */ +#define IUCLC 0x0200 +#define IXON 0x0400 +#define IXOFF 0x1000 +#define IMAXBEL 0x2000 +#define IUTF8 0x4000 + +/* c_oflag bits */ +#define OPOST 0x01 /* Perform output processing */ +#define OCRNL 0x08 +#define ONOCR 0x10 +#define ONLRET 0x20 +#define OFILL 0x40 +#define OFDEL 0x80 +#define OLCUC 0x00002 +#define ONLCR 0x00004 +#define NLDLY 0x00100 +#define NL0 0x00000 +#define NL1 0x00100 +#define CRDLY 0x00600 +#define CR0 0x00000 +#define CR1 0x00200 +#define CR2 0x00400 +#define CR3 0x00600 +#define TABDLY 0x01800 +#define TAB0 0x00000 +#define TAB1 0x00800 +#define TAB2 0x01000 +#define TAB3 0x01800 +#define XTABS 0x01800 +#define BSDLY 0x02000 +#define BS0 0x00000 +#define BS1 0x02000 +#define VTDLY 0x04000 +#define VT0 0x00000 +#define VT1 0x04000 +#define FFDLY 0x08000 +#define FF0 0x00000 +#define FF1 0x08000 + +/* c_cflag bit meaning */ +/* Common CBAUD rates */ +#define B0 0x00000000 /* hang up */ +#define B50 0x00000001 +#define B75 0x00000002 +#define B110 0x00000003 +#define B134 0x00000004 +#define B150 0x00000005 +#define B200 0x00000006 +#define B300 0x00000007 +#define B600 0x00000008 +#define B1200 0x00000009 +#define B1800 0x0000000a +#define B2400 0x0000000b +#define B4800 0x0000000c +#define B9600 0x0000000d +#define B19200 0x0000000e +#define B38400 0x0000000f +#define EXTA B19200 +#define EXTB B38400 + +#define CBAUD 0x0000100f +#define CSIZE 0x00000030 +#define CS5 0x00000000 +#define CS6 0x00000010 +#define CS7 0x00000020 +#define CS8 0x00000030 +#define CSTOPB 0x00000040 +#define CREAD 0x00000080 +#define PARENB 0x00000100 +#define PARODD 0x00000200 +#define HUPCL 0x00000400 +#define CLOCAL 0x00000800 +#define CBAUDEX 0x00001000 +#define BOTHER 0x00001000 +#define B57600 0x00001001 +#define B115200 0x00001002 +#define B230400 0x00001003 +#define B460800 0x00001004 +#define B500000 0x00001005 +#define B576000 0x00001006 +#define B921600 0x00001007 +#define B1000000 0x00001008 +#define B1152000 0x00001009 +#define B1500000 0x0000100a +#define B2000000 0x0000100b +#define B2500000 0x0000100c +#define B3000000 0x0000100d +#define B3500000 0x0000100e +#define B4000000 0x0000100f +#define CIBAUD 0x100f0000 /* input baud rate */ + +#define ADDRB 0x20000000 /* address bit */ +#define CMSPAR 0x40000000 /* mark or space (stick) parity */ +#define CRTSCTS 0x80000000 /* flow control */ + +#define IBSHIFT 16 /* Shift from CBAUD to CIBAUD */ + +/* c_lflag bits */ +#define ISIG 0x00001 +#define ICANON 0x00002 +#define XCASE 0x00004 +#define ECHO 0x00008 +#define ECHOE 0x00010 +#define ECHOK 0x00020 +#define ECHONL 0x00040 +#define NOFLSH 0x00080 +#define TOSTOP 0x00100 +#define ECHOCTL 0x00200 +#define ECHOPRT 0x00400 +#define ECHOKE 0x00800 +#define FLUSHO 0x01000 +#define PENDIN 0x04000 +#define IEXTEN 0x08000 +#define EXTPROC 0x10000 + +/* tcflow() ACTION argument and TCXONC use these */ +#define TCOOFF 0 /* Suspend output */ +#define TCOON 1 /* Restart suspended output */ +#define TCIOFF 2 /* Send a STOP character */ +#define TCION 3 /* Send a START character */ + +/* tcflush() QUEUE_SELECTOR argument and TCFLSH use these */ +#define TCIFLUSH 0 /* Discard data received but not yet read */ +#define TCOFLUSH 1 /* Discard data written but not yet sent */ +#define TCIOFLUSH 2 /* Discard all pending data */ + +/* clang-format on */ + +#endif // TERMIOS_H diff --git a/usr/src/more.c b/usr/src/more.c index e1b3e0dfe..aa42990fb 100644 --- a/usr/src/more.c +++ b/usr/src/more.c @@ -21,6 +21,8 @@ #include +#include +#include #include #include #include @@ -32,9 +34,19 @@ char buf[BUFSIZE]; struct winsize wsz; +struct termios old_term; + +/* Handler for sigint to restore console flags. */ +void sigint_handler(int sig) +{ + tcsetattr(STDERR_FILENO, TCSANOW, &old_term); + exit(0); +} int main(int argc, char **argv) { + struct termios raw_term; + struct sigaction sa = {}; int quit = 0; int fd = STDIN_FILENO, nb_bytes, line_max, columns_max; int cpt_columns = -1, cpt_line = 0; @@ -53,8 +65,20 @@ int main(int argc, char **argv) return 2; } } + + /* Save old console mode */ + tcgetattr(STDERR_FILENO, &old_term); + + /* Set SIGINT handler to restore the terminal mode correctly */ + sa.sa_handler = sigint_handler; + sigaction(SIGINT, &sa, NULL); + + /* Set console mode to raw */ + cfmakeraw(&raw_term); + tcsetattr(STDERR_FILENO, TCSANOW, &raw_term); + /* Get number of lines and columns */ - err = ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsz); + err = ioctl(STDERR_FILENO, TIOCGWINSZ, &wsz); if (err != 0) { printf("Errno: %d\n ioctl error %d\n", errno, err); return 3; @@ -97,7 +121,16 @@ int main(int argc, char **argv) printf("\n--MORE--"); fflush(stdout); - key = getc(stderr); + /* Read next char. Don't use getc as it requires + a FILE* and this will result in no actual read + on stderr. stdin isn't available as it can be + an input pipe. */ + err = read(STDERR_FILENO, &key, 1); + if (err != 1) { + quit = 1; + break; + } + if ((key == 'q') || (key == 'Q')) { quit = 1; break; @@ -113,5 +146,7 @@ int main(int argc, char **argv) } putchar('\n'); + tcsetattr(STDERR_FILENO, TCSANOW, &old_term); + return 0; } From 849a2ad1e16cda64c372a5c43ff11aef3acdf0b5 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 3 Dec 2025 15:07:46 +0100 Subject: [PATCH 57/69] [ci] new test with added musl toolchain Signed-off-by: Jean-Pierre Miceli --- docker/Dockerfile.lvperf_64b | 45 +++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/docker/Dockerfile.lvperf_64b b/docker/Dockerfile.lvperf_64b index 2db857e0e..a94a57fc7 100644 --- a/docker/Dockerfile.lvperf_64b +++ b/docker/Dockerfile.lvperf_64b @@ -1,11 +1,19 @@ -FROM alpine:latest AS baseimage +FROM ubuntu:24.04 AS baseimage FROM baseimage AS builder -RUN apk update; \ - apk add --no-cache make cmake gcc-aarch64-none-elf \ - qemu-system-aarch64 \ - bison flex libc-dev libressl-dev dtc +RUN apt update && \ + apt install -y build-essential cmake qemu-system-arm \ + bison flex libssl-dev device-tree-compiler wget && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +# Download aarch64-none-elf toolchain +RUN wget https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz +RUN tar -xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz +RUN rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz + +ENV PATH="$PATH:/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf/bin" WORKDIR /so3 @@ -29,10 +37,19 @@ RUN cd u-boot;\ FROM baseimage AS runner -RUN apk update; \ - apk add --no-cache make cmake gcc-aarch64-none-elf \ - g++-aarch64-none-elf qemu-system-aarch64 \ - util-linux dtc u-boot-tools dosfstools python3 py3-pip +RUN apt update && apt install -y --no-install-recommends \ + build-essential \ + cmake \ + qemu-system-arm \ + util-linux \ + device-tree-compiler \ + u-boot-tools \ + dosfstools \ + python3 \ + python3-pip \ + bash patch git && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* RUN pip install --break-system-packages pcpp @@ -49,10 +66,10 @@ COPY --from=builder /so3/u-boot/u-boot u-boot COPY u-boot/uEnv.d u-boot/uEnv.d -COPY toolchains /so3/toolchains -RUN toolchains/build-toolchain.sh && rm -rf toolchains/musl-cross-make -ENV PATH=$PATH:/so3/toolchains/aarch64-linux-musl/bin -ENV PATH=$PATH:/so3/toolchains/arm-linux-musleabihf/bin +COPY toolchains /toolchains +RUN /toolchains/build-toolchain.sh && rm -rf /toolchains/musl-cross-make +ENV PATH=$PATH:/toolchains/aarch64-linux-musl/bin +ENV PATH=$PATH:/toolchains/arm-linux-musleabihf/bin RUN mkdir target RUN mkdir -p usr @@ -78,4 +95,4 @@ ENV USR_BUILD_TOOLCHAIN_FILE=aarch64_none_toolchain.cmake ENV QEMU_ARCH=aarch64 ENV PLATFORM=virt64 -CMD ./install_dependencies.sh && ./docker/scripts/setup_ramfs.sh && ./docker/scripts/setup_filesystem.sh && ./docker/scripts/run.sh +#CMD ./install_dependencies.sh && ./docker/scripts/setup_ramfs.sh && ./docker/scripts/setup_filesystem.sh && ./docker/scripts/run.sh From 18afa9e46836a8b5277bec37de3cbbd7238a8d8c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 3 Dec 2025 17:52:12 +0100 Subject: [PATCH 58/69] [CI] Add new docker image to build toolchains Signed-off-by: Jean-Pierre Miceli --- .github/workflows/docker.yml | 46 +++++++++++++++++++++++++++++++++++- docker/Dockerfile.env | 24 ++----------------- docker/Dockerfile.lvperf_32b | 2 +- docker/Dockerfile.lvperf_64b | 13 +++------- docker/Dockerfile.toolchains | 25 ++++++++++++++++++++ 5 files changed, 76 insertions(+), 34 deletions(-) create mode 100644 docker/Dockerfile.toolchains diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ea0f9fb10..dce095bfe 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,15 +2,59 @@ name: Docker Image CI on: push: - branches: ["main", "216-use-musl-toolchain-in-usr"] + branches: ["main"] workflow_dispatch: env: REGISTRY: ghcr.io jobs: + build-toolchains: + runs-on: ubuntu-latest + strategy: + fail-fast: false + + permissions: + contents: read + packages: write + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + submodules: 'true' + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/smartobjectoriented/so3-toolchains + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Dockerfile.toolchains + push: true + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + annotations: ${{ steps.meta.outputs.annotations }} + cache-from: type=gha + cache-to: type=gha,mode=max + build-image: runs-on: ubuntu-latest + needs: ['build-toolchains'] strategy: fail-fast: false matrix: diff --git a/docker/Dockerfile.env b/docker/Dockerfile.env index 2fdda4b8e..18db1039e 100644 --- a/docker/Dockerfile.env +++ b/docker/Dockerfile.env @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM ghcr.io/smartobjectoriented/so3-toolchains RUN dpkg --add-architecture i386 RUN apt update @@ -13,7 +13,6 @@ RUN apt install fdisk -y RUN apt install libncurses-dev -y RUN apt install flex bison -y -RUN apt install gcc-arm-none-eabi -y RUN apt install wget unzip -y RUN apt install python3-venv -y RUN apt install ninja-build -y @@ -23,31 +22,12 @@ RUN apt install python3-pip -y RUN pip3 install pcpp -# Download aarch64-none-linux-gnu toolchain -RUN wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz -RUN tar -xvf gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz -RUN rm gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz - -ENV PATH="$PATH:/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin" - -# Download aarch64-none-elf toolchain -RUN wget https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz -RUN tar -xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz -RUN rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz - -ENV PATH="$PATH:/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf/bin" - -# Get current so3 +# Get current so3 so we can build qemu RUN wget https://github.com/smartobjectoriented/so3/archive/refs/heads/main.zip RUN unzip main.zip RUN rm main.zip RUN mv so3-* generated -# Build Musl toolchains -RUN /generated/build-toolchain.sh -ENV PATH="$PATH:/generated/aarch64-linux-musl/bin" -ENV PATH="$PATH:/generated/arm-linux-musleabihf/bin" - # Build qemu RUN cd /generated/qemu && ./fetch.sh && ./configure --target-list=arm-softmmu,aarch64-softmmu --disable-attr --disable-werror --disable-docs ENV PATH="$PATH:/generated/qemu/build" diff --git a/docker/Dockerfile.lvperf_32b b/docker/Dockerfile.lvperf_32b index 09c43637c..78de6dbd6 100644 --- a/docker/Dockerfile.lvperf_32b +++ b/docker/Dockerfile.lvperf_32b @@ -1,4 +1,4 @@ -FROM alpine:latest AS baseimage +FROM ghcr.io/smartobjectoriented/so3-toolchains:latest AS baseimage FROM baseimage AS builder diff --git a/docker/Dockerfile.lvperf_64b b/docker/Dockerfile.lvperf_64b index a94a57fc7..448759940 100644 --- a/docker/Dockerfile.lvperf_64b +++ b/docker/Dockerfile.lvperf_64b @@ -1,20 +1,13 @@ -FROM ubuntu:24.04 AS baseimage +FROM ghcr.io/smartobjectoriented/so3-toolchains:latest AS baseimage FROM baseimage AS builder RUN apt update && \ apt install -y build-essential cmake qemu-system-arm \ - bison flex libssl-dev device-tree-compiler wget && \ + bison flex libssl-dev device-tree-compiler && \ apt clean && \ rm -rf /var/lib/apt/lists/* -# Download aarch64-none-elf toolchain -RUN wget https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz -RUN tar -xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz -RUN rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz - -ENV PATH="$PATH:/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf/bin" - WORKDIR /so3 COPY u-boot u-boot @@ -91,7 +84,7 @@ RUN rm -rf /usr/share/man /usr/share/doc /usr/share/info /var/cache/apk/* # This env varialbe is read from the usr/build.sh script in order to set a custom aarch64 toolchain # This may be removed if so3 is fully migrated to the aarch64-none-elf toolchain # Right now aarch64-none-linux-gnu is still used by default -ENV USR_BUILD_TOOLCHAIN_FILE=aarch64_none_toolchain.cmake +#ENV USR_BUILD_TOOLCHAIN_FILE=aarch64_none_toolchain.cmake ENV QEMU_ARCH=aarch64 ENV PLATFORM=virt64 diff --git a/docker/Dockerfile.toolchains b/docker/Dockerfile.toolchains new file mode 100644 index 000000000..969062639 --- /dev/null +++ b/docker/Dockerfile.toolchains @@ -0,0 +1,25 @@ +# Create a Docker image which prepare the toolchains needed by SO3 env. +# +# Copyright (c) 2025 REDS Institute, HEIG-VD + +FROM ubuntu:24.04 AS toolchains-utils + +RUN apt-get update && apt-get install -y gcc-arm-none-eabi gcc-11 g++-11 git make \ + patch sudo xz-utils wget && \ + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 10 && \ + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 10 && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* + +# Download aarch64-none-elf toolchain +RUN wget https://developer.arm.com/-/media/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz +RUN tar -xvf arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz +RUN rm arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf.tar.xz + +ENV PATH="$PATH:/arm-gnu-toolchain-12.3.rel1-x86_64-aarch64-none-elf/bin" + +COPY toolchains /toolchains +RUN /toolchains/build-toolchain.sh && rm -rf /toolchains/musl-cross-make + +ENV PATH=$PATH:/toolchains/aarch64-linux-musl/bin +ENV PATH=$PATH:/toolchains/arm-linux-musleabihf/bin From 049925f78e30b46e3ecdae16e55ad2b01399c181 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 4 Dec 2025 07:58:42 +0100 Subject: [PATCH 59/69] [CI] Add tags for docker toolchains image Signed-off-by: Jean-Pierre Miceli --- .github/workflows/docker.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index dce095bfe..c798e70a4 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,9 @@ name: Docker Image CI on: push: - branches: ["main"] + paths: + - 'Dockerfile.*' + - 'toolchains/*' workflow_dispatch: env: @@ -35,11 +37,15 @@ jobs: uses: docker/metadata-action@v5 with: images: ghcr.io/smartobjectoriented/so3-toolchains + tags: | + type=raw,value=latest + type=sha - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and push + id: build_toolchains uses: docker/build-push-action@v5 with: context: . From fd9fc9246596fb939160062fdf20b41be9001332 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 4 Dec 2025 09:22:40 +0100 Subject: [PATCH 60/69] [ci] Dockerfile.env update for ubuntu 24.04 Signed-off-by: Jean-Pierre Miceli --- .github/workflows/docker.yml | 2 +- docker/Dockerfile.env | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c798e70a4..fd092f670 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,7 +3,7 @@ name: Docker Image CI on: push: paths: - - 'Dockerfile.*' + - 'docker/Dockerfile.*' - 'toolchains/*' workflow_dispatch: diff --git a/docker/Dockerfile.env b/docker/Dockerfile.env index 18db1039e..c893f9116 100644 --- a/docker/Dockerfile.env +++ b/docker/Dockerfile.env @@ -1,8 +1,11 @@ FROM ghcr.io/smartobjectoriented/so3-toolchains +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=UTC + RUN dpkg --add-architecture i386 RUN apt update -RUN apt install libc6:i386 libncurses5:i386 libstdc++6:i386 -y +RUN apt install libc6:i386 libncurses6:i386 libstdc++6:i386 -y RUN apt install lib32z1-dev -y RUN apt install zlib1g:i386 -y RUN apt install pkg-config libgtk2.0-dev bridge-utils -y From 8a656644552d2a2995997b7e3c8663041cd75fd2 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 4 Dec 2025 10:37:07 +0100 Subject: [PATCH 61/69] [CI] Add toolchains dependency for usr build Signed-off-by: Jean-Pierre Miceli --- .github/workflows/build.yml | 5 +++++ docker/Dockerfile.env | 2 +- docker/Dockerfile.lvperf_32b | 9 +++++---- docker/Dockerfile.lvperf_64b | 3 +++ docker/Dockerfile.toolchains | 4 ++++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eeba71355..fa1308a98 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,9 +6,13 @@ on: - main pull_request: branches: ["main", "144-support-musl"] + workflow_run: + workflows: ["Docker Image CI"] + types: [completed] jobs: build-so3: + if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -27,6 +31,7 @@ jobs: docker run --rm -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:main bash -c "cd so3 && make ${{ matrix.CONFIG }} && make -j`nproc`" build-usr: + if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/docker/Dockerfile.env b/docker/Dockerfile.env index c893f9116..048cdcfa3 100644 --- a/docker/Dockerfile.env +++ b/docker/Dockerfile.env @@ -23,7 +23,7 @@ RUN apt install git -y RUN apt install cmake -y RUN apt install python3-pip -y -RUN pip3 install pcpp +RUN pip install --break-system-packages pcpp # Get current so3 so we can build qemu RUN wget https://github.com/smartobjectoriented/so3/archive/refs/heads/main.zip diff --git a/docker/Dockerfile.lvperf_32b b/docker/Dockerfile.lvperf_32b index 78de6dbd6..7bb89d37b 100644 --- a/docker/Dockerfile.lvperf_32b +++ b/docker/Dockerfile.lvperf_32b @@ -2,10 +2,11 @@ FROM ghcr.io/smartobjectoriented/so3-toolchains:latest AS baseimage FROM baseimage AS builder -RUN apk update; \ - apk add --no-cache make cmake gcc-arm-none-eabi \ - g++-arm-none-eabi qemu-system-arm \ - bison flex libc-dev libressl-dev dtc +RUN apt update && \ + apt install -y build-essential cmake qemu-system-arm gcc-arm-none-eabi \ + bison flex libssl-dev device-tree-compiler qemu-system-arm g++-arm-none-eabi && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* WORKDIR /so3 diff --git a/docker/Dockerfile.lvperf_64b b/docker/Dockerfile.lvperf_64b index 448759940..5cb9cbc78 100644 --- a/docker/Dockerfile.lvperf_64b +++ b/docker/Dockerfile.lvperf_64b @@ -1,5 +1,8 @@ FROM ghcr.io/smartobjectoriented/so3-toolchains:latest AS baseimage +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=UTC + FROM baseimage AS builder RUN apt update && \ diff --git a/docker/Dockerfile.toolchains b/docker/Dockerfile.toolchains index 969062639..4c048f0ca 100644 --- a/docker/Dockerfile.toolchains +++ b/docker/Dockerfile.toolchains @@ -1,6 +1,10 @@ # Create a Docker image which prepare the toolchains needed by SO3 env. # # Copyright (c) 2025 REDS Institute, HEIG-VD +# +# Set 'aarch64-none-elf' toolchain & build arm & aarch64 musl toolchains +# +# Note: 'arm-none-eabi-' is installed for package manager in the others docker images FROM ubuntu:24.04 AS toolchains-utils From aea9df9fa182c95eef4a6a1fa0c61eaffc4ffd77 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 4 Dec 2025 10:58:07 +0100 Subject: [PATCH 62/69] [CI] Fix issue with lvgl 32 docker image Signed-off-by: Jean-Pierre Miceli --- .github/workflows/build.yml | 5 ----- docker/Dockerfile.lvperf_32b | 10 ++++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa1308a98..eeba71355 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,13 +6,9 @@ on: - main pull_request: branches: ["main", "144-support-musl"] - workflow_run: - workflows: ["Docker Image CI"] - types: [completed] jobs: build-so3: - if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -31,7 +27,6 @@ jobs: docker run --rm -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:main bash -c "cd so3 && make ${{ matrix.CONFIG }} && make -j`nproc`" build-usr: - if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest strategy: fail-fast: false diff --git a/docker/Dockerfile.lvperf_32b b/docker/Dockerfile.lvperf_32b index 7bb89d37b..05c69b953 100644 --- a/docker/Dockerfile.lvperf_32b +++ b/docker/Dockerfile.lvperf_32b @@ -30,10 +30,12 @@ RUN cd u-boot;\ FROM baseimage AS runner -RUN apk update; \ - apk add --no-cache make cmake gcc-arm-none-eabi \ - g++-arm-none-eabi qemu-system-arm \ - util-linux dtc u-boot-tools dosfstools python3 py3-pip +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt install -y \ + make cmake gcc-arm-none-eabi g++-arm-none-eabi qemu-system-arm \ + util-linux device-tree-compiler u-boot-tools dosfstools python3 \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* RUN pip install --break-system-packages pcpp From 51474f86a24ceb0eb3587daeca2f3ef99c6b8f02 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 4 Dec 2025 14:35:14 +0100 Subject: [PATCH 63/69] [CI] Fix bug in lvgl 32b docker image Signed-off-by: Jean-Pierre Miceli --- docker/Dockerfile.lvperf_32b | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.lvperf_32b b/docker/Dockerfile.lvperf_32b index 05c69b953..72a674e4a 100644 --- a/docker/Dockerfile.lvperf_32b +++ b/docker/Dockerfile.lvperf_32b @@ -30,12 +30,12 @@ RUN cd u-boot;\ FROM baseimage AS runner -RUN apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt install -y \ - make cmake gcc-arm-none-eabi g++-arm-none-eabi qemu-system-arm \ +RUN apt-get update && \ + apt install -y make cmake gcc-arm-none-eabi qemu-system-arm \ util-linux device-tree-compiler u-boot-tools dosfstools python3 \ - python3-pip \ - && rm -rf /var/lib/apt/lists/* + python3-pip && \ + apt clean && \ + rm -rf /var/lib/apt/lists/* RUN pip install --break-system-packages pcpp From 02e00a01bd6b9e59ad8e8d4ad77c0bd26f281613 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Thu, 4 Dec 2025 16:22:51 +0100 Subject: [PATCH 64/69] [CI] Fix bug in lvgl 32b docker image (again) Signed-off-by: Jean-Pierre Miceli --- docker/Dockerfile.lvperf_32b | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile.lvperf_32b b/docker/Dockerfile.lvperf_32b index 72a674e4a..0cbccf523 100644 --- a/docker/Dockerfile.lvperf_32b +++ b/docker/Dockerfile.lvperf_32b @@ -4,7 +4,7 @@ FROM baseimage AS builder RUN apt update && \ apt install -y build-essential cmake qemu-system-arm gcc-arm-none-eabi \ - bison flex libssl-dev device-tree-compiler qemu-system-arm g++-arm-none-eabi && \ + bison flex libssl-dev device-tree-compiler qemu-system-arm && \ apt clean && \ rm -rf /var/lib/apt/lists/* From 95527d8a870a9ffe7ddb6969c4570c5ef6ee18d6 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Fri, 5 Dec 2025 07:54:41 +0100 Subject: [PATCH 65/69] [ci] Some fixes * Add tag for docker images * Remove build of musl toolchains in lvgl 64b * Use the new docker images for build workflows Signed-off-by: Jean-Pierre Miceli --- .github/workflows/build.yml | 4 ++-- .github/workflows/docker.yml | 3 ++- docker/Dockerfile.lvperf_64b | 5 ----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eeba71355..6a1df906a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: - name: Build run: | - docker run --rm -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:main bash -c "cd so3 && make ${{ matrix.CONFIG }} && make -j`nproc`" + docker run --rm -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:latest bash -c "cd so3 && make ${{ matrix.CONFIG }} && make -j`nproc`" build-usr: runs-on: ubuntu-latest @@ -42,4 +42,4 @@ jobs: - name: Build run: | - docker run --rm -t -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:main bash -c "mkdir usr/build && cd usr/build && cmake --no-warn-unused-cli -DCMAKE_C_FLAGS='-Werror' -Wno-dev -DCMAKE_BUILD_TYPE=${{ matrix.BUILD_TYPE }} -DCMAKE_TOOLCHAIN_FILE=../${{matrix.CMAKE_TOOLCHAIN_FILE }} .. && make -j`nproc`" + docker run --rm -t -v "${PWD}:/so3" ghcr.io/smartobjectoriented/so3-env:latest bash -c "mkdir usr/build && cd usr/build && cmake --no-warn-unused-cli -DCMAKE_C_FLAGS='-Werror' -Wno-dev -DCMAKE_BUILD_TYPE=${{ matrix.BUILD_TYPE }} -DCMAKE_TOOLCHAIN_FILE=../${{matrix.CMAKE_TOOLCHAIN_FILE }} .. && make -j`nproc`" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index fd092f670..df3e74333 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -39,7 +39,6 @@ jobs: images: ghcr.io/smartobjectoriented/so3-toolchains tags: | type=raw,value=latest - type=sha - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -97,6 +96,8 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ matrix.image }} + tags: | + type=raw,value=latest - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/docker/Dockerfile.lvperf_64b b/docker/Dockerfile.lvperf_64b index 5cb9cbc78..c8038f429 100644 --- a/docker/Dockerfile.lvperf_64b +++ b/docker/Dockerfile.lvperf_64b @@ -62,11 +62,6 @@ COPY --from=builder /so3/u-boot/u-boot u-boot COPY u-boot/uEnv.d u-boot/uEnv.d -COPY toolchains /toolchains -RUN /toolchains/build-toolchain.sh && rm -rf /toolchains/musl-cross-make -ENV PATH=$PATH:/toolchains/aarch64-linux-musl/bin -ENV PATH=$PATH:/toolchains/arm-linux-musleabihf/bin - RUN mkdir target RUN mkdir -p usr RUN mkdir -p docker/scripts From 3543a93c07707a965e3a76eb3fb731e797630545 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Fri, 5 Dec 2025 14:37:29 +0100 Subject: [PATCH 66/69] Add missing header file Signed-off-by: Jean-Pierre Miceli --- usr/lib/slv/slv_keyboard.c | 1 + usr/lib/slv/slv_mouse.c | 1 + 2 files changed, 2 insertions(+) diff --git a/usr/lib/slv/slv_keyboard.c b/usr/lib/slv/slv_keyboard.c index 6cfe5ee61..d80326338 100644 --- a/usr/lib/slv/slv_keyboard.c +++ b/usr/lib/slv/slv_keyboard.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "slv_keyboard.h" diff --git a/usr/lib/slv/slv_mouse.c b/usr/lib/slv/slv_mouse.c index 6f37e1047..51e7f08e0 100644 --- a/usr/lib/slv/slv_mouse.c +++ b/usr/lib/slv/slv_mouse.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "slv_mouse.h" From 1e626b2ac58e660d2b80870238970dd4d51daec8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 10 Dec 2025 08:57:58 +0100 Subject: [PATCH 67/69] [musl] remove the original so3 libc src Signed-off-by: Jean-Pierre Miceli --- usr/CMakeLists.txt | 4 - usr/lib/libc/CMakeLists.txt | 43 -- usr/lib/libc/aarch64.lds | 54 -- usr/lib/libc/arm.lds | 54 -- usr/lib/libc/crt0.S | 180 ----- usr/lib/libc/crt1.c | 101 --- usr/lib/libc/ctype/CMakeLists.txt | 6 - usr/lib/libc/ctype/__ctype_b_loc.c | 41 -- usr/lib/libc/ctype/__ctype_get_mb_cur_max.c | 7 - usr/lib/libc/ctype/__ctype_tolower_loc.c | 30 - usr/lib/libc/ctype/__ctype_toupper_loc.c | 30 - usr/lib/libc/ctype/alpha.h | 125 ---- usr/lib/libc/ctype/isalnum.c | 14 - usr/lib/libc/ctype/isalpha.c | 15 - usr/lib/libc/ctype/isascii.c | 7 - usr/lib/libc/ctype/isblank.c | 14 - usr/lib/libc/ctype/iscntrl.c | 14 - usr/lib/libc/ctype/isdigit.c | 15 - usr/lib/libc/ctype/isgraph.c | 15 - usr/lib/libc/ctype/islower.c | 15 - usr/lib/libc/ctype/isprint.c | 15 - usr/lib/libc/ctype/ispunct.c | 14 - usr/lib/libc/ctype/isspace.c | 15 - usr/lib/libc/ctype/isupper.c | 15 - usr/lib/libc/ctype/iswalnum.c | 14 - usr/lib/libc/ctype/iswalpha.c | 22 - usr/lib/libc/ctype/iswblank.c | 15 - usr/lib/libc/ctype/iswcntrl.c | 17 - usr/lib/libc/ctype/iswctype.c | 76 -- usr/lib/libc/ctype/iswdigit.c | 16 - usr/lib/libc/ctype/iswgraph.c | 15 - usr/lib/libc/ctype/iswlower.c | 14 - usr/lib/libc/ctype/iswprint.c | 27 - usr/lib/libc/ctype/iswpunct.c | 20 - usr/lib/libc/ctype/iswspace.c | 25 - usr/lib/libc/ctype/iswupper.c | 14 - usr/lib/libc/ctype/iswxdigit.c | 14 - usr/lib/libc/ctype/isxdigit.c | 14 - usr/lib/libc/ctype/nonspacing.h | 62 -- usr/lib/libc/ctype/punct.h | 109 --- usr/lib/libc/ctype/toascii.c | 7 - usr/lib/libc/ctype/tolower.c | 15 - usr/lib/libc/ctype/toupper.c | 15 - usr/lib/libc/ctype/towctrans.c | 279 ------- usr/lib/libc/ctype/wcswidth.c | 8 - usr/lib/libc/ctype/wctrans.c | 30 - usr/lib/libc/ctype/wcwidth.c | 29 - usr/lib/libc/ctype/wide.h | 42 -- usr/lib/libc/dirent/CMakeLists.txt | 7 - usr/lib/libc/dirent/__dirent.h | 9 - usr/lib/libc/dirent/__getdents.c | 12 - usr/lib/libc/dirent/alphasort.c | 10 - usr/lib/libc/dirent/closedir.c | 11 - usr/lib/libc/dirent/dirfd.c | 7 - usr/lib/libc/dirent/fdopendir.c | 27 - usr/lib/libc/dirent/opendir.c | 27 - usr/lib/libc/dirent/readdir.c | 34 - usr/lib/libc/dirent/readdir_r.c | 29 - usr/lib/libc/dirent/rewinddir.c | 13 - usr/lib/libc/dirent/scandir.c | 48 -- usr/lib/libc/dirent/seekdir.c | 12 - usr/lib/libc/dirent/telldir.c | 7 - usr/lib/libc/dirent/versionsort.c | 12 - usr/lib/libc/eabi_compat.c | 38 - usr/lib/libc/env/CMakeLists.txt | 11 - usr/lib/libc/env/__environ.c | 6 - usr/lib/libc/env/__init_tls.c | 136 ---- usr/lib/libc/env/__libc_start_main.c | 84 --- usr/lib/libc/env/__reset_tls.c | 16 - usr/lib/libc/env/__stack_chk_fail.c | 23 - usr/lib/libc/env/clearenv.c | 10 - usr/lib/libc/env/getenv.c | 14 - usr/lib/libc/env/putenv.c | 61 -- usr/lib/libc/env/setenv.c | 30 - usr/lib/libc/env/unsetenv.c | 31 - usr/lib/libc/errno/CMakeLists.txt | 6 - usr/lib/libc/errno/__errno_location.c | 6 - usr/lib/libc/errno/__strerror.h | 104 --- usr/lib/libc/errno/strerror.c | 47 -- usr/lib/libc/exit/CMakeLists.txt | 8 - usr/lib/libc/exit/_Exit.c | 12 - usr/lib/libc/exit/abort.c | 23 - usr/lib/libc/exit/assert.c | 9 - usr/lib/libc/exit/at_quick_exit.c | 29 - usr/lib/libc/exit/atexit.c | 71 -- usr/lib/libc/exit/exit.c | 34 - usr/lib/libc/exit/quick_exit.c | 11 - usr/lib/libc/fcntl/CMakeLists.txt | 5 - usr/lib/libc/fcntl/creat.c | 9 - usr/lib/libc/fcntl/fcntl.c | 49 -- usr/lib/libc/fcntl/open.c | 27 - usr/lib/libc/fcntl/openat.c | 20 - usr/lib/libc/fcntl/posix_fadvise.c | 19 - usr/lib/libc/fcntl/posix_fallocate.c | 11 - usr/lib/libc/floatscan.c | 510 ------------- usr/lib/libc/include/alloca.h | 21 - usr/lib/libc/include/arpa/ftp.h | 35 - usr/lib/libc/include/arpa/inet.h | 36 - usr/lib/libc/include/arpa/nameser.h | 455 ------------ usr/lib/libc/include/arpa/nameser_compat.h | 2 - usr/lib/libc/include/arpa/telnet.h | 251 ------- usr/lib/libc/include/arpa/tftp.h | 31 - .../libc/include/asm-aarch32/atomic_arch.h | 107 --- .../include/asm-aarch32/bits/alltypes.h.in | 21 - usr/lib/libc/include/asm-aarch32/bits/fcntl.h | 40 - usr/lib/libc/include/asm-aarch32/bits/fenv.h | 23 - usr/lib/libc/include/asm-aarch32/bits/float.h | 16 - usr/lib/libc/include/asm-aarch32/bits/hwcap.h | 53 -- .../libc/include/asm-aarch32/bits/ioctl_fix.h | 2 - .../libc/include/asm-aarch32/bits/ipcstat.h | 1 - usr/lib/libc/include/asm-aarch32/bits/msg.h | 18 - usr/lib/libc/include/asm-aarch32/bits/posix.h | 2 - .../libc/include/asm-aarch32/bits/ptrace.h | 25 - usr/lib/libc/include/asm-aarch32/bits/reg.h | 3 - usr/lib/libc/include/asm-aarch32/bits/sem.h | 18 - .../libc/include/asm-aarch32/bits/setjmp.h | 1 - usr/lib/libc/include/asm-aarch32/bits/shm.h | 31 - .../libc/include/asm-aarch32/bits/signal.h | 86 --- usr/lib/libc/include/asm-aarch32/bits/stat.h | 25 - .../libc/include/asm-aarch32/bits/stdint.h | 20 - .../include/asm-aarch32/bits/syscall.h.in | 409 ---------- usr/lib/libc/include/asm-aarch32/bits/user.h | 36 - usr/lib/libc/include/asm-aarch32/crt_arch.h | 18 - usr/lib/libc/include/asm-aarch32/kstat.h | 21 - .../libc/include/asm-aarch32/pthread_arch.h | 32 - usr/lib/libc/include/asm-aarch32/reloc.h | 32 - usr/lib/libc/include/asm-aarch32/socket.h | 43 -- usr/lib/libc/include/asm-aarch32/sockios.h | 11 - .../libc/include/asm-aarch32/syscall_arch.h | 103 --- .../libc/include/asm-aarch64/atomic_arch.h | 82 --- .../include/asm-aarch64/bits/alltypes.h.in | 24 - usr/lib/libc/include/asm-aarch64/bits/fcntl.h | 38 - usr/lib/libc/include/asm-aarch64/bits/fenv.h | 19 - usr/lib/libc/include/asm-aarch64/bits/float.h | 16 - usr/lib/libc/include/asm-aarch64/bits/hwcap.h | 52 -- .../libc/include/asm-aarch64/bits/ioctl_fix.h | 2 - .../libc/include/asm-aarch64/bits/ipcstat.h | 1 - usr/lib/libc/include/asm-aarch64/bits/mman.h | 2 - usr/lib/libc/include/asm-aarch64/bits/msg.h | 18 - usr/lib/libc/include/asm-aarch64/bits/posix.h | 2 - .../libc/include/asm-aarch64/bits/ptrace.h | 25 - usr/lib/libc/include/asm-aarch64/bits/reg.h | 2 - usr/lib/libc/include/asm-aarch64/bits/sem.h | 18 - .../libc/include/asm-aarch64/bits/setjmp.h | 1 - usr/lib/libc/include/asm-aarch64/bits/shm.h | 31 - .../libc/include/asm-aarch64/bits/signal.h | 153 ---- usr/lib/libc/include/asm-aarch64/bits/stat.h | 18 - .../libc/include/asm-aarch64/bits/stdint.h | 20 - .../include/asm-aarch64/bits/syscall.h.in | 302 -------- usr/lib/libc/include/asm-aarch64/bits/user.h | 16 - usr/lib/libc/include/asm-aarch64/crt_arch.h | 15 - usr/lib/libc/include/asm-aarch64/fp_arch.h | 25 - usr/lib/libc/include/asm-aarch64/kstat.h | 21 - .../libc/include/asm-aarch64/pthread_arch.h | 11 - usr/lib/libc/include/asm-aarch64/reloc.h | 24 - usr/lib/libc/include/asm-aarch64/socket.h | 43 -- usr/lib/libc/include/asm-aarch64/sockios.h | 11 - .../libc/include/asm-aarch64/syscall_arch.h | 78 -- usr/lib/libc/include/assert.h | 23 - usr/lib/libc/include/atomic.h | 293 -------- usr/lib/libc/include/bits/alltypes.h | 81 -- usr/lib/libc/include/bits/byteswap.h | 26 - usr/lib/libc/include/bits/endian.h | 5 - usr/lib/libc/include/bits/fcntl.h | 40 - usr/lib/libc/include/bits/fenv.h | 23 - usr/lib/libc/include/bits/float.h | 16 - usr/lib/libc/include/bits/hwcap.h | 29 - usr/lib/libc/include/bits/ioctl.h | 210 ------ usr/lib/libc/include/bits/ioctl_fix.h | 2 - usr/lib/libc/include/bits/limits.h | 7 - usr/lib/libc/include/bits/mman.h | 1 - usr/lib/libc/include/bits/posix.h | 2 - usr/lib/libc/include/bits/reg.h | 3 - usr/lib/libc/include/bits/setjmp.h | 1 - usr/lib/libc/include/bits/signal.h | 86 --- usr/lib/libc/include/bits/sockaddr.h | 42 -- usr/lib/libc/include/bits/socket.h | 404 ---------- usr/lib/libc/include/bits/socket_type.h | 55 -- usr/lib/libc/include/bits/stat.h | 32 - usr/lib/libc/include/bits/stdint.h | 20 - usr/lib/libc/include/bits/syscall.h.in | 359 --------- usr/lib/libc/include/bits/user.h | 36 - usr/lib/libc/include/byteswap.h | 27 - usr/lib/libc/include/complex.h | 133 ---- usr/lib/libc/include/ctype.h | 75 -- usr/lib/libc/include/dirent.h | 81 -- usr/lib/libc/include/dlfcn.h | 46 -- usr/lib/libc/include/endian.h | 82 --- usr/lib/libc/include/errno.h | 153 ---- usr/lib/libc/include/fcntl.h | 188 ----- usr/lib/libc/include/fdop.h | 10 - usr/lib/libc/include/features.h | 38 - usr/lib/libc/include/floatscan.h | 8 - usr/lib/libc/include/iconv.h | 24 - usr/lib/libc/include/inet.h | 8 - usr/lib/libc/include/intscan.h | 8 - usr/lib/libc/include/inttypes.h | 229 ------ usr/lib/libc/include/ksigaction.h | 11 - usr/lib/libc/include/langinfo.h | 113 --- usr/lib/libc/include/libc.h | 77 -- usr/lib/libc/include/libm.h | 184 ----- usr/lib/libc/include/limits.h | 154 ---- usr/lib/libc/include/locale.h | 11 - usr/lib/libc/include/locale_impl.h | 43 -- usr/lib/libc/include/malloc.h | 16 - usr/lib/libc/include/math.h | 430 ----------- usr/lib/libc/include/mman.h | 1 - usr/lib/libc/include/mutex.h | 10 - usr/lib/libc/include/net/ethernet.h | 55 -- usr/lib/libc/include/net/if.h | 141 ---- usr/lib/libc/include/net/if_arp.h | 142 ---- usr/lib/libc/include/net/route.h | 124 ---- usr/lib/libc/include/netdb.h | 155 ---- usr/lib/libc/include/netinet/ether.h | 22 - usr/lib/libc/include/netinet/icmp6.h | 305 -------- usr/lib/libc/include/netinet/if_ether.h | 147 ---- usr/lib/libc/include/netinet/igmp.h | 45 -- usr/lib/libc/include/netinet/in.h | 415 ----------- usr/lib/libc/include/netinet/in_systm.h | 9 - usr/lib/libc/include/netinet/ip.h | 199 ----- usr/lib/libc/include/netinet/ip6.h | 141 ---- usr/lib/libc/include/netinet/ip_icmp.h | 193 ----- usr/lib/libc/include/netinet/tcp.h | 282 ------- usr/lib/libc/include/netinet/udp.h | 45 -- usr/lib/libc/include/pthread.h | 47 -- usr/lib/libc/include/pthread_impl.h | 156 ---- usr/lib/libc/include/shgetc.h | 9 - usr/lib/libc/include/signal.h | 276 ------- usr/lib/libc/include/stdarg.h | 21 - usr/lib/libc/include/stddef.h | 25 - usr/lib/libc/include/stdint.h | 117 --- usr/lib/libc/include/stdio.h | 203 ----- usr/lib/libc/include/stdio_impl.h | 105 --- usr/lib/libc/include/stdlib.h | 164 ----- usr/lib/libc/include/string.h | 106 --- usr/lib/libc/include/strings.h | 39 - usr/lib/libc/include/sys/acct.h | 73 -- usr/lib/libc/include/sys/auxv.h | 17 - usr/lib/libc/include/sys/cachectl.h | 22 - usr/lib/libc/include/sys/dir.h | 2 - usr/lib/libc/include/sys/epoll.h | 68 -- usr/lib/libc/include/sys/errno.h | 2 - usr/lib/libc/include/sys/eventfd.h | 26 - usr/lib/libc/include/sys/fanotify.h | 73 -- usr/lib/libc/include/sys/fcntl.h | 2 - usr/lib/libc/include/sys/file.h | 21 - usr/lib/libc/include/sys/fsuid.h | 20 - usr/lib/libc/include/sys/inotify.h | 57 -- usr/lib/libc/include/sys/io.h | 17 - usr/lib/libc/include/sys/ioctl.h | 16 - usr/lib/libc/include/sys/ipc.h | 42 -- usr/lib/libc/include/sys/kd.h | 8 - usr/lib/libc/include/sys/klog.h | 14 - usr/lib/libc/include/sys/mman.h | 118 --- usr/lib/libc/include/sys/mount.h | 74 -- usr/lib/libc/include/sys/msg.h | 52 -- usr/lib/libc/include/sys/mtio.h | 188 ----- usr/lib/libc/include/sys/param.h | 35 - usr/lib/libc/include/sys/personality.h | 46 -- usr/lib/libc/include/sys/poll.h | 2 - usr/lib/libc/include/sys/prctl.h | 139 ---- usr/lib/libc/include/sys/procfs.h | 64 -- usr/lib/libc/include/sys/ptrace.h | 195 ----- usr/lib/libc/include/sys/quota.h | 102 --- usr/lib/libc/include/sys/reboot.h | 20 - usr/lib/libc/include/sys/reg.h | 9 - usr/lib/libc/include/sys/resource.h | 112 --- usr/lib/libc/include/sys/select.h | 41 -- usr/lib/libc/include/sys/sem.h | 67 -- usr/lib/libc/include/sys/sendfile.h | 22 - usr/lib/libc/include/sys/shm.h | 54 -- usr/lib/libc/include/sys/signal.h | 2 - usr/lib/libc/include/sys/signalfd.h | 45 -- usr/lib/libc/include/sys/socket.h | 204 ----- usr/lib/libc/include/sys/soundcard.h | 1 - usr/lib/libc/include/sys/stat.h | 137 ---- usr/lib/libc/include/sys/statfs.h | 32 - usr/lib/libc/include/sys/statvfs.h | 57 -- usr/lib/libc/include/sys/stropts.h | 1 - usr/lib/libc/include/sys/swap.h | 21 - usr/lib/libc/include/sys/syscall.h | 6 - usr/lib/libc/include/sys/sysinfo.h | 36 - usr/lib/libc/include/sys/syslog.h | 1 - usr/lib/libc/include/sys/sysmacros.h | 15 - usr/lib/libc/include/sys/termios.h | 2 - usr/lib/libc/include/sys/time.h | 62 -- usr/lib/libc/include/sys/timeb.h | 22 - usr/lib/libc/include/sys/timerfd.h | 26 - usr/lib/libc/include/sys/times.h | 25 - usr/lib/libc/include/sys/timex.h | 98 --- usr/lib/libc/include/sys/ttydefaults.h | 39 - usr/lib/libc/include/sys/types.h | 86 --- usr/lib/libc/include/sys/ucontext.h | 1 - usr/lib/libc/include/sys/uio.h | 48 -- usr/lib/libc/include/sys/un.h | 31 - usr/lib/libc/include/sys/user.h | 16 - usr/lib/libc/include/sys/utsname.h | 29 - usr/lib/libc/include/sys/vfs.h | 1 - usr/lib/libc/include/sys/vt.h | 1 - usr/lib/libc/include/sys/wait.h | 64 -- usr/lib/libc/include/sys/xattr.h | 30 - usr/lib/libc/include/syscall.h | 589 --------------- usr/lib/libc/include/time.h | 138 ---- usr/lib/libc/include/types.h | 29 - usr/lib/libc/include/unistd.h | 478 ------------ usr/lib/libc/include/wchar.h | 201 ----- usr/lib/libc/include/wctype.h | 79 -- usr/lib/libc/inet.c | 43 -- usr/lib/libc/intscan.c | 100 --- usr/lib/libc/libc.c | 3 - usr/lib/libc/longjmp.S | 80 -- usr/lib/libc/malloc.c | 543 -------------- usr/lib/libc/malloc/CMakeLists.txt | 5 - usr/lib/libc/malloc/DESIGN | 22 - usr/lib/libc/malloc/__brk.c | 7 - usr/lib/libc/malloc/aligned_alloc.c | 8 - usr/lib/libc/malloc/calloc.c | 33 - usr/lib/libc/malloc/expand_heap.c | 72 -- usr/lib/libc/malloc/lite_malloc.c | 50 -- usr/lib/libc/malloc/malloc.c | 532 ------------- usr/lib/libc/malloc/malloc_usable_size.c | 17 - usr/lib/libc/malloc/memalign.c | 57 -- usr/lib/libc/malloc/posix_memalign.c | 13 - usr/lib/libc/math/CMakeLists.txt | 24 - usr/lib/libc/math/__cos.c | 71 -- usr/lib/libc/math/__cosdf.c | 35 - usr/lib/libc/math/__cosl.c | 96 --- usr/lib/libc/math/__expo2.c | 16 - usr/lib/libc/math/__expo2f.c | 16 - usr/lib/libc/math/__fpclassify.c | 11 - usr/lib/libc/math/__fpclassifyf.c | 11 - usr/lib/libc/math/__fpclassifyl.c | 34 - usr/lib/libc/math/__invtrigl.c | 63 -- usr/lib/libc/math/__invtrigl.h | 6 - usr/lib/libc/math/__polevll.c | 93 --- usr/lib/libc/math/__rem_pio2.c | 177 ----- usr/lib/libc/math/__rem_pio2_large.c | 442 ----------- usr/lib/libc/math/__rem_pio2f.c | 75 -- usr/lib/libc/math/__rem_pio2l.c | 141 ---- usr/lib/libc/math/__signbit.c | 13 - usr/lib/libc/math/__signbitf.c | 11 - usr/lib/libc/math/__signbitl.c | 14 - usr/lib/libc/math/__sin.c | 64 -- usr/lib/libc/math/__sindf.c | 36 - usr/lib/libc/math/__sinl.c | 78 -- usr/lib/libc/math/__tan.c | 110 --- usr/lib/libc/math/__tandf.c | 54 -- usr/lib/libc/math/__tanl.c | 143 ---- usr/lib/libc/math/acos.c | 101 --- usr/lib/libc/math/acosf.c | 71 -- usr/lib/libc/math/acosh.c | 24 - usr/lib/libc/math/acoshf.c | 26 - usr/lib/libc/math/acoshl.c | 29 - usr/lib/libc/math/acosl.c | 67 -- usr/lib/libc/math/asin.c | 107 --- usr/lib/libc/math/asinf.c | 61 -- usr/lib/libc/math/asinh.c | 28 - usr/lib/libc/math/asinhf.c | 28 - usr/lib/libc/math/asinhl.c | 41 -- usr/lib/libc/math/asinl.c | 71 -- usr/lib/libc/math/atan.c | 116 --- usr/lib/libc/math/atan2.c | 107 --- usr/lib/libc/math/atan2f.c | 83 --- usr/lib/libc/math/atan2l.c | 85 --- usr/lib/libc/math/atanf.c | 94 --- usr/lib/libc/math/atanh.c | 29 - usr/lib/libc/math/atanhf.c | 28 - usr/lib/libc/math/atanhl.c | 35 - usr/lib/libc/math/atanl.c | 184 ----- usr/lib/libc/math/cbrt.c | 103 --- usr/lib/libc/math/cbrtf.c | 66 -- usr/lib/libc/math/cbrtl.c | 124 ---- usr/lib/libc/math/ceil.c | 31 - usr/lib/libc/math/ceilf.c | 27 - usr/lib/libc/math/ceill.c | 34 - usr/lib/libc/math/copysign.c | 8 - usr/lib/libc/math/copysignf.c | 10 - usr/lib/libc/math/copysignl.c | 16 - usr/lib/libc/math/cos.c | 77 -- usr/lib/libc/math/cosf.c | 78 -- usr/lib/libc/math/cosh.c | 40 - usr/lib/libc/math/coshf.c | 33 - usr/lib/libc/math/coshl.c | 47 -- usr/lib/libc/math/cosl.c | 39 - usr/lib/libc/math/erf.c | 273 ------- usr/lib/libc/math/erff.c | 183 ----- usr/lib/libc/math/erfl.c | 353 --------- usr/lib/libc/math/exp.c | 134 ---- usr/lib/libc/math/exp10.c | 25 - usr/lib/libc/math/exp10f.c | 23 - usr/lib/libc/math/exp10l.c | 33 - usr/lib/libc/math/exp2.c | 375 ---------- usr/lib/libc/math/exp2f.c | 126 ---- usr/lib/libc/math/exp2l.c | 619 ---------------- usr/lib/libc/math/expf.c | 83 --- usr/lib/libc/math/expl.c | 128 ---- usr/lib/libc/math/expm1.c | 201 ----- usr/lib/libc/math/expm1f.c | 111 --- usr/lib/libc/math/expm1l.c | 123 ---- usr/lib/libc/math/fabs.c | 9 - usr/lib/libc/math/fabsf.c | 9 - usr/lib/libc/math/fabsl.c | 15 - usr/lib/libc/math/fdim.c | 10 - usr/lib/libc/math/fdimf.c | 10 - usr/lib/libc/math/fdiml.c | 18 - usr/lib/libc/math/finite.c | 7 - usr/lib/libc/math/finitef.c | 7 - usr/lib/libc/math/floor.c | 33 - usr/lib/libc/math/floorf.c | 27 - usr/lib/libc/math/floorl.c | 34 - usr/lib/libc/math/fma.c | 460 ------------ usr/lib/libc/math/fmaf.c | 93 --- usr/lib/libc/math/fmal.c | 293 -------- usr/lib/libc/math/fmax.c | 13 - usr/lib/libc/math/fmaxf.c | 13 - usr/lib/libc/math/fmaxl.c | 21 - usr/lib/libc/math/fmin.c | 13 - usr/lib/libc/math/fminf.c | 13 - usr/lib/libc/math/fminl.c | 21 - usr/lib/libc/math/fmod.c | 68 -- usr/lib/libc/math/fmodf.c | 65 -- usr/lib/libc/math/fmodl.c | 105 --- usr/lib/libc/math/frexp.c | 23 - usr/lib/libc/math/frexpf.c | 23 - usr/lib/libc/math/frexpl.c | 29 - usr/lib/libc/math/hypot.c | 67 -- usr/lib/libc/math/hypotf.c | 35 - usr/lib/libc/math/hypotl.c | 66 -- usr/lib/libc/math/ilogb.c | 26 - usr/lib/libc/math/ilogbf.c | 26 - usr/lib/libc/math/ilogbl.c | 55 -- usr/lib/libc/math/j0.c | 375 ---------- usr/lib/libc/math/j0f.c | 314 -------- usr/lib/libc/math/j1.c | 362 --------- usr/lib/libc/math/j1f.c | 310 -------- usr/lib/libc/math/jn.c | 280 ------- usr/lib/libc/math/jnf.c | 202 ----- usr/lib/libc/math/ldexp.c | 6 - usr/lib/libc/math/ldexpf.c | 6 - usr/lib/libc/math/ldexpl.c | 6 - usr/lib/libc/math/lgamma.c | 9 - usr/lib/libc/math/lgamma_r.c | 284 ------- usr/lib/libc/math/lgammaf.c | 9 - usr/lib/libc/math/lgammaf_r.c | 219 ------ usr/lib/libc/math/lgammal.c | 360 --------- usr/lib/libc/math/llrint.c | 8 - usr/lib/libc/math/llrintf.c | 8 - usr/lib/libc/math/llrintl.c | 36 - usr/lib/libc/math/llround.c | 6 - usr/lib/libc/math/llroundf.c | 6 - usr/lib/libc/math/llroundl.c | 6 - usr/lib/libc/math/log.c | 118 --- usr/lib/libc/math/log10.c | 101 --- usr/lib/libc/math/log10f.c | 77 -- usr/lib/libc/math/log10l.c | 191 ----- usr/lib/libc/math/log1p.c | 122 --- usr/lib/libc/math/log1pf.c | 77 -- usr/lib/libc/math/log1pl.c | 177 ----- usr/lib/libc/math/log2.c | 122 --- usr/lib/libc/math/log2f.c | 74 -- usr/lib/libc/math/log2l.c | 182 ----- usr/lib/libc/math/logb.c | 17 - usr/lib/libc/math/logbf.c | 10 - usr/lib/libc/math/logbl.c | 16 - usr/lib/libc/math/logf.c | 69 -- usr/lib/libc/math/logl.c | 175 ----- usr/lib/libc/math/lrint.c | 46 -- usr/lib/libc/math/lrintf.c | 8 - usr/lib/libc/math/lrintl.c | 36 - usr/lib/libc/math/lround.c | 6 - usr/lib/libc/math/lroundf.c | 6 - usr/lib/libc/math/lroundl.c | 6 - usr/lib/libc/math/modf.c | 34 - usr/lib/libc/math/modff.c | 34 - usr/lib/libc/math/modfl.c | 53 -- usr/lib/libc/math/nan.c | 6 - usr/lib/libc/math/nanf.c | 6 - usr/lib/libc/math/nanl.c | 6 - usr/lib/libc/math/nearbyint.c | 20 - usr/lib/libc/math/nearbyintf.c | 18 - usr/lib/libc/math/nearbyintl.c | 26 - usr/lib/libc/math/nextafter.c | 31 - usr/lib/libc/math/nextafterf.c | 30 - usr/lib/libc/math/nextafterl.c | 75 -- usr/lib/libc/math/nexttoward.c | 42 -- usr/lib/libc/math/nexttowardf.c | 35 - usr/lib/libc/math/nexttowardl.c | 6 - usr/lib/libc/math/pow.c | 328 --------- usr/lib/libc/math/powf.c | 259 ------- usr/lib/libc/math/powl.c | 522 ------------- usr/lib/libc/math/remainder.c | 10 - usr/lib/libc/math/remainderf.c | 10 - usr/lib/libc/math/remainderl.c | 15 - usr/lib/libc/math/remquo.c | 82 --- usr/lib/libc/math/remquof.c | 82 --- usr/lib/libc/math/remquol.c | 124 ---- usr/lib/libc/math/rint.c | 28 - usr/lib/libc/math/rintf.c | 30 - usr/lib/libc/math/rintl.c | 29 - usr/lib/libc/math/round.c | 35 - usr/lib/libc/math/roundf.c | 36 - usr/lib/libc/math/roundl.c | 37 - usr/lib/libc/math/scalb.c | 35 - usr/lib/libc/math/scalbf.c | 32 - usr/lib/libc/math/scalbln.c | 11 - usr/lib/libc/math/scalblnf.c | 11 - usr/lib/libc/math/scalblnl.c | 19 - usr/lib/libc/math/scalbn.c | 33 - usr/lib/libc/math/scalbnf.c | 31 - usr/lib/libc/math/scalbnl.c | 36 - usr/lib/libc/math/signgam.c | 6 - usr/lib/libc/math/significand.c | 7 - usr/lib/libc/math/significandf.c | 7 - usr/lib/libc/math/sin.c | 78 -- usr/lib/libc/math/sincos.c | 69 -- usr/lib/libc/math/sincosf.c | 117 --- usr/lib/libc/math/sincosl.c | 60 -- usr/lib/libc/math/sinf.c | 76 -- usr/lib/libc/math/sinh.c | 39 - usr/lib/libc/math/sinhf.c | 31 - usr/lib/libc/math/sinhl.c | 43 -- usr/lib/libc/math/sinl.c | 41 -- usr/lib/libc/math/sqrt.c | 185 ----- usr/lib/libc/math/sqrtf.c | 84 --- usr/lib/libc/math/sqrtl.c | 7 - usr/lib/libc/math/tan.c | 70 -- usr/lib/libc/math/tanf.c | 64 -- usr/lib/libc/math/tanh.c | 45 -- usr/lib/libc/math/tanhf.c | 39 - usr/lib/libc/math/tanhl.c | 48 -- usr/lib/libc/math/tanl.c | 29 - usr/lib/libc/math/tgamma.c | 222 ------ usr/lib/libc/math/tgammaf.c | 6 - usr/lib/libc/math/tgammal.c | 281 ------- usr/lib/libc/math/trunc.c | 19 - usr/lib/libc/math/truncf.c | 19 - usr/lib/libc/math/truncl.c | 34 - usr/lib/libc/mbsinit.c | 6 - usr/lib/libc/misc/CMakeLists.txt | 6 - usr/lib/libc/misc/a64l.c | 29 - usr/lib/libc/misc/basename.c | 15 - usr/lib/libc/misc/dirname.c | 14 - usr/lib/libc/misc/ffs.c | 7 - usr/lib/libc/misc/ffsl.c | 7 - usr/lib/libc/misc/ffsll.c | 7 - usr/lib/libc/misc/fmtmsg.c | 90 --- usr/lib/libc/misc/forkpty.c | 57 -- usr/lib/libc/misc/get_current_dir_name.c | 15 - usr/lib/libc/misc/getauxval.c | 13 - usr/lib/libc/misc/getdomainname.c | 17 - usr/lib/libc/misc/gethostid.c | 4 - usr/lib/libc/misc/getopt.c | 104 --- usr/lib/libc/misc/getopt_long.c | 133 ---- usr/lib/libc/misc/getpriority.c | 9 - usr/lib/libc/misc/getresgid.c | 8 - usr/lib/libc/misc/getresuid.c | 8 - usr/lib/libc/misc/getrlimit.c | 27 - usr/lib/libc/misc/getrusage.c | 7 - usr/lib/libc/misc/getsubopt.c | 23 - usr/lib/libc/misc/initgroups.c | 11 - usr/lib/libc/misc/ioctl.c | 16 - usr/lib/libc/misc/issetugid.c | 7 - usr/lib/libc/misc/lockf.c | 33 - usr/lib/libc/misc/login_tty.c | 14 - usr/lib/libc/misc/mntent.c | 77 -- usr/lib/libc/misc/nftw.c | 123 ---- usr/lib/libc/misc/openpty.c | 40 - usr/lib/libc/misc/ptsname.c | 15 - usr/lib/libc/misc/pty.c | 34 - usr/lib/libc/misc/realpath.c | 45 -- usr/lib/libc/misc/setdomainname.c | 8 - usr/lib/libc/misc/setpriority.c | 7 - usr/lib/libc/misc/setrlimit.c | 50 -- usr/lib/libc/misc/stat.c | 8 - usr/lib/libc/misc/syslog.c | 144 ---- usr/lib/libc/misc/uname.c | 7 - usr/lib/libc/misc/wordexp.c | 193 ----- usr/lib/libc/mman/CMakeLists.txt | 5 - usr/lib/libc/mman/madvise.c | 10 - usr/lib/libc/mman/mincore.c | 8 - usr/lib/libc/mman/mlock.c | 7 - usr/lib/libc/mman/mlockall.c | 7 - usr/lib/libc/mman/mmap.c | 51 -- usr/lib/libc/mman/mprotect.c | 13 - usr/lib/libc/mman/mremap.c | 33 - usr/lib/libc/mman/msync.c | 7 - usr/lib/libc/mman/munlock.c | 7 - usr/lib/libc/mman/munlockall.c | 7 - usr/lib/libc/mman/munmap.c | 14 - usr/lib/libc/mman/posix_madvise.c | 9 - usr/lib/libc/mman/shm_open.c | 45 -- usr/lib/libc/multibyte/CMakeLists.txt | 9 - usr/lib/libc/multibyte/btowc.c | 10 - usr/lib/libc/multibyte/c16rtomb.c | 35 - usr/lib/libc/multibyte/c32rtomb.c | 7 - usr/lib/libc/multibyte/internal.c | 26 - usr/lib/libc/multibyte/internal.h | 28 - usr/lib/libc/multibyte/mblen.c | 6 - usr/lib/libc/multibyte/mbrlen.c | 7 - usr/lib/libc/multibyte/mbrtoc16.c | 30 - usr/lib/libc/multibyte/mbrtoc32.c | 13 - usr/lib/libc/multibyte/mbrtowc.c | 51 -- usr/lib/libc/multibyte/mbsinit.c | 6 - usr/lib/libc/multibyte/mbsnrtowcs.c | 53 -- usr/lib/libc/multibyte/mbsrtowcs.c | 114 --- usr/lib/libc/multibyte/mbstowcs.c | 7 - usr/lib/libc/multibyte/mbtowc.c | 47 -- usr/lib/libc/multibyte/wcrtomb.c | 37 - usr/lib/libc/multibyte/wcsnrtombs.c | 41 -- usr/lib/libc/multibyte/wcsrtombs.c | 55 -- usr/lib/libc/multibyte/wcstombs.c | 7 - usr/lib/libc/multibyte/wctob.c | 11 - usr/lib/libc/multibyte/wctomb.c | 8 - usr/lib/libc/mutex.c | 12 - usr/lib/libc/network/CMakeLists.txt | 21 - usr/lib/libc/network/accept.c | 8 - usr/lib/libc/network/accept4.c | 20 - usr/lib/libc/network/bind.c | 7 - usr/lib/libc/network/connect.c | 8 - usr/lib/libc/network/dn_comp.c | 110 --- usr/lib/libc/network/dn_expand.c | 34 - usr/lib/libc/network/dn_skipname.c | 12 - usr/lib/libc/network/dns_parse.c | 32 - usr/lib/libc/network/ent.c | 18 - usr/lib/libc/network/ether.c | 58 -- usr/lib/libc/network/freeaddrinfo.c | 7 - usr/lib/libc/network/gai_strerror.c | 25 - usr/lib/libc/network/getaddrinfo.c | 92 --- usr/lib/libc/network/gethostbyaddr.c | 24 - usr/lib/libc/network/gethostbyaddr_r.c | 71 -- usr/lib/libc/network/gethostbyname.c | 11 - usr/lib/libc/network/gethostbyname2.c | 25 - usr/lib/libc/network/gethostbyname2_r.c | 80 -- usr/lib/libc/network/gethostbyname_r.c | 11 - usr/lib/libc/network/getifaddrs.c | 216 ------ usr/lib/libc/network/getnameinfo.c | 202 ----- usr/lib/libc/network/getpeername.c | 7 - usr/lib/libc/network/getservbyname.c | 12 - usr/lib/libc/network/getservbyname_r.c | 49 -- usr/lib/libc/network/getservbyport.c | 12 - usr/lib/libc/network/getservbyport_r.c | 56 -- usr/lib/libc/network/getsockname.c | 7 - usr/lib/libc/network/getsockopt.c | 7 - usr/lib/libc/network/h_errno.c | 9 - usr/lib/libc/network/herror.c | 8 - usr/lib/libc/network/hstrerror.c | 18 - usr/lib/libc/network/htonl.c | 9 - usr/lib/libc/network/htons.c | 8 - usr/lib/libc/network/if_freenameindex.c | 7 - usr/lib/libc/network/if_indextoname.c | 23 - usr/lib/libc/network/if_nameindex.c | 114 --- usr/lib/libc/network/if_nametoindex.c | 18 - usr/lib/libc/network/in6addr_any.c | 3 - usr/lib/libc/network/in6addr_loopback.c | 3 - usr/lib/libc/network/inet_addr.c | 12 - usr/lib/libc/network/inet_aton.c | 41 -- usr/lib/libc/network/inet_legacy.c | 32 - usr/lib/libc/network/inet_ntoa.c | 10 - usr/lib/libc/network/inet_ntop.c | 54 -- usr/lib/libc/network/inet_pton.c | 71 -- usr/lib/libc/network/listen.c | 7 - usr/lib/libc/network/lookup.h | 39 - usr/lib/libc/network/lookup_ipliteral.c | 57 -- usr/lib/libc/network/lookup_name.c | 398 ---------- usr/lib/libc/network/lookup_serv.c | 113 --- usr/lib/libc/network/netlink.c | 52 -- usr/lib/libc/network/netlink.h | 94 --- usr/lib/libc/network/netname.c | 12 - usr/lib/libc/network/ns_parse.c | 171 ----- usr/lib/libc/network/ntohl.c | 8 - usr/lib/libc/network/ntohs.c | 8 - usr/lib/libc/network/proto.c | 84 --- usr/lib/libc/network/recv.c | 6 - usr/lib/libc/network/recvfrom.c | 8 - usr/lib/libc/network/recvmmsg.c | 15 - usr/lib/libc/network/recvmsg.c | 22 - usr/lib/libc/network/res_init.c | 6 - usr/lib/libc/network/res_mkquery.c | 44 -- usr/lib/libc/network/res_msend.c | 188 ----- usr/lib/libc/network/res_query.c | 17 - usr/lib/libc/network/res_querydomain.c | 14 - usr/lib/libc/network/res_send.c | 12 - usr/lib/libc/network/res_state.c | 9 - usr/lib/libc/network/resolvconf.c | 93 --- usr/lib/libc/network/send.c | 6 - usr/lib/libc/network/sendmmsg.c | 30 - usr/lib/libc/network/sendmsg.c | 30 - usr/lib/libc/network/sendto.c | 12 - usr/lib/libc/network/serv.c | 14 - usr/lib/libc/network/setsockopt.c | 7 - usr/lib/libc/network/shutdown.c | 7 - usr/lib/libc/network/sockatmark.c | 10 - usr/lib/libc/network/socket.c | 22 - usr/lib/libc/network/socketpair.c | 25 - usr/lib/libc/prng/CMakeLists.txt | 6 - usr/lib/libc/prng/__rand48_step.c | 13 - usr/lib/libc/prng/__seed48.c | 1 - usr/lib/libc/prng/drand48.c | 19 - usr/lib/libc/prng/lcong48.c | 9 - usr/lib/libc/prng/lrand48.c | 15 - usr/lib/libc/prng/mrand48.c | 15 - usr/lib/libc/prng/rand.c | 15 - usr/lib/libc/prng/rand_r.c | 15 - usr/lib/libc/prng/random.c | 122 --- usr/lib/libc/prng/seed48.c | 12 - usr/lib/libc/prng/srand48.c | 6 - usr/lib/libc/process/CMakeLists.txt | 13 - usr/lib/libc/process/execl.c | 22 - usr/lib/libc/process/execle.c | 23 - usr/lib/libc/process/execlp.c | 22 - usr/lib/libc/process/execv.c | 8 - usr/lib/libc/process/execve.c | 11 - usr/lib/libc/process/execvp.c | 55 -- usr/lib/libc/process/fexecve.c | 13 - usr/lib/libc/process/fork.c | 44 -- usr/lib/libc/process/posix_spawn.c | 199 ----- .../posix_spawn_file_actions_addclose.c | 16 - .../posix_spawn_file_actions_adddup2.c | 17 - .../posix_spawn_file_actions_addopen.c | 20 - .../posix_spawn_file_actions_destroy.c | 14 - .../process/posix_spawn_file_actions_init.c | 7 - .../libc/process/posix_spawnattr_destroy.c | 6 - .../libc/process/posix_spawnattr_getflags.c | 7 - .../libc/process/posix_spawnattr_getpgroup.c | 7 - .../process/posix_spawnattr_getsigdefault.c | 7 - .../libc/process/posix_spawnattr_getsigmask.c | 7 - usr/lib/libc/process/posix_spawnattr_init.c | 7 - usr/lib/libc/process/posix_spawnattr_sched.c | 25 - .../libc/process/posix_spawnattr_setflags.c | 18 - .../libc/process/posix_spawnattr_setpgroup.c | 7 - .../process/posix_spawnattr_setsigdefault.c | 7 - .../libc/process/posix_spawnattr_setsigmask.c | 7 - usr/lib/libc/process/posix_spawnp.c | 17 - usr/lib/libc/process/ptrace.c | 27 - usr/lib/libc/process/system.c | 47 -- usr/lib/libc/process/vfork.c | 17 - usr/lib/libc/process/wait.c | 6 - usr/lib/libc/process/waitid.c | 8 - usr/lib/libc/process/waitpid.c | 12 - usr/lib/libc/pthread.c | 86 --- usr/lib/libc/sbrk.c | 15 - usr/lib/libc/setjmp.S | 83 --- usr/lib/libc/shgetc.c | 34 - usr/lib/libc/signal/CMakeLists.txt | 7 - usr/lib/libc/signal/block.c | 44 -- usr/lib/libc/signal/getitimer.c | 7 - usr/lib/libc/signal/handler | 0 usr/lib/libc/signal/kill.c | 11 - usr/lib/libc/signal/killpg.c | 11 - usr/lib/libc/signal/psiginfo.c | 10 - usr/lib/libc/signal/psignal.c | 10 - usr/lib/libc/signal/raise.c | 15 - usr/lib/libc/signal/restore.c | 10 - usr/lib/libc/signal/setitimer.c | 7 - usr/lib/libc/signal/sigaction.c | 95 --- usr/lib/libc/signal/sigaddset.c | 13 - usr/lib/libc/signal/sigaltstack.c | 18 - usr/lib/libc/signal/sigandset.c | 12 - usr/lib/libc/signal/sigdelset.c | 13 - usr/lib/libc/signal/sigemptyset.c | 13 - usr/lib/libc/signal/sigfillset.c | 18 - usr/lib/libc/signal/sighold.c | 10 - usr/lib/libc/signal/sigignore.c | 11 - usr/lib/libc/signal/siginterrupt.c | 12 - usr/lib/libc/signal/sigisemptyset.c | 9 - usr/lib/libc/signal/sigismember.c | 8 - usr/lib/libc/signal/siglongjmp.c | 9 - usr/lib/libc/signal/signal.c | 16 - usr/lib/libc/signal/sigorset.c | 12 - usr/lib/libc/signal/sigpause.c | 9 - usr/lib/libc/signal/sigpending.c | 7 - usr/lib/libc/signal/sigprocmask.c | 10 - usr/lib/libc/signal/sigqueue.c | 22 - usr/lib/libc/signal/sigrelse.c | 10 - usr/lib/libc/signal/sigrtmax.c | 6 - usr/lib/libc/signal/sigrtmin.c | 4 - usr/lib/libc/signal/sigset.c | 27 - usr/lib/libc/signal/sigsetjmp.c | 0 usr/lib/libc/signal/sigsetjmp_tail.c | 11 - usr/lib/libc/signal/sigsuspend.c | 8 - usr/lib/libc/signal/sigtimedwait.c | 13 - usr/lib/libc/signal/sigwait.c | 10 - usr/lib/libc/signal/sigwaitinfo.c | 6 - usr/lib/libc/stdarg.h | 205 ------ usr/lib/libc/stdio/CMakeLists.txt | 55 -- usr/lib/libc/stdio/__fclose_ca.c | 6 - usr/lib/libc/stdio/__fdopen.c | 77 -- usr/lib/libc/stdio/__fmodeflags.c | 16 - usr/lib/libc/stdio/__fopen_rb_ca.c | 22 - usr/lib/libc/stdio/__lockfile.c | 35 - usr/lib/libc/stdio/__overflow.c | 10 - usr/lib/libc/stdio/__stdio_close.c | 16 - usr/lib/libc/stdio/__stdio_exit.c | 24 - usr/lib/libc/stdio/__stdio_read.c | 33 - usr/lib/libc/stdio/__stdio_seek.c | 21 - usr/lib/libc/stdio/__stdio_write.c | 47 -- usr/lib/libc/stdio/__stdout_write.c | 20 - usr/lib/libc/stdio/__string_read.c | 16 - usr/lib/libc/stdio/__toread.c | 21 - usr/lib/libc/stdio/__towrite.c | 25 - usr/lib/libc/stdio/__uflow.c | 11 - usr/lib/libc/stdio/asprintf.c | 13 - usr/lib/libc/stdio/clearerr.c | 10 - usr/lib/libc/stdio/dprintf.c | 12 - usr/lib/libc/stdio/ext.c | 57 -- usr/lib/libc/stdio/ext2.c | 24 - usr/lib/libc/stdio/fclose.c | 38 - usr/lib/libc/stdio/feof.c | 14 - usr/lib/libc/stdio/ferror.c | 14 - usr/lib/libc/stdio/fflush.c | 41 -- usr/lib/libc/stdio/fgetc.c | 13 - usr/lib/libc/stdio/fgetln.c | 21 - usr/lib/libc/stdio/fgetpos.c | 11 - usr/lib/libc/stdio/fgets.c | 68 -- usr/lib/libc/stdio/fgetwc.c | 61 -- usr/lib/libc/stdio/fgetws.c | 28 - usr/lib/libc/stdio/fileno.c | 13 - usr/lib/libc/stdio/flockfile.c | 10 - usr/lib/libc/stdio/fmemopen.c | 114 --- usr/lib/libc/stdio/fopen.c | 44 -- usr/lib/libc/stdio/fprintf.c | 12 - usr/lib/libc/stdio/fputc.c | 10 - usr/lib/libc/stdio/fputs.c | 10 - usr/lib/libc/stdio/fputwc.c | 40 - usr/lib/libc/stdio/fputws.c | 29 - usr/lib/libc/stdio/fread.c | 38 - usr/lib/libc/stdio/freopen.c | 54 -- usr/lib/libc/stdio/fscanf.c | 15 - usr/lib/libc/stdio/fseek.c | 45 -- usr/lib/libc/stdio/fsetpos.c | 8 - usr/lib/libc/stdio/ftell.c | 39 - usr/lib/libc/stdio/ftrylockfile.c | 40 - usr/lib/libc/stdio/funlockfile.c | 15 - usr/lib/libc/stdio/fwide.c | 15 - usr/lib/libc/stdio/fwprintf.c | 13 - usr/lib/libc/stdio/fwrite.c | 39 - usr/lib/libc/stdio/fwscanf.c | 16 - usr/lib/libc/stdio/getc.c | 13 - usr/lib/libc/stdio/getc_unlocked.c | 9 - usr/lib/libc/stdio/getchar.c | 6 - usr/lib/libc/stdio/getchar_unlocked.c | 6 - usr/lib/libc/stdio/getdelim.c | 68 -- usr/lib/libc/stdio/getline.c | 6 - usr/lib/libc/stdio/gets.c | 10 - usr/lib/libc/stdio/getw.c | 8 - usr/lib/libc/stdio/getwc.c | 7 - usr/lib/libc/stdio/getwchar.c | 9 - usr/lib/libc/stdio/ofl.c | 16 - usr/lib/libc/stdio/ofl_add.c | 11 - usr/lib/libc/stdio/open_memstream.c | 90 --- usr/lib/libc/stdio/open_wmemstream.c | 92 --- usr/lib/libc/stdio/pclose.c | 13 - usr/lib/libc/stdio/perror.c | 22 - usr/lib/libc/stdio/popen.c | 73 -- usr/lib/libc/stdio/printf.c | 13 - usr/lib/libc/stdio/putc.c | 12 - usr/lib/libc/stdio/putc_unlocked.c | 9 - usr/lib/libc/stdio/putchar.c | 13 - usr/lib/libc/stdio/putchar_unlocked.c | 6 - usr/lib/libc/stdio/puts.c | 10 - usr/lib/libc/stdio/putw.c | 7 - usr/lib/libc/stdio/putwc.c | 7 - usr/lib/libc/stdio/putwchar.c | 9 - usr/lib/libc/stdio/remove.c | 19 - usr/lib/libc/stdio/rename.c | 12 - usr/lib/libc/stdio/rewind.c | 9 - usr/lib/libc/stdio/scanf.c | 15 - usr/lib/libc/stdio/setbuf.c | 6 - usr/lib/libc/stdio/setbuffer.c | 7 - usr/lib/libc/stdio/setlinebuf.c | 7 - usr/lib/libc/stdio/setvbuf.c | 24 - usr/lib/libc/stdio/snprintf.c | 13 - usr/lib/libc/stdio/sprintf.c | 12 - usr/lib/libc/stdio/sscanf.c | 15 - usr/lib/libc/stdio/stderr.c | 22 - usr/lib/libc/stdio/stdin.c | 15 - usr/lib/libc/stdio/stdout.c | 16 - usr/lib/libc/stdio/swprintf.c | 13 - usr/lib/libc/stdio/swscanf.c | 15 - usr/lib/libc/stdio/tempnam.c | 49 -- usr/lib/libc/stdio/tmpfile.c | 32 - usr/lib/libc/stdio/tmpnam.c | 29 - usr/lib/libc/stdio/ungetc.c | 20 - usr/lib/libc/stdio/ungetwc.c | 35 - usr/lib/libc/stdio/vasprintf.c | 15 - usr/lib/libc/stdio/vdprintf.c | 16 - usr/lib/libc/stdio/vfprintf.c | 696 ------------------ usr/lib/libc/stdio/vfscanf.c | 332 --------- usr/lib/libc/stdio/vfwprintf.c | 386 ---------- usr/lib/libc/stdio/vfwscanf.c | 329 --------- usr/lib/libc/stdio/vprintf.c | 6 - usr/lib/libc/stdio/vscanf.c | 10 - usr/lib/libc/stdio/vsnprintf.c | 56 -- usr/lib/libc/stdio/vsprintf.c | 7 - usr/lib/libc/stdio/vsscanf.c | 18 - usr/lib/libc/stdio/vswprintf.c | 60 -- usr/lib/libc/stdio/vswscanf.c | 39 - usr/lib/libc/stdio/vwprintf.c | 7 - usr/lib/libc/stdio/vwscanf.c | 11 - usr/lib/libc/stdio/wprintf.c | 13 - usr/lib/libc/stdio/wscanf.c | 16 - usr/lib/libc/stdlib.c | 29 - usr/lib/libc/stdlib/CMakeLists.txt | 9 - usr/lib/libc/stdlib/abs.c | 4 - usr/lib/libc/stdlib/atof.c | 6 - usr/lib/libc/stdlib/atoi.c | 16 - usr/lib/libc/stdlib/atol.c | 17 - usr/lib/libc/stdlib/atoll.c | 17 - usr/lib/libc/stdlib/bsearch.c | 20 - usr/lib/libc/stdlib/div.c | 6 - usr/lib/libc/stdlib/ecvt.c | 20 - usr/lib/libc/stdlib/fcvt.c | 25 - usr/lib/libc/stdlib/gcvt.c | 9 - usr/lib/libc/stdlib/imaxabs.c | 6 - usr/lib/libc/stdlib/imaxdiv.c | 6 - usr/lib/libc/stdlib/labs.c | 4 - usr/lib/libc/stdlib/ldiv.c | 6 - usr/lib/libc/stdlib/llabs.c | 4 - usr/lib/libc/stdlib/lldiv.c | 6 - usr/lib/libc/stdlib/qsort.c | 215 ------ usr/lib/libc/stdlib/strtod.c | 43 -- usr/lib/libc/stdlib/strtol.c | 64 -- usr/lib/libc/stdlib/wcstod.c | 65 -- usr/lib/libc/stdlib/wcstol.c | 82 --- usr/lib/libc/string/CMakeLists.txt | 25 - usr/lib/libc/string/arm/__aeabi_memclr.c | 9 - usr/lib/libc/string/arm/__aeabi_memcpy.c | 9 - usr/lib/libc/string/arm/__aeabi_memmove.c | 9 - usr/lib/libc/string/arm/__aeabi_memset.c | 9 - usr/lib/libc/string/arm/memcpy.c | 3 - usr/lib/libc/string/arm/memcpy_le.S | 383 ---------- usr/lib/libc/string/bcmp.c | 8 - usr/lib/libc/string/bcopy.c | 8 - usr/lib/libc/string/bzero.c | 8 - usr/lib/libc/string/index.c | 8 - usr/lib/libc/string/memccpy.c | 31 - usr/lib/libc/string/memchr.c | 23 - usr/lib/libc/string/memcmp.c | 8 - usr/lib/libc/string/memcpy.c | 124 ---- usr/lib/libc/string/memmem.c | 149 ---- usr/lib/libc/string/memmove.c | 36 - usr/lib/libc/string/mempcpy.c | 7 - usr/lib/libc/string/memrchr.c | 12 - usr/lib/libc/string/memset.c | 86 --- usr/lib/libc/string/rindex.c | 8 - usr/lib/libc/string/stpcpy.c | 28 - usr/lib/libc/string/stpncpy.c | 31 - usr/lib/libc/string/strcasecmp.c | 17 - usr/lib/libc/string/strcasestr.c | 9 - usr/lib/libc/string/strcat.c | 7 - usr/lib/libc/string/strchr.c | 9 - usr/lib/libc/string/strchrnul.c | 26 - usr/lib/libc/string/strcmp.c | 7 - usr/lib/libc/string/strcpy.c | 16 - usr/lib/libc/string/strcspn.c | 19 - usr/lib/libc/string/strdup.c | 13 - usr/lib/libc/string/strerror_r.c | 20 - usr/lib/libc/string/strlcat.c | 9 - usr/lib/libc/string/strlcpy.c | 32 - usr/lib/libc/string/strlen.c | 31 - usr/lib/libc/string/strncasecmp.c | 18 - usr/lib/libc/string/strncat.c | 10 - usr/lib/libc/string/strncmp.c | 9 - usr/lib/libc/string/strncpy.c | 9 - usr/lib/libc/string/strndup.c | 12 - usr/lib/libc/string/strnlen.c | 7 - usr/lib/libc/string/strpbrk.c | 7 - usr/lib/libc/string/strrchr.c | 8 - usr/lib/libc/string/strsep.c | 13 - usr/lib/libc/string/strsignal.c | 116 --- usr/lib/libc/string/strspn.c | 20 - usr/lib/libc/string/strstr.c | 155 ---- usr/lib/libc/string/strtok.c | 13 - usr/lib/libc/string/strtok_r.c | 12 - usr/lib/libc/string/strverscmp.c | 34 - usr/lib/libc/string/swab.c | 13 - usr/lib/libc/string/wcpcpy.c | 6 - usr/lib/libc/string/wcpncpy.c | 6 - usr/lib/libc/string/wcscasecmp.c | 7 - usr/lib/libc/string/wcscasecmp_l.c | 6 - usr/lib/libc/string/wcscat.c | 7 - usr/lib/libc/string/wcschr.c | 8 - usr/lib/libc/string/wcscmp.c | 7 - usr/lib/libc/string/wcscpy.c | 8 - usr/lib/libc/string/wcscspn.c | 10 - usr/lib/libc/string/wcsdup.c | 11 - usr/lib/libc/string/wcslen.c | 8 - usr/lib/libc/string/wcsncasecmp.c | 9 - usr/lib/libc/string/wcsncasecmp_l.c | 6 - usr/lib/libc/string/wcsncat.c | 10 - usr/lib/libc/string/wcsncmp.c | 7 - usr/lib/libc/string/wcsncpy.c | 9 - usr/lib/libc/string/wcsnlen.c | 8 - usr/lib/libc/string/wcspbrk.c | 7 - usr/lib/libc/string/wcsrchr.c | 8 - usr/lib/libc/string/wcsspn.c | 8 - usr/lib/libc/string/wcsstr.c | 105 --- usr/lib/libc/string/wcstok.c | 12 - usr/lib/libc/string/wcswcs.c | 6 - usr/lib/libc/string/wmemchr.c | 7 - usr/lib/libc/string/wmemcmp.c | 7 - usr/lib/libc/string/wmemcpy.c | 8 - usr/lib/libc/string/wmemmove.c | 11 - usr/lib/libc/string/wmemset.c | 8 - usr/lib/libc/syscall_ret.c | 11 - usr/lib/libc/thread/CMakeLists.txt | 19 - usr/lib/libc/thread/__futex.c | 7 - usr/lib/libc/thread/__lock.c | 19 - usr/lib/libc/thread/__set_thread_area.c | 10 - usr/lib/libc/thread/__syscall_cp.c | 21 - usr/lib/libc/thread/__timedwait.c | 46 -- usr/lib/libc/thread/__tls_get_addr.c | 16 - usr/lib/libc/thread/__unmapself.c | 29 - usr/lib/libc/thread/__wait.c | 17 - usr/lib/libc/thread/atomics.S | 106 --- usr/lib/libc/thread/call_once.c | 8 - usr/lib/libc/thread/clone.c | 7 - usr/lib/libc/thread/cnd_broadcast.c | 10 - usr/lib/libc/thread/cnd_destroy.c | 6 - usr/lib/libc/thread/cnd_init.c | 7 - usr/lib/libc/thread/cnd_signal.c | 10 - usr/lib/libc/thread/cnd_timedwait.c | 15 - usr/lib/libc/thread/cnd_wait.c | 9 - usr/lib/libc/thread/lock_ptc.c | 18 - usr/lib/libc/thread/mtx_destroy.c | 5 - usr/lib/libc/thread/mtx_init.c | 10 - usr/lib/libc/thread/mtx_lock.c | 12 - usr/lib/libc/thread/mtx_timedlock.c | 14 - usr/lib/libc/thread/mtx_trylock.c | 17 - usr/lib/libc/thread/mtx_unlock.c | 11 - usr/lib/libc/thread/pthread_atfork.c | 48 -- usr/lib/libc/thread/pthread_attr_destroy.c | 6 - usr/lib/libc/thread/pthread_attr_get.c | 98 --- usr/lib/libc/thread/pthread_attr_init.c | 9 - .../libc/thread/pthread_attr_setdetachstate.c | 8 - .../libc/thread/pthread_attr_setguardsize.c | 8 - .../thread/pthread_attr_setinheritsched.c | 8 - .../libc/thread/pthread_attr_setschedparam.c | 7 - .../libc/thread/pthread_attr_setschedpolicy.c | 7 - usr/lib/libc/thread/pthread_attr_setscope.c | 13 - usr/lib/libc/thread/pthread_attr_setstack.c | 9 - .../libc/thread/pthread_attr_setstacksize.c | 9 - usr/lib/libc/thread/pthread_barrier_destroy.c | 15 - usr/lib/libc/thread/pthread_barrier_init.c | 8 - usr/lib/libc/thread/pthread_barrier_wait.c | 111 --- .../libc/thread/pthread_barrierattr_destroy.c | 6 - .../libc/thread/pthread_barrierattr_init.c | 7 - .../thread/pthread_barrierattr_setpshared.c | 7 - usr/lib/libc/thread/pthread_cancel.c | 97 --- usr/lib/libc/thread/pthread_cleanup_push.c | 20 - usr/lib/libc/thread/pthread_cond_broadcast.c | 12 - usr/lib/libc/thread/pthread_cond_destroy.c | 14 - usr/lib/libc/thread/pthread_cond_init.c | 11 - usr/lib/libc/thread/pthread_cond_signal.c | 12 - usr/lib/libc/thread/pthread_cond_timedwait.c | 214 ------ usr/lib/libc/thread/pthread_cond_wait.c | 6 - .../libc/thread/pthread_condattr_destroy.c | 6 - usr/lib/libc/thread/pthread_condattr_init.c | 7 - .../libc/thread/pthread_condattr_setclock.c | 9 - .../libc/thread/pthread_condattr_setpshared.c | 9 - usr/lib/libc/thread/pthread_create.c | 311 -------- usr/lib/libc/thread/pthread_detach.c | 17 - usr/lib/libc/thread/pthread_equal.c | 11 - usr/lib/libc/thread/pthread_getattr_np.c | 23 - usr/lib/libc/thread/pthread_getconcurrency.c | 6 - usr/lib/libc/thread/pthread_getcpuclockid.c | 7 - usr/lib/libc/thread/pthread_getschedparam.c | 17 - usr/lib/libc/thread/pthread_getspecific.c | 11 - usr/lib/libc/thread/pthread_join.c | 36 - usr/lib/libc/thread/pthread_key_create.c | 56 -- usr/lib/libc/thread/pthread_kill.c | 10 - .../libc/thread/pthread_mutex_consistent.c | 10 - usr/lib/libc/thread/pthread_mutex_destroy.c | 6 - .../thread/pthread_mutex_getprioceiling.c | 6 - usr/lib/libc/thread/pthread_mutex_init.c | 8 - usr/lib/libc/thread/pthread_mutex_lock.c | 14 - .../thread/pthread_mutex_setprioceiling.c | 6 - usr/lib/libc/thread/pthread_mutex_timedlock.c | 34 - usr/lib/libc/thread/pthread_mutex_trylock.c | 58 -- usr/lib/libc/thread/pthread_mutex_unlock.c | 37 - .../libc/thread/pthread_mutexattr_destroy.c | 6 - usr/lib/libc/thread/pthread_mutexattr_init.c | 7 - .../thread/pthread_mutexattr_setprotocol.c | 7 - .../thread/pthread_mutexattr_setpshared.c | 9 - .../libc/thread/pthread_mutexattr_setrobust.c | 9 - .../libc/thread/pthread_mutexattr_settype.c | 8 - usr/lib/libc/thread/pthread_once.c | 50 -- usr/lib/libc/thread/pthread_rwlock_destroy.c | 6 - usr/lib/libc/thread/pthread_rwlock_init.c | 8 - usr/lib/libc/thread/pthread_rwlock_rdlock.c | 6 - .../libc/thread/pthread_rwlock_timedrdlock.c | 23 - .../libc/thread/pthread_rwlock_timedwrlock.c | 23 - .../libc/thread/pthread_rwlock_tryrdlock.c | 13 - .../libc/thread/pthread_rwlock_trywrlock.c | 7 - usr/lib/libc/thread/pthread_rwlock_unlock.c | 18 - usr/lib/libc/thread/pthread_rwlock_wrlock.c | 6 - .../libc/thread/pthread_rwlockattr_destroy.c | 6 - usr/lib/libc/thread/pthread_rwlockattr_init.c | 7 - .../thread/pthread_rwlockattr_setpshared.c | 8 - usr/lib/libc/thread/pthread_self.c | 11 - .../libc/thread/pthread_setattr_default_np.c | 35 - usr/lib/libc/thread/pthread_setcancelstate.c | 12 - usr/lib/libc/thread/pthread_setcanceltype.c | 11 - usr/lib/libc/thread/pthread_setconcurrency.c | 9 - usr/lib/libc/thread/pthread_setname_np.c | 26 - usr/lib/libc/thread/pthread_setschedparam.c | 10 - usr/lib/libc/thread/pthread_setschedprio.c | 10 - usr/lib/libc/thread/pthread_setspecific.c | 12 - usr/lib/libc/thread/pthread_sigmask.c | 19 - usr/lib/libc/thread/pthread_spin_destroy.c | 6 - usr/lib/libc/thread/pthread_spin_init.c | 6 - usr/lib/libc/thread/pthread_spin_lock.c | 8 - usr/lib/libc/thread/pthread_spin_trylock.c | 7 - usr/lib/libc/thread/pthread_spin_unlock.c | 7 - usr/lib/libc/thread/pthread_testcancel.c | 15 - usr/lib/libc/thread/sem_destroy.c | 6 - usr/lib/libc/thread/sem_getvalue.c | 8 - usr/lib/libc/thread/sem_init.c | 15 - usr/lib/libc/thread/sem_open.c | 175 ----- usr/lib/libc/thread/sem_post.c | 17 - usr/lib/libc/thread/sem_timedwait.c | 31 - usr/lib/libc/thread/sem_trywait.c | 13 - usr/lib/libc/thread/sem_unlink.c | 7 - usr/lib/libc/thread/sem_wait.c | 6 - usr/lib/libc/thread/synccall.c | 178 ----- usr/lib/libc/thread/syscall_cp.c | 0 usr/lib/libc/thread/thrd_create.c | 14 - usr/lib/libc/thread/thrd_exit.c | 9 - usr/lib/libc/thread/thrd_join.c | 12 - usr/lib/libc/thread/thrd_sleep.c | 16 - usr/lib/libc/thread/thrd_yield.c | 7 - usr/lib/libc/thread/tls.c | 0 usr/lib/libc/thread/tss_create.c | 11 - usr/lib/libc/thread/tss_delete.c | 8 - usr/lib/libc/thread/tss_set.c | 13 - usr/lib/libc/thread/vmlock.c | 21 - usr/lib/libc/time/CMakeLists.txt | 19 - usr/lib/libc/time/__asctime.c | 32 - usr/lib/libc/time/__map_file.c | 20 - usr/lib/libc/time/__month_to_secs.c | 10 - usr/lib/libc/time/__secs_to_tm.c | 82 --- usr/lib/libc/time/__tm_to_secs.c | 24 - usr/lib/libc/time/__tz.c | 421 ----------- usr/lib/libc/time/__year_to_secs.c | 49 -- usr/lib/libc/time/asctime.c | 9 - usr/lib/libc/time/asctime_r.c | 8 - usr/lib/libc/time/clock.c | 18 - usr/lib/libc/time/clock_getcpuclockid.c | 14 - usr/lib/libc/time/clock_getres.c | 7 - usr/lib/libc/time/clock_gettime.c | 65 -- usr/lib/libc/time/clock_nanosleep.c | 10 - usr/lib/libc/time/clock_settime.c | 7 - usr/lib/libc/time/ctime.c | 8 - usr/lib/libc/time/ctime_r.c | 8 - usr/lib/libc/time/difftime.c | 6 - usr/lib/libc/time/ftime.c | 12 - usr/lib/libc/time/getdate.c | 46 -- usr/lib/libc/time/gettimeofday.c | 16 - usr/lib/libc/time/gmtime.c | 10 - usr/lib/libc/time/gmtime_r.c | 19 - usr/lib/libc/time/localtime.c | 9 - usr/lib/libc/time/localtime_r.c | 25 - usr/lib/libc/time/mktime.c | 28 - usr/lib/libc/time/nanosleep.c | 8 - usr/lib/libc/time/strftime.c | 327 -------- usr/lib/libc/time/strptime.c | 206 ------ usr/lib/libc/time/time.c | 12 - usr/lib/libc/time/time_impl.h | 9 - usr/lib/libc/time/timegm.c | 20 - usr/lib/libc/time/timer_create.c | 141 ---- usr/lib/libc/time/timer_delete.c | 14 - usr/lib/libc/time/timer_getoverrun.c | 12 - usr/lib/libc/time/timer_gettime.c | 12 - usr/lib/libc/time/timer_settime.c | 12 - usr/lib/libc/time/times.c | 7 - usr/lib/libc/time/timespec_get.c | 12 - usr/lib/libc/time/utime.c | 11 - usr/lib/libc/time/wcsftime.c | 71 -- usr/lib/libc/unistd/CMakeLists.txt | 14 - usr/lib/libc/unistd/_exit.c | 7 - usr/lib/libc/unistd/access.c | 12 - usr/lib/libc/unistd/acct.c | 9 - usr/lib/libc/unistd/alarm.c | 10 - usr/lib/libc/unistd/chdir.c | 7 - usr/lib/libc/unistd/chown.c | 12 - usr/lib/libc/unistd/close.c | 25 - usr/lib/libc/unistd/ctermid.c | 7 - usr/lib/libc/unistd/dup.c | 7 - usr/lib/libc/unistd/dup2.c | 27 - usr/lib/libc/unistd/dup3.c | 25 - usr/lib/libc/unistd/faccessat.c | 63 -- usr/lib/libc/unistd/fchdir.c | 17 - usr/lib/libc/unistd/fchown.c | 22 - usr/lib/libc/unistd/fchownat.c | 7 - usr/lib/libc/unistd/fdatasync.c | 7 - usr/lib/libc/unistd/fsync.c | 7 - usr/lib/libc/unistd/ftruncate.c | 10 - usr/lib/libc/unistd/getcwd.c | 19 - usr/lib/libc/unistd/getegid.c | 7 - usr/lib/libc/unistd/geteuid.c | 7 - usr/lib/libc/unistd/getgid.c | 7 - usr/lib/libc/unistd/getgroups.c | 7 - usr/lib/libc/unistd/gethostname.c | 13 - usr/lib/libc/unistd/getlogin.c | 7 - usr/lib/libc/unistd/getlogin_r.c | 12 - usr/lib/libc/unistd/getpgid.c | 7 - usr/lib/libc/unistd/getpgrp.c | 7 - usr/lib/libc/unistd/getpid.c | 10 - usr/lib/libc/unistd/getppid.c | 7 - usr/lib/libc/unistd/getsid.c | 7 - usr/lib/libc/unistd/getuid.c | 7 - usr/lib/libc/unistd/isatty.c | 9 - usr/lib/libc/unistd/lchown.c | 12 - usr/lib/libc/unistd/link.c | 12 - usr/lib/libc/unistd/linkat.c | 7 - usr/lib/libc/unistd/lseek.c | 19 - usr/lib/libc/unistd/nice.c | 12 - usr/lib/libc/unistd/pause.c | 13 - usr/lib/libc/unistd/pipe.c | 14 - usr/lib/libc/unistd/pipe2.c | 22 - usr/lib/libc/unistd/posix_close.c | 6 - usr/lib/libc/unistd/pread.c | 10 - usr/lib/libc/unistd/preadv.c | 13 - usr/lib/libc/unistd/pwrite.c | 10 - usr/lib/libc/unistd/pwritev.c | 13 - usr/lib/libc/unistd/read.c | 11 - usr/lib/libc/unistd/readlink.c | 12 - usr/lib/libc/unistd/readlinkat.c | 7 - usr/lib/libc/unistd/readv.c | 8 - usr/lib/libc/unistd/renameat.c | 7 - usr/lib/libc/unistd/rmdir.c | 12 - usr/lib/libc/unistd/setegid.c | 8 - usr/lib/libc/unistd/seteuid.c | 8 - usr/lib/libc/unistd/setgid.c | 8 - usr/lib/libc/unistd/setpgid.c | 7 - usr/lib/libc/unistd/setpgrp.c | 6 - usr/lib/libc/unistd/setregid.c | 8 - usr/lib/libc/unistd/setresgid.c | 9 - usr/lib/libc/unistd/setresuid.c | 9 - usr/lib/libc/unistd/setreuid.c | 8 - usr/lib/libc/unistd/setsid.c | 7 - usr/lib/libc/unistd/setuid.c | 8 - usr/lib/libc/unistd/setxid.c | 39 - usr/lib/libc/unistd/sleep.c | 10 - usr/lib/libc/unistd/symlink.c | 12 - usr/lib/libc/unistd/symlinkat.c | 7 - usr/lib/libc/unistd/sync.c | 7 - usr/lib/libc/unistd/tcgetpgrp.c | 11 - usr/lib/libc/unistd/tcsetpgrp.c | 9 - usr/lib/libc/unistd/truncate.c | 10 - usr/lib/libc/unistd/ttyname.c | 14 - usr/lib/libc/unistd/ttyname_r.c | 29 - usr/lib/libc/unistd/ualarm.c | 13 - usr/lib/libc/unistd/unlink.c | 12 - usr/lib/libc/unistd/unlinkat.c | 7 - usr/lib/libc/unistd/usleep.c | 12 - usr/lib/libc/unistd/write.c | 12 - usr/lib/libc/unistd/writev.c | 8 - 1258 files changed, 57611 deletions(-) delete mode 100644 usr/lib/libc/CMakeLists.txt delete mode 100644 usr/lib/libc/aarch64.lds delete mode 100644 usr/lib/libc/arm.lds delete mode 100755 usr/lib/libc/crt0.S delete mode 100644 usr/lib/libc/crt1.c delete mode 100644 usr/lib/libc/ctype/CMakeLists.txt delete mode 100644 usr/lib/libc/ctype/__ctype_b_loc.c delete mode 100644 usr/lib/libc/ctype/__ctype_get_mb_cur_max.c delete mode 100644 usr/lib/libc/ctype/__ctype_tolower_loc.c delete mode 100644 usr/lib/libc/ctype/__ctype_toupper_loc.c delete mode 100644 usr/lib/libc/ctype/alpha.h delete mode 100644 usr/lib/libc/ctype/isalnum.c delete mode 100644 usr/lib/libc/ctype/isalpha.c delete mode 100644 usr/lib/libc/ctype/isascii.c delete mode 100644 usr/lib/libc/ctype/isblank.c delete mode 100644 usr/lib/libc/ctype/iscntrl.c delete mode 100644 usr/lib/libc/ctype/isdigit.c delete mode 100644 usr/lib/libc/ctype/isgraph.c delete mode 100644 usr/lib/libc/ctype/islower.c delete mode 100644 usr/lib/libc/ctype/isprint.c delete mode 100644 usr/lib/libc/ctype/ispunct.c delete mode 100644 usr/lib/libc/ctype/isspace.c delete mode 100644 usr/lib/libc/ctype/isupper.c delete mode 100644 usr/lib/libc/ctype/iswalnum.c delete mode 100644 usr/lib/libc/ctype/iswalpha.c delete mode 100644 usr/lib/libc/ctype/iswblank.c delete mode 100644 usr/lib/libc/ctype/iswcntrl.c delete mode 100644 usr/lib/libc/ctype/iswctype.c delete mode 100644 usr/lib/libc/ctype/iswdigit.c delete mode 100644 usr/lib/libc/ctype/iswgraph.c delete mode 100644 usr/lib/libc/ctype/iswlower.c delete mode 100644 usr/lib/libc/ctype/iswprint.c delete mode 100644 usr/lib/libc/ctype/iswpunct.c delete mode 100644 usr/lib/libc/ctype/iswspace.c delete mode 100644 usr/lib/libc/ctype/iswupper.c delete mode 100644 usr/lib/libc/ctype/iswxdigit.c delete mode 100644 usr/lib/libc/ctype/isxdigit.c delete mode 100644 usr/lib/libc/ctype/nonspacing.h delete mode 100644 usr/lib/libc/ctype/punct.h delete mode 100644 usr/lib/libc/ctype/toascii.c delete mode 100644 usr/lib/libc/ctype/tolower.c delete mode 100644 usr/lib/libc/ctype/toupper.c delete mode 100644 usr/lib/libc/ctype/towctrans.c delete mode 100644 usr/lib/libc/ctype/wcswidth.c delete mode 100644 usr/lib/libc/ctype/wctrans.c delete mode 100644 usr/lib/libc/ctype/wcwidth.c delete mode 100644 usr/lib/libc/ctype/wide.h delete mode 100644 usr/lib/libc/dirent/CMakeLists.txt delete mode 100644 usr/lib/libc/dirent/__dirent.h delete mode 100644 usr/lib/libc/dirent/__getdents.c delete mode 100644 usr/lib/libc/dirent/alphasort.c delete mode 100644 usr/lib/libc/dirent/closedir.c delete mode 100644 usr/lib/libc/dirent/dirfd.c delete mode 100644 usr/lib/libc/dirent/fdopendir.c delete mode 100644 usr/lib/libc/dirent/opendir.c delete mode 100644 usr/lib/libc/dirent/readdir.c delete mode 100644 usr/lib/libc/dirent/readdir_r.c delete mode 100644 usr/lib/libc/dirent/rewinddir.c delete mode 100644 usr/lib/libc/dirent/scandir.c delete mode 100644 usr/lib/libc/dirent/seekdir.c delete mode 100644 usr/lib/libc/dirent/telldir.c delete mode 100644 usr/lib/libc/dirent/versionsort.c delete mode 100644 usr/lib/libc/eabi_compat.c delete mode 100644 usr/lib/libc/env/CMakeLists.txt delete mode 100644 usr/lib/libc/env/__environ.c delete mode 100644 usr/lib/libc/env/__init_tls.c delete mode 100644 usr/lib/libc/env/__libc_start_main.c delete mode 100644 usr/lib/libc/env/__reset_tls.c delete mode 100644 usr/lib/libc/env/__stack_chk_fail.c delete mode 100644 usr/lib/libc/env/clearenv.c delete mode 100644 usr/lib/libc/env/getenv.c delete mode 100644 usr/lib/libc/env/putenv.c delete mode 100644 usr/lib/libc/env/setenv.c delete mode 100644 usr/lib/libc/env/unsetenv.c delete mode 100644 usr/lib/libc/errno/CMakeLists.txt delete mode 100644 usr/lib/libc/errno/__errno_location.c delete mode 100644 usr/lib/libc/errno/__strerror.h delete mode 100644 usr/lib/libc/errno/strerror.c delete mode 100644 usr/lib/libc/exit/CMakeLists.txt delete mode 100644 usr/lib/libc/exit/_Exit.c delete mode 100644 usr/lib/libc/exit/abort.c delete mode 100644 usr/lib/libc/exit/assert.c delete mode 100644 usr/lib/libc/exit/at_quick_exit.c delete mode 100644 usr/lib/libc/exit/atexit.c delete mode 100644 usr/lib/libc/exit/exit.c delete mode 100644 usr/lib/libc/exit/quick_exit.c delete mode 100644 usr/lib/libc/fcntl/CMakeLists.txt delete mode 100644 usr/lib/libc/fcntl/creat.c delete mode 100644 usr/lib/libc/fcntl/fcntl.c delete mode 100644 usr/lib/libc/fcntl/open.c delete mode 100644 usr/lib/libc/fcntl/openat.c delete mode 100644 usr/lib/libc/fcntl/posix_fadvise.c delete mode 100644 usr/lib/libc/fcntl/posix_fallocate.c delete mode 100644 usr/lib/libc/floatscan.c delete mode 100644 usr/lib/libc/include/alloca.h delete mode 100644 usr/lib/libc/include/arpa/ftp.h delete mode 100644 usr/lib/libc/include/arpa/inet.h delete mode 100644 usr/lib/libc/include/arpa/nameser.h delete mode 100644 usr/lib/libc/include/arpa/nameser_compat.h delete mode 100644 usr/lib/libc/include/arpa/telnet.h delete mode 100644 usr/lib/libc/include/arpa/tftp.h delete mode 100644 usr/lib/libc/include/asm-aarch32/atomic_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/alltypes.h.in delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/fcntl.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/fenv.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/float.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/hwcap.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/ioctl_fix.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/ipcstat.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/msg.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/posix.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/ptrace.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/reg.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/sem.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/setjmp.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/shm.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/signal.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/stat.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/stdint.h delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/syscall.h.in delete mode 100644 usr/lib/libc/include/asm-aarch32/bits/user.h delete mode 100644 usr/lib/libc/include/asm-aarch32/crt_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch32/kstat.h delete mode 100644 usr/lib/libc/include/asm-aarch32/pthread_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch32/reloc.h delete mode 100644 usr/lib/libc/include/asm-aarch32/socket.h delete mode 100644 usr/lib/libc/include/asm-aarch32/sockios.h delete mode 100644 usr/lib/libc/include/asm-aarch32/syscall_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch64/atomic_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/alltypes.h.in delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/fcntl.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/fenv.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/float.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/hwcap.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/ioctl_fix.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/ipcstat.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/mman.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/msg.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/posix.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/ptrace.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/reg.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/sem.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/setjmp.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/shm.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/signal.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/stat.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/stdint.h delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/syscall.h.in delete mode 100644 usr/lib/libc/include/asm-aarch64/bits/user.h delete mode 100644 usr/lib/libc/include/asm-aarch64/crt_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch64/fp_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch64/kstat.h delete mode 100644 usr/lib/libc/include/asm-aarch64/pthread_arch.h delete mode 100644 usr/lib/libc/include/asm-aarch64/reloc.h delete mode 100644 usr/lib/libc/include/asm-aarch64/socket.h delete mode 100644 usr/lib/libc/include/asm-aarch64/sockios.h delete mode 100644 usr/lib/libc/include/asm-aarch64/syscall_arch.h delete mode 100644 usr/lib/libc/include/assert.h delete mode 100644 usr/lib/libc/include/atomic.h delete mode 100644 usr/lib/libc/include/bits/alltypes.h delete mode 100644 usr/lib/libc/include/bits/byteswap.h delete mode 100644 usr/lib/libc/include/bits/endian.h delete mode 100644 usr/lib/libc/include/bits/fcntl.h delete mode 100644 usr/lib/libc/include/bits/fenv.h delete mode 100644 usr/lib/libc/include/bits/float.h delete mode 100644 usr/lib/libc/include/bits/hwcap.h delete mode 100644 usr/lib/libc/include/bits/ioctl.h delete mode 100644 usr/lib/libc/include/bits/ioctl_fix.h delete mode 100644 usr/lib/libc/include/bits/limits.h delete mode 100644 usr/lib/libc/include/bits/mman.h delete mode 100644 usr/lib/libc/include/bits/posix.h delete mode 100644 usr/lib/libc/include/bits/reg.h delete mode 100644 usr/lib/libc/include/bits/setjmp.h delete mode 100644 usr/lib/libc/include/bits/signal.h delete mode 100644 usr/lib/libc/include/bits/sockaddr.h delete mode 100644 usr/lib/libc/include/bits/socket.h delete mode 100644 usr/lib/libc/include/bits/socket_type.h delete mode 100644 usr/lib/libc/include/bits/stat.h delete mode 100644 usr/lib/libc/include/bits/stdint.h delete mode 100644 usr/lib/libc/include/bits/syscall.h.in delete mode 100644 usr/lib/libc/include/bits/user.h delete mode 100644 usr/lib/libc/include/byteswap.h delete mode 100644 usr/lib/libc/include/complex.h delete mode 100644 usr/lib/libc/include/ctype.h delete mode 100644 usr/lib/libc/include/dirent.h delete mode 100644 usr/lib/libc/include/dlfcn.h delete mode 100644 usr/lib/libc/include/endian.h delete mode 100644 usr/lib/libc/include/errno.h delete mode 100644 usr/lib/libc/include/fcntl.h delete mode 100644 usr/lib/libc/include/fdop.h delete mode 100644 usr/lib/libc/include/features.h delete mode 100644 usr/lib/libc/include/floatscan.h delete mode 100644 usr/lib/libc/include/iconv.h delete mode 100644 usr/lib/libc/include/inet.h delete mode 100644 usr/lib/libc/include/intscan.h delete mode 100644 usr/lib/libc/include/inttypes.h delete mode 100644 usr/lib/libc/include/ksigaction.h delete mode 100644 usr/lib/libc/include/langinfo.h delete mode 100644 usr/lib/libc/include/libc.h delete mode 100644 usr/lib/libc/include/libm.h delete mode 100644 usr/lib/libc/include/limits.h delete mode 100644 usr/lib/libc/include/locale.h delete mode 100644 usr/lib/libc/include/locale_impl.h delete mode 100644 usr/lib/libc/include/malloc.h delete mode 100644 usr/lib/libc/include/math.h delete mode 100644 usr/lib/libc/include/mman.h delete mode 100644 usr/lib/libc/include/mutex.h delete mode 100644 usr/lib/libc/include/net/ethernet.h delete mode 100644 usr/lib/libc/include/net/if.h delete mode 100644 usr/lib/libc/include/net/if_arp.h delete mode 100644 usr/lib/libc/include/net/route.h delete mode 100644 usr/lib/libc/include/netdb.h delete mode 100644 usr/lib/libc/include/netinet/ether.h delete mode 100644 usr/lib/libc/include/netinet/icmp6.h delete mode 100644 usr/lib/libc/include/netinet/if_ether.h delete mode 100644 usr/lib/libc/include/netinet/igmp.h delete mode 100644 usr/lib/libc/include/netinet/in.h delete mode 100644 usr/lib/libc/include/netinet/in_systm.h delete mode 100644 usr/lib/libc/include/netinet/ip.h delete mode 100644 usr/lib/libc/include/netinet/ip6.h delete mode 100644 usr/lib/libc/include/netinet/ip_icmp.h delete mode 100644 usr/lib/libc/include/netinet/tcp.h delete mode 100644 usr/lib/libc/include/netinet/udp.h delete mode 100644 usr/lib/libc/include/pthread.h delete mode 100644 usr/lib/libc/include/pthread_impl.h delete mode 100644 usr/lib/libc/include/shgetc.h delete mode 100644 usr/lib/libc/include/signal.h delete mode 100644 usr/lib/libc/include/stdarg.h delete mode 100644 usr/lib/libc/include/stddef.h delete mode 100644 usr/lib/libc/include/stdint.h delete mode 100644 usr/lib/libc/include/stdio.h delete mode 100644 usr/lib/libc/include/stdio_impl.h delete mode 100644 usr/lib/libc/include/stdlib.h delete mode 100644 usr/lib/libc/include/string.h delete mode 100644 usr/lib/libc/include/strings.h delete mode 100644 usr/lib/libc/include/sys/acct.h delete mode 100644 usr/lib/libc/include/sys/auxv.h delete mode 100644 usr/lib/libc/include/sys/cachectl.h delete mode 100644 usr/lib/libc/include/sys/dir.h delete mode 100644 usr/lib/libc/include/sys/epoll.h delete mode 100644 usr/lib/libc/include/sys/errno.h delete mode 100644 usr/lib/libc/include/sys/eventfd.h delete mode 100644 usr/lib/libc/include/sys/fanotify.h delete mode 100644 usr/lib/libc/include/sys/fcntl.h delete mode 100644 usr/lib/libc/include/sys/file.h delete mode 100644 usr/lib/libc/include/sys/fsuid.h delete mode 100644 usr/lib/libc/include/sys/inotify.h delete mode 100644 usr/lib/libc/include/sys/io.h delete mode 100644 usr/lib/libc/include/sys/ioctl.h delete mode 100644 usr/lib/libc/include/sys/ipc.h delete mode 100644 usr/lib/libc/include/sys/kd.h delete mode 100644 usr/lib/libc/include/sys/klog.h delete mode 100644 usr/lib/libc/include/sys/mman.h delete mode 100644 usr/lib/libc/include/sys/mount.h delete mode 100644 usr/lib/libc/include/sys/msg.h delete mode 100644 usr/lib/libc/include/sys/mtio.h delete mode 100644 usr/lib/libc/include/sys/param.h delete mode 100644 usr/lib/libc/include/sys/personality.h delete mode 100644 usr/lib/libc/include/sys/poll.h delete mode 100644 usr/lib/libc/include/sys/prctl.h delete mode 100644 usr/lib/libc/include/sys/procfs.h delete mode 100644 usr/lib/libc/include/sys/ptrace.h delete mode 100644 usr/lib/libc/include/sys/quota.h delete mode 100644 usr/lib/libc/include/sys/reboot.h delete mode 100644 usr/lib/libc/include/sys/reg.h delete mode 100644 usr/lib/libc/include/sys/resource.h delete mode 100644 usr/lib/libc/include/sys/select.h delete mode 100644 usr/lib/libc/include/sys/sem.h delete mode 100644 usr/lib/libc/include/sys/sendfile.h delete mode 100644 usr/lib/libc/include/sys/shm.h delete mode 100644 usr/lib/libc/include/sys/signal.h delete mode 100644 usr/lib/libc/include/sys/signalfd.h delete mode 100644 usr/lib/libc/include/sys/socket.h delete mode 100644 usr/lib/libc/include/sys/soundcard.h delete mode 100644 usr/lib/libc/include/sys/stat.h delete mode 100644 usr/lib/libc/include/sys/statfs.h delete mode 100644 usr/lib/libc/include/sys/statvfs.h delete mode 100644 usr/lib/libc/include/sys/stropts.h delete mode 100644 usr/lib/libc/include/sys/swap.h delete mode 100644 usr/lib/libc/include/sys/syscall.h delete mode 100644 usr/lib/libc/include/sys/sysinfo.h delete mode 100644 usr/lib/libc/include/sys/syslog.h delete mode 100644 usr/lib/libc/include/sys/sysmacros.h delete mode 100644 usr/lib/libc/include/sys/termios.h delete mode 100644 usr/lib/libc/include/sys/time.h delete mode 100644 usr/lib/libc/include/sys/timeb.h delete mode 100644 usr/lib/libc/include/sys/timerfd.h delete mode 100644 usr/lib/libc/include/sys/times.h delete mode 100644 usr/lib/libc/include/sys/timex.h delete mode 100644 usr/lib/libc/include/sys/ttydefaults.h delete mode 100644 usr/lib/libc/include/sys/types.h delete mode 100644 usr/lib/libc/include/sys/ucontext.h delete mode 100644 usr/lib/libc/include/sys/uio.h delete mode 100644 usr/lib/libc/include/sys/un.h delete mode 100644 usr/lib/libc/include/sys/user.h delete mode 100644 usr/lib/libc/include/sys/utsname.h delete mode 100644 usr/lib/libc/include/sys/vfs.h delete mode 100644 usr/lib/libc/include/sys/vt.h delete mode 100644 usr/lib/libc/include/sys/wait.h delete mode 100644 usr/lib/libc/include/sys/xattr.h delete mode 100644 usr/lib/libc/include/syscall.h delete mode 100644 usr/lib/libc/include/time.h delete mode 100644 usr/lib/libc/include/types.h delete mode 100644 usr/lib/libc/include/unistd.h delete mode 100644 usr/lib/libc/include/wchar.h delete mode 100644 usr/lib/libc/include/wctype.h delete mode 100644 usr/lib/libc/inet.c delete mode 100644 usr/lib/libc/intscan.c delete mode 100644 usr/lib/libc/libc.c delete mode 100644 usr/lib/libc/longjmp.S delete mode 100644 usr/lib/libc/malloc.c delete mode 100644 usr/lib/libc/malloc/CMakeLists.txt delete mode 100644 usr/lib/libc/malloc/DESIGN delete mode 100644 usr/lib/libc/malloc/__brk.c delete mode 100644 usr/lib/libc/malloc/aligned_alloc.c delete mode 100644 usr/lib/libc/malloc/calloc.c delete mode 100644 usr/lib/libc/malloc/expand_heap.c delete mode 100644 usr/lib/libc/malloc/lite_malloc.c delete mode 100644 usr/lib/libc/malloc/malloc.c delete mode 100644 usr/lib/libc/malloc/malloc_usable_size.c delete mode 100644 usr/lib/libc/malloc/memalign.c delete mode 100644 usr/lib/libc/malloc/posix_memalign.c delete mode 100644 usr/lib/libc/math/CMakeLists.txt delete mode 100644 usr/lib/libc/math/__cos.c delete mode 100644 usr/lib/libc/math/__cosdf.c delete mode 100644 usr/lib/libc/math/__cosl.c delete mode 100644 usr/lib/libc/math/__expo2.c delete mode 100644 usr/lib/libc/math/__expo2f.c delete mode 100644 usr/lib/libc/math/__fpclassify.c delete mode 100644 usr/lib/libc/math/__fpclassifyf.c delete mode 100644 usr/lib/libc/math/__fpclassifyl.c delete mode 100644 usr/lib/libc/math/__invtrigl.c delete mode 100644 usr/lib/libc/math/__invtrigl.h delete mode 100644 usr/lib/libc/math/__polevll.c delete mode 100644 usr/lib/libc/math/__rem_pio2.c delete mode 100644 usr/lib/libc/math/__rem_pio2_large.c delete mode 100644 usr/lib/libc/math/__rem_pio2f.c delete mode 100644 usr/lib/libc/math/__rem_pio2l.c delete mode 100644 usr/lib/libc/math/__signbit.c delete mode 100644 usr/lib/libc/math/__signbitf.c delete mode 100644 usr/lib/libc/math/__signbitl.c delete mode 100644 usr/lib/libc/math/__sin.c delete mode 100644 usr/lib/libc/math/__sindf.c delete mode 100644 usr/lib/libc/math/__sinl.c delete mode 100644 usr/lib/libc/math/__tan.c delete mode 100644 usr/lib/libc/math/__tandf.c delete mode 100644 usr/lib/libc/math/__tanl.c delete mode 100644 usr/lib/libc/math/acos.c delete mode 100644 usr/lib/libc/math/acosf.c delete mode 100644 usr/lib/libc/math/acosh.c delete mode 100644 usr/lib/libc/math/acoshf.c delete mode 100644 usr/lib/libc/math/acoshl.c delete mode 100644 usr/lib/libc/math/acosl.c delete mode 100644 usr/lib/libc/math/asin.c delete mode 100644 usr/lib/libc/math/asinf.c delete mode 100644 usr/lib/libc/math/asinh.c delete mode 100644 usr/lib/libc/math/asinhf.c delete mode 100644 usr/lib/libc/math/asinhl.c delete mode 100644 usr/lib/libc/math/asinl.c delete mode 100644 usr/lib/libc/math/atan.c delete mode 100644 usr/lib/libc/math/atan2.c delete mode 100644 usr/lib/libc/math/atan2f.c delete mode 100644 usr/lib/libc/math/atan2l.c delete mode 100644 usr/lib/libc/math/atanf.c delete mode 100644 usr/lib/libc/math/atanh.c delete mode 100644 usr/lib/libc/math/atanhf.c delete mode 100644 usr/lib/libc/math/atanhl.c delete mode 100644 usr/lib/libc/math/atanl.c delete mode 100644 usr/lib/libc/math/cbrt.c delete mode 100644 usr/lib/libc/math/cbrtf.c delete mode 100644 usr/lib/libc/math/cbrtl.c delete mode 100644 usr/lib/libc/math/ceil.c delete mode 100644 usr/lib/libc/math/ceilf.c delete mode 100644 usr/lib/libc/math/ceill.c delete mode 100644 usr/lib/libc/math/copysign.c delete mode 100644 usr/lib/libc/math/copysignf.c delete mode 100644 usr/lib/libc/math/copysignl.c delete mode 100644 usr/lib/libc/math/cos.c delete mode 100644 usr/lib/libc/math/cosf.c delete mode 100644 usr/lib/libc/math/cosh.c delete mode 100644 usr/lib/libc/math/coshf.c delete mode 100644 usr/lib/libc/math/coshl.c delete mode 100644 usr/lib/libc/math/cosl.c delete mode 100644 usr/lib/libc/math/erf.c delete mode 100644 usr/lib/libc/math/erff.c delete mode 100644 usr/lib/libc/math/erfl.c delete mode 100644 usr/lib/libc/math/exp.c delete mode 100644 usr/lib/libc/math/exp10.c delete mode 100644 usr/lib/libc/math/exp10f.c delete mode 100644 usr/lib/libc/math/exp10l.c delete mode 100644 usr/lib/libc/math/exp2.c delete mode 100644 usr/lib/libc/math/exp2f.c delete mode 100644 usr/lib/libc/math/exp2l.c delete mode 100644 usr/lib/libc/math/expf.c delete mode 100644 usr/lib/libc/math/expl.c delete mode 100644 usr/lib/libc/math/expm1.c delete mode 100644 usr/lib/libc/math/expm1f.c delete mode 100644 usr/lib/libc/math/expm1l.c delete mode 100644 usr/lib/libc/math/fabs.c delete mode 100644 usr/lib/libc/math/fabsf.c delete mode 100644 usr/lib/libc/math/fabsl.c delete mode 100644 usr/lib/libc/math/fdim.c delete mode 100644 usr/lib/libc/math/fdimf.c delete mode 100644 usr/lib/libc/math/fdiml.c delete mode 100644 usr/lib/libc/math/finite.c delete mode 100644 usr/lib/libc/math/finitef.c delete mode 100644 usr/lib/libc/math/floor.c delete mode 100644 usr/lib/libc/math/floorf.c delete mode 100644 usr/lib/libc/math/floorl.c delete mode 100644 usr/lib/libc/math/fma.c delete mode 100644 usr/lib/libc/math/fmaf.c delete mode 100644 usr/lib/libc/math/fmal.c delete mode 100644 usr/lib/libc/math/fmax.c delete mode 100644 usr/lib/libc/math/fmaxf.c delete mode 100644 usr/lib/libc/math/fmaxl.c delete mode 100644 usr/lib/libc/math/fmin.c delete mode 100644 usr/lib/libc/math/fminf.c delete mode 100644 usr/lib/libc/math/fminl.c delete mode 100644 usr/lib/libc/math/fmod.c delete mode 100644 usr/lib/libc/math/fmodf.c delete mode 100644 usr/lib/libc/math/fmodl.c delete mode 100644 usr/lib/libc/math/frexp.c delete mode 100644 usr/lib/libc/math/frexpf.c delete mode 100644 usr/lib/libc/math/frexpl.c delete mode 100644 usr/lib/libc/math/hypot.c delete mode 100644 usr/lib/libc/math/hypotf.c delete mode 100644 usr/lib/libc/math/hypotl.c delete mode 100644 usr/lib/libc/math/ilogb.c delete mode 100644 usr/lib/libc/math/ilogbf.c delete mode 100644 usr/lib/libc/math/ilogbl.c delete mode 100644 usr/lib/libc/math/j0.c delete mode 100644 usr/lib/libc/math/j0f.c delete mode 100644 usr/lib/libc/math/j1.c delete mode 100644 usr/lib/libc/math/j1f.c delete mode 100644 usr/lib/libc/math/jn.c delete mode 100644 usr/lib/libc/math/jnf.c delete mode 100644 usr/lib/libc/math/ldexp.c delete mode 100644 usr/lib/libc/math/ldexpf.c delete mode 100644 usr/lib/libc/math/ldexpl.c delete mode 100644 usr/lib/libc/math/lgamma.c delete mode 100644 usr/lib/libc/math/lgamma_r.c delete mode 100644 usr/lib/libc/math/lgammaf.c delete mode 100644 usr/lib/libc/math/lgammaf_r.c delete mode 100644 usr/lib/libc/math/lgammal.c delete mode 100644 usr/lib/libc/math/llrint.c delete mode 100644 usr/lib/libc/math/llrintf.c delete mode 100644 usr/lib/libc/math/llrintl.c delete mode 100644 usr/lib/libc/math/llround.c delete mode 100644 usr/lib/libc/math/llroundf.c delete mode 100644 usr/lib/libc/math/llroundl.c delete mode 100644 usr/lib/libc/math/log.c delete mode 100644 usr/lib/libc/math/log10.c delete mode 100644 usr/lib/libc/math/log10f.c delete mode 100644 usr/lib/libc/math/log10l.c delete mode 100644 usr/lib/libc/math/log1p.c delete mode 100644 usr/lib/libc/math/log1pf.c delete mode 100644 usr/lib/libc/math/log1pl.c delete mode 100644 usr/lib/libc/math/log2.c delete mode 100644 usr/lib/libc/math/log2f.c delete mode 100644 usr/lib/libc/math/log2l.c delete mode 100644 usr/lib/libc/math/logb.c delete mode 100644 usr/lib/libc/math/logbf.c delete mode 100644 usr/lib/libc/math/logbl.c delete mode 100644 usr/lib/libc/math/logf.c delete mode 100644 usr/lib/libc/math/logl.c delete mode 100644 usr/lib/libc/math/lrint.c delete mode 100644 usr/lib/libc/math/lrintf.c delete mode 100644 usr/lib/libc/math/lrintl.c delete mode 100644 usr/lib/libc/math/lround.c delete mode 100644 usr/lib/libc/math/lroundf.c delete mode 100644 usr/lib/libc/math/lroundl.c delete mode 100644 usr/lib/libc/math/modf.c delete mode 100644 usr/lib/libc/math/modff.c delete mode 100644 usr/lib/libc/math/modfl.c delete mode 100644 usr/lib/libc/math/nan.c delete mode 100644 usr/lib/libc/math/nanf.c delete mode 100644 usr/lib/libc/math/nanl.c delete mode 100644 usr/lib/libc/math/nearbyint.c delete mode 100644 usr/lib/libc/math/nearbyintf.c delete mode 100644 usr/lib/libc/math/nearbyintl.c delete mode 100644 usr/lib/libc/math/nextafter.c delete mode 100644 usr/lib/libc/math/nextafterf.c delete mode 100644 usr/lib/libc/math/nextafterl.c delete mode 100644 usr/lib/libc/math/nexttoward.c delete mode 100644 usr/lib/libc/math/nexttowardf.c delete mode 100644 usr/lib/libc/math/nexttowardl.c delete mode 100644 usr/lib/libc/math/pow.c delete mode 100644 usr/lib/libc/math/powf.c delete mode 100644 usr/lib/libc/math/powl.c delete mode 100644 usr/lib/libc/math/remainder.c delete mode 100644 usr/lib/libc/math/remainderf.c delete mode 100644 usr/lib/libc/math/remainderl.c delete mode 100644 usr/lib/libc/math/remquo.c delete mode 100644 usr/lib/libc/math/remquof.c delete mode 100644 usr/lib/libc/math/remquol.c delete mode 100644 usr/lib/libc/math/rint.c delete mode 100644 usr/lib/libc/math/rintf.c delete mode 100644 usr/lib/libc/math/rintl.c delete mode 100644 usr/lib/libc/math/round.c delete mode 100644 usr/lib/libc/math/roundf.c delete mode 100644 usr/lib/libc/math/roundl.c delete mode 100644 usr/lib/libc/math/scalb.c delete mode 100644 usr/lib/libc/math/scalbf.c delete mode 100644 usr/lib/libc/math/scalbln.c delete mode 100644 usr/lib/libc/math/scalblnf.c delete mode 100644 usr/lib/libc/math/scalblnl.c delete mode 100644 usr/lib/libc/math/scalbn.c delete mode 100644 usr/lib/libc/math/scalbnf.c delete mode 100644 usr/lib/libc/math/scalbnl.c delete mode 100644 usr/lib/libc/math/signgam.c delete mode 100644 usr/lib/libc/math/significand.c delete mode 100644 usr/lib/libc/math/significandf.c delete mode 100644 usr/lib/libc/math/sin.c delete mode 100644 usr/lib/libc/math/sincos.c delete mode 100644 usr/lib/libc/math/sincosf.c delete mode 100644 usr/lib/libc/math/sincosl.c delete mode 100644 usr/lib/libc/math/sinf.c delete mode 100644 usr/lib/libc/math/sinh.c delete mode 100644 usr/lib/libc/math/sinhf.c delete mode 100644 usr/lib/libc/math/sinhl.c delete mode 100644 usr/lib/libc/math/sinl.c delete mode 100644 usr/lib/libc/math/sqrt.c delete mode 100644 usr/lib/libc/math/sqrtf.c delete mode 100644 usr/lib/libc/math/sqrtl.c delete mode 100644 usr/lib/libc/math/tan.c delete mode 100644 usr/lib/libc/math/tanf.c delete mode 100644 usr/lib/libc/math/tanh.c delete mode 100644 usr/lib/libc/math/tanhf.c delete mode 100644 usr/lib/libc/math/tanhl.c delete mode 100644 usr/lib/libc/math/tanl.c delete mode 100644 usr/lib/libc/math/tgamma.c delete mode 100644 usr/lib/libc/math/tgammaf.c delete mode 100644 usr/lib/libc/math/tgammal.c delete mode 100644 usr/lib/libc/math/trunc.c delete mode 100644 usr/lib/libc/math/truncf.c delete mode 100644 usr/lib/libc/math/truncl.c delete mode 100644 usr/lib/libc/mbsinit.c delete mode 100644 usr/lib/libc/misc/CMakeLists.txt delete mode 100644 usr/lib/libc/misc/a64l.c delete mode 100644 usr/lib/libc/misc/basename.c delete mode 100644 usr/lib/libc/misc/dirname.c delete mode 100644 usr/lib/libc/misc/ffs.c delete mode 100644 usr/lib/libc/misc/ffsl.c delete mode 100644 usr/lib/libc/misc/ffsll.c delete mode 100644 usr/lib/libc/misc/fmtmsg.c delete mode 100644 usr/lib/libc/misc/forkpty.c delete mode 100644 usr/lib/libc/misc/get_current_dir_name.c delete mode 100644 usr/lib/libc/misc/getauxval.c delete mode 100644 usr/lib/libc/misc/getdomainname.c delete mode 100644 usr/lib/libc/misc/gethostid.c delete mode 100644 usr/lib/libc/misc/getopt.c delete mode 100644 usr/lib/libc/misc/getopt_long.c delete mode 100644 usr/lib/libc/misc/getpriority.c delete mode 100644 usr/lib/libc/misc/getresgid.c delete mode 100644 usr/lib/libc/misc/getresuid.c delete mode 100644 usr/lib/libc/misc/getrlimit.c delete mode 100644 usr/lib/libc/misc/getrusage.c delete mode 100644 usr/lib/libc/misc/getsubopt.c delete mode 100644 usr/lib/libc/misc/initgroups.c delete mode 100644 usr/lib/libc/misc/ioctl.c delete mode 100644 usr/lib/libc/misc/issetugid.c delete mode 100644 usr/lib/libc/misc/lockf.c delete mode 100644 usr/lib/libc/misc/login_tty.c delete mode 100644 usr/lib/libc/misc/mntent.c delete mode 100644 usr/lib/libc/misc/nftw.c delete mode 100644 usr/lib/libc/misc/openpty.c delete mode 100644 usr/lib/libc/misc/ptsname.c delete mode 100644 usr/lib/libc/misc/pty.c delete mode 100644 usr/lib/libc/misc/realpath.c delete mode 100644 usr/lib/libc/misc/setdomainname.c delete mode 100644 usr/lib/libc/misc/setpriority.c delete mode 100644 usr/lib/libc/misc/setrlimit.c delete mode 100644 usr/lib/libc/misc/stat.c delete mode 100644 usr/lib/libc/misc/syslog.c delete mode 100644 usr/lib/libc/misc/uname.c delete mode 100644 usr/lib/libc/misc/wordexp.c delete mode 100644 usr/lib/libc/mman/CMakeLists.txt delete mode 100644 usr/lib/libc/mman/madvise.c delete mode 100644 usr/lib/libc/mman/mincore.c delete mode 100644 usr/lib/libc/mman/mlock.c delete mode 100644 usr/lib/libc/mman/mlockall.c delete mode 100644 usr/lib/libc/mman/mmap.c delete mode 100644 usr/lib/libc/mman/mprotect.c delete mode 100644 usr/lib/libc/mman/mremap.c delete mode 100644 usr/lib/libc/mman/msync.c delete mode 100644 usr/lib/libc/mman/munlock.c delete mode 100644 usr/lib/libc/mman/munlockall.c delete mode 100644 usr/lib/libc/mman/munmap.c delete mode 100644 usr/lib/libc/mman/posix_madvise.c delete mode 100644 usr/lib/libc/mman/shm_open.c delete mode 100644 usr/lib/libc/multibyte/CMakeLists.txt delete mode 100644 usr/lib/libc/multibyte/btowc.c delete mode 100644 usr/lib/libc/multibyte/c16rtomb.c delete mode 100644 usr/lib/libc/multibyte/c32rtomb.c delete mode 100644 usr/lib/libc/multibyte/internal.c delete mode 100644 usr/lib/libc/multibyte/internal.h delete mode 100644 usr/lib/libc/multibyte/mblen.c delete mode 100644 usr/lib/libc/multibyte/mbrlen.c delete mode 100644 usr/lib/libc/multibyte/mbrtoc16.c delete mode 100644 usr/lib/libc/multibyte/mbrtoc32.c delete mode 100644 usr/lib/libc/multibyte/mbrtowc.c delete mode 100644 usr/lib/libc/multibyte/mbsinit.c delete mode 100644 usr/lib/libc/multibyte/mbsnrtowcs.c delete mode 100644 usr/lib/libc/multibyte/mbsrtowcs.c delete mode 100644 usr/lib/libc/multibyte/mbstowcs.c delete mode 100644 usr/lib/libc/multibyte/mbtowc.c delete mode 100644 usr/lib/libc/multibyte/wcrtomb.c delete mode 100644 usr/lib/libc/multibyte/wcsnrtombs.c delete mode 100644 usr/lib/libc/multibyte/wcsrtombs.c delete mode 100644 usr/lib/libc/multibyte/wcstombs.c delete mode 100644 usr/lib/libc/multibyte/wctob.c delete mode 100644 usr/lib/libc/multibyte/wctomb.c delete mode 100644 usr/lib/libc/mutex.c delete mode 100644 usr/lib/libc/network/CMakeLists.txt delete mode 100644 usr/lib/libc/network/accept.c delete mode 100644 usr/lib/libc/network/accept4.c delete mode 100644 usr/lib/libc/network/bind.c delete mode 100644 usr/lib/libc/network/connect.c delete mode 100644 usr/lib/libc/network/dn_comp.c delete mode 100644 usr/lib/libc/network/dn_expand.c delete mode 100644 usr/lib/libc/network/dn_skipname.c delete mode 100644 usr/lib/libc/network/dns_parse.c delete mode 100644 usr/lib/libc/network/ent.c delete mode 100644 usr/lib/libc/network/ether.c delete mode 100644 usr/lib/libc/network/freeaddrinfo.c delete mode 100644 usr/lib/libc/network/gai_strerror.c delete mode 100644 usr/lib/libc/network/getaddrinfo.c delete mode 100644 usr/lib/libc/network/gethostbyaddr.c delete mode 100644 usr/lib/libc/network/gethostbyaddr_r.c delete mode 100644 usr/lib/libc/network/gethostbyname.c delete mode 100644 usr/lib/libc/network/gethostbyname2.c delete mode 100644 usr/lib/libc/network/gethostbyname2_r.c delete mode 100644 usr/lib/libc/network/gethostbyname_r.c delete mode 100644 usr/lib/libc/network/getifaddrs.c delete mode 100644 usr/lib/libc/network/getnameinfo.c delete mode 100644 usr/lib/libc/network/getpeername.c delete mode 100644 usr/lib/libc/network/getservbyname.c delete mode 100644 usr/lib/libc/network/getservbyname_r.c delete mode 100644 usr/lib/libc/network/getservbyport.c delete mode 100644 usr/lib/libc/network/getservbyport_r.c delete mode 100644 usr/lib/libc/network/getsockname.c delete mode 100644 usr/lib/libc/network/getsockopt.c delete mode 100644 usr/lib/libc/network/h_errno.c delete mode 100644 usr/lib/libc/network/herror.c delete mode 100644 usr/lib/libc/network/hstrerror.c delete mode 100644 usr/lib/libc/network/htonl.c delete mode 100644 usr/lib/libc/network/htons.c delete mode 100644 usr/lib/libc/network/if_freenameindex.c delete mode 100644 usr/lib/libc/network/if_indextoname.c delete mode 100644 usr/lib/libc/network/if_nameindex.c delete mode 100644 usr/lib/libc/network/if_nametoindex.c delete mode 100644 usr/lib/libc/network/in6addr_any.c delete mode 100644 usr/lib/libc/network/in6addr_loopback.c delete mode 100644 usr/lib/libc/network/inet_addr.c delete mode 100644 usr/lib/libc/network/inet_aton.c delete mode 100644 usr/lib/libc/network/inet_legacy.c delete mode 100644 usr/lib/libc/network/inet_ntoa.c delete mode 100644 usr/lib/libc/network/inet_ntop.c delete mode 100644 usr/lib/libc/network/inet_pton.c delete mode 100644 usr/lib/libc/network/listen.c delete mode 100644 usr/lib/libc/network/lookup.h delete mode 100644 usr/lib/libc/network/lookup_ipliteral.c delete mode 100644 usr/lib/libc/network/lookup_name.c delete mode 100644 usr/lib/libc/network/lookup_serv.c delete mode 100644 usr/lib/libc/network/netlink.c delete mode 100644 usr/lib/libc/network/netlink.h delete mode 100644 usr/lib/libc/network/netname.c delete mode 100644 usr/lib/libc/network/ns_parse.c delete mode 100644 usr/lib/libc/network/ntohl.c delete mode 100644 usr/lib/libc/network/ntohs.c delete mode 100644 usr/lib/libc/network/proto.c delete mode 100644 usr/lib/libc/network/recv.c delete mode 100644 usr/lib/libc/network/recvfrom.c delete mode 100644 usr/lib/libc/network/recvmmsg.c delete mode 100644 usr/lib/libc/network/recvmsg.c delete mode 100644 usr/lib/libc/network/res_init.c delete mode 100644 usr/lib/libc/network/res_mkquery.c delete mode 100644 usr/lib/libc/network/res_msend.c delete mode 100644 usr/lib/libc/network/res_query.c delete mode 100644 usr/lib/libc/network/res_querydomain.c delete mode 100644 usr/lib/libc/network/res_send.c delete mode 100644 usr/lib/libc/network/res_state.c delete mode 100644 usr/lib/libc/network/resolvconf.c delete mode 100644 usr/lib/libc/network/send.c delete mode 100644 usr/lib/libc/network/sendmmsg.c delete mode 100644 usr/lib/libc/network/sendmsg.c delete mode 100644 usr/lib/libc/network/sendto.c delete mode 100644 usr/lib/libc/network/serv.c delete mode 100644 usr/lib/libc/network/setsockopt.c delete mode 100644 usr/lib/libc/network/shutdown.c delete mode 100644 usr/lib/libc/network/sockatmark.c delete mode 100644 usr/lib/libc/network/socket.c delete mode 100644 usr/lib/libc/network/socketpair.c delete mode 100644 usr/lib/libc/prng/CMakeLists.txt delete mode 100644 usr/lib/libc/prng/__rand48_step.c delete mode 100644 usr/lib/libc/prng/__seed48.c delete mode 100644 usr/lib/libc/prng/drand48.c delete mode 100644 usr/lib/libc/prng/lcong48.c delete mode 100644 usr/lib/libc/prng/lrand48.c delete mode 100644 usr/lib/libc/prng/mrand48.c delete mode 100644 usr/lib/libc/prng/rand.c delete mode 100644 usr/lib/libc/prng/rand_r.c delete mode 100644 usr/lib/libc/prng/random.c delete mode 100644 usr/lib/libc/prng/seed48.c delete mode 100644 usr/lib/libc/prng/srand48.c delete mode 100644 usr/lib/libc/process/CMakeLists.txt delete mode 100644 usr/lib/libc/process/execl.c delete mode 100644 usr/lib/libc/process/execle.c delete mode 100644 usr/lib/libc/process/execlp.c delete mode 100644 usr/lib/libc/process/execv.c delete mode 100644 usr/lib/libc/process/execve.c delete mode 100644 usr/lib/libc/process/execvp.c delete mode 100644 usr/lib/libc/process/fexecve.c delete mode 100644 usr/lib/libc/process/fork.c delete mode 100644 usr/lib/libc/process/posix_spawn.c delete mode 100644 usr/lib/libc/process/posix_spawn_file_actions_addclose.c delete mode 100644 usr/lib/libc/process/posix_spawn_file_actions_adddup2.c delete mode 100644 usr/lib/libc/process/posix_spawn_file_actions_addopen.c delete mode 100644 usr/lib/libc/process/posix_spawn_file_actions_destroy.c delete mode 100644 usr/lib/libc/process/posix_spawn_file_actions_init.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_destroy.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_getflags.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_getpgroup.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_getsigdefault.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_getsigmask.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_init.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_sched.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_setflags.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_setpgroup.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_setsigdefault.c delete mode 100644 usr/lib/libc/process/posix_spawnattr_setsigmask.c delete mode 100644 usr/lib/libc/process/posix_spawnp.c delete mode 100644 usr/lib/libc/process/ptrace.c delete mode 100644 usr/lib/libc/process/system.c delete mode 100644 usr/lib/libc/process/vfork.c delete mode 100644 usr/lib/libc/process/wait.c delete mode 100644 usr/lib/libc/process/waitid.c delete mode 100644 usr/lib/libc/process/waitpid.c delete mode 100644 usr/lib/libc/pthread.c delete mode 100644 usr/lib/libc/sbrk.c delete mode 100644 usr/lib/libc/setjmp.S delete mode 100644 usr/lib/libc/shgetc.c delete mode 100644 usr/lib/libc/signal/CMakeLists.txt delete mode 100644 usr/lib/libc/signal/block.c delete mode 100644 usr/lib/libc/signal/getitimer.c delete mode 100644 usr/lib/libc/signal/handler delete mode 100644 usr/lib/libc/signal/kill.c delete mode 100644 usr/lib/libc/signal/killpg.c delete mode 100644 usr/lib/libc/signal/psiginfo.c delete mode 100644 usr/lib/libc/signal/psignal.c delete mode 100644 usr/lib/libc/signal/raise.c delete mode 100644 usr/lib/libc/signal/restore.c delete mode 100644 usr/lib/libc/signal/setitimer.c delete mode 100644 usr/lib/libc/signal/sigaction.c delete mode 100644 usr/lib/libc/signal/sigaddset.c delete mode 100644 usr/lib/libc/signal/sigaltstack.c delete mode 100644 usr/lib/libc/signal/sigandset.c delete mode 100644 usr/lib/libc/signal/sigdelset.c delete mode 100644 usr/lib/libc/signal/sigemptyset.c delete mode 100644 usr/lib/libc/signal/sigfillset.c delete mode 100644 usr/lib/libc/signal/sighold.c delete mode 100644 usr/lib/libc/signal/sigignore.c delete mode 100644 usr/lib/libc/signal/siginterrupt.c delete mode 100644 usr/lib/libc/signal/sigisemptyset.c delete mode 100644 usr/lib/libc/signal/sigismember.c delete mode 100644 usr/lib/libc/signal/siglongjmp.c delete mode 100644 usr/lib/libc/signal/signal.c delete mode 100644 usr/lib/libc/signal/sigorset.c delete mode 100644 usr/lib/libc/signal/sigpause.c delete mode 100644 usr/lib/libc/signal/sigpending.c delete mode 100644 usr/lib/libc/signal/sigprocmask.c delete mode 100644 usr/lib/libc/signal/sigqueue.c delete mode 100644 usr/lib/libc/signal/sigrelse.c delete mode 100644 usr/lib/libc/signal/sigrtmax.c delete mode 100644 usr/lib/libc/signal/sigrtmin.c delete mode 100644 usr/lib/libc/signal/sigset.c delete mode 100644 usr/lib/libc/signal/sigsetjmp.c delete mode 100644 usr/lib/libc/signal/sigsetjmp_tail.c delete mode 100644 usr/lib/libc/signal/sigsuspend.c delete mode 100644 usr/lib/libc/signal/sigtimedwait.c delete mode 100644 usr/lib/libc/signal/sigwait.c delete mode 100644 usr/lib/libc/signal/sigwaitinfo.c delete mode 100644 usr/lib/libc/stdarg.h delete mode 100644 usr/lib/libc/stdio/CMakeLists.txt delete mode 100644 usr/lib/libc/stdio/__fclose_ca.c delete mode 100644 usr/lib/libc/stdio/__fdopen.c delete mode 100644 usr/lib/libc/stdio/__fmodeflags.c delete mode 100644 usr/lib/libc/stdio/__fopen_rb_ca.c delete mode 100644 usr/lib/libc/stdio/__lockfile.c delete mode 100644 usr/lib/libc/stdio/__overflow.c delete mode 100644 usr/lib/libc/stdio/__stdio_close.c delete mode 100644 usr/lib/libc/stdio/__stdio_exit.c delete mode 100644 usr/lib/libc/stdio/__stdio_read.c delete mode 100644 usr/lib/libc/stdio/__stdio_seek.c delete mode 100644 usr/lib/libc/stdio/__stdio_write.c delete mode 100644 usr/lib/libc/stdio/__stdout_write.c delete mode 100644 usr/lib/libc/stdio/__string_read.c delete mode 100644 usr/lib/libc/stdio/__toread.c delete mode 100644 usr/lib/libc/stdio/__towrite.c delete mode 100644 usr/lib/libc/stdio/__uflow.c delete mode 100644 usr/lib/libc/stdio/asprintf.c delete mode 100644 usr/lib/libc/stdio/clearerr.c delete mode 100644 usr/lib/libc/stdio/dprintf.c delete mode 100644 usr/lib/libc/stdio/ext.c delete mode 100644 usr/lib/libc/stdio/ext2.c delete mode 100644 usr/lib/libc/stdio/fclose.c delete mode 100644 usr/lib/libc/stdio/feof.c delete mode 100644 usr/lib/libc/stdio/ferror.c delete mode 100644 usr/lib/libc/stdio/fflush.c delete mode 100644 usr/lib/libc/stdio/fgetc.c delete mode 100644 usr/lib/libc/stdio/fgetln.c delete mode 100644 usr/lib/libc/stdio/fgetpos.c delete mode 100644 usr/lib/libc/stdio/fgets.c delete mode 100644 usr/lib/libc/stdio/fgetwc.c delete mode 100644 usr/lib/libc/stdio/fgetws.c delete mode 100644 usr/lib/libc/stdio/fileno.c delete mode 100644 usr/lib/libc/stdio/flockfile.c delete mode 100644 usr/lib/libc/stdio/fmemopen.c delete mode 100644 usr/lib/libc/stdio/fopen.c delete mode 100644 usr/lib/libc/stdio/fprintf.c delete mode 100644 usr/lib/libc/stdio/fputc.c delete mode 100644 usr/lib/libc/stdio/fputs.c delete mode 100644 usr/lib/libc/stdio/fputwc.c delete mode 100644 usr/lib/libc/stdio/fputws.c delete mode 100644 usr/lib/libc/stdio/fread.c delete mode 100644 usr/lib/libc/stdio/freopen.c delete mode 100644 usr/lib/libc/stdio/fscanf.c delete mode 100644 usr/lib/libc/stdio/fseek.c delete mode 100644 usr/lib/libc/stdio/fsetpos.c delete mode 100644 usr/lib/libc/stdio/ftell.c delete mode 100644 usr/lib/libc/stdio/ftrylockfile.c delete mode 100644 usr/lib/libc/stdio/funlockfile.c delete mode 100644 usr/lib/libc/stdio/fwide.c delete mode 100644 usr/lib/libc/stdio/fwprintf.c delete mode 100644 usr/lib/libc/stdio/fwrite.c delete mode 100644 usr/lib/libc/stdio/fwscanf.c delete mode 100644 usr/lib/libc/stdio/getc.c delete mode 100644 usr/lib/libc/stdio/getc_unlocked.c delete mode 100644 usr/lib/libc/stdio/getchar.c delete mode 100644 usr/lib/libc/stdio/getchar_unlocked.c delete mode 100644 usr/lib/libc/stdio/getdelim.c delete mode 100644 usr/lib/libc/stdio/getline.c delete mode 100644 usr/lib/libc/stdio/gets.c delete mode 100644 usr/lib/libc/stdio/getw.c delete mode 100644 usr/lib/libc/stdio/getwc.c delete mode 100644 usr/lib/libc/stdio/getwchar.c delete mode 100644 usr/lib/libc/stdio/ofl.c delete mode 100644 usr/lib/libc/stdio/ofl_add.c delete mode 100644 usr/lib/libc/stdio/open_memstream.c delete mode 100644 usr/lib/libc/stdio/open_wmemstream.c delete mode 100644 usr/lib/libc/stdio/pclose.c delete mode 100644 usr/lib/libc/stdio/perror.c delete mode 100644 usr/lib/libc/stdio/popen.c delete mode 100644 usr/lib/libc/stdio/printf.c delete mode 100644 usr/lib/libc/stdio/putc.c delete mode 100644 usr/lib/libc/stdio/putc_unlocked.c delete mode 100644 usr/lib/libc/stdio/putchar.c delete mode 100644 usr/lib/libc/stdio/putchar_unlocked.c delete mode 100644 usr/lib/libc/stdio/puts.c delete mode 100644 usr/lib/libc/stdio/putw.c delete mode 100644 usr/lib/libc/stdio/putwc.c delete mode 100644 usr/lib/libc/stdio/putwchar.c delete mode 100644 usr/lib/libc/stdio/remove.c delete mode 100644 usr/lib/libc/stdio/rename.c delete mode 100644 usr/lib/libc/stdio/rewind.c delete mode 100644 usr/lib/libc/stdio/scanf.c delete mode 100644 usr/lib/libc/stdio/setbuf.c delete mode 100644 usr/lib/libc/stdio/setbuffer.c delete mode 100644 usr/lib/libc/stdio/setlinebuf.c delete mode 100644 usr/lib/libc/stdio/setvbuf.c delete mode 100644 usr/lib/libc/stdio/snprintf.c delete mode 100644 usr/lib/libc/stdio/sprintf.c delete mode 100644 usr/lib/libc/stdio/sscanf.c delete mode 100644 usr/lib/libc/stdio/stderr.c delete mode 100644 usr/lib/libc/stdio/stdin.c delete mode 100644 usr/lib/libc/stdio/stdout.c delete mode 100644 usr/lib/libc/stdio/swprintf.c delete mode 100644 usr/lib/libc/stdio/swscanf.c delete mode 100644 usr/lib/libc/stdio/tempnam.c delete mode 100644 usr/lib/libc/stdio/tmpfile.c delete mode 100644 usr/lib/libc/stdio/tmpnam.c delete mode 100644 usr/lib/libc/stdio/ungetc.c delete mode 100644 usr/lib/libc/stdio/ungetwc.c delete mode 100644 usr/lib/libc/stdio/vasprintf.c delete mode 100644 usr/lib/libc/stdio/vdprintf.c delete mode 100644 usr/lib/libc/stdio/vfprintf.c delete mode 100644 usr/lib/libc/stdio/vfscanf.c delete mode 100644 usr/lib/libc/stdio/vfwprintf.c delete mode 100644 usr/lib/libc/stdio/vfwscanf.c delete mode 100644 usr/lib/libc/stdio/vprintf.c delete mode 100644 usr/lib/libc/stdio/vscanf.c delete mode 100644 usr/lib/libc/stdio/vsnprintf.c delete mode 100644 usr/lib/libc/stdio/vsprintf.c delete mode 100644 usr/lib/libc/stdio/vsscanf.c delete mode 100644 usr/lib/libc/stdio/vswprintf.c delete mode 100644 usr/lib/libc/stdio/vswscanf.c delete mode 100644 usr/lib/libc/stdio/vwprintf.c delete mode 100644 usr/lib/libc/stdio/vwscanf.c delete mode 100644 usr/lib/libc/stdio/wprintf.c delete mode 100644 usr/lib/libc/stdio/wscanf.c delete mode 100644 usr/lib/libc/stdlib.c delete mode 100644 usr/lib/libc/stdlib/CMakeLists.txt delete mode 100644 usr/lib/libc/stdlib/abs.c delete mode 100644 usr/lib/libc/stdlib/atof.c delete mode 100644 usr/lib/libc/stdlib/atoi.c delete mode 100644 usr/lib/libc/stdlib/atol.c delete mode 100644 usr/lib/libc/stdlib/atoll.c delete mode 100644 usr/lib/libc/stdlib/bsearch.c delete mode 100644 usr/lib/libc/stdlib/div.c delete mode 100644 usr/lib/libc/stdlib/ecvt.c delete mode 100644 usr/lib/libc/stdlib/fcvt.c delete mode 100644 usr/lib/libc/stdlib/gcvt.c delete mode 100644 usr/lib/libc/stdlib/imaxabs.c delete mode 100644 usr/lib/libc/stdlib/imaxdiv.c delete mode 100644 usr/lib/libc/stdlib/labs.c delete mode 100644 usr/lib/libc/stdlib/ldiv.c delete mode 100644 usr/lib/libc/stdlib/llabs.c delete mode 100644 usr/lib/libc/stdlib/lldiv.c delete mode 100644 usr/lib/libc/stdlib/qsort.c delete mode 100644 usr/lib/libc/stdlib/strtod.c delete mode 100644 usr/lib/libc/stdlib/strtol.c delete mode 100644 usr/lib/libc/stdlib/wcstod.c delete mode 100644 usr/lib/libc/stdlib/wcstol.c delete mode 100644 usr/lib/libc/string/CMakeLists.txt delete mode 100644 usr/lib/libc/string/arm/__aeabi_memclr.c delete mode 100644 usr/lib/libc/string/arm/__aeabi_memcpy.c delete mode 100644 usr/lib/libc/string/arm/__aeabi_memmove.c delete mode 100644 usr/lib/libc/string/arm/__aeabi_memset.c delete mode 100644 usr/lib/libc/string/arm/memcpy.c delete mode 100644 usr/lib/libc/string/arm/memcpy_le.S delete mode 100644 usr/lib/libc/string/bcmp.c delete mode 100644 usr/lib/libc/string/bcopy.c delete mode 100644 usr/lib/libc/string/bzero.c delete mode 100644 usr/lib/libc/string/index.c delete mode 100644 usr/lib/libc/string/memccpy.c delete mode 100644 usr/lib/libc/string/memchr.c delete mode 100644 usr/lib/libc/string/memcmp.c delete mode 100644 usr/lib/libc/string/memcpy.c delete mode 100644 usr/lib/libc/string/memmem.c delete mode 100644 usr/lib/libc/string/memmove.c delete mode 100644 usr/lib/libc/string/mempcpy.c delete mode 100644 usr/lib/libc/string/memrchr.c delete mode 100644 usr/lib/libc/string/memset.c delete mode 100644 usr/lib/libc/string/rindex.c delete mode 100644 usr/lib/libc/string/stpcpy.c delete mode 100644 usr/lib/libc/string/stpncpy.c delete mode 100644 usr/lib/libc/string/strcasecmp.c delete mode 100644 usr/lib/libc/string/strcasestr.c delete mode 100644 usr/lib/libc/string/strcat.c delete mode 100644 usr/lib/libc/string/strchr.c delete mode 100644 usr/lib/libc/string/strchrnul.c delete mode 100644 usr/lib/libc/string/strcmp.c delete mode 100644 usr/lib/libc/string/strcpy.c delete mode 100644 usr/lib/libc/string/strcspn.c delete mode 100644 usr/lib/libc/string/strdup.c delete mode 100644 usr/lib/libc/string/strerror_r.c delete mode 100644 usr/lib/libc/string/strlcat.c delete mode 100644 usr/lib/libc/string/strlcpy.c delete mode 100644 usr/lib/libc/string/strlen.c delete mode 100644 usr/lib/libc/string/strncasecmp.c delete mode 100644 usr/lib/libc/string/strncat.c delete mode 100644 usr/lib/libc/string/strncmp.c delete mode 100644 usr/lib/libc/string/strncpy.c delete mode 100644 usr/lib/libc/string/strndup.c delete mode 100644 usr/lib/libc/string/strnlen.c delete mode 100644 usr/lib/libc/string/strpbrk.c delete mode 100644 usr/lib/libc/string/strrchr.c delete mode 100644 usr/lib/libc/string/strsep.c delete mode 100644 usr/lib/libc/string/strsignal.c delete mode 100644 usr/lib/libc/string/strspn.c delete mode 100644 usr/lib/libc/string/strstr.c delete mode 100644 usr/lib/libc/string/strtok.c delete mode 100644 usr/lib/libc/string/strtok_r.c delete mode 100644 usr/lib/libc/string/strverscmp.c delete mode 100644 usr/lib/libc/string/swab.c delete mode 100644 usr/lib/libc/string/wcpcpy.c delete mode 100644 usr/lib/libc/string/wcpncpy.c delete mode 100644 usr/lib/libc/string/wcscasecmp.c delete mode 100644 usr/lib/libc/string/wcscasecmp_l.c delete mode 100644 usr/lib/libc/string/wcscat.c delete mode 100644 usr/lib/libc/string/wcschr.c delete mode 100644 usr/lib/libc/string/wcscmp.c delete mode 100644 usr/lib/libc/string/wcscpy.c delete mode 100644 usr/lib/libc/string/wcscspn.c delete mode 100644 usr/lib/libc/string/wcsdup.c delete mode 100644 usr/lib/libc/string/wcslen.c delete mode 100644 usr/lib/libc/string/wcsncasecmp.c delete mode 100644 usr/lib/libc/string/wcsncasecmp_l.c delete mode 100644 usr/lib/libc/string/wcsncat.c delete mode 100644 usr/lib/libc/string/wcsncmp.c delete mode 100644 usr/lib/libc/string/wcsncpy.c delete mode 100644 usr/lib/libc/string/wcsnlen.c delete mode 100644 usr/lib/libc/string/wcspbrk.c delete mode 100644 usr/lib/libc/string/wcsrchr.c delete mode 100644 usr/lib/libc/string/wcsspn.c delete mode 100644 usr/lib/libc/string/wcsstr.c delete mode 100644 usr/lib/libc/string/wcstok.c delete mode 100644 usr/lib/libc/string/wcswcs.c delete mode 100644 usr/lib/libc/string/wmemchr.c delete mode 100644 usr/lib/libc/string/wmemcmp.c delete mode 100644 usr/lib/libc/string/wmemcpy.c delete mode 100644 usr/lib/libc/string/wmemmove.c delete mode 100644 usr/lib/libc/string/wmemset.c delete mode 100644 usr/lib/libc/syscall_ret.c delete mode 100644 usr/lib/libc/thread/CMakeLists.txt delete mode 100644 usr/lib/libc/thread/__futex.c delete mode 100644 usr/lib/libc/thread/__lock.c delete mode 100644 usr/lib/libc/thread/__set_thread_area.c delete mode 100644 usr/lib/libc/thread/__syscall_cp.c delete mode 100644 usr/lib/libc/thread/__timedwait.c delete mode 100644 usr/lib/libc/thread/__tls_get_addr.c delete mode 100644 usr/lib/libc/thread/__unmapself.c delete mode 100644 usr/lib/libc/thread/__wait.c delete mode 100644 usr/lib/libc/thread/atomics.S delete mode 100644 usr/lib/libc/thread/call_once.c delete mode 100644 usr/lib/libc/thread/clone.c delete mode 100644 usr/lib/libc/thread/cnd_broadcast.c delete mode 100644 usr/lib/libc/thread/cnd_destroy.c delete mode 100644 usr/lib/libc/thread/cnd_init.c delete mode 100644 usr/lib/libc/thread/cnd_signal.c delete mode 100644 usr/lib/libc/thread/cnd_timedwait.c delete mode 100644 usr/lib/libc/thread/cnd_wait.c delete mode 100644 usr/lib/libc/thread/lock_ptc.c delete mode 100644 usr/lib/libc/thread/mtx_destroy.c delete mode 100644 usr/lib/libc/thread/mtx_init.c delete mode 100644 usr/lib/libc/thread/mtx_lock.c delete mode 100644 usr/lib/libc/thread/mtx_timedlock.c delete mode 100644 usr/lib/libc/thread/mtx_trylock.c delete mode 100644 usr/lib/libc/thread/mtx_unlock.c delete mode 100644 usr/lib/libc/thread/pthread_atfork.c delete mode 100644 usr/lib/libc/thread/pthread_attr_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_attr_get.c delete mode 100644 usr/lib/libc/thread/pthread_attr_init.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setdetachstate.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setguardsize.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setinheritsched.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setschedparam.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setschedpolicy.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setscope.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setstack.c delete mode 100644 usr/lib/libc/thread/pthread_attr_setstacksize.c delete mode 100644 usr/lib/libc/thread/pthread_barrier_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_barrier_init.c delete mode 100644 usr/lib/libc/thread/pthread_barrier_wait.c delete mode 100644 usr/lib/libc/thread/pthread_barrierattr_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_barrierattr_init.c delete mode 100644 usr/lib/libc/thread/pthread_barrierattr_setpshared.c delete mode 100644 usr/lib/libc/thread/pthread_cancel.c delete mode 100644 usr/lib/libc/thread/pthread_cleanup_push.c delete mode 100644 usr/lib/libc/thread/pthread_cond_broadcast.c delete mode 100644 usr/lib/libc/thread/pthread_cond_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_cond_init.c delete mode 100644 usr/lib/libc/thread/pthread_cond_signal.c delete mode 100644 usr/lib/libc/thread/pthread_cond_timedwait.c delete mode 100644 usr/lib/libc/thread/pthread_cond_wait.c delete mode 100644 usr/lib/libc/thread/pthread_condattr_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_condattr_init.c delete mode 100644 usr/lib/libc/thread/pthread_condattr_setclock.c delete mode 100644 usr/lib/libc/thread/pthread_condattr_setpshared.c delete mode 100644 usr/lib/libc/thread/pthread_create.c delete mode 100644 usr/lib/libc/thread/pthread_detach.c delete mode 100644 usr/lib/libc/thread/pthread_equal.c delete mode 100644 usr/lib/libc/thread/pthread_getattr_np.c delete mode 100644 usr/lib/libc/thread/pthread_getconcurrency.c delete mode 100644 usr/lib/libc/thread/pthread_getcpuclockid.c delete mode 100644 usr/lib/libc/thread/pthread_getschedparam.c delete mode 100644 usr/lib/libc/thread/pthread_getspecific.c delete mode 100644 usr/lib/libc/thread/pthread_join.c delete mode 100644 usr/lib/libc/thread/pthread_key_create.c delete mode 100644 usr/lib/libc/thread/pthread_kill.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_consistent.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_getprioceiling.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_init.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_lock.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_setprioceiling.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_timedlock.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_trylock.c delete mode 100644 usr/lib/libc/thread/pthread_mutex_unlock.c delete mode 100644 usr/lib/libc/thread/pthread_mutexattr_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_mutexattr_init.c delete mode 100644 usr/lib/libc/thread/pthread_mutexattr_setprotocol.c delete mode 100644 usr/lib/libc/thread/pthread_mutexattr_setpshared.c delete mode 100644 usr/lib/libc/thread/pthread_mutexattr_setrobust.c delete mode 100644 usr/lib/libc/thread/pthread_mutexattr_settype.c delete mode 100644 usr/lib/libc/thread/pthread_once.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_init.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_rdlock.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_timedrdlock.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_timedwrlock.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_tryrdlock.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_trywrlock.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_unlock.c delete mode 100644 usr/lib/libc/thread/pthread_rwlock_wrlock.c delete mode 100644 usr/lib/libc/thread/pthread_rwlockattr_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_rwlockattr_init.c delete mode 100644 usr/lib/libc/thread/pthread_rwlockattr_setpshared.c delete mode 100644 usr/lib/libc/thread/pthread_self.c delete mode 100644 usr/lib/libc/thread/pthread_setattr_default_np.c delete mode 100644 usr/lib/libc/thread/pthread_setcancelstate.c delete mode 100644 usr/lib/libc/thread/pthread_setcanceltype.c delete mode 100644 usr/lib/libc/thread/pthread_setconcurrency.c delete mode 100644 usr/lib/libc/thread/pthread_setname_np.c delete mode 100644 usr/lib/libc/thread/pthread_setschedparam.c delete mode 100644 usr/lib/libc/thread/pthread_setschedprio.c delete mode 100644 usr/lib/libc/thread/pthread_setspecific.c delete mode 100644 usr/lib/libc/thread/pthread_sigmask.c delete mode 100644 usr/lib/libc/thread/pthread_spin_destroy.c delete mode 100644 usr/lib/libc/thread/pthread_spin_init.c delete mode 100644 usr/lib/libc/thread/pthread_spin_lock.c delete mode 100644 usr/lib/libc/thread/pthread_spin_trylock.c delete mode 100644 usr/lib/libc/thread/pthread_spin_unlock.c delete mode 100644 usr/lib/libc/thread/pthread_testcancel.c delete mode 100644 usr/lib/libc/thread/sem_destroy.c delete mode 100644 usr/lib/libc/thread/sem_getvalue.c delete mode 100644 usr/lib/libc/thread/sem_init.c delete mode 100644 usr/lib/libc/thread/sem_open.c delete mode 100644 usr/lib/libc/thread/sem_post.c delete mode 100644 usr/lib/libc/thread/sem_timedwait.c delete mode 100644 usr/lib/libc/thread/sem_trywait.c delete mode 100644 usr/lib/libc/thread/sem_unlink.c delete mode 100644 usr/lib/libc/thread/sem_wait.c delete mode 100644 usr/lib/libc/thread/synccall.c delete mode 100644 usr/lib/libc/thread/syscall_cp.c delete mode 100644 usr/lib/libc/thread/thrd_create.c delete mode 100644 usr/lib/libc/thread/thrd_exit.c delete mode 100644 usr/lib/libc/thread/thrd_join.c delete mode 100644 usr/lib/libc/thread/thrd_sleep.c delete mode 100644 usr/lib/libc/thread/thrd_yield.c delete mode 100644 usr/lib/libc/thread/tls.c delete mode 100644 usr/lib/libc/thread/tss_create.c delete mode 100644 usr/lib/libc/thread/tss_delete.c delete mode 100644 usr/lib/libc/thread/tss_set.c delete mode 100644 usr/lib/libc/thread/vmlock.c delete mode 100644 usr/lib/libc/time/CMakeLists.txt delete mode 100644 usr/lib/libc/time/__asctime.c delete mode 100644 usr/lib/libc/time/__map_file.c delete mode 100644 usr/lib/libc/time/__month_to_secs.c delete mode 100644 usr/lib/libc/time/__secs_to_tm.c delete mode 100644 usr/lib/libc/time/__tm_to_secs.c delete mode 100644 usr/lib/libc/time/__tz.c delete mode 100644 usr/lib/libc/time/__year_to_secs.c delete mode 100644 usr/lib/libc/time/asctime.c delete mode 100644 usr/lib/libc/time/asctime_r.c delete mode 100644 usr/lib/libc/time/clock.c delete mode 100644 usr/lib/libc/time/clock_getcpuclockid.c delete mode 100644 usr/lib/libc/time/clock_getres.c delete mode 100644 usr/lib/libc/time/clock_gettime.c delete mode 100644 usr/lib/libc/time/clock_nanosleep.c delete mode 100644 usr/lib/libc/time/clock_settime.c delete mode 100644 usr/lib/libc/time/ctime.c delete mode 100644 usr/lib/libc/time/ctime_r.c delete mode 100644 usr/lib/libc/time/difftime.c delete mode 100644 usr/lib/libc/time/ftime.c delete mode 100644 usr/lib/libc/time/getdate.c delete mode 100644 usr/lib/libc/time/gettimeofday.c delete mode 100644 usr/lib/libc/time/gmtime.c delete mode 100644 usr/lib/libc/time/gmtime_r.c delete mode 100644 usr/lib/libc/time/localtime.c delete mode 100644 usr/lib/libc/time/localtime_r.c delete mode 100644 usr/lib/libc/time/mktime.c delete mode 100644 usr/lib/libc/time/nanosleep.c delete mode 100644 usr/lib/libc/time/strftime.c delete mode 100644 usr/lib/libc/time/strptime.c delete mode 100644 usr/lib/libc/time/time.c delete mode 100644 usr/lib/libc/time/time_impl.h delete mode 100644 usr/lib/libc/time/timegm.c delete mode 100644 usr/lib/libc/time/timer_create.c delete mode 100644 usr/lib/libc/time/timer_delete.c delete mode 100644 usr/lib/libc/time/timer_getoverrun.c delete mode 100644 usr/lib/libc/time/timer_gettime.c delete mode 100644 usr/lib/libc/time/timer_settime.c delete mode 100644 usr/lib/libc/time/times.c delete mode 100644 usr/lib/libc/time/timespec_get.c delete mode 100644 usr/lib/libc/time/utime.c delete mode 100644 usr/lib/libc/time/wcsftime.c delete mode 100644 usr/lib/libc/unistd/CMakeLists.txt delete mode 100644 usr/lib/libc/unistd/_exit.c delete mode 100644 usr/lib/libc/unistd/access.c delete mode 100644 usr/lib/libc/unistd/acct.c delete mode 100644 usr/lib/libc/unistd/alarm.c delete mode 100644 usr/lib/libc/unistd/chdir.c delete mode 100644 usr/lib/libc/unistd/chown.c delete mode 100644 usr/lib/libc/unistd/close.c delete mode 100644 usr/lib/libc/unistd/ctermid.c delete mode 100644 usr/lib/libc/unistd/dup.c delete mode 100644 usr/lib/libc/unistd/dup2.c delete mode 100644 usr/lib/libc/unistd/dup3.c delete mode 100644 usr/lib/libc/unistd/faccessat.c delete mode 100644 usr/lib/libc/unistd/fchdir.c delete mode 100644 usr/lib/libc/unistd/fchown.c delete mode 100644 usr/lib/libc/unistd/fchownat.c delete mode 100644 usr/lib/libc/unistd/fdatasync.c delete mode 100644 usr/lib/libc/unistd/fsync.c delete mode 100644 usr/lib/libc/unistd/ftruncate.c delete mode 100644 usr/lib/libc/unistd/getcwd.c delete mode 100644 usr/lib/libc/unistd/getegid.c delete mode 100644 usr/lib/libc/unistd/geteuid.c delete mode 100644 usr/lib/libc/unistd/getgid.c delete mode 100644 usr/lib/libc/unistd/getgroups.c delete mode 100644 usr/lib/libc/unistd/gethostname.c delete mode 100644 usr/lib/libc/unistd/getlogin.c delete mode 100644 usr/lib/libc/unistd/getlogin_r.c delete mode 100644 usr/lib/libc/unistd/getpgid.c delete mode 100644 usr/lib/libc/unistd/getpgrp.c delete mode 100644 usr/lib/libc/unistd/getpid.c delete mode 100644 usr/lib/libc/unistd/getppid.c delete mode 100644 usr/lib/libc/unistd/getsid.c delete mode 100644 usr/lib/libc/unistd/getuid.c delete mode 100644 usr/lib/libc/unistd/isatty.c delete mode 100644 usr/lib/libc/unistd/lchown.c delete mode 100644 usr/lib/libc/unistd/link.c delete mode 100644 usr/lib/libc/unistd/linkat.c delete mode 100644 usr/lib/libc/unistd/lseek.c delete mode 100644 usr/lib/libc/unistd/nice.c delete mode 100644 usr/lib/libc/unistd/pause.c delete mode 100644 usr/lib/libc/unistd/pipe.c delete mode 100644 usr/lib/libc/unistd/pipe2.c delete mode 100644 usr/lib/libc/unistd/posix_close.c delete mode 100644 usr/lib/libc/unistd/pread.c delete mode 100644 usr/lib/libc/unistd/preadv.c delete mode 100644 usr/lib/libc/unistd/pwrite.c delete mode 100644 usr/lib/libc/unistd/pwritev.c delete mode 100644 usr/lib/libc/unistd/read.c delete mode 100644 usr/lib/libc/unistd/readlink.c delete mode 100644 usr/lib/libc/unistd/readlinkat.c delete mode 100644 usr/lib/libc/unistd/readv.c delete mode 100644 usr/lib/libc/unistd/renameat.c delete mode 100644 usr/lib/libc/unistd/rmdir.c delete mode 100644 usr/lib/libc/unistd/setegid.c delete mode 100644 usr/lib/libc/unistd/seteuid.c delete mode 100644 usr/lib/libc/unistd/setgid.c delete mode 100644 usr/lib/libc/unistd/setpgid.c delete mode 100644 usr/lib/libc/unistd/setpgrp.c delete mode 100644 usr/lib/libc/unistd/setregid.c delete mode 100644 usr/lib/libc/unistd/setresgid.c delete mode 100644 usr/lib/libc/unistd/setresuid.c delete mode 100644 usr/lib/libc/unistd/setreuid.c delete mode 100644 usr/lib/libc/unistd/setsid.c delete mode 100644 usr/lib/libc/unistd/setuid.c delete mode 100644 usr/lib/libc/unistd/setxid.c delete mode 100644 usr/lib/libc/unistd/sleep.c delete mode 100644 usr/lib/libc/unistd/symlink.c delete mode 100644 usr/lib/libc/unistd/symlinkat.c delete mode 100644 usr/lib/libc/unistd/sync.c delete mode 100644 usr/lib/libc/unistd/tcgetpgrp.c delete mode 100644 usr/lib/libc/unistd/tcsetpgrp.c delete mode 100644 usr/lib/libc/unistd/truncate.c delete mode 100644 usr/lib/libc/unistd/ttyname.c delete mode 100644 usr/lib/libc/unistd/ttyname_r.c delete mode 100644 usr/lib/libc/unistd/ualarm.c delete mode 100644 usr/lib/libc/unistd/unlink.c delete mode 100644 usr/lib/libc/unistd/unlinkat.c delete mode 100644 usr/lib/libc/unistd/usleep.c delete mode 100644 usr/lib/libc/unistd/write.c delete mode 100644 usr/lib/libc/unistd/writev.c diff --git a/usr/CMakeLists.txt b/usr/CMakeLists.txt index c0bf2d1a5..387abe07c 100644 --- a/usr/CMakeLists.txt +++ b/usr/CMakeLists.txt @@ -10,10 +10,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) option(MICROPYTHON "Support for micro-python apps" OFF) - -# Detect the correct compiler runtime library and add it -# to 'LIBCXX_LIBRARIES'. back to gcc_s if available. - # Where the header files are located include_directories( src diff --git a/usr/lib/libc/CMakeLists.txt b/usr/lib/libc/CMakeLists.txt deleted file mode 100644 index c88b1d7e3..000000000 --- a/usr/lib/libc/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ - -if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l") - -file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/include/asm-aarch32" "${CMAKE_CURRENT_SOURCE_DIR}/include/asm" SYMBOLIC) - -else() - -file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/include/asm-aarch64" "${CMAKE_CURRENT_SOURCE_DIR}/include/asm" SYMBOLIC) - -endif() - - -include_directories( - include -) - -add_library(c STATIC - crt0.S crt1.c longjmp.S setjmp.S libc.c - pthread.c inet.c eabi_compat.c malloc.c - shgetc.c intscan.c floatscan.c mutex.c sbrk.c - syscall_ret.c) - -add_subdirectory(string) -add_subdirectory(stdio) -add_subdirectory(fcntl) -add_subdirectory(misc) -add_subdirectory(errno) -add_subdirectory(multibyte) -add_subdirectory(ctype) -add_subdirectory(thread) -add_subdirectory(stdlib) -add_subdirectory(dirent) -add_subdirectory(unistd) -add_subdirectory(env) -add_subdirectory(malloc) -add_subdirectory(math) -add_subdirectory(exit) -add_subdirectory(process) -add_subdirectory(signal) -add_subdirectory(time) -add_subdirectory(prng) -add_subdirectory(mman) -add_subdirectory(network) diff --git a/usr/lib/libc/aarch64.lds b/usr/lib/libc/aarch64.lds deleted file mode 100644 index 1010b255e..000000000 --- a/usr/lib/libc/aarch64.lds +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (C) Copyright 2003 - * Wolfgang Denk Engineering, - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -OUTPUT_ARCH(aarch64) -ENTRY(__start) - -SECTIONS -{ - .text 0x1000 : - { - *(.head) - *(.text*) - } - - . = ALIGN(4096); - .rodata : - { - - - } - - . = ALIGN(4096); - - .data : { *(.data*) } - - . = ALIGN(4096); - - __bss_start = .; - .sbss (NOLOAD) : { *(.sbss*) } - .bss (NOLOAD) : { *(.bss*) . = ALIGN(4096); } - __bss_end = .; - - _end = .; -} diff --git a/usr/lib/libc/arm.lds b/usr/lib/libc/arm.lds deleted file mode 100644 index 9152a290e..000000000 --- a/usr/lib/libc/arm.lds +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (C) Copyright 2003 - * Wolfgang Denk Engineering, - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -OUTPUT_ARCH(arm) -ENTRY(__start) - -SECTIONS -{ - .text 0x1000 : - { - *(.head) - *(.text*) - } - - . = ALIGN(4096); - .rodata : - { - - - } - - . = ALIGN(4096); - - .data : { *(.data*) } - - . = ALIGN(4096); - - __bss_start = .; - .sbss (NOLOAD) : { *(.sbss*) } - .bss (NOLOAD) : { *(.bss*) . = ALIGN(4096); } - __bss_end = .; - - _end = .; -} diff --git a/usr/lib/libc/crt0.S b/usr/lib/libc/crt0.S deleted file mode 100755 index 22ba5aeda..000000000 --- a/usr/lib/libc/crt0.S +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2014-2017 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include - -.extern __entryC - -.data -.globl errno - -.align 8 -errno: - .word 0x0 - -.text - - -/* ------------------------------------------------------------- - * __start - * Initialize running a C program, by calling "main". - * ------------------------------------------------------------- - */ - - .globl __start - .section ".head", "ax" -__start: - - /* r0 points to the argument page */ - - bl __entryC - - b exit /* if we return from main, exit(return value) */ - - nop - -#ifdef __ARM__ - -/* ------------------------------------------------------------- - * System call stubs: - * - r0-r3 are used to store arguments - * - Further argument are on stack and will be put to r4-r5 if needed. - * - r7 is used to store the syscall number - * ------------------------------------------------------------- - */ - -.macro SYSCALLSTUB name, number, nargs - .globl \name -\name: - - stmfd sp!, {r4, r5, r7} - -/* Retrieve arguments 5 and 6 from the stack if needed */ -.ifge \nargs - 5 - ldr r4, [sp, #20] -.endif -.ifge \nargs - 6 - ldr r5, [sp, #24] -.endif - - mov r7, #\number - - swi 0 - - ldmfd sp!, {r4, r5, r7} - - mov pc, lr - -.endm - -#else /* __ARM64__ */ - -/* ------------------------------------------------------------- - * System call stubs: - * - x0-x5 are used to store arguments - * - x8 is used to store the syscall number - * ------------------------------------------------------------- - */ - -.macro SYSCALLSTUB name, number, nargs - .globl \name -\name: - - // 16-byte stack alignment - sub sp, sp, #16 - - str x8, [sp] - str lr, [sp, #8] - - mov x8, #\number - - svc 0 - - ldr x8, [sp] - ldr lr, [sp, #8] - - add sp, sp, #16 - - ret - -.endm - - -#endif /* __ARM64__ */ - - -/* Syscalls stubs */ -SYSCALLSTUB sys_halt, syscallHalt 0 -SYSCALLSTUB sys_write, syscallWrite 3 -SYSCALLSTUB sys_read, syscallRead 3 -SYSCALLSTUB sys_exit, syscallExit 1 -SYSCALLSTUB sys_execve, syscallExecve 3 -SYSCALLSTUB sys_waitpid, syscallWaitpid 3 -SYSCALLSTUB sys_pause, syscallPause 1 -SYSCALLSTUB sys_fork, syscallFork 0 -SYSCALLSTUB sys_readdir, syscallReaddir 3 -/* SYSCALLSTUB sys_chdir, syscallChdir */ -/* SYSCALLSTUB sys_getcwd, syscallGetcwd */ -SYSCALLSTUB sys_creat, syscallCreate 2 -SYSCALLSTUB sys_unlink, syscallUnlink 1 -SYSCALLSTUB sys_open, syscallOpen 3 -SYSCALLSTUB sys_close, syscallClose 1 -SYSCALLSTUB sys_thread_create, syscallThreadCreate 4 -SYSCALLSTUB sys_thread_join, syscallThreadJoin 2 -SYSCALLSTUB sys_thread_exit, syscallThreadExit 1 -SYSCALLSTUB sys_thread_yield, syscallThreadYield 0 -SYSCALLSTUB sys_pipe, syscallPipe 1 -SYSCALLSTUB sys_ioctl, syscallIoctl 3 -SYSCALLSTUB sys_fcntl, syscallFcntl 3 -SYSCALLSTUB sys_stat, syscallStat 2 -SYSCALLSTUB sys_dup, syscallDup 1 -SYSCALLSTUB sys_dup2, syscallDup2 2 -SYSCALLSTUB sys_sched_setparam, syscallSchedSetParam 2 -SYSCALLSTUB sys_socket, syscallSocket 3 -SYSCALLSTUB sys_bind, syscallBind 3 -SYSCALLSTUB sys_listen, syscallListen 2 -SYSCALLSTUB sys_accept, syscallAccept 3 -SYSCALLSTUB sys_connect, syscallConnect 3 -SYSCALLSTUB sys_mmap, syscallMmap 5 -SYSCALLSTUB sys_ptrace, syscallPtrace 4 -SYSCALLSTUB sys_send, syscallSend 4 -SYSCALLSTUB sys_recv, syscallRecv 4 -SYSCALLSTUB sys_recvfrom, syscallRecvfrom 6 -SYSCALLSTUB sys_setsockopt, syscallSetsockopt 5 -SYSCALLSTUB sys_sendto, syscallSendTo 6 -SYSCALLSTUB sys_getpid, syscallGetpid 0 - -SYSCALLSTUB sys_gettimeofday, syscallGetTimeOfDay 2 -SYSCALLSTUB sys_settimeofday, syscallSetTimeOfDay 2 -SYSCALLSTUB sys_clock_gettime, syscallClockGetTime 2 - -SYSCALLSTUB sys_sbrk, syscallSbrk 1 -SYSCALLSTUB sys_info, syscallSysinfo 2 - -SYSCALLSTUB sys_lseek, syscallLseek 3 - -SYSCALLSTUB sys_mutex_lock, syscallMutexLock 1 -SYSCALLSTUB sys_mutex_unlock, syscallMutexUnlock 1 - -SYSCALLSTUB sys_sigaction, syscallSigaction 3 -SYSCALLSTUB sys_kill, syscallKill 2 -SYSCALLSTUB sys_sigreturn, syscallSigreturn 0 - -SYSCALLSTUB sys_nanosleep, syscallNanosleep 2 - - diff --git a/usr/lib/libc/crt1.c b/usr/lib/libc/crt1.c deleted file mode 100644 index b22ef48bc..000000000 --- a/usr/lib/libc/crt1.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2014-2018 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -/* - * This entry code handles the initialization of the BSS section. - * - */ -extern char __bss_start[], __bss_end[]; -extern int main(int argc, char **argv); -extern void mutex_init(void); - -void finish_child(int signum) { - int saved_errno; - int pid; - - saved_errno = errno; - while ((pid = waitpid((pid_t)(-1), NULL, WNOHANG)) > 0) - printf("[%d] Terminated\n", pid); - - errno = saved_errno; -} - -/* - * Handling the ctrl/C key (SIGINT) - */ -void term_default(int signum) { - if (signum == SIGTERM) - printf("[%d] Terminated\n", getpid()); - - /* Force the process to quit */ - exit(0); -} - -__attribute__((__section__(".head"))) int __entryC(void *args) { - struct sigaction sa; - - memset(&sa, 0, sizeof(struct sigaction)); - - char *cp = __bss_start; - int argc; - char **argv; - - /* Zero out BSS */ - while (cp < __bss_end) - *cp++ = 0; - - /* - * Prepare argc & argv - * The arguments are placed in a argument page on top of the user space. - * The first four bytes are used to store argc, and the array of string pointers - * follow right after. The strings themselves are placed after the array of pointers. - */ - argc = *((int *) args); - - /* Just give the beginning of the array of pointers */ - argv = (char **) (args + 4); - -#ifdef __ARM__ - __environ = (char **) (args + 4 + 4*argc); -#else - __environ = (char **) (args + 4 + 8*argc); -#endif - - sa.sa_handler = term_default; - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGKILL, &sa, NULL); - - sa.sa_handler = finish_child; - sigaction(SIGCHLD, &sa, NULL); - - return main(argc, argv); - -} - - diff --git a/usr/lib/libc/ctype/CMakeLists.txt b/usr/lib/libc/ctype/CMakeLists.txt deleted file mode 100644 index 704cf3d38..000000000 --- a/usr/lib/libc/ctype/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -target_sources(c - PRIVATE - __ctype_get_mb_cur_max.c - toupper.c -) diff --git a/usr/lib/libc/ctype/__ctype_b_loc.c b/usr/lib/libc/ctype/__ctype_b_loc.c deleted file mode 100644 index f43795e94..000000000 --- a/usr/lib/libc/ctype/__ctype_b_loc.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -#if __BYTE_ORDER == __BIG_ENDIAN -#define X(x) x -#else -#define X(x) (((x)/256 | (x)*256) % 65536) -#endif - -static const unsigned short table[] = { -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200), -X(0x200),X(0x320),X(0x220),X(0x220),X(0x220),X(0x220),X(0x200),X(0x200), -X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200), -X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200), -X(0x160),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), -X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), -X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8), -X(0x8d8),X(0x8d8),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), -X(0x4c0),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8c5), -X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5), -X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5), -X(0x8c5),X(0x8c5),X(0x8c5),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), -X(0x4c0),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8c6), -X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6), -X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6), -X(0x8c6),X(0x8c6),X(0x8c6),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x200), -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; - -static const unsigned short *const ptable = table+128; - -const unsigned short **__ctype_b_loc(void) -{ - return (void *)&ptable; -} diff --git a/usr/lib/libc/ctype/__ctype_get_mb_cur_max.c b/usr/lib/libc/ctype/__ctype_get_mb_cur_max.c deleted file mode 100644 index 8e946fc12..000000000 --- a/usr/lib/libc/ctype/__ctype_get_mb_cur_max.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "locale_impl.h" - -size_t __ctype_get_mb_cur_max() -{ - return MB_CUR_MAX; -} diff --git a/usr/lib/libc/ctype/__ctype_tolower_loc.c b/usr/lib/libc/ctype/__ctype_tolower_loc.c deleted file mode 100644 index efb991054..000000000 --- a/usr/lib/libc/ctype/__ctype_tolower_loc.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -static const int32_t table[] = { -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64, -'a','b','c','d','e','f','g','h','i','j','k','l','m', -'n','o','p','q','r','s','t','u','v','w','x','y','z', -91,92,93,94,95,96, -'a','b','c','d','e','f','g','h','i','j','k','l','m', -'n','o','p','q','r','s','t','u','v','w','x','y','z', -123,124,125,126,127, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; - -static const int32_t *const ptable = table+128; - -const int32_t **__ctype_tolower_loc(void) -{ - return (void *)&ptable; -} diff --git a/usr/lib/libc/ctype/__ctype_toupper_loc.c b/usr/lib/libc/ctype/__ctype_toupper_loc.c deleted file mode 100644 index ffaef0e91..000000000 --- a/usr/lib/libc/ctype/__ctype_toupper_loc.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -static const int32_t table[] = { -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64, -'A','B','C','D','E','F','G','H','I','J','K','L','M', -'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', -91,92,93,94,95,96, -'A','B','C','D','E','F','G','H','I','J','K','L','M', -'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', -123,124,125,126,127, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -}; - -static const int32_t *const ptable = table+128; - -const int32_t **__ctype_toupper_loc(void) -{ - return (void *)&ptable; -} diff --git a/usr/lib/libc/ctype/alpha.h b/usr/lib/libc/ctype/alpha.h deleted file mode 100644 index b318c827f..000000000 --- a/usr/lib/libc/ctype/alpha.h +++ /dev/null @@ -1,125 +0,0 @@ -18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,17,34,35,36,17,37,38,39,40, -41,42,43,44,17,45,46,47,16,16,48,16,16,16,16,16,16,16,49,50,51,16,52,53,16,16, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,54, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67,68,69,70,71,72, -73,16,16,16,74,75,76,77,78,16,16,16,79,80,16,16,16,16,81,16,16,16,16,16,16,16, -16,16,17,17,17,82,83,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,84,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,85,16, -16,16,16,86,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,87,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -88,89,90,91,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -92,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,0,0,0,0,0,4,32,4, -255,255,127,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,195,255,3,0,31,80,0,0,0,0, -0,0,0,0,0,0,32,0,0,0,0,0,223,60,64,215,255,255,251,255,255,255,255,255,255, -255,255,255,191,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,3,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,0,254,255,255,255,127,2,254,255,255,255,255,0,0,0,0,0,255,191,182, -0,255,255,255,7,7,0,0,0,255,7,255,255,255,255,255,255,255,254,255,195,255,255, -255,255,255,255,255,255,255,255,255,255,239,31,254,225,255,159,0,0,255,255, -255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255,255,255,3,0,255, -255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255,1,0,0,0,0,0,0,0, -0,253,31,0,0,0,0,0,0,240,3,255,127,255,255,255,255,255,255,255,239,255,223, -225,255,207,255,254,254,238,159,249,255,255,253,197,227,159,89,128,176,207, -255,3,0,238,135,249,255,255,253,109,195,135,25,2,94,192,255,63,0,238,191,251, -255,255,253,237,227,191,27,1,0,207,255,0,0,238,159,249,255,255,253,237,227, -159,25,192,176,207,255,2,0,236,199,61,214,24,199,255,195,199,29,129,0,192,255, -0,0,238,223,253,255,255,253,239,227,223,29,96,3,207,255,0,0,236,223,253,255, -255,253,239,227,223,29,96,64,207,255,6,0,236,223,253,255,255,255,255,231,223, -93,128,0,207,255,0,252,236,255,127,252,255,255,251,47,127,128,95,255,0,0,12,0, -254,255,255,255,255,127,255,7,63,32,255,3,0,0,0,0,150,37,240,254,174,236,255, -59,95,32,255,243,0,0,0,0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3, -255,255,254,255,255,255,31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249, -255,3,255,255,231,193,255,255,127,64,255,51,255,255,255,255,191,32,255,255, -255,255,255,247,255,255,255,255,255,255,255,255,255,61,127,61,255,255,255,255, -255,61,255,255,255,255,61,127,61,255,127,255,255,255,255,255,255,255,61,255, -255,255,255,255,255,255,255,135,0,0,0,0,255,255,0,0,255,255,255,255,255,255, -255,255,255,255,31,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,159,255,255,254,255,255,7,255, -255,255,255,255,255,255,255,255,199,1,0,255,223,15,0,255,255,15,0,255,255,15, -0,255,223,13,0,255,255,255,255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255, -3,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,7,255,255, -255,255,255,255,255,255,63,0,255,255,255,31,255,15,255,1,192,255,255,255,255, -63,31,0,255,255,255,255,255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255, -255,255,255,255,255,255,127,254,255,31,0,255,3,255,3,128,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255, -243,255,255,255,255,255,255,191,255,3,0,255,255,255,255,255,255,63,0,255,227, -255,255,255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,222,111,0,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,0,0,0,0,0,0,0,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255, -63,255,255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255, -243,224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,0,255,255,255, -255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255,255,255,255, -255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127,255,255,255, -255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,0,0, -0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254,255,255,255, -255,255,255,255,255,255,255,247,224,255,255,255,255,63,254,255,255,255,255, -255,255,255,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -63,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,31,0,0,0,0,0,0,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,255, -255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255,255,127,240,143, -255,255,255,128,255,255,255,255,255,255,255,255,255,255,0,0,0,0,128,255,252, -255,255,255,255,255,255,255,255,255,255,255,255,121,15,0,255,7,0,0,0,0,0,0,0, -0,0,255,187,247,255,255,255,0,0,0,255,255,255,255,255,255,15,0,255,255,255, -255,255,255,255,255,15,0,255,3,0,0,252,8,255,255,255,255,255,7,255,255,255, -255,7,0,255,255,255,31,255,255,255,255,255,255,247,255,0,128,255,3,0,0,0,0, -255,255,255,255,255,255,127,0,255,63,255,3,255,255,127,4,255,255,255,255,255, -255,255,127,5,0,0,56,255,255,60,0,126,126,126,0,127,127,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255, -255,255,15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255, -255,255,255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127, -95,219,255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255, -255,255,255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255, -255,255,252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0, -0,255,3,254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255, -255,127,252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63, -0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0, -0,0,0,0,255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0,0, -255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255,255,63,255,255,255,255, -15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,63,255,3,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191, -145,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,63,0,255,255, -255,3,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240, -239,254,255,255,15,0,0,0,0,0,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,255,255,255,255,255,255,255,255,63,0,0,0,192,255,0,0,252,255,255, -255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,255,255,255,255,199,255,0,0, -0,0,0,0,0,0,255,255,255,255,255,255,255,255,30,0,255,3,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,63,0,255,3,0,0,0,0,0,0,255,255,255, -255,255,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,255,255,255,255,255,255,255,255,31,0,255,255,255,255,255,127,0,0, -248,255,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255, -255,255,255,255,223,100,222,255,235,239,255,255,255,255,255,255,255,191,231, -223,223,255,255,255,123,95,252,253,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,253,255,255, -247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,255,255,127, -255,255,255,253,255,255,255,253,255,255,247,207,255,255,255,255,255,255,239, -255,255,255,150,254,247,10,132,234,150,170,150,247,247,94,255,251,255,15,238, -251,255,15,0,0,0,0,0,0,0,0, diff --git a/usr/lib/libc/ctype/isalnum.c b/usr/lib/libc/ctype/isalnum.c deleted file mode 100644 index 2214936f2..000000000 --- a/usr/lib/libc/ctype/isalnum.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int isalnum(int c) -{ - return isalpha(c) || isdigit(c); -} - -int __isalnum_l(int c, locale_t l) -{ - return isalnum(c); -} - -weak_alias(__isalnum_l, isalnum_l); diff --git a/usr/lib/libc/ctype/isalpha.c b/usr/lib/libc/ctype/isalpha.c deleted file mode 100644 index f155d3aa9..000000000 --- a/usr/lib/libc/ctype/isalpha.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" -#undef isalpha - -int isalpha(int c) -{ - return ((unsigned)c|32)-'a' < 26; -} - -int __isalpha_l(int c, locale_t l) -{ - return isalpha(c); -} - -weak_alias(__isalpha_l, isalpha_l); diff --git a/usr/lib/libc/ctype/isascii.c b/usr/lib/libc/ctype/isascii.c deleted file mode 100644 index 54ad3bf02..000000000 --- a/usr/lib/libc/ctype/isascii.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#undef isascii - -int isascii(int c) -{ - return !(c&~0x7f); -} diff --git a/usr/lib/libc/ctype/isblank.c b/usr/lib/libc/ctype/isblank.c deleted file mode 100644 index 299120e96..000000000 --- a/usr/lib/libc/ctype/isblank.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int isblank(int c) -{ - return (c == ' ' || c == '\t'); -} - -int __isblank_l(int c, locale_t l) -{ - return isblank(c); -} - -weak_alias(__isblank_l, isblank_l); diff --git a/usr/lib/libc/ctype/iscntrl.c b/usr/lib/libc/ctype/iscntrl.c deleted file mode 100644 index cb4114a06..000000000 --- a/usr/lib/libc/ctype/iscntrl.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int iscntrl(int c) -{ - return (unsigned)c < 0x20 || c == 0x7f; -} - -int __iscntrl_l(int c, locale_t l) -{ - return iscntrl(c); -} - -weak_alias(__iscntrl_l, iscntrl_l); diff --git a/usr/lib/libc/ctype/isdigit.c b/usr/lib/libc/ctype/isdigit.c deleted file mode 100644 index 4d8a103e6..000000000 --- a/usr/lib/libc/ctype/isdigit.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" -#undef isdigit - -int isdigit(int c) -{ - return (unsigned)c-'0' < 10; -} - -int __isdigit_l(int c, locale_t l) -{ - return isdigit(c); -} - -weak_alias(__isdigit_l, isdigit_l); diff --git a/usr/lib/libc/ctype/isgraph.c b/usr/lib/libc/ctype/isgraph.c deleted file mode 100644 index a0aae08aa..000000000 --- a/usr/lib/libc/ctype/isgraph.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" -#undef isgraph - -int isgraph(int c) -{ - return (unsigned)c-0x21 < 0x5e; -} - -int __isgraph_l(int c, locale_t l) -{ - return isgraph(c); -} - -weak_alias(__isgraph_l, isgraph_l); diff --git a/usr/lib/libc/ctype/islower.c b/usr/lib/libc/ctype/islower.c deleted file mode 100644 index 02640213e..000000000 --- a/usr/lib/libc/ctype/islower.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" -#undef islower - -int islower(int c) -{ - return (unsigned)c-'a' < 26; -} - -int __islower_l(int c, locale_t l) -{ - return islower(c); -} - -weak_alias(__islower_l, islower_l); diff --git a/usr/lib/libc/ctype/isprint.c b/usr/lib/libc/ctype/isprint.c deleted file mode 100644 index 067275fa0..000000000 --- a/usr/lib/libc/ctype/isprint.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" -#undef isprint - -int isprint(int c) -{ - return (unsigned)c-0x20 < 0x5f; -} - -int __isprint_l(int c, locale_t l) -{ - return isprint(c); -} - -weak_alias(__isprint_l, isprint_l); diff --git a/usr/lib/libc/ctype/ispunct.c b/usr/lib/libc/ctype/ispunct.c deleted file mode 100644 index e772d76a0..000000000 --- a/usr/lib/libc/ctype/ispunct.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int ispunct(int c) -{ - return isgraph(c) && !isalnum(c); -} - -int __ispunct_l(int c, locale_t l) -{ - return ispunct(c); -} - -weak_alias(__ispunct_l, ispunct_l); diff --git a/usr/lib/libc/ctype/isspace.c b/usr/lib/libc/ctype/isspace.c deleted file mode 100644 index 231e90793..000000000 --- a/usr/lib/libc/ctype/isspace.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" -#undef isspace - -int isspace(int c) -{ - return c == ' ' || (unsigned)c-'\t' < 5; -} - -int __isspace_l(int c, locale_t l) -{ - return isspace(c); -} - -weak_alias(__isspace_l, isspace_l); diff --git a/usr/lib/libc/ctype/isupper.c b/usr/lib/libc/ctype/isupper.c deleted file mode 100644 index 68c36f4a4..000000000 --- a/usr/lib/libc/ctype/isupper.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" -#undef isupper - -int isupper(int c) -{ - return (unsigned)c-'A' < 26; -} - -int __isupper_l(int c, locale_t l) -{ - return isupper(c); -} - -weak_alias(__isupper_l, isupper_l); diff --git a/usr/lib/libc/ctype/iswalnum.c b/usr/lib/libc/ctype/iswalnum.c deleted file mode 100644 index a6082da43..000000000 --- a/usr/lib/libc/ctype/iswalnum.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int iswalnum(wint_t wc) -{ - return iswdigit(wc) || iswalpha(wc); -} - -int __iswalnum_l(wint_t c, locale_t l) -{ - return iswalnum(c); -} - -weak_alias(__iswalnum_l, iswalnum_l); diff --git a/usr/lib/libc/ctype/iswalpha.c b/usr/lib/libc/ctype/iswalpha.c deleted file mode 100644 index 00f9d81f5..000000000 --- a/usr/lib/libc/ctype/iswalpha.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include "libc.h" - -static const unsigned char table[] = { -#include "alpha.h" -}; - -int iswalpha(wint_t wc) -{ - if (wc<0x20000U) - return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1; - if (wc<0x2fffeU) - return 1; - return 0; -} - -int __iswalpha_l(wint_t c, locale_t l) -{ - return iswalpha(c); -} - -weak_alias(__iswalpha_l, iswalpha_l); diff --git a/usr/lib/libc/ctype/iswblank.c b/usr/lib/libc/ctype/iswblank.c deleted file mode 100644 index d9b33ef47..000000000 --- a/usr/lib/libc/ctype/iswblank.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include "libc.h" - -int iswblank(wint_t wc) -{ - return isblank(wc); -} - -int __iswblank_l(wint_t c, locale_t l) -{ - return iswblank(c); -} - -weak_alias(__iswblank_l, iswblank_l); diff --git a/usr/lib/libc/ctype/iswcntrl.c b/usr/lib/libc/ctype/iswcntrl.c deleted file mode 100644 index daace82a3..000000000 --- a/usr/lib/libc/ctype/iswcntrl.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "libc.h" - -int iswcntrl(wint_t wc) -{ - return (unsigned)wc < 32 - || (unsigned)(wc-0x7f) < 33 - || (unsigned)(wc-0x2028) < 2 - || (unsigned)(wc-0xfff9) < 3; -} - -int __iswcntrl_l(wint_t c, locale_t l) -{ - return iswcntrl(c); -} - -weak_alias(__iswcntrl_l, iswcntrl_l); diff --git a/usr/lib/libc/ctype/iswctype.c b/usr/lib/libc/ctype/iswctype.c deleted file mode 100644 index 3d9c2cc7c..000000000 --- a/usr/lib/libc/ctype/iswctype.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include "libc.h" - -#define WCTYPE_ALNUM 1 -#define WCTYPE_ALPHA 2 -#define WCTYPE_BLANK 3 -#define WCTYPE_CNTRL 4 -#define WCTYPE_DIGIT 5 -#define WCTYPE_GRAPH 6 -#define WCTYPE_LOWER 7 -#define WCTYPE_PRINT 8 -#define WCTYPE_PUNCT 9 -#define WCTYPE_SPACE 10 -#define WCTYPE_UPPER 11 -#define WCTYPE_XDIGIT 12 - -int iswctype(wint_t wc, wctype_t type) -{ - switch (type) { - case WCTYPE_ALNUM: - return iswalnum(wc); - case WCTYPE_ALPHA: - return iswalpha(wc); - case WCTYPE_BLANK: - return iswblank(wc); - case WCTYPE_CNTRL: - return iswcntrl(wc); - case WCTYPE_DIGIT: - return iswdigit(wc); - case WCTYPE_GRAPH: - return iswgraph(wc); - case WCTYPE_LOWER: - return iswlower(wc); - case WCTYPE_PRINT: - return iswprint(wc); - case WCTYPE_PUNCT: - return iswpunct(wc); - case WCTYPE_SPACE: - return iswspace(wc); - case WCTYPE_UPPER: - return iswupper(wc); - case WCTYPE_XDIGIT: - return iswxdigit(wc); - } - return 0; -} - -wctype_t wctype(const char *s) -{ - int i; - const char *p; - /* order must match! */ - static const char names[] = - "alnum\0" "alpha\0" "blank\0" - "cntrl\0" "digit\0" "graph\0" - "lower\0" "print\0" "punct\0" - "space\0" "upper\0" "xdigit"; - for (i=1, p=names; *p; i++, p+=6) - if (*s == *p && !strcmp(s, p)) - return i; - return 0; -} - -int __iswctype_l(wint_t c, wctype_t t, locale_t l) -{ - return iswctype(c, t); -} - -wctype_t __wctype_l(const char *s, locale_t l) -{ - return wctype(s); -} - -weak_alias(__iswctype_l, iswctype_l); -weak_alias(__wctype_l, wctype_l); diff --git a/usr/lib/libc/ctype/iswdigit.c b/usr/lib/libc/ctype/iswdigit.c deleted file mode 100644 index ed9a88e74..000000000 --- a/usr/lib/libc/ctype/iswdigit.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include "libc.h" - -#undef iswdigit - -int iswdigit(wint_t wc) -{ - return (unsigned)wc-'0' < 10; -} - -int __iswdigit_l(wint_t c, locale_t l) -{ - return iswdigit(c); -} - -weak_alias(__iswdigit_l, iswdigit_l); diff --git a/usr/lib/libc/ctype/iswgraph.c b/usr/lib/libc/ctype/iswgraph.c deleted file mode 100644 index 0ea5ca3a4..000000000 --- a/usr/lib/libc/ctype/iswgraph.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" - -int iswgraph(wint_t wc) -{ - /* ISO C defines this function as: */ - return !iswspace(wc) && iswprint(wc); -} - -int __iswgraph_l(wint_t c, locale_t l) -{ - return iswgraph(c); -} - -weak_alias(__iswgraph_l, iswgraph_l); diff --git a/usr/lib/libc/ctype/iswlower.c b/usr/lib/libc/ctype/iswlower.c deleted file mode 100644 index 79df44a3d..000000000 --- a/usr/lib/libc/ctype/iswlower.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int iswlower(wint_t wc) -{ - return towupper(wc) != wc; -} - -int __iswlower_l(wint_t c, locale_t l) -{ - return iswlower(c); -} - -weak_alias(__iswlower_l, iswlower_l); diff --git a/usr/lib/libc/ctype/iswprint.c b/usr/lib/libc/ctype/iswprint.c deleted file mode 100644 index 69856e0d8..000000000 --- a/usr/lib/libc/ctype/iswprint.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include "libc.h" - -/* Consider all legal codepoints as printable except for: - * - C0 and C1 control characters - * - U+2028 and U+2029 (line/para break) - * - U+FFF9 through U+FFFB (interlinear annotation controls) - * The following code is optimized heavily to make hot paths for the - * expected printable characters. */ - -int iswprint(wint_t wc) -{ - if (wc < 0xffU) - return (wc+1 & 0x7f) >= 0x21; - if (wc < 0x2028U || wc-0x202aU < 0xd800-0x202a || wc-0xe000U < 0xfff9-0xe000) - return 1; - if (wc-0xfffcU > 0x10ffff-0xfffc || (wc&0xfffe)==0xfffe) - return 0; - return 1; -} - -int __iswprint_l(wint_t c, locale_t l) -{ - return iswprint(c); -} - -weak_alias(__iswprint_l, iswprint_l); diff --git a/usr/lib/libc/ctype/iswpunct.c b/usr/lib/libc/ctype/iswpunct.c deleted file mode 100644 index d88010463..000000000 --- a/usr/lib/libc/ctype/iswpunct.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include "libc.h" - -static const unsigned char table[] = { -#include "punct.h" -}; - -int iswpunct(wint_t wc) -{ - if (wc<0x20000U) - return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1; - return 0; -} - -int __iswpunct_l(wint_t c, locale_t l) -{ - return iswpunct(c); -} - -weak_alias(__iswpunct_l, iswpunct_l); diff --git a/usr/lib/libc/ctype/iswspace.c b/usr/lib/libc/ctype/iswspace.c deleted file mode 100644 index 75ae7e8ee..000000000 --- a/usr/lib/libc/ctype/iswspace.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include "libc.h" - -/* Our definition of whitespace is the Unicode White_Space property, - * minus non-breaking spaces (U+00A0, U+2007, and U+202F) and script- - * specific characters with non-blank glyphs (U+1680 and U+180E). */ - -int iswspace(wint_t wc) -{ - static const wchar_t spaces[] = { - ' ', '\t', '\n', '\r', 11, 12, 0x0085, - 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, - 0x2006, 0x2008, 0x2009, 0x200a, - 0x2028, 0x2029, 0x205f, 0x3000, 0 - }; - return wc && wcschr(spaces, wc); -} - -int __iswspace_l(wint_t c, locale_t l) -{ - return iswspace(c); -} - -weak_alias(__iswspace_l, iswspace_l); diff --git a/usr/lib/libc/ctype/iswupper.c b/usr/lib/libc/ctype/iswupper.c deleted file mode 100644 index 6e1e029c4..000000000 --- a/usr/lib/libc/ctype/iswupper.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int iswupper(wint_t wc) -{ - return towlower(wc) != wc; -} - -int __iswupper_l(wint_t c, locale_t l) -{ - return iswupper(c); -} - -weak_alias(__iswupper_l, iswupper_l); diff --git a/usr/lib/libc/ctype/iswxdigit.c b/usr/lib/libc/ctype/iswxdigit.c deleted file mode 100644 index 1e27f1f0f..000000000 --- a/usr/lib/libc/ctype/iswxdigit.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int iswxdigit(wint_t wc) -{ - return (unsigned)(wc-'0') < 10 || (unsigned)((wc|32)-'a') < 6; -} - -int __iswxdigit_l(wint_t c, locale_t l) -{ - return iswxdigit(c); -} - -weak_alias(__iswxdigit_l, iswxdigit_l); diff --git a/usr/lib/libc/ctype/isxdigit.c b/usr/lib/libc/ctype/isxdigit.c deleted file mode 100644 index 0e9152a7b..000000000 --- a/usr/lib/libc/ctype/isxdigit.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "libc.h" - -int isxdigit(int c) -{ - return isdigit(c) || ((unsigned)c|32)-'a' < 6; -} - -int __isxdigit_l(int c, locale_t l) -{ - return isxdigit(c); -} - -weak_alias(__isxdigit_l, isxdigit_l); diff --git a/usr/lib/libc/ctype/nonspacing.h b/usr/lib/libc/ctype/nonspacing.h deleted file mode 100644 index 4c25ef517..000000000 --- a/usr/lib/libc/ctype/nonspacing.h +++ /dev/null @@ -1,62 +0,0 @@ -16,16,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,16,16,32,16,16,16,33,34,35, -36,37,38,39,16,16,40,16,16,16,16,16,16,16,16,16,16,16,41,42,16,16,43,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,44,16,45,46,47,48,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50,51,16,52,16,16, -16,16,16,16,16,16,53,16,16,16,16,16,54,55,16,16,16,16,56,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,57,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,58,59,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,3,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,255,255,191, -182,0,0,0,0,0,0,0,31,0,255,7,0,0,0,0,0,248,255,255,0,0,1,0,0,0,0,0,0,0,0,0,0, -0,192,191,159,61,0,0,0,128,2,0,0,0,255,255,255,7,0,0,0,0,0,0,0,0,0,0,192,255, -1,0,0,0,0,0,0,248,15,0,0,0,192,251,239,62,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,240,255,255,127,7,0,0,0,0,0,0,20,254,33,254,0,12,0,0,0,2,0,0,0,0,0, -0,16,30,32,0,0,12,0,0,0,6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16, -190,33,0,0,12,0,0,0,2,0,0,0,0,0,0,144,30,32,64,0,12,0,0,0,4,0,0,0,0,0,0,0,1, -32,0,0,0,0,0,0,0,0,0,0,0,0,0,192,193,61,96,0,12,0,0,0,0,0,0,0,0,0,0,144,64,48, -0,0,12,0,0,0,0,0,0,0,0,0,0,0,30,32,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,4,92,0,0,0, -0,0,0,0,0,0,0,0,242,7,128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,27,0,63,0,0,0,0,0,0, -0,0,0,3,0,0,160,2,0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0, -0,0,0,0,0,0,0,0,0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -28,0,0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,56, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4, -14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,0,0,0,0,0,0,64, -127,229,31,248,159,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0, -0,0,248,15,0,3,0,0,0,60,11,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,255,255,255,255,127,0,0,240,0,248,0,0,0,124,0,0,0,0,0,0,31, -252,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0, -0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,247,63,0,0,0,128,0,0,0,0,0, -0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,255, -255,3,0,0,0,0,0,192,63,0,0,128,255,3,0,0,0,0,0,7,0,0,0,0,0,200,19,0,0,0,0,0,0, -0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0,0,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,127,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,32,110,240,0,0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,3,0,0,0,0,0,120,38,0,0, -0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,192,127,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/usr/lib/libc/ctype/punct.h b/usr/lib/libc/ctype/punct.h deleted file mode 100644 index 466e6b330..000000000 --- a/usr/lib/libc/ctype/punct.h +++ /dev/null @@ -1,109 +0,0 @@ -18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,16,16,34,35,16,36,37,38,39, -40,41,42,43,16,44,45,46,17,47,48,17,17,49,17,17,17,50,51,52,53,54,55,56,57,17, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,58, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,59,16,60,61,62,63,64,65,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,66,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,67,16,16,68,16,69,70,71,16,72,16,73, -16,16,16,16,74,75,76,77,16,16,78,16,79,80,16,16,16,16,81,16,16,16,16,16,16,16, -16,16,16,16,16,16,82,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,83,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,84,85,86,87, -16,16,88,89,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -90,16,91,92,93,94,95,96,97,98,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,0,0,0,0,254,255,0,252,1,0,0,248,1,0,0,120,0,0,0,0,255,251,223, -251,0,0,128,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,0, -252,255,224,175,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255, -255,32,64,176,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -252,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,134,254, -255,255,255,0,64,73,0,0,0,0,0,24,0,223,255,0,200,0,0,0,0,0,0,0,1,0,60,0,0,0,0, -0,0,0,0,0,0,0,0,16,224,1,30,0,96,255,191,0,0,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,248,207,3,0,0,0,3,0,32,255,127,0,0,0,78,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0,0,0,16,0,32,30,0,48,0,1,0,0,0,0,0,0,0,0,16, -0,32,0,0,0,0,252,15,0,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,32,0, -0,0,0,3,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,253,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0, -255,7,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,255,0,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,32,0,0,0,0,63,2,0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,0,0,0,0,0, -128,0,128,192,223,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,254,255,255, -255,0,252,255,255,0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,192,255,223,255,7,0,0,0,0,0, -0,0,0,0,0,128,6,0,252,0,0,24,62,0,0,128,191,0,204,0,0,0,0,0,0,0,0,0,0,0,8,0,0, -0,0,0,0,0,0,0,0,0,96,255,255,255,31,0,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,96,0,0,1,0,0,24,0,0,0,0,0,0,0,0,0,56,0,0,0,0,16,0,0,0,112,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,48,0,0,254,127,47,0,0,255,3,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,49,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,196,255,255,255,255,0,0,0,192,0,0,0,0,0,0,0,0,1,0,224,159,0,0,0,0, -127,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,16,0,0,252,255,255,255,31,0,0,0,0, -0,12,0,0,0,0,0,0,64,0,12,240,0,0,0,0,0,0,192,248,0,0,0,0,0,0,0,192,0,0,0,0,0, -0,0,0,255,0,255,255,255,33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,127,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -160,3,224,0,224,0,224,0,96,128,248,255,255,255,252,255,255,255,255,255,127,31, -252,241,127,255,127,0,0,255,255,255,3,0,0,255,255,255,255,1,0,123,3,208,193, -175,66,0,12,31,188,255,255,0,0,0,0,0,2,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,255, -255,255,127,0,0,0,255,7,0,0,255,255,255,255,255,255,255,255,255,255,63,0,0,0, -0,0,0,252,255,255,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,31,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,135,3,254,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, -127,255,15,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255,255,255,255,255,255, -255,255,15,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15,30,255,255,255,1,252, -193,224,0,0,0,0,0,0,0,0,0,0,0,30,1,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,255,255,255,15,0,0,0,255,255,255,127,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, -255,255,255,255,127,0,0,0,0,0,0,192,0,224,0,0,0,0,0,0,0,0,0,0,0,128,15,112,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,255,127,0,3,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,68,8,0,0,0,15,255,3,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0, -16,192,0,0,255,255,3,7,0,0,0,0,0,248,0,0,0,0,8,128,0,0,0,0,0,0,0,0,0,0,8,0, -255,63,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,128,11,0,0,0,0,0,0,0,128,2, -0,0,192,0,0,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,2,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,255,255,255,3,127,0,255,255,255,255,247, -255,127,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,254,255,0,252,1,0,0,248,1,0, -0,248,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,127,0,48,135,255,255,255,255,255, -143,255,0,0,0,0,0,0,224,255,255,7,255,15,0,0,0,0,0,0,255,255,255,255,255,63,0, -0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,128,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,143,0,0,0,128, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,255,0,255,1, -0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,0,0,0,255,0,0,0, -255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,127,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,63,252,255,63,0,0,0,3,0,0,0, -0,0,0,254,3,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -225,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,63,0,255,255,255,255,127,254,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,0, -255,255,255,255,255,255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,255,255,255,255,255,255,255,255,255,255,127,0,255,255,3,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,8,0,0,0, -8,0,0,32,0,0,0,32,0,0,128,0,0,0,128,0,0,0,2,0,0,0,2,0,0,8,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,255,255,255,255,255, -15,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,127,254,127,254, -255,254,255,0,0,0,0,255,7,255,255,255,127,255,255,255,255,255,255,255,15,255, -255,255,255,255,7,0,0,0,0,0,0,0,0,192,255,255,255,7,0,255,255,255,255,255,7, -255,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,1,0,191,255, -255,255,255,255,255,255,255,31,255,255,15,0,255,255,255,255,223,7,0,0,255,255, -1,0,255,255,255,255,255,255,255,127,253,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,30,255,255,255,255,255, -255,255,63,15,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,255,255, -255,255,255,255,255,255,225,255,0,0,0,0,0,0,255,255,255,255,255,255,255,255, -63,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/usr/lib/libc/ctype/toascii.c b/usr/lib/libc/ctype/toascii.c deleted file mode 100644 index f0e48e8e9..000000000 --- a/usr/lib/libc/ctype/toascii.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -/* nonsense function that should NEVER be used! */ -int toascii(int c) -{ - return c & 0x7f; -} diff --git a/usr/lib/libc/ctype/tolower.c b/usr/lib/libc/ctype/tolower.c deleted file mode 100644 index 362d6b2be..000000000 --- a/usr/lib/libc/ctype/tolower.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" - -int tolower(int c) -{ - if (isupper(c)) return c | 32; - return c; -} - -int __tolower_l(int c, locale_t l) -{ - return tolower(c); -} - -weak_alias(__tolower_l, tolower_l); diff --git a/usr/lib/libc/ctype/toupper.c b/usr/lib/libc/ctype/toupper.c deleted file mode 100644 index bbf4e06e8..000000000 --- a/usr/lib/libc/ctype/toupper.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include "libc.h" - -int toupper(int c) -{ - if (islower(c)) return c & 0x5f; - return c; -} - -int __toupper_l(int c, locale_t l) -{ - return toupper(c); -} - -weak_alias(__toupper_l, toupper_l); diff --git a/usr/lib/libc/ctype/towctrans.c b/usr/lib/libc/ctype/towctrans.c deleted file mode 100644 index cf13a8628..000000000 --- a/usr/lib/libc/ctype/towctrans.c +++ /dev/null @@ -1,279 +0,0 @@ -#include -#include -#include "libc.h" - -#define CASEMAP(u1,u2,l) { (u1), (l)-(u1), (u2)-(u1)+1 } -#define CASELACE(u1,u2) CASEMAP((u1),(u2),(u1)+1) - -static const struct { - unsigned short upper; - signed char lower; - unsigned char len; -} casemaps[] = { - CASEMAP(0xc0,0xde,0xe0), - - CASELACE(0x0100,0x012e), - CASELACE(0x0132,0x0136), - CASELACE(0x0139,0x0147), - CASELACE(0x014a,0x0176), - CASELACE(0x0179,0x017d), - - CASELACE(0x370,0x372), - CASEMAP(0x391,0x3a1,0x3b1), - CASEMAP(0x3a3,0x3ab,0x3c3), - CASEMAP(0x400,0x40f,0x450), - CASEMAP(0x410,0x42f,0x430), - - CASELACE(0x460,0x480), - CASELACE(0x48a,0x4be), - CASELACE(0x4c1,0x4cd), - CASELACE(0x4d0,0x50e), - - CASELACE(0x514,0x526), - CASEMAP(0x531,0x556,0x561), - - CASELACE(0x01a0,0x01a4), - CASELACE(0x01b3,0x01b5), - CASELACE(0x01cd,0x01db), - CASELACE(0x01de,0x01ee), - CASELACE(0x01f8,0x021e), - CASELACE(0x0222,0x0232), - CASELACE(0x03d8,0x03ee), - - CASELACE(0x1e00,0x1e94), - CASELACE(0x1ea0,0x1efe), - - CASEMAP(0x1f08,0x1f0f,0x1f00), - CASEMAP(0x1f18,0x1f1d,0x1f10), - CASEMAP(0x1f28,0x1f2f,0x1f20), - CASEMAP(0x1f38,0x1f3f,0x1f30), - CASEMAP(0x1f48,0x1f4d,0x1f40), - - CASEMAP(0x1f68,0x1f6f,0x1f60), - CASEMAP(0x1f88,0x1f8f,0x1f80), - CASEMAP(0x1f98,0x1f9f,0x1f90), - CASEMAP(0x1fa8,0x1faf,0x1fa0), - CASEMAP(0x1fb8,0x1fb9,0x1fb0), - CASEMAP(0x1fba,0x1fbb,0x1f70), - CASEMAP(0x1fc8,0x1fcb,0x1f72), - CASEMAP(0x1fd8,0x1fd9,0x1fd0), - CASEMAP(0x1fda,0x1fdb,0x1f76), - CASEMAP(0x1fe8,0x1fe9,0x1fe0), - CASEMAP(0x1fea,0x1feb,0x1f7a), - CASEMAP(0x1ff8,0x1ff9,0x1f78), - CASEMAP(0x1ffa,0x1ffb,0x1f7c), - - CASELACE(0x246,0x24e), - CASELACE(0x510,0x512), - CASEMAP(0x2160,0x216f,0x2170), - CASEMAP(0x2c00,0x2c2e,0x2c30), - CASELACE(0x2c67,0x2c6b), - CASELACE(0x2c80,0x2ce2), - CASELACE(0x2ceb,0x2ced), - - CASELACE(0xa640,0xa66c), - CASELACE(0xa680,0xa696), - - CASELACE(0xa722,0xa72e), - CASELACE(0xa732,0xa76e), - CASELACE(0xa779,0xa77b), - CASELACE(0xa77e,0xa786), - - CASELACE(0xa790,0xa792), - CASELACE(0xa7a0,0xa7a8), - - CASEMAP(0xff21,0xff3a,0xff41), - { 0,0,0 } -}; - -static const unsigned short pairs[][2] = { - { 'I', 0x0131 }, - { 'S', 0x017f }, - { 0x0130, 'i' }, - { 0x0178, 0x00ff }, - { 0x0181, 0x0253 }, - { 0x0182, 0x0183 }, - { 0x0184, 0x0185 }, - { 0x0186, 0x0254 }, - { 0x0187, 0x0188 }, - { 0x0189, 0x0256 }, - { 0x018a, 0x0257 }, - { 0x018b, 0x018c }, - { 0x018e, 0x01dd }, - { 0x018f, 0x0259 }, - { 0x0190, 0x025b }, - { 0x0191, 0x0192 }, - { 0x0193, 0x0260 }, - { 0x0194, 0x0263 }, - { 0x0196, 0x0269 }, - { 0x0197, 0x0268 }, - { 0x0198, 0x0199 }, - { 0x019c, 0x026f }, - { 0x019d, 0x0272 }, - { 0x019f, 0x0275 }, - { 0x01a6, 0x0280 }, - { 0x01a7, 0x01a8 }, - { 0x01a9, 0x0283 }, - { 0x01ac, 0x01ad }, - { 0x01ae, 0x0288 }, - { 0x01af, 0x01b0 }, - { 0x01b1, 0x028a }, - { 0x01b2, 0x028b }, - { 0x01b7, 0x0292 }, - { 0x01b8, 0x01b9 }, - { 0x01bc, 0x01bd }, - { 0x01c4, 0x01c6 }, - { 0x01c4, 0x01c5 }, - { 0x01c5, 0x01c6 }, - { 0x01c7, 0x01c9 }, - { 0x01c7, 0x01c8 }, - { 0x01c8, 0x01c9 }, - { 0x01ca, 0x01cc }, - { 0x01ca, 0x01cb }, - { 0x01cb, 0x01cc }, - { 0x01f1, 0x01f3 }, - { 0x01f1, 0x01f2 }, - { 0x01f2, 0x01f3 }, - { 0x01f4, 0x01f5 }, - { 0x01f6, 0x0195 }, - { 0x01f7, 0x01bf }, - { 0x0220, 0x019e }, - { 0x0386, 0x03ac }, - { 0x0388, 0x03ad }, - { 0x0389, 0x03ae }, - { 0x038a, 0x03af }, - { 0x038c, 0x03cc }, - { 0x038e, 0x03cd }, - { 0x038f, 0x03ce }, - { 0x0399, 0x0345 }, - { 0x0399, 0x1fbe }, - { 0x03a3, 0x03c2 }, - { 0x03f7, 0x03f8 }, - { 0x03fa, 0x03fb }, - { 0x1e60, 0x1e9b }, - { 0x1e9e, 0xdf }, - - { 0x1f59, 0x1f51 }, - { 0x1f5b, 0x1f53 }, - { 0x1f5d, 0x1f55 }, - { 0x1f5f, 0x1f57 }, - { 0x1fbc, 0x1fb3 }, - { 0x1fcc, 0x1fc3 }, - { 0x1fec, 0x1fe5 }, - { 0x1ffc, 0x1ff3 }, - - { 0x23a, 0x2c65 }, - { 0x23b, 0x23c }, - { 0x23d, 0x19a }, - { 0x23e, 0x2c66 }, - { 0x241, 0x242 }, - { 0x243, 0x180 }, - { 0x244, 0x289 }, - { 0x245, 0x28c }, - { 0x3f4, 0x3b8 }, - { 0x3f9, 0x3f2 }, - { 0x3fd, 0x37b }, - { 0x3fe, 0x37c }, - { 0x3ff, 0x37d }, - { 0x4c0, 0x4cf }, - - { 0x2126, 0x3c9 }, - { 0x212a, 'k' }, - { 0x212b, 0xe5 }, - { 0x2132, 0x214e }, - { 0x2183, 0x2184 }, - { 0x2c60, 0x2c61 }, - { 0x2c62, 0x26b }, - { 0x2c63, 0x1d7d }, - { 0x2c64, 0x27d }, - { 0x2c6d, 0x251 }, - { 0x2c6e, 0x271 }, - { 0x2c6f, 0x250 }, - { 0x2c70, 0x252 }, - { 0x2c72, 0x2c73 }, - { 0x2c75, 0x2c76 }, - { 0x2c7e, 0x23f }, - { 0x2c7f, 0x240 }, - { 0x2cf2, 0x2cf3 }, - - { 0xa77d, 0x1d79 }, - { 0xa78b, 0xa78c }, - { 0xa78d, 0x265 }, - { 0xa7aa, 0x266 }, - - { 0x10c7, 0x2d27 }, - { 0x10cd, 0x2d2d }, - - /* bogus greek 'symbol' letters */ - { 0x376, 0x377 }, - { 0x39c, 0xb5 }, - { 0x392, 0x3d0 }, - { 0x398, 0x3d1 }, - { 0x3a6, 0x3d5 }, - { 0x3a0, 0x3d6 }, - { 0x39a, 0x3f0 }, - { 0x3a1, 0x3f1 }, - { 0x395, 0x3f5 }, - { 0x3cf, 0x3d7 }, - - { 0,0 } -}; - - -static wchar_t __towcase(wchar_t wc, int lower) -{ - int i; - int lmul = 2*lower-1; - int lmask = lower-1; - /* no letters with case in these large ranges */ - if (!iswalpha(wc) - || (unsigned)wc - 0x0600 <= 0x0fff-0x0600 - || (unsigned)wc - 0x2e00 <= 0xa63f-0x2e00 - || (unsigned)wc - 0xa800 <= 0xfeff-0xa800) - return wc; - /* special case because the diff between upper/lower is too big */ - if (lower && (unsigned)wc - 0x10a0 < 0x2e) - if (wc>0x10c5 && wc != 0x10c7 && wc != 0x10cd) return wc; - else return wc + 0x2d00 - 0x10a0; - if (!lower && (unsigned)wc - 0x2d00 < 0x26) - if (wc>0x2d25 && wc != 0x2d27 && wc != 0x2d2d) return wc; - else return wc + 0x10a0 - 0x2d00; - for (i=0; casemaps[i].len; i++) { - int base = casemaps[i].upper + (lmask & casemaps[i].lower); - if ((unsigned)wc-base < casemaps[i].len) { - if (casemaps[i].lower == 1) - return wc + lower - ((wc-casemaps[i].upper)&1); - return wc + lmul*casemaps[i].lower; - } - } - for (i=0; pairs[i][1-lower]; i++) { - if (pairs[i][1-lower] == wc) - return pairs[i][lower]; - } - if ((unsigned)wc - (0x10428 - 0x28*lower) < 0x28) - return wc - 0x28 + 0x50*lower; - return wc; -} - -wint_t towupper(wint_t wc) -{ - return (unsigned)wc < 128 ? toupper(wc) : __towcase(wc, 0); -} - -wint_t towlower(wint_t wc) -{ - return (unsigned)wc < 128 ? tolower(wc) : __towcase(wc, 1); -} - -wint_t __towupper_l(wint_t c, locale_t l) -{ - return towupper(c); -} - -wint_t __towlower_l(wint_t c, locale_t l) -{ - return towlower(c); -} - -weak_alias(__towupper_l, towupper_l); -weak_alias(__towlower_l, towlower_l); diff --git a/usr/lib/libc/ctype/wcswidth.c b/usr/lib/libc/ctype/wcswidth.c deleted file mode 100644 index 5c8a5a4da..000000000 --- a/usr/lib/libc/ctype/wcswidth.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int wcswidth(const wchar_t *wcs, size_t n) -{ - int l=0, k=0; - for (; n-- && *wcs && (k = wcwidth(*wcs)) >= 0; l+=k, wcs++); - return (k < 0) ? k : l; -} diff --git a/usr/lib/libc/ctype/wctrans.c b/usr/lib/libc/ctype/wctrans.c deleted file mode 100644 index b1b126548..000000000 --- a/usr/lib/libc/ctype/wctrans.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include "libc.h" - -wctrans_t wctrans(const char *class) -{ - if (!strcmp(class, "toupper")) return (wctrans_t)1; - if (!strcmp(class, "tolower")) return (wctrans_t)2; - return 0; -} - -wint_t towctrans(wint_t wc, wctrans_t trans) -{ - if (trans == (wctrans_t)1) return towupper(wc); - if (trans == (wctrans_t)2) return towlower(wc); - return wc; -} - -wctrans_t __wctrans_l(const char *s, locale_t l) -{ - return wctrans(s); -} - -wint_t __towctrans_l(wint_t c, wctrans_t t, locale_t l) -{ - return towctrans(c, t); -} - -weak_alias(__wctrans_l, wctrans_l); -weak_alias(__towctrans_l, towctrans_l); diff --git a/usr/lib/libc/ctype/wcwidth.c b/usr/lib/libc/ctype/wcwidth.c deleted file mode 100644 index 49c40eea8..000000000 --- a/usr/lib/libc/ctype/wcwidth.c +++ /dev/null @@ -1,29 +0,0 @@ -#include - -static const unsigned char table[] = { -#include "nonspacing.h" -}; - -static const unsigned char wtable[] = { -#include "wide.h" -}; - -int wcwidth(wchar_t wc) -{ - if (wc < 0xffU) - return (wc+1 & 0x7f) >= 0x21 ? 1 : wc ? -1 : 0; - if ((wc & 0xfffeffffU) < 0xfffe) { - if ((table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1) - return 0; - if ((wtable[wtable[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1) - return 2; - return 1; - } - if ((wc & 0xfffe) == 0xfffe) - return -1; - if (wc-0x20000U < 0x20000) - return 2; - if (wc == 0xe0001 || wc-0xe0020U < 0x5f || wc-0xe0100 < 0xef) - return 0; - return 1; -} diff --git a/usr/lib/libc/ctype/wide.h b/usr/lib/libc/ctype/wide.h deleted file mode 100644 index 125d0ce39..000000000 --- a/usr/lib/libc/ctype/wide.h +++ /dev/null @@ -1,42 +0,0 @@ -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,19,16,16,16,16,16,16,16,16,16,16,20,21,22,23,24,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,25, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,26,16,16,16,16,27,16,16,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,28,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,16,16,16,29,30,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,31,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,32,16,16,16,16,16,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0, -0,248,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255, -255,255,255,255,255,255,255,15,0,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15, -255,255,255,255,255,255,255,127,254,255,255,255,255,255,255,255,255,255,127, -254,255,255,255,255,255,255,255,255,255,255,255,255,224,255,255,255,255,63, -254,255,255,255,255,255,255,255,255,255,255,127,255,255,255,255,255,7,255,255, -255,255,15,0,255,255,255,255,255,127,255,255,255,255,255,0,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,31,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255, -255,127,248,255,255,255,255,255,15,0,0,255,3,0,0,255,255,255,255,247,255,127, -15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,255,255,255,255,255,255, -255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,255,255,255,255,255,7,255,1,3,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/usr/lib/libc/dirent/CMakeLists.txt b/usr/lib/libc/dirent/CMakeLists.txt deleted file mode 100644 index c9f7d8eec..000000000 --- a/usr/lib/libc/dirent/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ - -target_sources(c - PRIVATE - opendir.c - readdir.c - closedir.c -) diff --git a/usr/lib/libc/dirent/__dirent.h b/usr/lib/libc/dirent/__dirent.h deleted file mode 100644 index 32871baf5..000000000 --- a/usr/lib/libc/dirent/__dirent.h +++ /dev/null @@ -1,9 +0,0 @@ -struct __dirstream -{ - int fd; - off_t tell; - int buf_pos; - int buf_end; - volatile int lock[2]; - char buf[2048]; -}; diff --git a/usr/lib/libc/dirent/__getdents.c b/usr/lib/libc/dirent/__getdents.c deleted file mode 100644 index 1acd5a696..000000000 --- a/usr/lib/libc/dirent/__getdents.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int __getdents(int fd, struct dirent *buf, size_t len) -{ - return syscall(SYS_getdents, fd, buf, len); -} - -weak_alias(__getdents, getdents); - -LFS64(getdents); diff --git a/usr/lib/libc/dirent/alphasort.c b/usr/lib/libc/dirent/alphasort.c deleted file mode 100644 index 42050fb7c..000000000 --- a/usr/lib/libc/dirent/alphasort.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include "libc.h" - -int alphasort(const struct dirent **a, const struct dirent **b) -{ - return strcoll((*a)->d_name, (*b)->d_name); -} - -LFS64(alphasort); diff --git a/usr/lib/libc/dirent/closedir.c b/usr/lib/libc/dirent/closedir.c deleted file mode 100644 index 81e9591c6..000000000 --- a/usr/lib/libc/dirent/closedir.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "__dirent.h" -#include "libc.h" - -int closedir(DIR *dir) -{ - int ret = close(dir->fd); - free(dir); - return ret; -} diff --git a/usr/lib/libc/dirent/dirfd.c b/usr/lib/libc/dirent/dirfd.c deleted file mode 100644 index 6c8600739..000000000 --- a/usr/lib/libc/dirent/dirfd.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "__dirent.h" - -int dirfd(DIR *d) -{ - return d->fd; -} diff --git a/usr/lib/libc/dirent/fdopendir.c b/usr/lib/libc/dirent/fdopendir.c deleted file mode 100644 index c377271da..000000000 --- a/usr/lib/libc/dirent/fdopendir.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include -#include -#include "__dirent.h" - -DIR *fdopendir(int fd) -{ - DIR *dir; - struct stat st; - - if (fstat(fd, &st) < 0) { - 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; -} diff --git a/usr/lib/libc/dirent/opendir.c b/usr/lib/libc/dirent/opendir.c deleted file mode 100644 index 4242acace..000000000 --- a/usr/lib/libc/dirent/opendir.c +++ /dev/null @@ -1,27 +0,0 @@ - -#include -#include -#include -#include "__dirent.h" -#include - -#include -DIR *opendir(const char *name) -{ - int fd; - DIR *dir; - - if ((fd = open(name, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) < 0) - return 0; - if (!(dir = calloc(1, sizeof *dir))) { - sys_close(fd); -#if 0 - __syscall(SYS_close, fd); -#endif - return 0; - } - - dir->fd = fd; - - return dir; -} diff --git a/usr/lib/libc/dirent/readdir.c b/usr/lib/libc/dirent/readdir.c deleted file mode 100644 index 758f58e51..000000000 --- a/usr/lib/libc/dirent/readdir.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include "__dirent.h" -#include -#include - -int __getdents(int, struct dirent *, size_t); - -struct dirent *readdir(DIR *dir) -{ - struct dirent *de; - - if (dir->buf_pos >= dir->buf_end) { - - int len = sys_readdir(dir->fd, dir->buf, sizeof dir->buf); - -#if 0 - int len = __syscall(SYS_getdents, dir->fd, dir->buf, sizeof dir->buf); -#endif - if (len <= 0) { - if (len < 0 && len != -ENOENT) errno = -len; - return 0; - } - dir->buf_end = len; - dir->buf_pos = 0; - } - de = (void *)(dir->buf + dir->buf_pos); - dir->buf_pos += de->d_reclen; - dir->tell = de->d_off; - return de; - -} - - diff --git a/usr/lib/libc/dirent/readdir_r.c b/usr/lib/libc/dirent/readdir_r.c deleted file mode 100644 index daa6c6ed6..000000000 --- a/usr/lib/libc/dirent/readdir_r.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include "__dirent.h" -#include "libc.h" - -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; -} - -LFS64_2(readdir_r, readdir64_r); diff --git a/usr/lib/libc/dirent/rewinddir.c b/usr/lib/libc/dirent/rewinddir.c deleted file mode 100644 index f2053008b..000000000 --- a/usr/lib/libc/dirent/rewinddir.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "__dirent.h" -#include "libc.h" - -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); -} diff --git a/usr/lib/libc/dirent/scandir.c b/usr/lib/libc/dirent/scandir.c deleted file mode 100644 index 3af2b50f8..000000000 --- a/usr/lib/libc/dirent/scandir.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "libc.h" - -int scandir(const char *path, struct dirent ***res, - int (*sel)(const struct dirent *), - int (*cmp)(const struct dirent **, const struct dirent **)) -{ - DIR *d = opendir(path); - struct dirent *de, **names=0, **tmp; - size_t cnt=0, len=0; - int old_errno = errno; - - if (!d) return -1; - - while ((errno=0), (de = readdir(d))) { - if (sel && !sel(de)) continue; - if (cnt >= len) { - len = 2*len+1; - if (len > SIZE_MAX/sizeof *names) break; - tmp = realloc(names, len * sizeof *names); - if (!tmp) break; - names = tmp; - } - names[cnt] = malloc(de->d_reclen); - if (!names[cnt]) break; - memcpy(names[cnt++], de, de->d_reclen); - } - - closedir(d); - - if (errno) { - if (names) while (cnt-->0) free(names[cnt]); - free(names); - return -1; - } - errno = old_errno; - - if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp); - *res = names; - return cnt; -} - -LFS64(scandir); diff --git a/usr/lib/libc/dirent/seekdir.c b/usr/lib/libc/dirent/seekdir.c deleted file mode 100644 index 5be47d4a1..000000000 --- a/usr/lib/libc/dirent/seekdir.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "__dirent.h" -#include "libc.h" - -void seekdir(DIR *dir, long off) -{ - LOCK(dir->lock); - dir->tell = lseek(dir->fd, off, SEEK_SET); - dir->buf_pos = dir->buf_end = 0; - UNLOCK(dir->lock); -} diff --git a/usr/lib/libc/dirent/telldir.c b/usr/lib/libc/dirent/telldir.c deleted file mode 100644 index cf25acff6..000000000 --- a/usr/lib/libc/dirent/telldir.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "__dirent.h" - -long telldir(DIR *dir) -{ - return dir->tell; -} diff --git a/usr/lib/libc/dirent/versionsort.c b/usr/lib/libc/dirent/versionsort.c deleted file mode 100644 index 410cb7034..000000000 --- a/usr/lib/libc/dirent/versionsort.c +++ /dev/null @@ -1,12 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include "libc.h" - -int versionsort(const struct dirent **a, const struct dirent **b) -{ - return strverscmp((*a)->d_name, (*b)->d_name); -} - -#undef versionsort64 -LFS64(versionsort); diff --git a/usr/lib/libc/eabi_compat.c b/usr/lib/libc/eabi_compat.c deleted file mode 100644 index 419e28c35..000000000 --- a/usr/lib/libc/eabi_compat.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2014-2018 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/* eabi_compat.c - * - * Utility functions needed for (some) EABI conformant tool chains. - * Required to be able to link against libgcc which provides integer division - * callbacks and other EABI functions' implementation. - * Taken from U-Boot's arch/arm/lib/eabi_compat.c - */ - -int raise (int signum) { - return 0; -} - -/* Dummy function to avoid linker complaints */ -void __aeabi_unwind_cpp_pr0(void) -{ -}; - -void __aeabi_unwind_cpp_pr1(void) -{ -}; diff --git a/usr/lib/libc/env/CMakeLists.txt b/usr/lib/libc/env/CMakeLists.txt deleted file mode 100644 index e12f11ff4..000000000 --- a/usr/lib/libc/env/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ - - -target_sources(c - PRIVATE - clearenv.c - getenv.c - putenv.c - setenv.c - unsetenv.c - __environ.c -) diff --git a/usr/lib/libc/env/__environ.c b/usr/lib/libc/env/__environ.c deleted file mode 100644 index 8c992e5a3..000000000 --- a/usr/lib/libc/env/__environ.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -char **__environ = 0; -weak_alias(__environ, ___environ); -weak_alias(__environ, _environ); -weak_alias(__environ, environ); diff --git a/usr/lib/libc/env/__init_tls.c b/usr/lib/libc/env/__init_tls.c deleted file mode 100644 index b125eb1f5..000000000 --- a/usr/lib/libc/env/__init_tls.c +++ /dev/null @@ -1,136 +0,0 @@ -#include -#include -#include -#include -#include -#include "pthread_impl.h" -#include "libc.h" -#include "atomic.h" -#include "syscall.h" - -int __init_tp(void *p) -{ - pthread_t td = p; - td->self = td; - int r = __set_thread_area(TP_ADJ(p)); - if (r < 0) return -1; - if (!r) libc.can_do_threads = 1; - td->tid = __syscall(SYS_set_tid_address, &td->tid); - td->locale = &libc.global_locale; - td->robust_list.head = &td->robust_list.head; - return 0; -} - -static struct builtin_tls { - char c; - struct pthread pt; - void *space[16]; -} builtin_tls[1]; -#define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt) - -static struct tls_module main_tls; - -void *__copy_tls(unsigned char *mem) -{ - pthread_t td; - struct tls_module *p; - size_t i; - void **dtv; - -#ifdef TLS_ABOVE_TP - dtv = (void **)(mem + libc.tls_size) - (libc.tls_cnt + 1); - - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1); - td = (pthread_t)mem; - mem += sizeof(struct pthread); - - for (i=1, p=libc.tls_head; p; i++, p=p->next) { - dtv[i] = mem + p->offset; - memcpy(dtv[i], p->image, p->len); - } -#else - dtv = (void **)mem; - - mem += libc.tls_size - sizeof(struct pthread); - mem -= (uintptr_t)mem & (libc.tls_align-1); - td = (pthread_t)mem; - - for (i=1, p=libc.tls_head; p; i++, p=p->next) { - dtv[i] = mem - p->offset; - memcpy(dtv[i], p->image, p->len); - } -#endif - dtv[0] = (void *)libc.tls_cnt; - td->dtv = td->dtv_copy = dtv; - return td; -} - -#if ULONG_MAX == 0xffffffff -typedef Elf32_Phdr Phdr; -#else -typedef Elf64_Phdr Phdr; -#endif - -__attribute__((__weak__, __visibility__("hidden"))) -extern const size_t _DYNAMIC[]; - -static void static_init_tls(size_t *aux) -{ - unsigned char *p; - size_t n; - Phdr *phdr, *tls_phdr=0; - size_t base = 0; - void *mem; - - for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) { - phdr = (void *)p; - if (phdr->p_type == PT_PHDR) - base = aux[AT_PHDR] - phdr->p_vaddr; - if (phdr->p_type == PT_DYNAMIC && _DYNAMIC) - base = (size_t)_DYNAMIC - phdr->p_vaddr; - if (phdr->p_type == PT_TLS) - tls_phdr = phdr; - } - - if (tls_phdr) { - main_tls.image = (void *)(base + tls_phdr->p_vaddr); - main_tls.len = tls_phdr->p_filesz; - main_tls.size = tls_phdr->p_memsz; - main_tls.align = tls_phdr->p_align; - libc.tls_cnt = 1; - libc.tls_head = &main_tls; - } - - main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) - & (main_tls.align-1); - if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; -#ifndef TLS_ABOVE_TP - main_tls.offset = main_tls.size; -#endif - - libc.tls_align = main_tls.align; - libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread) - + main_tls.size + main_tls.align - + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN; - - if (libc.tls_size > sizeof builtin_tls) { -#ifndef SYS_mmap2 -#define SYS_mmap2 SYS_mmap -#endif - mem = (void *)__syscall( - SYS_mmap2, - 0, libc.tls_size, PROT_READ|PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - /* -4095...-1 cast to void * will crash on dereference anyway, - * so don't bloat the init code checking for error codes and - * explicitly calling a_crash(). */ - } else { - mem = builtin_tls; - } - - /* Failure to initialize thread pointer is always fatal. */ - if (__init_tp(__copy_tls(mem)) < 0) - a_crash(); -} - -weak_alias(static_init_tls, __init_tls); diff --git a/usr/lib/libc/env/__libc_start_main.c b/usr/lib/libc/env/__libc_start_main.c deleted file mode 100644 index f2a7ec374..000000000 --- a/usr/lib/libc/env/__libc_start_main.c +++ /dev/null @@ -1,84 +0,0 @@ - -#include - -#include -//#include -#include -#include -#include -#include -#include - -void __init_tls(size_t *); - -static void dummy(void) {} -weak_alias(dummy, _init); - -__attribute__((__weak__, __visibility__("hidden"))) -extern void (*const __init_array_start)(void), (*const __init_array_end)(void); - -static void dummy1(void *p) {} -weak_alias(dummy1, __init_ssp); - -#define AUX_CNT 38 - -void __init_libc(char **envp, char *pn) -{ - size_t i, *auxv, aux[AUX_CNT] = { 0 }; - __environ = envp; - for (i=0; envp[i]; i++); - libc.auxv = auxv = (void *)(envp+i+1); - for (i=0; auxv[i]; i+=2) if (auxv[i] -#include "pthread_impl.h" -#include "libc.h" - -void __reset_tls() -{ - pthread_t self = __pthread_self(); - struct tls_module *p; - size_t i, n = (size_t)self->dtv[0]; - if (n) for (p=libc.tls_head, i=1; i<=n; i++, p=p->next) { - if (!self->dtv[i]) continue; - memcpy(self->dtv[i], p->image, p->len); - memset((char *)self->dtv[i]+p->len, 0, - p->size - p->len); - } -} diff --git a/usr/lib/libc/env/__stack_chk_fail.c b/usr/lib/libc/env/__stack_chk_fail.c deleted file mode 100644 index 4de82fd9d..000000000 --- a/usr/lib/libc/env/__stack_chk_fail.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include "pthread_impl.h" - -uintptr_t __stack_chk_guard; - -void __init_ssp(void *entropy) -{ - if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t)); - else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245; - - __pthread_self()->CANARY = __stack_chk_guard; -} - -void __stack_chk_fail(void) -{ - a_crash(); -} - -__attribute__((__visibility__("hidden"))) -void __stack_chk_fail_local(void); - -weak_alias(__stack_chk_fail, __stack_chk_fail_local); diff --git a/usr/lib/libc/env/clearenv.c b/usr/lib/libc/env/clearenv.c deleted file mode 100644 index 15b871c96..000000000 --- a/usr/lib/libc/env/clearenv.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include - -extern char **__environ; - -int clearenv() -{ - __environ[0] = 0; - return 0; -} diff --git a/usr/lib/libc/env/getenv.c b/usr/lib/libc/env/getenv.c deleted file mode 100644 index 881b4b12d..000000000 --- a/usr/lib/libc/env/getenv.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -char *getenv(const char *name) -{ - int i; - size_t l = strlen(name); - if (!__environ || !*name || strchr(name, '=')) return NULL; - for (i=0; __environ[i] && (strncmp(name, __environ[i], l) - || __environ[i][l] != '='); i++); - if (__environ[i]) return __environ[i] + l+1; - return NULL; -} diff --git a/usr/lib/libc/env/putenv.c b/usr/lib/libc/env/putenv.c deleted file mode 100644 index 03a6a9234..000000000 --- a/usr/lib/libc/env/putenv.c +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include - -extern char **__environ; -char **__env_map; - -int __putenv(char *s, int a) -{ - int i=0, j=0; - char *z = strchr(s, '='); - char **newenv = 0; - char **newmap = 0; - static char **oldenv = NULL; - - if (!z) return unsetenv(s); - if (z==s) return -1; - for (; __environ[i] && memcmp(s, __environ[i], z-s+1); i++); - if (a) { - if (!__env_map) { - __env_map = calloc(2, sizeof(char *)); - if (__env_map) __env_map[0] = s; - } else { - for (; __env_map[j] && __env_map[j] != __environ[i]; j++); - if (!__env_map[j]) { - newmap = realloc(__env_map, sizeof(char *)*(j+2)); - if (newmap) { - __env_map = newmap; - __env_map[j] = s; - __env_map[j+1] = NULL; - } - } else { - free(__env_map[j]); - __env_map[j] = s; - } - } - } - if (!__environ[i]) { - newenv = malloc(sizeof(char *)*(i+2)); - if (!newenv) { - if (a && __env_map) __env_map[j] = 0; - return -1; - } - memcpy(newenv, __environ, sizeof(char *)*i); - newenv[i] = s; - newenv[i+1] = 0; - __environ = newenv; - if (oldenv) { - free(oldenv); - } - - oldenv = __environ; - } - - __environ[i] = s; - return 0; -} - -int putenv(char *s) -{ - return __putenv(s, 0); -} diff --git a/usr/lib/libc/env/setenv.c b/usr/lib/libc/env/setenv.c deleted file mode 100644 index 76e8ee120..000000000 --- a/usr/lib/libc/env/setenv.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -int __putenv(char *s, int a); - -int setenv(const char *var, const char *value, int overwrite) -{ - char *s; - int l1, l2; - - if (!var || !*var || strchr(var, '=')) { - errno = EINVAL; - return -1; - } - if (!overwrite && getenv(var)) return 0; - - l1 = strlen(var); - l2 = strlen(value); - s = malloc(l1+l2+2); - if (s) { - memcpy(s, var, l1); - s[l1] = '='; - memcpy(s+l1+1, value, l2); - s[l1+l2+1] = 0; - if (!__putenv(s, 1)) return 0; - } - free(s); - return -1; -} diff --git a/usr/lib/libc/env/unsetenv.c b/usr/lib/libc/env/unsetenv.c deleted file mode 100644 index 356933546..000000000 --- a/usr/lib/libc/env/unsetenv.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -extern char **__environ; -extern char **__env_map; - -int unsetenv(const char *name) -{ - int i, j; - size_t l = strlen(name); - - if (!*name || strchr(name, '=')) { - errno = EINVAL; - return -1; - } -again: - for (i=0; __environ[i] && (memcmp(name, __environ[i], l) || __environ[i][l] != '='); i++); - if (__environ[i]) { - if (__env_map) { - for (j=0; __env_map[j] && __env_map[j] != __environ[i]; j++); - free (__env_map[j]); - for (; __env_map[j]; j++) - __env_map[j] = __env_map[j+1]; - } - for (; __environ[i]; i++) - __environ[i] = __environ[i+1]; - goto again; - } - return 0; -} diff --git a/usr/lib/libc/errno/CMakeLists.txt b/usr/lib/libc/errno/CMakeLists.txt deleted file mode 100644 index f23781084..000000000 --- a/usr/lib/libc/errno/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - - -target_sources(c - PRIVATE - strerror.c -) \ No newline at end of file diff --git a/usr/lib/libc/errno/__errno_location.c b/usr/lib/libc/errno/__errno_location.c deleted file mode 100644 index 7172a1be3..000000000 --- a/usr/lib/libc/errno/__errno_location.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int *__errno_location(void) -{ - return &__pthread_self()->errno_val; -} diff --git a/usr/lib/libc/errno/__strerror.h b/usr/lib/libc/errno/__strerror.h deleted file mode 100644 index 915044b5c..000000000 --- a/usr/lib/libc/errno/__strerror.h +++ /dev/null @@ -1,104 +0,0 @@ -/* This file is sorted such that 'errors' which represent exceptional - * conditions under which a correct program may fail come first, followed - * by messages that indicate an incorrect program or system failure. The - * macro E() along with double-inclusion is used to ensure that ordering - * of the strings remains synchronized. */ - -E(EILSEQ, "Illegal byte sequence") -E(EDOM, "Domain error") -E(ERANGE, "Result not representable") - -E(ENOTTY, "Not a tty") -E(EACCES, "Permission denied") -E(EPERM, "Operation not permitted") -E(ENOENT, "No such file or directory") -E(ESRCH, "No such process") -E(EEXIST, "File exists") - -E(EOVERFLOW, "Value too large for data type") -E(ENOSPC, "No space left on device") -E(ENOMEM, "Out of memory") - -E(EBUSY, "Resource busy") -E(EINTR, "Interrupted system call") -E(EAGAIN, "Resource temporarily unavailable") -E(ESPIPE, "Invalid seek") - -E(EXDEV, "Cross-device link") -E(EROFS, "Read-only file system") -E(ENOTEMPTY, "Directory not empty") - -E(ECONNRESET, "Connection reset by peer") -E(ETIMEDOUT, "Operation timed out") -E(ECONNREFUSED, "Connection refused") -E(EHOSTDOWN, "Host is down") -E(EHOSTUNREACH, "Host is unreachable") -E(EADDRINUSE, "Address in use") - -E(EPIPE, "Broken pipe") -E(EIO, "I/O error") -E(ENXIO, "No such device or address") -E(ENOTBLK, "Block device required") -E(ENODEV, "No such device") -E(ENOTDIR, "Not a directory") -E(EISDIR, "Is a directory") -E(ETXTBSY, "Text file busy") -E(ENOEXEC, "Exec format error") - -E(EINVAL, "Invalid argument") - -E(E2BIG, "Argument list too long") -E(ELOOP, "Symbolic link loop") -E(ENAMETOOLONG, "Filename too long") -E(ENFILE, "Too many open files in system") -E(EMFILE, "No file descriptors available") -E(EBADF, "Bad file descriptor") -E(ECHILD, "No child process") -E(EFAULT, "Bad address") -E(EFBIG, "File too large") -E(EMLINK, "Too many links") -E(ENOLCK, "No locks available") - -E(EDEADLK, "Resource deadlock would occur") -E(ENOTRECOVERABLE, "State not recoverable") -E(EOWNERDEAD, "Previous owner died") -E(ECANCELED, "Operation canceled") -E(ENOSYS, "Function not implemented") -E(ENOMSG, "No message of desired type") -E(EIDRM, "Identifier removed") -E(ENOSTR, "Device not a stream") -E(ENODATA, "No data available") -E(ETIME, "Device timeout") -E(ENOSR, "Out of streams resources") -E(ENOLINK, "Link has been severed") -E(EPROTO, "Protocol error") -E(EBADMSG, "Bad message") -E(EBADFD, "File descriptor in bad state") -E(ENOTSOCK, "Not a socket") -E(EDESTADDRREQ, "Destination address required") -E(EMSGSIZE, "Message too large") -E(EPROTOTYPE, "Protocol wrong type for socket") -E(ENOPROTOOPT, "Protocol not available") -E(EPROTONOSUPPORT,"Protocol not supported") -E(ESOCKTNOSUPPORT,"Socket type not supported") -E(ENOTSUP, "Not supported") -E(EPFNOSUPPORT, "Protocol family not supported") -E(EAFNOSUPPORT, "Address family not supported by protocol") -E(EADDRNOTAVAIL,"Address not available") -E(ENETDOWN, "Network is down") -E(ENETUNREACH, "Network unreachable") -E(ENETRESET, "Connection reset by network") -E(ECONNABORTED, "Connection aborted") -E(ENOBUFS, "No buffer space available") -E(EISCONN, "Socket is connected") -E(ENOTCONN, "Socket not connected") -E(ESHUTDOWN, "Cannot send after socket shutdown") -E(EALREADY, "Operation already in progress") -E(EINPROGRESS, "Operation in progress") -E(ESTALE, "Stale file handle") -E(EREMOTEIO, "Remote I/O error") -E(EDQUOT, "Quota exceeded") -E(ENOMEDIUM, "No medium found") -E(EMEDIUMTYPE, "Wrong medium type") - -E(0, "No error information") diff --git a/usr/lib/libc/errno/strerror.c b/usr/lib/libc/errno/strerror.c deleted file mode 100644 index 8289ba400..000000000 --- a/usr/lib/libc/errno/strerror.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include - -#if 0 -#include "locale_impl.h" -#endif - -#include "libc.h" - -#define E(a,b) ((unsigned char)a), -static const unsigned char errid[] = { -#include "__strerror.h" -}; - -#undef E -#define E(a,b) b "\0" -static const char errmsg[] = -#include "__strerror.h" -; - -char *__strerror_l(int e, locale_t loc) -{ - const char *s; - int i; - /* mips has one error code outside of the 8-bit range due to a - * historical typo, so we just remap it. */ - if (EDQUOT==1133) { - if (e==109) e=-1; - else if (e==EDQUOT) e=109; - } - for (i=0; errid[i] && errid[i] != e; i++); - for (s=errmsg; i; s++, i--) for (; *s; s++); -#if 0 - return (char *)LCTRANS(s, LC_MESSAGES, loc); -#endif - return NULL; -} - -char *strerror(int e) -{ -#if 0 - return __strerror_l(e, CURRENT_LOCALE); -#endif - return "Not yet implemented\n"; -} - -weak_alias(__strerror_l, strerror_l); diff --git a/usr/lib/libc/exit/CMakeLists.txt b/usr/lib/libc/exit/CMakeLists.txt deleted file mode 100644 index d378bbf1b..000000000 --- a/usr/lib/libc/exit/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ - -target_sources(c - PRIVATE - assert.c - abort.c - exit.c - _Exit.c -) \ No newline at end of file diff --git a/usr/lib/libc/exit/_Exit.c b/usr/lib/libc/exit/_Exit.c deleted file mode 100644 index 280a9bcd4..000000000 --- a/usr/lib/libc/exit/_Exit.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -_Noreturn void _Exit(int ec) -{ - sys_exit(ec); - -#if 0 - __syscall(SYS_exit_group, ec); - for (;;) __syscall(SYS_exit, ec); -#endif /* 0 */ -} diff --git a/usr/lib/libc/exit/abort.c b/usr/lib/libc/exit/abort.c deleted file mode 100644 index 7cc03d7e4..000000000 --- a/usr/lib/libc/exit/abort.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#if 0 -#include -#endif - -#include - -#if 0 -#include -#include -#endif - -_Noreturn void abort(void) -{ -#if 0 - raise(SIGABRT); - __block_all_sigs(0); - a_crash(); - raise(SIGKILL); -#endif /* 0 */ - _Exit(127); - -} diff --git a/usr/lib/libc/exit/assert.c b/usr/lib/libc/exit/assert.c deleted file mode 100644 index 49b0dc3ec..000000000 --- a/usr/lib/libc/exit/assert.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -_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); - fflush(NULL); - abort(); -} diff --git a/usr/lib/libc/exit/at_quick_exit.c b/usr/lib/libc/exit/at_quick_exit.c deleted file mode 100644 index 34541bada..000000000 --- a/usr/lib/libc/exit/at_quick_exit.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include "libc.h" - -#define COUNT 32 - -static void (*funcs[COUNT])(void); -static int count; -static volatile int lock[2]; - -void __funcs_on_quick_exit() -{ - void (*func)(void); - LOCK(lock); - while (count > 0) { - func = funcs[--count]; - UNLOCK(lock); - func(); - LOCK(lock); - } -} - -int at_quick_exit(void (*func)(void)) -{ - if (count == 32) return -1; - LOCK(lock); - funcs[count++] = func; - UNLOCK(lock); - return 0; -} diff --git a/usr/lib/libc/exit/atexit.c b/usr/lib/libc/exit/atexit.c deleted file mode 100644 index 2b58b8bbf..000000000 --- a/usr/lib/libc/exit/atexit.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include "libc.h" - -/* Ensure that at least 32 atexit handlers can be registered without malloc */ -#define COUNT 32 - -static struct fl -{ - struct fl *next; - void (*f[COUNT])(void *); - void *a[COUNT]; -} builtin, *head; - -static int slot; -static volatile int lock[2]; - -void __funcs_on_exit() -{ - void (*func)(void *), *arg; - LOCK(lock); - for (; head; head=head->next, slot=COUNT) while(slot-->0) { - func = head->f[slot]; - arg = head->a[slot]; - UNLOCK(lock); - func(arg); - LOCK(lock); - } -} - -void __cxa_finalize(void *dso) -{ -} - -int __cxa_atexit(void (*func)(void *), void *arg, void *dso) -{ - LOCK(lock); - - /* Defer initialization of head so it can be in BSS */ - if (!head) head = &builtin; - - /* If the current function list is full, add a new one */ - if (slot==COUNT) { - struct fl *new_fl = calloc(sizeof(struct fl), 1); - if (!new_fl) { - UNLOCK(lock); - return -1; - } - new_fl->next = head; - head = new_fl; - slot = 0; - } - - /* Append function to the list. */ - head->f[slot] = func; - head->a[slot] = arg; - slot++; - - UNLOCK(lock); - return 0; -} - -static void call(void *p) -{ - ((void (*)(void))(uintptr_t)p)(); -} - -int atexit(void (*func)(void)) -{ - return __cxa_atexit(call, (void *)(uintptr_t)func, 0); -} diff --git a/usr/lib/libc/exit/exit.c b/usr/lib/libc/exit/exit.c deleted file mode 100644 index 42feb6703..000000000 --- a/usr/lib/libc/exit/exit.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -static void dummy() -{ -} - -/* atexit.c and __stdio_exit.c override these. the latter is linked - * as a consequence of linking either __toread.c or __towrite.c. */ -weak_alias(dummy, __funcs_on_exit); -weak_alias(dummy, __stdio_exit); -weak_alias(dummy, _fini); - -__attribute__((__weak__, __visibility__("hidden"))) -extern void (*const __fini_array_start)(void), (*const __fini_array_end)(void); - -static void libc_exit_fini(void) -{ - uintptr_t a = (uintptr_t)&__fini_array_end; - for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)())) - (*(void (**)())(a-sizeof(void(*)())))(); - _fini(); -} - -weak_alias(libc_exit_fini, __libc_exit_fini); - -_Noreturn void exit(int code) -{ - __funcs_on_exit(); - __libc_exit_fini(); - __stdio_exit(); - _Exit(code); -} diff --git a/usr/lib/libc/exit/quick_exit.c b/usr/lib/libc/exit/quick_exit.c deleted file mode 100644 index ada91348b..000000000 --- a/usr/lib/libc/exit/quick_exit.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "libc.h" - -static void dummy() { } -weak_alias(dummy, __funcs_on_quick_exit); - -_Noreturn void quick_exit(int code) -{ - __funcs_on_quick_exit(); - _Exit(code); -} diff --git a/usr/lib/libc/fcntl/CMakeLists.txt b/usr/lib/libc/fcntl/CMakeLists.txt deleted file mode 100644 index 7c96da032..000000000 --- a/usr/lib/libc/fcntl/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -target_sources(c - PRIVATE - open.c -) \ No newline at end of file diff --git a/usr/lib/libc/fcntl/creat.c b/usr/lib/libc/fcntl/creat.c deleted file mode 100644 index be05faae9..000000000 --- a/usr/lib/libc/fcntl/creat.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "libc.h" - -int creat(const char *filename, mode_t mode) -{ - return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode); -} - -LFS64(creat); diff --git a/usr/lib/libc/fcntl/fcntl.c b/usr/lib/libc/fcntl/fcntl.c deleted file mode 100644 index ce615d0e5..000000000 --- a/usr/lib/libc/fcntl/fcntl.c +++ /dev/null @@ -1,49 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -int fcntl(int fd, int cmd, ...) -{ - unsigned long arg; - va_list ap; - va_start(ap, cmd); - arg = va_arg(ap, unsigned long); - va_end(ap); - if (cmd == F_SETFL) arg |= O_LARGEFILE; - if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg); - if (cmd == F_GETOWN) { - struct f_owner_ex ex; - int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex); - if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg); - if (ret) return __syscall_ret(ret); - return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid; - } - if (cmd == F_DUPFD_CLOEXEC) { - int ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, arg); - if (ret != -EINVAL) { - if (ret >= 0) - __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); - return __syscall_ret(ret); - } - ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, 0); - if (ret != -EINVAL) { - if (ret >= 0) __syscall(SYS_close, ret); - return __syscall_ret(-EINVAL); - } - ret = __syscall(SYS_fcntl, fd, F_DUPFD, arg); - if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); - return __syscall_ret(ret); - } - switch (cmd) { - case F_SETLK: - case F_GETLK: - case F_GETOWN_EX: - case F_SETOWN_EX: - return syscall(SYS_fcntl, fd, cmd, (void *)arg); - default: - return syscall(SYS_fcntl, fd, cmd, arg); - } -} diff --git a/usr/lib/libc/fcntl/open.c b/usr/lib/libc/fcntl/open.c deleted file mode 100644 index 44dba8f1f..000000000 --- a/usr/lib/libc/fcntl/open.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include - -int open(const char *filename, int flags, ...) -{ - mode_t mode = 0; - - if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) { - va_list ap; - va_start(ap, flags); - mode = va_arg(ap, mode_t); - va_end(ap); - } - - return __syscall_ret(sys_open(filename, flags, mode)); - -#if 0 /* so3 */ - int fd = __sys_open_cp(filename, flags, mode); - if (fd>=0 && (flags & O_CLOEXEC)) - __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); - - return __syscall_ret(fd); -#endif -} - diff --git a/usr/lib/libc/fcntl/openat.c b/usr/lib/libc/fcntl/openat.c deleted file mode 100644 index e741336c6..000000000 --- a/usr/lib/libc/fcntl/openat.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -int openat(int fd, const char *filename, int flags, ...) -{ - mode_t mode = 0; - - if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) { - va_list ap; - va_start(ap, flags); - mode = va_arg(ap, mode_t); - va_end(ap); - } - - return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode); -} - -LFS64(openat); diff --git a/usr/lib/libc/fcntl/posix_fadvise.c b/usr/lib/libc/fcntl/posix_fadvise.c deleted file mode 100644 index c1a0ef5a2..000000000 --- a/usr/lib/libc/fcntl/posix_fadvise.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int posix_fadvise(int fd, off_t base, off_t len, int advice) -{ -#if defined(SYSCALL_FADVISE_6_ARG) - /* Some archs, at least arm and powerpc, have the syscall - * arguments reordered to avoid needing 7 argument registers - * due to 64-bit argument alignment. */ - return -__syscall(SYS_fadvise, fd, advice, - __SYSCALL_LL_E(base), __SYSCALL_LL_E(len)); -#else - return -__syscall(SYS_fadvise, fd, __SYSCALL_LL_O(base), - __SYSCALL_LL_E(len), advice); -#endif -} - -LFS64(posix_fadvise); diff --git a/usr/lib/libc/fcntl/posix_fallocate.c b/usr/lib/libc/fcntl/posix_fallocate.c deleted file mode 100644 index 91d8063ca..000000000 --- a/usr/lib/libc/fcntl/posix_fallocate.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int posix_fallocate(int fd, off_t base, off_t len) -{ - return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base), - __SYSCALL_LL_E(len)); -} - -LFS64(posix_fallocate); diff --git a/usr/lib/libc/floatscan.c b/usr/lib/libc/floatscan.c deleted file mode 100644 index 83ad63f8f..000000000 --- a/usr/lib/libc/floatscan.c +++ /dev/null @@ -1,510 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "shgetc.h" -#include "floatscan.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - -#define LD_B1B_DIG 2 -#define LD_B1B_MAX 9007199, 254740991 -#define KMAX 128 - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - -#define LD_B1B_DIG 3 -#define LD_B1B_MAX 18, 446744073, 709551615 -#define KMAX 2048 - -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 - -#define LD_B1B_DIG 4 -#define LD_B1B_MAX 10384593, 717069655, 257060992, 658440191 -#define KMAX 2048 - -#else -#error Unsupported long double representation -#endif - -#define MASK (KMAX-1) - -#define CONCAT2(x,y) x ## y -#define CONCAT(x,y) CONCAT2(x,y) - -static long long scanexp(FILE *f, int pok) -{ - int c; - int x; - long long y; - int neg = 0; - - c = shgetc(f); - if (c=='+' || c=='-') { - neg = (c=='-'); - c = shgetc(f); - if (c-'0'>=10U && pok) shunget(f); - } - if (c-'0'>=10U) { - shunget(f); - return LLONG_MIN; - } - for (x=0; c-'0'<10U && x=0) { - shunget(f); - } - if (!gotdig) { - errno = EINVAL; - shlim(f, 0); - return 0; - } - - /* Handle zero specially to avoid nasty special cases later */ - if (!x[0]) return sign * 0.0; - - /* Optimize small integers (w/no exponent) and over/under-flow */ - if (lrp==dc && dc<10 && (bits>30 || x[0]>>bits==0)) - return sign * (long double)x[0]; - if (lrp > -emin/2) { - errno = ERANGE; - return sign * LDBL_MAX * LDBL_MAX; - } - if (lrp < emin-2*LDBL_MANT_DIG) { - errno = ERANGE; - return sign * LDBL_MIN * LDBL_MIN; - } - - /* Align incomplete final B1B digit */ - if (j) { - for (; j<9; j++) x[k]*=10; - k++; - j=0; - } - - a = 0; - z = k; - e2 = 0; - rp = lrp; - - /* Optimize small to mid-size integers (even in exp. notation) */ - if (lnz<9 && lnz<=rp && rp < 18) { - if (rp == 9) return sign * (long double)x[0]; - if (rp < 9) return sign * (long double)x[0] / p10s[8-rp]; - int bitlim = bits-3*(int)(rp-9); - if (bitlim>30 || x[0]>>bitlim==0) - return sign * (long double)x[0] * p10s[rp-10]; - } - - /* Drop trailing zeros */ - for (; !x[z-1]; z--); - - /* Align radix point to B1B digit boundary */ - if (rp % 9) { - int rpm9 = rp>=0 ? rp%9 : rp%9+9; - int p10 = p10s[8-rpm9]; - uint32_t carry = 0; - for (k=a; k!=z; k++) { - uint32_t tmp = x[k] % p10; - x[k] = x[k]/p10 + carry; - carry = 1000000000/p10 * tmp; - if (k==a && !x[k]) { - a = ((a+1) & MASK); - rp -= 9; - } - } - if (carry) x[z++] = carry; - rp += 9-rpm9; - } - - /* Upscale until desired number of bits are left of radix point */ - while (rp < 9*LD_B1B_DIG || (rp == 9*LD_B1B_DIG && x[a] 1000000000) { - carry = tmp / 1000000000; - x[k] = tmp % 1000000000; - } else { - carry = 0; - x[k] = tmp; - } - if (k==((z-1) & MASK) && (k !=a ) && !x[k]) z = k; - if (k==a) break; - } - if (carry) { - rp += 9; - a = ((a-1) & MASK); - if (a == z) { - z = ((z-1) & MASK); - x[(z-1) & MASK] |= x[z]; - } - x[a] = carry; - } - } - - /* Downscale until exactly number of bits are left of radix point */ - for (;;) { - uint32_t carry = 0; - int sh = 1; - for (i=0; i th[i]) break; - } - if (i==LD_B1B_DIG && rp==9*LD_B1B_DIG) break; - /* FIXME: find a way to compute optimal sh */ - if (rp > 9+9*LD_B1B_DIG) sh = 9; - e2 += sh; - for (k=a; k!=z; k=((k+1) & MASK)) { - uint32_t tmp = x[k] & ((1<>sh) + carry; - carry = (1000000000>>sh) * tmp; - if (k==a && !x[k]) { - a = ((a+1) & MASK); - i--; - rp -= 9; - } - } - if (carry) { - if (((z+1) & MASK) != a) { - x[z] = carry; - z = ((z+1) & MASK); - } else x[(z-1) & MASK] |= 1; - } - } - - /* Assemble desired bits into floating point variable */ - for (y=i=0; i LDBL_MANT_DIG+e2-emin) { - bits = LDBL_MANT_DIG+e2-emin; - if (bits<0) bits=0; - denormal = 1; - } - - /* Calculate bias term to force rounding, move out lower bits */ - if (bits < LDBL_MANT_DIG) { - bias = copysignl(scalbn(1, 2*LDBL_MANT_DIG-bits-1), y); - frac = fmodl(y, scalbn(1, LDBL_MANT_DIG-bits)); - y -= frac; - y += bias; - } - - /* Process tail of decimal input so it can affect rounding */ - if (((a+i) & MASK) != z) { - uint32_t t = x[(a+i) & MASK]; - if (t < 500000000 && (t || ((a+i+1) & MASK) != z)) - frac += 0.25*sign; - else if (t > 500000000) - frac += 0.75*sign; - else if (t == 500000000) { - if (((a+i+1) & MASK) == z) - frac += 0.5*sign; - else - frac += 0.75*sign; - } - if (LDBL_MANT_DIG-bits >= 2 && !fmodl(frac, 1)) - frac++; - } - - y += frac; - y -= bias; - - if (((e2+LDBL_MANT_DIG) & INT_MAX) > emax-5) { - if (fabs(y) >= CONCAT(0x1p, LDBL_MANT_DIG)) { - if (denormal && bits==LDBL_MANT_DIG+e2-emin) - denormal = 0; - y *= 0.5; - e2++; - } - if (e2+LDBL_MANT_DIG>emax || (denormal && frac)) - errno = ERANGE; - } - - return scalbnl(y, e2); -} - -static long double hexfloat(FILE *f, int bits, int emin, int sign, int pok) -{ - uint32_t x = 0; - long double y = 0; - long double scale = 1; - long double bias = 0; - int gottail = 0, gotrad = 0, gotdig = 0; - long long rp = 0; - long long dc = 0; - long long e2 = 0; - int d; - int c; - - c = shgetc(f); - - /* Skip leading zeros */ - for (; c=='0'; c = shgetc(f)) gotdig = 1; - - if (c=='.') { - gotrad = 1; - c = shgetc(f); - /* Count zeros after the radix point before significand */ - for (rp=0; c=='0'; c = shgetc(f), rp--) gotdig = 1; - } - - for (; c-'0'<10U || (c|32)-'a'<6U || c=='.'; c = shgetc(f)) { - if (c=='.') { - if (gotrad) break; - rp = dc; - gotrad = 1; - } else { - gotdig = 1; - if (c > '9') d = (c|32)+10-'a'; - else d = c-'0'; - if (dc<8) { - x = x*16 + d; - } else if (dc < LDBL_MANT_DIG/4+1) { - y += d*(scale/=16); - } else if (d && !gottail) { - y += 0.5*scale; - gottail = 1; - } - dc++; - } - } - if (!gotdig) { - shunget(f); - if (pok) { - shunget(f); - if (gotrad) shunget(f); - } else { - shlim(f, 0); - } - return sign * 0.0; - } - if (!gotrad) rp = dc; - while (dc<8) x *= 16, dc++; - if ((c|32)=='p') { - e2 = scanexp(f, pok); - if (e2 == LLONG_MIN) { - if (pok) { - shunget(f); - } else { - shlim(f, 0); - return 0; - } - e2 = 0; - } - } else { - shunget(f); - } - e2 += 4*rp - 32; - - if (!x) return sign * 0.0; - if (e2 > -emin) { - errno = ERANGE; - return sign * LDBL_MAX * LDBL_MAX; - } - if (e2 < emin-2*LDBL_MANT_DIG) { - errno = ERANGE; - return sign * LDBL_MIN * LDBL_MIN; - } - - while (x < 0x80000000) { - if (y>=0.5) { - x += x + 1; - y += y - 1; - } else { - x += x; - y += y; - } - e2--; - } - - if (bits > 32+e2-emin) { - bits = 32+e2-emin; - if (bits<0) bits=0; - } - - if (bits < LDBL_MANT_DIG) - bias = copysignl(scalbn(1, 32+LDBL_MANT_DIG-bits-1), sign); - - if (bits<32 && y && !(x&1)) x++, y=0; - - y = bias + sign*(long double)x + sign*y; - y -= bias; - - if (!y) errno = ERANGE; - - return scalbnl(y, e2); -} - -long double __floatscan(FILE *f, int prec, int pok) -{ - int sign = 1; - size_t i; - int bits; - int emin; - int c; - - switch (prec) { - case 0: - bits = FLT_MANT_DIG; - emin = FLT_MIN_EXP-bits; - break; - case 1: - bits = DBL_MANT_DIG; - emin = DBL_MIN_EXP-bits; - break; - case 2: - bits = LDBL_MANT_DIG; - emin = LDBL_MIN_EXP-bits; - break; - default: - return 0; - } - - while (isspace((c=shgetc(f)))); - - if (c=='+' || c=='-') { - sign -= 2*(c=='-'); - c = shgetc(f); - } - - for (i=0; i<8 && (c|32)=="infinity"[i]; i++) - if (i<7) c = shgetc(f); - if (i==3 || i==8 || (i>3 && pok)) { - if (i!=8) { - shunget(f); - if (pok) for (; i>3; i--) shunget(f); - } - return sign * INFINITY; - } - if (!i) for (i=0; i<3 && (c|32)=="nan"[i]; i++) - if (i<2) c = shgetc(f); - if (i==3) { - if (shgetc(f) != '(') { - shunget(f); - return NAN; - } - for (i=1; ; i++) { - c = shgetc(f); - if (c-'0'<10U || c-'A'<26U || c-'a'<26U || c=='_') - continue; - if (c==')') return NAN; - shunget(f); - if (!pok) { - errno = EINVAL; - shlim(f, 0); - return 0; - } - while (i--) shunget(f); - return NAN; - } - return NAN; - } - - if (i) { - shunget(f); - errno = EINVAL; - shlim(f, 0); - return 0; - } - - if (c=='0') { - c = shgetc(f); - if ((c|32) == 'x') - return hexfloat(f, bits, emin, sign, pok); - shunget(f); - c = '0'; - } - - return decfloat(f, c, bits, emin, sign, pok); -} diff --git a/usr/lib/libc/include/alloca.h b/usr/lib/libc/include/alloca.h deleted file mode 100644 index d2e6f1c68..000000000 --- a/usr/lib/libc/include/alloca.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _ALLOCA_H -#define _ALLOCA_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t -#include - -void *alloca(size_t); - -#ifdef __GNUC__ -#define alloca __builtin_alloca -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/arpa/ftp.h b/usr/lib/libc/include/arpa/ftp.h deleted file mode 100644 index fb0a46f2b..000000000 --- a/usr/lib/libc/include/arpa/ftp.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _ARPA_FTP_H -#define _ARPA_FTP_H -#define PRELIM 1 -#define COMPLETE 2 -#define CONTINUE 3 -#define TRANSIENT 4 -#define ERROR 5 -#define TYPE_A 1 -#define TYPE_E 2 -#define TYPE_I 3 -#define TYPE_L 4 -#define FORM_N 1 -#define FORM_T 2 -#define FORM_C 3 -#define STRU_F 1 -#define STRU_R 2 -#define STRU_P 3 -#define MODE_S 1 -#define MODE_B 2 -#define MODE_C 3 -#define REC_ESC '\377' -#define REC_EOR '\001' -#define REC_EOF '\002' -#define BLK_EOR 0x80 -#define BLK_EOF 0x40 -#define BLK_ERRORS 0x20 -#define BLK_RESTART 0x10 -#define BLK_BYTECOUNT 2 -#ifdef FTP_NAMES -char *modenames[] = {"0", "Stream", "Block", "Compressed" }; -char *strunames[] = {"0", "File", "Record", "Page" }; -char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; -char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; -#endif -#endif diff --git a/usr/lib/libc/include/arpa/inet.h b/usr/lib/libc/include/arpa/inet.h deleted file mode 100644 index 37f8c11ee..000000000 --- a/usr/lib/libc/include/arpa/inet.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _ARPA_INET_H -#define _ARPA_INET_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -in_addr_t inet_addr (const char *); -in_addr_t inet_network (const char *); -char *inet_ntoa (struct in_addr); -int inet_pton (int, const char *__restrict, void *__restrict); -const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); - -int inet_aton (const char *, struct in_addr *); -struct in_addr inet_makeaddr(in_addr_t, in_addr_t); -in_addr_t inet_lnaof(struct in_addr); -in_addr_t inet_netof(struct in_addr); - -#undef INET_ADDRSTRLEN -#undef INET6_ADDRSTRLEN -#define INET_ADDRSTRLEN 16 -#define INET6_ADDRSTRLEN 46 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/arpa/nameser.h b/usr/lib/libc/include/arpa/nameser.h deleted file mode 100644 index 581925a43..000000000 --- a/usr/lib/libc/include/arpa/nameser.h +++ /dev/null @@ -1,455 +0,0 @@ -#ifndef _ARPA_NAMESER_H -#define _ARPA_NAMESER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NAMESER 19991006 -#define NS_PACKETSZ 512 -#define NS_MAXDNAME 1025 -#define NS_MAXMSG 65535 -#define NS_MAXCDNAME 255 -#define NS_MAXLABEL 63 -#define NS_HFIXEDSZ 12 -#define NS_QFIXEDSZ 4 -#define NS_RRFIXEDSZ 10 -#define NS_INT32SZ 4 -#define NS_INT16SZ 2 -#define NS_INT8SZ 1 -#define NS_INADDRSZ 4 -#define NS_IN6ADDRSZ 16 -#define NS_CMPRSFLGS 0xc0 -#define NS_DEFAULTPORT 53 - -typedef enum __ns_sect { - ns_s_qd = 0, - ns_s_zn = 0, - ns_s_an = 1, - ns_s_pr = 1, - ns_s_ns = 2, - ns_s_ud = 2, - ns_s_ar = 3, - ns_s_max = 4 -} ns_sect; - -typedef struct __ns_msg { - const unsigned char *_msg, *_eom; - uint16_t _id, _flags, _counts[ns_s_max]; - const unsigned char *_sections[ns_s_max]; - ns_sect _sect; - int _rrnum; - const unsigned char *_msg_ptr; -} ns_msg; - -struct _ns_flagdata { int mask, shift; }; -extern const struct _ns_flagdata _ns_flagdata[]; - -#define ns_msg_id(handle) ((handle)._id + 0) -#define ns_msg_base(handle) ((handle)._msg + 0) -#define ns_msg_end(handle) ((handle)._eom + 0) -#define ns_msg_size(handle) ((handle)._eom - (handle)._msg) -#define ns_msg_count(handle, section) ((handle)._counts[section] + 0) -#define ns_msg_getflag(handle, flag) \ - (((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift) - -typedef struct __ns_rr { - char name[NS_MAXDNAME]; - uint16_t type; - uint16_t rr_class; - uint32_t ttl; - uint16_t rdlength; - const unsigned char *rdata; -} ns_rr; - -#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") -#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) -#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) -#define ns_rr_ttl(rr) ((rr).ttl + 0) -#define ns_rr_rdlen(rr) ((rr).rdlength + 0) -#define ns_rr_rdata(rr) ((rr).rdata + 0) - -typedef enum __ns_flag { - ns_f_qr, - ns_f_opcode, - ns_f_aa, - ns_f_tc, - ns_f_rd, - ns_f_ra, - ns_f_z, - ns_f_ad, - ns_f_cd, - ns_f_rcode, - ns_f_max -} ns_flag; - -typedef enum __ns_opcode { - ns_o_query = 0, - ns_o_iquery = 1, - ns_o_status = 2, - ns_o_notify = 4, - ns_o_update = 5, - ns_o_max = 6 -} ns_opcode; - -typedef enum __ns_rcode { - ns_r_noerror = 0, - ns_r_formerr = 1, - ns_r_servfail = 2, - ns_r_nxdomain = 3, - ns_r_notimpl = 4, - ns_r_refused = 5, - ns_r_yxdomain = 6, - ns_r_yxrrset = 7, - ns_r_nxrrset = 8, - ns_r_notauth = 9, - ns_r_notzone = 10, - ns_r_max = 11, - ns_r_badvers = 16, - ns_r_badsig = 16, - ns_r_badkey = 17, - ns_r_badtime = 18 -} ns_rcode; - -typedef enum __ns_update_operation { - ns_uop_delete = 0, - ns_uop_add = 1, - ns_uop_max = 2 -} ns_update_operation; - -struct ns_tsig_key { - char name[NS_MAXDNAME], alg[NS_MAXDNAME]; - unsigned char *data; - int len; -}; -typedef struct ns_tsig_key ns_tsig_key; - -struct ns_tcp_tsig_state { - int counter; - struct dst_key *key; - void *ctx; - unsigned char sig[NS_PACKETSZ]; - int siglen; -}; -typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; - -#define NS_TSIG_FUDGE 300 -#define NS_TSIG_TCP_COUNT 100 -#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" - -#define NS_TSIG_ERROR_NO_TSIG -10 -#define NS_TSIG_ERROR_NO_SPACE -11 -#define NS_TSIG_ERROR_FORMERR -12 - -typedef enum __ns_type { - ns_t_invalid = 0, - ns_t_a = 1, - ns_t_ns = 2, - ns_t_md = 3, - ns_t_mf = 4, - ns_t_cname = 5, - ns_t_soa = 6, - ns_t_mb = 7, - ns_t_mg = 8, - ns_t_mr = 9, - ns_t_null = 10, - ns_t_wks = 11, - ns_t_ptr = 12, - ns_t_hinfo = 13, - ns_t_minfo = 14, - ns_t_mx = 15, - ns_t_txt = 16, - ns_t_rp = 17, - ns_t_afsdb = 18, - ns_t_x25 = 19, - ns_t_isdn = 20, - ns_t_rt = 21, - ns_t_nsap = 22, - ns_t_nsap_ptr = 23, - ns_t_sig = 24, - ns_t_key = 25, - ns_t_px = 26, - ns_t_gpos = 27, - ns_t_aaaa = 28, - ns_t_loc = 29, - ns_t_nxt = 30, - ns_t_eid = 31, - ns_t_nimloc = 32, - ns_t_srv = 33, - ns_t_atma = 34, - ns_t_naptr = 35, - ns_t_kx = 36, - ns_t_cert = 37, - ns_t_a6 = 38, - ns_t_dname = 39, - ns_t_sink = 40, - ns_t_opt = 41, - ns_t_apl = 42, - ns_t_tkey = 249, - ns_t_tsig = 250, - ns_t_ixfr = 251, - ns_t_axfr = 252, - ns_t_mailb = 253, - ns_t_maila = 254, - ns_t_any = 255, - ns_t_zxfr = 256, - ns_t_max = 65536 -} ns_type; - -#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ - (t) == ns_t_mailb || (t) == ns_t_maila) -#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) -#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) -#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) -#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ - (t) == ns_t_zxfr) - -typedef enum __ns_class { - ns_c_invalid = 0, - ns_c_in = 1, - ns_c_2 = 2, - ns_c_chaos = 3, - ns_c_hs = 4, - ns_c_none = 254, - ns_c_any = 255, - ns_c_max = 65536 -} ns_class; - -typedef enum __ns_key_types { - ns_kt_rsa = 1, - ns_kt_dh = 2, - ns_kt_dsa = 3, - ns_kt_private = 254 -} ns_key_types; - -typedef enum __ns_cert_types { - cert_t_pkix = 1, - cert_t_spki = 2, - cert_t_pgp = 3, - cert_t_url = 253, - cert_t_oid = 254 -} ns_cert_types; - -#define NS_KEY_TYPEMASK 0xC000 -#define NS_KEY_TYPE_AUTH_CONF 0x0000 -#define NS_KEY_TYPE_CONF_ONLY 0x8000 -#define NS_KEY_TYPE_AUTH_ONLY 0x4000 -#define NS_KEY_TYPE_NO_KEY 0xC000 -#define NS_KEY_NO_AUTH 0x8000 -#define NS_KEY_NO_CONF 0x4000 -#define NS_KEY_RESERVED2 0x2000 -#define NS_KEY_EXTENDED_FLAGS 0x1000 -#define NS_KEY_RESERVED4 0x0800 -#define NS_KEY_RESERVED5 0x0400 -#define NS_KEY_NAME_TYPE 0x0300 -#define NS_KEY_NAME_USER 0x0000 -#define NS_KEY_NAME_ENTITY 0x0200 -#define NS_KEY_NAME_ZONE 0x0100 -#define NS_KEY_NAME_RESERVED 0x0300 -#define NS_KEY_RESERVED8 0x0080 -#define NS_KEY_RESERVED9 0x0040 -#define NS_KEY_RESERVED10 0x0020 -#define NS_KEY_RESERVED11 0x0010 -#define NS_KEY_SIGNATORYMASK 0x000F -#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ - NS_KEY_RESERVED4 | \ - NS_KEY_RESERVED5 | \ - NS_KEY_RESERVED8 | \ - NS_KEY_RESERVED9 | \ - NS_KEY_RESERVED10 | \ - NS_KEY_RESERVED11 ) -#define NS_KEY_RESERVED_BITMASK2 0xFFFF -#define NS_ALG_MD5RSA 1 -#define NS_ALG_DH 2 -#define NS_ALG_DSA 3 -#define NS_ALG_DSS NS_ALG_DSA -#define NS_ALG_EXPIRE_ONLY 253 -#define NS_ALG_PRIVATE_OID 254 - -#define NS_KEY_PROT_TLS 1 -#define NS_KEY_PROT_EMAIL 2 -#define NS_KEY_PROT_DNSSEC 3 -#define NS_KEY_PROT_IPSEC 4 -#define NS_KEY_PROT_ANY 255 - -#define NS_MD5RSA_MIN_BITS 512 -#define NS_MD5RSA_MAX_BITS 4096 -#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) -#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) -#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) -#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) - -#define NS_DSA_SIG_SIZE 41 -#define NS_DSA_MIN_SIZE 213 -#define NS_DSA_MAX_BYTES 405 - -#define NS_SIG_TYPE 0 -#define NS_SIG_ALG 2 -#define NS_SIG_LABELS 3 -#define NS_SIG_OTTL 4 -#define NS_SIG_EXPIR 8 -#define NS_SIG_SIGNED 12 -#define NS_SIG_FOOT 16 -#define NS_SIG_SIGNER 18 -#define NS_NXT_BITS 8 -#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_MAX 127 - -#define NS_OPT_DNSSEC_OK 0x8000U -#define NS_OPT_NSID 3 - -#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2)) -#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4)) -#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2) -#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4) - -unsigned ns_get16(const unsigned char *); -unsigned long ns_get32(const unsigned char *); -void ns_put16(unsigned, unsigned char *); -void ns_put32(unsigned long, unsigned char *); - -int ns_initparse(const unsigned char *, int, ns_msg *); -int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); -int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int); -int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t); - - -#define __BIND 19950621 - -typedef struct { - unsigned id :16; -#if __BYTE_ORDER == __BIG_ENDIAN - unsigned qr: 1; - unsigned opcode: 4; - unsigned aa: 1; - unsigned tc: 1; - unsigned rd: 1; - unsigned ra: 1; - unsigned unused :1; - unsigned ad: 1; - unsigned cd: 1; - unsigned rcode :4; -#else - unsigned rd :1; - unsigned tc :1; - unsigned aa :1; - unsigned opcode :4; - unsigned qr :1; - unsigned rcode :4; - unsigned cd: 1; - unsigned ad: 1; - unsigned unused :1; - unsigned ra :1; -#endif - unsigned qdcount :16; - unsigned ancount :16; - unsigned nscount :16; - unsigned arcount :16; -} HEADER; - -#define PACKETSZ NS_PACKETSZ -#define MAXDNAME NS_MAXDNAME -#define MAXCDNAME NS_MAXCDNAME -#define MAXLABEL NS_MAXLABEL -#define HFIXEDSZ NS_HFIXEDSZ -#define QFIXEDSZ NS_QFIXEDSZ -#define RRFIXEDSZ NS_RRFIXEDSZ -#define INT32SZ NS_INT32SZ -#define INT16SZ NS_INT16SZ -#define INT8SZ NS_INT8SZ -#define INADDRSZ NS_INADDRSZ -#define IN6ADDRSZ NS_IN6ADDRSZ -#define INDIR_MASK NS_CMPRSFLGS -#define NAMESERVER_PORT NS_DEFAULTPORT - -#define S_ZONE ns_s_zn -#define S_PREREQ ns_s_pr -#define S_UPDATE ns_s_ud -#define S_ADDT ns_s_ar - -#define QUERY ns_o_query -#define IQUERY ns_o_iquery -#define STATUS ns_o_status -#define NS_NOTIFY_OP ns_o_notify -#define NS_UPDATE_OP ns_o_update - -#define NOERROR ns_r_noerror -#define FORMERR ns_r_formerr -#define SERVFAIL ns_r_servfail -#define NXDOMAIN ns_r_nxdomain -#define NOTIMP ns_r_notimpl -#define REFUSED ns_r_refused -#define YXDOMAIN ns_r_yxdomain -#define YXRRSET ns_r_yxrrset -#define NXRRSET ns_r_nxrrset -#define NOTAUTH ns_r_notauth -#define NOTZONE ns_r_notzone - -#define DELETE ns_uop_delete -#define ADD ns_uop_add - -#define T_A ns_t_a -#define T_NS ns_t_ns -#define T_MD ns_t_md -#define T_MF ns_t_mf -#define T_CNAME ns_t_cname -#define T_SOA ns_t_soa -#define T_MB ns_t_mb -#define T_MG ns_t_mg -#define T_MR ns_t_mr -#define T_NULL ns_t_null -#define T_WKS ns_t_wks -#define T_PTR ns_t_ptr -#define T_HINFO ns_t_hinfo -#define T_MINFO ns_t_minfo -#define T_MX ns_t_mx -#define T_TXT ns_t_txt -#define T_RP ns_t_rp -#define T_AFSDB ns_t_afsdb -#define T_X25 ns_t_x25 -#define T_ISDN ns_t_isdn -#define T_RT ns_t_rt -#define T_NSAP ns_t_nsap -#define T_NSAP_PTR ns_t_nsap_ptr -#define T_SIG ns_t_sig -#define T_KEY ns_t_key -#define T_PX ns_t_px -#define T_GPOS ns_t_gpos -#define T_AAAA ns_t_aaaa -#define T_LOC ns_t_loc -#define T_NXT ns_t_nxt -#define T_EID ns_t_eid -#define T_NIMLOC ns_t_nimloc -#define T_SRV ns_t_srv -#define T_ATMA ns_t_atma -#define T_NAPTR ns_t_naptr -#define T_A6 ns_t_a6 -#define T_DNAME ns_t_dname -#define T_TSIG ns_t_tsig -#define T_IXFR ns_t_ixfr -#define T_AXFR ns_t_axfr -#define T_MAILB ns_t_mailb -#define T_MAILA ns_t_maila -#define T_ANY ns_t_any - -#define C_IN ns_c_in -#define C_CHAOS ns_c_chaos -#define C_HS ns_c_hs -#define C_NONE ns_c_none -#define C_ANY ns_c_any - -#define GETSHORT NS_GET16 -#define GETLONG NS_GET32 -#define PUTSHORT NS_PUT16 -#define PUTLONG NS_PUT32 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/arpa/nameser_compat.h b/usr/lib/libc/include/arpa/nameser_compat.h deleted file mode 100644 index 3aac25c98..000000000 --- a/usr/lib/libc/include/arpa/nameser_compat.h +++ /dev/null @@ -1,2 +0,0 @@ -#include - diff --git a/usr/lib/libc/include/arpa/telnet.h b/usr/lib/libc/include/arpa/telnet.h deleted file mode 100644 index e2ad97429..000000000 --- a/usr/lib/libc/include/arpa/telnet.h +++ /dev/null @@ -1,251 +0,0 @@ -#ifndef _ARPA_TELNET_H -#define _ARPA_TELNET_H - -#define IAC 255 -#define DONT 254 -#define DO 253 -#define WONT 252 -#define WILL 251 -#define SB 250 -#define GA 249 -#define EL 248 -#define EC 247 -#define AYT 246 -#define AO 245 -#define IP 244 -#define BREAK 243 -#define DM 242 -#define NOP 241 -#define SE 240 -#define EOR 239 -#define ABORT 238 -#define SUSP 237 -#define xEOF 236 - -#define SYNCH 242 - -#define telcmds ((char [][6]){ "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0 }) - -#define TELCMD_FIRST xEOF -#define TELCMD_LAST IAC -#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ - (unsigned int)(x) >= TELCMD_FIRST) -#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] - -#define TELOPT_BINARY 0 -#define TELOPT_ECHO 1 -#define TELOPT_RCP 2 -#define TELOPT_SGA 3 -#define TELOPT_NAMS 4 -#define TELOPT_STATUS 5 -#define TELOPT_TM 6 -#define TELOPT_RCTE 7 -#define TELOPT_NAOL 8 -#define TELOPT_NAOP 9 -#define TELOPT_NAOCRD 10 -#define TELOPT_NAOHTS 11 -#define TELOPT_NAOHTD 12 -#define TELOPT_NAOFFD 13 -#define TELOPT_NAOVTS 14 -#define TELOPT_NAOVTD 15 -#define TELOPT_NAOLFD 16 -#define TELOPT_XASCII 17 -#define TELOPT_LOGOUT 18 -#define TELOPT_BM 19 -#define TELOPT_DET 20 -#define TELOPT_SUPDUP 21 -#define TELOPT_SUPDUPOUTPUT 22 -#define TELOPT_SNDLOC 23 -#define TELOPT_TTYPE 24 -#define TELOPT_EOR 25 -#define TELOPT_TUID 26 -#define TELOPT_OUTMRK 27 -#define TELOPT_TTYLOC 28 -#define TELOPT_3270REGIME 29 -#define TELOPT_X3PAD 30 -#define TELOPT_NAWS 31 -#define TELOPT_TSPEED 32 -#define TELOPT_LFLOW 33 -#define TELOPT_LINEMODE 34 -#define TELOPT_XDISPLOC 35 -#define TELOPT_OLD_ENVIRON 36 -#define TELOPT_AUTHENTICATION 37/* Authenticate */ -#define TELOPT_ENCRYPT 38 -#define TELOPT_NEW_ENVIRON 39 -#define TELOPT_EXOPL 255 - - -#define NTELOPTS (1+TELOPT_NEW_ENVIRON) -#ifdef TELOPTS -char *telopts[NTELOPTS+1] = { - "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", - "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", - "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", - "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", - "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", - "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", - "TACACS UID", "OUTPUT MARKING", "TTYLOC", - "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", - "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", - "ENCRYPT", "NEW-ENVIRON", - 0, -}; -#define TELOPT_FIRST TELOPT_BINARY -#define TELOPT_LAST TELOPT_NEW_ENVIRON -#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) -#define TELOPT(x) telopts[(x)-TELOPT_FIRST] -#endif - -#define TELQUAL_IS 0 -#define TELQUAL_SEND 1 -#define TELQUAL_INFO 2 -#define TELQUAL_REPLY 2 -#define TELQUAL_NAME 3 - -#define LFLOW_OFF 0 -#define LFLOW_ON 1 -#define LFLOW_RESTART_ANY 2 -#define LFLOW_RESTART_XON 3 - - -#define LM_MODE 1 -#define LM_FORWARDMASK 2 -#define LM_SLC 3 - -#define MODE_EDIT 0x01 -#define MODE_TRAPSIG 0x02 -#define MODE_ACK 0x04 -#define MODE_SOFT_TAB 0x08 -#define MODE_LIT_ECHO 0x10 - -#define MODE_MASK 0x1f - -#define MODE_FLOW 0x0100 -#define MODE_ECHO 0x0200 -#define MODE_INBIN 0x0400 -#define MODE_OUTBIN 0x0800 -#define MODE_FORCE 0x1000 - -#define SLC_SYNCH 1 -#define SLC_BRK 2 -#define SLC_IP 3 -#define SLC_AO 4 -#define SLC_AYT 5 -#define SLC_EOR 6 -#define SLC_ABORT 7 -#define SLC_EOF 8 -#define SLC_SUSP 9 -#define SLC_EC 10 -#define SLC_EL 11 -#define SLC_EW 12 -#define SLC_RP 13 -#define SLC_LNEXT 14 -#define SLC_XON 15 -#define SLC_XOFF 16 -#define SLC_FORW1 17 -#define SLC_FORW2 18 - -#define NSLC 18 - -#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ - "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ - "LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0, -#ifdef SLC_NAMES -char *slc_names[] = { - SLC_NAMELIST -}; -#else -extern char *slc_names[]; -#define SLC_NAMES SLC_NAMELIST -#endif - -#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) -#define SLC_NAME(x) slc_names[x] - -#define SLC_NOSUPPORT 0 -#define SLC_CANTCHANGE 1 -#define SLC_VARIABLE 2 -#define SLC_DEFAULT 3 -#define SLC_LEVELBITS 0x03 - -#define SLC_FUNC 0 -#define SLC_FLAGS 1 -#define SLC_VALUE 2 - -#define SLC_ACK 0x80 -#define SLC_FLUSHIN 0x40 -#define SLC_FLUSHOUT 0x20 - -#define OLD_ENV_VAR 1 -#define OLD_ENV_VALUE 0 -#define NEW_ENV_VAR 0 -#define NEW_ENV_VALUE 1 -#define ENV_ESC 2 -#define ENV_USERVAR 3 - -#define AUTH_WHO_CLIENT 0 -#define AUTH_WHO_SERVER 1 -#define AUTH_WHO_MASK 1 - -#define AUTH_HOW_ONE_WAY 0 -#define AUTH_HOW_MUTUAL 2 -#define AUTH_HOW_MASK 2 - -#define AUTHTYPE_NULL 0 -#define AUTHTYPE_KERBEROS_V4 1 -#define AUTHTYPE_KERBEROS_V5 2 -#define AUTHTYPE_SPX 3 -#define AUTHTYPE_MINK 4 -#define AUTHTYPE_CNT 5 - -#define AUTHTYPE_TEST 99 - -#ifdef AUTH_NAMES -char *authtype_names[] = { - "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0, -}; -#else -extern char *authtype_names[]; -#endif - -#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) -#define AUTHTYPE_NAME(x) authtype_names[x] - -#define ENCRYPT_IS 0 -#define ENCRYPT_SUPPORT 1 -#define ENCRYPT_REPLY 2 -#define ENCRYPT_START 3 -#define ENCRYPT_END 4 -#define ENCRYPT_REQSTART 5 -#define ENCRYPT_REQEND 6 -#define ENCRYPT_ENC_KEYID 7 -#define ENCRYPT_DEC_KEYID 8 -#define ENCRYPT_CNT 9 - -#define ENCTYPE_ANY 0 -#define ENCTYPE_DES_CFB64 1 -#define ENCTYPE_DES_OFB64 2 -#define ENCTYPE_CNT 3 - -#ifdef ENCRYPT_NAMES -char *encrypt_names[] = { - "IS", "SUPPORT", "REPLY", "START", "END", - "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", - 0, -}; -char *enctype_names[] = { - "ANY", "DES_CFB64", "DES_OFB64", 0, -}; -#else -extern char *encrypt_names[]; -extern char *enctype_names[]; -#endif - - -#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) -#define ENCRYPT_NAME(x) encrypt_names[x] - -#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) -#define ENCTYPE_NAME(x) enctype_names[x] - -#endif diff --git a/usr/lib/libc/include/arpa/tftp.h b/usr/lib/libc/include/arpa/tftp.h deleted file mode 100644 index 799c54f22..000000000 --- a/usr/lib/libc/include/arpa/tftp.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _ARPA_TFTP_H -#define _ARPA_TFTP_H -#define SEGSIZE 512 -#define RRQ 01 -#define WRQ 02 -#define DATA 03 -#define ACK 04 -#define ERROR 05 -struct tftphdr { - short th_opcode; - union { - unsigned short tu_block; - short tu_code; - char tu_stuff[1]; - } th_u; - char th_data[1]; -}; -#define th_block th_u.tu_block -#define th_code th_u.tu_code -#define th_stuff th_u.tu_stuff -#define th_msg th_data -#define EUNDEF 0 -#define ENOTFOUND 1 -#define EACCESS 2 -#define ENOSPACE 3 -#define EBADOP 4 -#define EBADID 5 -#define EEXISTS 6 -#define ENOUSER 7 -#endif - diff --git a/usr/lib/libc/include/asm-aarch32/atomic_arch.h b/usr/lib/libc/include/asm-aarch32/atomic_arch.h deleted file mode 100644 index bb9e473cb..000000000 --- a/usr/lib/libc/include/asm-aarch32/atomic_arch.h +++ /dev/null @@ -1,107 +0,0 @@ -#include "libc.h" - -#if __ARM_ARCH_4__ || __ARM_ARCH_4T__ || __ARM_ARCH == 4 -#define BLX "mov lr,pc\n\tbx" -#else -#define BLX "blx" -#endif - -extern /*hidden*/ uintptr_t __a_cas_ptr, __a_barrier_ptr; - -#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ - || __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 - -#define a_ll a_ll -static inline int a_ll(volatile int *p) -{ - int v; - __asm__ __volatile__ ("ldrex %0, %1" : "=r"(v) : "Q"(*p)); - return v; -} - -#define a_sc a_sc -static inline int a_sc(volatile int *p, int v) -{ - int r; - __asm__ __volatile__ ("strex %0,%2,%1" : "=&r"(r), "=Q"(*p) : "r"(v) : "memory"); - return !r; -} - -#if __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 - -#define a_barrier a_barrier -static inline void a_barrier() -{ - __asm__ __volatile__ ("dmb ish" : : : "memory"); -} - -#endif - -#define a_pre_llsc a_barrier -#define a_post_llsc a_barrier - -#else - -#define a_cas a_cas -static inline int a_cas(volatile int *p, int t, int s) -{ - for (;;) { - register int r0 __asm__("r0") = t; - register int r1 __asm__("r1") = s; - register volatile int *r2 __asm__("r2") = p; - register uintptr_t r3 __asm__("r3") = __a_cas_ptr; - int old; - __asm__ __volatile__ ( - BLX " r3" - : "+r"(r0), "+r"(r3) : "r"(r1), "r"(r2) - : "memory", "lr", "ip", "cc" ); - if (!r0) return t; - if ((old=*p)!=t) return old; - } -} - -#endif - -#ifndef a_barrier -#define a_barrier a_barrier -static inline void a_barrier() -{ - register uintptr_t ip __asm__("ip") = __a_barrier_ptr; - __asm__ __volatile__( BLX " ip" : "+r"(ip) : : "memory", "cc", "lr" ); -} -#endif - -#define a_crash a_crash -static inline void a_crash() -{ - __asm__ __volatile__( -#ifndef __thumb__ - ".word 0xe7f000f0" -#else - ".short 0xdeff" -#endif - : : : "memory"); -} - -#if __ARM_ARCH >= 5 && (!__thumb__ || __thumb2__) - -#define a_clz_32 a_clz_32 -static inline int a_clz_32(uint32_t x) -{ - __asm__ ("clz %0, %1" : "=r"(x) : "r"(x)); - return x; -} - -#if __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 - -#define a_ctz_32 a_ctz_32 -static inline int a_ctz_32(uint32_t x) -{ - uint32_t xr; - __asm__ ("rbit %0, %1" : "=r"(xr) : "r"(x)); - return a_clz_32(xr); -} - -#endif - -#endif diff --git a/usr/lib/libc/include/asm-aarch32/bits/alltypes.h.in b/usr/lib/libc/include/asm-aarch32/bits/alltypes.h.in deleted file mode 100644 index d62bd7bde..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/alltypes.h.in +++ /dev/null @@ -1,21 +0,0 @@ -#define _REDIR_TIME64 1 -#define _Addr int -#define _Int64 long long -#define _Reg int - -#if __ARMEB__ -#define __BYTE_ORDER 4321 -#else -#define __BYTE_ORDER 1234 -#endif - -#define __LONG_MAX 0x7fffffffL - -#ifndef __cplusplus -TYPEDEF unsigned wchar_t; -#endif - -TYPEDEF float float_t; -TYPEDEF double double_t; - -TYPEDEF struct { long long __ll; long double __ld; } max_align_t; diff --git a/usr/lib/libc/include/asm-aarch32/bits/fcntl.h b/usr/lib/libc/include/asm-aarch32/bits/fcntl.h deleted file mode 100644 index 4cb1753b7..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/fcntl.h +++ /dev/null @@ -1,40 +0,0 @@ -#define O_CREAT 0100 -#define O_EXCL 0200 -#define O_NOCTTY 0400 -#define O_TRUNC 01000 -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_DSYNC 010000 -#define O_SYNC 04010000 -#define O_RSYNC 04010000 -#define O_DIRECTORY 040000 -#define O_NOFOLLOW 0100000 -#define O_CLOEXEC 02000000 - -#define O_ASYNC 020000 -#define O_DIRECT 0200000 -#define O_LARGEFILE 0400000 -#define O_NOATIME 01000000 -#define O_PATH 010000000 -#define O_TMPFILE 020040000 -#define O_NDELAY O_NONBLOCK - -#define F_DUPFD 0 -#define F_GETFD 1 -#define F_SETFD 2 -#define F_GETFL 3 -#define F_SETFL 4 - -#define F_SETOWN 8 -#define F_GETOWN 9 -#define F_SETSIG 10 -#define F_GETSIG 11 - -#define F_GETLK 12 -#define F_SETLK 13 -#define F_SETLKW 14 - -#define F_SETOWN_EX 15 -#define F_GETOWN_EX 16 - -#define F_GETOWNER_UIDS 17 diff --git a/usr/lib/libc/include/asm-aarch32/bits/fenv.h b/usr/lib/libc/include/asm-aarch32/bits/fenv.h deleted file mode 100644 index d85fc86d7..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/fenv.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __ARM_PCS_VFP -#define FE_ALL_EXCEPT 0 -#define FE_TONEAREST 0 -#else -#define FE_INVALID 1 -#define FE_DIVBYZERO 2 -#define FE_OVERFLOW 4 -#define FE_UNDERFLOW 8 -#define FE_INEXACT 16 -#define FE_ALL_EXCEPT 31 -#define FE_TONEAREST 0 -#define FE_DOWNWARD 0x800000 -#define FE_UPWARD 0x400000 -#define FE_TOWARDZERO 0xc00000 -#endif - -typedef unsigned long fexcept_t; - -typedef struct { - unsigned long __cw; -} fenv_t; - -#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/usr/lib/libc/include/asm-aarch32/bits/float.h b/usr/lib/libc/include/asm-aarch32/bits/float.h deleted file mode 100644 index c4a655e7b..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/float.h +++ /dev/null @@ -1,16 +0,0 @@ -#define FLT_EVAL_METHOD 0 - -#define LDBL_TRUE_MIN 4.94065645841246544177e-324L -#define LDBL_MIN 2.22507385850720138309e-308L -#define LDBL_MAX 1.79769313486231570815e+308L -#define LDBL_EPSILON 2.22044604925031308085e-16L - -#define LDBL_MANT_DIG 53 -#define LDBL_MIN_EXP (-1021) -#define LDBL_MAX_EXP 1024 - -#define LDBL_DIG 15 -#define LDBL_MIN_10_EXP (-307) -#define LDBL_MAX_10_EXP 308 - -#define DECIMAL_DIG 17 diff --git a/usr/lib/libc/include/asm-aarch32/bits/hwcap.h b/usr/lib/libc/include/asm-aarch32/bits/hwcap.h deleted file mode 100644 index a3d87312d..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/hwcap.h +++ /dev/null @@ -1,53 +0,0 @@ -#define HWCAP_SWP (1 << 0) -#define HWCAP_HALF (1 << 1) -#define HWCAP_THUMB (1 << 2) -#define HWCAP_26BIT (1 << 3) -#define HWCAP_FAST_MULT (1 << 4) -#define HWCAP_FPA (1 << 5) -#define HWCAP_VFP (1 << 6) -#define HWCAP_EDSP (1 << 7) -#define HWCAP_JAVA (1 << 8) -#define HWCAP_IWMMXT (1 << 9) -#define HWCAP_CRUNCH (1 << 10) -#define HWCAP_THUMBEE (1 << 11) -#define HWCAP_NEON (1 << 12) -#define HWCAP_VFPv3 (1 << 13) -#define HWCAP_VFPv3D16 (1 << 14) -#define HWCAP_TLS (1 << 15) -#define HWCAP_VFPv4 (1 << 16) -#define HWCAP_IDIVA (1 << 17) -#define HWCAP_IDIVT (1 << 18) -#define HWCAP_VFPD32 (1 << 19) -#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT) -#define HWCAP_LPAE (1 << 20) -#define HWCAP_EVTSTRM (1 << 21) - -#define HWCAP2_AES (1 << 0) -#define HWCAP2_PMULL (1 << 1) -#define HWCAP2_SHA1 (1 << 2) -#define HWCAP2_SHA2 (1 << 3) -#define HWCAP2_CRC32 (1 << 4) - -#define HWCAP_ARM_SWP (1 << 0) -#define HWCAP_ARM_HALF (1 << 1) -#define HWCAP_ARM_THUMB (1 << 2) -#define HWCAP_ARM_26BIT (1 << 3) -#define HWCAP_ARM_FAST_MULT (1 << 4) -#define HWCAP_ARM_FPA (1 << 5) -#define HWCAP_ARM_VFP (1 << 6) -#define HWCAP_ARM_EDSP (1 << 7) -#define HWCAP_ARM_JAVA (1 << 8) -#define HWCAP_ARM_IWMMXT (1 << 9) -#define HWCAP_ARM_CRUNCH (1 << 10) -#define HWCAP_ARM_THUMBEE (1 << 11) -#define HWCAP_ARM_NEON (1 << 12) -#define HWCAP_ARM_VFPv3 (1 << 13) -#define HWCAP_ARM_VFPv3D16 (1 << 14) -#define HWCAP_ARM_TLS (1 << 15) -#define HWCAP_ARM_VFPv4 (1 << 16) -#define HWCAP_ARM_IDIVA (1 << 17) -#define HWCAP_ARM_IDIVT (1 << 18) -#define HWCAP_ARM_VFPD32 (1 << 19) -#define HWCAP_ARM_IDIV (HWCAP_ARM_IDIVA | HWCAP_ARM_IDIVT) -#define HWCAP_ARM_LPAE (1 << 20) -#define HWCAP_ARM_EVTSTRM (1 << 21) diff --git a/usr/lib/libc/include/asm-aarch32/bits/ioctl_fix.h b/usr/lib/libc/include/asm-aarch32/bits/ioctl_fix.h deleted file mode 100644 index ebb383daf..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/ioctl_fix.h +++ /dev/null @@ -1,2 +0,0 @@ -#undef FIOQSIZE -#define FIOQSIZE 0x545e diff --git a/usr/lib/libc/include/asm-aarch32/bits/ipcstat.h b/usr/lib/libc/include/asm-aarch32/bits/ipcstat.h deleted file mode 100644 index 4f4fcb0c5..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/ipcstat.h +++ /dev/null @@ -1 +0,0 @@ -#define IPC_STAT 0x102 diff --git a/usr/lib/libc/include/asm-aarch32/bits/msg.h b/usr/lib/libc/include/asm-aarch32/bits/msg.h deleted file mode 100644 index 7bbbb2bf4..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/msg.h +++ /dev/null @@ -1,18 +0,0 @@ -struct msqid_ds { - struct ipc_perm msg_perm; - unsigned long __msg_stime_lo; - unsigned long __msg_stime_hi; - unsigned long __msg_rtime_lo; - unsigned long __msg_rtime_hi; - unsigned long __msg_ctime_lo; - unsigned long __msg_ctime_hi; - unsigned long msg_cbytes; - msgqnum_t msg_qnum; - msglen_t msg_qbytes; - pid_t msg_lspid; - pid_t msg_lrpid; - unsigned long __unused[2]; - time_t msg_stime; - time_t msg_rtime; - time_t msg_ctime; -}; diff --git a/usr/lib/libc/include/asm-aarch32/bits/posix.h b/usr/lib/libc/include/asm-aarch32/bits/posix.h deleted file mode 100644 index 30a38714f..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_ILP32_OFFBIG 1 -#define _POSIX_V7_ILP32_OFFBIG 1 diff --git a/usr/lib/libc/include/asm-aarch32/bits/ptrace.h b/usr/lib/libc/include/asm-aarch32/bits/ptrace.h deleted file mode 100644 index 9556ef4b7..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/ptrace.h +++ /dev/null @@ -1,25 +0,0 @@ -#define PTRACE_GETWMMXREGS 18 -#define PTRACE_SETWMMXREGS 19 -#define PTRACE_GET_THREAD_AREA 22 -#define PTRACE_SET_SYSCALL 23 -#define PTRACE_GETCRUNCHREGS 25 -#define PTRACE_SETCRUNCHREGS 26 -#define PTRACE_GETVFPREGS 27 -#define PTRACE_SETVFPREGS 28 -#define PTRACE_GETHBPREGS 29 -#define PTRACE_SETHBPREGS 30 -#define PTRACE_GETFDPIC 31 -#define PTRACE_GETFDPIC_EXEC 0 -#define PTRACE_GETFDPIC_INTERP 1 - -#define PT_GETWMMXREGS PTRACE_GETWMMXREGS -#define PT_SETWMMXREGS PTRACE_SETWMMXREGS -#define PT_GET_THREAD_AREA PTRACE_GET_THREAD_AREA -#define PT_SET_SYSCALL PTRACE_SET_SYSCALL -#define PT_GETCRUNCHREGS PTRACE_GETCRUNCHREGS -#define PT_SETCRUNCHREGS PTRACE_SETCRUNCHREGS -#define PT_GETVFPREGS PTRACE_GETVFPREGS -#define PT_SETVFPREGS PTRACE_SETVFPREGS -#define PT_GETHBPREGS PTRACE_GETHBPREGS -#define PT_SETHBPREGS PTRACE_SETHBPREGS -#define PT_GETFDPIC PTRACE_GETFDPIC diff --git a/usr/lib/libc/include/asm-aarch32/bits/reg.h b/usr/lib/libc/include/asm-aarch32/bits/reg.h deleted file mode 100644 index 0c7bffca0..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/reg.h +++ /dev/null @@ -1,3 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 32 -/* FIXME */ diff --git a/usr/lib/libc/include/asm-aarch32/bits/sem.h b/usr/lib/libc/include/asm-aarch32/bits/sem.h deleted file mode 100644 index 544e3d2a5..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/sem.h +++ /dev/null @@ -1,18 +0,0 @@ -struct semid_ds { - struct ipc_perm sem_perm; - unsigned long __sem_otime_lo; - unsigned long __sem_otime_hi; - unsigned long __sem_ctime_lo; - unsigned long __sem_ctime_hi; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned short sem_nsems; - char __sem_nsems_pad[sizeof(long)-sizeof(short)]; -#else - char __sem_nsems_pad[sizeof(long)-sizeof(short)]; - unsigned short sem_nsems; -#endif - long __unused3; - long __unused4; - time_t sem_otime; - time_t sem_ctime; -}; diff --git a/usr/lib/libc/include/asm-aarch32/bits/setjmp.h b/usr/lib/libc/include/asm-aarch32/bits/setjmp.h deleted file mode 100644 index 55e3a95bb..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/setjmp.h +++ /dev/null @@ -1 +0,0 @@ -typedef unsigned long long __jmp_buf[32]; diff --git a/usr/lib/libc/include/asm-aarch32/bits/shm.h b/usr/lib/libc/include/asm-aarch32/bits/shm.h deleted file mode 100644 index 725fb4696..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/shm.h +++ /dev/null @@ -1,31 +0,0 @@ -#define SHMLBA 4096 - -struct shmid_ds { - struct ipc_perm shm_perm; - size_t shm_segsz; - unsigned long __shm_atime_lo; - unsigned long __shm_atime_hi; - unsigned long __shm_dtime_lo; - unsigned long __shm_dtime_hi; - unsigned long __shm_ctime_lo; - unsigned long __shm_ctime_hi; - pid_t shm_cpid; - pid_t shm_lpid; - unsigned long shm_nattch; - unsigned long __pad1; - unsigned long __pad2; - unsigned long __pad3; - time_t shm_atime; - time_t shm_dtime; - time_t shm_ctime; -}; - -struct shminfo { - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4]; -}; - -struct shm_info { - int __used_ids; - unsigned long shm_tot, shm_rss, shm_swp; - unsigned long __swap_attempts, __swap_successes; -}; diff --git a/usr/lib/libc/include/asm-aarch32/bits/signal.h b/usr/lib/libc/include/asm-aarch32/bits/signal.h deleted file mode 100644 index 3c7898567..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/signal.h +++ /dev/null @@ -1,86 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define MINSIGSTKSZ 2048 -#define SIGSTKSZ 8192 -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -typedef int greg_t, gregset_t[18]; -typedef struct sigcontext { - unsigned long trap_no, error_code, oldmask; - unsigned long arm_r0, arm_r1, arm_r2, arm_r3; - unsigned long arm_r4, arm_r5, arm_r6, arm_r7; - unsigned long arm_r8, arm_r9, arm_r10, arm_fp; - unsigned long arm_ip, arm_sp, arm_lr, arm_pc; - unsigned long arm_cpsr, fault_address; -} mcontext_t; -#else -typedef struct { - unsigned long __regs[21]; -} mcontext_t; -#endif - -struct sigaltstack { - void *ss_sp; - int ss_flags; - size_t ss_size; -}; - -typedef struct __ucontext { - unsigned long uc_flags; - struct __ucontext *uc_link; - stack_t uc_stack; - mcontext_t uc_mcontext; - sigset_t uc_sigmask; - unsigned long long uc_regspace[64]; -} ucontext_t; - -#define SA_NOCLDSTOP 1 -#define SA_NOCLDWAIT 2 -#define SA_SIGINFO 4 -#define SA_ONSTACK 0x08000000 -#define SA_RESTART 0x10000000 -#define SA_NODEFER 0x40000000 -#define SA_RESETHAND 0x80000000 -#define SA_RESTORER 0x04000000 - -#endif - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT SIGABRT -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL 29 -#define SIGPWR 30 -#define SIGSYS 31 -#define SIGUNUSED SIGSYS - -#define _NSIG 65 diff --git a/usr/lib/libc/include/asm-aarch32/bits/stat.h b/usr/lib/libc/include/asm-aarch32/bits/stat.h deleted file mode 100644 index 5d7828cf7..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/stat.h +++ /dev/null @@ -1,25 +0,0 @@ -/* copied from kernel definition, but with padding replaced - * by the corresponding correctly-sized userspace types. */ - -struct stat { - dev_t st_dev; - int __st_dev_padding; - long __st_ino_truncated; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - int __st_rdev_padding; - off_t st_size; - blksize_t st_blksize; - blkcnt_t st_blocks; - struct { - long tv_sec; - long tv_nsec; - } __st_atim32, __st_mtim32, __st_ctim32; - ino_t st_ino; - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; -}; diff --git a/usr/lib/libc/include/asm-aarch32/bits/stdint.h b/usr/lib/libc/include/asm-aarch32/bits/stdint.h deleted file mode 100644 index d1b271219..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/stdint.h +++ /dev/null @@ -1,20 +0,0 @@ -typedef int32_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef uint32_t uint_fast16_t; -typedef uint32_t uint_fast32_t; - -#define INT_FAST16_MIN INT32_MIN -#define INT_FAST32_MIN INT32_MIN - -#define INT_FAST16_MAX INT32_MAX -#define INT_FAST32_MAX INT32_MAX - -#define UINT_FAST16_MAX UINT32_MAX -#define UINT_FAST32_MAX UINT32_MAX - -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX -#define SIZE_MAX UINT32_MAX diff --git a/usr/lib/libc/include/asm-aarch32/bits/syscall.h.in b/usr/lib/libc/include/asm-aarch32/bits/syscall.h.in deleted file mode 100644 index 048fdea79..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/syscall.h.in +++ /dev/null @@ -1,409 +0,0 @@ -#define __NR_restart_syscall 0 -#define __NR_exit 1 -#define __NR_fork 2 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_creat 8 -#define __NR_link 9 -#define __NR_unlink 10 -#define __NR_execve 11 -#define __NR_chdir 12 -#define __NR_mknod 14 -#define __NR_chmod 15 -#define __NR_lchown 16 -#define __NR_lseek 19 -#define __NR_getpid 20 -#define __NR_mount 21 -#define __NR_setuid 23 -#define __NR_getuid 24 -#define __NR_ptrace 26 -#define __NR_pause 29 -#define __NR_access 33 -#define __NR_nice 34 -#define __NR_sync 36 -#define __NR_kill 37 -#define __NR_rename 38 -#define __NR_mkdir 39 -#define __NR_rmdir 40 -#define __NR_dup 41 -#define __NR_pipe 42 -#define __NR_times 43 -#define __NR_brk 45 -#define __NR_setgid 46 -#define __NR_getgid 47 -#define __NR_geteuid 49 -#define __NR_getegid 50 -#define __NR_acct 51 -#define __NR_umount2 52 -#define __NR_ioctl 54 -#define __NR_fcntl 55 -#define __NR_setpgid 57 -#define __NR_umask 60 -#define __NR_chroot 61 -#define __NR_ustat 62 -#define __NR_dup2 63 -#define __NR_getppid 64 -#define __NR_getpgrp 65 -#define __NR_setsid 66 -#define __NR_sigaction 67 -#define __NR_setreuid 70 -#define __NR_setregid 71 -#define __NR_sigsuspend 72 -#define __NR_sigpending 73 -#define __NR_sethostname 74 -#define __NR_setrlimit 75 -#define __NR_getrusage 77 -#define __NR_gettimeofday_time32 78 -#define __NR_settimeofday_time32 79 -#define __NR_getgroups 80 -#define __NR_setgroups 81 -#define __NR_symlink 83 -#define __NR_readlink 85 -#define __NR_uselib 86 -#define __NR_swapon 87 -#define __NR_reboot 88 -#define __NR_munmap 91 -#define __NR_truncate 92 -#define __NR_ftruncate 93 -#define __NR_fchmod 94 -#define __NR_fchown 95 -#define __NR_getpriority 96 -#define __NR_setpriority 97 -#define __NR_statfs 99 -#define __NR_fstatfs 100 -#define __NR_syslog 103 -#define __NR_setitimer 104 -#define __NR_getitimer 105 -#define __NR_stat 106 -#define __NR_lstat 107 -#define __NR_fstat 108 -#define __NR_vhangup 111 -#define __NR_wait4 114 -#define __NR_swapoff 115 -#define __NR_sysinfo 116 -#define __NR_fsync 118 -#define __NR_sigreturn 119 -#define __NR_clone 120 -#define __NR_setdomainname 121 -#define __NR_uname 122 -#define __NR_adjtimex 124 -#define __NR_mprotect 125 -#define __NR_sigprocmask 126 -#define __NR_init_module 128 -#define __NR_delete_module 129 -#define __NR_quotactl 131 -#define __NR_getpgid 132 -#define __NR_fchdir 133 -#define __NR_bdflush 134 -#define __NR_sysfs 135 -#define __NR_personality 136 -#define __NR_setfsuid 138 -#define __NR_setfsgid 139 -#define __NR__llseek 140 -#define __NR_getdents 141 -#define __NR__newselect 142 -#define __NR_flock 143 -#define __NR_msync 144 -#define __NR_readv 145 -#define __NR_writev 146 -#define __NR_getsid 147 -#define __NR_fdatasync 148 -#define __NR__sysctl 149 -#define __NR_mlock 150 -#define __NR_munlock 151 -#define __NR_mlockall 152 -#define __NR_munlockall 153 -#define __NR_sched_setparam 154 -#define __NR_sched_getparam 155 -#define __NR_sched_setscheduler 156 -#define __NR_sched_getscheduler 157 -#define __NR_sched_yield 158 -#define __NR_sched_get_priority_max 159 -#define __NR_sched_get_priority_min 160 -#define __NR_sched_rr_get_interval 161 -#define __NR_nanosleep 162 -#define __NR_mremap 163 -#define __NR_setresuid 164 -#define __NR_getresuid 165 -#define __NR_poll 168 -#define __NR_nfsservctl 169 -#define __NR_setresgid 170 -#define __NR_getresgid 171 -#define __NR_prctl 172 -#define __NR_rt_sigreturn 173 -#define __NR_rt_sigaction 174 -#define __NR_rt_sigprocmask 175 -#define __NR_rt_sigpending 176 -#define __NR_rt_sigtimedwait 177 -#define __NR_rt_sigqueueinfo 178 -#define __NR_rt_sigsuspend 179 -#define __NR_pread64 180 -#define __NR_pwrite64 181 -#define __NR_chown 182 -#define __NR_getcwd 183 -#define __NR_capget 184 -#define __NR_capset 185 -#define __NR_sigaltstack 186 -#define __NR_sendfile 187 -#define __NR_vfork 190 -#define __NR_ugetrlimit 191 -#define __NR_mmap2 192 -#define __NR_truncate64 193 -#define __NR_ftruncate64 194 -#define __NR_stat64 195 -#define __NR_lstat64 196 -#define __NR_fstat64 197 -#define __NR_lchown32 198 -#define __NR_getuid32 199 -#define __NR_getgid32 200 -#define __NR_geteuid32 201 -#define __NR_getegid32 202 -#define __NR_setreuid32 203 -#define __NR_setregid32 204 -#define __NR_getgroups32 205 -#define __NR_setgroups32 206 -#define __NR_fchown32 207 -#define __NR_setresuid32 208 -#define __NR_getresuid32 209 -#define __NR_setresgid32 210 -#define __NR_getresgid32 211 -#define __NR_chown32 212 -#define __NR_setuid32 213 -#define __NR_setgid32 214 -#define __NR_setfsuid32 215 -#define __NR_setfsgid32 216 -#define __NR_getdents64 217 -#define __NR_pivot_root 218 -#define __NR_mincore 219 -#define __NR_madvise 220 -#define __NR_fcntl64 221 -#define __NR_gettid 224 -#define __NR_readahead 225 -#define __NR_setxattr 226 -#define __NR_lsetxattr 227 -#define __NR_fsetxattr 228 -#define __NR_getxattr 229 -#define __NR_lgetxattr 230 -#define __NR_fgetxattr 231 -#define __NR_listxattr 232 -#define __NR_llistxattr 233 -#define __NR_flistxattr 234 -#define __NR_removexattr 235 -#define __NR_lremovexattr 236 -#define __NR_fremovexattr 237 -#define __NR_tkill 238 -#define __NR_sendfile64 239 -#define __NR_futex 240 -#define __NR_sched_setaffinity 241 -#define __NR_sched_getaffinity 242 -#define __NR_io_setup 243 -#define __NR_io_destroy 244 -#define __NR_io_getevents 245 -#define __NR_io_submit 246 -#define __NR_io_cancel 247 -#define __NR_exit_group 248 -#define __NR_lookup_dcookie 249 -#define __NR_epoll_create 250 -#define __NR_epoll_ctl 251 -#define __NR_epoll_wait 252 -#define __NR_remap_file_pages 253 -#define __NR_set_tid_address 256 -#define __NR_timer_create 257 -#define __NR_timer_settime32 258 -#define __NR_timer_gettime32 259 -#define __NR_timer_getoverrun 260 -#define __NR_timer_delete 261 -#define __NR_clock_settime32 262 -#define __NR_clock_gettime32 263 -#define __NR_clock_getres_time32 264 -#define __NR_clock_nanosleep_time32 265 -#define __NR_statfs64 266 -#define __NR_fstatfs64 267 -#define __NR_tgkill 268 -#define __NR_utimes 269 -#define __NR_fadvise64_64 270 -#define __NR_arm_fadvise64_64 270 -#define __NR_pciconfig_iobase 271 -#define __NR_pciconfig_read 272 -#define __NR_pciconfig_write 273 -#define __NR_mq_open 274 -#define __NR_mq_unlink 275 -#define __NR_mq_timedsend 276 -#define __NR_mq_timedreceive 277 -#define __NR_mq_notify 278 -#define __NR_mq_getsetattr 279 -#define __NR_waitid 280 -#define __NR_socket 281 -#define __NR_bind 282 -#define __NR_connect 283 -#define __NR_listen 284 -#define __NR_accept 285 -#define __NR_getsockname 286 -#define __NR_getpeername 287 -#define __NR_socketpair 288 -#define __NR_send 289 -#define __NR_sendto 290 -#define __NR_recv 291 -#define __NR_recvfrom 292 -#define __NR_shutdown 293 -#define __NR_setsockopt 294 -#define __NR_getsockopt 295 -#define __NR_sendmsg 296 -#define __NR_recvmsg 297 -#define __NR_semop 298 -#define __NR_semget 299 -#define __NR_semctl 300 -#define __NR_msgsnd 301 -#define __NR_msgrcv 302 -#define __NR_msgget 303 -#define __NR_msgctl 304 -#define __NR_shmat 305 -#define __NR_shmdt 306 -#define __NR_shmget 307 -#define __NR_shmctl 308 -#define __NR_add_key 309 -#define __NR_request_key 310 -#define __NR_keyctl 311 -#define __NR_semtimedop 312 -#define __NR_vserver 313 -#define __NR_ioprio_set 314 -#define __NR_ioprio_get 315 -#define __NR_inotify_init 316 -#define __NR_inotify_add_watch 317 -#define __NR_inotify_rm_watch 318 -#define __NR_mbind 319 -#define __NR_get_mempolicy 320 -#define __NR_set_mempolicy 321 -#define __NR_openat 322 -#define __NR_mkdirat 323 -#define __NR_mknodat 324 -#define __NR_fchownat 325 -#define __NR_futimesat 326 -#define __NR_fstatat64 327 -#define __NR_unlinkat 328 -#define __NR_renameat 329 -#define __NR_linkat 330 -#define __NR_symlinkat 331 -#define __NR_readlinkat 332 -#define __NR_fchmodat 333 -#define __NR_faccessat 334 -#define __NR_pselect6 335 -#define __NR_ppoll 336 -#define __NR_unshare 337 -#define __NR_set_robust_list 338 -#define __NR_get_robust_list 339 -#define __NR_splice 340 -#define __NR_sync_file_range2 341 -#define __NR_arm_sync_file_range 341 -#define __NR_tee 342 -#define __NR_vmsplice 343 -#define __NR_move_pages 344 -#define __NR_getcpu 345 -#define __NR_epoll_pwait 346 -#define __NR_kexec_load 347 -#define __NR_utimensat 348 -#define __NR_signalfd 349 -#define __NR_timerfd_create 350 -#define __NR_eventfd 351 -#define __NR_fallocate 352 -#define __NR_timerfd_settime32 353 -#define __NR_timerfd_gettime32 354 -#define __NR_signalfd4 355 -#define __NR_eventfd2 356 -#define __NR_epoll_create1 357 -#define __NR_dup3 358 -#define __NR_pipe2 359 -#define __NR_inotify_init1 360 -#define __NR_preadv 361 -#define __NR_pwritev 362 -#define __NR_rt_tgsigqueueinfo 363 -#define __NR_perf_event_open 364 -#define __NR_recvmmsg 365 -#define __NR_accept4 366 -#define __NR_fanotify_init 367 -#define __NR_fanotify_mark 368 -#define __NR_prlimit64 369 -#define __NR_name_to_handle_at 370 -#define __NR_open_by_handle_at 371 -#define __NR_clock_adjtime 372 -#define __NR_syncfs 373 -#define __NR_sendmmsg 374 -#define __NR_setns 375 -#define __NR_process_vm_readv 376 -#define __NR_process_vm_writev 377 -#define __NR_kcmp 378 -#define __NR_finit_module 379 -#define __NR_sched_setattr 380 -#define __NR_sched_getattr 381 -#define __NR_renameat2 382 -#define __NR_seccomp 383 -#define __NR_getrandom 384 -#define __NR_memfd_create 385 -#define __NR_bpf 386 -#define __NR_execveat 387 -#define __NR_userfaultfd 388 -#define __NR_membarrier 389 -#define __NR_mlock2 390 -#define __NR_copy_file_range 391 -#define __NR_preadv2 392 -#define __NR_pwritev2 393 -#define __NR_pkey_mprotect 394 -#define __NR_pkey_alloc 395 -#define __NR_pkey_free 396 -#define __NR_statx 397 -#define __NR_rseq 398 -#define __NR_io_pgetevents 399 -#define __NR_migrate_pages 400 -#define __NR_kexec_file_load 401 -#define __NR_clock_gettime64 403 -#define __NR_clock_settime64 404 -#define __NR_clock_adjtime64 405 -#define __NR_clock_getres_time64 406 -#define __NR_clock_nanosleep_time64 407 -#define __NR_timer_gettime64 408 -#define __NR_timer_settime64 409 -#define __NR_timerfd_gettime64 410 -#define __NR_timerfd_settime64 411 -#define __NR_utimensat_time64 412 -#define __NR_pselect6_time64 413 -#define __NR_ppoll_time64 414 -#define __NR_io_pgetevents_time64 416 -#define __NR_recvmmsg_time64 417 -#define __NR_mq_timedsend_time64 418 -#define __NR_mq_timedreceive_time64 419 -#define __NR_semtimedop_time64 420 -#define __NR_rt_sigtimedwait_time64 421 -#define __NR_futex_time64 422 -#define __NR_sched_rr_get_interval_time64 423 -#define __NR_pidfd_send_signal 424 -#define __NR_io_uring_setup 425 -#define __NR_io_uring_enter 426 -#define __NR_io_uring_register 427 -#define __NR_open_tree 428 -#define __NR_move_mount 429 -#define __NR_fsopen 430 -#define __NR_fsconfig 431 -#define __NR_fsmount 432 -#define __NR_fspick 433 -#define __NR_pidfd_open 434 -#define __NR_clone3 435 -#define __NR_close_range 436 -#define __NR_openat2 437 -#define __NR_pidfd_getfd 438 -#define __NR_faccessat2 439 -#define __NR_process_madvise 440 -#define __NR_epoll_pwait2 441 -#define __NR_mount_setattr 442 -#define __NR_landlock_create_ruleset 444 -#define __NR_landlock_add_rule 445 -#define __NR_landlock_restrict_self 446 - -#define __ARM_NR_breakpoint 0x0f0001 -#define __ARM_NR_cacheflush 0x0f0002 -#define __ARM_NR_usr26 0x0f0003 -#define __ARM_NR_usr32 0x0f0004 -#define __ARM_NR_set_tls 0x0f0005 -#define __ARM_NR_get_tls 0x0f0006 - diff --git a/usr/lib/libc/include/asm-aarch32/bits/user.h b/usr/lib/libc/include/asm-aarch32/bits/user.h deleted file mode 100644 index 3e5a4d21d..000000000 --- a/usr/lib/libc/include/asm-aarch32/bits/user.h +++ /dev/null @@ -1,36 +0,0 @@ -typedef struct user_fpregs { - struct fp_reg { - unsigned sign1:1; - unsigned unused:15; - unsigned sign2:1; - unsigned exponent:14; - unsigned j:1; - unsigned mantissa1:31; - unsigned mantissa0:32; - } fpregs[8]; - unsigned fpsr:32; - unsigned fpcr:32; - unsigned char ftype[8]; - unsigned int init_flag; -} elf_fpregset_t; - -struct user_regs { - unsigned long uregs[18]; -}; -#define ELF_NGREG 18 -typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG]; - -struct user { - struct user_regs regs; - int u_fpvalid; - unsigned long u_tsize, u_dsize, u_ssize; - unsigned long start_code, start_stack; - long signal; - int reserved; - struct user_regs *u_ar0; - unsigned long magic; - char u_comm[32]; - int u_debugreg[8]; - struct user_fpregs u_fp; - struct user_fpregs *u_fp0; -}; diff --git a/usr/lib/libc/include/asm-aarch32/crt_arch.h b/usr/lib/libc/include/asm-aarch32/crt_arch.h deleted file mode 100644 index 99508b1db..000000000 --- a/usr/lib/libc/include/asm-aarch32/crt_arch.h +++ /dev/null @@ -1,18 +0,0 @@ -__asm__( -".text \n" -".global " START " \n" -".type " START ",%function \n" -START ": \n" -" mov fp, #0 \n" -" mov lr, #0 \n" -" ldr a2, 1f \n" -" add a2, pc, a2 \n" -" mov a1, sp \n" -"2: and ip, a1, #-16 \n" -" mov sp, ip \n" -" bl " START "_c \n" -".weak _DYNAMIC \n" -".hidden _DYNAMIC \n" -".align 2 \n" -"1: .word _DYNAMIC-2b \n" -); diff --git a/usr/lib/libc/include/asm-aarch32/kstat.h b/usr/lib/libc/include/asm-aarch32/kstat.h deleted file mode 100644 index af449c950..000000000 --- a/usr/lib/libc/include/asm-aarch32/kstat.h +++ /dev/null @@ -1,21 +0,0 @@ -struct kstat { - dev_t st_dev; - int __st_dev_padding; - long __st_ino_truncated; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - int __st_rdev_padding; - off_t st_size; - blksize_t st_blksize; - blkcnt_t st_blocks; - long st_atime_sec; - long st_atime_nsec; - long st_mtime_sec; - long st_mtime_nsec; - long st_ctime_sec; - long st_ctime_nsec; - ino_t st_ino; -}; diff --git a/usr/lib/libc/include/asm-aarch32/pthread_arch.h b/usr/lib/libc/include/asm-aarch32/pthread_arch.h deleted file mode 100644 index 157e2eae6..000000000 --- a/usr/lib/libc/include/asm-aarch32/pthread_arch.h +++ /dev/null @@ -1,32 +0,0 @@ -#if ((__ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ - || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 - -static inline uintptr_t __get_tp() -{ - uintptr_t tp; - __asm__ ( "mrc p15,0,%0,c13,c0,3" : "=r"(tp) ); - return tp; -} - -#else - -#if __ARM_ARCH_4__ || __ARM_ARCH_4T__ || __ARM_ARCH == 4 -#define BLX "mov lr,pc\n\tbx" -#else -#define BLX "blx" -#endif - -static inline uintptr_t __get_tp() -{ - extern hidden uintptr_t __a_gettp_ptr; - register uintptr_t tp __asm__("r0"); - __asm__ ( BLX " %1" : "=r"(tp) : "r"(__a_gettp_ptr) : "cc", "lr" ); - return tp; -} - -#endif - -#define TLS_ABOVE_TP -#define GAP_ABOVE_TP 8 - -#define MC_PC arm_pc diff --git a/usr/lib/libc/include/asm-aarch32/reloc.h b/usr/lib/libc/include/asm-aarch32/reloc.h deleted file mode 100644 index d091d2ad9..000000000 --- a/usr/lib/libc/include/asm-aarch32/reloc.h +++ /dev/null @@ -1,32 +0,0 @@ -#if __BYTE_ORDER == __BIG_ENDIAN -#define ENDIAN_SUFFIX "eb" -#else -#define ENDIAN_SUFFIX "" -#endif - -#if __ARM_PCS_VFP -#define FP_SUFFIX "hf" -#else -#define FP_SUFFIX "" -#endif - -#define LDSO_ARCH "arm" ENDIAN_SUFFIX FP_SUFFIX - -#define NO_LEGACY_INITFINI - -#define TPOFF_K 0 - -#define REL_SYMBOLIC R_ARM_ABS32 -#define REL_GOT R_ARM_GLOB_DAT -#define REL_PLT R_ARM_JUMP_SLOT -#define REL_RELATIVE R_ARM_RELATIVE -#define REL_COPY R_ARM_COPY -#define REL_DTPMOD R_ARM_TLS_DTPMOD32 -#define REL_DTPOFF R_ARM_TLS_DTPOFF32 -#define REL_TPOFF R_ARM_TLS_TPOFF32 -#define REL_TLSDESC R_ARM_TLS_DESC - -#define TLSDESC_BACKWARDS - -#define CRTJMP(pc,sp) __asm__ __volatile__( \ - "mov sp,%1 ; bx %0" : : "r"(pc), "r"(sp) : "memory" ) diff --git a/usr/lib/libc/include/asm-aarch32/socket.h b/usr/lib/libc/include/asm-aarch32/socket.h deleted file mode 100644 index 6187f49b0..000000000 --- a/usr/lib/libc/include/asm-aarch32/socket.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _ASMARM_SOCKET_H -#define _ASMARM_SOCKET_H -#include -/* For setsockopt(2) */ -#define SOL_SOCKET 1 -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_SNDBUFFORCE 32 -#define SO_RCVBUFFORCE 33 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -/* To add :#define SO_REUSEPORT 15 */ -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 -/* Security levels - as per NRL IPv6 - don't actually do anything */ -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 -#define SO_BINDTODEVICE 25 -/* Socket filtering */ -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 -#define SO_PEERNAME 28 -#define SO_TIMESTAMP 29 -#define SCM_TIMESTAMP SO_TIMESTAMP -#define SO_ACCEPTCONN 30 -#define SO_PEERSEC 31 -#define SO_PASSSEC 34 -#endif /* _ASM_SOCKET_H */ diff --git a/usr/lib/libc/include/asm-aarch32/sockios.h b/usr/lib/libc/include/asm-aarch32/sockios.h deleted file mode 100644 index c238e77b1..000000000 --- a/usr/lib/libc/include/asm-aarch32/sockios.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __ARCH_ARM_SOCKIOS_H -#define __ARCH_ARM_SOCKIOS_H -/* Socket-level I/O control calls. */ -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -#define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 /* Get stamp */ - -#endif diff --git a/usr/lib/libc/include/asm-aarch32/syscall_arch.h b/usr/lib/libc/include/asm-aarch32/syscall_arch.h deleted file mode 100644 index a877b2cff..000000000 --- a/usr/lib/libc/include/asm-aarch32/syscall_arch.h +++ /dev/null @@ -1,103 +0,0 @@ -#define __SYSCALL_LL_E(x) \ -((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ -((union { long long ll; long l[2]; }){ .ll = x }).l[1] -#define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x)) - -#ifdef __thumb__ - -/* Avoid use of r7 in asm constraints when producing thumb code, - * since it's reserved as frame pointer and might not be supported. */ -#define __ASM____R7__ -#define __asm_syscall(...) do { \ - __asm__ __volatile__ ( "mov %1,r7 ; mov r7,%2 ; svc 0 ; mov r7,%1" \ - : "=r"(r0), "=&r"((int){0}) : __VA_ARGS__ : "memory"); \ - return r0; \ - } while (0) - -#else - -#define __ASM____R7__ __asm__("r7") -#define __asm_syscall(...) do { \ - __asm__ __volatile__ ( "svc 0" \ - : "=r"(r0) : __VA_ARGS__ : "memory"); \ - return r0; \ - } while (0) -#endif - -/* For thumb2, we can allow 8-bit immediate syscall numbers, saving a - * register in the above dance around r7. Does not work for thumb1 where - * only movs, not mov, supports immediates, and we can't use movs because - * it doesn't support high regs. */ -#ifdef __thumb2__ -#define R7_OPERAND "rI"(r7) -#else -#define R7_OPERAND "r"(r7) -#endif - -static inline long __syscall0(long n) -{ - register long r7 __ASM____R7__ = n; - register long r0 __asm__("r0"); - __asm_syscall(R7_OPERAND); -} - -static inline long __syscall1(long n, long a) -{ - register long r7 __ASM____R7__ = n; - register long r0 __asm__("r0") = a; - __asm_syscall(R7_OPERAND, "0"(r0)); -} - -static inline long __syscall2(long n, long a, long b) -{ - register long r7 __ASM____R7__ = n; - register long r0 __asm__("r0") = a; - register long r1 __asm__("r1") = b; - __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1)); -} - -static inline long __syscall3(long n, long a, long b, long c) -{ - register long r7 __ASM____R7__ = n; - register long r0 __asm__("r0") = a; - register long r1 __asm__("r1") = b; - register long r2 __asm__("r2") = c; - __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2)); -} - -static inline long __syscall4(long n, long a, long b, long c, long d) -{ - register long r7 __ASM____R7__ = n; - register long r0 __asm__("r0") = a; - register long r1 __asm__("r1") = b; - register long r2 __asm__("r2") = c; - register long r3 __asm__("r3") = d; - __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3)); -} - -static inline long __syscall5(long n, long a, long b, long c, long d, long e) -{ - register long r7 __ASM____R7__ = n; - register long r0 __asm__("r0") = a; - register long r1 __asm__("r1") = b; - register long r2 __asm__("r2") = c; - register long r3 __asm__("r3") = d; - register long r4 __asm__("r4") = e; - __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)); -} - -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) -{ - register long r7 __ASM____R7__ = n; - register long r0 __asm__("r0") = a; - register long r1 __asm__("r1") = b; - register long r2 __asm__("r2") = c; - register long r3 __asm__("r3") = d; - register long r4 __asm__("r4") = e; - register long r5 __asm__("r5") = f; - __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5)); -} - -#define SYSCALL_FADVISE_6_ARG - -#define SYSCALL_IPC_BROKEN_MODE diff --git a/usr/lib/libc/include/asm-aarch64/atomic_arch.h b/usr/lib/libc/include/asm-aarch64/atomic_arch.h deleted file mode 100644 index 40fefc25b..000000000 --- a/usr/lib/libc/include/asm-aarch64/atomic_arch.h +++ /dev/null @@ -1,82 +0,0 @@ -#define a_ll a_ll -static inline int a_ll(volatile int *p) -{ - int v; - __asm__ __volatile__ ("ldaxr %w0,%1" : "=r"(v) : "Q"(*p)); - return v; -} - -#define a_sc a_sc -static inline int a_sc(volatile int *p, int v) -{ - int r; - __asm__ __volatile__ ("stlxr %w0,%w2,%1" : "=&r"(r), "=Q"(*p) : "r"(v) : "memory"); - return !r; -} - -#define a_barrier a_barrier -static inline void a_barrier() -{ - __asm__ __volatile__ ("dmb ish" : : : "memory"); -} - -#define a_cas a_cas -static inline int a_cas(volatile int *p, int t, int s) -{ - int old; - do { - old = a_ll(p); - if (old != t) { - a_barrier(); - break; - } - } while (!a_sc(p, s)); - return old; -} - -#define a_ll_p a_ll_p -static inline void *a_ll_p(volatile void *p) -{ - void *v; - __asm__ __volatile__ ("ldaxr %0, %1" : "=r"(v) : "Q"(*(void *volatile *)p)); - return v; -} - -#define a_sc_p a_sc_p -static inline int a_sc_p(volatile int *p, void *v) -{ - int r; - __asm__ __volatile__ ("stlxr %w0,%2,%1" : "=&r"(r), "=Q"(*(void *volatile *)p) : "r"(v) : "memory"); - return !r; -} - -#define a_cas_p a_cas_p -static inline void *a_cas_p(volatile void *p, void *t, void *s) -{ - void *old; - do { - old = a_ll_p(p); - if (old != t) { - a_barrier(); - break; - } - } while (!a_sc_p(p, s)); - return old; -} - -#define a_ctz_64 a_ctz_64 -static inline int a_ctz_64(uint64_t x) -{ - __asm__( - " rbit %0, %1\n" - " clz %0, %0\n" - : "=r"(x) : "r"(x)); - return x; -} - -#define a_clz_64 a_clz_64 -static inline int a_clz_64(uint64_t x) -{ - __asm__("clz %0, %1" : "=r"(x) : "r"(x)); - return x; -} diff --git a/usr/lib/libc/include/asm-aarch64/bits/alltypes.h.in b/usr/lib/libc/include/asm-aarch64/bits/alltypes.h.in deleted file mode 100644 index c547ca0b7..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/alltypes.h.in +++ /dev/null @@ -1,24 +0,0 @@ -#define _Addr long -#define _Int64 long -#define _Reg long - -#if __AARCH64EB__ -#define __BYTE_ORDER 4321 -#else -#define __BYTE_ORDER 1234 -#endif - -#define __LONG_MAX 0x7fffffffffffffffL - -#ifndef __cplusplus -TYPEDEF unsigned wchar_t; -#endif -TYPEDEF unsigned wint_t; - -TYPEDEF int blksize_t; -TYPEDEF unsigned int nlink_t; - -TYPEDEF float float_t; -TYPEDEF double double_t; - -TYPEDEF struct { long long __ll; long double __ld; } max_align_t; diff --git a/usr/lib/libc/include/asm-aarch64/bits/fcntl.h b/usr/lib/libc/include/asm-aarch64/bits/fcntl.h deleted file mode 100644 index 927879760..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/fcntl.h +++ /dev/null @@ -1,38 +0,0 @@ -#define O_CREAT 0100 -#define O_EXCL 0200 -#define O_NOCTTY 0400 -#define O_TRUNC 01000 -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_DSYNC 010000 -#define O_SYNC 04010000 -#define O_RSYNC 04010000 -#define O_DIRECTORY 040000 -#define O_NOFOLLOW 0100000 -#define O_CLOEXEC 02000000 - -#define O_ASYNC 020000 -#define O_DIRECT 0200000 -#define O_LARGEFILE 0400000 -#define O_NOATIME 01000000 -#define O_PATH 010000000 -#define O_TMPFILE 020040000 -#define O_NDELAY O_NONBLOCK - -#define F_DUPFD 0 -#define F_GETFD 1 -#define F_SETFD 2 -#define F_GETFL 3 -#define F_SETFL 4 -#define F_GETLK 5 -#define F_SETLK 6 -#define F_SETLKW 7 -#define F_SETOWN 8 -#define F_GETOWN 9 -#define F_SETSIG 10 -#define F_GETSIG 11 - -#define F_SETOWN_EX 15 -#define F_GETOWN_EX 16 - -#define F_GETOWNER_UIDS 17 diff --git a/usr/lib/libc/include/asm-aarch64/bits/fenv.h b/usr/lib/libc/include/asm-aarch64/bits/fenv.h deleted file mode 100644 index 2f3279abc..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/fenv.h +++ /dev/null @@ -1,19 +0,0 @@ -#define FE_INVALID 1 -#define FE_DIVBYZERO 2 -#define FE_OVERFLOW 4 -#define FE_UNDERFLOW 8 -#define FE_INEXACT 16 -#define FE_ALL_EXCEPT 31 -#define FE_TONEAREST 0 -#define FE_DOWNWARD 0x800000 -#define FE_UPWARD 0x400000 -#define FE_TOWARDZERO 0xc00000 - -typedef unsigned int fexcept_t; - -typedef struct { - unsigned int __fpcr; - unsigned int __fpsr; -} fenv_t; - -#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/usr/lib/libc/include/asm-aarch64/bits/float.h b/usr/lib/libc/include/asm-aarch64/bits/float.h deleted file mode 100644 index 719c79085..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/float.h +++ /dev/null @@ -1,16 +0,0 @@ -#define FLT_EVAL_METHOD 0 - -#define LDBL_TRUE_MIN 6.47517511943802511092443895822764655e-4966L -#define LDBL_MIN 3.36210314311209350626267781732175260e-4932L -#define LDBL_MAX 1.18973149535723176508575932662800702e+4932L -#define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L - -#define LDBL_MANT_DIG 113 -#define LDBL_MIN_EXP (-16381) -#define LDBL_MAX_EXP 16384 - -#define LDBL_DIG 33 -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_10_EXP 4932 - -#define DECIMAL_DIG 36 diff --git a/usr/lib/libc/include/asm-aarch64/bits/hwcap.h b/usr/lib/libc/include/asm-aarch64/bits/hwcap.h deleted file mode 100644 index 424cc4d4f..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/hwcap.h +++ /dev/null @@ -1,52 +0,0 @@ -#define HWCAP_FP (1 << 0) -#define HWCAP_ASIMD (1 << 1) -#define HWCAP_EVTSTRM (1 << 2) -#define HWCAP_AES (1 << 3) -#define HWCAP_PMULL (1 << 4) -#define HWCAP_SHA1 (1 << 5) -#define HWCAP_SHA2 (1 << 6) -#define HWCAP_CRC32 (1 << 7) -#define HWCAP_ATOMICS (1 << 8) -#define HWCAP_FPHP (1 << 9) -#define HWCAP_ASIMDHP (1 << 10) -#define HWCAP_CPUID (1 << 11) -#define HWCAP_ASIMDRDM (1 << 12) -#define HWCAP_JSCVT (1 << 13) -#define HWCAP_FCMA (1 << 14) -#define HWCAP_LRCPC (1 << 15) -#define HWCAP_DCPOP (1 << 16) -#define HWCAP_SHA3 (1 << 17) -#define HWCAP_SM3 (1 << 18) -#define HWCAP_SM4 (1 << 19) -#define HWCAP_ASIMDDP (1 << 20) -#define HWCAP_SHA512 (1 << 21) -#define HWCAP_SVE (1 << 22) -#define HWCAP_ASIMDFHM (1 << 23) -#define HWCAP_DIT (1 << 24) -#define HWCAP_USCAT (1 << 25) -#define HWCAP_ILRCPC (1 << 26) -#define HWCAP_FLAGM (1 << 27) -#define HWCAP_SSBS (1 << 28) -#define HWCAP_SB (1 << 29) -#define HWCAP_PACA (1 << 30) -#define HWCAP_PACG (1UL << 31) - -#define HWCAP2_DCPODP (1 << 0) -#define HWCAP2_SVE2 (1 << 1) -#define HWCAP2_SVEAES (1 << 2) -#define HWCAP2_SVEPMULL (1 << 3) -#define HWCAP2_SVEBITPERM (1 << 4) -#define HWCAP2_SVESHA3 (1 << 5) -#define HWCAP2_SVESM4 (1 << 6) -#define HWCAP2_FLAGM2 (1 << 7) -#define HWCAP2_FRINT (1 << 8) -#define HWCAP2_SVEI8MM (1 << 9) -#define HWCAP2_SVEF32MM (1 << 10) -#define HWCAP2_SVEF64MM (1 << 11) -#define HWCAP2_SVEBF16 (1 << 12) -#define HWCAP2_I8MM (1 << 13) -#define HWCAP2_BF16 (1 << 14) -#define HWCAP2_DGH (1 << 15) -#define HWCAP2_RNG (1 << 16) -#define HWCAP2_BTI (1 << 17) -#define HWCAP2_MTE (1 << 18) diff --git a/usr/lib/libc/include/asm-aarch64/bits/ioctl_fix.h b/usr/lib/libc/include/asm-aarch64/bits/ioctl_fix.h deleted file mode 100644 index ebb383daf..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/ioctl_fix.h +++ /dev/null @@ -1,2 +0,0 @@ -#undef FIOQSIZE -#define FIOQSIZE 0x545e diff --git a/usr/lib/libc/include/asm-aarch64/bits/ipcstat.h b/usr/lib/libc/include/asm-aarch64/bits/ipcstat.h deleted file mode 100644 index 4f4fcb0c5..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/ipcstat.h +++ /dev/null @@ -1 +0,0 @@ -#define IPC_STAT 0x102 diff --git a/usr/lib/libc/include/asm-aarch64/bits/mman.h b/usr/lib/libc/include/asm-aarch64/bits/mman.h deleted file mode 100644 index 8fad5ceb0..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/mman.h +++ /dev/null @@ -1,2 +0,0 @@ -#define PROT_BTI 0x10 -#define PROT_MTE 0x20 diff --git a/usr/lib/libc/include/asm-aarch64/bits/msg.h b/usr/lib/libc/include/asm-aarch64/bits/msg.h deleted file mode 100644 index 7bbbb2bf4..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/msg.h +++ /dev/null @@ -1,18 +0,0 @@ -struct msqid_ds { - struct ipc_perm msg_perm; - unsigned long __msg_stime_lo; - unsigned long __msg_stime_hi; - unsigned long __msg_rtime_lo; - unsigned long __msg_rtime_hi; - unsigned long __msg_ctime_lo; - unsigned long __msg_ctime_hi; - unsigned long msg_cbytes; - msgqnum_t msg_qnum; - msglen_t msg_qbytes; - pid_t msg_lspid; - pid_t msg_lrpid; - unsigned long __unused[2]; - time_t msg_stime; - time_t msg_rtime; - time_t msg_ctime; -}; diff --git a/usr/lib/libc/include/asm-aarch64/bits/posix.h b/usr/lib/libc/include/asm-aarch64/bits/posix.h deleted file mode 100644 index c37b94c14..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_LP64_OFF64 1 -#define _POSIX_V7_LP64_OFF64 1 diff --git a/usr/lib/libc/include/asm-aarch64/bits/ptrace.h b/usr/lib/libc/include/asm-aarch64/bits/ptrace.h deleted file mode 100644 index 9556ef4b7..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/ptrace.h +++ /dev/null @@ -1,25 +0,0 @@ -#define PTRACE_GETWMMXREGS 18 -#define PTRACE_SETWMMXREGS 19 -#define PTRACE_GET_THREAD_AREA 22 -#define PTRACE_SET_SYSCALL 23 -#define PTRACE_GETCRUNCHREGS 25 -#define PTRACE_SETCRUNCHREGS 26 -#define PTRACE_GETVFPREGS 27 -#define PTRACE_SETVFPREGS 28 -#define PTRACE_GETHBPREGS 29 -#define PTRACE_SETHBPREGS 30 -#define PTRACE_GETFDPIC 31 -#define PTRACE_GETFDPIC_EXEC 0 -#define PTRACE_GETFDPIC_INTERP 1 - -#define PT_GETWMMXREGS PTRACE_GETWMMXREGS -#define PT_SETWMMXREGS PTRACE_SETWMMXREGS -#define PT_GET_THREAD_AREA PTRACE_GET_THREAD_AREA -#define PT_SET_SYSCALL PTRACE_SET_SYSCALL -#define PT_GETCRUNCHREGS PTRACE_GETCRUNCHREGS -#define PT_SETCRUNCHREGS PTRACE_SETCRUNCHREGS -#define PT_GETVFPREGS PTRACE_GETVFPREGS -#define PT_SETVFPREGS PTRACE_SETVFPREGS -#define PT_GETHBPREGS PTRACE_GETHBPREGS -#define PT_SETHBPREGS PTRACE_SETHBPREGS -#define PT_GETFDPIC PTRACE_GETFDPIC diff --git a/usr/lib/libc/include/asm-aarch64/bits/reg.h b/usr/lib/libc/include/asm-aarch64/bits/reg.h deleted file mode 100644 index 2633f39d7..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/reg.h +++ /dev/null @@ -1,2 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 64 diff --git a/usr/lib/libc/include/asm-aarch64/bits/sem.h b/usr/lib/libc/include/asm-aarch64/bits/sem.h deleted file mode 100644 index 544e3d2a5..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/sem.h +++ /dev/null @@ -1,18 +0,0 @@ -struct semid_ds { - struct ipc_perm sem_perm; - unsigned long __sem_otime_lo; - unsigned long __sem_otime_hi; - unsigned long __sem_ctime_lo; - unsigned long __sem_ctime_hi; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned short sem_nsems; - char __sem_nsems_pad[sizeof(long)-sizeof(short)]; -#else - char __sem_nsems_pad[sizeof(long)-sizeof(short)]; - unsigned short sem_nsems; -#endif - long __unused3; - long __unused4; - time_t sem_otime; - time_t sem_ctime; -}; diff --git a/usr/lib/libc/include/asm-aarch64/bits/setjmp.h b/usr/lib/libc/include/asm-aarch64/bits/setjmp.h deleted file mode 100644 index 54bc2610c..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/setjmp.h +++ /dev/null @@ -1 +0,0 @@ -typedef unsigned long __jmp_buf[22]; diff --git a/usr/lib/libc/include/asm-aarch64/bits/shm.h b/usr/lib/libc/include/asm-aarch64/bits/shm.h deleted file mode 100644 index 725fb4696..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/shm.h +++ /dev/null @@ -1,31 +0,0 @@ -#define SHMLBA 4096 - -struct shmid_ds { - struct ipc_perm shm_perm; - size_t shm_segsz; - unsigned long __shm_atime_lo; - unsigned long __shm_atime_hi; - unsigned long __shm_dtime_lo; - unsigned long __shm_dtime_hi; - unsigned long __shm_ctime_lo; - unsigned long __shm_ctime_hi; - pid_t shm_cpid; - pid_t shm_lpid; - unsigned long shm_nattch; - unsigned long __pad1; - unsigned long __pad2; - unsigned long __pad3; - time_t shm_atime; - time_t shm_dtime; - time_t shm_ctime; -}; - -struct shminfo { - unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4]; -}; - -struct shm_info { - int __used_ids; - unsigned long shm_tot, shm_rss, shm_swp; - unsigned long __swap_attempts, __swap_successes; -}; diff --git a/usr/lib/libc/include/asm-aarch64/bits/signal.h b/usr/lib/libc/include/asm-aarch64/bits/signal.h deleted file mode 100644 index 5098c7341..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/signal.h +++ /dev/null @@ -1,153 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define MINSIGSTKSZ 6144 -#define SIGSTKSZ 12288 -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -typedef unsigned long greg_t; -typedef unsigned long gregset_t[34]; - -typedef struct { - __uint128_t vregs[32]; - unsigned int fpsr; - unsigned int fpcr; -} fpregset_t; -typedef struct sigcontext { - unsigned long fault_address; - unsigned long regs[31]; - unsigned long sp, pc, pstate; - long double __reserved[256]; -} mcontext_t; - -#define FPSIMD_MAGIC 0x46508001 -#define ESR_MAGIC 0x45535201 -#define EXTRA_MAGIC 0x45585401 -#define SVE_MAGIC 0x53564501 -struct _aarch64_ctx { - unsigned int magic; - unsigned int size; -}; -struct fpsimd_context { - struct _aarch64_ctx head; - unsigned int fpsr; - unsigned int fpcr; - __uint128_t vregs[32]; -}; -struct esr_context { - struct _aarch64_ctx head; - unsigned long esr; -}; -struct extra_context { - struct _aarch64_ctx head; - unsigned long datap; - unsigned int size; - unsigned int __reserved[3]; -}; -struct sve_context { - struct _aarch64_ctx head; - unsigned short vl; - unsigned short __reserved[3]; -}; -#define SVE_VQ_BYTES 16 -#define SVE_VQ_MIN 1 -#define SVE_VQ_MAX 512 -#define SVE_VL_MIN (SVE_VQ_MIN * SVE_VQ_BYTES) -#define SVE_VL_MAX (SVE_VQ_MAX * SVE_VQ_BYTES) -#define SVE_NUM_ZREGS 32 -#define SVE_NUM_PREGS 16 -#define sve_vl_valid(vl) \ - ((vl) % SVE_VQ_BYTES == 0 && (vl) >= SVE_VL_MIN && (vl) <= SVE_VL_MAX) -#define sve_vq_from_vl(vl) ((vl) / SVE_VQ_BYTES) -#define sve_vl_from_vq(vq) ((vq) * SVE_VQ_BYTES) -#define SVE_SIG_ZREG_SIZE(vq) ((unsigned)(vq) * SVE_VQ_BYTES) -#define SVE_SIG_PREG_SIZE(vq) ((unsigned)(vq) * (SVE_VQ_BYTES / 8)) -#define SVE_SIG_FFR_SIZE(vq) SVE_SIG_PREG_SIZE(vq) -#define SVE_SIG_REGS_OFFSET \ - ((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1)) \ - / SVE_VQ_BYTES * SVE_VQ_BYTES) -#define SVE_SIG_ZREGS_OFFSET SVE_SIG_REGS_OFFSET -#define SVE_SIG_ZREG_OFFSET(vq, n) \ - (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREG_SIZE(vq) * (n)) -#define SVE_SIG_ZREGS_SIZE(vq) \ - (SVE_SIG_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_SIG_ZREGS_OFFSET) -#define SVE_SIG_PREGS_OFFSET(vq) \ - (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREGS_SIZE(vq)) -#define SVE_SIG_PREG_OFFSET(vq, n) \ - (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREG_SIZE(vq) * (n)) -#define SVE_SIG_PREGS_SIZE(vq) \ - (SVE_SIG_PREG_OFFSET(vq, SVE_NUM_PREGS) - SVE_SIG_PREGS_OFFSET(vq)) -#define SVE_SIG_FFR_OFFSET(vq) \ - (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREGS_SIZE(vq)) -#define SVE_SIG_REGS_SIZE(vq) \ - (SVE_SIG_FFR_OFFSET(vq) + SVE_SIG_FFR_SIZE(vq) - SVE_SIG_REGS_OFFSET) -#define SVE_SIG_CONTEXT_SIZE(vq) (SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq)) -#else -typedef struct { - long double __regs[18+256]; -} mcontext_t; -#endif - -struct sigaltstack { - void *ss_sp; - int ss_flags; - size_t ss_size; -}; - -typedef struct __ucontext { - unsigned long uc_flags; - struct __ucontext *uc_link; - stack_t uc_stack; - sigset_t uc_sigmask; - mcontext_t uc_mcontext; -} ucontext_t; - -#define SA_NOCLDSTOP 1 -#define SA_NOCLDWAIT 2 -#define SA_SIGINFO 4 -#define SA_ONSTACK 0x08000000 -#define SA_RESTART 0x10000000 -#define SA_NODEFER 0x40000000 -#define SA_RESETHAND 0x80000000 -#define SA_RESTORER 0x04000000 - -#endif - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT SIGABRT -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL 29 -#define SIGPWR 30 -#define SIGSYS 31 -#define SIGUNUSED SIGSYS - -#define _NSIG 65 diff --git a/usr/lib/libc/include/asm-aarch64/bits/stat.h b/usr/lib/libc/include/asm-aarch64/bits/stat.h deleted file mode 100644 index b7f4221be..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/stat.h +++ /dev/null @@ -1,18 +0,0 @@ -struct stat { - dev_t st_dev; - ino_t st_ino; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - unsigned long __pad; - off_t st_size; - blksize_t st_blksize; - int __pad2; - blkcnt_t st_blocks; - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - unsigned __unused[2]; -}; diff --git a/usr/lib/libc/include/asm-aarch64/bits/stdint.h b/usr/lib/libc/include/asm-aarch64/bits/stdint.h deleted file mode 100644 index 1bb147f24..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/stdint.h +++ /dev/null @@ -1,20 +0,0 @@ -typedef int32_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef uint32_t uint_fast16_t; -typedef uint32_t uint_fast32_t; - -#define INT_FAST16_MIN INT32_MIN -#define INT_FAST32_MIN INT32_MIN - -#define INT_FAST16_MAX INT32_MAX -#define INT_FAST32_MAX INT32_MAX - -#define UINT_FAST16_MAX UINT32_MAX -#define UINT_FAST32_MAX UINT32_MAX - -#define INTPTR_MIN INT64_MIN -#define INTPTR_MAX INT64_MAX -#define UINTPTR_MAX UINT64_MAX -#define PTRDIFF_MIN INT64_MIN -#define PTRDIFF_MAX INT64_MAX -#define SIZE_MAX UINT64_MAX diff --git a/usr/lib/libc/include/asm-aarch64/bits/syscall.h.in b/usr/lib/libc/include/asm-aarch64/bits/syscall.h.in deleted file mode 100644 index 5f420e617..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/syscall.h.in +++ /dev/null @@ -1,302 +0,0 @@ -#define __NR_io_setup 0 -#define __NR_io_destroy 1 -#define __NR_io_submit 2 -#define __NR_io_cancel 3 -#define __NR_io_getevents 4 -#define __NR_setxattr 5 -#define __NR_lsetxattr 6 -#define __NR_fsetxattr 7 -#define __NR_getxattr 8 -#define __NR_lgetxattr 9 -#define __NR_fgetxattr 10 -#define __NR_listxattr 11 -#define __NR_llistxattr 12 -#define __NR_flistxattr 13 -#define __NR_removexattr 14 -#define __NR_lremovexattr 15 -#define __NR_fremovexattr 16 -#define __NR_getcwd 17 -#define __NR_lookup_dcookie 18 -#define __NR_eventfd2 19 -#define __NR_epoll_create1 20 -#define __NR_epoll_ctl 21 -#define __NR_epoll_pwait 22 -#define __NR_dup 23 -#define __NR_dup3 24 -#define __NR_fcntl 25 -#define __NR_inotify_init1 26 -#define __NR_inotify_add_watch 27 -#define __NR_inotify_rm_watch 28 -#define __NR_ioctl 29 -#define __NR_ioprio_set 30 -#define __NR_ioprio_get 31 -#define __NR_flock 32 -#define __NR_mknodat 33 -#define __NR_mkdirat 34 -#define __NR_unlinkat 35 -#define __NR_symlinkat 36 -#define __NR_linkat 37 -#define __NR_renameat 38 -#define __NR_umount2 39 -#define __NR_mount 40 -#define __NR_pivot_root 41 -#define __NR_nfsservctl 42 -#define __NR_statfs 43 -#define __NR_fstatfs 44 -#define __NR_truncate 45 -#define __NR_ftruncate 46 -#define __NR_fallocate 47 -#define __NR_faccessat 48 -#define __NR_chdir 49 -#define __NR_fchdir 50 -#define __NR_chroot 51 -#define __NR_fchmod 52 -#define __NR_fchmodat 53 -#define __NR_fchownat 54 -#define __NR_fchown 55 -#define __NR_openat 56 -#define __NR_close 57 -#define __NR_vhangup 58 -#define __NR_pipe2 59 -#define __NR_quotactl 60 -#define __NR_getdents64 61 -#define __NR_lseek 62 -#define __NR_read 63 -#define __NR_write 64 -#define __NR_readv 65 -#define __NR_writev 66 -#define __NR_pread64 67 -#define __NR_pwrite64 68 -#define __NR_preadv 69 -#define __NR_pwritev 70 -#define __NR_sendfile 71 -#define __NR_pselect6 72 -#define __NR_ppoll 73 -#define __NR_signalfd4 74 -#define __NR_vmsplice 75 -#define __NR_splice 76 -#define __NR_tee 77 -#define __NR_readlinkat 78 -#define __NR_newfstatat 79 -#define __NR_fstat 80 -#define __NR_sync 81 -#define __NR_fsync 82 -#define __NR_fdatasync 83 -#define __NR_sync_file_range 84 -#define __NR_timerfd_create 85 -#define __NR_timerfd_settime 86 -#define __NR_timerfd_gettime 87 -#define __NR_utimensat 88 -#define __NR_acct 89 -#define __NR_capget 90 -#define __NR_capset 91 -#define __NR_personality 92 -#define __NR_exit 93 -#define __NR_exit_group 94 -#define __NR_waitid 95 -#define __NR_set_tid_address 96 -#define __NR_unshare 97 -#define __NR_futex 98 -#define __NR_set_robust_list 99 -#define __NR_get_robust_list 100 -#define __NR_nanosleep 101 -#define __NR_getitimer 102 -#define __NR_setitimer 103 -#define __NR_kexec_load 104 -#define __NR_init_module 105 -#define __NR_delete_module 106 -#define __NR_timer_create 107 -#define __NR_timer_gettime 108 -#define __NR_timer_getoverrun 109 -#define __NR_timer_settime 110 -#define __NR_timer_delete 111 -#define __NR_clock_settime 112 -#define __NR_clock_gettime 113 -#define __NR_clock_getres 114 -#define __NR_clock_nanosleep 115 -#define __NR_syslog 116 -#define __NR_ptrace 117 -#define __NR_sched_setparam 118 -#define __NR_sched_setscheduler 119 -#define __NR_sched_getscheduler 120 -#define __NR_sched_getparam 121 -#define __NR_sched_setaffinity 122 -#define __NR_sched_getaffinity 123 -#define __NR_sched_yield 124 -#define __NR_sched_get_priority_max 125 -#define __NR_sched_get_priority_min 126 -#define __NR_sched_rr_get_interval 127 -#define __NR_restart_syscall 128 -#define __NR_kill 129 -#define __NR_tkill 130 -#define __NR_tgkill 131 -#define __NR_sigaltstack 132 -#define __NR_rt_sigsuspend 133 -#define __NR_rt_sigaction 134 -#define __NR_rt_sigprocmask 135 -#define __NR_rt_sigpending 136 -#define __NR_rt_sigtimedwait 137 -#define __NR_rt_sigqueueinfo 138 -#define __NR_rt_sigreturn 139 -#define __NR_setpriority 140 -#define __NR_getpriority 141 -#define __NR_reboot 142 -#define __NR_setregid 143 -#define __NR_setgid 144 -#define __NR_setreuid 145 -#define __NR_setuid 146 -#define __NR_setresuid 147 -#define __NR_getresuid 148 -#define __NR_setresgid 149 -#define __NR_getresgid 150 -#define __NR_setfsuid 151 -#define __NR_setfsgid 152 -#define __NR_times 153 -#define __NR_setpgid 154 -#define __NR_getpgid 155 -#define __NR_getsid 156 -#define __NR_setsid 157 -#define __NR_getgroups 158 -#define __NR_setgroups 159 -#define __NR_uname 160 -#define __NR_sethostname 161 -#define __NR_setdomainname 162 -#define __NR_getrlimit 163 -#define __NR_setrlimit 164 -#define __NR_getrusage 165 -#define __NR_umask 166 -#define __NR_prctl 167 -#define __NR_getcpu 168 -#define __NR_gettimeofday 169 -#define __NR_settimeofday 170 -#define __NR_adjtimex 171 -#define __NR_getpid 172 -#define __NR_getppid 173 -#define __NR_getuid 174 -#define __NR_geteuid 175 -#define __NR_getgid 176 -#define __NR_getegid 177 -#define __NR_gettid 178 -#define __NR_sysinfo 179 -#define __NR_mq_open 180 -#define __NR_mq_unlink 181 -#define __NR_mq_timedsend 182 -#define __NR_mq_timedreceive 183 -#define __NR_mq_notify 184 -#define __NR_mq_getsetattr 185 -#define __NR_msgget 186 -#define __NR_msgctl 187 -#define __NR_msgrcv 188 -#define __NR_msgsnd 189 -#define __NR_semget 190 -#define __NR_semctl 191 -#define __NR_semtimedop 192 -#define __NR_semop 193 -#define __NR_shmget 194 -#define __NR_shmctl 195 -#define __NR_shmat 196 -#define __NR_shmdt 197 -#define __NR_socket 198 -#define __NR_socketpair 199 -#define __NR_bind 200 -#define __NR_listen 201 -#define __NR_accept 202 -#define __NR_connect 203 -#define __NR_getsockname 204 -#define __NR_getpeername 205 -#define __NR_sendto 206 -#define __NR_recvfrom 207 -#define __NR_setsockopt 208 -#define __NR_getsockopt 209 -#define __NR_shutdown 210 -#define __NR_sendmsg 211 -#define __NR_recvmsg 212 -#define __NR_readahead 213 -#define __NR_brk 214 -#define __NR_munmap 215 -#define __NR_mremap 216 -#define __NR_add_key 217 -#define __NR_request_key 218 -#define __NR_keyctl 219 -#define __NR_clone 220 -#define __NR_execve 221 -#define __NR_mmap 222 -#define __NR_fadvise64 223 -#define __NR_swapon 224 -#define __NR_swapoff 225 -#define __NR_mprotect 226 -#define __NR_msync 227 -#define __NR_mlock 228 -#define __NR_munlock 229 -#define __NR_mlockall 230 -#define __NR_munlockall 231 -#define __NR_mincore 232 -#define __NR_madvise 233 -#define __NR_remap_file_pages 234 -#define __NR_mbind 235 -#define __NR_get_mempolicy 236 -#define __NR_set_mempolicy 237 -#define __NR_migrate_pages 238 -#define __NR_move_pages 239 -#define __NR_rt_tgsigqueueinfo 240 -#define __NR_perf_event_open 241 -#define __NR_accept4 242 -#define __NR_recvmmsg 243 -#define __NR_wait4 260 -#define __NR_prlimit64 261 -#define __NR_fanotify_init 262 -#define __NR_fanotify_mark 263 -#define __NR_name_to_handle_at 264 -#define __NR_open_by_handle_at 265 -#define __NR_clock_adjtime 266 -#define __NR_syncfs 267 -#define __NR_setns 268 -#define __NR_sendmmsg 269 -#define __NR_process_vm_readv 270 -#define __NR_process_vm_writev 271 -#define __NR_kcmp 272 -#define __NR_finit_module 273 -#define __NR_sched_setattr 274 -#define __NR_sched_getattr 275 -#define __NR_renameat2 276 -#define __NR_seccomp 277 -#define __NR_getrandom 278 -#define __NR_memfd_create 279 -#define __NR_bpf 280 -#define __NR_execveat 281 -#define __NR_userfaultfd 282 -#define __NR_membarrier 283 -#define __NR_mlock2 284 -#define __NR_copy_file_range 285 -#define __NR_preadv2 286 -#define __NR_pwritev2 287 -#define __NR_pkey_mprotect 288 -#define __NR_pkey_alloc 289 -#define __NR_pkey_free 290 -#define __NR_statx 291 -#define __NR_io_pgetevents 292 -#define __NR_rseq 293 -#define __NR_kexec_file_load 294 -#define __NR_pidfd_send_signal 424 -#define __NR_io_uring_setup 425 -#define __NR_io_uring_enter 426 -#define __NR_io_uring_register 427 -#define __NR_open_tree 428 -#define __NR_move_mount 429 -#define __NR_fsopen 430 -#define __NR_fsconfig 431 -#define __NR_fsmount 432 -#define __NR_fspick 433 -#define __NR_pidfd_open 434 -#define __NR_clone3 435 -#define __NR_close_range 436 -#define __NR_openat2 437 -#define __NR_pidfd_getfd 438 -#define __NR_faccessat2 439 -#define __NR_process_madvise 440 -#define __NR_epoll_pwait2 441 -#define __NR_mount_setattr 442 -#define __NR_landlock_create_ruleset 444 -#define __NR_landlock_add_rule 445 -#define __NR_landlock_restrict_self 446 - diff --git a/usr/lib/libc/include/asm-aarch64/bits/user.h b/usr/lib/libc/include/asm-aarch64/bits/user.h deleted file mode 100644 index 8a1002aa6..000000000 --- a/usr/lib/libc/include/asm-aarch64/bits/user.h +++ /dev/null @@ -1,16 +0,0 @@ -struct user_regs_struct { - unsigned long long regs[31]; - unsigned long long sp; - unsigned long long pc; - unsigned long long pstate; -}; - -struct user_fpsimd_struct { - __uint128_t vregs[32]; - unsigned int fpsr; - unsigned int fpcr; -}; - -#define ELF_NREG 34 -typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NREG]; -typedef struct user_fpsimd_struct elf_fpregset_t; diff --git a/usr/lib/libc/include/asm-aarch64/crt_arch.h b/usr/lib/libc/include/asm-aarch64/crt_arch.h deleted file mode 100644 index b64fb3dd6..000000000 --- a/usr/lib/libc/include/asm-aarch64/crt_arch.h +++ /dev/null @@ -1,15 +0,0 @@ -__asm__( -".text \n" -".global " START "\n" -".type " START ",%function\n" -START ":\n" -" mov x29, #0\n" -" mov x30, #0\n" -" mov x0, sp\n" -".weak _DYNAMIC\n" -".hidden _DYNAMIC\n" -" adrp x1, _DYNAMIC\n" -" add x1, x1, #:lo12:_DYNAMIC\n" -" and sp, x0, #-16\n" -" b " START "_c\n" -); diff --git a/usr/lib/libc/include/asm-aarch64/fp_arch.h b/usr/lib/libc/include/asm-aarch64/fp_arch.h deleted file mode 100644 index f3d445b95..000000000 --- a/usr/lib/libc/include/asm-aarch64/fp_arch.h +++ /dev/null @@ -1,25 +0,0 @@ -#define fp_barrierf fp_barrierf -static inline float fp_barrierf(float x) -{ - __asm__ __volatile__ ("" : "+w"(x)); - return x; -} - -#define fp_barrier fp_barrier -static inline double fp_barrier(double x) -{ - __asm__ __volatile__ ("" : "+w"(x)); - return x; -} - -#define fp_force_evalf fp_force_evalf -static inline void fp_force_evalf(float x) -{ - __asm__ __volatile__ ("" : "+w"(x)); -} - -#define fp_force_eval fp_force_eval -static inline void fp_force_eval(double x) -{ - __asm__ __volatile__ ("" : "+w"(x)); -} diff --git a/usr/lib/libc/include/asm-aarch64/kstat.h b/usr/lib/libc/include/asm-aarch64/kstat.h deleted file mode 100644 index 92625f363..000000000 --- a/usr/lib/libc/include/asm-aarch64/kstat.h +++ /dev/null @@ -1,21 +0,0 @@ -struct kstat { - dev_t st_dev; - ino_t st_ino; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - unsigned long __pad; - off_t st_size; - blksize_t st_blksize; - int __pad2; - blkcnt_t st_blocks; - long st_atime_sec; - long st_atime_nsec; - long st_mtime_sec; - long st_mtime_nsec; - long st_ctime_sec; - long st_ctime_nsec; - unsigned __unused[2]; -}; diff --git a/usr/lib/libc/include/asm-aarch64/pthread_arch.h b/usr/lib/libc/include/asm-aarch64/pthread_arch.h deleted file mode 100644 index 3909616c3..000000000 --- a/usr/lib/libc/include/asm-aarch64/pthread_arch.h +++ /dev/null @@ -1,11 +0,0 @@ -static inline uintptr_t __get_tp() -{ - uintptr_t tp; - __asm__ ("mrs %0,tpidr_el0" : "=r"(tp)); - return tp; -} - -#define TLS_ABOVE_TP -#define GAP_ABOVE_TP 16 - -#define MC_PC pc diff --git a/usr/lib/libc/include/asm-aarch64/reloc.h b/usr/lib/libc/include/asm-aarch64/reloc.h deleted file mode 100644 index b1b68c725..000000000 --- a/usr/lib/libc/include/asm-aarch64/reloc.h +++ /dev/null @@ -1,24 +0,0 @@ -#if __BYTE_ORDER == __BIG_ENDIAN -#define ENDIAN_SUFFIX "_be" -#else -#define ENDIAN_SUFFIX "" -#endif - -#define LDSO_ARCH "aarch64" ENDIAN_SUFFIX - -#define NO_LEGACY_INITFINI - -#define TPOFF_K 0 - -#define REL_SYMBOLIC R_AARCH64_ABS64 -#define REL_GOT R_AARCH64_GLOB_DAT -#define REL_PLT R_AARCH64_JUMP_SLOT -#define REL_RELATIVE R_AARCH64_RELATIVE -#define REL_COPY R_AARCH64_COPY -#define REL_DTPMOD R_AARCH64_TLS_DTPMOD64 -#define REL_DTPOFF R_AARCH64_TLS_DTPREL64 -#define REL_TPOFF R_AARCH64_TLS_TPREL64 -#define REL_TLSDESC R_AARCH64_TLSDESC - -#define CRTJMP(pc,sp) __asm__ __volatile__( \ - "mov sp,%1 ; br %0" : : "r"(pc), "r"(sp) : "memory" ) diff --git a/usr/lib/libc/include/asm-aarch64/socket.h b/usr/lib/libc/include/asm-aarch64/socket.h deleted file mode 100644 index 6187f49b0..000000000 --- a/usr/lib/libc/include/asm-aarch64/socket.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _ASMARM_SOCKET_H -#define _ASMARM_SOCKET_H -#include -/* For setsockopt(2) */ -#define SOL_SOCKET 1 -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_SNDBUFFORCE 32 -#define SO_RCVBUFFORCE 33 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -/* To add :#define SO_REUSEPORT 15 */ -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 -/* Security levels - as per NRL IPv6 - don't actually do anything */ -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 -#define SO_BINDTODEVICE 25 -/* Socket filtering */ -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 -#define SO_PEERNAME 28 -#define SO_TIMESTAMP 29 -#define SCM_TIMESTAMP SO_TIMESTAMP -#define SO_ACCEPTCONN 30 -#define SO_PEERSEC 31 -#define SO_PASSSEC 34 -#endif /* _ASM_SOCKET_H */ diff --git a/usr/lib/libc/include/asm-aarch64/sockios.h b/usr/lib/libc/include/asm-aarch64/sockios.h deleted file mode 100644 index c238e77b1..000000000 --- a/usr/lib/libc/include/asm-aarch64/sockios.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __ARCH_ARM_SOCKIOS_H -#define __ARCH_ARM_SOCKIOS_H -/* Socket-level I/O control calls. */ -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -#define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 /* Get stamp */ - -#endif diff --git a/usr/lib/libc/include/asm-aarch64/syscall_arch.h b/usr/lib/libc/include/asm-aarch64/syscall_arch.h deleted file mode 100644 index 504983aa2..000000000 --- a/usr/lib/libc/include/asm-aarch64/syscall_arch.h +++ /dev/null @@ -1,78 +0,0 @@ -#define __SYSCALL_LL_E(x) (x) -#define __SYSCALL_LL_O(x) (x) - -#define __asm_syscall(...) do { \ - __asm__ __volatile__ ( "svc 0" \ - : "=r"(x0) : __VA_ARGS__ : "memory", "cc"); \ - return x0; \ - } while (0) - -static inline long __syscall0(long n) -{ - register long x8 __asm__("x8") = n; - register long x0 __asm__("x0"); - __asm_syscall("r"(x8)); -} - -static inline long __syscall1(long n, long a) -{ - register long x8 __asm__("x8") = n; - register long x0 __asm__("x0") = a; - __asm_syscall("r"(x8), "0"(x0)); -} - -static inline long __syscall2(long n, long a, long b) -{ - register long x8 __asm__("x8") = n; - register long x0 __asm__("x0") = a; - register long x1 __asm__("x1") = b; - __asm_syscall("r"(x8), "0"(x0), "r"(x1)); -} - -static inline long __syscall3(long n, long a, long b, long c) -{ - register long x8 __asm__("x8") = n; - register long x0 __asm__("x0") = a; - register long x1 __asm__("x1") = b; - register long x2 __asm__("x2") = c; - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2)); -} - -static inline long __syscall4(long n, long a, long b, long c, long d) -{ - register long x8 __asm__("x8") = n; - register long x0 __asm__("x0") = a; - register long x1 __asm__("x1") = b; - register long x2 __asm__("x2") = c; - register long x3 __asm__("x3") = d; - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3)); -} - -static inline long __syscall5(long n, long a, long b, long c, long d, long e) -{ - register long x8 __asm__("x8") = n; - register long x0 __asm__("x0") = a; - register long x1 __asm__("x1") = b; - register long x2 __asm__("x2") = c; - register long x3 __asm__("x3") = d; - register long x4 __asm__("x4") = e; - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)); -} - -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) -{ - register long x8 __asm__("x8") = n; - register long x0 __asm__("x0") = a; - register long x1 __asm__("x1") = b; - register long x2 __asm__("x2") = c; - register long x3 __asm__("x3") = d; - register long x4 __asm__("x4") = e; - register long x5 __asm__("x5") = f; - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)); -} - -#define VDSO_USEFUL -#define VDSO_CGT_SYM "__kernel_clock_gettime" -#define VDSO_CGT_VER "LINUX_2.6.39" - -#define IPC_64 0 diff --git a/usr/lib/libc/include/assert.h b/usr/lib/libc/include/assert.h deleted file mode 100644 index d14ec94e7..000000000 --- a/usr/lib/libc/include/assert.h +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#undef assert - -#ifdef NDEBUG -#define assert(x) (void)0 -#else -#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) -#endif - -#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus) -#define static_assert _Static_assert -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -_Noreturn void __assert_fail (const char *, const char *, int, const char *); - -#ifdef __cplusplus -} -#endif diff --git a/usr/lib/libc/include/atomic.h b/usr/lib/libc/include/atomic.h deleted file mode 100644 index 14c6025b4..000000000 --- a/usr/lib/libc/include/atomic.h +++ /dev/null @@ -1,293 +0,0 @@ -#ifndef _ATOMIC_H -#define _ATOMIC_H - -#include - -#include - -#ifdef a_ll - -#ifndef a_pre_llsc -#define a_pre_llsc() -#endif - -#ifndef a_post_llsc -#define a_post_llsc() -#endif - -#ifndef a_cas -#define a_cas a_cas -static inline int a_cas(volatile int *p, int t, int s) -{ - int old; - a_pre_llsc(); - do old = a_ll(p); - while (old==t && !a_sc(p, s)); - a_post_llsc(); - return old; -} -#endif - -#ifndef a_swap -#define a_swap a_swap -static inline int a_swap(volatile int *p, int v) -{ - int old; - a_pre_llsc(); - do old = a_ll(p); - while (!a_sc(p, v)); - a_post_llsc(); - return old; -} -#endif - -#ifndef a_fetch_add -#define a_fetch_add a_fetch_add -static inline int a_fetch_add(volatile int *p, int v) -{ - int old; - a_pre_llsc(); - do old = a_ll(p); - while (!a_sc(p, (unsigned)old + v)); - a_post_llsc(); - return old; -} -#endif - -#ifndef a_fetch_and -#define a_fetch_and a_fetch_and -static inline int a_fetch_and(volatile int *p, int v) -{ - int old; - a_pre_llsc(); - do old = a_ll(p); - while (!a_sc(p, old & v)); - a_post_llsc(); - return old; -} -#endif - -#ifndef a_fetch_or -#define a_fetch_or a_fetch_or -static inline int a_fetch_or(volatile int *p, int v) -{ - int old; - a_pre_llsc(); - do old = a_ll(p); - while (!a_sc(p, old | v)); - a_post_llsc(); - return old; -} -#endif - -#endif - -#ifdef a_ll_p - -#ifndef a_cas_p -#define a_cas_p a_cas_p -static inline void *a_cas_p(volatile void *p, void *t, void *s) -{ - void *old; - a_pre_llsc(); - do old = a_ll_p(p); - while (old==t && !a_sc_p(p, s)); - a_post_llsc(); - return old; -} -#endif - -#endif - -#ifndef a_cas -#error missing definition of a_cas -#endif - -#ifndef a_swap -#define a_swap a_swap -static inline int a_swap(volatile int *p, int v) -{ - int old; - do old = *p; - while (a_cas(p, old, v) != old); - return old; -} -#endif - -#ifndef a_fetch_add -#define a_fetch_add a_fetch_add -static inline int a_fetch_add(volatile int *p, int v) -{ - int old; - do old = *p; - while (a_cas(p, old, (unsigned)old+v) != old); - return old; -} -#endif - -#ifndef a_fetch_and -#define a_fetch_and a_fetch_and -static inline int a_fetch_and(volatile int *p, int v) -{ - int old; - do old = *p; - while (a_cas(p, old, old&v) != old); - return old; -} -#endif -#ifndef a_fetch_or -#define a_fetch_or a_fetch_or -static inline int a_fetch_or(volatile int *p, int v) -{ - int old; - do old = *p; - while (a_cas(p, old, old|v) != old); - return old; -} -#endif - -#ifndef a_and -#define a_and a_and -static inline void a_and(volatile int *p, int v) -{ - a_fetch_and(p, v); -} -#endif - -#ifndef a_or -#define a_or a_or -static inline void a_or(volatile int *p, int v) -{ - a_fetch_or(p, v); -} -#endif - -#ifndef a_inc -#define a_inc a_inc -static inline void a_inc(volatile int *p) -{ - a_fetch_add(p, 1); -} -#endif - -#ifndef a_dec -#define a_dec a_dec -static inline void a_dec(volatile int *p) -{ - a_fetch_add(p, -1); -} -#endif - -#ifndef a_store -#define a_store a_store -static inline void a_store(volatile int *p, int v) -{ -#ifdef a_barrier - a_barrier(); - *p = v; - a_barrier(); -#else - a_swap(p, v); -#endif -} -#endif - -#ifndef a_barrier -#define a_barrier a_barrier -static void a_barrier() -{ - volatile int tmp = 0; - a_cas(&tmp, 0, 0); -} -#endif - -#ifndef a_spin -#define a_spin a_barrier -#endif - -#ifndef a_and_64 -#define a_and_64 a_and_64 -static inline void a_and_64(volatile uint64_t *p, uint64_t v) -{ - union { uint64_t v; uint32_t r[2]; } u = { v }; - if (u.r[0]+1) a_and((int *)p, u.r[0]); - if (u.r[1]+1) a_and((int *)p+1, u.r[1]); -} -#endif - -#ifndef a_or_64 -#define a_or_64 a_or_64 -static inline void a_or_64(volatile uint64_t *p, uint64_t v) -{ - union { uint64_t v; uint32_t r[2]; } u = { v }; - if (u.r[0]) a_or((int *)p, u.r[0]); - if (u.r[1]) a_or((int *)p+1, u.r[1]); -} -#endif - -#ifndef a_cas_p -typedef char a_cas_p_undefined_but_pointer_not_32bit[-sizeof(char) == 0xffffffff ? 1 : -1]; -#define a_cas_p a_cas_p -static inline void *a_cas_p(volatile void *p, void *t, void *s) -{ - return (void *)a_cas((volatile int *)p, (int)t, (int)s); -} -#endif - -#ifndef a_or_l -#define a_or_l a_or_l -static inline void a_or_l(volatile void *p, long v) -{ - if (sizeof(long) == sizeof(int)) a_or(p, v); - else a_or_64(p, v); -} -#endif - -#ifndef a_crash -#define a_crash a_crash -static inline void a_crash() -{ - *(volatile char *)0=0; -} -#endif - -#ifndef a_ctz_64 -#define a_ctz_64 a_ctz_64 -static inline int a_ctz_64(uint64_t x) -{ - static const char debruijn64[64] = { - 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, - 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, - 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, - 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 - }; - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; - if (sizeof(long) < 8) { - uint32_t y = x; - if (!y) { - y = x>>32; - return 32 + debruijn32[(y&-y)*0x076be629 >> 27]; - } - return debruijn32[(y&-y)*0x076be629 >> 27]; - } - return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; -} -#endif - -#ifndef a_ctz_l -#define a_ctz_l a_ctz_l -static inline int a_ctz_l(unsigned long x) -{ - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; - if (sizeof(long) == 8) return a_ctz_64(x); - return debruijn32[(x&-x)*0x076be629 >> 27]; -} -#endif - -#endif diff --git a/usr/lib/libc/include/bits/alltypes.h b/usr/lib/libc/include/bits/alltypes.h deleted file mode 100644 index 19c7dfcb7..000000000 --- a/usr/lib/libc/include/bits/alltypes.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef ALLTYPES_H -#define ALLTYPES_H - -#define _Addr long -#define _Int64 long long -#define _Reg int - -typedef __builtin_va_list va_list; -typedef __builtin_va_list __isoc_va_list; - -typedef struct _IO_FILE FILE; - -typedef unsigned _Addr uintptr_t; -typedef _Addr intptr_t; - -typedef signed char int8_t; -typedef short int16_t; -typedef int int32_t; -typedef _Int64 int64_t; -typedef _Int64 intmax_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -typedef unsigned _Int64 uint64_t; -typedef unsigned _Int64 u_int64_t; -typedef unsigned _Int64 uintmax_t; - -typedef uint32_t mode_t; - -typedef unsigned _Int64 ino_t; - -typedef uint16_t u_short; - -typedef void *timer_t; -typedef int clockid_t; -typedef int pid_t; -typedef unsigned uid_t; -typedef unsigned gid_t; - -typedef long clock_t; -typedef uint64_t time_t; - -typedef uint64_t suseconds_t; -struct timeval { time_t tv_sec; suseconds_t tv_usec; }; -struct timespec { time_t tv_sec; time_t tv_nsec; }; - -#ifndef __cplusplus -typedef unsigned wchar_t; -#endif -typedef unsigned long size_t; -typedef long ssize_t; -typedef unsigned int locale_t; - -typedef unsigned int off_t; - -typedef float float_t; -typedef double double_t; - -typedef unsigned wint_t; -typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; -typedef unsigned long wctype_t; -typedef _Addr ptrdiff_t; - -typedef struct { long long __ll; long double __ld; } max_align_t; - -struct iovec { void *iov_base; size_t iov_len; }; - -typedef struct { union { int __i[9]; volatile int __vi[9]; unsigned __s[9]; } __u; } pthread_attr_t; -typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t; -typedef struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } mtx_t; -typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } pthread_cond_t; -typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } cnd_t; -typedef struct { union { int __i[8]; volatile int __vi[8]; void *__p[8]; } __u; } pthread_rwlock_t; -typedef struct { union { int __i[5]; volatile int __vi[5]; void *__p[5]; } __u; } pthread_barrier_t; - -typedef struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t; - -typedef uint32_t socklen_t; - - -#endif /* ALLTYPES_H */ diff --git a/usr/lib/libc/include/bits/byteswap.h b/usr/lib/libc/include/bits/byteswap.h deleted file mode 100644 index 01b383a90..000000000 --- a/usr/lib/libc/include/bits/byteswap.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef BITS_BYTESWAP_H -#define BITS_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 /* BITS_BYTESWAP_H */ diff --git a/usr/lib/libc/include/bits/endian.h b/usr/lib/libc/include/bits/endian.h deleted file mode 100644 index 5953724a0..000000000 --- a/usr/lib/libc/include/bits/endian.h +++ /dev/null @@ -1,5 +0,0 @@ -#if __ARMEB__ -#define __BYTE_ORDER __BIG_ENDIAN -#else -#define __BYTE_ORDER __LITTLE_ENDIAN -#endif diff --git a/usr/lib/libc/include/bits/fcntl.h b/usr/lib/libc/include/bits/fcntl.h deleted file mode 100644 index 4cb1753b7..000000000 --- a/usr/lib/libc/include/bits/fcntl.h +++ /dev/null @@ -1,40 +0,0 @@ -#define O_CREAT 0100 -#define O_EXCL 0200 -#define O_NOCTTY 0400 -#define O_TRUNC 01000 -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_DSYNC 010000 -#define O_SYNC 04010000 -#define O_RSYNC 04010000 -#define O_DIRECTORY 040000 -#define O_NOFOLLOW 0100000 -#define O_CLOEXEC 02000000 - -#define O_ASYNC 020000 -#define O_DIRECT 0200000 -#define O_LARGEFILE 0400000 -#define O_NOATIME 01000000 -#define O_PATH 010000000 -#define O_TMPFILE 020040000 -#define O_NDELAY O_NONBLOCK - -#define F_DUPFD 0 -#define F_GETFD 1 -#define F_SETFD 2 -#define F_GETFL 3 -#define F_SETFL 4 - -#define F_SETOWN 8 -#define F_GETOWN 9 -#define F_SETSIG 10 -#define F_GETSIG 11 - -#define F_GETLK 12 -#define F_SETLK 13 -#define F_SETLKW 14 - -#define F_SETOWN_EX 15 -#define F_GETOWN_EX 16 - -#define F_GETOWNER_UIDS 17 diff --git a/usr/lib/libc/include/bits/fenv.h b/usr/lib/libc/include/bits/fenv.h deleted file mode 100644 index d85fc86d7..000000000 --- a/usr/lib/libc/include/bits/fenv.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __ARM_PCS_VFP -#define FE_ALL_EXCEPT 0 -#define FE_TONEAREST 0 -#else -#define FE_INVALID 1 -#define FE_DIVBYZERO 2 -#define FE_OVERFLOW 4 -#define FE_UNDERFLOW 8 -#define FE_INEXACT 16 -#define FE_ALL_EXCEPT 31 -#define FE_TONEAREST 0 -#define FE_DOWNWARD 0x800000 -#define FE_UPWARD 0x400000 -#define FE_TOWARDZERO 0xc00000 -#endif - -typedef unsigned long fexcept_t; - -typedef struct { - unsigned long __cw; -} fenv_t; - -#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/usr/lib/libc/include/bits/float.h b/usr/lib/libc/include/bits/float.h deleted file mode 100644 index c4a655e7b..000000000 --- a/usr/lib/libc/include/bits/float.h +++ /dev/null @@ -1,16 +0,0 @@ -#define FLT_EVAL_METHOD 0 - -#define LDBL_TRUE_MIN 4.94065645841246544177e-324L -#define LDBL_MIN 2.22507385850720138309e-308L -#define LDBL_MAX 1.79769313486231570815e+308L -#define LDBL_EPSILON 2.22044604925031308085e-16L - -#define LDBL_MANT_DIG 53 -#define LDBL_MIN_EXP (-1021) -#define LDBL_MAX_EXP 1024 - -#define LDBL_DIG 15 -#define LDBL_MIN_10_EXP (-307) -#define LDBL_MAX_10_EXP 308 - -#define DECIMAL_DIG 17 diff --git a/usr/lib/libc/include/bits/hwcap.h b/usr/lib/libc/include/bits/hwcap.h deleted file mode 100644 index ac4edeac8..000000000 --- a/usr/lib/libc/include/bits/hwcap.h +++ /dev/null @@ -1,29 +0,0 @@ -#define HWCAP_SWP (1 << 0) -#define HWCAP_HALF (1 << 1) -#define HWCAP_THUMB (1 << 2) -#define HWCAP_26BIT (1 << 3) -#define HWCAP_FAST_MULT (1 << 4) -#define HWCAP_FPA (1 << 5) -#define HWCAP_VFP (1 << 6) -#define HWCAP_EDSP (1 << 7) -#define HWCAP_JAVA (1 << 8) -#define HWCAP_IWMMXT (1 << 9) -#define HWCAP_CRUNCH (1 << 10) -#define HWCAP_THUMBEE (1 << 11) -#define HWCAP_NEON (1 << 12) -#define HWCAP_VFPv3 (1 << 13) -#define HWCAP_VFPv3D16 (1 << 14) -#define HWCAP_TLS (1 << 15) -#define HWCAP_VFPv4 (1 << 16) -#define HWCAP_IDIVA (1 << 17) -#define HWCAP_IDIVT (1 << 18) -#define HWCAP_VFPD32 (1 << 19) -#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT) -#define HWCAP_LPAE (1 << 20) -#define HWCAP_EVTSTRM (1 << 21) - -#define HWCAP2_AES (1 << 0) -#define HWCAP2_PMULL (1 << 1) -#define HWCAP2_SHA1 (1 << 2) -#define HWCAP2_SHA2 (1 << 3) -#define HWCAP2_CRC32 (1 << 4) diff --git a/usr/lib/libc/include/bits/ioctl.h b/usr/lib/libc/include/bits/ioctl.h deleted file mode 100644 index 3dbb11ba1..000000000 --- a/usr/lib/libc/include/bits/ioctl.h +++ /dev/null @@ -1,210 +0,0 @@ - -#ifndef BITS_IOCTL_H -#define BITS_IOCTL_H - -#define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) -#define _IOC_NONE 0U -#define _IOC_WRITE 1U -#define _IOC_READ 2U - -#define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) -#define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) -#define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) -#define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) - -#define TCGETS 0x5401 -#define TCSETS 0x5402 -#define TCSETSW 0x5403 -#define TCSETSF 0x5404 -#define TCGETA 0x5405 -#define TCSETA 0x5406 -#define TCSETAW 0x5407 -#define TCSETAF 0x5408 -#define TCSBRK 0x5409 -#define TCXONC 0x540A -#define TCFLSH 0x540B -#define TIOCEXCL 0x540C -#define TIOCNXCL 0x540D -#define TIOCSCTTY 0x540E -#define TIOCGPGRP 0x540F -#define TIOCSPGRP 0x5410 -#define TIOCOUTQ 0x5411 -#define TIOCSTI 0x5412 -#define TIOCGWINSZ 0x5413 -#define TIOCSWINSZ 0x5414 -#define TIOCMGET 0x5415 -#define TIOCMBIS 0x5416 -#define TIOCMBIC 0x5417 -#define TIOCMSET 0x5418 -#define TIOCGSOFTCAR 0x5419 -#define TIOCSSOFTCAR 0x541A -#define FIONREAD 0x541B -#define TIOCINQ FIONREAD -#define TIOCLINUX 0x541C -#define TIOCCONS 0x541D -#define TIOCGSERIAL 0x541E -#define TIOCSSERIAL 0x541F -#define TIOCPKT 0x5420 -#define FIONBIO 0x5421 -#define TIOCNOTTY 0x5422 -#define TIOCSETD 0x5423 -#define TIOCGETD 0x5424 -#define TCSBRKP 0x5425 -#define TIOCSBRK 0x5427 -#define TIOCCBRK 0x5428 -#define TIOCGSID 0x5429 -#define TIOCGRS485 0x542E -#define TIOCSRS485 0x542F -#define TIOCGPTN 0x80045430 -#define TIOCSPTLCK 0x40045431 -#define TIOCGDEV 0x80045432 -#define TCGETX 0x5432 -#define TCSETX 0x5433 -#define TCSETXF 0x5434 -#define TCSETXW 0x5435 -#define TIOCSIG 0x40045436 -#define TIOCVHANGUP 0x5437 -#define TIOCGPKT 0x80045438 -#define TIOCGPTLCK 0x80045439 -#define TIOCGEXCL 0x80045440 - -#define FIONCLEX 0x5450 -#define FIOCLEX 0x5451 -#define FIOASYNC 0x5452 -#define TIOCSERCONFIG 0x5453 -#define TIOCSERGWILD 0x5454 -#define TIOCSERSWILD 0x5455 -#define TIOCGLCKTRMIOS 0x5456 -#define TIOCSLCKTRMIOS 0x5457 -#define TIOCSERGSTRUCT 0x5458 -#define TIOCSERGETLSR 0x5459 -#define TIOCSERGETMULTI 0x545A -#define TIOCSERSETMULTI 0x545B - -#define TIOCMIWAIT 0x545C -#define TIOCGICOUNT 0x545D -#define FIOQSIZE 0x5460 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 0x01 - -struct winsize { - unsigned short ws_row; - unsigned short ws_col; - unsigned short ws_xpixel; - unsigned short ws_ypixel; -}; - -#define TIOCM_LE 0x001 -#define TIOCM_DTR 0x002 -#define TIOCM_RTS 0x004 -#define TIOCM_ST 0x008 -#define TIOCM_SR 0x010 -#define TIOCM_CTS 0x020 -#define TIOCM_CAR 0x040 -#define TIOCM_RNG 0x080 -#define TIOCM_DSR 0x100 -#define TIOCM_CD TIOCM_CAR -#define TIOCM_RI TIOCM_RNG -#define TIOCM_OUT1 0x2000 -#define TIOCM_OUT2 0x4000 -#define TIOCM_LOOP 0x8000 - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 - -#define FIOSETOWN 0x8901 -#define SIOCSPGRP 0x8902 -#define FIOGETOWN 0x8903 -#define SIOCGPGRP 0x8904 -#define SIOCATMARK 0x8905 -#define SIOCGSTAMP 0x8906 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFNAME 0x8923 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 - -#include - -#endif /* BITS_IOCTL_H */ diff --git a/usr/lib/libc/include/bits/ioctl_fix.h b/usr/lib/libc/include/bits/ioctl_fix.h deleted file mode 100644 index 97f03d73e..000000000 --- a/usr/lib/libc/include/bits/ioctl_fix.h +++ /dev/null @@ -1,2 +0,0 @@ - -int ioctl(int fd, int req, ...); diff --git a/usr/lib/libc/include/bits/limits.h b/usr/lib/libc/include/bits/limits.h deleted file mode 100644 index fbc6d238d..000000000 --- a/usr/lib/libc/include/bits/limits.h +++ /dev/null @@ -1,7 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define LONG_BIT 32 -#endif - -#define LONG_MAX 0x7fffffffL -#define LLONG_MAX 0x7fffffffffffffffLL diff --git a/usr/lib/libc/include/bits/mman.h b/usr/lib/libc/include/bits/mman.h deleted file mode 100644 index 8b1378917..000000000 --- a/usr/lib/libc/include/bits/mman.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/usr/lib/libc/include/bits/posix.h b/usr/lib/libc/include/bits/posix.h deleted file mode 100644 index 30a38714f..000000000 --- a/usr/lib/libc/include/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_ILP32_OFFBIG 1 -#define _POSIX_V7_ILP32_OFFBIG 1 diff --git a/usr/lib/libc/include/bits/reg.h b/usr/lib/libc/include/bits/reg.h deleted file mode 100644 index 0c7bffca0..000000000 --- a/usr/lib/libc/include/bits/reg.h +++ /dev/null @@ -1,3 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 32 -/* FIXME */ diff --git a/usr/lib/libc/include/bits/setjmp.h b/usr/lib/libc/include/bits/setjmp.h deleted file mode 100644 index 55e3a95bb..000000000 --- a/usr/lib/libc/include/bits/setjmp.h +++ /dev/null @@ -1 +0,0 @@ -typedef unsigned long long __jmp_buf[32]; diff --git a/usr/lib/libc/include/bits/signal.h b/usr/lib/libc/include/bits/signal.h deleted file mode 100644 index 3c7898567..000000000 --- a/usr/lib/libc/include/bits/signal.h +++ /dev/null @@ -1,86 +0,0 @@ -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define MINSIGSTKSZ 2048 -#define SIGSTKSZ 8192 -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -typedef int greg_t, gregset_t[18]; -typedef struct sigcontext { - unsigned long trap_no, error_code, oldmask; - unsigned long arm_r0, arm_r1, arm_r2, arm_r3; - unsigned long arm_r4, arm_r5, arm_r6, arm_r7; - unsigned long arm_r8, arm_r9, arm_r10, arm_fp; - unsigned long arm_ip, arm_sp, arm_lr, arm_pc; - unsigned long arm_cpsr, fault_address; -} mcontext_t; -#else -typedef struct { - unsigned long __regs[21]; -} mcontext_t; -#endif - -struct sigaltstack { - void *ss_sp; - int ss_flags; - size_t ss_size; -}; - -typedef struct __ucontext { - unsigned long uc_flags; - struct __ucontext *uc_link; - stack_t uc_stack; - mcontext_t uc_mcontext; - sigset_t uc_sigmask; - unsigned long long uc_regspace[64]; -} ucontext_t; - -#define SA_NOCLDSTOP 1 -#define SA_NOCLDWAIT 2 -#define SA_SIGINFO 4 -#define SA_ONSTACK 0x08000000 -#define SA_RESTART 0x10000000 -#define SA_NODEFER 0x40000000 -#define SA_RESETHAND 0x80000000 -#define SA_RESTORER 0x04000000 - -#endif - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT SIGABRT -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL 29 -#define SIGPWR 30 -#define SIGSYS 31 -#define SIGUNUSED SIGSYS - -#define _NSIG 65 diff --git a/usr/lib/libc/include/bits/sockaddr.h b/usr/lib/libc/include/bits/sockaddr.h deleted file mode 100644 index 8b3e5ad6d..000000000 --- a/usr/lib/libc/include/bits/sockaddr.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Definition of struct sockaddr_* common members and sizes, generic version. - Copyright (C) 1995-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* - * Never include this file directly; use instead. - */ - -#ifndef _BITS_SOCKADDR_H -#define _BITS_SOCKADDR_H 1 - - -/* POSIX.1g specifies this type name for the `sa_family' member. */ -typedef unsigned short int sa_family_t; - -/* This macro is used to declare the initial common members - of the data types used for socket addresses, `struct sockaddr', - `struct sockaddr_in', `struct sockaddr_un', etc. */ - -#define __SOCKADDR_COMMON(sa_prefix) \ - sa_family_t sa_prefix##family - -#define __SOCKADDR_COMMON_SIZE (sizeof (unsigned short int)) - -/* Size of struct sockaddr_storage. */ -#define _SS_SIZE 128 - -#endif /* bits/sockaddr.h */ diff --git a/usr/lib/libc/include/bits/socket.h b/usr/lib/libc/include/bits/socket.h deleted file mode 100644 index ab094adfa..000000000 --- a/usr/lib/libc/include/bits/socket.h +++ /dev/null @@ -1,404 +0,0 @@ -/* System-specific socket constants and types. Linux version. - Copyright (C) 1991-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef __BITS_SOCKET_H -#define __BITS_SOCKET_H - -#ifndef _SYS_SOCKET_H -# error "Never include directly; use instead." -#endif - -#define __need_size_t -#include - -#include - -/* Get the architecture-dependent definition of enum __socket_type. */ -#include - -/* Protocol families. */ -#define PF_UNSPEC 0 /* Unspecified. */ -#define PF_LOCAL 1 /* Local to host (pipes and file-domain). */ -#define PF_UNIX PF_LOCAL /* POSIX name for PF_LOCAL. */ -#define PF_FILE PF_LOCAL /* Another non-standard name for PF_LOCAL. */ -#define PF_INET 2 /* IP protocol family. */ -#define PF_AX25 3 /* Amateur Radio AX.25. */ -#define PF_IPX 4 /* Novell Internet Protocol. */ -#define PF_APPLETALK 5 /* Appletalk DDP. */ -#define PF_NETROM 6 /* Amateur radio NetROM. */ -#define PF_BRIDGE 7 /* Multiprotocol bridge. */ -#define PF_ATMPVC 8 /* ATM PVCs. */ -#define PF_X25 9 /* Reserved for X.25 project. */ -#define PF_INET6 10 /* IP version 6. */ -#define PF_ROSE 11 /* Amateur Radio X.25 PLP. */ -#define PF_DECnet 12 /* Reserved for DECnet project. */ -#define PF_NETBEUI 13 /* Reserved for 802.2LLC project. */ -#define PF_SECURITY 14 /* Security callback pseudo AF. */ -#define PF_KEY 15 /* PF_KEY key management API. */ -#define PF_NETLINK 16 -#define PF_ROUTE PF_NETLINK /* Alias to emulate 4.4BSD. */ -#define PF_PACKET 17 /* Packet family. */ -#define PF_ASH 18 /* Ash. */ -#define PF_ECONET 19 /* Acorn Econet. */ -#define PF_ATMSVC 20 /* ATM SVCs. */ -#define PF_RDS 21 /* RDS sockets. */ -#define PF_SNA 22 /* Linux SNA Project */ -#define PF_IRDA 23 /* IRDA sockets. */ -#define PF_PPPOX 24 /* PPPoX sockets. */ -#define PF_WANPIPE 25 /* Wanpipe API sockets. */ -#define PF_LLC 26 /* Linux LLC. */ -#define PF_IB 27 /* Native InfiniBand address. */ -#define PF_MPLS 28 /* MPLS. */ -#define PF_CAN 29 /* Controller Area Network. */ -#define PF_TIPC 30 /* TIPC sockets. */ -#define PF_BLUETOOTH 31 /* Bluetooth sockets. */ -#define PF_IUCV 32 /* IUCV sockets. */ -#define PF_RXRPC 33 /* RxRPC sockets. */ -#define PF_ISDN 34 /* mISDN sockets. */ -#define PF_PHONET 35 /* Phonet sockets. */ -#define PF_IEEE802154 36 /* IEEE 802.15.4 sockets. */ -#define PF_CAIF 37 /* CAIF sockets. */ -#define PF_ALG 38 /* Algorithm sockets. */ -#define PF_NFC 39 /* NFC sockets. */ -#define PF_VSOCK 40 /* vSockets. */ -#define PF_KCM 41 /* Kernel Connection Multiplexor. */ -#define PF_QIPCRTR 42 /* Qualcomm IPC Router. */ -#define PF_MAX 43 /* For now.. */ - -/* Address families. */ -#define AF_UNSPEC PF_UNSPEC -#define AF_LOCAL PF_LOCAL -#define AF_UNIX PF_UNIX -#define AF_FILE PF_FILE -#define AF_INET PF_INET -#define AF_AX25 PF_AX25 -#define AF_IPX PF_IPX -#define AF_APPLETALK PF_APPLETALK -#define AF_NETROM PF_NETROM -#define AF_BRIDGE PF_BRIDGE -#define AF_ATMPVC PF_ATMPVC -#define AF_X25 PF_X25 -#define AF_INET6 PF_INET6 -#define AF_ROSE PF_ROSE -#define AF_DECnet PF_DECnet -#define AF_NETBEUI PF_NETBEUI -#define AF_SECURITY PF_SECURITY -#define AF_KEY PF_KEY -#define AF_NETLINK PF_NETLINK -#define AF_ROUTE PF_ROUTE -#define AF_PACKET PF_PACKET -#define AF_ASH PF_ASH -#define AF_ECONET PF_ECONET -#define AF_ATMSVC PF_ATMSVC -#define AF_RDS PF_RDS -#define AF_SNA PF_SNA -#define AF_IRDA PF_IRDA -#define AF_PPPOX PF_PPPOX -#define AF_WANPIPE PF_WANPIPE -#define AF_LLC PF_LLC -#define AF_IB PF_IB -#define AF_MPLS PF_MPLS -#define AF_CAN PF_CAN -#define AF_TIPC PF_TIPC -#define AF_BLUETOOTH PF_BLUETOOTH -#define AF_IUCV PF_IUCV -#define AF_RXRPC PF_RXRPC -#define AF_ISDN PF_ISDN -#define AF_PHONET PF_PHONET -#define AF_IEEE802154 PF_IEEE802154 -#define AF_CAIF PF_CAIF -#define AF_ALG PF_ALG -#define AF_NFC PF_NFC -#define AF_VSOCK PF_VSOCK -#define AF_KCM PF_KCM -#define AF_QIPCRTR PF_QIPCRTR -#define AF_MAX PF_MAX - -/* Socket level values. Others are defined in the appropriate headers. - - XXX These definitions also should go into the appropriate headers as - far as they are available. */ -#define SOL_RAW 255 -#define SOL_DECNET 261 -#define SOL_X25 262 -#define SOL_PACKET 263 -#define SOL_ATM 264 /* ATM layer (cell level). */ -#define SOL_AAL 265 /* ATM Adaption Layer (packet level). */ -#define SOL_IRDA 266 -#define SOL_NETBEUI 267 -#define SOL_LLC 268 -#define SOL_DCCP 269 -#define SOL_NETLINK 270 -#define SOL_TIPC 271 -#define SOL_RXRPC 272 -#define SOL_PPPOL2TP 273 -#define SOL_BLUETOOTH 274 -#define SOL_PNPIPE 275 -#define SOL_RDS 276 -#define SOL_IUCV 277 -#define SOL_CAIF 278 -#define SOL_ALG 279 -#define SOL_NFC 280 -#define SOL_KCM 281 - -/* Maximum queue length specifiable by listen. */ -#define SOMAXCONN 128 - -/* Get the definition of the macro to define the common sockaddr members. */ -#include - -/* Structure describing a generic socket address. */ -struct sockaddr -{ - __SOCKADDR_COMMON (sa_); /* Common data: address family and length. */ - char sa_data[14]; /* Address data. */ -}; - - -/* Structure large enough to hold any socket address (with the historical - exception of AF_UNIX). */ -#define __ss_aligntype unsigned long int -#define _SS_PADSIZE \ - (_SS_SIZE - __SOCKADDR_COMMON_SIZE - sizeof (__ss_aligntype)) - -/** TODO struct sockaddr_storage -{ - __SOCKADDR_COMMON (ss_); / Address family, etc. / - char __ss_padding[_SS_PADSIZE]; - __ss_aligntype __ss_align; / Force desired alignment. / -};*/ - - -/* Bits in the FLAGS argument to `send', `recv', et al. */ -enum -{ - MSG_OOB = 0x01, /* Process out-of-band data. */ -#define MSG_OOB MSG_OOB - MSG_PEEK = 0x02, /* Peek at incoming messages. */ -#define MSG_PEEK MSG_PEEK - MSG_DONTROUTE = 0x04, /* Don't use local routing. */ -#define MSG_DONTROUTE MSG_DONTROUTE -#ifdef __USE_GNU - /* DECnet uses a different name. */ - MSG_TRYHARD = MSG_DONTROUTE, -# define MSG_TRYHARD MSG_DONTROUTE -#endif - MSG_CTRUNC = 0x08, /* Control data lost before delivery. */ -#define MSG_CTRUNC MSG_CTRUNC - MSG_PROXY = 0x10, /* Supply or ask second address. */ -#define MSG_PROXY MSG_PROXY - MSG_TRUNC = 0x20, -#define MSG_TRUNC MSG_TRUNC - MSG_DONTWAIT = 0x40, /* Nonblocking IO. */ -#define MSG_DONTWAIT MSG_DONTWAIT - MSG_EOR = 0x80, /* End of record. */ -#define MSG_EOR MSG_EOR - MSG_WAITALL = 0x100, /* Wait for a full request. */ -#define MSG_WAITALL MSG_WAITALL - MSG_FIN = 0x200, -#define MSG_FIN MSG_FIN - MSG_SYN = 0x400, -#define MSG_SYN MSG_SYN - MSG_CONFIRM = 0x800, /* Confirm path validity. */ -#define MSG_CONFIRM MSG_CONFIRM - MSG_RST = 0x1000, -#define MSG_RST MSG_RST - MSG_ERRQUEUE = 0x2000, /* Fetch message from error queue. */ -#define MSG_ERRQUEUE MSG_ERRQUEUE - MSG_NOSIGNAL = 0x4000, /* Do not generate SIGPIPE. */ -#define MSG_NOSIGNAL MSG_NOSIGNAL - MSG_MORE = 0x8000, /* Sender will send more. */ -#define MSG_MORE MSG_MORE - MSG_WAITFORONE = 0x10000, /* Wait for at least one packet to return.*/ -#define MSG_WAITFORONE MSG_WAITFORONE - MSG_BATCH = 0x40000, /* sendmmsg: more messages coming. */ -#define MSG_BATCH MSG_BATCH - MSG_FASTOPEN = 0x20000000, /* Send data in TCP SYN. */ -#define MSG_FASTOPEN MSG_FASTOPEN - - MSG_CMSG_CLOEXEC = 0x40000000 /* Set close_on_exit for file - descriptor received through - SCM_RIGHTS. */ -#define MSG_CMSG_CLOEXEC MSG_CMSG_CLOEXEC -}; - - -/* Structure describing messages sent by - `sendmsg' and received by `recvmsg'. */ -struct msghdr -{ - void *msg_name; /* Address to send to/receive from. */ - socklen_t msg_namelen; /* Length of address data. */ - - struct iovec *msg_iov; /* Vector of data to send/receive into. */ - size_t msg_iovlen; /* Number of elements in the vector. */ - - void *msg_control; /* Ancillary data (eg BSD filedesc passing). */ - size_t msg_controllen; /* Ancillary data buffer length. - !! The type should be socklen_t but the - definition of the kernel is incompatible - with this. */ - - int msg_flags; /* Flags on received message. */ -}; - -/* Structure used for storage of ancillary data object information. */ -struct cmsghdr -{ - size_t cmsg_len; /* Length of data in cmsg_data plus length - of cmsghdr structure. - !! The type should be socklen_t but the - definition of the kernel is incompatible - with this. */ - int cmsg_level; /* Originating protocol. */ - int cmsg_type; /* Protocol specific type. */ -#if __glibc_c99_flexarr_available - __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data. */ -#endif -}; - -/* Ancillary data object manipulation macros. */ -#if __glibc_c99_flexarr_available -# define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data) -#else -# define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1)) -#endif -#define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg) -#define CMSG_FIRSTHDR(mhdr) \ - ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \ - ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) -#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)) - -extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr, - struct cmsghdr *__cmsg); -#ifdef __USE_EXTERN_INLINES -# ifndef _EXTERN_INLINE -# define _EXTERN_INLINE __extern_inline -# endif -_EXTERN_INLINE struct cmsghdr * -__NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg)) -{ - if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr)) - /* The kernel header does this so there may be a reason. */ - return (struct cmsghdr *) 0; - - __cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg - + CMSG_ALIGN (__cmsg->cmsg_len)); - if ((unsigned char *) (__cmsg + 1) > ((unsigned char *) __mhdr->msg_control - + __mhdr->msg_controllen) - || ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len) - > ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen))) - /* No more entries. */ - return (struct cmsghdr *) 0; - return __cmsg; -} -#endif /* Use `extern inline'. */ - -/* Socket level message types. This must match the definitions in - . */ -enum -{ - SCM_RIGHTS = 0x01 /* Transfer file descriptors. */ -#define SCM_RIGHTS SCM_RIGHTS -#ifdef __USE_GNU - , SCM_CREDENTIALS = 0x02 /* Credentials passing. */ -# define SCM_CREDENTIALS SCM_CREDENTIALS -#endif -}; - -#ifdef __USE_GNU -/* User visible structure for SCM_CREDENTIALS message */ -struct ucred -{ - pid_t pid; /* PID of sending process. */ - uid_t uid; /* UID of sending process. */ - gid_t gid; /* GID of sending process. */ -}; -#endif - -/* Ugly workaround for unclean kernel headers. */ -#ifndef __USE_MISC -# ifndef FIOGETOWN -# define __SYS_SOCKET_H_undef_FIOGETOWN -# endif -# ifndef FIOSETOWN -# define __SYS_SOCKET_H_undef_FIOSETOWN -# endif -# ifndef SIOCATMARK -# define __SYS_SOCKET_H_undef_SIOCATMARK -# endif -# ifndef SIOCGPGRP -# define __SYS_SOCKET_H_undef_SIOCGPGRP -# endif -# ifndef SIOCGSTAMP -# define __SYS_SOCKET_H_undef_SIOCGSTAMP -# endif -# ifndef SIOCGSTAMPNS -# define __SYS_SOCKET_H_undef_SIOCGSTAMPNS -# endif -# ifndef SIOCSPGRP -# define __SYS_SOCKET_H_undef_SIOCSPGRP -# endif -#endif - -/* Get socket manipulation related informations from kernel headers. */ -#include - -#ifndef __USE_MISC -# ifdef __SYS_SOCKET_H_undef_FIOGETOWN -# undef __SYS_SOCKET_H_undef_FIOGETOWN -# undef FIOGETOWN -# endif -# ifdef __SYS_SOCKET_H_undef_FIOSETOWN -# undef __SYS_SOCKET_H_undef_FIOSETOWN -# undef FIOSETOWN -# endif -# ifdef __SYS_SOCKET_H_undef_SIOCATMARK -# undef __SYS_SOCKET_H_undef_SIOCATMARK -# undef SIOCATMARK -# endif -# ifdef __SYS_SOCKET_H_undef_SIOCGPGRP -# undef __SYS_SOCKET_H_undef_SIOCGPGRP -# undef SIOCGPGRP -# endif -# ifdef __SYS_SOCKET_H_undef_SIOCGSTAMP -# undef __SYS_SOCKET_H_undef_SIOCGSTAMP -# undef SIOCGSTAMP -# endif -# ifdef __SYS_SOCKET_H_undef_SIOCGSTAMPNS -# undef __SYS_SOCKET_H_undef_SIOCGSTAMPNS -# undef SIOCGSTAMPNS -# endif -# ifdef __SYS_SOCKET_H_undef_SIOCSPGRP -# undef __SYS_SOCKET_H_undef_SIOCSPGRP -# undef SIOCSPGRP -# endif -#endif - -/* Structure used to manipulate the SO_LINGER option. */ -struct linger -{ - int l_onoff; /* Nonzero to linger on close. */ - int l_linger; /* Time to linger. */ -}; - -#endif /* bits/socket.h */ diff --git a/usr/lib/libc/include/bits/socket_type.h b/usr/lib/libc/include/bits/socket_type.h deleted file mode 100644 index fcb34bcc9..000000000 --- a/usr/lib/libc/include/bits/socket_type.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Define enum __socket_type for generic Linux. - Copyright (C) 1991-2017 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _SYS_SOCKET_H -# error "Never include directly; use instead." -#endif - -/* Types of sockets. */ -enum __socket_type -{ - SOCK_STREAM = 1, /* Sequenced, reliable, connection-based - byte streams. */ -#define SOCK_STREAM SOCK_STREAM - SOCK_DGRAM = 2, /* Connectionless, unreliable datagrams - of fixed maximum length. */ -#define SOCK_DGRAM SOCK_DGRAM - SOCK_RAW = 3, /* Raw protocol interface. */ -#define SOCK_RAW SOCK_RAW - SOCK_RDM = 4, /* Reliably-delivered messages. */ -#define SOCK_RDM SOCK_RDM - SOCK_SEQPACKET = 5, /* Sequenced, reliable, connection-based, - datagrams of fixed maximum length. */ -#define SOCK_SEQPACKET SOCK_SEQPACKET - SOCK_DCCP = 6, /* Datagram Congestion Control Protocol. */ -#define SOCK_DCCP SOCK_DCCP - SOCK_PACKET = 10, /* Linux specific way of getting packets - at the dev level. For writing rarp and - other similar things on the user level. */ -#define SOCK_PACKET SOCK_PACKET - - /* Flags to be ORed into the type parameter of socket and socketpair and - used for the flags parameter of paccept. */ - - SOCK_CLOEXEC = 02000000, /* Atomically set close-on-exec flag for the - new descriptor(s). */ -#define SOCK_CLOEXEC SOCK_CLOEXEC - SOCK_NONBLOCK = 00004000 /* Atomically mark descriptor(s) as - non-blocking. */ -#define SOCK_NONBLOCK SOCK_NONBLOCK -}; diff --git a/usr/lib/libc/include/bits/stat.h b/usr/lib/libc/include/bits/stat.h deleted file mode 100644 index c51665f50..000000000 --- a/usr/lib/libc/include/bits/stat.h +++ /dev/null @@ -1,32 +0,0 @@ -/* copied from kernel definition, but with padding replaced - * by the corresponding correctly-sized userspace types. */ - -#define FILENAME_SIZE 256 - -struct stat { - -#if 0 /* Not yet available */ -dev_t st_dev; - int __st_dev_padding; - long __st_ino_truncated; - mode_t st_mode; - nlink_t st_nlink; - uid_t st_uid; - gid_t st_gid; - dev_t st_rdev; - int __st_rdev_padding; - off_t st_size; - blksize_t st_blksize; - blkcnt_t st_blocks; - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - ino_t st_ino; -#endif /* 0 */ - - char st_name[FILENAME_SIZE]; /* Filename */ - unsigned long st_size; /* Size of file */ - time_t st_mtim; /* Time of last modification in sec*/ - unsigned char st_flags; /* Regular file flag (not supported on fat) */ - mode_t st_mode; /* Protection not used (not supported on fat) */ -}; diff --git a/usr/lib/libc/include/bits/stdint.h b/usr/lib/libc/include/bits/stdint.h deleted file mode 100644 index d1b271219..000000000 --- a/usr/lib/libc/include/bits/stdint.h +++ /dev/null @@ -1,20 +0,0 @@ -typedef int32_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef uint32_t uint_fast16_t; -typedef uint32_t uint_fast32_t; - -#define INT_FAST16_MIN INT32_MIN -#define INT_FAST32_MIN INT32_MIN - -#define INT_FAST16_MAX INT32_MAX -#define INT_FAST32_MAX INT32_MAX - -#define UINT_FAST16_MAX UINT32_MAX -#define UINT_FAST32_MAX UINT32_MAX - -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX -#define SIZE_MAX UINT32_MAX diff --git a/usr/lib/libc/include/bits/syscall.h.in b/usr/lib/libc/include/bits/syscall.h.in deleted file mode 100644 index 9b129b235..000000000 --- a/usr/lib/libc/include/bits/syscall.h.in +++ /dev/null @@ -1,359 +0,0 @@ -#define __NR_restart_syscall 0 -#define __NR_exit 1 -#define __NR_fork 2 -#define __NR_read 3 -#define __NR_write 4 -#define __NR_open 5 -#define __NR_close 6 -#define __NR_creat 8 -#define __NR_link 9 -#define __NR_unlink 10 -#define __NR_execve 11 -#define __NR_chdir 12 -#define __NR_mknod 14 -#define __NR_chmod 15 -#define __NR_lchown 16 -#define __NR_lseek 19 -#define __NR_getpid 20 -#define __NR_mount 21 -#define __NR_setuid 23 -#define __NR_getuid 24 -#define __NR_ptrace 26 -#define __NR_pause 29 -#define __NR_access 33 -#define __NR_nice 34 -#define __NR_sync 36 -#define __NR_kill 37 -#define __NR_rename 38 -#define __NR_mkdir 39 -#define __NR_rmdir 40 -#define __NR_dup 41 -#define __NR_pipe 42 -#define __NR_times 43 -#define __NR_brk 45 -#define __NR_setgid 46 -#define __NR_getgid 47 -#define __NR_geteuid 49 -#define __NR_getegid 50 -#define __NR_acct 51 -#define __NR_umount2 52 -#define __NR_ioctl 54 -#define __NR_fcntl 55 -#define __NR_setpgid 57 -#define __NR_umask 60 -#define __NR_chroot 61 -#define __NR_ustat 62 -#define __NR_dup2 63 -#define __NR_getppid 64 -#define __NR_getpgrp 65 -#define __NR_setsid 66 -#define __NR_sigaction 67 -#define __NR_setreuid 70 -#define __NR_setregid 71 -#define __NR_sigsuspend 72 -#define __NR_sigpending 73 -#define __NR_sethostname 74 -#define __NR_setrlimit 75 -#define __NR_getrusage 77 -#define __NR_gettimeofday 78 -#define __NR_settimeofday 79 -#define __NR_getgroups 80 -#define __NR_setgroups 81 -#define __NR_symlink 83 -#define __NR_readlink 85 -#define __NR_uselib 86 -#define __NR_swapon 87 -#define __NR_reboot 88 -#define __NR_munmap 91 -#define __NR_truncate 92 -#define __NR_ftruncate 93 -#define __NR_fchmod 94 -#define __NR_fchown 95 -#define __NR_getpriority 96 -#define __NR_setpriority 97 -#define __NR_statfs 99 -#define __NR_fstatfs 100 -#define __NR_syslog 103 -#define __NR_setitimer 104 -#define __NR_getitimer 105 -#define __NR_stat 106 -#define __NR_lstat 107 -#define __NR_fstat 108 -#define __NR_vhangup 111 -#define __NR_wait4 114 -#define __NR_swapoff 115 -#define __NR_sysinfo 116 -#define __NR_fsync 118 -#define __NR_sigreturn 119 -#define __NR_clone 120 -#define __NR_setdomainname 121 -#define __NR_uname 122 -#define __NR_adjtimex 124 -#define __NR_mprotect 125 -#define __NR_sigprocmask 126 -#define __NR_init_module 128 -#define __NR_delete_module 129 -#define __NR_quotactl 131 -#define __NR_getpgid 132 -#define __NR_fchdir 133 -#define __NR_bdflush 134 -#define __NR_sysfs 135 -#define __NR_personality 136 -#define __NR_setfsuid 138 -#define __NR_setfsgid 139 -#define __NR__llseek 140 -#define __NR_getdents 141 -#define __NR__newselect 142 -#define __NR_flock 143 -#define __NR_msync 144 -#define __NR_readv 145 -#define __NR_writev 146 -#define __NR_getsid 147 -#define __NR_fdatasync 148 -#define __NR__sysctl 149 -#define __NR_mlock 150 -#define __NR_munlock 151 -#define __NR_mlockall 152 -#define __NR_munlockall 153 -#define __NR_sched_setparam 154 -#define __NR_sched_getparam 155 -#define __NR_sched_setscheduler 156 -#define __NR_sched_getscheduler 157 -#define __NR_sched_yield 158 -#define __NR_sched_get_priority_max 159 -#define __NR_sched_get_priority_min 160 -#define __NR_sched_rr_get_interval 161 -#define __NR_nanosleep 162 -#define __NR_mremap 163 -#define __NR_setresuid 164 -#define __NR_getresuid 165 -#define __NR_poll 168 -#define __NR_nfsservctl 169 -#define __NR_setresgid 170 -#define __NR_getresgid 171 -#define __NR_prctl 172 -#define __NR_rt_sigreturn 173 -#define __NR_rt_sigaction 174 -#define __NR_rt_sigprocmask 175 -#define __NR_rt_sigpending 176 -#define __NR_rt_sigtimedwait 177 -#define __NR_rt_sigqueueinfo 178 -#define __NR_rt_sigsuspend 179 -#define __NR_pread64 180 -#define __NR_pwrite64 181 -#define __NR_chown 182 -#define __NR_getcwd 183 -#define __NR_capget 184 -#define __NR_capset 185 -#define __NR_sigaltstack 186 -#define __NR_sendfile 187 -#define __NR_vfork 190 -#define __NR_ugetrlimit 191 -#define __NR_mmap2 192 -#define __NR_truncate64 193 -#define __NR_ftruncate64 194 -#define __NR_stat64 195 -#define __NR_lstat64 196 -#define __NR_fstat64 197 -#define __NR_lchown32 198 -#define __NR_getuid32 199 -#define __NR_getgid32 200 -#define __NR_geteuid32 201 -#define __NR_getegid32 202 -#define __NR_setreuid32 203 -#define __NR_setregid32 204 -#define __NR_getgroups32 205 -#define __NR_setgroups32 206 -#define __NR_fchown32 207 -#define __NR_setresuid32 208 -#define __NR_getresuid32 209 -#define __NR_setresgid32 210 -#define __NR_getresgid32 211 -#define __NR_chown32 212 -#define __NR_setuid32 213 -#define __NR_setgid32 214 -#define __NR_setfsuid32 215 -#define __NR_setfsgid32 216 -#define __NR_getdents64 217 -#define __NR_pivot_root 218 -#define __NR_mincore 219 -#define __NR_madvise 220 -#define __NR_fcntl64 221 -#define __NR_gettid 224 -#define __NR_readahead 225 -#define __NR_setxattr 226 -#define __NR_lsetxattr 227 -#define __NR_fsetxattr 228 -#define __NR_getxattr 229 -#define __NR_lgetxattr 230 -#define __NR_fgetxattr 231 -#define __NR_listxattr 232 -#define __NR_llistxattr 233 -#define __NR_flistxattr 234 -#define __NR_removexattr 235 -#define __NR_lremovexattr 236 -#define __NR_fremovexattr 237 -#define __NR_tkill 238 -#define __NR_sendfile64 239 -#define __NR_futex 240 -#define __NR_sched_setaffinity 241 -#define __NR_sched_getaffinity 242 -#define __NR_io_setup 243 -#define __NR_io_destroy 244 -#define __NR_io_getevents 245 -#define __NR_io_submit 246 -#define __NR_io_cancel 247 -#define __NR_exit_group 248 -#define __NR_lookup_dcookie 249 -#define __NR_epoll_create 250 -#define __NR_epoll_ctl 251 -#define __NR_epoll_wait 252 -#define __NR_remap_file_pages 253 -#define __NR_set_tid_address 256 -#define __NR_timer_create 257 -#define __NR_timer_settime 258 -#define __NR_timer_gettime 259 -#define __NR_timer_getoverrun 260 -#define __NR_timer_delete 261 -#define __NR_clock_settime 262 -#define __NR_clock_gettime 263 -#define __NR_clock_getres 264 -#define __NR_clock_nanosleep 265 -#define __NR_statfs64 266 -#define __NR_fstatfs64 267 -#define __NR_tgkill 268 -#define __NR_utimes 269 -#define __NR_fadvise64_64 270 -#define __NR_pciconfig_iobase 271 -#define __NR_pciconfig_read 272 -#define __NR_pciconfig_write 273 -#define __NR_mq_open 274 -#define __NR_mq_unlink 275 -#define __NR_mq_timedsend 276 -#define __NR_mq_timedreceive 277 -#define __NR_mq_notify 278 -#define __NR_mq_getsetattr 279 -#define __NR_waitid 280 -#define __NR_socket 281 -#define __NR_bind 282 -#define __NR_connect 283 -#define __NR_listen 284 -#define __NR_accept 285 -#define __NR_getsockname 286 -#define __NR_getpeername 287 -#define __NR_socketpair 288 -#define __NR_send 289 -#define __NR_sendto 290 -#define __NR_recv 291 -#define __NR_recvfrom 292 -#define __NR_shutdown 293 -#define __NR_setsockopt 294 -#define __NR_getsockopt 295 -#define __NR_sendmsg 296 -#define __NR_recvmsg 297 -#define __NR_semop 298 -#define __NR_semget 299 -#define __NR_semctl 300 -#define __NR_msgsnd 301 -#define __NR_msgrcv 302 -#define __NR_msgget 303 -#define __NR_msgctl 304 -#define __NR_shmat 305 -#define __NR_shmdt 306 -#define __NR_shmget 307 -#define __NR_shmctl 308 -#define __NR_add_key 309 -#define __NR_request_key 310 -#define __NR_keyctl 311 -#define __NR_semtimedop 312 -#define __NR_vserver 313 -#define __NR_ioprio_set 314 -#define __NR_ioprio_get 315 -#define __NR_inotify_init 316 -#define __NR_inotify_add_watch 317 -#define __NR_inotify_rm_watch 318 -#define __NR_mbind 319 -#define __NR_get_mempolicy 320 -#define __NR_set_mempolicy 321 -#define __NR_openat 322 -#define __NR_mkdirat 323 -#define __NR_mknodat 324 -#define __NR_fchownat 325 -#define __NR_futimesat 326 -#define __NR_fstatat64 327 -#define __NR_unlinkat 328 -#define __NR_renameat 329 -#define __NR_linkat 330 -#define __NR_symlinkat 331 -#define __NR_readlinkat 332 -#define __NR_fchmodat 333 -#define __NR_faccessat 334 -#define __NR_pselect6 335 -#define __NR_ppoll 336 -#define __NR_unshare 337 -#define __NR_set_robust_list 338 -#define __NR_get_robust_list 339 -#define __NR_splice 340 -#define __NR_sync_file_range2 341 -#define __NR_tee 342 -#define __NR_vmsplice 343 -#define __NR_move_pages 344 -#define __NR_getcpu 345 -#define __NR_epoll_pwait 346 -#define __NR_kexec_load 347 -#define __NR_utimensat 348 -#define __NR_signalfd 349 -#define __NR_timerfd_create 350 -#define __NR_eventfd 351 -#define __NR_fallocate 352 -#define __NR_timerfd_settime 353 -#define __NR_timerfd_gettime 354 -#define __NR_signalfd4 355 -#define __NR_eventfd2 356 -#define __NR_epoll_create1 357 -#define __NR_dup3 358 -#define __NR_pipe2 359 -#define __NR_inotify_init1 360 -#define __NR_preadv 361 -#define __NR_pwritev 362 -#define __NR_rt_tgsigqueueinfo 363 -#define __NR_perf_event_open 364 -#define __NR_recvmmsg 365 -#define __NR_accept4 366 -#define __NR_fanotify_init 367 -#define __NR_fanotify_mark 368 -#define __NR_prlimit64 369 -#define __NR_name_to_handle_at 370 -#define __NR_open_by_handle_at 371 -#define __NR_clock_adjtime 372 -#define __NR_syncfs 373 -#define __NR_sendmmsg 374 -#define __NR_setns 375 -#define __NR_process_vm_readv 376 -#define __NR_process_vm_writev 377 -#define __NR_kcmp 378 -#define __NR_finit_module 379 -#define __NR_sched_setattr 380 -#define __NR_sched_getattr 381 -#define __NR_renameat2 382 -#define __NR_seccomp 383 -#define __NR_getrandom 384 -#define __NR_memfd_create 385 -#define __NR_bpf 386 -#define __NR_execveat 387 -#define __NR_userfaultfd 388 -#define __NR_membarrier 389 -#define __NR_mlock2 390 -#define __NR_copy_file_range 391 -#define __NR_preadv2 392 -#define __NR_pwritev2 393 -#define __NR_pkey_mprotect 394 -#define __NR_pkey_alloc 395 -#define __NR_pkey_free 396 - -#define __ARM_NR_breakpoint 0x0f0001 -#define __ARM_NR_cacheflush 0x0f0002 -#define __ARM_NR_usr26 0x0f0003 -#define __ARM_NR_usr32 0x0f0004 -#define __ARM_NR_set_tls 0x0f0005 - diff --git a/usr/lib/libc/include/bits/user.h b/usr/lib/libc/include/bits/user.h deleted file mode 100644 index 3e5a4d21d..000000000 --- a/usr/lib/libc/include/bits/user.h +++ /dev/null @@ -1,36 +0,0 @@ -typedef struct user_fpregs { - struct fp_reg { - unsigned sign1:1; - unsigned unused:15; - unsigned sign2:1; - unsigned exponent:14; - unsigned j:1; - unsigned mantissa1:31; - unsigned mantissa0:32; - } fpregs[8]; - unsigned fpsr:32; - unsigned fpcr:32; - unsigned char ftype[8]; - unsigned int init_flag; -} elf_fpregset_t; - -struct user_regs { - unsigned long uregs[18]; -}; -#define ELF_NGREG 18 -typedef unsigned long elf_greg_t, elf_gregset_t[ELF_NGREG]; - -struct user { - struct user_regs regs; - int u_fpvalid; - unsigned long u_tsize, u_dsize, u_ssize; - unsigned long start_code, start_stack; - long signal; - int reserved; - struct user_regs *u_ar0; - unsigned long magic; - char u_comm[32]; - int u_debugreg[8]; - struct user_fpregs u_fp; - struct user_fpregs *u_fp0; -}; diff --git a/usr/lib/libc/include/byteswap.h b/usr/lib/libc/include/byteswap.h deleted file mode 100644 index 7696979d1..000000000 --- a/usr/lib/libc/include/byteswap.h +++ /dev/null @@ -1,27 +0,0 @@ -#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 - diff --git a/usr/lib/libc/include/complex.h b/usr/lib/libc/include/complex.h deleted file mode 100644 index 008b3c7e3..000000000 --- a/usr/lib/libc/include/complex.h +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef _COMPLEX_H -#define _COMPLEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define complex _Complex -#ifdef __GNUC__ -#define _Complex_I (__extension__ (0.0f+1.0fi)) -#else -#define _Complex_I (0.0f+1.0fi) -#endif -#define I _Complex_I - -double complex cacos(double complex); -float complex cacosf(float complex); -long double complex cacosl(long double complex); - -double complex casin(double complex); -float complex casinf(float complex); -long double complex casinl(long double complex); - -double complex catan(double complex); -float complex catanf(float complex); -long double complex catanl(long double complex); - -double complex ccos(double complex); -float complex ccosf(float complex); -long double complex ccosl(long double complex); - -double complex csin(double complex); -float complex csinf(float complex); -long double complex csinl(long double complex); - -double complex ctan(double complex); -float complex ctanf(float complex); -long double complex ctanl(long double complex); - -double complex cacosh(double complex); -float complex cacoshf(float complex); -long double complex cacoshl(long double complex); - -double complex casinh(double complex); -float complex casinhf(float complex); -long double complex casinhl(long double complex); - -double complex catanh(double complex); -float complex catanhf(float complex); -long double complex catanhl(long double complex); - -double complex ccosh(double complex); -float complex ccoshf(float complex); -long double complex ccoshl(long double complex); - -double complex csinh(double complex); -float complex csinhf(float complex); -long double complex csinhl(long double complex); - -double complex ctanh(double complex); -float complex ctanhf(float complex); -long double complex ctanhl(long double complex); - -double complex cexp(double complex); -float complex cexpf(float complex); -long double complex cexpl(long double complex); - -double complex clog(double complex); -float complex clogf(float complex); -long double complex clogl(long double complex); - -double cabs(double complex); -float cabsf(float complex); -long double cabsl(long double complex); - -double complex cpow(double complex, double complex); -float complex cpowf(float complex, float complex); -long double complex cpowl(long double complex, long double complex); - -double complex csqrt(double complex); -float complex csqrtf(float complex); -long double complex csqrtl(long double complex); - -double carg(double complex); -float cargf(float complex); -long double cargl(long double complex); - -double cimag(double complex); -float cimagf(float complex); -long double cimagl(long double complex); - -double complex conj(double complex); -float complex conjf(float complex); -long double complex conjl(long double complex); - -double complex cproj(double complex); -float complex cprojf(float complex); -long double complex cprojl(long double complex); - -double creal(double complex); -float crealf(float complex); -long double creall(long double complex); - -#ifndef __cplusplus -#define __CIMAG(x, t) \ - (+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) - -#define creal(x) ((double)(x)) -#define crealf(x) ((float)(x)) -#define creall(x) ((long double)(x)) - -#define cimag(x) __CIMAG(x, double) -#define cimagf(x) __CIMAG(x, float) -#define cimagl(x) __CIMAG(x, long double) -#endif - -#if __STDC_VERSION__ >= 201112L -#if defined(_Imaginary_I) -#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)) -#elif defined(__clang__) -#define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) }) -#else -#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y))) -#endif -#define CMPLX(x, y) __CMPLX(x, y, double) -#define CMPLXF(x, y) __CMPLX(x, y, float) -#define CMPLXL(x, y) __CMPLX(x, y, long double) -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/ctype.h b/usr/lib/libc/include/ctype.h deleted file mode 100644 index 7936536f5..000000000 --- a/usr/lib/libc/include/ctype.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef _CTYPE_H -#define _CTYPE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -int isalnum(int); -int isalpha(int); -int isblank(int); -int iscntrl(int); -int isdigit(int); -int isgraph(int); -int islower(int); -int isprint(int); -int ispunct(int); -int isspace(int); -int isupper(int); -int isxdigit(int); -int tolower(int); -int toupper(int); - -#ifndef __cplusplus -static __inline int __isspace(int _c) -{ - return _c == ' ' || (unsigned)_c-'\t' < 5; -} - -#define isalpha(a) (0 ? isalpha(a) : (((unsigned)(a)|32)-'a') < 26) -#define isdigit(a) (0 ? isdigit(a) : ((unsigned)(a)-'0') < 10) -#define islower(a) (0 ? islower(a) : ((unsigned)(a)-'a') < 26) -#define isupper(a) (0 ? isupper(a) : ((unsigned)(a)-'A') < 26) -#define isprint(a) (0 ? isprint(a) : ((unsigned)(a)-0x20) < 0x5f) -#define isgraph(a) (0 ? isgraph(a) : ((unsigned)(a)-0x21) < 0x5e) -#define isspace(a) __isspace(a) -#endif - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#define __NEED_locale_t -#include - -int isalnum_l(int, locale_t); -int isalpha_l(int, locale_t); -int isblank_l(int, locale_t); -int iscntrl_l(int, locale_t); -int isdigit_l(int, locale_t); -int isgraph_l(int, locale_t); -int islower_l(int, locale_t); -int isprint_l(int, locale_t); -int ispunct_l(int, locale_t); -int isspace_l(int, locale_t); -int isupper_l(int, locale_t); -int isxdigit_l(int, locale_t); -int tolower_l(int, locale_t); -int toupper_l(int, locale_t); - -int isascii(int); -int toascii(int); -#define _tolower(a) ((a)|0x20) -#define _toupper(a) ((a)&0x5f) -#define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128) - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/dirent.h b/usr/lib/libc/include/dirent.h deleted file mode 100644 index 88d3c3cfd..000000000 --- a/usr/lib/libc/include/dirent.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef _DIRENT_H -#define _DIRENT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_ino_t -#define __NEED_off_t -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define __NEED_size_t -#endif - -#include - -typedef struct __dirstream DIR; - -struct dirent { - ino_t d_ino; - off_t d_off; - unsigned short d_reclen; - unsigned char d_type; - char d_name[256]; -}; - -#define d_fileno d_ino - -int closedir(DIR *); -DIR *fdopendir(int); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict); -void rewinddir(DIR *); -int dirfd(DIR *); - -int alphasort(const struct dirent **, const struct dirent **); -int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -void seekdir(DIR *, long); -long telldir(DIR *); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 -#define DT_DIR 4 -#define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 -#define IFTODT(x) ((x)>>12 & 017) -#define DTTOIF(x) ((x)<<12) -int getdents(int, struct dirent *, size_t); -#endif - -#ifdef _GNU_SOURCE -int versionsort(const struct dirent **, const struct dirent **); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define dirent64 dirent -#define readdir64 readdir -#define readdir64_r readdir_r -#define scandir64 scandir -#define alphasort64 alphasort -#define versionsort64 versionsort -#define off64_t off_t -#define ino64_t ino_t -#define getdents64 getdents -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/dlfcn.h b/usr/lib/libc/include/dlfcn.h deleted file mode 100644 index 13ab71dd0..000000000 --- a/usr/lib/libc/include/dlfcn.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _DLFCN_H -#define _DLFCN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define RTLD_LAZY 1 -#define RTLD_NOW 2 -#define RTLD_NOLOAD 4 -#define RTLD_NODELETE 4096 -#define RTLD_GLOBAL 256 -#define RTLD_LOCAL 0 - -#define RTLD_NEXT ((void *)-1) -#define RTLD_DEFAULT ((void *)0) - -#define RTLD_DI_LINKMAP 2 - -int dlclose(void *); -char *dlerror(void); -void *dlopen(const char *, int); -void *dlsym(void *__restrict, const char *__restrict); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -typedef struct { - const char *dli_fname; - void *dli_fbase; - const char *dli_sname; - void *dli_saddr; -} Dl_info; -int dladdr(const void *, Dl_info *); -int dlinfo(void *, int, void *); -#endif - -#if _REDIR_TIME64 -__REDIR(dlsym, __dlsym_time64); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/endian.h b/usr/lib/libc/include/endian.h deleted file mode 100644 index b53a6d56e..000000000 --- a/usr/lib/libc/include/endian.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef _ENDIAN_H -#define _ENDIAN_H - -#include - -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 - -#if defined(__GNUC__) && defined(__BYTE_ORDER__) -#define __BYTE_ORDER __BYTE_ORDER__ -#else -#include -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define BIG_ENDIAN __BIG_ENDIAN -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define PDP_ENDIAN __PDP_ENDIAN -#define BYTE_ORDER __BYTE_ORDER - -#include - -static __inline uint16_t __bswap16(uint16_t __x) -{ - return __x<<8 | __x>>8; -} - -static __inline uint32_t __bswap32(uint32_t __x) -{ - return (__x>>24) | (__x>>8&0xff00) | (__x<<8&0xff0000) | (__x<<24); -} - -static __inline uint64_t __bswap64(uint64_t __x) -{ - return (__bswap32(__x)+(0ULL<<32)) | (__bswap32(__x>>32)); -} - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define htobe16(x) __bswap16(x) -#define be16toh(x) __bswap16(x) -#define betoh16(x) __bswap16(x) -#define htobe32(x) __bswap32(x) -#define be32toh(x) __bswap32(x) -#define betoh32(x) __bswap32(x) -#define htobe64(x) __bswap64(x) -#define be64toh(x) __bswap64(x) -#define betoh64(x) __bswap64(x) -#define htole16(x) (uint16_t)(x) -#define le16toh(x) (uint16_t)(x) -#define letoh16(x) (uint16_t)(x) -#define htole32(x) (uint32_t)(x) -#define le32toh(x) (uint32_t)(x) -#define letoh32(x) (uint32_t)(x) -#define htole64(x) (uint64_t)(x) -#define le64toh(x) (uint64_t)(x) -#define letoh64(x) (uint64_t)(x) -#else -#define htobe16(x) (uint16_t)(x) -#define be16toh(x) (uint16_t)(x) -#define betoh16(x) (uint16_t)(x) -#define htobe32(x) (uint32_t)(x) -#define be32toh(x) (uint32_t)(x) -#define betoh32(x) (uint32_t)(x) -#define htobe64(x) (uint64_t)(x) -#define be64toh(x) (uint64_t)(x) -#define betoh64(x) (uint64_t)(x) -#define htole16(x) __bswap16(x) -#define le16toh(x) __bswap16(x) -#define letoh16(x) __bswap16(x) -#define htole32(x) __bswap32(x) -#define le32toh(x) __bswap32(x) -#define letoh32(x) __bswap32(x) -#define htole64(x) __bswap64(x) -#define le64toh(x) __bswap64(x) -#define letoh64(x) __bswap64(x) -#endif - -#endif - -#endif diff --git a/usr/lib/libc/include/errno.h b/usr/lib/libc/include/errno.h deleted file mode 100644 index bf88e0993..000000000 --- a/usr/lib/libc/include/errno.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * errno.h - * - * Created on: 22 août 2008 - * Author: drossier - */ - -#ifndef ERRNO_H_ -#define ERRNO_H_ - - -#define EPERM 1 /* Operation not permitted */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* I/O error */ -#define ENXIO 6 /* No such device or address */ -#define E2BIG 7 /* Argument list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file number */ -#define ECHILD 10 /* No child processes */ -#define EAGAIN 11 /* Try again */ -#define ENOMEM 12 /* Out of memory */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ENOTBLK 15 /* Block device required */ -#define EBUSY 16 /* Device or resource busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* No such device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* File table overflow */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Not a typewriter */ -#define ETXTBSY 26 /* Text file busy */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ -#define EDOM 33 /* Math argument out of domain of func */ -#define ERANGE 34 /* Math result not representable */ - -#define EDEADLK 35 /* Resource deadlock would occur */ -#define ENAMETOOLONG 36 /* File name too long */ -#define ENOLCK 37 /* No record locks available */ -#define ENOSYS 38 /* Function not implemented */ -#define ENOTEMPTY 39 /* Directory not empty */ -#define ELOOP 40 /* Too many symbolic links encountered */ -#define EWOULDBLOCK EAGAIN /* Operation would block */ -#define ENOMSG 42 /* No message of desired type */ -#define EIDRM 43 /* Identifier removed */ -#define ECHRNG 44 /* Channel number out of range */ -#define EL2NSYNC 45 /* Level 2 not synchronized */ -#define EL3HLT 46 /* Level 3 halted */ -#define EL3RST 47 /* Level 3 reset */ -#define ELNRNG 48 /* Link number out of range */ -#define EUNATCH 49 /* Protocol driver not attached */ -#define ENOCSI 50 /* No CSI structure available */ -#define EL2HLT 51 /* Level 2 halted */ -#define EBADE 52 /* Invalid exchange */ -#define EBADR 53 /* Invalid request descriptor */ -#define EXFULL 54 /* Exchange full */ -#define ENOANO 55 /* No anode */ -#define EBADRQC 56 /* Invalid request code */ -#define EBADSLT 57 /* Invalid slot */ - -#define EDEADLOCK EDEADLK - -#define EBFONT 59 /* Bad font file format */ -#define ENOSTR 60 /* Device not a stream */ -#define ENODATA 61 /* No data available */ -#define ETIME 62 /* Timer expired */ -#define ENOSR 63 /* Out of streams resources */ -#define ENONET 64 /* Machine is not on the network */ -#define ENOPKG 65 /* Package not installed */ -#define EREMOTE 66 /* Object is remote */ -#define ENOLINK 67 /* Link has been severed */ -#define EADV 68 /* Advertise error */ -#define ESRMNT 69 /* Srmount error */ -#define ECOMM 70 /* Communication error on send */ -#define EPROTO 71 /* Protocol error */ -#define EMULTIHOP 72 /* Multihop attempted */ -#define EDOTDOT 73 /* RFS specific error */ -#define EBADMSG 74 /* Not a data message */ -#define EOVERFLOW 75 /* Value too large for defined data type */ -#define ENOTUNIQ 76 /* Name not unique on network */ -#define EBADFD 77 /* File descriptor in bad state */ -#define EREMCHG 78 /* Remote address changed */ -#define ELIBACC 79 /* Can not access a needed shared library */ -#define ELIBBAD 80 /* Accessing a corrupted shared library */ -#define ELIBSCN 81 /* .lib section in a.out corrupted */ -#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ -#define ELIBEXEC 83 /* Cannot exec a shared library directly */ -#define EILSEQ 84 /* Illegal byte sequence */ -#define ERESTART 85 /* Interrupted system call should be restarted */ -#define ESTRPIPE 86 /* Streams pipe error */ -#define EUSERS 87 /* Too many users */ -#define ENOTSOCK 88 /* Socket operation on non-socket */ -#define EDESTADDRREQ 89 /* Destination address required */ -#define EMSGSIZE 90 /* Message too long */ -#define EPROTOTYPE 91 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 92 /* Protocol not available */ -#define EPROTONOSUPPORT 93 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ -#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ -#define ENOTSUP EOPNOTSUPP -#define EPFNOSUPPORT 96 /* Protocol family not supported */ -#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ -#define EADDRINUSE 98 /* Address already in use */ -#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ -#define ENETDOWN 100 /* Network is down */ -#define ENETUNREACH 101 /* Network is unreachable */ -#define ENETRESET 102 /* Network dropped connection because of reset */ -#define ECONNABORTED 103 /* Software caused connection abort */ -#define ECONNRESET 104 /* Connection reset by peer */ -#define ENOBUFS 105 /* No buffer space available */ -#define EISCONN 106 /* Transport endpoint is already connected */ -#define ENOTCONN 107 /* Transport endpoint is not connected */ -#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ -#define ETOOMANYREFS 109 /* Too many references: cannot splice */ -#define ETIMEDOUT 110 /* Connection timed out */ -#define ECONNREFUSED 111 /* Connection refused */ -#define EHOSTDOWN 112 /* Host is down */ -#define EHOSTUNREACH 113 /* No route to host */ -#define EALREADY 114 /* Operation already in progress */ -#define EINPROGRESS 115 /* Operation now in progress */ -#define ESTALE 116 /* Stale NFS file handle */ -#define EUCLEAN 117 /* Structure needs cleaning */ -#define ENOTNAM 118 /* Not a XENIX named type file */ -#define ENAVAIL 119 /* No XENIX semaphores available */ -#define EISNAM 120 /* Is a named type file */ -#define EREMOTEIO 121 /* Remote I/O error */ -#define EDQUOT 122 /* Quota exceeded */ - -#define ENOMEDIUM 123 /* No medium found */ -#define EMEDIUMTYPE 124 /* Wrong medium type */ -#define ECANCELED 125 /* Operation Canceled */ -#define ENOKEY 126 /* Required key not available */ -#define EKEYEXPIRED 127 /* Key has expired */ -#define EKEYREVOKED 128 /* Key has been revoked */ -#define EKEYREJECTED 129 /* Key was rejected by service */ - -/* for robust mutexes */ -#define EOWNERDEAD 130 /* Owner died */ -#define ENOTRECOVERABLE 131 /* State not recoverable */ - -extern int errno; - -#endif /* ERRNO_H_ */ diff --git a/usr/lib/libc/include/fcntl.h b/usr/lib/libc/include/fcntl.h deleted file mode 100644 index 8ae15d755..000000000 --- a/usr/lib/libc/include/fcntl.h +++ /dev/null @@ -1,188 +0,0 @@ -#ifndef _FCNTL_H -#define _FCNTL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_mode_t - -#ifdef _GNU_SOURCE -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_struct_iovec -#endif - -#include - -#include -#include - -struct flock { - short l_type; - short l_whence; - off_t l_start; - off_t l_len; - pid_t l_pid; -}; - -int creat(const char *, mode_t); -int fcntl(int, int, ...); -int open(const char *, int, ...); -int openat(int, const char *, int, ...); -int posix_fadvise(int, off_t, off_t, int); -int posix_fallocate(int, off_t, off_t); - -#define O_SEARCH O_PATH -#define O_EXEC O_PATH - -#define O_ACCMODE (03|O_SEARCH) -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 - -#define F_OFD_GETLK 36 -#define F_OFD_SETLK 37 -#define F_OFD_SETLKW 38 - -#define F_DUPFD_CLOEXEC 1030 - -#define F_RDLCK 0 -#define F_WRLCK 1 -#define F_UNLCK 2 - -#define FD_CLOEXEC 1 - -#define AT_FDCWD (-100) -#define AT_SYMLINK_NOFOLLOW 0x100 -#define AT_REMOVEDIR 0x200 -#define AT_SYMLINK_FOLLOW 0x400 -#define AT_EACCESS 0x200 - -#define POSIX_FADV_NORMAL 0 -#define POSIX_FADV_RANDOM 1 -#define POSIX_FADV_SEQUENTIAL 2 -#define POSIX_FADV_WILLNEED 3 -#define POSIX_FADV_DONTNEED 4 -#define POSIX_FADV_NOREUSE 5 - -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#ifndef S_IRUSR -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRWXU 0700 -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IRWXG 0070 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 -#define S_IRWXO 0007 -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define AT_NO_AUTOMOUNT 0x800 -#define AT_EMPTY_PATH 0x1000 - -#define FAPPEND O_APPEND -#define FFSYNC O_SYNC -#define FASYNC O_ASYNC -#define FNONBLOCK O_NONBLOCK -#define FNDELAY O_NDELAY - -#define F_OK 0 -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 -#define F_ULOCK 0 -#define F_LOCK 1 -#define F_TLOCK 2 -#define F_TEST 3 - -#define F_SETLEASE 1024 -#define F_GETLEASE 1025 -#define F_NOTIFY 1026 -#define F_CANCELLK 1029 -#define F_SETPIPE_SZ 1031 -#define F_GETPIPE_SZ 1032 -#define F_ADD_SEALS 1033 -#define F_GET_SEALS 1034 - -#define F_SEAL_SEAL 0x0001 -#define F_SEAL_SHRINK 0x0002 -#define F_SEAL_GROW 0x0004 -#define F_SEAL_WRITE 0x0008 - -#define DN_ACCESS 0x00000001 -#define DN_MODIFY 0x00000002 -#define DN_CREATE 0x00000004 -#define DN_DELETE 0x00000008 -#define DN_RENAME 0x00000010 -#define DN_ATTRIB 0x00000020 -#define DN_MULTISHOT 0x80000000 - -int lockf(int, int, off_t); -#endif - -#if defined(_GNU_SOURCE) -#define F_OWNER_TID 0 -#define F_OWNER_PID 1 -#define F_OWNER_PGRP 2 -#define F_OWNER_GID 2 -struct f_owner_ex { - int type; - pid_t pid; -}; -#define FALLOC_FL_KEEP_SIZE 1 -#define FALLOC_FL_PUNCH_HOLE 2 -#define SYNC_FILE_RANGE_WAIT_BEFORE 1 -#define SYNC_FILE_RANGE_WRITE 2 -#define SYNC_FILE_RANGE_WAIT_AFTER 4 -#define SPLICE_F_MOVE 1 -#define SPLICE_F_NONBLOCK 2 -#define SPLICE_F_MORE 4 -#define SPLICE_F_GIFT 8 -int fallocate(int, int, off_t, off_t); -#define fallocate64 fallocate -ssize_t readahead(int, off_t, size_t); -int sync_file_range(int, off_t, off_t, unsigned); -ssize_t vmsplice(int, const struct iovec *, size_t, unsigned); -ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned); -ssize_t tee(int, int, size_t, unsigned); -#define loff_t off_t -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define F_GETLK64 F_GETLK -#define F_SETLK64 F_SETLK -#define F_SETLKW64 F_SETLKW -#define flock64 flock -#define open64 open -#define openat64 openat -#define creat64 creat -#define lockf64 lockf -#define posix_fadvise64 posix_fadvise -#define posix_fallocate64 posix_fallocate -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/fdop.h b/usr/lib/libc/include/fdop.h deleted file mode 100644 index 00b875143..000000000 --- a/usr/lib/libc/include/fdop.h +++ /dev/null @@ -1,10 +0,0 @@ -#define FDOP_CLOSE 1 -#define FDOP_DUP2 2 -#define FDOP_OPEN 3 - -struct fdop { - struct fdop *next, *prev; - int cmd, fd, srcfd, oflag; - mode_t mode; - char path[]; -}; diff --git a/usr/lib/libc/include/features.h b/usr/lib/libc/include/features.h deleted file mode 100644 index f4d651efc..000000000 --- a/usr/lib/libc/include/features.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _FEATURES_H -#define _FEATURES_H - -#if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) -#define _GNU_SOURCE 1 -#endif - -#if defined(_DEFAULT_SOURCE) && !defined(_BSD_SOURCE) -#define _BSD_SOURCE 1 -#endif - -#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ - && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \ - && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__) -#define _BSD_SOURCE 1 -#define _XOPEN_SOURCE 700 -#endif - -#if __STDC_VERSION__ >= 199901L -#define __restrict restrict -#elif !defined(__GNUC__) -#define __restrict -#endif - -#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) -#define __inline inline -#elif !defined(__GNUC__) -#define __inline -#endif - -#if __STDC_VERSION__ >= 201112L -#elif defined(__GNUC__) -#define _Noreturn __attribute__((__noreturn__)) -#else -#define _Noreturn -#endif - -#endif diff --git a/usr/lib/libc/include/floatscan.h b/usr/lib/libc/include/floatscan.h deleted file mode 100644 index e027fa08f..000000000 --- a/usr/lib/libc/include/floatscan.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef FLOATSCAN_H -#define FLOATSCAN_H - -#include - -long double __floatscan(FILE *, int, int); - -#endif diff --git a/usr/lib/libc/include/iconv.h b/usr/lib/libc/include/iconv.h deleted file mode 100644 index ebe9bfda3..000000000 --- a/usr/lib/libc/include/iconv.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _ICONV_H -#define _ICONV_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t - -#include - -typedef void *iconv_t; - -iconv_t iconv_open(const char *, const char *); -size_t iconv(iconv_t, char **__restrict, size_t *__restrict, char **__restrict, size_t *__restrict); -int iconv_close(iconv_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/inet.h b/usr/lib/libc/include/inet.h deleted file mode 100644 index e0ae55e66..000000000 --- a/usr/lib/libc/include/inet.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef LIBC_INET_H_ -#define LIBC_INET_H_ - -#include "types.h" - -in_addr_t inet_addr(const char *cp); - -#endif /* LIBC_INET_H_ */ diff --git a/usr/lib/libc/include/intscan.h b/usr/lib/libc/include/intscan.h deleted file mode 100644 index 994c5e7de..000000000 --- a/usr/lib/libc/include/intscan.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef INTSCAN_H -#define INTSCAN_H - -#include - -unsigned long long __intscan(FILE *, unsigned, int, unsigned long long); - -#endif diff --git a/usr/lib/libc/include/inttypes.h b/usr/lib/libc/include/inttypes.h deleted file mode 100644 index 61dcb7273..000000000 --- a/usr/lib/libc/include/inttypes.h +++ /dev/null @@ -1,229 +0,0 @@ -#ifndef _INTTYPES_H -#define _INTTYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_wchar_t -#include - -typedef struct { intmax_t quot, rem; } imaxdiv_t; - -intmax_t imaxabs(intmax_t); -imaxdiv_t imaxdiv(intmax_t, intmax_t); - -intmax_t strtoimax(const char *__restrict, char **__restrict, int); -uintmax_t strtoumax(const char *__restrict, char **__restrict, int); - -intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); -uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); - -#if UINTPTR_MAX == UINT64_MAX -#define __PRI64 "l" -#define __PRIPTR "l" -#else -#define __PRI64 "ll" -#define __PRIPTR "" -#endif - -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 __PRI64 "d" - -#define PRIdLEAST8 "d" -#define PRIdLEAST16 "d" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 __PRI64 "d" - -#define PRIdFAST8 "d" -#define PRIdFAST16 "d" -#define PRIdFAST32 "d" -#define PRIdFAST64 __PRI64 "d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 __PRI64 "i" - -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 __PRI64 "i" - -#define PRIiFAST8 "i" -#define PRIiFAST16 "i" -#define PRIiFAST32 "i" -#define PRIiFAST64 __PRI64 "i" - -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 __PRI64 "o" - -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 __PRI64 "o" - -#define PRIoFAST8 "o" -#define PRIoFAST16 "o" -#define PRIoFAST32 "o" -#define PRIoFAST64 __PRI64 "o" - -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 __PRI64 "u" - -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 __PRI64 "u" - -#define PRIuFAST8 "u" -#define PRIuFAST16 "u" -#define PRIuFAST32 "u" -#define PRIuFAST64 __PRI64 "u" - -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -#define PRIx64 __PRI64 "x" - -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 __PRI64 "x" - -#define PRIxFAST8 "x" -#define PRIxFAST16 "x" -#define PRIxFAST32 "x" -#define PRIxFAST64 __PRI64 "x" - -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 __PRI64 "X" - -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 __PRI64 "X" - -#define PRIXFAST8 "X" -#define PRIXFAST16 "X" -#define PRIXFAST32 "X" -#define PRIXFAST64 __PRI64 "X" - -#define PRIdMAX __PRI64 "d" -#define PRIiMAX __PRI64 "i" -#define PRIoMAX __PRI64 "o" -#define PRIuMAX __PRI64 "u" -#define PRIxMAX __PRI64 "x" -#define PRIXMAX __PRI64 "X" - -#define PRIdPTR __PRIPTR "d" -#define PRIiPTR __PRIPTR "i" -#define PRIoPTR __PRIPTR "o" -#define PRIuPTR __PRIPTR "u" -#define PRIxPTR __PRIPTR "x" -#define PRIXPTR __PRIPTR "X" - -#define SCNd8 "hhd" -#define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 __PRI64 "d" - -#define SCNdLEAST8 "hhd" -#define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 __PRI64 "d" - -#define SCNdFAST8 "hhd" -#define SCNdFAST16 "d" -#define SCNdFAST32 "d" -#define SCNdFAST64 __PRI64 "d" - -#define SCNi8 "hhi" -#define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 __PRI64 "i" - -#define SCNiLEAST8 "hhi" -#define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 __PRI64 "i" - -#define SCNiFAST8 "hhi" -#define SCNiFAST16 "i" -#define SCNiFAST32 "i" -#define SCNiFAST64 __PRI64 "i" - -#define SCNu8 "hhu" -#define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 __PRI64 "u" - -#define SCNuLEAST8 "hhu" -#define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 __PRI64 "u" - -#define SCNuFAST8 "hhu" -#define SCNuFAST16 "u" -#define SCNuFAST32 "u" -#define SCNuFAST64 __PRI64 "u" - -#define SCNo8 "hho" -#define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 __PRI64 "o" - -#define SCNoLEAST8 "hho" -#define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 __PRI64 "o" - -#define SCNoFAST8 "hho" -#define SCNoFAST16 "o" -#define SCNoFAST32 "o" -#define SCNoFAST64 __PRI64 "o" - -#define SCNx8 "hhx" -#define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 __PRI64 "x" - -#define SCNxLEAST8 "hhx" -#define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 __PRI64 "x" - -#define SCNxFAST8 "hhx" -#define SCNxFAST16 "x" -#define SCNxFAST32 "x" -#define SCNxFAST64 __PRI64 "x" - -#define SCNdMAX __PRI64 "d" -#define SCNiMAX __PRI64 "i" -#define SCNoMAX __PRI64 "o" -#define SCNuMAX __PRI64 "u" -#define SCNxMAX __PRI64 "x" - -#define SCNdPTR __PRIPTR "d" -#define SCNiPTR __PRIPTR "i" -#define SCNoPTR __PRIPTR "o" -#define SCNuPTR __PRIPTR "u" -#define SCNxPTR __PRIPTR "x" - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/usr/lib/libc/include/ksigaction.h b/usr/lib/libc/include/ksigaction.h deleted file mode 100644 index 43ffc998f..000000000 --- a/usr/lib/libc/include/ksigaction.h +++ /dev/null @@ -1,11 +0,0 @@ -/* This is the structure used for the rt_sigaction syscall on most archs, - * but it can be overridden by a file with the same name in the top-level - * arch dir for a given arch, if necessary. */ -struct k_sigaction { - void (*handler)(int); - unsigned long flags; - void (*restorer)(int, void *); - unsigned mask[2]; -}; - -void __restore(), __restore_rt(); diff --git a/usr/lib/libc/include/langinfo.h b/usr/lib/libc/include/langinfo.h deleted file mode 100644 index 70ce8e32b..000000000 --- a/usr/lib/libc/include/langinfo.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef LANGINFO_H -#define LANGINFO_H - -/* Enumeration of locale items that can be queried with `nl_langinfo'. */ -typedef enum { - - /* LC_TIME category: date and time formatting. */ - - /* Abbreviated days of the week. */ - ABDAY_1 = 0, /* Sun */ - #define ABDAY_1 ABDAY_1 - ABDAY_2, - #define ABDAY_2 ABDAY_2 - ABDAY_3, - #define ABDAY_3 ABDAY_3 - ABDAY_4, - #define ABDAY_4 ABDAY_4 - ABDAY_5, - #define ABDAY_5 ABDAY_5 - ABDAY_6, - #define ABDAY_6 ABDAY_6 - ABDAY_7, - #define ABDAY_7 ABDAY_7 - - /* Long-named days of the week. */ - DAY_1, /* Sunday */ - #define DAY_1 DAY_1 - DAY_2, /* Monday */ - #define DAY_2 DAY_2 - DAY_3, /* Tuesday */ - #define DAY_3 DAY_3 - DAY_4, /* Wednesday */ - #define DAY_4 DAY_4 - DAY_5, /* Thursday */ - #define DAY_5 DAY_5 - DAY_6, /* Friday */ - #define DAY_6 DAY_6 - DAY_7, /* Saturday */ - #define DAY_7 DAY_7 - - /* Abbreviated month names, in the grammatical form used when the month - is a part of a complete date. */ - ABMON_1, /* Jan */ - #define ABMON_1 ABMON_1 - ABMON_2, - #define ABMON_2 ABMON_2 - ABMON_3, - #define ABMON_3 ABMON_3 - ABMON_4, - #define ABMON_4 ABMON_4 - ABMON_5, - #define ABMON_5 ABMON_5 - ABMON_6, - #define ABMON_6 ABMON_6 - ABMON_7, - #define ABMON_7 ABMON_7 - ABMON_8, - #define ABMON_8 ABMON_8 - ABMON_9, - #define ABMON_9 ABMON_9 - ABMON_10, - #define ABMON_10 ABMON_10 - ABMON_11, - #define ABMON_11 ABMON_11 - ABMON_12, - #define ABMON_12 ABMON_12 - - /* Long month names, in the grammatical form used when the month - is a part of a complete date. */ - MON_1, /* January */ - #define MON_1 MON_1 - MON_2, - #define MON_2 MON_2 - MON_3, - #define MON_3 MON_3 - MON_4, - #define MON_4 MON_4 - MON_5, - #define MON_5 MON_5 - MON_6, - #define MON_6 MON_6 - MON_7, - #define MON_7 MON_7 - MON_8, - #define MON_8 MON_8 - MON_9, - #define MON_9 MON_9 - MON_10, - #define MON_10 MON_10 - MON_11, - #define MON_11 MON_11 - MON_12, - #define MON_12 MON_12 - - AM_STR, /* Ante meridiem string. */ - #define AM_STR AM_STR - PM_STR, /* Post meridiem string. */ - #define PM_STR PM_STR - - D_T_FMT, /* Date and time format for strftime. */ - #define D_T_FMT D_T_FMT - D_FMT, /* Date format for strftime. */ - #define D_FMT D_FMT - T_FMT, /* Time format for strftime. */ - #define T_FMT T_FMT - T_FMT_AMPM, /* 12-hour time format for strftime. */ - #define T_FMT_AMPM T_FMT_AMPM - -} nl_item; - - - -#endif /* LANGINFO_H */ diff --git a/usr/lib/libc/include/libc.h b/usr/lib/libc/include/libc.h deleted file mode 100644 index fe6a31c2c..000000000 --- a/usr/lib/libc/include/libc.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef LIBC_H -#define LIBC_H - -#include -#include -#include - -struct __locale_map; - -struct __locale_struct { - const struct __locale_map *volatile cat[6]; -}; - -struct tls_module { - struct tls_module *next; - void *image; - size_t len, size, align, offset; -}; - -struct __libc { - int can_do_threads; - int threaded; - int secure; - volatile int threads_minus_1; - size_t *auxv; - struct tls_module *tls_head; - size_t tls_size, tls_align, tls_cnt; - size_t page_size; - struct __locale_struct global_locale; -}; - -/* SO3 */ -/* Make a 32 MB heap size of the user space */ - -#define HEAP_SIZE (32 * 1024 * 1024) - -#ifndef PAGE_SIZE -#define PAGE_SIZE libc.page_size -#endif - -#ifdef __PIC__ -#define ATTR_LIBC_VISIBILITY __attribute__((visibility("hidden"))) -#else -#define ATTR_LIBC_VISIBILITY -#endif - -extern struct __libc __libc ATTR_LIBC_VISIBILITY; -#define libc __libc - -extern size_t __hwcap ATTR_LIBC_VISIBILITY; -extern size_t __sysinfo ATTR_LIBC_VISIBILITY; -extern char *__progname, *__progname_full; - -/* Designed to avoid any overhead in non-threaded processes */ -void __lock(volatile int *) ATTR_LIBC_VISIBILITY; -void __unlock(volatile int *) ATTR_LIBC_VISIBILITY; -int __lockfile(FILE *) ATTR_LIBC_VISIBILITY; -void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY; -#define LOCK(x) __lock(x) -#define UNLOCK(x) __unlock(x) - -void __synccall(void (*)(void *), void *); -int __setxid(int, int, int, int); - -extern char **__environ; - -#undef weak_alias -#define weak_alias(old, new) \ - extern __typeof(old) new __attribute__((weak, alias(#old))) - -#undef LFS64_2 -#define LFS64_2(x, y) weak_alias(x, y) - -#undef LFS64 -#define LFS64(x) LFS64_2(x, x##64) - -#endif diff --git a/usr/lib/libc/include/libm.h b/usr/lib/libc/include/libm.h deleted file mode 100644 index df8641116..000000000 --- a/usr/lib/libc/include/libm.h +++ /dev/null @@ -1,184 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#ifndef _LIBM_H -#define _LIBM_H - -#include -#include -#include -#include -#include - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN -union ldshape { - long double f; - struct { - uint64_t m; - uint16_t se; - } i; -}; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN -union ldshape { - long double f; - struct { - uint64_t lo; - uint32_t mid; - uint16_t top; - uint16_t se; - } i; - struct { - uint64_t lo; - uint64_t hi; - } i2; -}; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN -union ldshape { - long double f; - struct { - uint16_t se; - uint16_t top; - uint32_t mid; - uint64_t lo; - } i; - struct { - uint64_t hi; - uint64_t lo; - } i2; -}; -#else -#error Unsupported long double representation -#endif - -#define FORCE_EVAL(x) do { \ - if (sizeof(x) == sizeof(float)) { \ - volatile float __x; \ - __x = (x); \ - } else if (sizeof(x) == sizeof(double)) { \ - volatile double __x; \ - __x = (x); \ - } else { \ - volatile long double __x; \ - __x = (x); \ - } \ -} while(0) - -/* Get two 32 bit ints from a double. */ -#define EXTRACT_WORDS(hi,lo,d) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - (hi) = __u.i >> 32; \ - (lo) = (uint32_t)__u.i; \ -} while (0) - -/* Get the more significant 32 bit int from a double. */ -#define GET_HIGH_WORD(hi,d) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - (hi) = __u.i >> 32; \ -} while (0) - -/* Get the less significant 32 bit int from a double. */ -#define GET_LOW_WORD(lo,d) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - (lo) = (uint32_t)__u.i; \ -} while (0) - -/* Set a double from two 32 bit ints. */ -#define INSERT_WORDS(d,hi,lo) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo); \ - (d) = __u.f; \ -} while (0) - -/* Set the more significant 32 bits of a double from an int. */ -#define SET_HIGH_WORD(d,hi) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - __u.i &= 0xffffffff; \ - __u.i |= (uint64_t)(hi) << 32; \ - (d) = __u.f; \ -} while (0) - -/* Set the less significant 32 bits of a double from an int. */ -#define SET_LOW_WORD(d,lo) \ -do { \ - union {double f; uint64_t i;} __u; \ - __u.f = (d); \ - __u.i &= 0xffffffff00000000ull; \ - __u.i |= (uint32_t)(lo); \ - (d) = __u.f; \ -} while (0) - -/* Get a 32 bit int from a float. */ -#define GET_FLOAT_WORD(w,d) \ -do { \ - union {float f; uint32_t i;} __u; \ - __u.f = (d); \ - (w) = __u.i; \ -} while (0) - -/* Set a float from a 32 bit int. */ -#define SET_FLOAT_WORD(d,w) \ -do { \ - union {float f; uint32_t i;} __u; \ - __u.i = (w); \ - (d) = __u.f; \ -} while (0) - -#undef __CMPLX -#undef CMPLX -#undef CMPLXF -#undef CMPLXL - -#define __CMPLX(x, y, t) \ - ((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z) - -#define CMPLX(x, y) __CMPLX(x, y, double) -#define CMPLXF(x, y) __CMPLX(x, y, float) -#define CMPLXL(x, y) __CMPLX(x, y, long double) - -/* fdlibm kernel functions */ - -int __rem_pio2_large(double*,double*,int,int,int); - -int __rem_pio2(double,double*); -double __sin(double,double,int); -double __cos(double,double); -double __tan(double,double,int); -double __expo2(double); -double complex __ldexp_cexp(double complex,int); - -int __rem_pio2f(float,double*); -float __sindf(double); -float __cosdf(double); -float __tandf(double,int); -float __expo2f(float); -float complex __ldexp_cexpf(float complex,int); - -int __rem_pio2l(long double, long double *); -long double __sinl(long double, long double, int); -long double __cosl(long double, long double); -long double __tanl(long double, long double, int); - -/* polynomial evaluation */ -long double __polevll(long double, const long double *, int); -long double __p1evll(long double, const long double *, int); - -#endif diff --git a/usr/lib/libc/include/limits.h b/usr/lib/libc/include/limits.h deleted file mode 100644 index f9805a1e1..000000000 --- a/usr/lib/libc/include/limits.h +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef _LIMITS_H -#define _LIMITS_H - -#include - -/* Most limits are system-specific */ - -#include - -/* Support signed or unsigned plain-char */ - -#if '\0'-1 > 0 -#define CHAR_MIN 0 -#define CHAR_MAX 255 -#else -#define CHAR_MIN (-128) -#define CHAR_MAX 127 -#endif - -/* Some universal constants... */ - -#define CHAR_BIT 8 -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 -#define UCHAR_MAX 255 -#define SHRT_MIN (-1-0x7fff) -#define SHRT_MAX 0x7fff -#define USHRT_MAX 0xffff -#define INT_MIN (-1-0x7fffffff) -#define INT_MAX 0x7fffffff -#define UINT_MAX 0xffffffffU -#define LONG_MIN (-LONG_MAX-1) -#define ULONG_MAX (2UL*LONG_MAX+1) -#define LLONG_MIN (-LLONG_MAX-1) -#define ULLONG_MAX (2ULL*LLONG_MAX+1) - -#define MB_LEN_MAX 4 - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define PIPE_BUF 4096 -#ifdef PAGE_SIZE -#define PAGESIZE PAGE_SIZE -#endif -#define FILESIZEBITS 64 -#define NAME_MAX 255 -#define SYMLINK_MAX 255 -#define PATH_MAX 4096 -#define NZERO 20 -#define NGROUPS_MAX 32 -#define ARG_MAX 131072 -#define IOV_MAX 1024 -#define SYMLOOP_MAX 40 -#define WORD_BIT 32 -#define SSIZE_MAX LONG_MAX -#define TZNAME_MAX 6 -#define TTY_NAME_MAX 32 -#define HOST_NAME_MAX 255 - -/* Implementation choices... */ - -#define PTHREAD_KEYS_MAX 128 -#define PTHREAD_STACK_MIN 2048 -#define PTHREAD_DESTRUCTOR_ITERATIONS 4 -#define SEM_VALUE_MAX 0x7fffffff -#define SEM_NSEMS_MAX 256 -#define DELAYTIMER_MAX 0x7fffffff -#define MQ_PRIO_MAX 32768 -#define LOGIN_NAME_MAX 256 - -/* Arbitrary numbers... */ - -#define BC_BASE_MAX 99 -#define BC_DIM_MAX 2048 -#define BC_SCALE_MAX 99 -#define BC_STRING_MAX 1000 -#define CHARCLASS_NAME_MAX 14 -#define COLL_WEIGHTS_MAX 2 -#define EXPR_NEST_MAX 32 -#define LINE_MAX 4096 -#define RE_DUP_MAX 255 - -#define NL_ARGMAX 9 -#define NL_LANGMAX 32 -#define NL_MSGMAX 32767 -#define NL_SETMAX 255 -#define NL_TEXTMAX 2048 - -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) - -#define NL_NMAX 16 - -#endif - -/* POSIX/SUS requirements follow. These numbers come directly - * from SUS and have nothing to do with the host system. */ - -#define _POSIX_AIO_LISTIO_MAX 2 -#define _POSIX_AIO_MAX 1 -#define _POSIX_ARG_MAX 4096 -#define _POSIX_CHILD_MAX 25 -#define _POSIX_CLOCKRES_MIN 20000000 -#define _POSIX_DELAYTIMER_MAX 32 -#define _POSIX_HOST_NAME_MAX 255 -#define _POSIX_LINK_MAX 8 -#define _POSIX_LOGIN_NAME_MAX 9 -#define _POSIX_MAX_CANON 255 -#define _POSIX_MAX_INPUT 255 -#define _POSIX_MQ_OPEN_MAX 8 -#define _POSIX_MQ_PRIO_MAX 32 -#define _POSIX_NAME_MAX 14 -#define _POSIX_NGROUPS_MAX 8 -#define _POSIX_OPEN_MAX 20 -#define _POSIX_PATH_MAX 256 -#define _POSIX_PIPE_BUF 512 -#define _POSIX_RE_DUP_MAX 255 -#define _POSIX_RTSIG_MAX 8 -#define _POSIX_SEM_NSEMS_MAX 256 -#define _POSIX_SEM_VALUE_MAX 32767 -#define _POSIX_SIGQUEUE_MAX 32 -#define _POSIX_SSIZE_MAX 32767 -#define _POSIX_STREAM_MAX 8 -#define _POSIX_SS_REPL_MAX 4 -#define _POSIX_SYMLINK_MAX 255 -#define _POSIX_SYMLOOP_MAX 8 -#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 -#define _POSIX_THREAD_KEYS_MAX 128 -#define _POSIX_THREAD_THREADS_MAX 64 -#define _POSIX_TIMER_MAX 32 -#define _POSIX_TRACE_EVENT_NAME_MAX 30 -#define _POSIX_TRACE_NAME_MAX 8 -#define _POSIX_TRACE_SYS_MAX 8 -#define _POSIX_TRACE_USER_EVENT_MAX 32 -#define _POSIX_TTY_NAME_MAX 9 -#define _POSIX_TZNAME_MAX 6 -#define _POSIX2_BC_BASE_MAX 99 -#define _POSIX2_BC_DIM_MAX 2048 -#define _POSIX2_BC_SCALE_MAX 99 -#define _POSIX2_BC_STRING_MAX 1000 -#define _POSIX2_CHARCLASS_NAME_MAX 14 -#define _POSIX2_COLL_WEIGHTS_MAX 2 -#define _POSIX2_EXPR_NEST_MAX 32 -#define _POSIX2_LINE_MAX 2048 -#define _POSIX2_RE_DUP_MAX 255 - -#define _XOPEN_IOV_MAX 16 -#define _XOPEN_NAME_MAX 255 -#define _XOPEN_PATH_MAX 1024 - -#endif diff --git a/usr/lib/libc/include/locale.h b/usr/lib/libc/include/locale.h deleted file mode 100644 index dae15b23f..000000000 --- a/usr/lib/libc/include/locale.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifndef LOCALE_H -#define LOCALE_H - - -#define C_LOCALE 0 - - -#endif /* LOCALE_H */ - - diff --git a/usr/lib/libc/include/locale_impl.h b/usr/lib/libc/include/locale_impl.h deleted file mode 100644 index eee6d8806..000000000 --- a/usr/lib/libc/include/locale_impl.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _LOCALE_IMPL_H -#define _LOCALE_IMPL_H - -#if 0 -#include -#include -#include "libc.h" -#include "pthread_impl.h" - -#define LOCALE_NAME_MAX 23 - -struct __locale_map { - const void *map; - size_t map_size; - char name[LOCALE_NAME_MAX+1]; - const struct __locale_map *next; -}; - -extern const struct __locale_map __c_dot_utf8; -extern const struct __locale_struct __c_locale; -extern const struct __locale_struct __c_dot_utf8_locale; - -const struct __locale_map *__get_locale(int, const char *); -const char *__mo_lookup(const void *, size_t, const char *); -const char *__lctrans(const char *, const struct __locale_map *); -const char *__lctrans_cur(const char *); - -#define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) -#define LCTRANS_CUR(msg) __lctrans_cur(msg) - -#define C_LOCALE ((locale_t)&__c_locale) -#define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) - -#define CURRENT_LOCALE (__pthread_self()->locale) - -#define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) - -#undef MB_CUR_MAX -#define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) - -#endif /* 0 */ - -#endif diff --git a/usr/lib/libc/include/malloc.h b/usr/lib/libc/include/malloc.h deleted file mode 100644 index 4dcce306d..000000000 --- a/usr/lib/libc/include/malloc.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MALLOC_H -#define MALLOC - -#include -#include - -void *malloc(size_t size); -void free(void *ptr); - -/* quickfit */ -void print_heap(void); - -/* bestfit */ -void printHeap(void); - -#endif diff --git a/usr/lib/libc/include/math.h b/usr/lib/libc/include/math.h deleted file mode 100644 index 6ac91da24..000000000 --- a/usr/lib/libc/include/math.h +++ /dev/null @@ -1,430 +0,0 @@ -#ifndef _MATH_H -#define _MATH_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_float_t -#define __NEED_double_t -#include - -#if 100*__GNUC__+__GNUC_MINOR__ >= 303 -#define NAN __builtin_nanf("") -#define INFINITY __builtin_inff() -#else -#define NAN (0.0f/0.0f) -#define INFINITY 1e5000f -#endif - -#define HUGE_VALF INFINITY -#define HUGE_VAL ((double)INFINITY) -#define HUGE_VALL ((long double)INFINITY) - -#define MATH_ERRNO 1 -#define MATH_ERREXCEPT 2 -#define math_errhandling 2 - -#define FP_ILOGBNAN (-1-(int)(((unsigned)-1)>>1)) -#define FP_ILOGB0 FP_ILOGBNAN - -#define FP_NAN 0 -#define FP_INFINITE 1 -#define FP_ZERO 2 -#define FP_SUBNORMAL 3 -#define FP_NORMAL 4 - -int __fpclassify(double); -int __fpclassifyf(float); -int __fpclassifyl(long double); - -static __inline unsigned __FLOAT_BITS(float __f) -{ - union {float __f; unsigned __i;} __u; - __u.__f = __f; - return __u.__i; -} -static __inline unsigned long long __DOUBLE_BITS(double __f) -{ - union {double __f; unsigned long long __i;} __u; - __u.__f = __f; - return __u.__i; -} - -#define fpclassify(x) ( \ - sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ - sizeof(x) == sizeof(double) ? __fpclassify(x) : \ - __fpclassifyl(x) ) - -#define isinf(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \ - __fpclassifyl(x) == FP_INFINITE) - -#define isnan(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ - __fpclassifyl(x) == FP_NAN) - -#define isnormal(x) ( \ - sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ - sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \ - __fpclassifyl(x) == FP_NORMAL) - -#define isfinite(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \ - __fpclassifyl(x) > FP_INFINITE) - -int __signbit(double); -int __signbitf(float); -int __signbitl(long double); - -#define signbit(x) ( \ - sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \ - sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \ - __signbitl(x) ) - -#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) - -#define __ISREL_DEF(rel, op, type) \ -static __inline int __is##rel(type __x, type __y) \ -{ return !isunordered(__x,__y) && __x op __y; } - -__ISREL_DEF(lessf, <, float_t) -__ISREL_DEF(less, <, double_t) -__ISREL_DEF(lessl, <, long double) -__ISREL_DEF(lessequalf, <=, float_t) -__ISREL_DEF(lessequal, <=, double_t) -__ISREL_DEF(lessequall, <=, long double) -__ISREL_DEF(lessgreaterf, !=, float_t) -__ISREL_DEF(lessgreater, !=, double_t) -__ISREL_DEF(lessgreaterl, !=, long double) -__ISREL_DEF(greaterf, >, float_t) -__ISREL_DEF(greater, >, double_t) -__ISREL_DEF(greaterl, >, long double) -__ISREL_DEF(greaterequalf, >=, float_t) -__ISREL_DEF(greaterequal, >=, double_t) -__ISREL_DEF(greaterequall, >=, long double) - -#define __tg_pred_2(x, y, p) ( \ - sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ - sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ - p##l(x, y) ) - -#define isless(x, y) __tg_pred_2(x, y, __isless) -#define islessequal(x, y) __tg_pred_2(x, y, __islessequal) -#define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater) -#define isgreater(x, y) __tg_pred_2(x, y, __isgreater) -#define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal) - -double acos(double); -float acosf(float); -long double acosl(long double); - -double acosh(double); -float acoshf(float); -long double acoshl(long double); - -double asin(double); -float asinf(float); -long double asinl(long double); - -double asinh(double); -float asinhf(float); -long double asinhl(long double); - -double atan(double); -float atanf(float); -long double atanl(long double); - -double atan2(double, double); -float atan2f(float, float); -long double atan2l(long double, long double); - -double atanh(double); -float atanhf(float); -long double atanhl(long double); - -double cbrt(double); -float cbrtf(float); -long double cbrtl(long double); - -double ceil(double); -float ceilf(float); -long double ceill(long double); - -double copysign(double, double); -float copysignf(float, float); -long double copysignl(long double, long double); - -double cos(double); -float cosf(float); -long double cosl(long double); - -double cosh(double); -float coshf(float); -long double coshl(long double); - -double erf(double); -float erff(float); -long double erfl(long double); - -double erfc(double); -float erfcf(float); -long double erfcl(long double); - -double exp(double); -float expf(float); -long double expl(long double); - -double exp2(double); -float exp2f(float); -long double exp2l(long double); - -double expm1(double); -float expm1f(float); -long double expm1l(long double); - -double fabs(double); -float fabsf(float); -long double fabsl(long double); - -double fdim(double, double); -float fdimf(float, float); -long double fdiml(long double, long double); - -double floor(double); -float floorf(float); -long double floorl(long double); - -double fma(double, double, double); -float fmaf(float, float, float); -long double fmal(long double, long double, long double); - -double fmax(double, double); -float fmaxf(float, float); -long double fmaxl(long double, long double); - -double fmin(double, double); -float fminf(float, float); -long double fminl(long double, long double); - -double fmod(double, double); -float fmodf(float, float); -long double fmodl(long double, long double); - -double frexp(double, int *); -float frexpf(float, int *); -long double frexpl(long double, int *); - -double hypot(double, double); -float hypotf(float, float); -long double hypotl(long double, long double); - -int ilogb(double); -int ilogbf(float); -int ilogbl(long double); - -double ldexp(double, int); -float ldexpf(float, int); -long double ldexpl(long double, int); - -double lgamma(double); -float lgammaf(float); -long double lgammal(long double); - -long long llrint(double); -long long llrintf(float); -long long llrintl(long double); - -long long llround(double); -long long llroundf(float); -long long llroundl(long double); - -double log(double); -float logf(float); -long double logl(long double); - -double log10(double); -float log10f(float); -long double log10l(long double); - -double log1p(double); -float log1pf(float); -long double log1pl(long double); - -double log2(double); -float log2f(float); -long double log2l(long double); - -double logb(double); -float logbf(float); -long double logbl(long double); - -long lrint(double); -long lrintf(float); -long lrintl(long double); - -long lround(double); -long lroundf(float); -long lroundl(long double); - -double modf(double, double *); -float modff(float, float *); -long double modfl(long double, long double *); - -double nan(const char *); -float nanf(const char *); -long double nanl(const char *); - -double nearbyint(double); -float nearbyintf(float); -long double nearbyintl(long double); - -double nextafter(double, double); -float nextafterf(float, float); -long double nextafterl(long double, long double); - -double nexttoward(double, long double); -float nexttowardf(float, long double); -long double nexttowardl(long double, long double); - -double pow(double, double); -float powf(float, float); -long double powl(long double, long double); - -double remainder(double, double); -float remainderf(float, float); -long double remainderl(long double, long double); - -double remquo(double, double, int *); -float remquof(float, float, int *); -long double remquol(long double, long double, int *); - -double rint(double); -float rintf(float); -long double rintl(long double); - -double round(double); -float roundf(float); -long double roundl(long double); - -double scalbln(double, long); -float scalblnf(float, long); -long double scalblnl(long double, long); - -double scalbn(double, int); -float scalbnf(float, int); -long double scalbnl(long double, int); - -double sin(double); -float sinf(float); -long double sinl(long double); - -double sinh(double); -float sinhf(float); -long double sinhl(long double); - -double sqrt(double); -float sqrtf(float); -long double sqrtl(long double); - -double tan(double); -float tanf(float); -long double tanl(long double); - -double tanh(double); -float tanhf(float); -long double tanhl(long double); - -double tgamma(double); -float tgammaf(float); -long double tgammal(long double); - -double trunc(double); -float truncf(float); -long double truncl(long double); - - -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) -#undef MAXFLOAT -#define MAXFLOAT 3.40282346638528859812e+38F -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define M_E 2.7182818284590452354 /* e */ -#define M_LOG2E 1.4426950408889634074 /* log_2 e */ -#define M_LOG10E 0.43429448190325182765 /* log_10 e */ -#define M_LN2 0.69314718055994530942 /* log_e 2 */ -#define M_LN10 2.30258509299404568402 /* log_e 10 */ -#define M_PI 3.14159265358979323846 /* pi */ -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#define M_PI_4 0.78539816339744830962 /* pi/4 */ -#define M_1_PI 0.31830988618379067154 /* 1/pi */ -#define M_2_PI 0.63661977236758134308 /* 2/pi */ -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ - -extern int signgam; - -double j0(double); -double j1(double); -double jn(int, double); - -double y0(double); -double y1(double); -double yn(int, double); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define HUGE 3.40282346638528859812e+38F - -double drem(double, double); -float dremf(float, float); - -int finite(double); -int finitef(float); - -double scalb(double, double); -float scalbf(float, float); - -double significand(double); -float significandf(float); - -double lgamma_r(double, int*); -float lgammaf_r(float, int*); - -float j0f(float); -float j1f(float); -float jnf(int, float); - -float y0f(float); -float y1f(float); -float ynf(int, float); -#endif - -#ifdef _GNU_SOURCE -long double lgammal_r(long double, int*); - -void sincos(double, double*, double*); -void sincosf(float, float*, float*); -void sincosl(long double, long double*, long double*); - -double exp10(double); -float exp10f(float); -long double exp10l(long double); - -double pow10(double); -float pow10f(float); -long double pow10l(long double); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/mman.h b/usr/lib/libc/include/mman.h deleted file mode 100644 index 8b1378917..000000000 --- a/usr/lib/libc/include/mman.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/usr/lib/libc/include/mutex.h b/usr/lib/libc/include/mutex.h deleted file mode 100644 index a6a3360b7..000000000 --- a/usr/lib/libc/include/mutex.h +++ /dev/null @@ -1,10 +0,0 @@ - - -#ifndef MUTEX_H -#define MUTEX_H - -void mutex_lock(int lock_idx); -void mutex_unlock(int lock_idx); - - -#endif /* MUTEX_H */ diff --git a/usr/lib/libc/include/net/ethernet.h b/usr/lib/libc/include/net/ethernet.h deleted file mode 100644 index c8d4177fd..000000000 --- a/usr/lib/libc/include/net/ethernet.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _NET_ETHERNET_H -#define _NET_ETHERNET_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -struct ether_addr { - uint8_t ether_addr_octet[ETH_ALEN]; -}; - -struct ether_header { - uint8_t ether_dhost[ETH_ALEN]; - uint8_t ether_shost[ETH_ALEN]; - uint16_t ether_type; -}; - -#define ETHERTYPE_PUP 0x0200 -#define ETHERTYPE_SPRITE 0x0500 -#define ETHERTYPE_IP 0x0800 -#define ETHERTYPE_ARP 0x0806 -#define ETHERTYPE_REVARP 0x8035 -#define ETHERTYPE_AT 0x809B -#define ETHERTYPE_AARP 0x80F3 -#define ETHERTYPE_VLAN 0x8100 -#define ETHERTYPE_IPX 0x8137 -#define ETHERTYPE_IPV6 0x86dd -#define ETHERTYPE_LOOPBACK 0x9000 - - -#define ETHER_ADDR_LEN ETH_ALEN -#define ETHER_TYPE_LEN 2 -#define ETHER_CRC_LEN 4 -#define ETHER_HDR_LEN ETH_HLEN -#define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) -#define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) - -#define ETHER_IS_VALID_LEN(foo) \ - ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) - -#define ETHERTYPE_TRAIL 0x1000 -#define ETHERTYPE_NTRAILER 16 - -#define ETHERMTU ETH_DATA_LEN -#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/net/if.h b/usr/lib/libc/include/net/if.h deleted file mode 100644 index 774cbff0b..000000000 --- a/usr/lib/libc/include/net/if.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef _NET_IF_H -#define _NET_IF_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define IF_NAMESIZE 16 - -struct if_nameindex { - unsigned int if_index; - char *if_name; -}; - -unsigned int if_nametoindex (const char *); -char *if_indextoname (unsigned int, char *); -struct if_nameindex *if_nameindex (void); -void if_freenameindex (struct if_nameindex *); - - - - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#include - -#define IFF_UP 0x1 -#define IFF_BROADCAST 0x2 -#define IFF_DEBUG 0x4 -#define IFF_LOOPBACK 0x8 -#define IFF_POINTOPOINT 0x10 -#define IFF_NOTRAILERS 0x20 -#define IFF_RUNNING 0x40 -#define IFF_NOARP 0x80 -#define IFF_PROMISC 0x100 -#define IFF_ALLMULTI 0x200 -#define IFF_MASTER 0x400 -#define IFF_SLAVE 0x800 -#define IFF_MULTICAST 0x1000 -#define IFF_PORTSEL 0x2000 -#define IFF_AUTOMEDIA 0x4000 -#define IFF_DYNAMIC 0x8000 -#define IFF_LOWER_UP 0x10000 -#define IFF_DORMANT 0x20000 -#define IFF_ECHO 0x40000 -#define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST| \ - IFF_ECHO|IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT) - -struct ifaddr { - struct sockaddr ifa_addr; - union { - struct sockaddr ifu_broadaddr; - struct sockaddr ifu_dstaddr; - } ifa_ifu; - struct iface *ifa_ifp; - struct ifaddr *ifa_next; -}; - -#define ifa_broadaddr ifa_ifu.ifu_broadaddr -#define ifa_dstaddr ifa_ifu.ifu_dstaddr - -struct ifmap { - unsigned long int mem_start; - unsigned long int mem_end; - unsigned short int base_addr; - unsigned char irq; - unsigned char dma; - unsigned char port; -}; - -#define IFHWADDRLEN 6 -#define IFNAMSIZ IF_NAMESIZE - -struct ifreq { - union { - char ifrn_name[IFNAMSIZ]; - } ifr_ifrn; - union { - struct sockaddr ifru_addr; - struct sockaddr ifru_dstaddr; - struct sockaddr ifru_broadaddr; - struct sockaddr ifru_netmask; - struct sockaddr ifru_hwaddr; - short int ifru_flags; - int ifru_ivalue; - int ifru_mtu; - struct ifmap ifru_map; - char ifru_slave[IFNAMSIZ]; - char ifru_newname[IFNAMSIZ]; - char *ifru_data; - } ifr_ifru; -}; - -#define ifr_name ifr_ifrn.ifrn_name -#define ifr_hwaddr ifr_ifru.ifru_hwaddr -#define ifr_addr ifr_ifru.ifru_addr -#define ifr_dstaddr ifr_ifru.ifru_dstaddr -#define ifr_broadaddr ifr_ifru.ifru_broadaddr -#define ifr_netmask ifr_ifru.ifru_netmask -#define ifr_flags ifr_ifru.ifru_flags -#define ifr_metric ifr_ifru.ifru_ivalue -#define ifr_mtu ifr_ifru.ifru_mtu -#define ifr_map ifr_ifru.ifru_map -#define ifr_slave ifr_ifru.ifru_slave -#define ifr_data ifr_ifru.ifru_data -#define ifr_ifindex ifr_ifru.ifru_ivalue -#define ifr_bandwidth ifr_ifru.ifru_ivalue -#define ifr_qlen ifr_ifru.ifru_ivalue -#define ifr_newname ifr_ifru.ifru_newname -#define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0) -#define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0) -#define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0) - -struct ifconf { - int ifc_len; - union { - char *ifcu_buf; - struct ifreq *ifcu_req; - } ifc_ifcu; -}; - -#define ifc_buf ifc_ifcu.ifcu_buf -#define ifc_req ifc_ifcu.ifcu_req -#define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0) - -#define __UAPI_DEF_IF_IFCONF 0 -#define __UAPI_DEF_IF_IFMAP 0 -#define __UAPI_DEF_IF_IFNAMSIZ 0 -#define __UAPI_DEF_IF_IFREQ 0 -#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0 -#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0 - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/net/if_arp.h b/usr/lib/libc/include/net/if_arp.h deleted file mode 100644 index 27becc835..000000000 --- a/usr/lib/libc/include/net/if_arp.h +++ /dev/null @@ -1,142 +0,0 @@ -/* Nonstandard header */ -#ifndef _NET_IF_ARP_H -#define _NET_IF_ARP_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#define MAX_ADDR_LEN 7 - -#define ARPOP_REQUEST 1 -#define ARPOP_REPLY 2 -#define ARPOP_RREQUEST 3 -#define ARPOP_RREPLY 4 -#define ARPOP_InREQUEST 8 -#define ARPOP_InREPLY 9 -#define ARPOP_NAK 10 - -struct arphdr { - uint16_t ar_hrd; - uint16_t ar_pro; - uint8_t ar_hln; - uint8_t ar_pln; - uint16_t ar_op; -}; - - -#define ARPHRD_NETROM 0 -#define ARPHRD_ETHER 1 -#define ARPHRD_EETHER 2 -#define ARPHRD_AX25 3 -#define ARPHRD_PRONET 4 -#define ARPHRD_CHAOS 5 -#define ARPHRD_IEEE802 6 -#define ARPHRD_ARCNET 7 -#define ARPHRD_APPLETLK 8 -#define ARPHRD_DLCI 15 -#define ARPHRD_ATM 19 -#define ARPHRD_METRICOM 23 -#define ARPHRD_IEEE1394 24 -#define ARPHRD_EUI64 27 -#define ARPHRD_INFINIBAND 32 -#define ARPHRD_SLIP 256 -#define ARPHRD_CSLIP 257 -#define ARPHRD_SLIP6 258 -#define ARPHRD_CSLIP6 259 -#define ARPHRD_RSRVD 260 -#define ARPHRD_ADAPT 264 -#define ARPHRD_ROSE 270 -#define ARPHRD_X25 271 -#define ARPHRD_HWX25 272 -#define ARPHRD_CAN 280 -#define ARPHRD_PPP 512 -#define ARPHRD_CISCO 513 -#define ARPHRD_HDLC ARPHRD_CISCO -#define ARPHRD_LAPB 516 -#define ARPHRD_DDCMP 517 -#define ARPHRD_RAWHDLC 518 -#define ARPHRD_RAWIP 519 - -#define ARPHRD_TUNNEL 768 -#define ARPHRD_TUNNEL6 769 -#define ARPHRD_FRAD 770 -#define ARPHRD_SKIP 771 -#define ARPHRD_LOOPBACK 772 -#define ARPHRD_LOCALTLK 773 -#define ARPHRD_FDDI 774 -#define ARPHRD_BIF 775 -#define ARPHRD_SIT 776 -#define ARPHRD_IPDDP 777 -#define ARPHRD_IPGRE 778 -#define ARPHRD_PIMREG 779 -#define ARPHRD_HIPPI 780 -#define ARPHRD_ASH 781 -#define ARPHRD_ECONET 782 -#define ARPHRD_IRDA 783 -#define ARPHRD_FCPP 784 -#define ARPHRD_FCAL 785 -#define ARPHRD_FCPL 786 -#define ARPHRD_FCFABRIC 787 -#define ARPHRD_IEEE802_TR 800 -#define ARPHRD_IEEE80211 801 -#define ARPHRD_IEEE80211_PRISM 802 -#define ARPHRD_IEEE80211_RADIOTAP 803 -#define ARPHRD_IEEE802154 804 -#define ARPHRD_IEEE802154_MONITOR 805 -#define ARPHRD_PHONET 820 -#define ARPHRD_PHONET_PIPE 821 -#define ARPHRD_CAIF 822 -#define ARPHRD_IP6GRE 823 -#define ARPHRD_NETLINK 824 -#define ARPHRD_6LOWPAN 825 -#define ARPHRD_VSOCKMON 826 - -#define ARPHRD_VOID 0xFFFF -#define ARPHRD_NONE 0xFFFE - -struct arpreq { - struct sockaddr arp_pa; - struct sockaddr arp_ha; - int arp_flags; - struct sockaddr arp_netmask; - char arp_dev[16]; -}; - -struct arpreq_old { - struct sockaddr arp_pa; - struct sockaddr arp_ha; - int arp_flags; - struct sockaddr arp_netmask; -}; - -#define ATF_COM 0x02 -#define ATF_PERM 0x04 -#define ATF_PUBL 0x08 -#define ATF_USETRAILERS 0x10 -#define ATF_NETMASK 0x20 -#define ATF_DONTPUB 0x40 -#define ATF_MAGIC 0x80 - -#define ARPD_UPDATE 0x01 -#define ARPD_LOOKUP 0x02 -#define ARPD_FLUSH 0x03 - -struct arpd_request { - unsigned short req; - uint32_t ip; - unsigned long dev; - unsigned long stamp; - unsigned long updated; - unsigned char ha[MAX_ADDR_LEN]; -}; - - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/net/route.h b/usr/lib/libc/include/net/route.h deleted file mode 100644 index 96ff48e01..000000000 --- a/usr/lib/libc/include/net/route.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef _NET_ROUTE_H -#define _NET_ROUTE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - - -struct rtentry { - unsigned long int rt_pad1; - struct sockaddr rt_dst; - struct sockaddr rt_gateway; - struct sockaddr rt_genmask; - unsigned short int rt_flags; - short int rt_pad2; - unsigned long int rt_pad3; - unsigned char rt_tos; - unsigned char rt_class; - short int rt_pad4[sizeof(long)/2-1]; - short int rt_metric; - char *rt_dev; - unsigned long int rt_mtu; - unsigned long int rt_window; - unsigned short int rt_irtt; -}; - -#define rt_mss rt_mtu - - -struct in6_rtmsg { - struct in6_addr rtmsg_dst; - struct in6_addr rtmsg_src; - struct in6_addr rtmsg_gateway; - uint32_t rtmsg_type; - uint16_t rtmsg_dst_len; - uint16_t rtmsg_src_len; - uint32_t rtmsg_metric; - unsigned long int rtmsg_info; - uint32_t rtmsg_flags; - int rtmsg_ifindex; -}; - - -#define RTF_UP 0x0001 -#define RTF_GATEWAY 0x0002 - -#define RTF_HOST 0x0004 -#define RTF_REINSTATE 0x0008 -#define RTF_DYNAMIC 0x0010 -#define RTF_MODIFIED 0x0020 -#define RTF_MTU 0x0040 -#define RTF_MSS RTF_MTU -#define RTF_WINDOW 0x0080 -#define RTF_IRTT 0x0100 -#define RTF_REJECT 0x0200 -#define RTF_STATIC 0x0400 -#define RTF_XRESOLVE 0x0800 -#define RTF_NOFORWARD 0x1000 -#define RTF_THROW 0x2000 -#define RTF_NOPMTUDISC 0x4000 - -#define RTF_DEFAULT 0x00010000 -#define RTF_ALLONLINK 0x00020000 -#define RTF_ADDRCONF 0x00040000 - -#define RTF_LINKRT 0x00100000 -#define RTF_NONEXTHOP 0x00200000 - -#define RTF_CACHE 0x01000000 -#define RTF_FLOW 0x02000000 -#define RTF_POLICY 0x04000000 - -#define RTCF_VALVE 0x00200000 -#define RTCF_MASQ 0x00400000 -#define RTCF_NAT 0x00800000 -#define RTCF_DOREDIRECT 0x01000000 -#define RTCF_LOG 0x02000000 -#define RTCF_DIRECTSRC 0x04000000 - -#define RTF_LOCAL 0x80000000 -#define RTF_INTERFACE 0x40000000 -#define RTF_MULTICAST 0x20000000 -#define RTF_BROADCAST 0x10000000 -#define RTF_NAT 0x08000000 - -#define RTF_ADDRCLASSMASK 0xF8000000 -#define RT_ADDRCLASS(flags) ((uint32_t) flags >> 23) - -#define RT_TOS(tos) ((tos) & IPTOS_TOS_MASK) - -#define RT_LOCALADDR(flags) ((flags & RTF_ADDRCLASSMASK) \ - == (RTF_LOCAL|RTF_INTERFACE)) - -#define RT_CLASS_UNSPEC 0 -#define RT_CLASS_DEFAULT 253 - -#define RT_CLASS_MAIN 254 -#define RT_CLASS_LOCAL 255 -#define RT_CLASS_MAX 255 - - -#define RTMSG_ACK NLMSG_ACK -#define RTMSG_OVERRUN NLMSG_OVERRUN - -#define RTMSG_NEWDEVICE 0x11 -#define RTMSG_DELDEVICE 0x12 -#define RTMSG_NEWROUTE 0x21 -#define RTMSG_DELROUTE 0x22 -#define RTMSG_NEWRULE 0x31 -#define RTMSG_DELRULE 0x32 -#define RTMSG_CONTROL 0x40 - -#define RTMSG_AR_FAILED 0x51 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netdb.h b/usr/lib/libc/include/netdb.h deleted file mode 100644 index 967ca211f..000000000 --- a/usr/lib/libc/include/netdb.h +++ /dev/null @@ -1,155 +0,0 @@ -#ifndef _NETDB_H -#define _NETDB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_size_t -#include -#endif - -struct addrinfo { - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - socklen_t ai_addrlen; - struct sockaddr *ai_addr; - char *ai_canonname; - struct addrinfo *ai_next; -}; - -#define IPPORT_RESERVED 1024 - -#define AI_PASSIVE 0x01 -#define AI_CANONNAME 0x02 -#define AI_NUMERICHOST 0x04 -#define AI_V4MAPPED 0x08 -#define AI_ALL 0x10 -#define AI_ADDRCONFIG 0x20 -#define AI_NUMERICSERV 0x400 - - -#define NI_NUMERICHOST 0x01 -#define NI_NUMERICSERV 0x02 -#define NI_NOFQDN 0x04 -#define NI_NAMEREQD 0x08 -#define NI_DGRAM 0x10 -#define NI_NUMERICSCOPE 0x100 - -#define EAI_BADFLAGS -1 -#define EAI_NONAME -2 -#define EAI_AGAIN -3 -#define EAI_FAIL -4 -#define EAI_FAMILY -6 -#define EAI_SOCKTYPE -7 -#define EAI_SERVICE -8 -#define EAI_MEMORY -10 -#define EAI_SYSTEM -11 -#define EAI_OVERFLOW -12 - -int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); -void freeaddrinfo (struct addrinfo *); -int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); -const char *gai_strerror(int); - - -/* 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; -}; - -void sethostent (int); -void endhostent (void); -struct hostent *gethostent (void); - -void setnetent (int); -void endnetent (void); -struct netent *getnetent (void); -struct netent *getnetbyaddr (uint32_t, int); -struct netent *getnetbyname (const char *); - -void setservent (int); -void endservent (void); -struct servent *getservent (void); -struct servent *getservbyname (const char *, const char *); -struct servent *getservbyport (int, const char *); - -void setprotoent (int); -void endprotoent (void); -struct protoent *getprotoent (void); -struct protoent *getprotobyname (const char *); -struct protoent *getprotobynumber (int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ - || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) -struct hostent *gethostbyname (const char *); -struct hostent *gethostbyaddr (const void *, socklen_t, int); -int *__h_errno_location(void); -#define h_errno (*__h_errno_location()) -#define HOST_NOT_FOUND 1 -#define TRY_AGAIN 2 -#define NO_RECOVERY 3 -#define NO_DATA 4 -#define NO_ADDRESS NO_DATA -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -void herror(const char *); -const char *hstrerror(int); -int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); -int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); -struct hostent *gethostbyname2(const char *, int); -int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); -int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); -int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); -#define EAI_NODATA -5 -#define EAI_ADDRFAMILY -9 -#define EAI_INPROGRESS -100 -#define EAI_CANCELED -101 -#define EAI_NOTCANCELED -102 -#define EAI_ALLDONE -103 -#define EAI_INTR -104 -#define EAI_IDN_ENCODE -105 -#define NI_MAXHOST 255 -#define NI_MAXSERV 32 -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/ether.h b/usr/lib/libc/include/netinet/ether.h deleted file mode 100644 index eec7e53ca..000000000 --- a/usr/lib/libc/include/netinet/ether.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _NETINET_ETHER_H -#define _NETINET_ETHER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -char *ether_ntoa (const struct ether_addr *); -struct ether_addr *ether_aton (const char *); -char *ether_ntoa_r (const struct ether_addr *, char *); -struct ether_addr *ether_aton_r (const char *, struct ether_addr *); -int ether_line(const char *, struct ether_addr *, char *); -int ether_ntohost(char *, const struct ether_addr *); -int ether_hostton(const char *, struct ether_addr *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/icmp6.h b/usr/lib/libc/include/netinet/icmp6.h deleted file mode 100644 index 01269e7d4..000000000 --- a/usr/lib/libc/include/netinet/icmp6.h +++ /dev/null @@ -1,305 +0,0 @@ -#ifndef _NETINET_ICMP6_H -#define _NETINET_ICMP6_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#define ICMP6_FILTER 1 - -#define ICMP6_FILTER_BLOCK 1 -#define ICMP6_FILTER_PASS 2 -#define ICMP6_FILTER_BLOCKOTHERS 3 -#define ICMP6_FILTER_PASSONLY 4 - -struct icmp6_filter { - uint32_t icmp6_filt[8]; -}; - -struct icmp6_hdr { - uint8_t icmp6_type; - uint8_t icmp6_code; - uint16_t icmp6_cksum; - union { - uint32_t icmp6_un_data32[1]; - uint16_t icmp6_un_data16[2]; - uint8_t icmp6_un_data8[4]; - } icmp6_dataun; -}; - -#define icmp6_data32 icmp6_dataun.icmp6_un_data32 -#define icmp6_data16 icmp6_dataun.icmp6_un_data16 -#define icmp6_data8 icmp6_dataun.icmp6_un_data8 -#define icmp6_pptr icmp6_data32[0] -#define icmp6_mtu icmp6_data32[0] -#define icmp6_id icmp6_data16[0] -#define icmp6_seq icmp6_data16[1] -#define icmp6_maxdelay icmp6_data16[0] - -#define ICMP6_DST_UNREACH 1 -#define ICMP6_PACKET_TOO_BIG 2 -#define ICMP6_TIME_EXCEEDED 3 -#define ICMP6_PARAM_PROB 4 - -#define ICMP6_INFOMSG_MASK 0x80 - -#define ICMP6_ECHO_REQUEST 128 -#define ICMP6_ECHO_REPLY 129 -#define MLD_LISTENER_QUERY 130 -#define MLD_LISTENER_REPORT 131 -#define MLD_LISTENER_REDUCTION 132 - -#define ICMP6_DST_UNREACH_NOROUTE 0 -#define ICMP6_DST_UNREACH_ADMIN 1 -#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 -#define ICMP6_DST_UNREACH_ADDR 3 -#define ICMP6_DST_UNREACH_NOPORT 4 - -#define ICMP6_TIME_EXCEED_TRANSIT 0 -#define ICMP6_TIME_EXCEED_REASSEMBLY 1 - -#define ICMP6_PARAMPROB_HEADER 0 -#define ICMP6_PARAMPROB_NEXTHEADER 1 -#define ICMP6_PARAMPROB_OPTION 2 - -#define ICMP6_FILTER_WILLPASS(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) - -#define ICMP6_FILTER_WILLBLOCK(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) - -#define ICMP6_FILTER_SETPASS(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))) - -#define ICMP6_FILTER_SETBLOCK(type, filterp) \ - ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))) - -#define ICMP6_FILTER_SETPASSALL(filterp) \ - memset (filterp, 0, sizeof (struct icmp6_filter)); - -#define ICMP6_FILTER_SETBLOCKALL(filterp) \ - memset (filterp, 0xFF, sizeof (struct icmp6_filter)); - -#define ND_ROUTER_SOLICIT 133 -#define ND_ROUTER_ADVERT 134 -#define ND_NEIGHBOR_SOLICIT 135 -#define ND_NEIGHBOR_ADVERT 136 -#define ND_REDIRECT 137 - -struct nd_router_solicit { - struct icmp6_hdr nd_rs_hdr; -}; - -#define nd_rs_type nd_rs_hdr.icmp6_type -#define nd_rs_code nd_rs_hdr.icmp6_code -#define nd_rs_cksum nd_rs_hdr.icmp6_cksum -#define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] - -struct nd_router_advert { - struct icmp6_hdr nd_ra_hdr; - uint32_t nd_ra_reachable; - uint32_t nd_ra_retransmit; -}; - -#define nd_ra_type nd_ra_hdr.icmp6_type -#define nd_ra_code nd_ra_hdr.icmp6_code -#define nd_ra_cksum nd_ra_hdr.icmp6_cksum -#define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] -#define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] -#define ND_RA_FLAG_MANAGED 0x80 -#define ND_RA_FLAG_OTHER 0x40 -#define ND_RA_FLAG_HOME_AGENT 0x20 -#define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] - -struct nd_neighbor_solicit { - struct icmp6_hdr nd_ns_hdr; - struct in6_addr nd_ns_target; -}; - -#define nd_ns_type nd_ns_hdr.icmp6_type -#define nd_ns_code nd_ns_hdr.icmp6_code -#define nd_ns_cksum nd_ns_hdr.icmp6_cksum -#define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] - -struct nd_neighbor_advert { - struct icmp6_hdr nd_na_hdr; - struct in6_addr nd_na_target; -}; - -#define nd_na_type nd_na_hdr.icmp6_type -#define nd_na_code nd_na_hdr.icmp6_code -#define nd_na_cksum nd_na_hdr.icmp6_cksum -#define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] -#if __BYTE_ORDER == __BIG_ENDIAN -#define ND_NA_FLAG_ROUTER 0x80000000 -#define ND_NA_FLAG_SOLICITED 0x40000000 -#define ND_NA_FLAG_OVERRIDE 0x20000000 -#else -#define ND_NA_FLAG_ROUTER 0x00000080 -#define ND_NA_FLAG_SOLICITED 0x00000040 -#define ND_NA_FLAG_OVERRIDE 0x00000020 -#endif - -struct nd_redirect { - struct icmp6_hdr nd_rd_hdr; - struct in6_addr nd_rd_target; - struct in6_addr nd_rd_dst; -}; - -#define nd_rd_type nd_rd_hdr.icmp6_type -#define nd_rd_code nd_rd_hdr.icmp6_code -#define nd_rd_cksum nd_rd_hdr.icmp6_cksum -#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] - -struct nd_opt_hdr { - uint8_t nd_opt_type; - uint8_t nd_opt_len; -}; - -#define ND_OPT_SOURCE_LINKADDR 1 -#define ND_OPT_TARGET_LINKADDR 2 -#define ND_OPT_PREFIX_INFORMATION 3 -#define ND_OPT_REDIRECTED_HEADER 4 -#define ND_OPT_MTU 5 -#define ND_OPT_RTR_ADV_INTERVAL 7 -#define ND_OPT_HOME_AGENT_INFO 8 - -struct nd_opt_prefix_info { - uint8_t nd_opt_pi_type; - uint8_t nd_opt_pi_len; - uint8_t nd_opt_pi_prefix_len; - uint8_t nd_opt_pi_flags_reserved; - uint32_t nd_opt_pi_valid_time; - uint32_t nd_opt_pi_preferred_time; - uint32_t nd_opt_pi_reserved2; - struct in6_addr nd_opt_pi_prefix; -}; - -#define ND_OPT_PI_FLAG_ONLINK 0x80 -#define ND_OPT_PI_FLAG_AUTO 0x40 -#define ND_OPT_PI_FLAG_RADDR 0x20 - -struct nd_opt_rd_hdr { - uint8_t nd_opt_rh_type; - uint8_t nd_opt_rh_len; - uint16_t nd_opt_rh_reserved1; - uint32_t nd_opt_rh_reserved2; -}; - -struct nd_opt_mtu { - uint8_t nd_opt_mtu_type; - uint8_t nd_opt_mtu_len; - uint16_t nd_opt_mtu_reserved; - uint32_t nd_opt_mtu_mtu; -}; - -struct mld_hdr { - struct icmp6_hdr mld_icmp6_hdr; - struct in6_addr mld_addr; -}; - -#define mld_type mld_icmp6_hdr.icmp6_type -#define mld_code mld_icmp6_hdr.icmp6_code -#define mld_cksum mld_icmp6_hdr.icmp6_cksum -#define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] -#define mld_reserved mld_icmp6_hdr.icmp6_data16[1] - -#define ICMP6_ROUTER_RENUMBERING 138 - -struct icmp6_router_renum { - struct icmp6_hdr rr_hdr; - uint8_t rr_segnum; - uint8_t rr_flags; - uint16_t rr_maxdelay; - uint32_t rr_reserved; -}; - -#define rr_type rr_hdr.icmp6_type -#define rr_code rr_hdr.icmp6_code -#define rr_cksum rr_hdr.icmp6_cksum -#define rr_seqnum rr_hdr.icmp6_data32[0] - -#define ICMP6_RR_FLAGS_TEST 0x80 -#define ICMP6_RR_FLAGS_REQRESULT 0x40 -#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 -#define ICMP6_RR_FLAGS_SPECSITE 0x10 -#define ICMP6_RR_FLAGS_PREVDONE 0x08 - -struct rr_pco_match { - uint8_t rpm_code; - uint8_t rpm_len; - uint8_t rpm_ordinal; - uint8_t rpm_matchlen; - uint8_t rpm_minlen; - uint8_t rpm_maxlen; - uint16_t rpm_reserved; - struct in6_addr rpm_prefix; -}; - -#define RPM_PCO_ADD 1 -#define RPM_PCO_CHANGE 2 -#define RPM_PCO_SETGLOBAL 3 - -struct rr_pco_use { - uint8_t rpu_uselen; - uint8_t rpu_keeplen; - uint8_t rpu_ramask; - uint8_t rpu_raflags; - uint32_t rpu_vltime; - uint32_t rpu_pltime; - uint32_t rpu_flags; - struct in6_addr rpu_prefix; -}; - -#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20 -#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10 - -#if __BYTE_ORDER == __BIG_ENDIAN -#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000 -#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000 -#else -#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 -#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 -#endif - -struct rr_result { - uint16_t rrr_flags; - uint8_t rrr_ordinal; - uint8_t rrr_matchedlen; - uint32_t rrr_ifid; - struct in6_addr rrr_prefix; -}; - -#if __BYTE_ORDER == __BIG_ENDIAN -#define ICMP6_RR_RESULT_FLAGS_OOB 0x0002 -#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001 -#else -#define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 -#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 -#endif - -struct nd_opt_adv_interval { - uint8_t nd_opt_adv_interval_type; - uint8_t nd_opt_adv_interval_len; - uint16_t nd_opt_adv_interval_reserved; - uint32_t nd_opt_adv_interval_ival; -}; - -struct nd_opt_home_agent_info { - uint8_t nd_opt_home_agent_info_type; - uint8_t nd_opt_home_agent_info_len; - uint16_t nd_opt_home_agent_info_reserved; - uint16_t nd_opt_home_agent_info_preference; - uint16_t nd_opt_home_agent_info_lifetime; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/if_ether.h b/usr/lib/libc/include/netinet/if_ether.h deleted file mode 100644 index a08485e7f..000000000 --- a/usr/lib/libc/include/netinet/if_ether.h +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef _NETINET_IF_ETHER_H -#define _NETINET_IF_ETHER_H - -#include -#include - -#define ETH_ALEN 6 -#define ETH_TLEN 2 -#define ETH_HLEN 14 -#define ETH_ZLEN 60 -#define ETH_DATA_LEN 1500 -#define ETH_FRAME_LEN 1514 -#define ETH_FCS_LEN 4 -#define ETH_MIN_MTU 68 -#define ETH_MAX_MTU 0xFFFFU - -#define ETH_P_LOOP 0x0060 -#define ETH_P_PUP 0x0200 -#define ETH_P_PUPAT 0x0201 -#define ETH_P_TSN 0x22F0 -#define ETH_P_ERSPAN2 0x22EB -#define ETH_P_IP 0x0800 -#define ETH_P_X25 0x0805 -#define ETH_P_ARP 0x0806 -#define ETH_P_BPQ 0x08FF -#define ETH_P_IEEEPUP 0x0a00 -#define ETH_P_IEEEPUPAT 0x0a01 -#define ETH_P_BATMAN 0x4305 -#define ETH_P_DEC 0x6000 -#define ETH_P_DNA_DL 0x6001 -#define ETH_P_DNA_RC 0x6002 -#define ETH_P_DNA_RT 0x6003 -#define ETH_P_LAT 0x6004 -#define ETH_P_DIAG 0x6005 -#define ETH_P_CUST 0x6006 -#define ETH_P_SCA 0x6007 -#define ETH_P_TEB 0x6558 -#define ETH_P_RARP 0x8035 -#define ETH_P_ATALK 0x809B -#define ETH_P_AARP 0x80F3 -#define ETH_P_8021Q 0x8100 -#define ETH_P_IPX 0x8137 -#define ETH_P_IPV6 0x86DD -#define ETH_P_PAUSE 0x8808 -#define ETH_P_SLOW 0x8809 -#define ETH_P_WCCP 0x883E -#define ETH_P_MPLS_UC 0x8847 -#define ETH_P_MPLS_MC 0x8848 -#define ETH_P_ATMMPOA 0x884c -#define ETH_P_PPP_DISC 0x8863 -#define ETH_P_PPP_SES 0x8864 -#define ETH_P_LINK_CTL 0x886c -#define ETH_P_ATMFATE 0x8884 -#define ETH_P_PAE 0x888E -#define ETH_P_AOE 0x88A2 -#define ETH_P_8021AD 0x88A8 -#define ETH_P_802_EX1 0x88B5 -#define ETH_P_ERSPAN 0x88BE -#define ETH_P_PREAUTH 0x88C7 -#define ETH_P_TIPC 0x88CA -#define ETH_P_LLDP 0x88CC -#define ETH_P_MACSEC 0x88E5 -#define ETH_P_8021AH 0x88E7 -#define ETH_P_MVRP 0x88F5 -#define ETH_P_1588 0x88F7 -#define ETH_P_NCSI 0x88F8 -#define ETH_P_PRP 0x88FB -#define ETH_P_FCOE 0x8906 -#define ETH_P_TDLS 0x890D -#define ETH_P_FIP 0x8914 -#define ETH_P_IBOE 0x8915 -#define ETH_P_80221 0x8917 -#define ETH_P_HSR 0x892F -#define ETH_P_NSH 0x894F -#define ETH_P_LOOPBACK 0x9000 -#define ETH_P_QINQ1 0x9100 -#define ETH_P_QINQ2 0x9200 -#define ETH_P_QINQ3 0x9300 -#define ETH_P_EDSA 0xDADA -#define ETH_P_DSA_8021Q 0xDADB -#define ETH_P_IFE 0xED3E -#define ETH_P_AF_IUCV 0xFBFB - -#define ETH_P_802_3_MIN 0x0600 - -#define ETH_P_802_3 0x0001 -#define ETH_P_AX25 0x0002 -#define ETH_P_ALL 0x0003 -#define ETH_P_802_2 0x0004 -#define ETH_P_SNAP 0x0005 -#define ETH_P_DDCMP 0x0006 -#define ETH_P_WAN_PPP 0x0007 -#define ETH_P_PPP_MP 0x0008 -#define ETH_P_LOCALTALK 0x0009 -#define ETH_P_CAN 0x000C -#define ETH_P_CANFD 0x000D -#define ETH_P_PPPTALK 0x0010 -#define ETH_P_TR_802_2 0x0011 -#define ETH_P_MOBITEX 0x0015 -#define ETH_P_CONTROL 0x0016 -#define ETH_P_IRDA 0x0017 -#define ETH_P_ECONET 0x0018 -#define ETH_P_HDLC 0x0019 -#define ETH_P_ARCNET 0x001A -#define ETH_P_DSA 0x001B -#define ETH_P_TRAILER 0x001C -#define ETH_P_PHONET 0x00F5 -#define ETH_P_IEEE802154 0x00F6 -#define ETH_P_CAIF 0x00F7 -#define ETH_P_XDSA 0x00F8 -#define ETH_P_MAP 0x00F9 - -struct ethhdr { - uint8_t h_dest[ETH_ALEN]; - uint8_t h_source[ETH_ALEN]; - uint16_t h_proto; -}; - -#include -#include - -struct ether_arp { - struct arphdr ea_hdr; - uint8_t arp_sha[ETH_ALEN]; - uint8_t arp_spa[4]; - uint8_t arp_tha[ETH_ALEN]; - uint8_t arp_tpa[4]; -}; -#define arp_hrd ea_hdr.ar_hrd -#define arp_pro ea_hdr.ar_pro -#define arp_hln ea_hdr.ar_hln -#define arp_pln ea_hdr.ar_pln -#define arp_op ea_hdr.ar_op - -#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ -do { \ - (enaddr)[0] = 0x01; \ - (enaddr)[1] = 0x00; \ - (enaddr)[2] = 0x5e; \ - (enaddr)[3] = ((uint8_t *)ipaddr)[1] & 0x7f; \ - (enaddr)[4] = ((uint8_t *)ipaddr)[2]; \ - (enaddr)[5] = ((uint8_t *)ipaddr)[3]; \ -} while(0) - -#define __UAPI_DEF_ETHHDR 0 - -#endif diff --git a/usr/lib/libc/include/netinet/igmp.h b/usr/lib/libc/include/netinet/igmp.h deleted file mode 100644 index bbe8206a1..000000000 --- a/usr/lib/libc/include/netinet/igmp.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _NETINET_IGMP_H -#define _NETINET_IGMP_H - -#include -#include - -struct igmp { - uint8_t igmp_type; - uint8_t igmp_code; - uint16_t igmp_cksum; - struct in_addr igmp_group; -}; - -#define IGMP_MINLEN 8 - -#define IGMP_MEMBERSHIP_QUERY 0x11 -#define IGMP_V1_MEMBERSHIP_REPORT 0x12 -#define IGMP_V2_MEMBERSHIP_REPORT 0x16 -#define IGMP_V2_LEAVE_GROUP 0x17 - -#define IGMP_DVMRP 0x13 -#define IGMP_PIM 0x14 -#define IGMP_TRACE 0x15 - -#define IGMP_MTRACE_RESP 0x1e -#define IGMP_MTRACE 0x1f - -#define IGMP_MAX_HOST_REPORT_DELAY 10 -#define IGMP_TIMER_SCALE 10 - -#define IGMP_DELAYING_MEMBER 1 -#define IGMP_IDLE_MEMBER 2 -#define IGMP_LAZY_MEMBER 3 -#define IGMP_SLEEPING_MEMBER 4 -#define IGMP_AWAKENING_MEMBER 5 - -#define IGMP_v1_ROUTER 1 -#define IGMP_v2_ROUTER 2 - -#define IGMP_HOST_MEMBERSHIP_QUERY IGMP_MEMBERSHIP_QUERY -#define IGMP_HOST_MEMBERSHIP_REPORT IGMP_V1_MEMBERSHIP_REPORT -#define IGMP_HOST_NEW_MEMBERSHIP_REPORT IGMP_V2_MEMBERSHIP_REPORT -#define IGMP_HOST_LEAVE_MESSAGE IGMP_V2_LEAVE_GROUP - -#endif diff --git a/usr/lib/libc/include/netinet/in.h b/usr/lib/libc/include/netinet/in.h deleted file mode 100644 index 5b8b21e64..000000000 --- a/usr/lib/libc/include/netinet/in.h +++ /dev/null @@ -1,415 +0,0 @@ -#ifndef _NETINET_IN_H -#define _NETINET_IN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -typedef uint16_t in_port_t; -typedef uint32_t in_addr_t; -struct in_addr { in_addr_t s_addr; }; - -struct sockaddr_in { - sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - uint8_t sin_zero[8]; -}; - -struct in6_addr { - union { - uint8_t __s6_addr[16]; - uint16_t __s6_addr16[8]; - uint32_t __s6_addr32[4]; - } __in6_union; -}; -#define s6_addr __in6_union.__s6_addr -#define s6_addr16 __in6_union.__s6_addr16 -#define s6_addr32 __in6_union.__s6_addr32 - -struct sockaddr_in6 { - sa_family_t sin6_family; - in_port_t sin6_port; - uint32_t sin6_flowinfo; - struct in6_addr sin6_addr; - uint32_t sin6_scope_id; -}; - -struct ipv6_mreq { - struct in6_addr ipv6mr_multiaddr; - unsigned ipv6mr_interface; -}; - -#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) - -#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) -#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) -#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) -#define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) -#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) - -#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } -#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } - -extern const struct in6_addr in6addr_any, in6addr_loopback; - -#undef INET_ADDRSTRLEN -#undef INET6_ADDRSTRLEN -#define INET_ADDRSTRLEN 16 -#define INET6_ADDRSTRLEN 46 - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -#define IPPORT_RESERVED 1024 - -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IGMP 2 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_EGP 8 -#define IPPROTO_PUP 12 -#define IPPROTO_UDP 17 -#define IPPROTO_IDP 22 -#define IPPROTO_TP 29 -#define IPPROTO_DCCP 33 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_RSVP 46 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_MTP 92 -#define IPPROTO_BEETPH 94 -#define IPPROTO_ENCAP 98 -#define IPPROTO_PIM 103 -#define IPPROTO_COMP 108 -#define IPPROTO_SCTP 132 -#define IPPROTO_MH 135 -#define IPPROTO_UDPLITE 136 -#define IPPROTO_MPLS 137 -#define IPPROTO_RAW 255 -#define IPPROTO_MAX 256 - -#define IN6_IS_ADDR_UNSPECIFIED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) - -#define IN6_IS_ADDR_LOOPBACK(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && \ - ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ - ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) - -#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) - -#define IN6_IS_ADDR_LINKLOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) - -#define IN6_IS_ADDR_SITELOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) - -#define IN6_IS_ADDR_V4MAPPED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ - ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) - -#define IN6_IS_ADDR_V4COMPAT(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) - -#define IN6_IS_ADDR_MC_NODELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) - -#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) - -#define IN6_IS_ADDR_MC_SITELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) - -#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) - -#define IN6_IS_ADDR_MC_GLOBAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) - -#define __ARE_4_EQUAL(a,b) \ - (!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) -#define IN6_ARE_ADDR_EQUAL(a,b) \ - __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) - -#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) -#define IN_CLASSA_NET 0xff000000 -#define IN_CLASSA_NSHIFT 24 -#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) -#define IN_CLASSA_MAX 128 -#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) -#define IN_CLASSB_NET 0xffff0000 -#define IN_CLASSB_NSHIFT 16 -#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) -#define IN_CLASSB_MAX 65536 -#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) -#define IN_CLASSC_NET 0xffffff00 -#define IN_CLASSC_NSHIFT 8 -#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) -#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) -#define IN_MULTICAST(a) IN_CLASSD(a) -#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) -#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) - -#define IN_LOOPBACKNET 127 - - -#define IP_TOS 1 -#define IP_TTL 2 -#define IP_HDRINCL 3 -#define IP_OPTIONS 4 -#define IP_ROUTER_ALERT 5 -#define IP_RECVOPTS 6 -#define IP_RETOPTS 7 -#define IP_PKTINFO 8 -#define IP_PKTOPTIONS 9 -#define IP_PMTUDISC 10 -#define IP_MTU_DISCOVER 10 -#define IP_RECVERR 11 -#define IP_RECVTTL 12 -#define IP_RECVTOS 13 -#define IP_MTU 14 -#define IP_FREEBIND 15 -#define IP_IPSEC_POLICY 16 -#define IP_XFRM_POLICY 17 -#define IP_PASSSEC 18 -#define IP_TRANSPARENT 19 -#define IP_ORIGDSTADDR 20 -#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR -#define IP_MINTTL 21 -#define IP_NODEFRAG 22 -#define IP_CHECKSUM 23 -#define IP_BIND_ADDRESS_NO_PORT 24 -#define IP_RECVFRAGSIZE 25 -#define IP_MULTICAST_IF 32 -#define IP_MULTICAST_TTL 33 -#define IP_MULTICAST_LOOP 34 -#define IP_ADD_MEMBERSHIP 35 -#define IP_DROP_MEMBERSHIP 36 -#define IP_UNBLOCK_SOURCE 37 -#define IP_BLOCK_SOURCE 38 -#define IP_ADD_SOURCE_MEMBERSHIP 39 -#define IP_DROP_SOURCE_MEMBERSHIP 40 -#define IP_MSFILTER 41 -#define IP_MULTICAST_ALL 49 -#define IP_UNICAST_IF 50 - -#define IP_RECVRETOPTS IP_RETOPTS - -#define IP_PMTUDISC_DONT 0 -#define IP_PMTUDISC_WANT 1 -#define IP_PMTUDISC_DO 2 -#define IP_PMTUDISC_PROBE 3 -#define IP_PMTUDISC_INTERFACE 4 -#define IP_PMTUDISC_OMIT 5 - -#define IP_DEFAULT_MULTICAST_TTL 1 -#define IP_DEFAULT_MULTICAST_LOOP 1 -#define IP_MAX_MEMBERSHIPS 20 - -struct ip_opts { - struct in_addr ip_dst; - char ip_opts[40]; -}; - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define MCAST_JOIN_GROUP 42 -#define MCAST_BLOCK_SOURCE 43 -#define MCAST_UNBLOCK_SOURCE 44 -#define MCAST_LEAVE_GROUP 45 -#define MCAST_JOIN_SOURCE_GROUP 46 -#define MCAST_LEAVE_SOURCE_GROUP 47 -#define MCAST_MSFILTER 48 - -#define MCAST_EXCLUDE 0 -#define MCAST_INCLUDE 1 - -struct ip_mreq { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; -}; - -struct ip_mreqn { - struct in_addr imr_multiaddr; - struct in_addr imr_address; - int imr_ifindex; -}; - -struct ip_mreq_source { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; - struct in_addr imr_sourceaddr; -}; - -struct ip_msfilter { - struct in_addr imsf_multiaddr; - struct in_addr imsf_interface; - uint32_t imsf_fmode; - uint32_t imsf_numsrc; - struct in_addr imsf_slist[1]; -}; -#define IP_MSFILTER_SIZE(numsrc) \ - (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \ - + (numsrc) * sizeof(struct in_addr)) - -struct group_req { - uint32_t gr_interface; - struct sockaddr_storage gr_group; -}; - -struct group_source_req { - uint32_t gsr_interface; - struct sockaddr_storage gsr_group; - struct sockaddr_storage gsr_source; -}; - -struct group_filter { - uint32_t gf_interface; - struct sockaddr_storage gf_group; - uint32_t gf_fmode; - uint32_t gf_numsrc; - struct sockaddr_storage gf_slist[1]; -}; -#define GROUP_FILTER_SIZE(numsrc) \ - (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \ - + (numsrc) * sizeof(struct sockaddr_storage)) - -struct in_pktinfo { - int ipi_ifindex; - struct in_addr ipi_spec_dst; - struct in_addr ipi_addr; -}; - -struct in6_pktinfo { - struct in6_addr ipi6_addr; - unsigned ipi6_ifindex; -}; - -struct ip6_mtuinfo { - struct sockaddr_in6 ip6m_addr; - uint32_t ip6m_mtu; -}; -#endif - -#define IPV6_ADDRFORM 1 -#define IPV6_2292PKTINFO 2 -#define IPV6_2292HOPOPTS 3 -#define IPV6_2292DSTOPTS 4 -#define IPV6_2292RTHDR 5 -#define IPV6_2292PKTOPTIONS 6 -#define IPV6_CHECKSUM 7 -#define IPV6_2292HOPLIMIT 8 -#define IPV6_NEXTHOP 9 -#define IPV6_AUTHHDR 10 -#define IPV6_UNICAST_HOPS 16 -#define IPV6_MULTICAST_IF 17 -#define IPV6_MULTICAST_HOPS 18 -#define IPV6_MULTICAST_LOOP 19 -#define IPV6_JOIN_GROUP 20 -#define IPV6_LEAVE_GROUP 21 -#define IPV6_ROUTER_ALERT 22 -#define IPV6_MTU_DISCOVER 23 -#define IPV6_MTU 24 -#define IPV6_RECVERR 25 -#define IPV6_V6ONLY 26 -#define IPV6_JOIN_ANYCAST 27 -#define IPV6_LEAVE_ANYCAST 28 -#define IPV6_MULTICAST_ALL 29 -#define IPV6_ROUTER_ALERT_ISOLATE 30 -#define IPV6_IPSEC_POLICY 34 -#define IPV6_XFRM_POLICY 35 -#define IPV6_HDRINCL 36 - -#define IPV6_RECVPKTINFO 49 -#define IPV6_PKTINFO 50 -#define IPV6_RECVHOPLIMIT 51 -#define IPV6_HOPLIMIT 52 -#define IPV6_RECVHOPOPTS 53 -#define IPV6_HOPOPTS 54 -#define IPV6_RTHDRDSTOPTS 55 -#define IPV6_RECVRTHDR 56 -#define IPV6_RTHDR 57 -#define IPV6_RECVDSTOPTS 58 -#define IPV6_DSTOPTS 59 -#define IPV6_RECVPATHMTU 60 -#define IPV6_PATHMTU 61 -#define IPV6_DONTFRAG 62 -#define IPV6_RECVTCLASS 66 -#define IPV6_TCLASS 67 -#define IPV6_AUTOFLOWLABEL 70 -#define IPV6_ADDR_PREFERENCES 72 -#define IPV6_MINHOPCOUNT 73 -#define IPV6_ORIGDSTADDR 74 -#define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR -#define IPV6_TRANSPARENT 75 -#define IPV6_UNICAST_IF 76 -#define IPV6_RECVFRAGSIZE 77 -#define IPV6_FREEBIND 78 - -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -#define IPV6_RXHOPOPTS IPV6_HOPOPTS -#define IPV6_RXDSTOPTS IPV6_DSTOPTS - -#define IPV6_PMTUDISC_DONT 0 -#define IPV6_PMTUDISC_WANT 1 -#define IPV6_PMTUDISC_DO 2 -#define IPV6_PMTUDISC_PROBE 3 -#define IPV6_PMTUDISC_INTERFACE 4 -#define IPV6_PMTUDISC_OMIT 5 - -#define IPV6_PREFER_SRC_TMP 0x0001 -#define IPV6_PREFER_SRC_PUBLIC 0x0002 -#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 -#define IPV6_PREFER_SRC_COA 0x0004 -#define IPV6_PREFER_SRC_HOME 0x0400 -#define IPV6_PREFER_SRC_CGA 0x0008 -#define IPV6_PREFER_SRC_NONCGA 0x0800 - -#define IPV6_RTHDR_LOOSE 0 -#define IPV6_RTHDR_STRICT 1 - -#define IPV6_RTHDR_TYPE_0 0 - -#define __UAPI_DEF_IN_ADDR 0 -#define __UAPI_DEF_IN_IPPROTO 0 -#define __UAPI_DEF_IN_PKTINFO 0 -#define __UAPI_DEF_IP_MREQ 0 -#define __UAPI_DEF_SOCKADDR_IN 0 -#define __UAPI_DEF_IN_CLASS 0 -#define __UAPI_DEF_IN6_ADDR 0 -#define __UAPI_DEF_IN6_ADDR_ALT 0 -#define __UAPI_DEF_SOCKADDR_IN6 0 -#define __UAPI_DEF_IPV6_MREQ 0 -#define __UAPI_DEF_IPPROTO_V6 0 -#define __UAPI_DEF_IPV6_OPTIONS 0 -#define __UAPI_DEF_IN6_PKTINFO 0 -#define __UAPI_DEF_IP6_MTUINFO 0 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/in_systm.h b/usr/lib/libc/include/netinet/in_systm.h deleted file mode 100644 index a7b417722..000000000 --- a/usr/lib/libc/include/netinet/in_systm.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _NETINET_IN_SYSTM_H -#define _NETINET_IN_SYSTM_H - -#include - -typedef uint16_t n_short; -typedef uint32_t n_long, n_time; - -#endif diff --git a/usr/lib/libc/include/netinet/ip.h b/usr/lib/libc/include/netinet/ip.h deleted file mode 100644 index 0ae132a58..000000000 --- a/usr/lib/libc/include/netinet/ip.h +++ /dev/null @@ -1,199 +0,0 @@ -#ifndef _NETINET_IP_H -#define _NETINET_IP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -struct timestamp { - uint8_t len; - uint8_t ptr; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int flags:4; - unsigned int overflow:4; -#else - unsigned int overflow:4; - unsigned int flags:4; -#endif - uint32_t data[9]; - }; - -struct iphdr { -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ihl:4; - unsigned int version:4; -#else - unsigned int version:4; - unsigned int ihl:4; -#endif - uint8_t tos; - uint16_t tot_len; - uint16_t id; - uint16_t frag_off; - uint8_t ttl; - uint8_t protocol; - uint16_t check; - uint32_t saddr; - uint32_t daddr; -}; - -struct ip { -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ip_hl:4; - unsigned int ip_v:4; -#else - unsigned int ip_v:4; - unsigned int ip_hl:4; -#endif - uint8_t ip_tos; - uint16_t ip_len; - uint16_t ip_id; - uint16_t ip_off; - uint8_t ip_ttl; - uint8_t ip_p; - uint16_t ip_sum; - struct in_addr ip_src, ip_dst; -}; - -#define IP_RF 0x8000 -#define IP_DF 0x4000 -#define IP_MF 0x2000 -#define IP_OFFMASK 0x1fff - -struct ip_timestamp { - uint8_t ipt_code; - uint8_t ipt_len; - uint8_t ipt_ptr; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int ipt_flg:4; - unsigned int ipt_oflw:4; -#else - unsigned int ipt_oflw:4; - unsigned int ipt_flg:4; -#endif - uint32_t data[9]; -}; - -#define IPVERSION 4 -#define IP_MAXPACKET 65535 - -#define IPTOS_ECN_MASK 0x03 -#define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) -#define IPTOS_ECN_NOT_ECT 0x00 -#define IPTOS_ECN_ECT1 0x01 -#define IPTOS_ECN_ECT0 0x02 -#define IPTOS_ECN_CE 0x03 - -#define IPTOS_DSCP_MASK 0xfc -#define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK) -#define IPTOS_DSCP_AF11 0x28 -#define IPTOS_DSCP_AF12 0x30 -#define IPTOS_DSCP_AF13 0x38 -#define IPTOS_DSCP_AF21 0x48 -#define IPTOS_DSCP_AF22 0x50 -#define IPTOS_DSCP_AF23 0x58 -#define IPTOS_DSCP_AF31 0x68 -#define IPTOS_DSCP_AF32 0x70 -#define IPTOS_DSCP_AF33 0x78 -#define IPTOS_DSCP_AF41 0x88 -#define IPTOS_DSCP_AF42 0x90 -#define IPTOS_DSCP_AF43 0x98 -#define IPTOS_DSCP_EF 0xb8 - -#define IPTOS_CLASS_MASK 0xe0 -#define IPTOS_CLASS(x) ((x) & IPTOS_CLASS_MASK) -#define IPTOS_CLASS_CS0 0x00 -#define IPTOS_CLASS_CS1 0x20 -#define IPTOS_CLASS_CS2 0x40 -#define IPTOS_CLASS_CS3 0x60 -#define IPTOS_CLASS_CS4 0x80 -#define IPTOS_CLASS_CS5 0xa0 -#define IPTOS_CLASS_CS6 0xc0 -#define IPTOS_CLASS_CS7 0xe0 -#define IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0 - -#define IPTOS_TOS_MASK 0x1E -#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) -#define IPTOS_LOWDELAY 0x10 -#define IPTOS_THROUGHPUT 0x08 -#define IPTOS_RELIABILITY 0x04 -#define IPTOS_LOWCOST 0x02 -#define IPTOS_MINCOST IPTOS_LOWCOST - -#define IPTOS_PREC_MASK 0xe0 -#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) -#define IPTOS_PREC_NETCONTROL 0xe0 -#define IPTOS_PREC_INTERNETCONTROL 0xc0 -#define IPTOS_PREC_CRITIC_ECP 0xa0 -#define IPTOS_PREC_FLASHOVERRIDE 0x80 -#define IPTOS_PREC_FLASH 0x60 -#define IPTOS_PREC_IMMEDIATE 0x40 -#define IPTOS_PREC_PRIORITY 0x20 -#define IPTOS_PREC_ROUTINE 0x00 - -#define IPOPT_COPY 0x80 -#define IPOPT_CLASS_MASK 0x60 -#define IPOPT_NUMBER_MASK 0x1f - -#define IPOPT_COPIED(o) ((o) & IPOPT_COPY) -#define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK) -#define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK) - -#define IPOPT_CONTROL 0x00 -#define IPOPT_RESERVED1 0x20 -#define IPOPT_DEBMEAS 0x40 -#define IPOPT_MEASUREMENT IPOPT_DEBMEAS -#define IPOPT_RESERVED2 0x60 - -#define IPOPT_EOL 0 -#define IPOPT_END IPOPT_EOL -#define IPOPT_NOP 1 -#define IPOPT_NOOP IPOPT_NOP - -#define IPOPT_RR 7 -#define IPOPT_TS 68 -#define IPOPT_TIMESTAMP IPOPT_TS -#define IPOPT_SECURITY 130 -#define IPOPT_SEC IPOPT_SECURITY -#define IPOPT_LSRR 131 -#define IPOPT_SATID 136 -#define IPOPT_SID IPOPT_SATID -#define IPOPT_SSRR 137 -#define IPOPT_RA 148 - -#define IPOPT_OPTVAL 0 -#define IPOPT_OLEN 1 -#define IPOPT_OFFSET 2 -#define IPOPT_MINOFF 4 - -#define MAX_IPOPTLEN 40 - -#define IPOPT_TS_TSONLY 0 -#define IPOPT_TS_TSANDADDR 1 -#define IPOPT_TS_PRESPEC 3 - -#define IPOPT_SECUR_UNCLASS 0x0000 -#define IPOPT_SECUR_CONFID 0xf135 -#define IPOPT_SECUR_EFTO 0x789a -#define IPOPT_SECUR_MMMM 0xbc4d -#define IPOPT_SECUR_RESTR 0xaf13 -#define IPOPT_SECUR_SECRET 0xd788 -#define IPOPT_SECUR_TOPSECRET 0x6bc5 - -#define MAXTTL 255 -#define IPDEFTTL 64 -#define IPFRAGTTL 60 -#define IPTTLDEC 1 - -#define IP_MSS 576 - -#define __UAPI_DEF_IPHDR 0 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/ip6.h b/usr/lib/libc/include/netinet/ip6.h deleted file mode 100644 index 50c626a69..000000000 --- a/usr/lib/libc/include/netinet/ip6.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef _NETINET_IP6_H -#define _NETINET_IP6_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -struct ip6_hdr { - union { - struct ip6_hdrctl { - uint32_t ip6_un1_flow; - uint16_t ip6_un1_plen; - uint8_t ip6_un1_nxt; - uint8_t ip6_un1_hlim; - } ip6_un1; - uint8_t ip6_un2_vfc; - } ip6_ctlun; - struct in6_addr ip6_src; - struct in6_addr ip6_dst; -}; - -#define ip6_vfc ip6_ctlun.ip6_un2_vfc -#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow -#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen -#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt -#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim -#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim - -struct ip6_ext { - uint8_t ip6e_nxt; - uint8_t ip6e_len; -}; - -struct ip6_hbh { - uint8_t ip6h_nxt; - uint8_t ip6h_len; -}; - -struct ip6_dest { - uint8_t ip6d_nxt; - uint8_t ip6d_len; -}; - -struct ip6_rthdr { - uint8_t ip6r_nxt; - uint8_t ip6r_len; - uint8_t ip6r_type; - uint8_t ip6r_segleft; -}; - -struct ip6_rthdr0 { - uint8_t ip6r0_nxt; - uint8_t ip6r0_len; - uint8_t ip6r0_type; - uint8_t ip6r0_segleft; - uint8_t ip6r0_reserved; - uint8_t ip6r0_slmap[3]; - struct in6_addr ip6r0_addr[]; -}; - -struct ip6_frag { - uint8_t ip6f_nxt; - uint8_t ip6f_reserved; - uint16_t ip6f_offlg; - uint32_t ip6f_ident; -}; - -#if __BYTE_ORDER == __BIG_ENDIAN -#define IP6F_OFF_MASK 0xfff8 -#define IP6F_RESERVED_MASK 0x0006 -#define IP6F_MORE_FRAG 0x0001 -#else -#define IP6F_OFF_MASK 0xf8ff -#define IP6F_RESERVED_MASK 0x0600 -#define IP6F_MORE_FRAG 0x0100 -#endif - -struct ip6_opt { - uint8_t ip6o_type; - uint8_t ip6o_len; -}; - -#define IP6OPT_TYPE(o) ((o) & 0xc0) -#define IP6OPT_TYPE_SKIP 0x00 -#define IP6OPT_TYPE_DISCARD 0x40 -#define IP6OPT_TYPE_FORCEICMP 0x80 -#define IP6OPT_TYPE_ICMP 0xc0 -#define IP6OPT_TYPE_MUTABLE 0x20 - -#define IP6OPT_PAD1 0 -#define IP6OPT_PADN 1 - -#define IP6OPT_JUMBO 0xc2 -#define IP6OPT_NSAP_ADDR 0xc3 -#define IP6OPT_TUNNEL_LIMIT 0x04 -#define IP6OPT_ROUTER_ALERT 0x05 - -struct ip6_opt_jumbo { - uint8_t ip6oj_type; - uint8_t ip6oj_len; - uint8_t ip6oj_jumbo_len[4]; -}; -#define IP6OPT_JUMBO_LEN 6 - -struct ip6_opt_nsap { - uint8_t ip6on_type; - uint8_t ip6on_len; - uint8_t ip6on_src_nsap_len; - uint8_t ip6on_dst_nsap_len; -}; - -struct ip6_opt_tunnel { - uint8_t ip6ot_type; - uint8_t ip6ot_len; - uint8_t ip6ot_encap_limit; -}; - -struct ip6_opt_router { - uint8_t ip6or_type; - uint8_t ip6or_len; - uint8_t ip6or_value[2]; -}; - -#if __BYTE_ORDER == __BIG_ENDIAN -#define IP6_ALERT_MLD 0x0000 -#define IP6_ALERT_RSVP 0x0001 -#define IP6_ALERT_AN 0x0002 -#else -#define IP6_ALERT_MLD 0x0000 -#define IP6_ALERT_RSVP 0x0100 -#define IP6_ALERT_AN 0x0200 -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/ip_icmp.h b/usr/lib/libc/include/netinet/ip_icmp.h deleted file mode 100644 index b9e0df899..000000000 --- a/usr/lib/libc/include/netinet/ip_icmp.h +++ /dev/null @@ -1,193 +0,0 @@ -#ifndef _NETINET_IP_ICMP_H -#define _NETINET_IP_ICMP_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct icmphdr { - uint8_t type; - uint8_t code; - uint16_t checksum; - union { - struct { - uint16_t id; - uint16_t sequence; - } echo; - uint32_t gateway; - struct { - uint16_t __unused; - uint16_t mtu; - } frag; - uint8_t reserved[4]; - } un; -}; - -#define ICMP_ECHOREPLY 0 -#define ICMP_DEST_UNREACH 3 -#define ICMP_SOURCE_QUENCH 4 -#define ICMP_REDIRECT 5 -#define ICMP_ECHO 8 -#define ICMP_TIME_EXCEEDED 11 -#define ICMP_PARAMETERPROB 12 -#define ICMP_TIMESTAMP 13 -#define ICMP_TIMESTAMPREPLY 14 -#define ICMP_INFO_REQUEST 15 -#define ICMP_INFO_REPLY 16 -#define ICMP_ADDRESS 17 -#define ICMP_ADDRESSREPLY 18 -#define NR_ICMP_TYPES 18 - - -#define ICMP_NET_UNREACH 0 -#define ICMP_HOST_UNREACH 1 -#define ICMP_PROT_UNREACH 2 -#define ICMP_PORT_UNREACH 3 -#define ICMP_FRAG_NEEDED 4 -#define ICMP_SR_FAILED 5 -#define ICMP_NET_UNKNOWN 6 -#define ICMP_HOST_UNKNOWN 7 -#define ICMP_HOST_ISOLATED 8 -#define ICMP_NET_ANO 9 -#define ICMP_HOST_ANO 10 -#define ICMP_NET_UNR_TOS 11 -#define ICMP_HOST_UNR_TOS 12 -#define ICMP_PKT_FILTERED 13 -#define ICMP_PREC_VIOLATION 14 -#define ICMP_PREC_CUTOFF 15 -#define NR_ICMP_UNREACH 15 - -#define ICMP_REDIR_NET 0 -#define ICMP_REDIR_HOST 1 -#define ICMP_REDIR_NETTOS 2 -#define ICMP_REDIR_HOSTTOS 3 - -#define ICMP_EXC_TTL 0 -#define ICMP_EXC_FRAGTIME 1 - - -struct icmp_ra_addr { - uint32_t ira_addr; - uint32_t ira_preference; -}; - -struct icmp { - uint8_t icmp_type; - uint8_t icmp_code; - uint16_t icmp_cksum; - union { - uint8_t ih_pptr; - struct in_addr ih_gwaddr; - struct ih_idseq { - uint16_t icd_id; - uint16_t icd_seq; - } ih_idseq; - uint32_t ih_void; - - struct ih_pmtu { - uint16_t ipm_void; - uint16_t ipm_nextmtu; - } ih_pmtu; - - struct ih_rtradv { - uint8_t irt_num_addrs; - uint8_t irt_wpa; - uint16_t irt_lifetime; - } ih_rtradv; - } icmp_hun; - union { - struct { - uint32_t its_otime; - uint32_t its_rtime; - uint32_t its_ttime; - } id_ts; - struct { - struct ip idi_ip; - } id_ip; - struct icmp_ra_addr id_radv; - uint32_t id_mask; - uint8_t id_data[1]; - } icmp_dun; -}; - -#define icmp_pptr icmp_hun.ih_pptr -#define icmp_gwaddr icmp_hun.ih_gwaddr -#define icmp_id icmp_hun.ih_idseq.icd_id -#define icmp_seq icmp_hun.ih_idseq.icd_seq -#define icmp_void icmp_hun.ih_void -#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void -#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu -#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs -#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa -#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime -#define icmp_otime icmp_dun.id_ts.its_otime -#define icmp_rtime icmp_dun.id_ts.its_rtime -#define icmp_ttime icmp_dun.id_ts.its_ttime -#define icmp_ip icmp_dun.id_ip.idi_ip -#define icmp_radv icmp_dun.id_radv -#define icmp_mask icmp_dun.id_mask -#define icmp_data icmp_dun.id_data - -#define ICMP_MINLEN 8 -#define ICMP_TSLEN (8 + 3 * sizeof (n_time)) -#define ICMP_MASKLEN 12 -#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) -#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) - -#define ICMP_UNREACH 3 -#define ICMP_SOURCEQUENCH 4 -#define ICMP_ROUTERADVERT 9 -#define ICMP_ROUTERSOLICIT 10 -#define ICMP_TIMXCEED 11 -#define ICMP_PARAMPROB 12 -#define ICMP_TSTAMP 13 -#define ICMP_TSTAMPREPLY 14 -#define ICMP_IREQ 15 -#define ICMP_IREQREPLY 16 -#define ICMP_MASKREQ 17 -#define ICMP_MASKREPLY 18 -#define ICMP_MAXTYPE 18 - -#define ICMP_UNREACH_NET 0 -#define ICMP_UNREACH_HOST 1 -#define ICMP_UNREACH_PROTOCOL 2 -#define ICMP_UNREACH_PORT 3 -#define ICMP_UNREACH_NEEDFRAG 4 -#define ICMP_UNREACH_SRCFAIL 5 -#define ICMP_UNREACH_NET_UNKNOWN 6 -#define ICMP_UNREACH_HOST_UNKNOWN 7 -#define ICMP_UNREACH_ISOLATED 8 -#define ICMP_UNREACH_NET_PROHIB 9 -#define ICMP_UNREACH_HOST_PROHIB 10 -#define ICMP_UNREACH_TOSNET 11 -#define ICMP_UNREACH_TOSHOST 12 -#define ICMP_UNREACH_FILTER_PROHIB 13 -#define ICMP_UNREACH_HOST_PRECEDENCE 14 -#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 - -#define ICMP_REDIRECT_NET 0 -#define ICMP_REDIRECT_HOST 1 -#define ICMP_REDIRECT_TOSNET 2 -#define ICMP_REDIRECT_TOSHOST 3 - -#define ICMP_TIMXCEED_INTRANS 0 -#define ICMP_TIMXCEED_REASS 1 - -#define ICMP_PARAMPROB_OPTABSENT 1 - -#define ICMP_INFOTYPE(type) \ - ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ - (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ - (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ - (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ - (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/tcp.h b/usr/lib/libc/include/netinet/tcp.h deleted file mode 100644 index 44a007aaf..000000000 --- a/usr/lib/libc/include/netinet/tcp.h +++ /dev/null @@ -1,282 +0,0 @@ -#ifndef _NETINET_TCP_H -#define _NETINET_TCP_H - -#include - -#define TCP_NODELAY 1 -#define TCP_MAXSEG 2 -#define TCP_CORK 3 -#define TCP_KEEPIDLE 4 -#define TCP_KEEPINTVL 5 -#define TCP_KEEPCNT 6 -#define TCP_SYNCNT 7 -#define TCP_LINGER2 8 -#define TCP_DEFER_ACCEPT 9 -#define TCP_WINDOW_CLAMP 10 -#define TCP_INFO 11 -#define TCP_QUICKACK 12 -#define TCP_CONGESTION 13 -#define TCP_MD5SIG 14 -#define TCP_THIN_LINEAR_TIMEOUTS 16 -#define TCP_THIN_DUPACK 17 -#define TCP_USER_TIMEOUT 18 -#define TCP_REPAIR 19 -#define TCP_REPAIR_QUEUE 20 -#define TCP_QUEUE_SEQ 21 -#define TCP_REPAIR_OPTIONS 22 -#define TCP_FASTOPEN 23 -#define TCP_TIMESTAMP 24 -#define TCP_NOTSENT_LOWAT 25 -#define TCP_CC_INFO 26 -#define TCP_SAVE_SYN 27 -#define TCP_SAVED_SYN 28 -#define TCP_REPAIR_WINDOW 29 -#define TCP_FASTOPEN_CONNECT 30 -#define TCP_ULP 31 -#define TCP_MD5SIG_EXT 32 -#define TCP_FASTOPEN_KEY 33 -#define TCP_FASTOPEN_NO_COOKIE 34 -#define TCP_ZEROCOPY_RECEIVE 35 -#define TCP_INQ 36 -#define TCP_TX_DELAY 37 - -#define TCP_CM_INQ TCP_INQ - -#define TCP_ESTABLISHED 1 -#define TCP_SYN_SENT 2 -#define TCP_SYN_RECV 3 -#define TCP_FIN_WAIT1 4 -#define TCP_FIN_WAIT2 5 -#define TCP_TIME_WAIT 6 -#define TCP_CLOSE 7 -#define TCP_CLOSE_WAIT 8 -#define TCP_LAST_ACK 9 -#define TCP_LISTEN 10 -#define TCP_CLOSING 11 - -enum { - TCP_NLA_PAD, - TCP_NLA_BUSY, - TCP_NLA_RWND_LIMITED, - TCP_NLA_SNDBUF_LIMITED, - TCP_NLA_DATA_SEGS_OUT, - TCP_NLA_TOTAL_RETRANS, - TCP_NLA_PACING_RATE, - TCP_NLA_DELIVERY_RATE, - TCP_NLA_SND_CWND, - TCP_NLA_REORDERING, - TCP_NLA_MIN_RTT, - TCP_NLA_RECUR_RETRANS, - TCP_NLA_DELIVERY_RATE_APP_LMT, - TCP_NLA_SNDQ_SIZE, - TCP_NLA_CA_STATE, - TCP_NLA_SND_SSTHRESH, - TCP_NLA_DELIVERED, - TCP_NLA_DELIVERED_CE, - TCP_NLA_BYTES_SENT, - TCP_NLA_BYTES_RETRANS, - TCP_NLA_DSACK_DUPS, - TCP_NLA_REORD_SEEN, - TCP_NLA_SRTT, -}; - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define TCPOPT_EOL 0 -#define TCPOPT_NOP 1 -#define TCPOPT_MAXSEG 2 -#define TCPOPT_WINDOW 3 -#define TCPOPT_SACK_PERMITTED 4 -#define TCPOPT_SACK 5 -#define TCPOPT_TIMESTAMP 8 -#define TCPOLEN_SACK_PERMITTED 2 -#define TCPOLEN_WINDOW 3 -#define TCPOLEN_MAXSEG 4 -#define TCPOLEN_TIMESTAMP 10 - -#define SOL_TCP 6 - -#include -#include -#include - -typedef uint32_t tcp_seq; - -#define TH_FIN 0x01 -#define TH_SYN 0x02 -#define TH_RST 0x04 -#define TH_PUSH 0x08 -#define TH_ACK 0x10 -#define TH_URG 0x20 - -struct tcphdr { -#ifdef _GNU_SOURCE -#ifdef __GNUC__ - __extension__ -#endif - union { struct { - - uint16_t source; - uint16_t dest; - uint32_t seq; - uint32_t ack_seq; -#if __BYTE_ORDER == __LITTLE_ENDIAN - uint16_t res1:4; - uint16_t doff:4; - uint16_t fin:1; - uint16_t syn:1; - uint16_t rst:1; - uint16_t psh:1; - uint16_t ack:1; - uint16_t urg:1; - uint16_t res2:2; -#else - uint16_t doff:4; - uint16_t res1:4; - uint16_t res2:2; - uint16_t urg:1; - uint16_t ack:1; - uint16_t psh:1; - uint16_t rst:1; - uint16_t syn:1; - uint16_t fin:1; -#endif - uint16_t window; - uint16_t check; - uint16_t urg_ptr; - - }; struct { -#endif - - uint16_t th_sport; - uint16_t th_dport; - uint32_t th_seq; - uint32_t th_ack; -#if __BYTE_ORDER == __LITTLE_ENDIAN - uint8_t th_x2:4; - uint8_t th_off:4; -#else - uint8_t th_off:4; - uint8_t th_x2:4; -#endif - uint8_t th_flags; - uint16_t th_win; - uint16_t th_sum; - uint16_t th_urp; - -#ifdef _GNU_SOURCE - }; }; -#endif -}; -#endif - -#ifdef _GNU_SOURCE -#define TCPI_OPT_TIMESTAMPS 1 -#define TCPI_OPT_SACK 2 -#define TCPI_OPT_WSCALE 4 -#define TCPI_OPT_ECN 8 - -#define TCP_CA_Open 0 -#define TCP_CA_Disorder 1 -#define TCP_CA_CWR 2 -#define TCP_CA_Recovery 3 -#define TCP_CA_Loss 4 - -struct tcp_info { - uint8_t tcpi_state; - uint8_t tcpi_ca_state; - uint8_t tcpi_retransmits; - uint8_t tcpi_probes; - uint8_t tcpi_backoff; - uint8_t tcpi_options; - uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; - uint8_t tcpi_delivery_rate_app_limited : 1; - uint32_t tcpi_rto; - uint32_t tcpi_ato; - uint32_t tcpi_snd_mss; - uint32_t tcpi_rcv_mss; - uint32_t tcpi_unacked; - uint32_t tcpi_sacked; - uint32_t tcpi_lost; - uint32_t tcpi_retrans; - uint32_t tcpi_fackets; - uint32_t tcpi_last_data_sent; - uint32_t tcpi_last_ack_sent; - uint32_t tcpi_last_data_recv; - uint32_t tcpi_last_ack_recv; - uint32_t tcpi_pmtu; - uint32_t tcpi_rcv_ssthresh; - uint32_t tcpi_rtt; - uint32_t tcpi_rttvar; - uint32_t tcpi_snd_ssthresh; - uint32_t tcpi_snd_cwnd; - uint32_t tcpi_advmss; - uint32_t tcpi_reordering; - uint32_t tcpi_rcv_rtt; - uint32_t tcpi_rcv_space; - uint32_t tcpi_total_retrans; - uint64_t tcpi_pacing_rate; - uint64_t tcpi_max_pacing_rate; - uint64_t tcpi_bytes_acked; - uint64_t tcpi_bytes_received; - uint32_t tcpi_segs_out; - uint32_t tcpi_segs_in; - uint32_t tcpi_notsent_bytes; - uint32_t tcpi_min_rtt; - uint32_t tcpi_data_segs_in; - uint32_t tcpi_data_segs_out; - uint64_t tcpi_delivery_rate; - uint64_t tcpi_busy_time; - uint64_t tcpi_rwnd_limited; - uint64_t tcpi_sndbuf_limited; - uint32_t tcpi_delivered; - uint32_t tcpi_delivered_ce; - uint64_t tcpi_bytes_sent; - uint64_t tcpi_bytes_retrans; - uint32_t tcpi_dsack_dups; - uint32_t tcpi_reord_seen; - uint32_t tcpi_rcv_ooopack; - uint32_t tcpi_snd_wnd; -}; - -#define TCP_MD5SIG_MAXKEYLEN 80 - -#define TCP_MD5SIG_FLAG_PREFIX 1 - -struct tcp_md5sig { - struct sockaddr_storage tcpm_addr; - uint8_t tcpm_flags; - uint8_t tcpm_prefixlen; - uint16_t tcpm_keylen; - uint32_t __tcpm_pad; - uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; -}; - -struct tcp_diag_md5sig { - uint8_t tcpm_family; - uint8_t tcpm_prefixlen; - uint16_t tcpm_keylen; - uint32_t tcpm_addr[4]; - uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; -}; - -#define TCP_REPAIR_ON 1 -#define TCP_REPAIR_OFF 0 -#define TCP_REPAIR_OFF_NO_WP -1 - -struct tcp_repair_window { - uint32_t snd_wl1; - uint32_t snd_wnd; - uint32_t max_window; - uint32_t rcv_wnd; - uint32_t rcv_wup; -}; - -struct tcp_zerocopy_receive { - uint64_t address; - uint32_t length; - uint32_t recv_skip_hint; -}; - -#endif - -#endif diff --git a/usr/lib/libc/include/netinet/udp.h b/usr/lib/libc/include/netinet/udp.h deleted file mode 100644 index ffd890796..000000000 --- a/usr/lib/libc/include/netinet/udp.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _NETINET_UDP_H -#define _NETINET_UDP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#ifdef _GNU_SOURCE -#define uh_sport source -#define uh_dport dest -#define uh_ulen len -#define uh_sum check -#endif - -struct udphdr { - uint16_t uh_sport; - uint16_t uh_dport; - uint16_t uh_ulen; - uint16_t uh_sum; -}; - -#define UDP_CORK 1 -#define UDP_ENCAP 100 -#define UDP_NO_CHECK6_TX 101 -#define UDP_NO_CHECK6_RX 102 -#define UDP_SEGMENT 103 -#define UDP_GRO 104 - -#define UDP_ENCAP_ESPINUDP_NON_IKE 1 -#define UDP_ENCAP_ESPINUDP 2 -#define UDP_ENCAP_L2TPINUDP 3 -#define UDP_ENCAP_GTP0 4 -#define UDP_ENCAP_GTP1U 5 -#define UDP_ENCAP_RXRPC 6 - -#define SOL_UDP 17 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/pthread.h b/usr/lib/libc/include/pthread.h deleted file mode 100644 index 53c3a4e20..000000000 --- a/usr/lib/libc/include/pthread.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2014-2017 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef PTHREAD_H_ -#define PTHREAD_H_ - -#include - - -typedef int pthread_t; - -/* Thread creation */ -int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); - -/* Thread join / synchronisation */ -int pthread_join(pthread_t thread, void **value_ptr); - -/* Modify thread priority */ -int pthread_setschedprio(pthread_t thread, int prio); - -/* Thread exit */ -void pthread_exit(void *value_ptr); - -/* Thread yield */ -int pthread_yield(void); - -#ifdef TEST_LABO03 -void pthread_test_start(void); -int pthread_test_verif(void); -#endif - -#endif /* PTHREAD_H_ */ diff --git a/usr/lib/libc/include/pthread_impl.h b/usr/lib/libc/include/pthread_impl.h deleted file mode 100644 index 6aa0f261f..000000000 --- a/usr/lib/libc/include/pthread_impl.h +++ /dev/null @@ -1,156 +0,0 @@ -#ifndef _PTHREAD_IMPL_H -#define _PTHREAD_IMPL_H - -#if 0 - -#include -#include -#include -#include -#include "libc.h" -#include "syscall.h" -#include "atomic.h" -#include "futex.h" - -#define pthread __pthread - -struct pthread { - struct pthread *self; - void **dtv, *unused1, *unused2; - uintptr_t sysinfo; - uintptr_t canary, canary2; - pid_t tid, pid; - int tsd_used, errno_val; - volatile int cancel, canceldisable, cancelasync; - int detached; - unsigned char *map_base; - size_t map_size; - void *stack; - size_t stack_size; - void *start_arg; - void *(*start)(void *); - void *result; - struct __ptcb *cancelbuf; - void **tsd; - volatile int dead; - struct { - volatile void *volatile head; - long off; - volatile void *volatile pending; - } robust_list; - int unblock_cancel; - volatile int timer_id; - locale_t locale; - volatile int killlock[2]; - volatile int exitlock[2]; - volatile int startlock[2]; - unsigned long sigmask[_NSIG/8/sizeof(long)]; - char *dlerror_buf; - int dlerror_flag; - void *stdio_locks; - uintptr_t canary_at_end; - void **dtv_copy; -}; - -struct __timer { - int timerid; - pthread_t thread; -}; - -#define __SU (sizeof(size_t)/sizeof(int)) - -#define _a_stacksize __u.__s[0] -#define _a_guardsize __u.__s[1] -#define _a_stackaddr __u.__s[2] -#define _a_detach __u.__i[3*__SU+0] -#define _a_sched __u.__i[3*__SU+1] -#define _a_policy __u.__i[3*__SU+2] -#define _a_prio __u.__i[3*__SU+3] -#define _m_type __u.__i[0] -#define _m_lock __u.__vi[1] -#define _m_waiters __u.__vi[2] -#define _m_prev __u.__p[3] -#define _m_next __u.__p[4] -#define _m_count __u.__i[5] -#define _c_shared __u.__p[0] -#define _c_seq __u.__vi[2] -#define _c_waiters __u.__vi[3] -#define _c_clock __u.__i[4] -#define _c_lock __u.__vi[8] -#define _c_head __u.__p[1] -#define _c_tail __u.__p[5] -#define _rw_lock __u.__vi[0] -#define _rw_waiters __u.__vi[1] -#define _rw_shared __u.__i[2] -#define _b_lock __u.__vi[0] -#define _b_waiters __u.__vi[1] -#define _b_limit __u.__i[2] -#define _b_count __u.__vi[3] -#define _b_waiters2 __u.__vi[4] -#define _b_inst __u.__p[3] - -#include "pthread_arch.h" - -#ifndef CANARY -#define CANARY canary -#endif - -#ifndef DTP_OFFSET -#define DTP_OFFSET 0 -#endif - -#ifndef tls_mod_off_t -#define tls_mod_off_t size_t -#endif - -#define SIGTIMER 32 -#define SIGCANCEL 33 -#define SIGSYNCCALL 34 - -#define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) -#define SIGPT_SET \ - ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ - [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) -#define SIGTIMER_SET \ - ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ - 0x80000000 }) - -pthread_t __pthread_self_init(void); - -int __clone(int (*)(void *), void *, int, void *, ...); -int __set_thread_area(void *); -int __libc_sigaction(int, const struct sigaction *, struct sigaction *); -int __libc_sigprocmask(int, const sigset_t *, sigset_t *); -void __lock(volatile int *); -void __unmapself(void *, size_t); - -void __vm_wait(void); -void __vm_lock(void); -void __vm_unlock(void); - -int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); -int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); -void __wait(volatile int *, volatile int *, int, int); -static inline void __wake(volatile void *addr, int cnt, int priv) -{ - if (priv) priv = 128; - if (cnt<0) cnt = INT_MAX; - __syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS || - __syscall(SYS_futex, addr, FUTEX_WAKE, cnt); -} - -void __acquire_ptc(void); -void __release_ptc(void); -void __inhibit_ptc(void); - -void __block_all_sigs(void *); -void __block_app_sigs(void *); -void __restore_sigs(void *); - -#define DEFAULT_STACK_SIZE 81920 -#define DEFAULT_GUARD_SIZE 4096 - -#define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1) -#endif - -#endif diff --git a/usr/lib/libc/include/shgetc.h b/usr/lib/libc/include/shgetc.h deleted file mode 100644 index 7beb8ce62..000000000 --- a/usr/lib/libc/include/shgetc.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "stdio_impl.h" - -void __shlim(FILE *, off_t); -int __shgetc(FILE *); - -#define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->rend)) -#define shlim(f, lim) __shlim((f), (lim)) -#define shgetc(f) (((f)->rpos < (f)->shend) ? *(f)->rpos++ : __shgetc(f)) -#define shunget(f) ((f)->shend ? (void)(f)->rpos-- : (void)0) diff --git a/usr/lib/libc/include/signal.h b/usr/lib/libc/include/signal.h deleted file mode 100644 index 55f996dea..000000000 --- a/usr/lib/libc/include/signal.h +++ /dev/null @@ -1,276 +0,0 @@ -#ifndef _SIGNAL_H -#define _SIGNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#ifdef _GNU_SOURCE -#define __ucontext ucontext -#endif - -#define __NEED_size_t -#define __NEED_pid_t -#define __NEED_uid_t -#define __NEED_struct_timespec -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_time_t -#define __NEED_clock_t -#define __NEED_sigset_t - -#include - -#define SIG_BLOCK 0 -#define SIG_UNBLOCK 1 -#define SIG_SETMASK 2 - -#define SI_ASYNCNL (-60) -#define SI_TKILL (-6) -#define SI_SIGIO (-5) -#define SI_ASYNCIO (-4) -#define SI_MESGQ (-3) -#define SI_TIMER (-2) -#define SI_QUEUE (-1) -#define SI_USER 0 -#define SI_KERNEL 128 - -typedef struct sigaltstack stack_t; - -#endif - -#include - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#define SIG_HOLD ((void (*)(int)) 2) - -#define FPE_INTDIV 1 -#define FPE_INTOVF 2 -#define FPE_FLTDIV 3 -#define FPE_FLTOVF 4 -#define FPE_FLTUND 5 -#define FPE_FLTRES 6 -#define FPE_FLTINV 7 -#define FPE_FLTSUB 8 - -#define ILL_ILLOPC 1 -#define ILL_ILLOPN 2 -#define ILL_ILLADR 3 -#define ILL_ILLTRP 4 -#define ILL_PRVOPC 5 -#define ILL_PRVREG 6 -#define ILL_COPROC 7 -#define ILL_BADSTK 8 - -#define SEGV_MAPERR 1 -#define SEGV_ACCERR 2 -#define SEGV_BNDERR 3 -#define SEGV_PKUERR 4 - -#define BUS_ADRALN 1 -#define BUS_ADRERR 2 -#define BUS_OBJERR 3 -#define BUS_MCEERR_AR 4 -#define BUS_MCEERR_AO 5 - -#define CLD_EXITED 1 -#define CLD_KILLED 2 -#define CLD_DUMPED 3 -#define CLD_TRAPPED 4 -#define CLD_STOPPED 5 -#define CLD_CONTINUED 6 - -union sigval { - int sival_int; - void *sival_ptr; -}; - -typedef struct { -#ifdef __SI_SWAP_ERRNO_CODE - int si_signo, si_code, si_errno; -#else - int si_signo, si_errno, si_code; -#endif - union { - char __pad[128 - 2*sizeof(int) - sizeof(long)]; - struct { - union { - struct { - pid_t si_pid; - uid_t si_uid; - } __piduid; - struct { - int si_timerid; - int si_overrun; - } __timer; - } __first; - union { - union sigval si_value; - struct { - int si_status; - clock_t si_utime, si_stime; - } __sigchld; - } __second; - } __si_common; - struct { - void *si_addr; - short si_addr_lsb; - union { - struct { - void *si_lower; - void *si_upper; - } __addr_bnd; - unsigned si_pkey; - } __first; - } __sigfault; - struct { - long si_band; - int si_fd; - } __sigpoll; - struct { - void *si_call_addr; - int si_syscall; - unsigned si_arch; - } __sigsys; - } __si_fields; -} siginfo_t; -#define si_pid __si_fields.__si_common.__first.__piduid.si_pid -#define si_uid __si_fields.__si_common.__first.__piduid.si_uid -#define si_status __si_fields.__si_common.__second.__sigchld.si_status -#define si_utime __si_fields.__si_common.__second.__sigchld.si_utime -#define si_stime __si_fields.__si_common.__second.__sigchld.si_stime -#define si_value __si_fields.__si_common.__second.si_value -#define si_addr __si_fields.__sigfault.si_addr -#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb -#define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower -#define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper -#define si_pkey __si_fields.__sigfault.__first.si_pkey -#define si_band __si_fields.__sigpoll.si_band -#define si_fd __si_fields.__sigpoll.si_fd -#define si_timerid __si_fields.__si_common.__first.__timer.si_timerid -#define si_overrun __si_fields.__si_common.__first.__timer.si_overrun -#define si_ptr si_value.sival_ptr -#define si_int si_value.sival_int -#define si_call_addr __si_fields.__sigsys.si_call_addr -#define si_syscall __si_fields.__sigsys.si_syscall -#define si_arch __si_fields.__sigsys.si_arch - -struct sigaction { - union { - void (*sa_handler)(int); - void (*sa_sigaction)(int, siginfo_t *, void *); - } __sa_handler; - sigset_t sa_mask; - int sa_flags; - void (*sa_restorer)(void); -}; -#define sa_handler __sa_handler.sa_handler -#define sa_sigaction __sa_handler.sa_sigaction - -struct sigevent { - union sigval sigev_value; - int sigev_signo; - int sigev_notify; - void (*sigev_notify_function)(union sigval); - pthread_attr_t *sigev_notify_attributes; - char __pad[56-3*sizeof(long)]; -}; - -#define SIGEV_SIGNAL 0 -#define SIGEV_NONE 1 -#define SIGEV_THREAD 2 - -int __libc_current_sigrtmin(void); -int __libc_current_sigrtmax(void); - -#define SIGRTMIN (__libc_current_sigrtmin()) -#define SIGRTMAX (__libc_current_sigrtmax()) - -int kill(pid_t, int); - -int sigemptyset(sigset_t *); -int sigfillset(sigset_t *); -int sigaddset(sigset_t *, int); -int sigdelset(sigset_t *, int); -int sigismember(const sigset_t *, int); - -int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); -int sigsuspend(const sigset_t *); -int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); -int sigpending(sigset_t *); -int sigwait(const sigset_t *__restrict, int *__restrict); -int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); -int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); -int sigqueue(pid_t, int, const union sigval); - -int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); -int pthread_kill(pthread_t, int); - -void psiginfo(const siginfo_t *, const char *); -void psignal(int, const char *); - -#endif - -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -int killpg(pid_t, int); -int sigaltstack(const stack_t *__restrict, stack_t *__restrict); -int sighold(int); -int sigignore(int); -int siginterrupt(int, int); -int sigpause(int); -int sigrelse(int); -void (*sigset(int, void (*)(int)))(int); -#define TRAP_BRKPT 1 -#define TRAP_TRACE 2 -#define POLL_IN 1 -#define POLL_OUT 2 -#define POLL_MSG 3 -#define POLL_ERR 4 -#define POLL_PRI 5 -#define POLL_HUP 6 -#define SS_ONSTACK 1 -#define SS_DISABLE 2 -#define SS_AUTODISARM (1U << 31) -#define SS_FLAG_BITS SS_AUTODISARM -#endif - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define NSIG _NSIG -typedef void (*sig_t)(int); -#endif - -#ifdef _GNU_SOURCE -typedef void (*sighandler_t)(int); -void (*bsd_signal(int, void (*)(int)))(int); -int sigisemptyset(const sigset_t *); -int sigorset (sigset_t *, const sigset_t *, const sigset_t *); -int sigandset(sigset_t *, const sigset_t *, const sigset_t *); - -#define SA_NOMASK SA_NODEFER -#define SA_ONESHOT SA_RESETHAND -#endif - -#define SIG_ERR ((void (*)(int))-1) -#define SIG_DFL ((void (*)(int)) 0) -#define SIG_IGN ((void (*)(int)) 1) - -typedef int sig_atomic_t; - -void (*signal(int, void (*)(int)))(int); -int raise(int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/stdarg.h b/usr/lib/libc/include/stdarg.h deleted file mode 100644 index 3256f8050..000000000 --- a/usr/lib/libc/include/stdarg.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_va_list - -#include - -#define va_start(v,l) __builtin_va_start(v,l) -#define va_end(v) __builtin_va_end(v) -#define va_arg(v,l) __builtin_va_arg(v,l) -#define va_copy(d,s) __builtin_va_copy(d,s) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/stddef.h b/usr/lib/libc/include/stddef.h deleted file mode 100644 index bd7538535..000000000 --- a/usr/lib/libc/include/stddef.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _STDDEF_H -#define _STDDEF_H - -#ifdef __cplusplus -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - -#define __NEED_ptrdiff_t -#define __NEED_size_t -#define __NEED_wchar_t -#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L -#define __NEED_max_align_t -#endif - -#include - -#if __GNUC__ > 3 -#define offsetof(type, member) __builtin_offsetof(type, member) -#else -#define offsetof(type, member) ((size_t)( (char *)&(((type *)0)->member) - (char *)0 )) -#endif - -#endif diff --git a/usr/lib/libc/include/stdint.h b/usr/lib/libc/include/stdint.h deleted file mode 100644 index a2968197d..000000000 --- a/usr/lib/libc/include/stdint.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef _STDINT_H -#define _STDINT_H - -#define __NEED_int8_t -#define __NEED_int16_t -#define __NEED_int32_t -#define __NEED_int64_t - -#define __NEED_uint8_t -#define __NEED_uint16_t -#define __NEED_uint32_t -#define __NEED_uint64_t - -#define __NEED_intptr_t -#define __NEED_uintptr_t - -#define __NEED_intmax_t -#define __NEED_uintmax_t - -#include - -typedef int8_t int_fast8_t; -typedef int64_t int_fast64_t; - -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; - -typedef uint8_t uint_fast8_t; -typedef uint64_t uint_fast64_t; - -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -#define INT8_MIN (-1-0x7f) -#define INT16_MIN (-1-0x7fff) -#define INT32_MIN (-1-0x7fffffff) -#define INT64_MIN (-1-0x7fffffffffffffff) - -#define INT8_MAX (0x7f) -#define INT16_MAX (0x7fff) -#define INT32_MAX (0x7fffffff) -#define INT64_MAX (0x7fffffffffffffff) - -#define UINT8_MAX (0xff) -#define UINT16_MAX (0xffff) -#define UINT32_MAX (0xffffffffu) -#define UINT64_MAX (0xffffffffffffffffu) - -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST64_MIN INT64_MIN - -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST64_MIN INT64_MIN - -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST64_MAX INT64_MAX - -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST64_MAX UINT64_MAX - -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -#define WINT_MIN 0U -#define WINT_MAX UINT32_MAX - -#if L'\0'-1 > 0 -#define WCHAR_MAX (0xffffffffu+L'\0') -#define WCHAR_MIN (0+L'\0') -#else -#define WCHAR_MAX (0x7fffffff+L'\0') -#define WCHAR_MIN (-1-0x7fffffff+L'\0') -#endif - -#define SIG_ATOMIC_MIN INT32_MIN -#define SIG_ATOMIC_MAX INT32_MAX - -#include - -#define INT8_C(c) c -#define INT16_C(c) c -#define INT32_C(c) c - -#define UINT8_C(c) c -#define UINT16_C(c) c -#define UINT32_C(c) c ## U - -#if UINTPTR_MAX == UINT64_MAX -#define INT64_C(c) c ## L -#define UINT64_C(c) c ## UL -#define INTMAX_C(c) c ## L -#define UINTMAX_C(c) c ## UL -#else -#define INT64_C(c) c ## LL -#define UINT64_C(c) c ## ULL -#define INTMAX_C(c) c ## LL -#define UINTMAX_C(c) c ## ULL -#endif - -#endif diff --git a/usr/lib/libc/include/stdio.h b/usr/lib/libc/include/stdio.h deleted file mode 100644 index 7ff77be45..000000000 --- a/usr/lib/libc/include/stdio.h +++ /dev/null @@ -1,203 +0,0 @@ -#ifndef _STDIO_H -#define _STDIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_FILE -#define __NEED___isoc_va_list -#define __NEED_size_t - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_ssize_t -#define __NEED_off_t -#define __NEED_va_list -#endif - -#include - -#ifdef __cplusplus -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - -#undef EOF -#define EOF (-1) - -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#define _IOFBF 0 -#define _IOLBF 1 -#define _IONBF 2 - -#define BUFSIZ 1024 -#define FILENAME_MAX 4096 -#define FOPEN_MAX 1000 -#define TMP_MAX 10000 -#define L_tmpnam 20 - -typedef union _G_fpos64_t { - char __opaque[16]; - double __align; -} fpos_t; - -extern FILE *const stdin; -extern FILE *const stdout; -extern FILE *const stderr; - -#define stdin (stdin) -#define stdout (stdout) -#define stderr (stderr) - -FILE *fopen(const char *, const char *); -FILE *freopen(const char *, const char *, FILE *); -int fclose(FILE *); - -int remove(const char *); -int rename(const char *, const char *); - -int feof(FILE *); -int ferror(FILE *); -int fflush(FILE *); -void clearerr(FILE *); - -int fseek(FILE *, long, int); -long ftell(FILE *); -void rewind(FILE *); - -int fgetpos(FILE *, fpos_t *); -int fsetpos(FILE *, const fpos_t *); - -size_t fread(void *, size_t, size_t, FILE *); -size_t fwrite(const void *, size_t, size_t, FILE *); - -int fgetc(FILE *); -int getc(FILE *); -int getchar(void); -int ungetc(int, FILE *); - -int fputc(int, FILE *); -int putc(int, FILE *); -int putchar(int); - -char *fgets(char *, int, FILE *); -#if __STDC_VERSION__ < 201112L -char *gets(char *); -#endif - -int fputs(const char *, FILE *); -int puts(const char *); - -int printf(const char *, ...); -int fprintf(FILE *, const char *, ...); -int sprintf(char *, const char *, ...); -int snprintf(char *, size_t, const char *, ...); - -int vprintf(const char *, __isoc_va_list); -int vfprintf(FILE *, const char *, __isoc_va_list); -int vsprintf(char *, const char *, __isoc_va_list); -int vsnprintf(char *, size_t, const char *, __isoc_va_list); - -int scanf(const char *, ...); -int fscanf(FILE *, const char *, ...); -int sscanf(const char *, const char *, ...); -int vscanf(const char *, __isoc_va_list); -int vfscanf(FILE *, const char *, __isoc_va_list); -int vsscanf(const char *, const char *, __isoc_va_list); - -void perror(const char *); - -int setvbuf(FILE *, char *, int, size_t); -void setbuf(FILE *, char *); - -char *tmpnam(char *); -FILE *tmpfile(void); - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -FILE *fmemopen(void *, size_t, const char *); -FILE *open_memstream(char **, size_t *); -FILE *fdopen(int, const char *); -FILE *popen(const char *, const char *); -int pclose(FILE *); -int fileno(FILE *); -int fseeko(FILE *, off_t, int); -off_t ftello(FILE *); -int dprintf(int, const char *, ...); -int vdprintf(int, const char *, __isoc_va_list); -void flockfile(FILE *); -int ftrylockfile(FILE *); -void funlockfile(FILE *); -int getc_unlocked(FILE *); -int getchar_unlocked(void); -int putc_unlocked(int, FILE *); -int putchar_unlocked(int); -ssize_t getdelim(char **, size_t *, int, FILE *); -ssize_t getline(char **, size_t *, FILE *); -int renameat(int, const char *, int, const char *); -char *ctermid(char *); -#define L_ctermid 20 -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define P_tmpdir "/tmp" -char *tempnam(const char *, const char *); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define L_cuserid 20 -char *cuserid(char *); -void setlinebuf(FILE *); -void setbuffer(FILE *, char *, size_t); -int fgetc_unlocked(FILE *); -int fputc_unlocked(int, FILE *); -int fflush_unlocked(FILE *); -size_t fread_unlocked(void *, size_t, size_t, FILE *); -size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); -void clearerr_unlocked(FILE *); -int feof_unlocked(FILE *); -int ferror_unlocked(FILE *); -int fileno_unlocked(FILE *); -int getw(FILE *); -int putw(int, FILE *); -char *fgetln(FILE *, size_t *); -int asprintf(char **, const char *, ...); -int vasprintf(char **, const char *, __isoc_va_list); -#endif - -#ifdef _GNU_SOURCE -char *fgets_unlocked(char *, int, FILE *); -int fputs_unlocked(const char *, FILE *); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define tmpfile64 tmpfile -#define fopen64 fopen -#define freopen64 freopen -#define fseeko64 fseeko -#define ftello64 ftello -#define fgetpos64 fgetpos -#define fsetpos64 fsetpos -#define fpos64_t fpos_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/stdio_impl.h b/usr/lib/libc/include/stdio_impl.h deleted file mode 100644 index c80fbe9aa..000000000 --- a/usr/lib/libc/include/stdio_impl.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef _STDIO_IMPL_H -#define _STDIO_IMPL_H - -#include -#include -#include - -#include - -#define UNGET 8 - -#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0) - -#if 0 /* SO3 */ -#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0) -#define FUNLOCK(f) if (__need_unlock) __unlockfile((f)); else -#endif - -#define FLOCK(f) __lockfile((f)) -#define FUNLOCK(f) __unlockfile((f)) - -#define F_PERM 1 -#define F_NORD 4 -#define F_NOWR 8 -#define F_EOF 16 -#define F_ERR 32 -#define F_SVB 64 -#define F_APP 128 - -struct _IO_FILE { - unsigned flags; - unsigned char *rpos, *rend; - int (*close)(FILE *); - unsigned char *wend, *wpos; - unsigned char *mustbezero_1; - unsigned char *wbase; - size_t (*read)(FILE *, unsigned char *, size_t); - size_t (*write)(FILE *, const unsigned char *, size_t); - off_t (*seek)(FILE *, off_t, int); - unsigned char *buf; - size_t buf_size; - FILE *prev, *next; - int fd; - int pipe_pid; - long lockcount; - short dummy3; - signed char mode; - signed char lbf; - volatile int lock; - volatile int waiters; - void *cookie; - off_t off; - char *getln_buf; - void *mustbezero_2; - unsigned char *shend; - off_t shlim, shcnt; - FILE *prev_locked, *next_locked; - struct __locale_struct *locale; -}; - -size_t __stdio_read(FILE *, unsigned char *, size_t); -size_t __stdio_write(FILE *, const unsigned char *, size_t); -size_t __stdout_write(FILE *, const unsigned char *, size_t); -off_t __stdio_seek(FILE *, off_t, int); -int __stdio_close(FILE *); - -size_t __string_read(FILE *, unsigned char *, size_t); - -int __toread(FILE *); -int __towrite(FILE *); - -#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303) -__attribute__((visibility("protected"))) -#endif -int __overflow(FILE *, int), __uflow(FILE *); - -int __fseeko(FILE *, off_t, int); -int __fseeko_unlocked(FILE *, off_t, int); -off_t __ftello(FILE *); -off_t __ftello_unlocked(FILE *); -size_t __fwritex(const unsigned char *, size_t, FILE *); -int __putc_unlocked(int, FILE *); - -FILE *__fdopen(int, const char *); -int __fmodeflags(const char *); - -FILE *__ofl_add(FILE *f); -FILE **__ofl_lock(void); -void __ofl_unlock(void); - -#define feof(f) ((f)->flags & F_EOF) -#define ferror(f) ((f)->flags & F_ERR) - -#define getc_unlocked(f) \ - ( ((f)->rpos < (f)->rend) ? *(f)->rpos++ : __uflow((f)) ) - -#define putc_unlocked(c, f) \ - ( ((unsigned char)(c)!=(f)->lbf && (f)->wpos<(f)->wend) \ - ? *(f)->wpos++ = (c) : __overflow((f),(c)) ) - -/* Caller-allocated FILE * operations */ -FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t); -int __fclose_ca(FILE *); - -#endif diff --git a/usr/lib/libc/include/stdlib.h b/usr/lib/libc/include/stdlib.h deleted file mode 100644 index bd38b6fd4..000000000 --- a/usr/lib/libc/include/stdlib.h +++ /dev/null @@ -1,164 +0,0 @@ -#ifndef _STDLIB_H -#define _STDLIB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __cplusplus -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - -#define __NEED_size_t -#define __NEED_wchar_t - -#include - -int atoi (const char *); -long atol (const char *); -long long atoll (const char *); -double atof (const char *); - -float strtof (const char *__restrict, char **__restrict); -double strtod (const char *__restrict, char **__restrict); -long double strtold (const char *__restrict, char **__restrict); - -long strtol (const char *__restrict, char **__restrict, int); -unsigned long strtoul (const char *__restrict, char **__restrict, int); -long long strtoll (const char *__restrict, char **__restrict, int); -unsigned long long strtoull (const char *__restrict, char **__restrict, int); - -int rand (void); -void srand (unsigned); - -void *malloc (size_t); -void *calloc (size_t, size_t); -void *realloc (void *, size_t); -void free (void *); -void *aligned_alloc(size_t, size_t); - -_Noreturn void abort (void); -int atexit (void (*) (void)); -_Noreturn void exit (int); -_Noreturn void _Exit (int); -int at_quick_exit (void (*) (void)); -_Noreturn void quick_exit (int); - -char *getenv (const char *); - -int system (const char *); - -void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); -void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); - -int abs (int); -long labs (long); -long long llabs (long long); - -typedef struct { int quot, rem; } div_t; -typedef struct { long quot, rem; } ldiv_t; -typedef struct { long long quot, rem; } lldiv_t; - -div_t div (int, int); -ldiv_t ldiv (long, long); -lldiv_t lldiv (long long, long long); - -int mblen (const char *, size_t); -int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); -int wctomb (char *, wchar_t); -size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); -size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); - -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -size_t __ctype_get_mb_cur_max(void); -#define MB_CUR_MAX (__ctype_get_mb_cur_max()) - -#define RAND_MAX (0x7fffffff) - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - - -int posix_memalign (void **, size_t, size_t); -int setenv (const char *, const char *, int); -int unsetenv (const char *); -int mkstemp (char *); -int mkostemp (char *, int); -char *mkdtemp (char *); -int getsubopt (char **, char *const *, char **); -int rand_r (unsigned *); - -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -char *realpath (const char *__restrict, char *__restrict); -long int random (void); -void srandom (unsigned int); -char *initstate (unsigned int, char *, size_t); -char *setstate (char *); -int putenv (char *); -int posix_openpt (int); -int grantpt (int); -int unlockpt (int); -char *ptsname (int); -char *l64a (long); -long a64l (const char *); -void setkey (const char *); -double drand48 (void); -double erand48 (unsigned short [3]); -long int lrand48 (void); -long int nrand48 (unsigned short [3]); -long mrand48 (void); -long jrand48 (unsigned short [3]); -void srand48 (long); -unsigned short *seed48 (unsigned short [3]); -void lcong48 (unsigned short [7]); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#include -char *mktemp (char *); -int mkstemps (char *, int); -int mkostemps (char *, int, int); -void *valloc (size_t); -void *memalign(size_t, size_t); -int getloadavg(double *, int); -int clearenv(void); -#define WCOREDUMP(s) ((s) & 0x80) -#define WIFCONTINUED(s) ((s) == 0xffff) -#endif - -#ifdef _GNU_SOURCE -int ptsname_r(int, char *, size_t); -char *ecvt(double, int, int *, int *); -char *fcvt(double, int, int *, int *); -char *gcvt(double, int, char *); -struct __locale_struct; -float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); -double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); -long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define mkstemp64 mkstemp -#define mkostemp64 mkostemp -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define mkstemps64 mkstemps -#define mkostemps64 mkostemps -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/string.h b/usr/lib/libc/include/string.h deleted file mode 100644 index ff9badb9c..000000000 --- a/usr/lib/libc/include/string.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef _STRING_H -#define _STRING_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __cplusplus -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - -#define __NEED_size_t -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_locale_t -#endif - -#include - -void *memcpy (void *__restrict, const void *__restrict, size_t); -void *memmove (void *, const void *, size_t); -void *memset (void *, int, size_t); -int memcmp (const void *, const void *, size_t); -void *memchr (const void *, int, size_t); - -char *strcpy (char *__restrict, const char *__restrict); -char *strncpy (char *__restrict, const char *__restrict, size_t); - -char *strcat (char *__restrict, const char *__restrict); -char *strncat (char *__restrict, const char *__restrict, size_t); - -int strcmp (const char *, const char *); -int strncmp (const char *, const char *, size_t); - -int strcoll (const char *, const char *); -size_t strxfrm (char *__restrict, const char *__restrict, size_t); - -char *strchr (const char *, int); -char *strrchr (const char *, int); - -size_t strcspn (const char *, const char *); -size_t strspn (const char *, const char *); -char *strpbrk (const char *, const char *); -char *strstr (const char *, const char *); -char *strtok (char *__restrict, const char *__restrict); - -size_t strlen (const char *); - -char *strerror (int); - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#include -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); -int strerror_r (int, char *, size_t); -char *stpcpy(char *__restrict, const char *__restrict); -char *stpncpy(char *__restrict, const char *__restrict, size_t); -size_t strnlen (const char *, size_t); -char *strdup (const char *); -char *strndup (const char *, size_t); -char *strsignal(int); -char *strerror_l (int, locale_t); -int strcoll_l (const char *, const char *, locale_t); -size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -void *memccpy (void *__restrict, const void *__restrict, int, size_t); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -char *strsep(char **, const char *); -size_t strlcat (char *, const char *, size_t); -size_t strlcpy (char *, const char *, size_t); -#endif - -#ifdef _GNU_SOURCE -#define strdupa(x) strcpy(alloca(strlen(x)+1),x) -int strverscmp (const char *, const char *); -int strcasecmp_l (const char *, const char *, locale_t); -int strncasecmp_l (const char *, const char *, size_t, locale_t); -char *strchrnul(const char *, int); -char *strcasestr(const char *, const char *); -void *memmem(const void *, size_t, const void *, size_t); -void *memrchr(const void *, int, size_t); -void *mempcpy(void *, const void *, size_t); -#ifndef __cplusplus -char *basename(); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/strings.h b/usr/lib/libc/include/strings.h deleted file mode 100644 index db0960b4e..000000000 --- a/usr/lib/libc/include/strings.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _STRINGS_H -#define _STRINGS_H - -#ifdef __cplusplus -extern "C" { -#endif - - -#define __NEED_size_t -#define __NEED_locale_t -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ - || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) -int bcmp (const void *, const void *, size_t); -void bcopy (const void *, void *, size_t); -void bzero (void *, size_t); -char *index (const char *, int); -char *rindex (const char *, int); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int ffs (int); -int ffsl (long); -int ffsll (long long); -#endif - -int strcasecmp (const char *, const char *); -int strncasecmp (const char *, const char *, size_t); - -int strcasecmp_l (const char *, const char *, locale_t); -int strncasecmp_l (const char *, const char *, size_t, locale_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/acct.h b/usr/lib/libc/include/sys/acct.h deleted file mode 100644 index 9b0ba36fb..000000000 --- a/usr/lib/libc/include/sys/acct.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _SYS_ACCT_H -#define _SYS_ACCT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#define ACCT_COMM 16 - -typedef uint16_t comp_t; - -struct acct { - char ac_flag; - uint16_t ac_uid; - uint16_t ac_gid; - uint16_t ac_tty; - uint32_t ac_btime; - comp_t ac_utime; - comp_t ac_stime; - comp_t ac_etime; - comp_t ac_mem; - comp_t ac_io; - comp_t ac_rw; - comp_t ac_minflt; - comp_t ac_majflt; - comp_t ac_swaps; - uint32_t ac_exitcode; - char ac_comm[ACCT_COMM+1]; - char ac_pad[10]; -}; - - -struct acct_v3 { - char ac_flag; - char ac_version; - uint16_t ac_tty; - uint32_t ac_exitcode; - uint32_t ac_uid; - uint32_t ac_gid; - uint32_t ac_pid; - uint32_t ac_ppid; - uint32_t ac_btime; - float ac_etime; - comp_t ac_utime; - comp_t ac_stime; - comp_t ac_mem; - comp_t ac_io; - comp_t ac_rw; - comp_t ac_minflt; - comp_t ac_majflt; - comp_t ac_swaps; - char ac_comm[ACCT_COMM]; -}; - -#define AFORK 1 -#define ASU 2 -#define ACORE 8 -#define AXSIG 16 -#define ACCT_BYTEORDER (128*(__BYTE_ORDER==__BIG_ENDIAN)) -#define AHZ 100 - -int acct(const char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/auxv.h b/usr/lib/libc/include/sys/auxv.h deleted file mode 100644 index ddccf57ff..000000000 --- a/usr/lib/libc/include/sys/auxv.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _SYS_AUXV_H -#define _SYS_AUXV_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -unsigned long getauxval(unsigned long); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/cachectl.h b/usr/lib/libc/include/sys/cachectl.h deleted file mode 100644 index f3b896a8e..000000000 --- a/usr/lib/libc/include/sys/cachectl.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _SYS_CACHECTL_H -#define _SYS_CACHECTL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define ICACHE (1<<0) -#define DCACHE (1<<1) -#define BCACHE (ICACHE|DCACHE) -#define CACHEABLE 0 -#define UNCACHEABLE 1 - -int cachectl(void *, int, int); -int cacheflush(void *, int, int); -int _flush_cache(void *, int, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/dir.h b/usr/lib/libc/include/sys/dir.h deleted file mode 100644 index 9ba1c79e2..000000000 --- a/usr/lib/libc/include/sys/dir.h +++ /dev/null @@ -1,2 +0,0 @@ -#include -#define direct dirent diff --git a/usr/lib/libc/include/sys/epoll.h b/usr/lib/libc/include/sys/epoll.h deleted file mode 100644 index ffe2311f9..000000000 --- a/usr/lib/libc/include/sys/epoll.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _SYS_EPOLL_H -#define _SYS_EPOLL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#define __NEED_sigset_t - -#include - -#define EPOLL_CLOEXEC O_CLOEXEC -#define EPOLL_NONBLOCK O_NONBLOCK - -enum EPOLL_EVENTS { __EPOLL_DUMMY }; -#define EPOLLIN 0x001 -#define EPOLLPRI 0x002 -#define EPOLLOUT 0x004 -#define EPOLLRDNORM 0x040 -#define EPOLLRDBAND 0x080 -#define EPOLLWRNORM 0x100 -#define EPOLLWRBAND 0x200 -#define EPOLLMSG 0x400 -#define EPOLLERR 0x008 -#define EPOLLHUP 0x010 -#define EPOLLRDHUP 0x2000 -#define EPOLLEXCLUSIVE (1U<<28) -#define EPOLLWAKEUP (1U<<29) -#define EPOLLONESHOT (1U<<30) -#define EPOLLET (1U<<31) - -#define EPOLL_CTL_ADD 1 -#define EPOLL_CTL_DEL 2 -#define EPOLL_CTL_MOD 3 - -typedef union epoll_data { - void *ptr; - int fd; - uint32_t u32; - uint64_t u64; -} epoll_data_t; - -struct epoll_event { - uint32_t events; - epoll_data_t data; -} -#ifdef __x86_64__ -__attribute__ ((__packed__)) -#endif -; - - -int epoll_create(int); -int epoll_create1(int); -int epoll_ctl(int, int, int, struct epoll_event *); -int epoll_wait(int, struct epoll_event *, int, int); -int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *); - - -#ifdef __cplusplus -} -#endif - -#endif /* sys/epoll.h */ diff --git a/usr/lib/libc/include/sys/errno.h b/usr/lib/libc/include/sys/errno.h deleted file mode 100644 index 35a3e5a2a..000000000 --- a/usr/lib/libc/include/sys/errno.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning redirecting incorrect #include to -#include diff --git a/usr/lib/libc/include/sys/eventfd.h b/usr/lib/libc/include/sys/eventfd.h deleted file mode 100644 index dc5c88f04..000000000 --- a/usr/lib/libc/include/sys/eventfd.h +++ /dev/null @@ -1,26 +0,0 @@ -#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 */ diff --git a/usr/lib/libc/include/sys/fanotify.h b/usr/lib/libc/include/sys/fanotify.h deleted file mode 100644 index daab76b13..000000000 --- a/usr/lib/libc/include/sys/fanotify.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _FANOTIFY_H -#define _FANOTIFY_H - -#ifdef __cplusplus -extern "C" { -#endif - -struct fanotify_event_metadata { - unsigned event_len; - unsigned char vers; - unsigned char reserved; - unsigned short metadata_len; - unsigned long long mask -#ifdef __GNUC__ - __attribute__((__aligned__(8))) -#endif - ; - int fd; - int pid; -}; - -struct fanotify_response { - int fd; - unsigned response; -}; - -#define FAN_ACCESS 0x01 -#define FAN_MODIFY 0x02 -#define FAN_CLOSE_WRITE 0x08 -#define FAN_CLOSE_NOWRITE 0x10 -#define FAN_OPEN 0x20 -#define FAN_Q_OVERFLOW 0x4000 -#define FAN_OPEN_PERM 0x10000 -#define FAN_ACCESS_PERM 0x20000 -#define FAN_ONDIR 0x40000000 -#define FAN_EVENT_ON_CHILD 0x08000000 -#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) -#define FAN_CLOEXEC 0x01 -#define FAN_NONBLOCK 0x02 -#define FAN_CLASS_NOTIF 0 -#define FAN_CLASS_CONTENT 0x04 -#define FAN_CLASS_PRE_CONTENT 0x08 -#define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT) -#define FAN_UNLIMITED_QUEUE 0x10 -#define FAN_UNLIMITED_MARKS 0x20 -#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) -#define FAN_MARK_ADD 0x01 -#define FAN_MARK_REMOVE 0x02 -#define FAN_MARK_DONT_FOLLOW 0x04 -#define FAN_MARK_ONLYDIR 0x08 -#define FAN_MARK_MOUNT 0x10 -#define FAN_MARK_IGNORED_MASK 0x20 -#define FAN_MARK_IGNORED_SURV_MODIFY 0x40 -#define FAN_MARK_FLUSH 0x80 -#define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_DONT_FOLLOW | FAN_MARK_ONLYDIR | FAN_MARK_MOUNT | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY | FAN_MARK_FLUSH) -#define FAN_ALL_EVENTS (FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN) -#define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM) -#define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_Q_OVERFLOW) -#define FANOTIFY_METADATA_VERSION 3 -#define FAN_ALLOW 0x01 -#define FAN_DENY 0x02 -#define FAN_NOFD -1 -#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) -#define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, (struct fanotify_event_metadata*)(((char *)(meta)) + (meta)->event_len)) -#define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len <= (long)(len)) - -int fanotify_init(unsigned, unsigned); -int fanotify_mark(int, unsigned, unsigned long long, int, const char *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/fcntl.h b/usr/lib/libc/include/sys/fcntl.h deleted file mode 100644 index 3dd928ef6..000000000 --- a/usr/lib/libc/include/sys/fcntl.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning redirecting incorrect #include to -#include diff --git a/usr/lib/libc/include/sys/file.h b/usr/lib/libc/include/sys/file.h deleted file mode 100644 index 4fc83b981..000000000 --- a/usr/lib/libc/include/sys/file.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _SYS_FILE_H -#define _SYS_FILE_H -#ifdef __cplusplus -extern "C" { -#endif - -#define LOCK_SH 1 -#define LOCK_EX 2 -#define LOCK_NB 4 -#define LOCK_UN 8 - -#define L_SET 0 -#define L_INCR 1 -#define L_XTND 2 - -int flock(int, int); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/fsuid.h b/usr/lib/libc/include/sys/fsuid.h deleted file mode 100644 index c7a9b8faa..000000000 --- a/usr/lib/libc/include/sys/fsuid.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _SYS_FSUID_H -#define _SYS_FSUID_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_uid_t -#define __NEED_gid_t - -#include - -int setfsuid(uid_t); -int setfsgid(gid_t); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/inotify.h b/usr/lib/libc/include/sys/inotify.h deleted file mode 100644 index 46638cac9..000000000 --- a/usr/lib/libc/include/sys/inotify.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _SYS_INOTIFY_H -#define _SYS_INOTIFY_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -struct inotify_event { - int wd; - uint32_t mask, cookie, len; - char name[]; -}; - -#define IN_CLOEXEC O_CLOEXEC -#define IN_NONBLOCK O_NONBLOCK - -#define IN_ACCESS 0x00000001 -#define IN_MODIFY 0x00000002 -#define IN_ATTRIB 0x00000004 -#define IN_CLOSE_WRITE 0x00000008 -#define IN_CLOSE_NOWRITE 0x00000010 -#define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) -#define IN_OPEN 0x00000020 -#define IN_MOVED_FROM 0x00000040 -#define IN_MOVED_TO 0x00000080 -#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) -#define IN_CREATE 0x00000100 -#define IN_DELETE 0x00000200 -#define IN_DELETE_SELF 0x00000400 -#define IN_MOVE_SELF 0x00000800 -#define IN_ALL_EVENTS 0x00000fff - -#define IN_UNMOUNT 0x00002000 -#define IN_Q_OVERFLOW 0x00004000 -#define IN_IGNORED 0x00008000 - -#define IN_ONLYDIR 0x01000000 -#define IN_DONT_FOLLOW 0x02000000 -#define IN_EXCL_UNLINK 0x04000000 -#define IN_MASK_ADD 0x20000000 - -#define IN_ISDIR 0x40000000 -#define IN_ONESHOT 0x80000000 - -int inotify_init(void); -int inotify_init1(int); -int inotify_add_watch(int, const char *, uint32_t); -int inotify_rm_watch(int, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/io.h b/usr/lib/libc/include/sys/io.h deleted file mode 100644 index 16658ceca..000000000 --- a/usr/lib/libc/include/sys/io.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _SYS_IO_H -#define _SYS_IO_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -int iopl(int); -int ioperm(unsigned long, unsigned long, int); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/ioctl.h b/usr/lib/libc/include/sys/ioctl.h deleted file mode 100644 index be48793d5..000000000 --- a/usr/lib/libc/include/sys/ioctl.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#if 0 -int ioctl (int, int, ...); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/ipc.h b/usr/lib/libc/include/sys/ipc.h deleted file mode 100644 index c5a39819c..000000000 --- a/usr/lib/libc/include/sys/ipc.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _SYS_IPC_H -#define _SYS_IPC_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_mode_t -#define __NEED_key_t - -#include - -#define __ipc_perm_key __key -#define __ipc_perm_seq __seq - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __key key -#define __seq seq -#endif - -#include - -#define IPC_CREAT 01000 -#define IPC_EXCL 02000 -#define IPC_NOWAIT 04000 - -#define IPC_RMID 0 -#define IPC_SET 1 -#define IPC_STAT 2 -#define IPC_INFO 3 - -#define IPC_PRIVATE ((key_t) 0) - -key_t ftok (const char *, int); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/kd.h b/usr/lib/libc/include/sys/kd.h deleted file mode 100644 index 793fd59fe..000000000 --- a/usr/lib/libc/include/sys/kd.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _SYS_KD_H -#define _SYS_KD_H - -#define _LINUX_TYPES_H -#include -#undef _LINUX_TYPES_H - -#endif diff --git a/usr/lib/libc/include/sys/klog.h b/usr/lib/libc/include/sys/klog.h deleted file mode 100644 index aa66684e3..000000000 --- a/usr/lib/libc/include/sys/klog.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _SYS_KLOG_H -#define _SYS_KLOG_H - -#ifdef __cplusplus -extern "C" { -#endif - -int klogctl (int, char *, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/mman.h b/usr/lib/libc/include/sys/mman.h deleted file mode 100644 index 8a5149c98..000000000 --- a/usr/lib/libc/include/sys/mman.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_mode_t -#define __NEED_size_t -#define __NEED_off_t - -#if defined(_GNU_SOURCE) -#define __NEED_ssize_t -#endif - -#include - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_FILE 0 - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -#define POSIX_MADV_NORMAL 0 -#define POSIX_MADV_RANDOM 1 -#define POSIX_MADV_SEQUENTIAL 2 -#define POSIX_MADV_WILLNEED 3 -#define POSIX_MADV_DONTNEED 4 - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define MADV_NORMAL 0 -#define MADV_RANDOM 1 -#define MADV_SEQUENTIAL 2 -#define MADV_WILLNEED 3 -#define MADV_DONTNEED 4 -#define MADV_FREE 8 -#define MADV_REMOVE 9 -#define MADV_DONTFORK 10 -#define MADV_DOFORK 11 -#define MADV_MERGEABLE 12 -#define MADV_UNMERGEABLE 13 -#define MADV_HUGEPAGE 14 -#define MADV_NOHUGEPAGE 15 -#define MADV_DONTDUMP 16 -#define MADV_DODUMP 17 -#define MADV_HWPOISON 100 -#define MADV_SOFT_OFFLINE 101 -#endif - -#include - -void *mmap (void *, size_t, int, int, int, off_t); -int munmap (void *, size_t); - -int mprotect (void *, size_t, int); -int msync (void *, size_t, int); - -int posix_madvise (void *, size_t, int); - -int mlock (const void *, size_t); -int munlock (const void *, size_t); -int mlockall (int); -int munlockall (void); - -#ifdef _GNU_SOURCE -#define MREMAP_MAYMOVE 1 -#define MREMAP_FIXED 2 -void *mremap (void *, size_t, size_t, int, ...); -int remap_file_pages (void *, size_t, int, size_t, int); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define MLOCK_ONFAULT 0x01 -int madvise (void *, size_t, int); -int mincore (void *, size_t, unsigned char *); -#endif - -int shm_open (const char *, int, mode_t); -int shm_unlink (const char *); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define mmap64 mmap -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/mount.h b/usr/lib/libc/include/sys/mount.h deleted file mode 100644 index 57a89c09e..000000000 --- a/usr/lib/libc/include/sys/mount.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef _SYS_MOUNT_H -#define _SYS_MOUNT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define BLKROSET _IO(0x12, 93) -#define BLKROGET _IO(0x12, 94) -#define BLKRRPART _IO(0x12, 95) -#define BLKGETSIZE _IO(0x12, 96) -#define BLKFLSBUF _IO(0x12, 97) -#define BLKRASET _IO(0x12, 98) -#define BLKRAGET _IO(0x12, 99) -#define BLKFRASET _IO(0x12,100) -#define BLKFRAGET _IO(0x12,101) -#define BLKSECTSET _IO(0x12,102) -#define BLKSECTGET _IO(0x12,103) -#define BLKSSZGET _IO(0x12,104) -#define BLKBSZGET _IOR(0x12,112,size_t) -#define BLKBSZSET _IOW(0x12,113,size_t) -#define BLKGETSIZE64 _IOR(0x12,114,size_t) - -#define MS_RDONLY 1 -#define MS_NOSUID 2 -#define MS_NODEV 4 -#define MS_NOEXEC 8 -#define MS_SYNCHRONOUS 16 -#define MS_REMOUNT 32 -#define MS_MANDLOCK 64 -#define MS_DIRSYNC 128 -#define MS_NOATIME 1024 -#define MS_NODIRATIME 2048 -#define MS_BIND 4096 -#define MS_MOVE 8192 -#define MS_REC 16384 -#define MS_SILENT 32768 -#define MS_POSIXACL (1<<16) -#define MS_UNBINDABLE (1<<17) -#define MS_PRIVATE (1<<18) -#define MS_SLAVE (1<<19) -#define MS_SHARED (1<<20) -#define MS_RELATIME (1<<21) -#define MS_KERNMOUNT (1<<22) -#define MS_I_VERSION (1<<23) -#define MS_STRICTATIME (1<<24) -#define MS_LAZYTIME (1<<25) -#define MS_NOREMOTELOCK (1<<27) -#define MS_NOSEC (1<<28) -#define MS_BORN (1<<29) -#define MS_ACTIVE (1<<30) -#define MS_NOUSER (1U<<31) - -#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME) - -#define MS_MGC_VAL 0xc0ed0000 -#define MS_MGC_MSK 0xffff0000 - -#define MNT_FORCE 1 -#define MNT_DETACH 2 -#define MNT_EXPIRE 4 -#define UMOUNT_NOFOLLOW 8 - -int mount(const char *, const char *, const char *, unsigned long, const void *); -int umount(const char *); -int umount2(const char *, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/msg.h b/usr/lib/libc/include/sys/msg.h deleted file mode 100644 index 139f22b70..000000000 --- a/usr/lib/libc/include/sys/msg.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _SYS_MSG_H -#define _SYS_MSG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_pid_t -#define __NEED_key_t -#define __NEED_time_t -#define __NEED_size_t -#define __NEED_ssize_t - -#include - -typedef unsigned long msgqnum_t; -typedef unsigned long msglen_t; - -#include - -#define __msg_cbytes msg_cbytes - -#define MSG_NOERROR 010000 -#define MSG_EXCEPT 020000 - -#define MSG_STAT 11 -#define MSG_INFO 12 - -struct msginfo { - int msgpool, msgmap, msgmax, msgmnb, msgmni, msgssz, msgtql; - unsigned short msgseg; -}; - -int msgctl (int, int, struct msqid_ds *); -int msgget (key_t, int); -ssize_t msgrcv (int, void *, size_t, long, int); -int msgsnd (int, const void *, size_t, int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -struct msgbuf { - long mtype; - char mtext[1]; -}; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/mtio.h b/usr/lib/libc/include/sys/mtio.h deleted file mode 100644 index f16a529bb..000000000 --- a/usr/lib/libc/include/sys/mtio.h +++ /dev/null @@ -1,188 +0,0 @@ -#ifndef _SYS_MTIO_H -#define _SYS_MTIO_H - -#include -#include - -struct mtop { - short mt_op; - int mt_count; -}; - -#define _IOT_mtop _IOT (_IOTS (short), 1, _IOTS (int), 1, 0, 0) -#define _IOT_mtget _IOT (_IOTS (long), 7, 0, 0, 0, 0) -#define _IOT_mtpos _IOT_SIMPLE (long) -#define _IOT_mtconfiginfo _IOT (_IOTS (long), 2, _IOTS (short), 3, _IOTS (long), 1) - - -#define MTRESET 0 -#define MTFSF 1 -#define MTBSF 2 -#define MTFSR 3 -#define MTBSR 4 -#define MTWEOF 5 -#define MTREW 6 -#define MTOFFL 7 -#define MTNOP 8 -#define MTRETEN 9 -#define MTBSFM 10 -#define MTFSFM 11 -#define MTEOM 12 -#define MTERASE 13 -#define MTRAS1 14 -#define MTRAS2 15 -#define MTRAS3 16 -#define MTSETBLK 20 -#define MTSETDENSITY 21 -#define MTSEEK 22 -#define MTTELL 23 -#define MTSETDRVBUFFER 24 -#define MTFSS 25 -#define MTBSS 26 -#define MTWSM 27 -#define MTLOCK 28 -#define MTUNLOCK 29 -#define MTLOAD 30 -#define MTUNLOAD 31 -#define MTCOMPRESSION 32 -#define MTSETPART 33 -#define MTMKPART 34 - -struct mtget { - long mt_type; - long mt_resid; - long mt_dsreg; - long mt_gstat; - long mt_erreg; - int mt_fileno; - int mt_blkno; -}; - -#define MT_ISUNKNOWN 0x01 -#define MT_ISQIC02 0x02 -#define MT_ISWT5150 0x03 -#define MT_ISARCHIVE_5945L2 0x04 -#define MT_ISCMSJ500 0x05 -#define MT_ISTDC3610 0x06 -#define MT_ISARCHIVE_VP60I 0x07 -#define MT_ISARCHIVE_2150L 0x08 -#define MT_ISARCHIVE_2060L 0x09 -#define MT_ISARCHIVESC499 0x0A -#define MT_ISQIC02_ALL_FEATURES 0x0F -#define MT_ISWT5099EEN24 0x11 -#define MT_ISTEAC_MT2ST 0x12 -#define MT_ISEVEREX_FT40A 0x32 -#define MT_ISDDS1 0x51 -#define MT_ISDDS2 0x52 -#define MT_ISSCSI1 0x71 -#define MT_ISSCSI2 0x72 -#define MT_ISFTAPE_UNKNOWN 0x800000 -#define MT_ISFTAPE_FLAG 0x800000 - -struct mt_tape_info { - long t_type; - char *t_name; -}; - -#define MT_TAPE_INFO \ -{ \ - {MT_ISUNKNOWN, "Unknown type of tape device"}, \ - {MT_ISQIC02, "Generic QIC-02 tape streamer"}, \ - {MT_ISWT5150, "Wangtek 5150, QIC-150"}, \ - {MT_ISARCHIVE_5945L2, "Archive 5945L-2"}, \ - {MT_ISCMSJ500, "CMS Jumbo 500"}, \ - {MT_ISTDC3610, "Tandberg TDC 3610, QIC-24"}, \ - {MT_ISARCHIVE_VP60I, "Archive VP60i, QIC-02"}, \ - {MT_ISARCHIVE_2150L, "Archive Viper 2150L"}, \ - {MT_ISARCHIVE_2060L, "Archive Viper 2060L"}, \ - {MT_ISARCHIVESC499, "Archive SC-499 QIC-36 controller"}, \ - {MT_ISQIC02_ALL_FEATURES, "Generic QIC-02 tape, all features"}, \ - {MT_ISWT5099EEN24, "Wangtek 5099-een24, 60MB"}, \ - {MT_ISTEAC_MT2ST, "Teac MT-2ST 155mb data cassette drive"}, \ - {MT_ISEVEREX_FT40A, "Everex FT40A, QIC-40"}, \ - {MT_ISSCSI1, "Generic SCSI-1 tape"}, \ - {MT_ISSCSI2, "Generic SCSI-2 tape"}, \ - {0, 0} \ -} - -struct mtpos { - long mt_blkno; -}; - -struct mtconfiginfo { - long mt_type; - long ifc_type; - unsigned short irqnr; - unsigned short dmanr; - unsigned short port; - unsigned long debug; - unsigned have_dens:1; - unsigned have_bsf:1; - unsigned have_fsr:1; - unsigned have_bsr:1; - unsigned have_eod:1; - unsigned have_seek:1; - unsigned have_tell:1; - unsigned have_ras1:1; - unsigned have_ras2:1; - unsigned have_ras3:1; - unsigned have_qfa:1; - unsigned pad1:5; - char reserved[10]; -}; - -#define MTIOCTOP _IOW('m', 1, struct mtop) -#define MTIOCGET _IOR('m', 2, struct mtget) -#define MTIOCPOS _IOR('m', 3, struct mtpos) - -#define MTIOCGETCONFIG _IOR('m', 4, struct mtconfiginfo) -#define MTIOCSETCONFIG _IOW('m', 5, struct mtconfiginfo) - -#define GMT_EOF(x) ((x) & 0x80000000) -#define GMT_BOT(x) ((x) & 0x40000000) -#define GMT_EOT(x) ((x) & 0x20000000) -#define GMT_SM(x) ((x) & 0x10000000) -#define GMT_EOD(x) ((x) & 0x08000000) -#define GMT_WR_PROT(x) ((x) & 0x04000000) -#define GMT_ONLINE(x) ((x) & 0x01000000) -#define GMT_D_6250(x) ((x) & 0x00800000) -#define GMT_D_1600(x) ((x) & 0x00400000) -#define GMT_D_800(x) ((x) & 0x00200000) -#define GMT_DR_OPEN(x) ((x) & 0x00040000) -#define GMT_IM_REP_EN(x) ((x) & 0x00010000) - -#define MT_ST_BLKSIZE_SHIFT 0 -#define MT_ST_BLKSIZE_MASK 0xffffff -#define MT_ST_DENSITY_SHIFT 24 -#define MT_ST_DENSITY_MASK 0xff000000 -#define MT_ST_SOFTERR_SHIFT 0 -#define MT_ST_SOFTERR_MASK 0xffff -#define MT_ST_OPTIONS 0xf0000000 -#define MT_ST_BOOLEANS 0x10000000 -#define MT_ST_SETBOOLEANS 0x30000000 -#define MT_ST_CLEARBOOLEANS 0x40000000 -#define MT_ST_WRITE_THRESHOLD 0x20000000 -#define MT_ST_DEF_BLKSIZE 0x50000000 -#define MT_ST_DEF_OPTIONS 0x60000000 -#define MT_ST_BUFFER_WRITES 0x1 -#define MT_ST_ASYNC_WRITES 0x2 -#define MT_ST_READ_AHEAD 0x4 -#define MT_ST_DEBUGGING 0x8 -#define MT_ST_TWO_FM 0x10 -#define MT_ST_FAST_MTEOM 0x20 -#define MT_ST_AUTO_LOCK 0x40 -#define MT_ST_DEF_WRITES 0x80 -#define MT_ST_CAN_BSR 0x100 -#define MT_ST_NO_BLKLIMS 0x200 -#define MT_ST_CAN_PARTITIONS 0x400 -#define MT_ST_SCSI2LOGICAL 0x800 -#define MT_ST_CLEAR_DEFAULT 0xfffff -#define MT_ST_DEF_DENSITY (MT_ST_DEF_OPTIONS | 0x100000) -#define MT_ST_DEF_COMPRESSION (MT_ST_DEF_OPTIONS | 0x200000) -#define MT_ST_DEF_DRVBUFFER (MT_ST_DEF_OPTIONS | 0x300000) -#define MT_ST_HPLOADER_OFFSET 10000 -#ifndef DEFTAPE -# define DEFTAPE "/dev/tape" -#endif - -#endif diff --git a/usr/lib/libc/include/sys/param.h b/usr/lib/libc/include/sys/param.h deleted file mode 100644 index ce6b80198..000000000 --- a/usr/lib/libc/include/sys/param.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _SYS_PARAM_H -#define _SYS_PARAM_H - -#define MAXSYMLINKS 20 -#define MAXHOSTNAMELEN 64 -#define MAXNAMLEN 255 -#define MAXPATHLEN 4096 -#define NBBY 8 -#define NGROUPS 32 -#define CANBSIZ 255 -#define NOFILE 256 -#define NCARGS 131072 -#define DEV_BSIZE 512 -#define NOGROUP (-1) - -#undef MIN -#undef MAX -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) - -#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8)) -#define setbit(x,i) __bitop(x,i,|=) -#define clrbit(x,i) __bitop(x,i,&=~) -#define isset(x,i) __bitop(x,i,&) -#define isclr(x,i) !isset(x,i) - -#define howmany(n,d) (((n)+((d)-1))/(d)) -#define roundup(n,d) (howmany(n,d)*(d)) -#define powerof2(n) !(((n)-1) & (n)) - -#include -#include -#include - -#endif diff --git a/usr/lib/libc/include/sys/personality.h b/usr/lib/libc/include/sys/personality.h deleted file mode 100644 index 31d43dfe1..000000000 --- a/usr/lib/libc/include/sys/personality.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _PERSONALITY_H -#define _PERSONALITY_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define ADDR_NO_RANDOMIZE 0x0040000 -#define MMAP_PAGE_ZERO 0x0100000 -#define ADDR_COMPAT_LAYOUT 0x0200000 -#define READ_IMPLIES_EXEC 0x0400000 -#define ADDR_LIMIT_32BIT 0x0800000 -#define SHORT_INODE 0x1000000 -#define WHOLE_SECONDS 0x2000000 -#define STICKY_TIMEOUTS 0x4000000 -#define ADDR_LIMIT_3GB 0x8000000 - -#define PER_LINUX 0 -#define PER_LINUX_32BIT ADDR_LIMIT_32BIT -#define PER_SVR4 (1 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO) -#define PER_SVR3 (2 | STICKY_TIMEOUTS | SHORT_INODE) -#define PER_SCOSVR3 (3 | STICKY_TIMEOUTS | WHOLE_SECONDS | SHORT_INODE) -#define PER_OSR5 (3 | STICKY_TIMEOUTS | WHOLE_SECONDS) -#define PER_WYSEV386 (4 | STICKY_TIMEOUTS | SHORT_INODE) -#define PER_ISCR4 (5 | STICKY_TIMEOUTS) -#define PER_BSD 6 -#define PER_SUNOS (6 | STICKY_TIMEOUTS) -#define PER_XENIX (7 | STICKY_TIMEOUTS | SHORT_INODE) -#define PER_LINUX32 8 -#define PER_LINUX32_3GB (8 | ADDR_LIMIT_3GB) -#define PER_IRIX32 (9 | STICKY_TIMEOUTS) -#define PER_IRIXN32 (0xa | STICKY_TIMEOUTS) -#define PER_IRIX64 (0x0b | STICKY_TIMEOUTS) -#define PER_RISCOS 0xc -#define PER_SOLARIS (0xd | STICKY_TIMEOUTS) -#define PER_UW7 (0xe | STICKY_TIMEOUTS | MMAP_PAGE_ZERO) -#define PER_OSF4 0xf -#define PER_HPUX 0x10 -#define PER_MASK 0xff - -int personality(unsigned long); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/poll.h b/usr/lib/libc/include/sys/poll.h deleted file mode 100644 index 99170401d..000000000 --- a/usr/lib/libc/include/sys/poll.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning redirecting incorrect #include to -#include diff --git a/usr/lib/libc/include/sys/prctl.h b/usr/lib/libc/include/sys/prctl.h deleted file mode 100644 index 24f4f8bdf..000000000 --- a/usr/lib/libc/include/sys/prctl.h +++ /dev/null @@ -1,139 +0,0 @@ -#ifndef _SYS_PRCTL_H -#define _SYS_PRCTL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define PR_SET_PDEATHSIG 1 -#define PR_GET_PDEATHSIG 2 -#define PR_GET_DUMPABLE 3 -#define PR_SET_DUMPABLE 4 -#define PR_GET_UNALIGN 5 -#define PR_SET_UNALIGN 6 -#define PR_UNALIGN_NOPRINT 1 -#define PR_UNALIGN_SIGBUS 2 -#define PR_GET_KEEPCAPS 7 -#define PR_SET_KEEPCAPS 8 -#define PR_GET_FPEMU 9 -#define PR_SET_FPEMU 10 -#define PR_FPEMU_NOPRINT 1 -#define PR_FPEMU_SIGFPE 2 -#define PR_GET_FPEXC 11 -#define PR_SET_FPEXC 12 -#define PR_FP_EXC_SW_ENABLE 0x80 -#define PR_FP_EXC_DIV 0x010000 -#define PR_FP_EXC_OVF 0x020000 -#define PR_FP_EXC_UND 0x040000 -#define PR_FP_EXC_RES 0x080000 -#define PR_FP_EXC_INV 0x100000 -#define PR_FP_EXC_DISABLED 0 -#define PR_FP_EXC_NONRECOV 1 -#define PR_FP_EXC_ASYNC 2 -#define PR_FP_EXC_PRECISE 3 -#define PR_GET_TIMING 13 -#define PR_SET_TIMING 14 -#define PR_TIMING_STATISTICAL 0 -#define PR_TIMING_TIMESTAMP 1 -#define PR_SET_NAME 15 -#define PR_GET_NAME 16 -#define PR_GET_ENDIAN 19 -#define PR_SET_ENDIAN 20 -#define PR_ENDIAN_BIG 0 -#define PR_ENDIAN_LITTLE 1 -#define PR_ENDIAN_PPC_LITTLE 2 -#define PR_GET_SECCOMP 21 -#define PR_SET_SECCOMP 22 -#define PR_CAPBSET_READ 23 -#define PR_CAPBSET_DROP 24 -#define PR_GET_TSC 25 -#define PR_SET_TSC 26 -#define PR_TSC_ENABLE 1 -#define PR_TSC_SIGSEGV 2 -#define PR_GET_SECUREBITS 27 -#define PR_SET_SECUREBITS 28 -#define PR_SET_TIMERSLACK 29 -#define PR_GET_TIMERSLACK 30 - -#define PR_TASK_PERF_EVENTS_DISABLE 31 -#define PR_TASK_PERF_EVENTS_ENABLE 32 - -#define PR_MCE_KILL 33 -#define PR_MCE_KILL_CLEAR 0 -#define PR_MCE_KILL_SET 1 -#define PR_MCE_KILL_LATE 0 -#define PR_MCE_KILL_EARLY 1 -#define PR_MCE_KILL_DEFAULT 2 -#define PR_MCE_KILL_GET 34 - -#define PR_SET_MM 35 -#define PR_SET_MM_START_CODE 1 -#define PR_SET_MM_END_CODE 2 -#define PR_SET_MM_START_DATA 3 -#define PR_SET_MM_END_DATA 4 -#define PR_SET_MM_START_STACK 5 -#define PR_SET_MM_START_BRK 6 -#define PR_SET_MM_BRK 7 -#define PR_SET_MM_ARG_START 8 -#define PR_SET_MM_ARG_END 9 -#define PR_SET_MM_ENV_START 10 -#define PR_SET_MM_ENV_END 11 -#define PR_SET_MM_AUXV 12 -#define PR_SET_MM_EXE_FILE 13 -#define PR_SET_MM_MAP 14 -#define PR_SET_MM_MAP_SIZE 15 - -struct prctl_mm_map { - uint64_t start_code; - uint64_t end_code; - uint64_t start_data; - uint64_t end_data; - uint64_t start_brk; - uint64_t brk; - uint64_t start_stack; - uint64_t arg_start; - uint64_t arg_end; - uint64_t env_start; - uint64_t env_end; - uint64_t *auxv; - uint32_t auxv_size; - uint32_t exe_fd; -}; - -#define PR_SET_PTRACER 0x59616d61 -#define PR_SET_PTRACER_ANY (-1UL) - -#define PR_SET_CHILD_SUBREAPER 36 -#define PR_GET_CHILD_SUBREAPER 37 - -#define PR_SET_NO_NEW_PRIVS 38 -#define PR_GET_NO_NEW_PRIVS 39 - -#define PR_GET_TID_ADDRESS 40 - -#define PR_SET_THP_DISABLE 41 -#define PR_GET_THP_DISABLE 42 - -#define PR_MPX_ENABLE_MANAGEMENT 43 -#define PR_MPX_DISABLE_MANAGEMENT 44 - -#define PR_SET_FP_MODE 45 -#define PR_GET_FP_MODE 46 -#define PR_FP_MODE_FR (1 << 0) -#define PR_FP_MODE_FRE (1 << 1) - -#define PR_CAP_AMBIENT 47 -#define PR_CAP_AMBIENT_IS_SET 1 -#define PR_CAP_AMBIENT_RAISE 2 -#define PR_CAP_AMBIENT_LOWER 3 -#define PR_CAP_AMBIENT_CLEAR_ALL 4 - -int prctl (int, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/procfs.h b/usr/lib/libc/include/sys/procfs.h deleted file mode 100644 index e23bf1ad6..000000000 --- a/usr/lib/libc/include/sys/procfs.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _SYS_PROCFS_H -#define _SYS_PROCFS_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -struct elf_siginfo { - int si_signo; - int si_code; - int si_errno; -}; - -struct elf_prstatus { - struct elf_siginfo pr_info; - short int pr_cursig; - unsigned long int pr_sigpend; - unsigned long int pr_sighold; - pid_t pr_pid; - pid_t pr_ppid; - pid_t pr_pgrp; - pid_t pr_sid; - struct timeval pr_utime; - struct timeval pr_stime; - struct timeval pr_cutime; - struct timeval pr_cstime; - elf_gregset_t pr_reg; - int pr_fpvalid; -}; - -#define ELF_PRARGSZ 80 - -struct elf_prpsinfo { - char pr_state; - char pr_sname; - char pr_zomb; - char pr_nice; - unsigned long int pr_flag; -#if UINTPTR_MAX == 0xffffffff - unsigned short int pr_uid; - unsigned short int pr_gid; -#else - unsigned int pr_uid; - unsigned int pr_gid; -#endif - int pr_pid, pr_ppid, pr_pgrp, pr_sid; - char pr_fname[16]; - char pr_psargs[ELF_PRARGSZ]; -}; - -typedef void *psaddr_t; -typedef elf_gregset_t prgregset_t; -typedef elf_fpregset_t prfpregset_t; -typedef pid_t lwpid_t; -typedef struct elf_prstatus prstatus_t; -typedef struct elf_prpsinfo prpsinfo_t; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/ptrace.h b/usr/lib/libc/include/sys/ptrace.h deleted file mode 100644 index b54e448b1..000000000 --- a/usr/lib/libc/include/sys/ptrace.h +++ /dev/null @@ -1,195 +0,0 @@ -#ifndef _SYS_PTRACE_H -#define _SYS_PTRACE_H - -#include - -/* Type of the REQUEST argument to `ptrace.' */ -enum __ptrace_request -{ - /* Indicate that the process making this request should be traced. - All signals received by this process can be intercepted by its - parent, and its parent can use the other `ptrace' requests. */ - PTRACE_TRACEME = 0, -#define PT_TRACE_ME PTRACE_TRACEME - - /* Return the word in the process's text space at address ADDR. */ - PTRACE_PEEKTEXT = 1, -#define PT_READ_I PTRACE_PEEKTEXT - - /* Return the word in the process's data space at address ADDR. */ - PTRACE_PEEKDATA = 2, -#define PT_READ_D PTRACE_PEEKDATA - - /* Return the word in the process's user area at offset ADDR. */ - PTRACE_PEEKUSER = 3, -#define PT_READ_U PTRACE_PEEKUSER - - /* Write the word DATA into the process's text space at address ADDR. */ - PTRACE_POKETEXT = 4, -#define PT_WRITE_I PTRACE_POKETEXT - - /* Write the word DATA into the process's data space at address ADDR. */ - PTRACE_POKEDATA = 5, -#define PT_WRITE_D PTRACE_POKEDATA - - /* Write the word DATA into the process's user area at offset ADDR. */ - PTRACE_POKEUSER = 6, -#define PT_WRITE_U PTRACE_POKEUSER - - /* Continue the process. */ - PTRACE_CONT = 7, -#define PT_CONTINUE PTRACE_CONT - - /* Kill the process. */ - PTRACE_KILL = 8, -#define PT_KILL PTRACE_KILL - - /* Single step the process. */ - PTRACE_SINGLESTEP = 9, -#define PT_STEP PTRACE_SINGLESTEP - - /* Get all general purpose registers used by a processes. */ - PTRACE_GETREGS = 12, -#define PT_GETREGS PTRACE_GETREGS - - /* Set all general purpose registers used by a processes. */ - PTRACE_SETREGS = 13, -#define PT_SETREGS PTRACE_SETREGS - - /* Get all floating point registers used by a processes. */ - PTRACE_GETFPREGS = 14, -#define PT_GETFPREGS PTRACE_GETFPREGS - - /* Set all floating point registers used by a processes. */ - PTRACE_SETFPREGS = 15, -#define PT_SETFPREGS PTRACE_SETFPREGS - - /* Attach to a process that is already running. */ - PTRACE_ATTACH = 16, -#define PT_ATTACH PTRACE_ATTACH - - /* Detach from a process attached to with PTRACE_ATTACH. */ - PTRACE_DETACH = 17, -#define PT_DETACH PTRACE_DETACH - - /* Get all extended floating point registers used by a processes. */ - PTRACE_GETFPXREGS = 18, -#define PT_GETFPXREGS PTRACE_GETFPXREGS - - /* Set all extended floating point registers used by a processes. */ - PTRACE_SETFPXREGS = 19, -#define PT_SETFPXREGS PTRACE_SETFPXREGS - - /* Continue and stop at the next entry to or return from syscall. */ - PTRACE_SYSCALL = 24, -#define PT_SYSCALL PTRACE_SYSCALL - - /* Get a TLS entry in the GDT. */ - PTRACE_GET_THREAD_AREA = 25, -#define PT_GET_THREAD_AREA PTRACE_GET_THREAD_AREA - - /* Change a TLS entry in the GDT. */ - PTRACE_SET_THREAD_AREA = 26, -#define PT_SET_THREAD_AREA PTRACE_SET_THREAD_AREA - - /* Continue and stop at the next syscall, it will not be executed. */ - PTRACE_SYSEMU = 31, -#define PT_SYSEMU PTRACE_SYSEMU - - /* Single step the process, the next syscall will not be executed. */ - PTRACE_SYSEMU_SINGLESTEP = 32, -#define PT_SYSEMU_SINGLESTEP PTRACE_SYSEMU_SINGLESTEP - - /* Execute process until next taken branch. */ - PTRACE_SINGLEBLOCK = 33, -#define PT_STEPBLOCK PTRACE_SINGLEBLOCK - - /* Set ptrace filter options. */ - PTRACE_SETOPTIONS = 0x4200, -#define PT_SETOPTIONS PTRACE_SETOPTIONS - - /* Get last ptrace message. */ - PTRACE_GETEVENTMSG = 0x4201, -#define PT_GETEVENTMSG PTRACE_GETEVENTMSG - - /* Get siginfo for process. */ - PTRACE_GETSIGINFO = 0x4202, -#define PT_GETSIGINFO PTRACE_GETSIGINFO - - /* Set new siginfo for process. */ - PTRACE_SETSIGINFO = 0x4203, -#define PT_SETSIGINFO PTRACE_SETSIGINFO - - /* Get register content. */ - PTRACE_GETREGSET = 0x4204, -#define PTRACE_GETREGSET PTRACE_GETREGSET - - /* Set register content. */ - PTRACE_SETREGSET = 0x4205, -#define PTRACE_SETREGSET PTRACE_SETREGSET - - /* Like PTRACE_ATTACH, but do not force tracee to trap and do not affect - signal or group stop state. */ - PTRACE_SEIZE = 0x4206, -#define PTRACE_SEIZE PTRACE_SEIZE - - /* Trap seized tracee. */ - PTRACE_INTERRUPT = 0x4207, -#define PTRACE_INTERRUPT PTRACE_INTERRUPT - - /* Wait for next group event. */ - PTRACE_LISTEN = 0x4208, -#define PTRACE_LISTEN PTRACE_LISTEN - - /* Retrieve siginfo_t structures without removing signals from a queue. */ - PTRACE_PEEKSIGINFO = 0x4209, -#define PTRACE_PEEKSIGINFO PTRACE_PEEKSIGINFO - - /* Get the mask of blocked signals. */ - PTRACE_GETSIGMASK = 0x420a, -#define PTRACE_GETSIGMASK PTRACE_GETSIGMASK - - /* Change the mask of blocked signals. */ - PTRACE_SETSIGMASK = 0x420b, -#define PTRACE_SETSIGMASK PTRACE_SETSIGMASK - - /* Get seccomp BPF filters. */ - PTRACE_SECCOMP_GET_FILTER = 0x420c -#define PTRACE_SECCOMP_GET_FILTER PTRACE_SECCOMP_GET_FILTER -}; - - -#define PTRACE_O_TRACESYSGOOD 0x00000001 -#define PTRACE_O_TRACEFORK 0x00000002 -#define PTRACE_O_TRACEVFORK 0x00000004 -#define PTRACE_O_TRACECLONE 0x00000008 -#define PTRACE_O_TRACEEXEC 0x00000010 -#define PTRACE_O_TRACEVFORKDONE 0x00000020 -#define PTRACE_O_TRACEEXIT 0x00000040 -#define PTRACE_O_TRACESECCOMP 0x00000080 -#define PTRACE_O_EXITKILL 0x00100000 -#define PTRACE_O_SUSPEND_SECCOMP 0x00200000 -#define PTRACE_O_MASK 0x003000ff - -#define PTRACE_EVENT_FORK 1 -#define PTRACE_EVENT_VFORK 2 -#define PTRACE_EVENT_CLONE 3 -#define PTRACE_EVENT_EXEC 4 -#define PTRACE_EVENT_VFORK_DONE 5 -#define PTRACE_EVENT_EXIT 6 -#define PTRACE_EVENT_SECCOMP 7 - -#define PTRACE_PEEKSIGINFO_SHARED 1 - -struct ptrace_peeksiginfo_args { - uint64_t off; - uint32_t flags; - int32_t nr; -}; - -long ptrace(int, ...); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/quota.h b/usr/lib/libc/include/sys/quota.h deleted file mode 100644 index 3ed73785d..000000000 --- a/usr/lib/libc/include/sys/quota.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef _SYS_QUOTA_H -#define _SYS_QUOTA_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define _LINUX_QUOTA_VERSION 2 - -#define dbtob(num) ((num) << 10) -#define btodb(num) ((num) >> 10) -#define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / 1024) - -#define MAX_IQ_TIME 604800 -#define MAX_DQ_TIME 604800 - -#define MAXQUOTAS 2 -#define USRQUOTA 0 -#define GRPQUOTA 1 - -#define INITQFNAMES { "user", "group", "undefined" }; - -#define QUOTAFILENAME "quota" -#define QUOTAGROUP "staff" - -#define NR_DQHASH 43 -#define NR_DQUOTS 256 - -#define SUBCMDMASK 0x00ff -#define SUBCMDSHIFT 8 -#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) - -#define Q_SYNC 0x800001 -#define Q_QUOTAON 0x800002 -#define Q_QUOTAOFF 0x800003 -#define Q_GETFMT 0x800004 -#define Q_GETINFO 0x800005 -#define Q_SETINFO 0x800006 -#define Q_GETQUOTA 0x800007 -#define Q_SETQUOTA 0x800008 - -#define QFMT_VFS_OLD 1 -#define QFMT_VFS_V0 2 -#define QFMT_OCFS2 3 -#define QFMT_VFS_V1 4 - -#define QIF_BLIMITS 1 -#define QIF_SPACE 2 -#define QIF_ILIMITS 4 -#define QIF_INODES 8 -#define QIF_BTIME 16 -#define QIF_ITIME 32 -#define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS) -#define QIF_USAGE (QIF_SPACE | QIF_INODES) -#define QIF_TIMES (QIF_BTIME | QIF_ITIME) -#define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES) - -struct dqblk { - uint64_t dqb_bhardlimit; - uint64_t dqb_bsoftlimit; - uint64_t dqb_curspace; - uint64_t dqb_ihardlimit; - uint64_t dqb_isoftlimit; - uint64_t dqb_curinodes; - uint64_t dqb_btime; - uint64_t dqb_itime; - uint32_t dqb_valid; -}; - -#define dq_bhardlimit dq_dqb.dqb_bhardlimit -#define dq_bsoftlimit dq_dqb.dqb_bsoftlimit -#define dq_curspace dq_dqb.dqb_curspace -#define dq_valid dq_dqb.dqb_valid -#define dq_ihardlimit dq_dqb.dqb_ihardlimit -#define dq_isoftlimit dq_dqb.dqb_isoftlimit -#define dq_curinodes dq_dqb.dqb_curinodes -#define dq_btime dq_dqb.dqb_btime -#define dq_itime dq_dqb.dqb_itime - -#define dqoff(UID) ((long long)(UID) * sizeof (struct dqblk)) - -#define IIF_BGRACE 1 -#define IIF_IGRACE 2 -#define IIF_FLAGS 4 -#define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS) - -struct dqinfo { - uint64_t dqi_bgrace; - uint64_t dqi_igrace; - uint32_t dqi_flags; - uint32_t dqi_valid; -}; - -int quotactl(int, const char *, int, char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/reboot.h b/usr/lib/libc/include/sys/reboot.h deleted file mode 100644 index 9702eddba..000000000 --- a/usr/lib/libc/include/sys/reboot.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _SYS_REBOOT_H -#define _SYS_REBOOT_H -#ifdef __cplusplus -extern "C" { -#endif - -#define RB_AUTOBOOT 0x01234567 -#define RB_HALT_SYSTEM 0xcdef0123 -#define RB_ENABLE_CAD 0x89abcdef -#define RB_DISABLE_CAD 0 -#define RB_POWER_OFF 0x4321fedc -#define RB_SW_SUSPEND 0xd000fce2 -#define RB_KEXEC 0x45584543 - -int reboot(int); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/reg.h b/usr/lib/libc/include/sys/reg.h deleted file mode 100644 index b47452d00..000000000 --- a/usr/lib/libc/include/sys/reg.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _SYS_REG_H -#define _SYS_REG_H - -#include -#include - -#include - -#endif diff --git a/usr/lib/libc/include/sys/resource.h b/usr/lib/libc/include/sys/resource.h deleted file mode 100644 index 5798955bc..000000000 --- a/usr/lib/libc/include/sys/resource.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef _SYS_RESOURCE_H -#define _SYS_RESOURCE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_id_t - -#ifdef _GNU_SOURCE -#define __NEED_pid_t -#endif - -#include -//#include - -typedef unsigned long long rlim_t; - -struct rlimit { - rlim_t rlim_cur; - rlim_t rlim_max; -}; - -struct rusage { - struct timeval ru_utime; - struct timeval ru_stime; - /* linux extentions, but useful */ - long ru_maxrss; - long ru_ixrss; - long ru_idrss; - long ru_isrss; - long ru_minflt; - long ru_majflt; - long ru_nswap; - long ru_inblock; - long ru_oublock; - long ru_msgsnd; - long ru_msgrcv; - long ru_nsignals; - long ru_nvcsw; - long ru_nivcsw; - /* room for more... */ - long __reserved[16]; -}; - -int getrlimit (int, struct rlimit *); -int setrlimit (int, const struct rlimit *); -int getrusage (int, struct rusage *); - -int getpriority (int, id_t); -int setpriority (int, id_t, int); - -#ifdef _GNU_SOURCE -int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); -#define prlimit64 prlimit -#endif - -#define PRIO_MIN (-20) -#define PRIO_MAX 20 - -#define PRIO_PROCESS 0 -#define PRIO_PGRP 1 -#define PRIO_USER 2 - -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN (-1) -#define RUSAGE_THREAD 1 - -#define RLIM_INFINITY (~0ULL) -#define RLIM_SAVED_CUR RLIM_INFINITY -#define RLIM_SAVED_MAX RLIM_INFINITY - - -#define RLIMIT_CPU 0 -#define RLIMIT_FSIZE 1 -#define RLIMIT_DATA 2 -#define RLIMIT_STACK 3 -#define RLIMIT_CORE 4 -#ifndef RLIMIT_RSS -#define RLIMIT_RSS 5 -#define RLIMIT_NPROC 6 -#define RLIMIT_NOFILE 7 -#define RLIMIT_MEMLOCK 8 -#define RLIMIT_AS 9 -#endif -#define RLIMIT_LOCKS 10 -#define RLIMIT_SIGPENDING 11 -#define RLIMIT_MSGQUEUE 12 -#define RLIMIT_NICE 13 -#define RLIMIT_RTPRIO 14 -#define RLIMIT_NLIMITS 15 - -#define RLIM_NLIMITS RLIMIT_NLIMITS - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define RLIM64_INFINITY RLIM_INFINITY -#define RLIM64_SAVED_CUR RLIM_SAVED_CUR -#define RLIM64_SAVED_MAX RLIM_SAVED_MAX -#define getrlimit64 getrlimit -#define setrlimit64 setrlimit -#define rlimit64 rlimit -#define rlim64_t rlim_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/select.h b/usr/lib/libc/include/sys/select.h deleted file mode 100644 index d34cbf10d..000000000 --- a/usr/lib/libc/include/sys/select.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _SYS_SELECT_H -#define _SYS_SELECT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_suseconds_t -#define __NEED_struct_timeval -#define __NEED_struct_timespec -#define __NEED_sigset_t - -#include - -#define FD_SETSIZE 1024 - -typedef unsigned long fd_mask; - -typedef struct { - unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; -} fd_set; - -#define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) -#define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) -#define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) -#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) - -int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); -int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define NFDBITS (8*(int)sizeof(long)) -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/sem.h b/usr/lib/libc/include/sys/sem.h deleted file mode 100644 index e7c369803..000000000 --- a/usr/lib/libc/include/sys/sem.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _SYS_SEM_H -#define _SYS_SEM_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_pid_t -#define __NEED_time_t -#ifdef _GNU_SOURCE -#define __NEED_struct_timespec -#endif -#include - -#include - -#define SEM_UNDO 0x1000 -#define GETPID 11 -#define GETVAL 12 -#define GETALL 13 -#define GETNCNT 14 -#define GETZCNT 15 -#define SETVAL 16 -#define SETALL 17 - -#include - -#include - -#define _SEM_SEMUN_UNDEFINED 1 - -#define SEM_STAT 18 -#define SEM_INFO 19 - -struct seminfo { - int semmap; - int semmni; - int semmns; - int semmnu; - int semmsl; - int semopm; - int semume; - int semusz; - int semvmx; - int semaem; -}; - -struct sembuf { - unsigned short sem_num; - short sem_op; - short sem_flg; -}; - -int semctl(int, int, int, ...); -int semget(key_t, int, int); -int semop(int, struct sembuf *, size_t); - -#ifdef _GNU_SOURCE -int semtimedop(int, struct sembuf *, size_t, const struct timespec *); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/sendfile.h b/usr/lib/libc/include/sys/sendfile.h deleted file mode 100644 index e7570d8e5..000000000 --- a/usr/lib/libc/include/sys/sendfile.h +++ /dev/null @@ -1,22 +0,0 @@ -#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 diff --git a/usr/lib/libc/include/sys/shm.h b/usr/lib/libc/include/sys/shm.h deleted file mode 100644 index 67be822bc..000000000 --- a/usr/lib/libc/include/sys/shm.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _SYS_SHM_H -#define _SYS_SHM_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_time_t -#define __NEED_size_t -#define __NEED_pid_t - -#include - -#include - -#ifdef _GNU_SOURCE -#define __used_ids used_ids -#define __swap_attempts swap_attempts -#define __swap_successes swap_successes -#endif - -#include - -#define SHM_R 0400 -#define SHM_W 0200 - -#define SHM_RDONLY 010000 -#define SHM_RND 020000 -#define SHM_REMAP 040000 -#define SHM_EXEC 0100000 - -#define SHM_LOCK 11 -#define SHM_UNLOCK 12 -#define SHM_STAT 13 -#define SHM_INFO 14 -#define SHM_DEST 01000 -#define SHM_LOCKED 02000 -#define SHM_HUGETLB 04000 -#define SHM_NORESERVE 010000 - -typedef unsigned long shmatt_t; - -void *shmat(int, const void *, int); -int shmctl(int, int, struct shmid_ds *); -int shmdt(const void *); -int shmget(key_t, size_t, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/signal.h b/usr/lib/libc/include/sys/signal.h deleted file mode 100644 index 45bdcc648..000000000 --- a/usr/lib/libc/include/sys/signal.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning redirecting incorrect #include to -#include diff --git a/usr/lib/libc/include/sys/signalfd.h b/usr/lib/libc/include/sys/signalfd.h deleted file mode 100644 index 55431b916..000000000 --- a/usr/lib/libc/include/sys/signalfd.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _SYS_SIGNALFD_H -#define _SYS_SIGNALFD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_sigset_t - -#include - -#define SFD_CLOEXEC O_CLOEXEC -#define SFD_NONBLOCK O_NONBLOCK - -int signalfd(int, const sigset_t *, int); - -struct signalfd_siginfo { - uint32_t ssi_signo; - int32_t ssi_errno; - int32_t ssi_code; - uint32_t ssi_pid; - uint32_t ssi_uid; - int32_t ssi_fd; - uint32_t ssi_tid; - uint32_t ssi_band; - uint32_t ssi_overrun; - uint32_t ssi_trapno; - int32_t ssi_status; - int32_t ssi_int; - uint64_t ssi_ptr; - uint64_t ssi_utime; - uint64_t ssi_stime; - uint64_t ssi_addr; - uint16_t ssi_addr_lsb; - uint8_t pad[128-12*4-4*8-2]; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/socket.h b/usr/lib/libc/include/sys/socket.h deleted file mode 100644 index ce48adecf..000000000 --- a/usr/lib/libc/include/sys/socket.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef _SYS_SOCKET_H -#define _SYS_SOCKET_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_socklen_t -#define __NEED_sa_family_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_pid_t -#define __NEED_gid_t -#define __NEED_struct_iovec - -#include - -#include - -#ifdef _GNU_SOURCE -struct ucred { - pid_t pid; - uid_t uid; - gid_t gid; -}; - -struct mmsghdr { - struct msghdr msg_hdr; - unsigned int msg_len; -}; - -struct timespec; - -int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); -int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); -#endif - -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#ifndef SOCK_STREAM -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#endif - -#ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC 02000000 -#define SOCK_NONBLOCK 04000 -#endif - -#ifndef SO_DEBUG -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -#define SO_REUSEPORT 15 -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 -#define SO_ACCEPTCONN 30 -#define SO_SNDBUFFORCE 32 -#define SO_RCVBUFFORCE 33 -#define SO_PROTOCOL 38 -#define SO_DOMAIN 39 -#endif - -#if 0 /* Already present in the toolchain */ -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 - -#define SO_BINDTODEVICE 25 - -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 -#define SO_GET_FILTER SO_ATTACH_FILTER - -#define SO_PEERNAME 28 -#define SO_TIMESTAMP 29 -#define SCM_TIMESTAMP SO_TIMESTAMP - -#define SO_PEERSEC 31 -#define SO_PASSSEC 34 -#define SO_TIMESTAMPNS 35 -#define SCM_TIMESTAMPNS SO_TIMESTAMPNS -#define SO_MARK 36 -#define SO_TIMESTAMPING 37 -#define SCM_TIMESTAMPING SO_TIMESTAMPING -#define SO_RXQ_OVFL 40 -#define SO_WIFI_STATUS 41 -#define SCM_WIFI_STATUS SO_WIFI_STATUS -#define SO_PEEK_OFF 42 -#define SO_NOFCS 43 -#define SO_LOCK_FILTER 44 -#define SO_SELECT_ERR_QUEUE 45 -#define SO_BUSY_POLL 46 -#define SO_MAX_PACING_RATE 47 -#define SO_BPF_EXTENSIONS 48 -#define SO_INCOMING_CPU 49 -#define SO_ATTACH_BPF 50 -#define SO_DETACH_BPF SO_DETACH_FILTER -#define SO_ATTACH_REUSEPORT_CBPF 51 -#define SO_ATTACH_REUSEPORT_EBPF 52 -#define SO_CNX_ADVICE 53 - -#endif /* 0 */ - -#ifndef SOL_SOCKET -#define SOL_SOCKET 1 -#endif - -#define SOL_IP 0 -#define SOL_IPV6 41 -#define SOL_ICMPV6 58 - -#define SOL_RAW 255 -#define SOL_DECNET 261 -#define SOL_X25 262 -#define SOL_PACKET 263 -#define SOL_ATM 264 -#define SOL_AAL 265 -#define SOL_IRDA 266 -#define SOL_NETBEUI 267 -#define SOL_LLC 268 -#define SOL_DCCP 269 -#define SOL_NETLINK 270 -#define SOL_TIPC 271 -#define SOL_RXRPC 272 -#define SOL_PPPOL2TP 273 -#define SOL_BLUETOOTH 274 -#define SOL_PNPIPE 275 -#define SOL_RDS 276 -#define SOL_IUCV 277 -#define SOL_CAIF 278 -#define SOL_ALG 279 -#define SOL_NFC 280 -#define SOL_KCM 281 - -#define SOMAXCONN 128 - -#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) -#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) -#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) - -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) - -#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)) - -#define SCM_CREDENTIALS 0x02 - -struct sockaddr_storage { - sa_family_t ss_family; - char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; - unsigned long __ss_align; -}; - -int socket (int, int, int); -int socketpair (int, int, int, int [2]); - -int shutdown (int, int); - -int bind (int, const struct sockaddr *, socklen_t); -int connect (int, const struct sockaddr *, socklen_t); -int listen (int, int); -int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); -int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); - -int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); -int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); - -ssize_t send (int, const void *, size_t, int); -ssize_t recv (int, void *, size_t, int); -ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); -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); - -int sockatmark (int); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/soundcard.h b/usr/lib/libc/include/sys/soundcard.h deleted file mode 100644 index fade986fe..000000000 --- a/usr/lib/libc/include/sys/soundcard.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/usr/lib/libc/include/sys/stat.h b/usr/lib/libc/include/sys/stat.h deleted file mode 100644 index 452e82d42..000000000 --- a/usr/lib/libc/include/sys/stat.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef _SYS_STAT_H -#define _SYS_STAT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_dev_t -#define __NEED_ino_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_time_t -#define __NEED_blksize_t -#define __NEED_blkcnt_t -#define __NEED_struct_timespec - -#include - -#include - -/* - * Currently, in so3, only FAT is supported and following - * mode attributes. - */ -#define AM_RDO 0x01 /* Read only */ -#define AM_HID 0x02 /* Hidden */ -#define AM_SYS 0x04 /* System */ -#define AM_DIR 0x10 /* Directory */ -#define AM_ARC 0x20 /* Archive */ -#define AM_SYM 0x40 /* Symbolic link */ -#define AM_RD 0x100 /* Read permissions */ -#define AM_WR 0x200 /* Write permissions */ -#define AM_EX 0x400 /* Execution permissions */ - - -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec - -#define S_IFMT 0170000 - -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFBLK 0060000 -#define S_IFREG 0100000 -#define S_IFIFO 0010000 -#define S_IFLNK 0120000 -#define S_IFSOCK 0140000 - -#define S_TYPEISMQ(buf) 0 -#define S_TYPEISSEM(buf) 0 -#define S_TYPEISSHM(buf) 0 -#define S_TYPEISTMO(buf) 0 - -#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) -#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) -#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) -#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) - -#ifndef S_IRUSR -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRWXU 0700 -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IRWXG 0070 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 -#define S_IRWXO 0007 -#endif - -#define UTIME_NOW 0x3fffffff -#define UTIME_OMIT 0x3ffffffe - -int stat(const char *__restrict, struct stat *__restrict); -int fstat(int, struct stat *); -int lstat(const char *__restrict, struct stat *__restrict); -int fstatat(int, const char *__restrict, struct stat *__restrict, int); -int chmod(const char *, mode_t); -int fchmod(int, mode_t); -int fchmodat(int, const char *, mode_t, int); -mode_t umask(mode_t); -int mkdir(const char *, mode_t); -int mkfifo(const char *, mode_t); -int mkdirat(int, const char *, mode_t); -int mkfifoat(int, const char *, mode_t); - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#if 0 /* Not available yet */ -int mknod(const char *, mode_t, dev_t); -int mknodat(int, const char *, mode_t, dev_t); -#endif /* 0 */ - -#endif - -int futimens(int, const struct timespec [2]); -int utimensat(int, const char *, const struct timespec [2], int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int lchmod(const char *, mode_t); -#define S_IREAD S_IRUSR -#define S_IWRITE S_IWUSR -#define S_IEXEC S_IXUSR -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define stat64 stat -#define fstat64 fstat -#define lstat64 lstat -#define fstatat64 fstatat -#define blkcnt64_t blkcnt_t -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#define ino64_t ino_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif -#endif - - diff --git a/usr/lib/libc/include/sys/statfs.h b/usr/lib/libc/include/sys/statfs.h deleted file mode 100644 index 6f4c6230f..000000000 --- a/usr/lib/libc/include/sys/statfs.h +++ /dev/null @@ -1,32 +0,0 @@ -#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 diff --git a/usr/lib/libc/include/sys/statvfs.h b/usr/lib/libc/include/sys/statvfs.h deleted file mode 100644 index e0839ecac..000000000 --- a/usr/lib/libc/include/sys/statvfs.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _SYS_STATVFS_H -#define _SYS_STATVFS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t -#include - -#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 - -#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 diff --git a/usr/lib/libc/include/sys/stropts.h b/usr/lib/libc/include/sys/stropts.h deleted file mode 100644 index 5b5bc02f4..000000000 --- a/usr/lib/libc/include/sys/stropts.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/usr/lib/libc/include/sys/swap.h b/usr/lib/libc/include/sys/swap.h deleted file mode 100644 index 11c0f9296..000000000 --- a/usr/lib/libc/include/sys/swap.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _SYS_SWAP_H -#define _SYS_SWAP_H - -#ifdef __cplusplus -extern "C" { -#endif - - -#define SWAP_FLAG_PREFER 0x8000 -#define SWAP_FLAG_PRIO_MASK 0x7fff -#define SWAP_FLAG_PRIO_SHIFT 0 -#define SWAP_FLAG_DISCARD 0x10000 - -int swapon (const char *, int); -int swapoff (const char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/syscall.h b/usr/lib/libc/include/sys/syscall.h deleted file mode 100644 index 24987ddf2..000000000 --- a/usr/lib/libc/include/sys/syscall.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _SYS_SYSCALL_H -#define _SYS_SYSCALL_H - -#include - -#endif diff --git a/usr/lib/libc/include/sys/sysinfo.h b/usr/lib/libc/include/sys/sysinfo.h deleted file mode 100644 index 6a3931e52..000000000 --- a/usr/lib/libc/include/sys/sysinfo.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _SYS_SYSINFO_H -#define _SYS_SYSINFO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define SI_LOAD_SHIFT 16 - -struct sysinfo { - unsigned long uptime; - unsigned long loads[3]; - unsigned long totalram; - unsigned long freeram; - unsigned long sharedram; - unsigned long bufferram; - unsigned long totalswap; - unsigned long freeswap; - unsigned short procs, pad; - unsigned long totalhigh; - unsigned long freehigh; - unsigned mem_unit; - char __reserved[256]; -}; - -int sysinfo (struct sysinfo *); -int get_nprocs_conf (void); -int get_nprocs (void); -long get_phys_pages (void); -long get_avphys_pages (void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/syslog.h b/usr/lib/libc/include/sys/syslog.h deleted file mode 100644 index 7761eceeb..000000000 --- a/usr/lib/libc/include/sys/syslog.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/usr/lib/libc/include/sys/sysmacros.h b/usr/lib/libc/include/sys/sysmacros.h deleted file mode 100644 index 07a3ef183..000000000 --- a/usr/lib/libc/include/sys/sysmacros.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _SYS_SYSMACROS_H -#define _SYS_SYSMACROS_H - -#define major(x) \ - ((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) )) -#define minor(x) \ - ((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) )) - -#define makedev(x,y) ( \ - (((x)&0xfffff000ULL) << 32) | \ - (((x)&0x00000fffULL) << 8) | \ - (((y)&0xffffff00ULL) << 12) | \ - (((y)&0x000000ffULL)) ) - -#endif diff --git a/usr/lib/libc/include/sys/termios.h b/usr/lib/libc/include/sys/termios.h deleted file mode 100644 index f5f751f04..000000000 --- a/usr/lib/libc/include/sys/termios.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning redirecting incorrect #include to -#include diff --git a/usr/lib/libc/include/sys/time.h b/usr/lib/libc/include/sys/time.h deleted file mode 100644 index c5cab814c..000000000 --- a/usr/lib/libc/include/sys/time.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _SYS_TIME_H -#define _SYS_TIME_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -int gettimeofday (struct timeval *__restrict, void *__restrict); - -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 - -struct itimerval { - struct timeval it_interval; - struct timeval it_value; -}; - -int getitimer (int, struct itimerval *); -int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict); -int utimes (const char *, const struct timeval [2]); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; -int futimes(int, const struct timeval [2]); -int futimesat(int, const char *, const struct timeval [2]); -int lutimes(const char *, const struct timeval [2]); -int settimeofday(const struct timeval *, const struct timezone *); -int adjtime (const struct timeval *, struct timeval *); -#define timerisset(t) ((t)->tv_sec || (t)->tv_usec) -#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) -#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ - (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) -#define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ - ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \ - ((a)->tv_usec -= 1000000, (a)->tv_sec++) ) -#define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \ - ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \ - ((a)->tv_usec += 1000000, (a)->tv_sec--) ) -#endif - -#if defined(_GNU_SOURCE) -#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \ - (ts)->tv_sec = (tv)->tv_sec, \ - (ts)->tv_nsec = (tv)->tv_usec * 1000, \ - (void)0 ) -#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \ - (tv)->tv_sec = (ts)->tv_sec, \ - (tv)->tv_usec = (ts)->tv_nsec / 1000, \ - (void)0 ) -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/timeb.h b/usr/lib/libc/include/sys/timeb.h deleted file mode 100644 index 108c1f5cc..000000000 --- a/usr/lib/libc/include/sys/timeb.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _SYS_TIMEB_H -#define _SYS_TIMEB_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_time_t - -#include - -struct timeb { - time_t time; - unsigned short millitm; - short timezone, dstflag; -}; - -int ftime(struct timeb *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/timerfd.h b/usr/lib/libc/include/sys/timerfd.h deleted file mode 100644 index 9724d9034..000000000 --- a/usr/lib/libc/include/sys/timerfd.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _SYS_TIMERFD_H -#define _SYS_TIMERFD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define TFD_NONBLOCK O_NONBLOCK -#define TFD_CLOEXEC O_CLOEXEC - -#define TFD_TIMER_ABSTIME 1 - -struct itimerspec; - -int timerfd_create(int, int); -int timerfd_settime(int, int, const struct itimerspec *, struct itimerspec *); -int timerfd_gettime(int, struct itimerspec *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/times.h b/usr/lib/libc/include/sys/times.h deleted file mode 100644 index 80a50522d..000000000 --- a/usr/lib/libc/include/sys/times.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _SYS_TIMES_H -#define _SYS_TIMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_clock_t -#include - -struct tms { - clock_t tms_utime; - clock_t tms_stime; - clock_t tms_cutime; - clock_t tms_cstime; -}; - -clock_t times (struct tms *); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/usr/lib/libc/include/sys/timex.h b/usr/lib/libc/include/sys/timex.h deleted file mode 100644 index 2e688880a..000000000 --- a/usr/lib/libc/include/sys/timex.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef _SYS_TIMEX_H -#define _SYS_TIMEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_clockid_t - -#include - -#include - -struct ntptimeval { - struct timeval time; - long maxerror, esterror; -}; - -struct timex { - unsigned modes; - long offset, freq, maxerror, esterror; - int status; - long constant, precision, tolerance; - struct timeval time; - long tick, ppsfreq, jitter; - int shift; - long stabil, jitcnt, calcnt, errcnt, stbcnt; - int tai; - int __padding[11]; -}; - -#define ADJ_OFFSET 0x0001 -#define ADJ_FREQUENCY 0x0002 -#define ADJ_MAXERROR 0x0004 -#define ADJ_ESTERROR 0x0008 -#define ADJ_STATUS 0x0010 -#define ADJ_TIMECONST 0x0020 -#define ADJ_TAI 0x0080 -#define ADJ_SETOFFSET 0x0100 -#define ADJ_MICRO 0x1000 -#define ADJ_NANO 0x2000 -#define ADJ_TICK 0x4000 -#define ADJ_OFFSET_SINGLESHOT 0x8001 -#define ADJ_OFFSET_SS_READ 0xa001 - -#define MOD_OFFSET ADJ_OFFSET -#define MOD_FREQUENCY ADJ_FREQUENCY -#define MOD_MAXERROR ADJ_MAXERROR -#define MOD_ESTERROR ADJ_ESTERROR -#define MOD_STATUS ADJ_STATUS -#define MOD_TIMECONST ADJ_TIMECONST -#define MOD_CLKB ADJ_TICK -#define MOD_CLKA ADJ_OFFSET_SINGLESHOT -#define MOD_TAI ADJ_TAI -#define MOD_MICRO ADJ_MICRO -#define MOD_NANO ADJ_NANO - -#define STA_PLL 0x0001 -#define STA_PPSFREQ 0x0002 -#define STA_PPSTIME 0x0004 -#define STA_FLL 0x0008 - -#define STA_INS 0x0010 -#define STA_DEL 0x0020 -#define STA_UNSYNC 0x0040 -#define STA_FREQHOLD 0x0080 - -#define STA_PPSSIGNAL 0x0100 -#define STA_PPSJITTER 0x0200 -#define STA_PPSWANDER 0x0400 -#define STA_PPSERROR 0x0800 - -#define STA_CLOCKERR 0x1000 -#define STA_NANO 0x2000 -#define STA_MODE 0x4000 -#define STA_CLK 0x8000 - -#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ - STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) - -#define TIME_OK 0 -#define TIME_INS 1 -#define TIME_DEL 2 -#define TIME_OOP 3 -#define TIME_WAIT 4 -#define TIME_ERROR 5 -#define TIME_BAD TIME_ERROR - -#define MAXTC 6 - -int adjtimex(struct timex *); -int clock_adjtime(clockid_t, struct timex *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/ttydefaults.h b/usr/lib/libc/include/sys/ttydefaults.h deleted file mode 100644 index d251b715c..000000000 --- a/usr/lib/libc/include/sys/ttydefaults.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _SYS_TTYDEFAULTS_H -#define _SYS_TTYDEFAULTS_H - -#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY) -#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS) -#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) -#define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL) -#define TTYDEF_SPEED (B9600) -#define CTRL(x) (x&037) -#define CEOF CTRL('d') - -#ifdef _POSIX_VDISABLE -#define CEOL _POSIX_VDISABLE -#define CSTATUS _POSIX_VDISABLE -#else -#define CEOL '\0' -#define CSTATUS '\0' -#endif - -#define CERASE 0177 -#define CINTR CTRL('c') -#define CKILL CTRL('u') -#define CMIN 1 -#define CQUIT 034 -#define CSUSP CTRL('z') -#define CTIME 0 -#define CDSUSP CTRL('y') -#define CSTART CTRL('q') -#define CSTOP CTRL('s') -#define CLNEXT CTRL('v') -#define CDISCARD CTRL('o') -#define CWERASE CTRL('w') -#define CREPRINT CTRL('r') -#define CEOT CEOF -#define CBRK CEOL -#define CRPRNT CREPRINT -#define CFLUSH CDISCARD - -#endif diff --git a/usr/lib/libc/include/sys/types.h b/usr/lib/libc/include/sys/types.h deleted file mode 100644 index 75e489c57..000000000 --- a/usr/lib/libc/include/sys/types.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _SYS_TYPES_H -#define _SYS_TYPES_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_ino_t -#define __NEED_dev_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_time_t -#define __NEED_timer_t -#define __NEED_clockid_t - -#define __NEED_blkcnt_t -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t - -#define __NEED_id_t -#define __NEED_key_t -#define __NEED_clock_t -#define __NEED_suseconds_t -#define __NEED_blksize_t - -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_pthread_mutexattr_t -#define __NEED_pthread_condattr_t -#define __NEED_pthread_rwlockattr_t -#define __NEED_pthread_barrierattr_t -#define __NEED_pthread_mutex_t -#define __NEED_pthread_cond_t -#define __NEED_pthread_rwlock_t -#define __NEED_pthread_barrier_t -#define __NEED_pthread_spinlock_t -#define __NEED_pthread_key_t -#define __NEED_pthread_once_t -#define __NEED_useconds_t - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_int8_t -#define __NEED_int16_t -#define __NEED_int32_t -#define __NEED_int64_t -#define __NEED_u_int64_t -#define __NEED_register_t -#endif - -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -typedef unsigned char u_int8_t; -typedef unsigned short u_int16_t; -typedef unsigned u_int32_t; -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 long long quad_t; -typedef unsigned long long u_quad_t; -#include -#include -#include -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define blkcnt64_t blkcnt_t -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#define ino64_t ino_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/ucontext.h b/usr/lib/libc/include/sys/ucontext.h deleted file mode 100644 index 5fdbd63db..000000000 --- a/usr/lib/libc/include/sys/ucontext.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/usr/lib/libc/include/sys/uio.h b/usr/lib/libc/include/sys/uio.h deleted file mode 100644 index 00f73a2f0..000000000 --- a/usr/lib/libc/include/sys/uio.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _SYS_UIO_H -#define _SYS_UIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_struct_iovec - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_off_t -#endif - -#ifdef _GNU_SOURCE -#define __NEED_pid_t -#endif - -#include - -#define UIO_MAXIOV 1024 - -ssize_t readv (int, const struct iovec *, int); -ssize_t writev (int, const struct iovec *, int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -ssize_t preadv (int, const struct iovec *, int, off_t); -ssize_t pwritev (int, const struct iovec *, int, off_t); -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define preadv64 preadv -#define pwritev64 pwritev -#define off64_t off_t -#endif -#endif - -#ifdef _GNU_SOURCE -ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); -ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/un.h b/usr/lib/libc/include/sys/un.h deleted file mode 100644 index 1a3193ad2..000000000 --- a/usr/lib/libc/include/sys/un.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _SYS_UN_H -#define _SYS_UN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_sa_family_t -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_size_t -#endif - -#include - -struct sockaddr_un { - sa_family_t sun_family; - char sun_path[108]; -}; - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -size_t strlen(const char *); -#define SUN_LEN(s) (2+strlen((s)->sun_path)) -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/user.h b/usr/lib/libc/include/sys/user.h deleted file mode 100644 index 96a034009..000000000 --- a/usr/lib/libc/include/sys/user.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _SYS_USER_H -#define _SYS_USER_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#include - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/utsname.h b/usr/lib/libc/include/sys/utsname.h deleted file mode 100644 index 2c80fb5a2..000000000 --- a/usr/lib/libc/include/sys/utsname.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _SYS_UTSNAME_H -#define _SYS_UTSNAME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -struct utsname { - char sysname[65]; - char nodename[65]; - char release[65]; - char version[65]; - char machine[65]; -#ifdef _GNU_SOURCE - char domainname[65]; -#else - char __domainname[65]; -#endif -}; - -int uname (struct utsname *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/sys/vfs.h b/usr/lib/libc/include/sys/vfs.h deleted file mode 100644 index a899db276..000000000 --- a/usr/lib/libc/include/sys/vfs.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/usr/lib/libc/include/sys/vt.h b/usr/lib/libc/include/sys/vt.h deleted file mode 100644 index 834abfbc8..000000000 --- a/usr/lib/libc/include/sys/vt.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/usr/lib/libc/include/sys/wait.h b/usr/lib/libc/include/sys/wait.h deleted file mode 100644 index 0a93364f1..000000000 --- a/usr/lib/libc/include/sys/wait.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _SYS_WAIT_H -#define _SYS_WAIT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_pid_t -#define __NEED_id_t - -/* so3 */ -typedef uint32_t id_t; - -#include - -typedef enum { - P_ALL = 0, - P_PID = 1, - P_PGID = 2 -} idtype_t; - -pid_t wait (int *); -pid_t waitpid (pid_t, int *, int ); - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#include -int waitid (idtype_t, id_t, siginfo_t *, int); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#include -pid_t wait3 (int *, int, struct rusage *); -pid_t wait4 (pid_t, int *, int, struct rusage *); -#endif - -#define WNOHANG 1 -#define WUNTRACED 2 - -#define WSTOPPED 2 -#define WEXITED 4 -#define WCONTINUED 8 -#define WNOWAIT 0x1000000 - -#define __WNOTHREAD 0x20000000 -#define __WALL 0x40000000 -#define __WCLONE 0x80000000 - -#define WEXITSTATUS(s) (((s) & 0xff00) >> 8) -#define WTERMSIG(s) ((s) & 0x7f) -#define WSTOPSIG(s) WEXITSTATUS(s) -#define WCOREDUMP(s) ((s) & 0x80) -#define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) -#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) -#define WIFCONTINUED(s) ((s) == 0xffff) - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/sys/xattr.h b/usr/lib/libc/include/sys/xattr.h deleted file mode 100644 index 6479fcc62..000000000 --- a/usr/lib/libc/include/sys/xattr.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _SYS_XATTR_H -#define _SYS_XATTR_H -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_ssize_t -#define __NEED_size_t -#include - -#define XATTR_CREATE 1 -#define XATTR_REPLACE 2 - -ssize_t getxattr(const char *, const char *, void *, size_t); -ssize_t lgetxattr(const char *, const char *, void *, size_t); -ssize_t fgetxattr(int, const char *, void *, size_t); -ssize_t listxattr(const char *, char *, size_t); -ssize_t llistxattr(const char *, char *, size_t); -ssize_t flistxattr(int, char *, size_t); -int setxattr(const char *, const char *, const void *, size_t, int); -int lsetxattr(const char *, const char *, const void *, size_t, int); -int fsetxattr(int, const char *, const void *, size_t, int); -int removexattr(const char *, const char *); -int lremovexattr(const char *, const char *); -int fremovexattr(int, const char *); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/usr/lib/libc/include/syscall.h b/usr/lib/libc/include/syscall.h deleted file mode 100644 index 2426d2bd4..000000000 --- a/usr/lib/libc/include/syscall.h +++ /dev/null @@ -1,589 +0,0 @@ -/* - * Copyright (C) 2014-2017 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef SYSCALL_H -#define SYSCALL_H - -#ifndef __ASSEMBLY__ -#include -#include -#endif - -/* System call codes, passed in r0 to tell the kernel which system call to do. */ - -#define syscallHalt 0 -#define syscallExit 1 -#define syscallExecve 2 -#define syscallWaitpid 3 -#define syscallRead 4 -#define syscallWrite 5 -#define syscallPause 6 -#define syscallFork 7 -#define syscallPtrace 8 -#define syscallReaddir 9 -#define syscallChdir 10 -#define syscallGetcwd 11 -#define syscallCreate 12 -#define syscallUnlink 13 -#define syscallOpen 14 -#define syscallClose 15 -#define syscallThreadCreate 16 -#define syscallThreadJoin 17 -#define syscallThreadExit 18 -#define syscallPipe 19 -#define syscallIoctl 20 -#define syscallFcntl 21 -#define syscallDup 22 -#define syscallDup2 23 -#define syscallSchedSetParam 25 -#define syscallSocket 26 -#define syscallBind 27 -#define syscallListen 28 -#define syscallAccept 29 -#define syscallConnect 30 -#define syscallRecv 31 -#define syscallSend 32 -#define syscallSendTo 33 -#define syscallStat 34 -#define syscallMmap 35 -#define syscallEndProc 36 - -/* getPID syscall */ -#define syscallGetpid 37 - -/* time management */ -#define syscallGetTimeOfDay 38 -#define syscallSetTimeOfDay 39 -#define syscallClockGetTime 40 - -#define syscallThreadYield 43 - -#define syscallSbrk 45 - -#define syscallSigaction 46 -#define syscallKill 47 -#define syscallSigreturn 48 - -#define syscallLseek 50 - -#define syscallMutexLock 60 -#define syscallMutexUnlock 61 - -#define syscallPs 63 - -#define syscallNanosleep 70 - -#define syscallSysinfo 99 - -#define syscallSetsockopt 110 -#define syscallRecvfrom 111 - - -#define SYSINFO_DUMP_HEAP 0 -#define SYSINFO_DUMP_SCHED 1 -#define SYSINFO_TEST_MALLOC 2 -#define SYSINFO_PRINTK 3 - -#ifndef __ASSEMBLY__ - -#include - -#include -#include -#include -#include -#include - -extern int errno; - -/** - * Convert a syscall return value into function return value and update errno accordingly. - */ -long __syscall_ret(unsigned long); - -/* The system call interface. These are the operations the SO3 kernel needs to - * support, to be able to run user programs. - * - * Each of these is invoked by a user program by simply calling the - * procedure; an assembly language stub stores the syscall code (see above) into $r0 - * and executes a syscall instruction. The kernel exception handler is then invoked. - */ - -void sys_halt(); - -/* PROCESS MANAGEMENT SYSCALLS: exit(), exec(), fork(), waitpid() */ - -/** - * Terminate the current process immediately. Any open file descriptors belonging to the - * process are closed. Any children of the process no longer have a parent process. - * - * status is returned to the parent process as this process's exit status and can be - * collected using the join syscall. A process exiting normally should set status to 0. - * - * exit() never returns. - */ -void sys_exit(int status) __attribute__((noreturn)); - -/** - * Execute the program stored in the specified file, with the specified arguments. - * The current process image is replaced by the program found in the file. - * - * file is a null-terminated string that specifies the name of the file containing the - * executable. Note that this string must include the ".elf" extension. - * - * argc specifies the number of arguments to pass to the child process. This number must - * be non-negative. - * - * argv is an array of pointers to null-terminated strings that represent the arguments - * to pass to the child process. argv[0] points to the first argument, and argv[argc-1] - * points to the last argument. - * - * exec() returns the child process's process ID, which can be passed to join(). On - * error, returns -1. - */ - -int sys_execve(const char *path, char *const argv[], char *const envp[]); - -/** - * This system call are used to wait for state changes in a child of the calling - * process, and obtain information about the child whose state has changed. - * A state change is considered to be: the child terminated; the child was stopped. - * - * By default, waitpid() waits only for terminated children, but this behavior - * is modifiable via the options argument, as described above. - * - * If status is not NULL, waitpid() store status information in the int to which it - * points. This integer can be inspected with the macros above (which take the - * integer itself as an argument, not a pointer to it, as is done in waitpid()!) - * - * on success, returns the process ID of the child whose state has changed; - * if WNOHANG was specified and one or more child(ren) specified by pid exist, - * but have not yet changed state, then 0 is returned. On error, -1 is returned. - */ -pid_t sys_waitpid(pid_t pid, int *status, int options); - -/* FILE MANAGEMENT SYSCALLS: creat, open, read, write, close, unlink - * - * A file descriptor is a small, non-negative integer that refers to a file on disk - * or to a stream (such as console input, console output, and network connections). - * A file descriptor can be passed to read() and write() to read/write the corresponding - * file/stream. A file descriptor can also be passed to close() to release the file - * descriptor and any associated resources. - */ - -/** - * Suspend the execution during millisecond(s). - */ -void sys_pause(int delay); - -/** - * Suspend the execution during microseconds. - * is not used at the moment. - */ -int sys_nanosleep(const struct timespec *req, struct timespec *rem); - -/** - * Fork a new process according to the standard UNIX fork system call. - */ -int sys_fork(void); - -/** - * creat() is equivalent to open() with flags equal to O_CREAT|O_WRONLY|O_TRUNC - */ -int sys_creat(const char *pathname, mode_t mode); - -/** - * Delete a file from the file system. If no processes have the file open, the file is - * deleted immediately and the space it was using is made available for reuse. - * - * If any processes still have the file open, the file will remain in existence until the - * last file descriptor referring to it is closed. However, creat() and open() will not - * be able to return new file descriptors for the file until it is deleted. - * - * Returns 0 on success, or -1 if an error occurred. - */ -int sys_unlink(char *name); - -/** - * open - open and possibly create a file or device - * - * Given a pathname for a file, open() returns a file descriptor, a small, nonnegative - * integer for use in subsequent system calls (read(2), write(2), seek(2), etc.). - * The file descriptor returned by a successful call will be the lowest-numbered file - * descriptor not currently open for the process. - * - * open() return the new file descriptor, or -1 if an error occurred - * (in which case, errno is set appropriately). - */ -int sys_open(const char *pathname, int flags, int mode); - -int sys_write(int fd, const void *buf, size_t count); -int sys_read(int fd, void *buf, size_t count); - -int sys_readdir(int fd, char *buf, int len); - -/** - * Close a file descriptor, so that it no longer refers to any file or stream and may be - * reused. - * - * If the file descriptor refers to a file, all data written to it by write() will be - * flushed to disk before close() returns. - * If the file descriptor refers to a stream, all data written to it by write() will - * eventually be flushed (unless the stream is terminated remotely), but not - * necessarily before close() returns. - * - * The resources associated with the file descriptor are released. If the descriptor is - * the last reference to a disk file which has been removed using unlink, the file is - * deleted (this detail is handled by the file system implementation). - * - * Returns 0 on success, or -1 if an error occurred. - */ -int sys_close(int fd); - -/** - * The ioctl() function manipulates the underlying device parameters of - * special files. In particular, many operating characteristics of character - * special files (e.g., terminals) may be controlled with ioctl() - * requests. The argument fd must be an open file descriptor. - * - * The second argument is a device-dependent request code. The third - * argument is an untyped pointer to memory. - * - * Returns 0 on success or -1 if an error occurred, and errno is set. - */ -int sys_ioctl(int fd, int cmd, void *val); - -/** - * fcntl() performs one of the operations described below on the open file descriptor fd. The operation is determined by cmd. - * fcntl() can take an optional third argument. Whether or not this argument is required is determined by cmd. - * The required argument type is indicated in parentheses after each cmd name (in most cases, the - * required type is int, and we identify the argument using the name arg), or void is specified if the argument is not required. - * - * Certain of the operations below are supported only since a particular Linux kernel version. - * The preferred method of checking whether the host kernel supports a particular operation is to invoke fcntl() - * with the desired cmd value and then test whether the call failed with EINVAL, indicating that the kernel does not recognize this value. - * - * See man page for returned value. - */ -int sys_fcntl(int fd, int cmd, void *val); - -/* - * lseek() repositions the file offset of the open file description associated with the file descriptor fd to the argument offset - * according to the directive whence as follows: - * - * SEEK_SET - * The file offset is set to offset bytes. - * - * SEEK_CUR - * The file offset is set to its current location plus offset bytes. - * - * SEEK_END - * The file offset is set to the size of the file plus offset bytes. - * - * lseek() allows the file offset to be set beyond the end of the file (but this does not change the size of the file). - * If data is later written at this point, subsequent reads of the data in the gap (a "hole") return null bytes ('\0') until data is actually written into the gap. - * - */ - -off_t sys_lseek(int fd, off_t offset, int whence); - -/** - * This IOCTL command returns the number of column and lines of the given - * fd. the result is returned in the following form: - * int val[0] = #lines - * int val[1] = #columns - */ -#define IOR_CONSOLE_SIZE 1 - -/** - * This IOCTL command returns the machine link address - * int *val = pointer to machine link address - */ -#define IOR_NETWORK_ADDRESS 2 - -/** - * Clone a thread. - * - * Returns the thread ID on success to the parent and 0 to the child, or - * -1 on error and set errno. - - * entryState=true: first invocation by the parent (routine and args has to be passed) - * entryState=false: second invocation by the child (which retrieved routine and args from the kernel) - */ -int sys_thread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); - -/** - * The thread_join() function waits for the thread specified by thread to - * terminate. If that thread has already terminated, then thread_join() - * returns immediately. The thread specified by thread must be joinable. - * - * If retval is not NULL, then thread_join() copies the exit status of - * the target thread (i.e., the value that the target thread supplied to - * thread_join(3)) into the location pointed to by *retval. - * - * On success, thread_join() returns 0; on error, it returns an error - * number. - */ -int sys_thread_join(pthread_t thread, void **value_ptr); - -/** - * The calling thread is terminated. This function does not return. - */ -void sys_thread_exit(int *exit_status); - -/* - * Yield to another thread. - */ -int sys_thread_yield(void); - -/** - * Open a pipe and returns the two file descriptors in the array fd. - * - * Returns 0 on success, or -1 on error and set errno. - */ -int sys_pipe(int fd[]); - -/** - * Duplicate an open file descriptor. - * - * Example:  - * dup2(1, 2); // Redirects messages from stderr to stdout - * - * Returns -1 on error, or fildes2 on success. - */ -int sys_dup(int oldfd); - - -/** - * Duplicate an open file descriptor. - * - * Example:  - * dup2(1, 2); // Redirects messages from stderr to stdout - * - * Returns -1 on error, or fildes2 on success. - */ -int sys_dup2(int newfd, int oldfd); - -/** - * Change priority of given thread - * - * Returns 0 on success, or -1 on error and set errno. - */ -int sys_sched_setparam(int threadId, int priority); - -/** - * Creates an endpoint for network communication (socket). - * The domain argument specifies a communication domain. Starts with AF_ - * The socket has the indicated type, which specifies the communication semantics. - * The protocol specifies a particular protocol to be used with the socket. - * - * Return a file descriptor on success, or -1 and set errno. - */ -int sys_socket(int domain, int type, int protocol); - -/** - * Assigns a port to a specific socket - * - * Returns 0 on success, or -1 on error and set errno. - */ -int sys_bind(int socket, const struct sockaddr *addr, int port); - -/** - * Marks the socket as passive and ready to accept incoming - * connection requests using accept(). the argument backlog represent - * the maximum number of pending requests. - * - * Returns 0 on success, or -1 on error and set errno. - */ -int sys_listen(int socket, int backlog); - -/** - * Attempt to accept a single connection on the specified local port and return - * a new file descriptor referring to the connection. Block until new requests. - * cli_addr and cli_port are fill up with remote client informations. - * - * Returns a new file descriptor on success, or -1 on error and set errno. - */ -int sys_accept(int socket, struct sockaddr *cli_addr, socklen_t *cli_port); - -/** - * Attempt to initiate a new connection (client side) to the specified port - * on the specific remote host. Block until the remote host response. - * - * Example : connect(s, 3, 1111); - * - * Returns 0 on success, or -1 on error and set errno. - */ -int sys_connect(int socket, const struct sockaddr *si, socklen_t addrlen); - -/** - * This system call is used to receive messages from a socket. If no messages are - * available on the socket, the receive calls wait for a message to arrive. - * - * Returns the number of byte read. On error, -1 is returned, this can append if - * a network stream has been terminated by the remote host and no more data is available. - * See errno variable to have more information on the error. - */ -int sys_recv(int socket_fd, void *buffer, int count, int flags); - -/** - * This system call is used to receive messages from a socket, and may be - * used to receive data on a socket whether or not it is connection-oriented. - * If no messages are available on the socket, the receive calls wait for a - * message to arrive. - * - * Returns the number of byte read. On error, -1 is returned, this can append if - * a network stream has been terminated by the remote host and no more data is available. - * See errno variable to have more information on the error. - */ -int sys_recvfrom(int sockfd, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); - -/** - * This system call is used to transmit a messages to another socket. - * This call may be used only when the socket is in a connected state. - * - * Returns the number of byte written. On error, -1 is returned, - * and errno is set appropriately. - */ -int sys_send(int socket_fd, void *buffer, int count, int flags); - -/** - * This system call is used to transmit a messages to another socket. - * This call does not need any connected state. - * - * Returns the number of byte written. On error, -1 is returned, - * and errno is set appropriately. - */ -int sys_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen); - -/* - * This system call returns information about a file in the buffer - * pointed by . - */ -int sys_stat(const char *pathname, struct stat *statbuf); - - -int sys_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen); - - -/** - * This system call is used to map a file (or a portion of it) to a memory buffer - * in virtual memory. You have to open a file prior this call. - * - * start: start of the virtual memory somewhere in the heap area of the process - * length: represents how many bytes you want to map - * prot: is the mode of accessing mapped memory (READ, WRITE, READ/WRITE) - * fd: is the file descriptor of the opened file - * offset: is where to start mapping in the file - */ -int sys_mmap(uint32_t start, size_t length, int prot, int fd, off_t offset); - -/** - * The ptrace() system call provides a means by which one process (the "tracer") - * may observe and control the execution of another process (the "tracee"), and - * examine and change the tracee's memory and registers. It is primarily used - * to implement breakpoint debugging and system call tracing. - * - * Return 0 on success, except for PTRACE_PEEK* requests which return the requested data. - * On error -1 is returned and errno is set appropriately. - */ -int sys_ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); - -/** - * The ioctl() function manipulates the underlying device parameters of - * special files. In particular, many operating characteristics of character - * special files (e.g., terminals) may be controlled with ioctl() - * requests. The argument fd must be an open file descriptor. - * - * The second argument is a device-dependent request code. The third - * argument is an untyped pointer to memory. - * - * Returns 0 on success or -1 if an error occurred, and errno is set. - */ -int sys_ioctl(int fd, int cmd, void *val); - - -/** - * getPID syscall - */ -int sys_getpid(); - -/** -* Time management - time zone is not supported yet. -*/ -int sys_gettimeofday(struct timespec *ts, void *tz); -int sys_settimeofday(struct timespec *ts, void *tz); - -int sys_clock_gettime(clockid_t clk, struct timespec *ts); - -/* - * sbrk syscall - * - * Grows heap - * - * increment: number of bytes to add to heap. If increment is not a multiple of PAGE_SIZE, - * it is internally incremented to the next whole page size. (1025 -> 2048 for example) - * return: Base address of newly allocated space. If there is not enough space left in - * the heap, return (void *) -1 and sets ERRNO to ENOMEM. If increment equals 0, return current heap top. - */ - -int sys_sbrk(int increment); - -/* - * First attempt of mutex implementation in the user space. Mainly used, at the moment, - * for debugging kernel mutexes. - */ - -void sys_mutex_lock(int lock_idx); -void sys_mutex_unlock(int lock_idx); - - -/* - * sigaction syscall. - * Used to change the action taken by a process on receipt of a specific signal. - * - * signum: Signal number to handle - * action: Handler for the signal. - * old_action: If non-NULL, the previous action is saved in old_action - */ -int sys_sigaction(int signum, void *sa, void *old); - -/* - * kill syscall. - * Used to send a signal to a process defined by its PID - * - * pid: Process PID. - * sig: Signal to send. - */ -int sys_kill(pid_t pid, int sig); - -/* - * Syscall used to restore the registers after a signal handler was called - * - */ -void sys_sigreturn(void); - -/* - * Get system information - * - @type = 0 : dump heap memory - */ -void sys_info(int type, int val); - -#endif /* __ASSEMBLY__ */ - -#endif /* SYSCALL_H */ diff --git a/usr/lib/libc/include/time.h b/usr/lib/libc/include/time.h deleted file mode 100644 index 672b3fc3e..000000000 --- a/usr/lib/libc/include/time.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef _TIME_H -#define _TIME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __cplusplus -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_clock_t -#define __NEED_struct_timespec - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_clockid_t -#define __NEED_timer_t -#define __NEED_pid_t -#define __NEED_locale_t -#endif - -#include - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define __tm_gmtoff tm_gmtoff -#define __tm_zone tm_zone -#endif - -struct tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - long __tm_gmtoff; - const char *__tm_zone; -}; - -clock_t clock (void); -time_t time (time_t *); -double difftime (time_t, time_t); -time_t mktime (struct tm *); -size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); -struct tm *gmtime (const time_t *); -struct tm *localtime (const time_t *); -char *asctime (const struct tm *); -char *ctime (const time_t *); -int timespec_get(struct timespec *, int); - -#define CLOCKS_PER_SEC 1000000L - -#define TIME_UTC 1 - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); - -struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); -struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); -char *asctime_r (const struct tm *__restrict, char *__restrict); -char *ctime_r (const time_t *, char *); - -void tzset (void); - -struct itimerspec { - struct timespec it_interval; - struct timespec it_value; -}; - -#define CLOCK_REALTIME 0 -#define CLOCK_MONOTONIC 1 -#define CLOCK_PROCESS_CPUTIME_ID 2 -#define CLOCK_THREAD_CPUTIME_ID 3 -#define CLOCK_MONOTONIC_RAW 4 -#define CLOCK_REALTIME_COARSE 5 -#define CLOCK_MONOTONIC_COARSE 6 -#define CLOCK_BOOTTIME 7 -#define CLOCK_REALTIME_ALARM 8 -#define CLOCK_BOOTTIME_ALARM 9 -#define CLOCK_SGI_CYCLE 10 -#define CLOCK_TAI 11 - -#define TIMER_ABSTIME 1 - -int nanosleep (const struct timespec *, struct timespec *); -int clock_getres (clockid_t, struct timespec *); -int clock_gettime (clockid_t, struct timespec *); -int clock_settime (clockid_t, const struct timespec *); -int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); -int clock_getcpuclockid (pid_t, clockid_t *); - -struct sigevent; -int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); -int timer_delete (timer_t); -int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); -int timer_gettime (timer_t, struct itimerspec *); -int timer_getoverrun (timer_t); - -extern char *tzname[2]; - -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); -extern int daylight; -extern long timezone; -extern int getdate_err; -struct tm *getdate (const char *); -#endif - - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int stime(const time_t *); -time_t timegm(struct tm *); -#endif - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/usr/lib/libc/include/types.h b/usr/lib/libc/include/types.h deleted file mode 100644 index 66d3576e2..000000000 --- a/usr/lib/libc/include/types.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2014-2021 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef TYPES_H_ -#define TYPES_H_ - -#include - -typedef unsigned int mode_t; -typedef int pid_t; - -typedef uint32_t in_addr_t; - -#endif /* TYPES_H_ */ diff --git a/usr/lib/libc/include/unistd.h b/usr/lib/libc/include/unistd.h deleted file mode 100644 index 78020d5de..000000000 --- a/usr/lib/libc/include/unistd.h +++ /dev/null @@ -1,478 +0,0 @@ -#ifndef _UNISTD_H -#define _UNISTD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#ifdef __cplusplus -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_intptr_t -#define __NEED_useconds_t - -#include - -ssize_t read(int, void *, size_t); -ssize_t write(int, const void *, size_t); -int pipe(int [2]); -pid_t fork(void); - -pid_t getpid(void); -int dup2(int, int); -int dup(int); - -int execve(const char *path, char *const argv[], char *const envp[]); -int execv(const char *, char *const []); -int execle(const char *, const char *, ...); -int execl(const char *, const char *, ...); -int execvp(const char *, char *const []); -int execlp(const char *, const char *, ...); -int close(int); - -void *sbrk(intptr_t); -extern char **__environ; - -unsigned sleep(unsigned); -int usleep(unsigned); - -#if 0 -int pipe(int [2]); -int pipe2(int [2], int); -int posix_close(int, int); -int dup3(int, int, int); -off_t lseek(int, off_t, int); -int fsync(int); -int fdatasync(int); - -ssize_t read(int, void *, size_t); -ssize_t write(int, const void *, size_t); -ssize_t pread(int, void *, size_t, off_t); -ssize_t pwrite(int, const void *, size_t, off_t); - -int chown(const char *, uid_t, gid_t); -int fchown(int, uid_t, gid_t); -int lchown(const char *, uid_t, gid_t); -int fchownat(int, const char *, uid_t, gid_t, int); - -int link(const char *, const char *); -int linkat(int, const char *, int, const char *, int); -int symlink(const char *, const char *); -int symlinkat(const char *, int, const char *); -ssize_t readlink(const char *__restrict, char *__restrict, size_t); -ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); -int unlink(const char *); -int unlinkat(int, const char *, int); -int rmdir(const char *); -int truncate(const char *, off_t); -int ftruncate(int, off_t); - -#define F_OK 0 -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 - -int access(const char *, int); -int faccessat(int, const char *, int, int); - -int chdir(const char *); -int fchdir(int); -char *getcwd(char *, size_t); - -unsigned alarm(unsigned); -int pause(void); - -pid_t fork(void); -int fexecve(int, char *const [], char *const []); -_Noreturn void _exit(int); - -pid_t getppid(void); -pid_t getpgrp(void); -pid_t getpgid(pid_t); -int setpgid(pid_t, pid_t); -pid_t setsid(void); -pid_t getsid(pid_t); -char *ttyname(int); -int ttyname_r(int, char *, size_t); -int isatty(int); -pid_t tcgetpgrp(int); -int tcsetpgrp(int, pid_t); - -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); -int getgroups(int, gid_t []); -int setuid(uid_t); -int seteuid(uid_t); -int setgid(gid_t); -int setegid(gid_t); - -char *getlogin(void); -int getlogin_r(char *, size_t); -int gethostname(char *, size_t); -char *ctermid(char *); - -int getopt(int, char * const [], const char *); -extern char *optarg; -extern int optind, opterr, optopt; - -long pathconf(const char *, int); -long fpathconf(int, int); -long sysconf(int); -size_t confstr(int, char *, size_t); - -#define F_ULOCK 0 -#define F_LOCK 1 -#define F_TLOCK 2 -#define F_TEST 3 - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int setreuid(uid_t, uid_t); -int setregid(gid_t, gid_t); -int lockf(int, int, off_t); -long gethostid(void); -int nice(int); -void sync(void); -pid_t setpgrp(void); -char *crypt(const char *, const char *); -void encrypt(char *, int); -void swab(const void *__restrict, void *__restrict, ssize_t); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) -int usleep(unsigned); -unsigned ualarm(unsigned, unsigned); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define L_SET 0 -#define L_INCR 1 -#define L_XTND 2 -int brk(void *); -pid_t vfork(void); -int vhangup(void); -int chroot(const char *); -int getpagesize(void); -int getdtablesize(void); -int sethostname(const char *, size_t); -int getdomainname(char *, size_t); -int setdomainname(const char *, size_t); -int setgroups(size_t, const gid_t *); -char *getpass(const char *); -int daemon(int, int); -void setusershell(void); -void endusershell(void); -char *getusershell(void); -int acct(const char *); -long syscall(long, ...); -int execvpe(const char *, char *const [], char *const []); -int issetugid(void); -#endif - -#ifdef _GNU_SOURCE -extern char **environ; -int setresuid(uid_t, uid_t, uid_t); -int setresgid(gid_t, gid_t, gid_t); -int getresuid(uid_t *, uid_t *, uid_t *); -int getresgid(gid_t *, gid_t *, gid_t *); -char *get_current_dir_name(void); -int syncfs(int); -int euidaccess(const char *, int); -int eaccess(const char *, int); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define lseek64 lseek -#define pread64 pread -#define pwrite64 pwrite -#define truncate64 truncate -#define ftruncate64 ftruncate -#define lockf64 lockf -#define off64_t off_t -#endif - -#define POSIX_CLOSE_RESTART 0 - -#define _XOPEN_VERSION 700 -#define _XOPEN_UNIX 1 -#define _XOPEN_ENH_I18N 1 - -#define _POSIX_VERSION 200809L -#define _POSIX2_VERSION _POSIX_VERSION - -#define _POSIX_ADVISORY_INFO _POSIX_VERSION -#define _POSIX_CHOWN_RESTRICTED 1 -#define _POSIX_IPV6 _POSIX_VERSION -#define _POSIX_JOB_CONTROL 1 -#define _POSIX_MAPPED_FILES _POSIX_VERSION -#define _POSIX_MEMLOCK _POSIX_VERSION -#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION -#define _POSIX_MEMORY_PROTECTION _POSIX_VERSION -#define _POSIX_MESSAGE_PASSING _POSIX_VERSION -#define _POSIX_FSYNC _POSIX_VERSION -#define _POSIX_NO_TRUNC 1 -#define _POSIX_RAW_SOCKETS _POSIX_VERSION -#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION -#define _POSIX_REGEXP 1 -#define _POSIX_SAVED_IDS 1 -#define _POSIX_SHELL 1 -#define _POSIX_SPAWN _POSIX_VERSION -#define _POSIX_VDISABLE 0 - -#define _POSIX_THREADS _POSIX_VERSION -#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION -#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION -#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION -#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION -#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION -#define _POSIX_THREAD_CPUTIME _POSIX_VERSION -#define _POSIX_TIMERS _POSIX_VERSION -#define _POSIX_TIMEOUTS _POSIX_VERSION -#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION -#define _POSIX_CPUTIME _POSIX_VERSION -#define _POSIX_CLOCK_SELECTION _POSIX_VERSION -#define _POSIX_BARRIERS _POSIX_VERSION -#define _POSIX_SPIN_LOCKS _POSIX_VERSION -#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION -#define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION -#define _POSIX_SEMAPHORES _POSIX_VERSION -#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION - -#define _POSIX2_C_BIND _POSIX_VERSION - -#include - -#define _PC_LINK_MAX 0 -#define _PC_MAX_CANON 1 -#define _PC_MAX_INPUT 2 -#define _PC_NAME_MAX 3 -#define _PC_PATH_MAX 4 -#define _PC_PIPE_BUF 5 -#define _PC_CHOWN_RESTRICTED 6 -#define _PC_NO_TRUNC 7 -#define _PC_VDISABLE 8 -#define _PC_SYNC_IO 9 -#define _PC_ASYNC_IO 10 -#define _PC_PRIO_IO 11 -#define _PC_SOCK_MAXBUF 12 -#define _PC_FILESIZEBITS 13 -#define _PC_REC_INCR_XFER_SIZE 14 -#define _PC_REC_MAX_XFER_SIZE 15 -#define _PC_REC_MIN_XFER_SIZE 16 -#define _PC_REC_XFER_ALIGN 17 -#define _PC_ALLOC_SIZE_MIN 18 -#define _PC_SYMLINK_MAX 19 -#define _PC_2_SYMLINKS 20 - -#define _SC_ARG_MAX 0 -#define _SC_CHILD_MAX 1 -#define _SC_CLK_TCK 2 -#define _SC_NGROUPS_MAX 3 -#define _SC_OPEN_MAX 4 -#define _SC_STREAM_MAX 5 -#define _SC_TZNAME_MAX 6 -#define _SC_JOB_CONTROL 7 -#define _SC_SAVED_IDS 8 -#define _SC_REALTIME_SIGNALS 9 -#define _SC_PRIORITY_SCHEDULING 10 -#define _SC_TIMERS 11 -#define _SC_ASYNCHRONOUS_IO 12 -#define _SC_PRIORITIZED_IO 13 -#define _SC_SYNCHRONIZED_IO 14 -#define _SC_FSYNC 15 -#define _SC_MAPPED_FILES 16 -#define _SC_MEMLOCK 17 -#define _SC_MEMLOCK_RANGE 18 -#define _SC_MEMORY_PROTECTION 19 -#define _SC_MESSAGE_PASSING 20 -#define _SC_SEMAPHORES 21 -#define _SC_SHARED_MEMORY_OBJECTS 22 -#define _SC_AIO_LISTIO_MAX 23 -#define _SC_AIO_MAX 24 -#define _SC_AIO_PRIO_DELTA_MAX 25 -#define _SC_DELAYTIMER_MAX 26 -#define _SC_MQ_OPEN_MAX 27 -#define _SC_MQ_PRIO_MAX 28 -#define _SC_VERSION 29 -#define _SC_PAGE_SIZE 30 -#define _SC_PAGESIZE 30 /* !! */ -#define _SC_RTSIG_MAX 31 -#define _SC_SEM_NSEMS_MAX 32 -#define _SC_SEM_VALUE_MAX 33 -#define _SC_SIGQUEUE_MAX 34 -#define _SC_TIMER_MAX 35 -#define _SC_BC_BASE_MAX 36 -#define _SC_BC_DIM_MAX 37 -#define _SC_BC_SCALE_MAX 38 -#define _SC_BC_STRING_MAX 39 -#define _SC_COLL_WEIGHTS_MAX 40 -#define _SC_EXPR_NEST_MAX 42 -#define _SC_LINE_MAX 43 -#define _SC_RE_DUP_MAX 44 -#define _SC_2_VERSION 46 -#define _SC_2_C_BIND 47 -#define _SC_2_C_DEV 48 -#define _SC_2_FORT_DEV 49 -#define _SC_2_FORT_RUN 50 -#define _SC_2_SW_DEV 51 -#define _SC_2_LOCALEDEF 52 -#define _SC_UIO_MAXIOV 60 /* !! */ -#define _SC_IOV_MAX 60 -#define _SC_THREADS 67 -#define _SC_THREAD_SAFE_FUNCTIONS 68 -#define _SC_GETGR_R_SIZE_MAX 69 -#define _SC_GETPW_R_SIZE_MAX 70 -#define _SC_LOGIN_NAME_MAX 71 -#define _SC_TTY_NAME_MAX 72 -#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73 -#define _SC_THREAD_KEYS_MAX 74 -#define _SC_THREAD_STACK_MIN 75 -#define _SC_THREAD_THREADS_MAX 76 -#define _SC_THREAD_ATTR_STACKADDR 77 -#define _SC_THREAD_ATTR_STACKSIZE 78 -#define _SC_THREAD_PRIORITY_SCHEDULING 79 -#define _SC_THREAD_PRIO_INHERIT 80 -#define _SC_THREAD_PRIO_PROTECT 81 -#define _SC_THREAD_PROCESS_SHARED 82 -#define _SC_NPROCESSORS_CONF 83 -#define _SC_NPROCESSORS_ONLN 84 -#define _SC_PHYS_PAGES 85 -#define _SC_AVPHYS_PAGES 86 -#define _SC_ATEXIT_MAX 87 -#define _SC_PASS_MAX 88 -#define _SC_XOPEN_VERSION 89 -#define _SC_XOPEN_XCU_VERSION 90 -#define _SC_XOPEN_UNIX 91 -#define _SC_XOPEN_CRYPT 92 -#define _SC_XOPEN_ENH_I18N 93 -#define _SC_XOPEN_SHM 94 -#define _SC_2_CHAR_TERM 95 -#define _SC_2_UPE 97 -#define _SC_XOPEN_XPG2 98 -#define _SC_XOPEN_XPG3 99 -#define _SC_XOPEN_XPG4 100 -#define _SC_NZERO 109 -#define _SC_XBS5_ILP32_OFF32 125 -#define _SC_XBS5_ILP32_OFFBIG 126 -#define _SC_XBS5_LP64_OFF64 127 -#define _SC_XBS5_LPBIG_OFFBIG 128 -#define _SC_XOPEN_LEGACY 129 -#define _SC_XOPEN_REALTIME 130 -#define _SC_XOPEN_REALTIME_THREADS 131 -#define _SC_ADVISORY_INFO 132 -#define _SC_BARRIERS 133 -#define _SC_CLOCK_SELECTION 137 -#define _SC_CPUTIME 138 -#define _SC_THREAD_CPUTIME 139 -#define _SC_MONOTONIC_CLOCK 149 -#define _SC_READER_WRITER_LOCKS 153 -#define _SC_SPIN_LOCKS 154 -#define _SC_REGEXP 155 -#define _SC_SHELL 157 -#define _SC_SPAWN 159 -#define _SC_SPORADIC_SERVER 160 -#define _SC_THREAD_SPORADIC_SERVER 161 -#define _SC_TIMEOUTS 164 -#define _SC_TYPED_MEMORY_OBJECTS 165 -#define _SC_2_PBS 168 -#define _SC_2_PBS_ACCOUNTING 169 -#define _SC_2_PBS_LOCATE 170 -#define _SC_2_PBS_MESSAGE 171 -#define _SC_2_PBS_TRACK 172 -#define _SC_SYMLOOP_MAX 173 -#define _SC_STREAMS 174 -#define _SC_2_PBS_CHECKPOINT 175 -#define _SC_V6_ILP32_OFF32 176 -#define _SC_V6_ILP32_OFFBIG 177 -#define _SC_V6_LP64_OFF64 178 -#define _SC_V6_LPBIG_OFFBIG 179 -#define _SC_HOST_NAME_MAX 180 -#define _SC_TRACE 181 -#define _SC_TRACE_EVENT_FILTER 182 -#define _SC_TRACE_INHERIT 183 -#define _SC_TRACE_LOG 184 - -#define _SC_IPV6 235 -#define _SC_RAW_SOCKETS 236 -#define _SC_V7_ILP32_OFF32 237 -#define _SC_V7_ILP32_OFFBIG 238 -#define _SC_V7_LP64_OFF64 239 -#define _SC_V7_LPBIG_OFFBIG 240 -#define _SC_SS_REPL_MAX 241 -#define _SC_TRACE_EVENT_NAME_MAX 242 -#define _SC_TRACE_NAME_MAX 243 -#define _SC_TRACE_SYS_MAX 244 -#define _SC_TRACE_USER_EVENT_MAX 245 -#define _SC_XOPEN_STREAMS 246 -#define _SC_THREAD_ROBUST_PRIO_INHERIT 247 -#define _SC_THREAD_ROBUST_PRIO_PROTECT 248 - -#define _CS_PATH 0 -#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1 -#define _CS_GNU_LIBC_VERSION 2 -#define _CS_GNU_LIBPTHREAD_VERSION 3 -#define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS 4 -#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 5 - -#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1116 -#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 1117 -#define _CS_POSIX_V6_ILP32_OFF32_LIBS 1118 -#define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS 1119 -#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 1120 -#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 1121 -#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 1122 -#define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS 1123 -#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 1124 -#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 1125 -#define _CS_POSIX_V6_LP64_OFF64_LIBS 1126 -#define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS 1127 -#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 1128 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 1129 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 1130 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS 1131 -#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1132 -#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 1133 -#define _CS_POSIX_V7_ILP32_OFF32_LIBS 1134 -#define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS 1135 -#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 1136 -#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 1137 -#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 1138 -#define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS 1139 -#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 1140 -#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 1141 -#define _CS_POSIX_V7_LP64_OFF64_LIBS 1142 -#define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS 1143 -#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 1144 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 1145 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 1146 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147 -#define _CS_V6_ENV 1148 -#define _CS_V7_ENV 1149 - -#ifdef __cplusplus -} -#endif -#endif /* 0 */ - -#endif diff --git a/usr/lib/libc/include/wchar.h b/usr/lib/libc/include/wchar.h deleted file mode 100644 index 369b1e9f2..000000000 --- a/usr/lib/libc/include/wchar.h +++ /dev/null @@ -1,201 +0,0 @@ -#ifndef _WCHAR_H -#define _WCHAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_FILE -#define __NEED___isoc_va_list -#define __NEED_size_t -#define __NEED_wchar_t -#define __NEED_wint_t -#define __NEED_mbstate_t - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_locale_t -#define __NEED_va_list -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_wctype_t -#endif - -#include - -#if L'\0'-1 > 0 -#define WCHAR_MAX (0xffffffffu+L'\0') -#define WCHAR_MIN (0+L'\0') -#else -#define WCHAR_MAX (0x7fffffff+L'\0') -#define WCHAR_MIN (-1-0x7fffffff+L'\0') -#endif - -#ifdef __cplusplus -#define NULL 0L -#else -#define NULL ((void*)0) -#endif - -#undef WEOF -#define WEOF 0xffffffffU - -wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -int wcscmp (const wchar_t *, const wchar_t *); -int wcsncmp (const wchar_t *, const wchar_t *, size_t); - -int wcscoll(const wchar_t *, const wchar_t *); -size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -wchar_t *wcschr (const wchar_t *, wchar_t); -wchar_t *wcsrchr (const wchar_t *, wchar_t); - -size_t wcscspn (const wchar_t *, const wchar_t *); -size_t wcsspn (const wchar_t *, const wchar_t *); -wchar_t *wcspbrk (const wchar_t *, const wchar_t *); - -wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); - -size_t wcslen (const wchar_t *); - -wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcswcs (const wchar_t *, const wchar_t *); - -wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); -int wmemcmp (const wchar_t *, const wchar_t *, size_t); -wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); -wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); -wchar_t *wmemset (wchar_t *, wchar_t, size_t); - -wint_t btowc (int); -int wctob (wint_t); - -int mbsinit (const mbstate_t *); -size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); -size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); - -size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); - -size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); -size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); - -float wcstof (const wchar_t *__restrict, wchar_t **__restrict); -double wcstod (const wchar_t *__restrict, wchar_t **__restrict); -long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); - -long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); -unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); - -long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); -unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); - - - -int fwide (FILE *, int); - - -int wprintf (const wchar_t *__restrict, ...); -int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); -int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); - -int vwprintf (const wchar_t *__restrict, __isoc_va_list); -int vfwprintf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); -int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list); - -int wscanf (const wchar_t *__restrict, ...); -int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); -int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); - -int vwscanf (const wchar_t *__restrict, __isoc_va_list); -int vfwscanf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); -int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list); - -wint_t fgetwc (FILE *); -wint_t getwc (FILE *); -wint_t getwchar (void); - -wint_t fputwc (wchar_t, FILE *); -wint_t putwc (wchar_t, FILE *); -wint_t putwchar (wchar_t); - -wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); -int fputws (const wchar_t *__restrict, FILE *__restrict); - -wint_t ungetwc (wint_t, FILE *); - -struct tm; -size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); - -#undef iswdigit - -#if defined(_GNU_SOURCE) -wint_t fgetwc_unlocked (FILE *); -wint_t getwc_unlocked (FILE *); -wint_t getwchar_unlocked (void); -wint_t fputwc_unlocked (wchar_t, FILE *); -wint_t putwc_unlocked (wchar_t, FILE *); -wint_t putwchar_unlocked (wchar_t); -wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict); -int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t); -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -FILE *open_wmemstream(wchar_t **, size_t *); -size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); -size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); -wchar_t *wcsdup(const wchar_t *); -size_t wcsnlen (const wchar_t *, size_t); -wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); -int wcscasecmp(const wchar_t *, const wchar_t *); -int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); -int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); -int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); -int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); -size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int wcwidth (wchar_t); -int wcswidth (const wchar_t *, size_t); -int iswalnum(wint_t); -int iswalpha(wint_t); -int iswblank(wint_t); -int iswcntrl(wint_t); -int iswdigit(wint_t); -int iswgraph(wint_t); -int iswlower(wint_t); -int iswprint(wint_t); -int iswpunct(wint_t); -int iswspace(wint_t); -int iswupper(wint_t); -int iswxdigit(wint_t); -int iswctype(wint_t, wctype_t); -wint_t towlower(wint_t); -wint_t towupper(wint_t); -wctype_t wctype(const char *); - -#ifndef __cplusplus -#undef iswdigit -#define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/include/wctype.h b/usr/lib/libc/include/wctype.h deleted file mode 100644 index bc2420d3f..000000000 --- a/usr/lib/libc/include/wctype.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _WCTYPE_H -#define _WCTYPE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_wint_t -#define __NEED_wctype_t - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_locale_t -#endif - -#include - -typedef const int * wctrans_t; - -#undef WEOF -#define WEOF 0xffffffffU - -#undef iswdigit - -int iswalnum(wint_t); -int iswalpha(wint_t); -int iswblank(wint_t); -int iswcntrl(wint_t); -int iswdigit(wint_t); -int iswgraph(wint_t); -int iswlower(wint_t); -int iswprint(wint_t); -int iswpunct(wint_t); -int iswspace(wint_t); -int iswupper(wint_t); -int iswxdigit(wint_t); -int iswctype(wint_t, wctype_t); -wint_t towctrans(wint_t, wctrans_t); -wint_t towlower(wint_t); -wint_t towupper(wint_t); -wctrans_t wctrans(const char *); -wctype_t wctype(const char *); - -#ifndef __cplusplus -#undef iswdigit -#define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -int iswalnum_l(wint_t, locale_t); -int iswalpha_l(wint_t, locale_t); -int iswblank_l(wint_t, locale_t); -int iswcntrl_l(wint_t, locale_t); -int iswdigit_l(wint_t, locale_t); -int iswgraph_l(wint_t, locale_t); -int iswlower_l(wint_t, locale_t); -int iswprint_l(wint_t, locale_t); -int iswpunct_l(wint_t, locale_t); -int iswspace_l(wint_t, locale_t); -int iswupper_l(wint_t, locale_t); -int iswxdigit_l(wint_t, locale_t); -int iswctype_l(wint_t, wctype_t, locale_t); -wint_t towlower_l(wint_t, locale_t); -wint_t towupper_l(wint_t, locale_t); -wint_t towctrans_l(wint_t, wctrans_t, locale_t); -wctrans_t wctrans_l(const char *, locale_t); -wctype_t wctype_l(const char *, locale_t); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/usr/lib/libc/inet.c b/usr/lib/libc/inet.c deleted file mode 100644 index cf9010ca5..000000000 --- a/usr/lib/libc/inet.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "inet.h" -#include "stdio.h" -#include "string.h" -#include "stdlib.h" - -in_addr_t inet_addr(const char *cp) -{ - in_addr_t result = 0; - - int i; - int j = 0; - int k = 0; - int l; - char buf[4]; - char ip[4]; - int len = strlen(cp); - char exp = 1; - - for (i = 0 ; i <= strlen(cp) ; i++) { - if ((cp[i] == '.') || (i == len)) { - buf[j] = '\0'; - j = 0; - ip[k] = (char)0; - exp = 1; - for (l = strlen(buf) - 1 ; l >= 0 ; l--) { - ip[k] += (char)((buf[l] - '0') * exp); - exp *= (char)10; - } - k++; - } - else { - buf[j] = cp[i]; - j++; - } - } - - result = (uint32_t)((uint32_t)(((ip[0] & 0xFF) << 24) & 0xFF000000) | - (uint32_t)(((ip[1] & 0xFF) << 16) & 0x00FF0000) | - (uint32_t)(((ip[2] & 0xFF) << 8) & 0x0000FF00) | - (uint32_t)((ip[3] & 0xFF) & 0x000000FF)); - - return result; -} diff --git a/usr/lib/libc/intscan.c b/usr/lib/libc/intscan.c deleted file mode 100644 index 7ebb389fc..000000000 --- a/usr/lib/libc/intscan.c +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -#include -#include "shgetc.h" - -/* Lookup table for digit values. -1==255>=36 -> invalid */ -static const unsigned char table[] = { -1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -}; - -unsigned long long __intscan(FILE *f, unsigned base, int pok, unsigned long long lim) -{ - const unsigned char *val = table+1; - int c, neg=0; - unsigned x; - unsigned long long y; - if (base > 36 || base == 1) { - errno = EINVAL; - return 0; - } - while (isspace((c=shgetc(f)))); - if (c=='+' || c=='-') { - neg = -(c=='-'); - c = shgetc(f); - } - if ((base == 0 || base == 16) && c=='0') { - c = shgetc(f); - if ((c|32)=='x') { - c = shgetc(f); - if (val[c]>=16) { - shunget(f); - if (pok) shunget(f); - else shlim(f, 0); - return 0; - } - base = 16; - } else if (base == 0) { - base = 8; - } - } else { - if (base == 0) base = 10; - if (val[c] >= base) { - shunget(f); - shlim(f, 0); - errno = EINVAL; - return 0; - } - } - if (base == 10) { - for (x=0; c-'0'<10U && x<=UINT_MAX/10-1; c=shgetc(f)) - x = x*10 + (c-'0'); - for (y=x; c-'0'<10U && y<=ULLONG_MAX/10 && 10*y<=ULLONG_MAX-(c-'0'); c=shgetc(f)) - y = y*10 + (c-'0'); - if (c-'0'>=10U) goto done; - } else if (!(base & (base-1))) { - int bs = "\0\1\2\4\7\3\6\5"[(0x17*base)>>5&7]; - for (x=0; val[c]>bs; c=shgetc(f)) - y = y<=lim) { - if (!(lim&1) && !neg) { - errno = ERANGE; - return lim-1; - } else if (y>lim) { - errno = ERANGE; - return lim; - } - } - return (y^neg)-neg; -} diff --git a/usr/lib/libc/libc.c b/usr/lib/libc/libc.c deleted file mode 100644 index 7706a8017..000000000 --- a/usr/lib/libc/libc.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -size_t __hwcap; diff --git a/usr/lib/libc/longjmp.S b/usr/lib/libc/longjmp.S deleted file mode 100644 index 9bde71706..000000000 --- a/usr/lib/libc/longjmp.S +++ /dev/null @@ -1,80 +0,0 @@ -#ifdef __ARM__ - -.syntax unified -.global _longjmp -.global longjmp -.type _longjmp,%function -.type longjmp,%function -_longjmp: -longjmp: - mov ip,r0 - movs r0,r1 - moveq r0,#1 - ldmia ip!, {v1,v2,v3,v4,v5,v6,sl,fp} - ldmia ip!, {r2,lr} - mov sp,r2 - - adr r1,1f - ldr r2,1f - ldr r1,[r1,r2] - -#if __ARM_ARCH < 8 - tst r1,#0x260 - beq 3f - // HWCAP_ARM_FPA - tst r1,#0x20 - beq 2f - ldc p2, cr4, [ip], #48 -#endif -2: tst r1,#0x40 - beq 2f - .fpu vfp - vldmia ip!, {d8-d15} - .fpu softvfp - .eabi_attribute 10, 0 - .eabi_attribute 27, 0 -#if __ARM_ARCH < 8 - // HWCAP_ARM_IWMMXT -2: tst r1,#0x200 - beq 3f - ldcl p1, cr10, [ip], #8 - ldcl p1, cr11, [ip], #8 - ldcl p1, cr12, [ip], #8 - ldcl p1, cr13, [ip], #8 - ldcl p1, cr14, [ip], #8 - ldcl p1, cr15, [ip], #8 -#endif -2: -3: bx lr - -.hidden __hwcap -.align 2 -1: .word __hwcap-1b - -#else /* __ARM64__ */ - -.global _longjmp -.global longjmp -.type _longjmp,%function -.type longjmp,%function -_longjmp: -longjmp: - // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers - ldp x19, x20, [x0,#0] - ldp x21, x22, [x0,#16] - ldp x23, x24, [x0,#32] - ldp x25, x26, [x0,#48] - ldp x27, x28, [x0,#64] - ldp x29, x30, [x0,#80] - ldr x2, [x0,#104] - mov sp, x2 - ldp d8 , d9, [x0,#112] - ldp d10, d11, [x0,#128] - ldp d12, d13, [x0,#144] - ldp d14, d15, [x0,#160] - - cmp w1, 0 - csinc w0, w1, wzr, ne - br x30 - -#endif /* __ARM__ */ diff --git a/usr/lib/libc/malloc.c b/usr/lib/libc/malloc.c deleted file mode 100644 index da1629693..000000000 --- a/usr/lib/libc/malloc.c +++ /dev/null @@ -1,543 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* debugging */ -#if 0 -#define DEBUG -#endif - -#define dprintf(...) \ - do { if (DEBUG) fprintf(stderr, __VA_ARGS__); } while (0) - -#ifdef DEBUG -#define DBG(...) printf("Malloc: Debug", __func__, __VA_ARGS__) -#else -#define DBG(...) -#endif - -/* - * Check if need of another init - */ -static bool is_heap_init = 0; - -/* there's a list for each size. The size changes over the process lifetime. */ -struct mem_chunk { - - /* Pointer to the next memchunk of a different size */ - struct mem_chunk *next_list; - - /* Pointer to the next memchunk of this size. */ - struct mem_chunk *next_chunk; - - /* Refer to the head of the (2nd-dimension) list for this size */ - struct mem_chunk *head; - - /* - * Size in bytes of the user area (this does NOT include the size of mem_chunk). - * This size can be over the requested size if the remaining area is not large enough - * to store the mem_chunk structure (use req_size to have the *real* requested area in any case). - */ - size_t size; - - /* Real requested size by the user. */ - size_t req_size; - - /* Used in case of specific alignment on address - These bytes are lost */ - size_t padding_bytes; -}; - -typedef struct mem_chunk mem_chunk_t; - -/* Head of the quick list */ -static struct mem_chunk *quick_list; - -/* - * Initialization of the quick-fit list. - */ -void heap_init(void) -{ - quick_list = (mem_chunk_t *) sbrk(0); - - quick_list->next_list = NULL; - quick_list->next_chunk = NULL; - quick_list->head = quick_list; - - /* Reserve the place for the first mem_chunk */ - quick_list->size = HEAP_SIZE - sizeof(mem_chunk_t); - quick_list->padding_bytes = 0; - - DBG("SO3: allocating a kernel heap of %d bytes.\n", quick_list->size); - - DBG("[list_init] List initialized. sizeof(mem_chunk_t) = %d bytes, sizeof(int) = %d bytes\n", sizeof(mem_chunk_t), sizeof(int)); -} - -/* - * Print the content of the quick-fit list. - */ -void dump_heap(const char *info) -{ - int i, j; - mem_chunk_t *list = quick_list; - mem_chunk_t *chunk = quick_list; - uint32_t total_size = 0; - - i = j = 0; - - while (list) { - printf("[%s - print_list] [0x%p] List #%d\n", info, list, j++); - - while (chunk) { - printf("[%s - print_list] [%p] %d size = %d bytes, head = %p, next_list = %p, next_chunk = %p ---> \n", - info, chunk, i++, chunk->size, chunk->head, chunk->next_list, chunk->next_chunk); - total_size += chunk->size; - - chunk = chunk->next_chunk; - } - i = 0; - - list = list->next_list; - chunk = list; - } - printf(" [%s] Heap total remaining size: %d\n", info, total_size); - -} - -void print_chunk(mem_chunk_t *chunk, const char *caller, const char *name) -{ - DBG("[%s - print_chunk] [%p] [%s] %d bytes, next_list = %p, next_chunk = %p\n", - caller, chunk, name, chunk->size, chunk->next_list, chunk->next_chunk); -} - -/* - * Re-init a chunk - */ -static void reset_chunk(mem_chunk_t *chunk) -{ - DBG("[reset_chunk] %p\n", chunk); - - chunk->next_list = NULL; - chunk->next_chunk = NULL; - chunk->head = NULL; - - /* Of course, size is preserved. */ -} - -/* - * Remove a memchunk from its current position in the quick list. - */ -static void remove_chunk(mem_chunk_t *chunk) -{ - mem_chunk_t *__chunk, *head; - - DBG("[remove_chunk] %p\n", chunk); - - __chunk = chunk; - head = chunk->head; - - /* Special case if the memchunk to be removed is the head of its list */ - if (head == chunk) { - /* The memchunk is at the head of the list */ - head = quick_list; - - /* Update the memchunk list references if necessary */ - if (chunk == quick_list) - - /* Check if the memchunk is at the head of the quick list */ - quick_list = ((chunk->next_chunk == NULL) ? chunk->next_list : chunk->next_chunk); - - else { - /* Look for the head predecessor of this chunk */ - while (head->next_list != chunk) - head = head->next_list; - - /* Update the previous head to the next_list */ - if (chunk->next_chunk == NULL) - head->next_list = chunk->next_list; - else - head->next_list = chunk->next_chunk; - - } - - if (chunk->next_chunk != NULL) { - /* We also need to update the head of each chunk of associated list */ - head = chunk->next_chunk; - head->next_list = chunk->next_list; /* Just the head */ - - chunk = head; - do { - chunk->head = head; - chunk = chunk->next_chunk; - } while (chunk != NULL); - } - - } else { - - while (head->next_chunk != chunk) - head = head->next_chunk; - - /* Found, detach the mem chunk */ - head->next_chunk = chunk->next_chunk; - } - - reset_chunk(__chunk); - -#ifdef DEBUG - dump_heap(__func__); -#endif - -} - -/* - * Insert a new mem_chunk in the quick list. - */ -static void append_chunk(mem_chunk_t *chunk) -{ - mem_chunk_t *tmp_list, *last; - mem_chunk_t *tmp_chunk; - - DBG("[append_chunk] %p with size %d padding: %d\n", chunk, chunk->size, chunk->padding_bytes); - - reset_chunk(chunk); - - if (!quick_list) { - DBG("[append_chunk] Adding first entry in quick_list\n"); - quick_list = chunk; - chunk->head = quick_list; - } else { - - /* Try to append our chunk to existing list */ - tmp_list = quick_list; - - while ((tmp_list != NULL) && (tmp_list->size < chunk->size)) { - last = tmp_list; /* Useful in the latest case */ - tmp_list = tmp_list->next_list; - } - - if (tmp_list != NULL) { /* We found a position in the list (sorted items) */ - - if (tmp_list->size == chunk->size) { /* Good, we have found the right size */ - DBG("[append_chunk] found a list with the right size %d\n", chunk->size); - tmp_chunk = tmp_list; - - /* Go to end of list */ - while (tmp_chunk->next_chunk != NULL) - tmp_chunk = tmp_chunk->next_chunk; - - /* Append our new free chunk */ - tmp_chunk->next_chunk = chunk; - chunk->head = tmp_list; - - } else { /* Not the right size, but tmp_list->size is greater than chunk->size, so create a list entry and insert right before */ - - DBG("[append_chunk] creating list of new size %d\n", chunk->size); - - if (tmp_list == quick_list) { /* This entry is the quick_list origin, update it */ - chunk->next_list = quick_list; - chunk->head = chunk; - quick_list = chunk; - - } else { /* Somewhere else in the quick list ... */ - - tmp_chunk = quick_list; - while (tmp_chunk->next_list != tmp_list) - tmp_chunk = tmp_chunk->next_list; - - /* Insert it - tmp_chunk now refers to the previous list. */ - - tmp_chunk->next_list = chunk; - - chunk->next_list = tmp_list; - chunk->head = chunk; - } - } - - } else { /* Definitively at the end of the list */ - - DBG("[append_chunk] adding at the end of quick_list with new size %d\n", chunk->size); - - last->next_list = chunk; - chunk->head = chunk; - } - } -} - -/* - * Find neighbouring chunks and merge them - */ -static void merge_chunks(mem_chunk_t *new_chunk) -{ - mem_chunk_t *tmp_list; - mem_chunk_t *tmp_chunk, *merged_chunk; - - /* - * Inspect the whole quick list to see if some possible merge is feasible. Since a merged chunk may be adjacent to another one, we need to - * re-iterate on the quick list to find a possible candidate for a merge. - */ -recheck: - tmp_list = quick_list; - - while (tmp_list) { - tmp_chunk = tmp_list; - - /* Iterate through every chunk */ - while (tmp_chunk) { - - /* Check if merging required. If we do this each time a chunk is freed, - * it's sufficient to only check for chunks adjacent to the one just freed */ - if ((char *) new_chunk + new_chunk->size + sizeof(mem_chunk_t) == (char *) tmp_chunk || /* adjacent chunk after */ - (char *) tmp_chunk + tmp_chunk->size + sizeof(mem_chunk_t) == (char *) new_chunk) { /* adjacent chunk before */ - - - /* tmp_chunk is adjacent to new_chunk. Merge them */ - DBG("[merge_chunks] merging new_chunk [%p] with tmp_chunk [%p]\n", new_chunk, tmp_chunk); -#ifdef DEBUG - dump_heap(__func__); -#endif - - /* merge these two chunks into a new one */ - if (new_chunk < tmp_chunk) { - - /* new_chunk is before tmp_chunk */ - new_chunk->size += tmp_chunk->size + sizeof(mem_chunk_t); /* Recover space used by memchunk */ - merged_chunk = new_chunk; - - } else { - - /* new_chunk is after tmp_chunk */ - tmp_chunk->size += new_chunk->size + sizeof(mem_chunk_t); - merged_chunk = tmp_chunk; - - } - - /* Remove both chunks from the list... */ - remove_chunk(tmp_chunk); - remove_chunk(new_chunk); - - /* ...and append the merged chunk. */ - DBG("[merge_chunks] tmp_chunk: %p new_chunk: %p merged_chunk: %p merged_chunk->size = %d\n", tmp_chunk, new_chunk, merged_chunk, merged_chunk->size); - append_chunk(merged_chunk); - - /* we will recheck for any adjacent chunk with our merged chunk */ - new_chunk = merged_chunk; - goto recheck; - } - - tmp_chunk = tmp_chunk->next_chunk; - } - - tmp_list = tmp_list->next_list; - } - -} - -/* - * Allocate a memory area of a certain size ( bytes). - * The address can be requested to be aligned according to @alignment which has to be a power of 2. - */ -static void *__malloc(size_t requested, unsigned int alignment) -{ - mem_chunk_t *victim; - mem_chunk_t *remaining = NULL; /* new free chunk if size < victim->size */ - mem_chunk_t tmp_memchunk; /* Used for possible shifting of the structure */ - void *addr = NULL, *tmp_addr; - - -#ifdef DEBUG - dump_heap(__func__); -#endif - - if (!is_heap_init) { - heap_init(); - is_heap_init = 1; - } - - - DBG("[malloc] requested size = %d, mem_chunk_size = %d bytes\n", requested, sizeof(mem_chunk_t)); - - /* find the best fit in our list */ - victim = quick_list; - -next_list: - /* We check victim to be different of NULL since we might iterate several times */ - while (victim && (victim->size < requested)) - victim = victim->next_list; - - if (!victim) { - /* not enough free space left */ - /* FIXME: do sbrk() here to request more space. Request less space in init() */ - printf("[malloc] Not enough free space"); - - dump_heap("Heap overflow"); - - return NULL; - } - - /* Go to the end of the list to avoid overhead time to re-process head of each chunk */ - while (victim->next_chunk != NULL) - victim = victim->next_chunk; - - /* Calculate the *real* address that will be returned to the caller */ - addr = (char *) victim + sizeof(mem_chunk_t); - - /* Store the requested size if the area becomes larger than requested because of the lack of space to store remaining chunk. */ - victim->req_size = requested; - - /* - * We enforce the address returned to be word-aligned so that if some data which requires word-alignment - * (for example in case of ldrex/strex based monitors) will stay aligned. - */ - - alignment = ((alignment == 0) ? sizeof(int) : alignment); - - /* Is a specific alignment requested ? (alignment must be a power of 2) */ - - if (alignment > 0) { - tmp_addr = (void *) (((unsigned long) addr + alignment - 1) & -((signed) alignment)); - - /* If there is a required shift, padding bytes are considered as payload bytes of the chunk */ - if ((unsigned int) (tmp_addr - addr) + requested > victim->size) { - - /* Look at a next possible victim in this list */ - victim = victim->head->next_list; - - goto next_list; - - } else { - - victim->padding_bytes = tmp_addr - addr; - - addr = tmp_addr; - } - } - - /* This chunk isn't free anymore */ - - remove_chunk(victim); - - /* - * If there is a remaining size, and if this remaining size supports storing a mem_chunk_t, then we - * can append a new (free) memchunk, otherwise remaining bytes are lost. - */ - if (victim->size > requested + victim->padding_bytes + sizeof(mem_chunk_t)) { - - /* Split this chunk and append in the list. */ - remaining = (mem_chunk_t *) ((char *) victim + sizeof(mem_chunk_t) + requested + victim->padding_bytes); - remaining->size = victim->size - requested - sizeof(mem_chunk_t) - victim->padding_bytes; - remaining->padding_bytes = 0; - - /* Re-calculate the size of the allocated chunk. */ - victim->size = requested + victim->padding_bytes; - - append_chunk(remaining); - - } - - /* - * If there are some padding bytes, we need to shift the mem_chunk_t of these bytes - * so that it is possible to retrieve the structure when freeing. - */ - if (victim->padding_bytes) { - memcpy(&tmp_memchunk, victim, sizeof(mem_chunk_t)); - memcpy(((char *) victim) + victim->padding_bytes, &tmp_memchunk, sizeof(mem_chunk_t)); - } - - -#ifdef DEBUG - dump_heap(__func__); -#endif - - return addr; -} - - -/* - * Request a chunk of heap memory of @size bytes. - */ -void *malloc(size_t size) { - return __malloc(size, 0); -} - -/* - * @memalign to retrieve a malloc area of a @requested size with a specific @alignment which is a power of 2. - */ -void *memalign(size_t size, size_t alignment) { - return __malloc(size, alignment); -} - -/** - * Free an allocated area. - * - * From section 7.20.3.2/2 of the C99 standard: - * - * The free function causes the space pointed to by ptr to be deallocated, that is, - * made available for further allocation. If ptr is a null pointer, no action occurs. - * - * @param ptr - */ -void free(void *ptr) -{ - mem_chunk_t *chunk = (mem_chunk_t *)((char *) ptr - sizeof(mem_chunk_t)); - mem_chunk_t tmp_memchunk; - - if (!ptr) - return ; - - if (chunk->padding_bytes) { - /* Restore the original position of the memchunk if any padding bytes are considered. */ - memcpy(&tmp_memchunk, chunk, sizeof(mem_chunk_t)); - - chunk = (mem_chunk_t *) ((char *) chunk - tmp_memchunk.padding_bytes); - - memcpy(chunk, &tmp_memchunk, sizeof(mem_chunk_t)); - - chunk->padding_bytes = 0; - } - - DBG("[free_chunk] %p with size %d\n", chunk, chunk->size); - -#ifdef DEBUG - dump_heap("free {before}"); -#endif - append_chunk(chunk); - merge_chunks(chunk); - -#ifdef DEBUG - dump_heap("free {after}"); -#endif -} - -/* - * Re-allocate an existing memory area (previously allocated with malloc). - * The size can be greater, equal, or less than the original. - */ -void *realloc(void *__ptr, size_t __size) { - - void *alloc; - struct mem_chunk *chunk; - - chunk = (struct mem_chunk *) (__ptr - sizeof(struct mem_chunk)); - - /* Check if the new zone is smaller than the original */ - if (__size < chunk->req_size) - __size = chunk->req_size; - - alloc = malloc(__size); - if (!alloc) - return NULL; - - DBG("Requesting a size of %d\n", __size); - DBG("Copying a size of %d\n", ((__size < chunk->req_size) ? __size : chunk->req_size)); - DBG("allocation pointer %p\n", alloc); - - memcpy(alloc, __ptr, ((__size < chunk->req_size) ? __size : chunk->req_size)); - - free(__ptr); - - return alloc; - -} - diff --git a/usr/lib/libc/malloc/CMakeLists.txt b/usr/lib/libc/malloc/CMakeLists.txt deleted file mode 100644 index 3d900d0c2..000000000 --- a/usr/lib/libc/malloc/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -target_sources(c - PRIVATE - calloc.c -) \ No newline at end of file diff --git a/usr/lib/libc/malloc/DESIGN b/usr/lib/libc/malloc/DESIGN deleted file mode 100644 index 58b0523ff..000000000 --- a/usr/lib/libc/malloc/DESIGN +++ /dev/null @@ -1,22 +0,0 @@ - - -In principle, this memory allocator is roughly equivalent to Doug -Lea's dlmalloc with fine-grained locking. - - - -malloc: - -Uses a freelist binned by chunk size, with a bitmap to optimize -searching for the smallest non-empty bin which can satisfy an -allocation. If no free chunks are available, it creates a new chunk of -the requested size and attempts to merge it with any existing free -chunk immediately below the newly created chunk. - -Whether the chunk was obtained from a bin or newly created, it's -likely to be larger than the requested allocation. malloc always -finishes its work by passing the new chunk to realloc, which will -split it into two chunks and free the tail portion. - - - diff --git a/usr/lib/libc/malloc/__brk.c b/usr/lib/libc/malloc/__brk.c deleted file mode 100644 index 4c9119b4d..000000000 --- a/usr/lib/libc/malloc/__brk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -uintptr_t __brk(uintptr_t newbrk) -{ - return __syscall(SYS_brk, newbrk); -} diff --git a/usr/lib/libc/malloc/aligned_alloc.c b/usr/lib/libc/malloc/aligned_alloc.c deleted file mode 100644 index cc0a80120..000000000 --- a/usr/lib/libc/malloc/aligned_alloc.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -void *__memalign(size_t, size_t); - -void *aligned_alloc(size_t align, size_t len) -{ - return __memalign(align, len); -} diff --git a/usr/lib/libc/malloc/calloc.c b/usr/lib/libc/malloc/calloc.c deleted file mode 100644 index e4067fcea..000000000 --- a/usr/lib/libc/malloc/calloc.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include - -#include - -#if 0 -void *__malloc0(size_t); -#endif - -void *calloc(size_t m, size_t n) -{ - void *__area; - - if (n && m > (size_t)-1/n) { - errno = ENOMEM; - return NULL; - } -#if 0 - return __malloc0(n * m); -#endif - __area = malloc(n * m); - - /* According to POSIX, the memory is set to 0. */ - if (!__area) { - errno = ENOMEM; - return NULL; - } - - memset(__area, 0, n*m); - - return __area; -} diff --git a/usr/lib/libc/malloc/expand_heap.c b/usr/lib/libc/malloc/expand_heap.c deleted file mode 100644 index d8c0be742..000000000 --- a/usr/lib/libc/malloc/expand_heap.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include -#include "libc.h" -#include "syscall.h" - -/* This function returns true if the interval [old,new] - * intersects the 'len'-sized interval below &libc.auxv - * (interpreted as the main-thread stack) or below &b - * (the current stack). It is used to defend against - * buggy brk implementations that can cross the stack. */ - -static int traverses_stack_p(uintptr_t old, uintptr_t new) -{ - const uintptr_t len = 8<<20; - uintptr_t a, b; - - b = (uintptr_t)libc.auxv; - a = b > len ? b-len : 0; - if (new>a && old len ? b-len : 0; - if (new>a && old SIZE_MAX/2 - PAGE_SIZE) { - errno = ENOMEM; - return 0; - } - n += -n & PAGE_SIZE-1; - - if (!brk) { - brk = __syscall(SYS_brk, 0); - brk += -brk & PAGE_SIZE-1; - } - - if (n < SIZE_MAX-brk && !traverses_stack_p(brk, brk+n) - && __syscall(SYS_brk, brk+n)==brk+n) { - *pn = n; - brk += n; - return (void *)(brk-n); - } - - size_t min = (size_t)PAGE_SIZE << mmap_step/2; - if (n < min) n = min; - void *area = __mmap(0, n, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - if (area == MAP_FAILED) return 0; - *pn = n; - mmap_step++; - return area; -} diff --git a/usr/lib/libc/malloc/lite_malloc.c b/usr/lib/libc/malloc/lite_malloc.c deleted file mode 100644 index a7e4a9f7b..000000000 --- a/usr/lib/libc/malloc/lite_malloc.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include -#include "libc.h" - -#define ALIGN 16 - -void *__expand_heap(size_t *); - -static void *__simple_malloc(size_t n) -{ - static char *cur, *end; - static volatile int lock[2]; - size_t align=1, pad; - void *p; - - if (!n) n++; - while (align end-cur) { - size_t m = n; - char *new = __expand_heap(&m); - if (!new) { - UNLOCK(lock); - return 0; - } - if (new != end) { - cur = new; - n -= pad; - pad = 0; - } - end = new + m; - } - - p = cur + pad; - cur += n; - UNLOCK(lock); - return p; -} - -weak_alias(__simple_malloc, malloc); -weak_alias(__simple_malloc, __malloc0); diff --git a/usr/lib/libc/malloc/malloc.c b/usr/lib/libc/malloc/malloc.c deleted file mode 100644 index d5ee4280e..000000000 --- a/usr/lib/libc/malloc/malloc.c +++ /dev/null @@ -1,532 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include "libc.h" -#include "atomic.h" -#include "pthread_impl.h" - -#if defined(__GNUC__) && defined(__PIC__) -#define inline inline __attribute__((always_inline)) -#endif - -void *__mmap(void *, size_t, int, int, int, off_t); -int __munmap(void *, size_t); -void *__mremap(void *, size_t, size_t, int, ...); -int __madvise(void *, size_t, int); - -struct chunk { - size_t psize, csize; - struct chunk *next, *prev; -}; - -struct bin { - volatile int lock[2]; - struct chunk *head; - struct chunk *tail; -}; - -static struct { - volatile uint64_t binmap; - struct bin bins[64]; - volatile int free_lock[2]; -} mal; - - -#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)) - - -/* Synchronization tools */ - -static inline void lock(volatile int *lk) -{ - if (libc.threads_minus_1) - while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); -} - -static inline void unlock(volatile int *lk) -{ - if (lk[0]) { - a_store(lk, 0); - if (lk[1]) __wake(lk, 1, 1); - } -} - -static inline void lock_bin(int i) -{ - lock(mal.bins[i].lock); - if (!mal.bins[i].head) - mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i); -} - -static inline void unlock_bin(int i) -{ - unlock(mal.bins[i].lock); -} - -static int first_set(uint64_t x) -{ -#if 1 - return a_ctz_64(x); -#else - static const char debruijn64[64] = { - 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, - 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, - 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, - 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 - }; - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; - if (sizeof(long) < 8) { - uint32_t y = x; - if (!y) { - y = x>>32; - return 32 + debruijn32[(y&-y)*0x076be629 >> 27]; - } - return debruijn32[(y&-y)*0x076be629 >> 27]; - } - return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; -#endif -} - -static const unsigned char bin_tab[60] = { - 32,33,34,35,36,36,37,37,38,38,39,39, - 40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43, - 44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45, - 46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47, -}; - -static int bin_index(size_t x) -{ - x = x / SIZE_ALIGN - 1; - if (x <= 32) return x; - if (x < 512) return bin_tab[x/8-4]; - if (x > 0x1c00) return 63; - return bin_tab[x/128-4] + 16; -} - -static int bin_index_up(size_t x) -{ - x = x / SIZE_ALIGN - 1; - if (x <= 32) return x; - x--; - if (x < 512) return bin_tab[x/8-4] + 1; - return bin_tab[x/128-4] + 17; -} - -#if 0 -void __dump_heap(int x) -{ - struct chunk *c; - int i; - for (c = (void *)mal.heap; CHUNK_SIZE(c); c = NEXT_CHUNK(c)) - fprintf(stderr, "base %p size %zu (%d) flags %d/%d\n", - c, CHUNK_SIZE(c), bin_index(CHUNK_SIZE(c)), - c->csize & 15, - NEXT_CHUNK(c)->psize & 15); - for (i=0; i<64; i++) { - if (mal.bins[i].head != BIN_TO_CHUNK(i) && mal.bins[i].head) { - fprintf(stderr, "bin %d: %p\n", i, mal.bins[i].head); - if (!(mal.binmap & 1ULL<psize = 0 | C_INUSE; - } - - /* Record new heap end and fill in footer. */ - end = (char *)p + n; - w = MEM_TO_CHUNK(end); - w->psize = n | C_INUSE; - w->csize = 0 | C_INUSE; - - /* Fill in header, which may be new or may be replacing a - * zero-size sentinel header at the old end-of-heap. */ - w = MEM_TO_CHUNK(p); - w->csize = n | C_INUSE; - - unlock(heap_lock); - - return w; -} - -static int adjust_size(size_t *n) -{ - /* Result of pointer difference must fit in ptrdiff_t. */ - if (*n-1 > PTRDIFF_MAX - SIZE_ALIGN - PAGE_SIZE) { - if (*n) { - errno = ENOMEM; - return -1; - } else { - *n = SIZE_ALIGN; - return 0; - } - } - *n = (*n + OVERHEAD + SIZE_ALIGN - 1) & SIZE_MASK; - return 0; -} - -static void unbin(struct chunk *c, int i) -{ - if (c->prev == c->next) - a_and_64(&mal.binmap, ~(1ULL<prev->next = c->next; - c->next->prev = c->prev; - c->csize |= C_INUSE; - NEXT_CHUNK(c)->psize |= C_INUSE; -} - -static int alloc_fwd(struct chunk *c) -{ - int i; - size_t k; - while (!((k=c->csize) & C_INUSE)) { - i = bin_index(k); - lock_bin(i); - if (c->csize == k) { - unbin(c, i); - unlock_bin(i); - return 1; - } - unlock_bin(i); - } - return 0; -} - -static int alloc_rev(struct chunk *c) -{ - int i; - size_t k; - while (!((k=c->psize) & C_INUSE)) { - i = bin_index(k); - lock_bin(i); - if (c->psize == k) { - unbin(PREV_CHUNK(c), i); - unlock_bin(i); - return 1; - } - unlock_bin(i); - } - return 0; -} - - -/* pretrim - trims a chunk _prior_ to removing it from its bin. - * Must be called with i as the ideal bin for size n, j the bin - * for the _free_ chunk self, and bin j locked. */ -static int pretrim(struct chunk *self, size_t n, int i, int j) -{ - size_t n1; - struct chunk *next, *split; - - /* We cannot pretrim if it would require re-binning. */ - if (j < 40) return 0; - if (j < i+3) { - if (j != 63) return 0; - n1 = CHUNK_SIZE(self); - if (n1-n <= MMAP_THRESHOLD) return 0; - } else { - n1 = CHUNK_SIZE(self); - } - if (bin_index(n1-n) != j) return 0; - - next = NEXT_CHUNK(self); - split = (void *)((char *)self + n); - - split->prev = self->prev; - split->next = self->next; - split->prev->next = split; - split->next->prev = split; - split->psize = n | C_INUSE; - split->csize = n1-n; - next->psize = n1-n; - self->csize = n | C_INUSE; - return 1; -} - -static void trim(struct chunk *self, size_t n) -{ - size_t n1 = CHUNK_SIZE(self); - struct chunk *next, *split; - - if (n >= n1 - DONTCARE) return; - - next = NEXT_CHUNK(self); - split = (void *)((char *)self + n); - - split->psize = n | C_INUSE; - split->csize = n1-n | C_INUSE; - next->psize = n1-n | C_INUSE; - self->csize = n | C_INUSE; - - free(CHUNK_TO_MEM(split)); -} - -void *malloc(size_t n) -{ - struct chunk *c; - int i, j; - - if (adjust_size(&n) < 0) return 0; - - if (n > MMAP_THRESHOLD) { - size_t len = n + OVERHEAD + PAGE_SIZE - 1 & -PAGE_SIZE; - char *base = __mmap(0, len, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - if (base == (void *)-1) return 0; - c = (void *)(base + SIZE_ALIGN - OVERHEAD); - c->csize = len - (SIZE_ALIGN - OVERHEAD); - c->psize = SIZE_ALIGN - OVERHEAD; - return CHUNK_TO_MEM(c); - } - - i = bin_index_up(n); - for (;;) { - uint64_t mask = mal.binmap & -(1ULL<psize = c->csize = - x->csize + CHUNK_SIZE(c); - } - break; - } - j = first_set(mask); - lock_bin(j); - c = mal.bins[j].head; - if (c != BIN_TO_CHUNK(j)) { - if (!pretrim(c, n, i, j)) unbin(c, j); - unlock_bin(j); - break; - } - unlock_bin(j); - } - - /* Now patch up in case we over-allocated */ - trim(c, n); - - return CHUNK_TO_MEM(c); -} - -void *__malloc0(size_t n) -{ - void *p = malloc(n); - if (p && !IS_MMAPPED(MEM_TO_CHUNK(p))) { - size_t *z; - n = (n + sizeof *z - 1)/sizeof *z; - for (z=p; n; n--, z++) if (*z) *z=0; - } - return p; -} - -void *realloc(void *p, size_t n) -{ - struct chunk *self, *next; - size_t n0, n1; - void *new; - - if (!p) return malloc(n); - - if (adjust_size(&n) < 0) return 0; - - self = MEM_TO_CHUNK(p); - n1 = n0 = CHUNK_SIZE(self); - - if (IS_MMAPPED(self)) { - size_t extra = self->psize; - char *base = (char *)self - extra; - size_t oldlen = n0 + extra; - size_t newlen = n + extra; - /* Crash on realloc of freed chunk */ - if (extra & 1) a_crash(); - if (newlen < PAGE_SIZE && (new = malloc(n))) { - memcpy(new, p, n-OVERHEAD); - free(p); - return new; - } - newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE; - if (oldlen == newlen) return p; - base = __mremap(base, oldlen, newlen, MREMAP_MAYMOVE); - if (base == (void *)-1) - goto copy_realloc; - self = (void *)(base + extra); - self->csize = newlen - extra; - return CHUNK_TO_MEM(self); - } - - next = NEXT_CHUNK(self); - - /* Crash on corrupted footer (likely from buffer overflow) */ - if (next->psize != self->csize) a_crash(); - - /* Merge adjacent chunks if we need more space. This is not - * a waste of time even if we fail to get enough space, because our - * subsequent call to free would otherwise have to do the merge. */ - if (n > n1 && alloc_fwd(next)) { - n1 += CHUNK_SIZE(next); - next = NEXT_CHUNK(next); - } - /* FIXME: find what's wrong here and reenable it..? */ - if (0 && n > n1 && alloc_rev(self)) { - self = PREV_CHUNK(self); - n1 += CHUNK_SIZE(self); - } - self->csize = n1 | C_INUSE; - next->psize = n1 | C_INUSE; - - /* If we got enough space, split off the excess and return */ - if (n <= n1) { - //memmove(CHUNK_TO_MEM(self), p, n0-OVERHEAD); - trim(self, n); - return CHUNK_TO_MEM(self); - } - -copy_realloc: - /* As a last resort, allocate a new chunk and copy to it. */ - new = malloc(n-OVERHEAD); - if (!new) return 0; - memcpy(new, p, n0-OVERHEAD); - free(CHUNK_TO_MEM(self)); - return new; -} - -void free(void *p) -{ - struct chunk *self = MEM_TO_CHUNK(p); - struct chunk *next; - size_t final_size, new_size, size; - int reclaim=0; - int i; - - if (!p) return; - - if (IS_MMAPPED(self)) { - size_t extra = self->psize; - char *base = (char *)self - extra; - size_t len = CHUNK_SIZE(self) + extra; - /* Crash on double free */ - if (extra & 1) a_crash(); - __munmap(base, len); - return; - } - - final_size = new_size = CHUNK_SIZE(self); - next = NEXT_CHUNK(self); - - /* Crash on corrupted footer (likely from buffer overflow) */ - if (next->psize != self->csize) a_crash(); - - for (;;) { - if (self->psize & next->csize & C_INUSE) { - self->csize = final_size | C_INUSE; - next->psize = final_size | C_INUSE; - i = bin_index(final_size); - lock_bin(i); - lock(mal.free_lock); - if (self->psize & next->csize & C_INUSE) - break; - unlock(mal.free_lock); - unlock_bin(i); - } - - if (alloc_rev(self)) { - self = PREV_CHUNK(self); - size = CHUNK_SIZE(self); - final_size += size; - if (new_size+size > RECLAIM && (new_size+size^size) > size) - reclaim = 1; - } - - if (alloc_fwd(next)) { - size = CHUNK_SIZE(next); - final_size += size; - if (new_size+size > RECLAIM && (new_size+size^size) > size) - reclaim = 1; - next = NEXT_CHUNK(next); - } - } - - if (!(mal.binmap & 1ULL<csize = final_size; - next->psize = final_size; - unlock(mal.free_lock); - - self->next = BIN_TO_CHUNK(i); - self->prev = mal.bins[i].tail; - self->next->prev = self; - self->prev->next = self; - - /* Replace middle of large chunks with fresh zero pages */ - if (reclaim) { - uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE; - uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE; -#if 1 - __madvise((void *)a, b-a, MADV_DONTNEED); -#else - __mmap((void *)a, b-a, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0); -#endif - } - - unlock_bin(i); -} diff --git a/usr/lib/libc/malloc/malloc_usable_size.c b/usr/lib/libc/malloc/malloc_usable_size.c deleted file mode 100644 index 6743ea775..000000000 --- a/usr/lib/libc/malloc/malloc_usable_size.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -void *(*const __realloc_dep)(void *, size_t) = realloc; - -struct chunk { - size_t psize, csize; - struct chunk *next, *prev; -}; - -#define OVERHEAD (2*sizeof(size_t)) -#define CHUNK_SIZE(c) ((c)->csize & -2) -#define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) - -size_t malloc_usable_size(void *p) -{ - return p ? CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD : 0; -} diff --git a/usr/lib/libc/malloc/memalign.c b/usr/lib/libc/malloc/memalign.c deleted file mode 100644 index 006bd21c7..000000000 --- a/usr/lib/libc/malloc/memalign.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include "libc.h" - -/* This function should work with most dlmalloc-like chunk bookkeeping - * systems, but it's only guaranteed to work with the native implementation - * used in this library. */ - -void *__memalign(size_t align, size_t len) -{ - unsigned char *mem, *new, *end; - size_t header, footer; - - if ((align & -align) != align) { - errno = EINVAL; - return NULL; - } - - if (len > SIZE_MAX - align) { - errno = ENOMEM; - return NULL; - } - - if (align <= 4*sizeof(size_t)) { - if (!(mem = malloc(len))) - return NULL; - return mem; - } - - if (!(mem = malloc(len + align-1))) - return NULL; - - new = (void *)((uintptr_t)mem + align-1 & -align); - if (new == mem) return mem; - - header = ((size_t *)mem)[-1]; - - if (!(header & 7)) { - ((size_t *)new)[-2] = ((size_t *)mem)[-2] + (new-mem); - ((size_t *)new)[-1] = ((size_t *)mem)[-1] - (new-mem); - return new; - } - - end = mem + (header & -8); - footer = ((size_t *)end)[-2]; - - ((size_t *)mem)[-1] = header&7 | new-mem; - ((size_t *)new)[-2] = footer&7 | new-mem; - ((size_t *)new)[-1] = header&7 | end-new; - ((size_t *)end)[-2] = footer&7 | end-new; - - free(mem); - return new; -} - -weak_alias(__memalign, memalign); diff --git a/usr/lib/libc/malloc/posix_memalign.c b/usr/lib/libc/malloc/posix_memalign.c deleted file mode 100644 index cf67db63b..000000000 --- a/usr/lib/libc/malloc/posix_memalign.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -void *__memalign(size_t, size_t); - -int posix_memalign(void **res, size_t align, size_t len) -{ - if (align < sizeof(void *)) return EINVAL; - void *mem = __memalign(align, len); - if (!mem) return errno; - *res = mem; - return 0; -} diff --git a/usr/lib/libc/math/CMakeLists.txt b/usr/lib/libc/math/CMakeLists.txt deleted file mode 100644 index fe5559700..000000000 --- a/usr/lib/libc/math/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ - - -target_sources(c - PRIVATE - frexpl - frexp - scalbn - scalbnl - fmodl - fabs - copysignl - copysignf - copysign - fmod - fminf - fmaxf - log - floor - pow - sqrt - __fpclassifyl - __signbitl -) - diff --git a/usr/lib/libc/math/__cos.c b/usr/lib/libc/math/__cos.c deleted file mode 100644 index 46cefb381..000000000 --- a/usr/lib/libc/math/__cos.c +++ /dev/null @@ -1,71 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_cos.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * __cos( x, y ) - * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * - * Algorithm - * 1. Since cos(-x) = cos(x), we need only to consider positive x. - * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0. - * 3. cos(x) is approximated by a polynomial of degree 14 on - * [0,pi/4] - * 4 14 - * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x - * where the remez error is - * - * | 2 4 6 8 10 12 14 | -58 - * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2 - * | | - * - * 4 6 8 10 12 14 - * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then - * cos(x) ~ 1 - x*x/2 + r - * since cos(x+y) ~ cos(x) - sin(x)*y - * ~ cos(x) - x*y, - * a correction term is necessary in cos(x) and hence - * cos(x+y) = 1 - (x*x/2 - (r - x*y)) - * For better accuracy, rearrange to - * cos(x+y) ~ w + (tmp + (r-x*y)) - * where w = 1 - x*x/2 and tmp is a tiny correction term - * (1 - x*x/2 == w + tmp exactly in infinite precision). - * The exactness of w + tmp in infinite precision depends on w - * and tmp having the same precision as x. If they have extra - * precision due to compiler bugs, then the extra precision is - * only good provided it is retained in all terms of the final - * expression for cos(). Retention happens in all cases tested - * under FreeBSD, so don't pessimize things by forcibly clipping - * any extra precision in w. - */ - -#include "libm.h" - -static const double -C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */ -C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */ -C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */ -C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */ -C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */ -C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ - -double __cos(double x, double y) -{ - double_t hz,z,r,w; - - z = x*x; - w = z*z; - r = z*(C1+z*(C2+z*C3)) + w*w*(C4+z*(C5+z*C6)); - hz = 0.5*z; - w = 1.0-hz; - return w + (((1.0-w)-hz) + (z*r-x*y)); -} diff --git a/usr/lib/libc/math/__cosdf.c b/usr/lib/libc/math/__cosdf.c deleted file mode 100644 index 2124989b3..000000000 --- a/usr/lib/libc/math/__cosdf.c +++ /dev/null @@ -1,35 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_cosf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Debugged and optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -/* |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). */ -static const double -C0 = -0x1ffffffd0c5e81.0p-54, /* -0.499999997251031003120 */ -C1 = 0x155553e1053a42.0p-57, /* 0.0416666233237390631894 */ -C2 = -0x16c087e80f1e27.0p-62, /* -0.00138867637746099294692 */ -C3 = 0x199342e0ee5069.0p-68; /* 0.0000243904487962774090654 */ - -float __cosdf(double x) -{ - double_t r, w, z; - - /* Try to optimize for parallel evaluation as in __tandf.c. */ - z = x*x; - w = z*z; - r = C2+z*C3; - return ((1.0+z*C0) + w*C1) + (w*z)*r; -} diff --git a/usr/lib/libc/math/__cosl.c b/usr/lib/libc/math/__cosl.c deleted file mode 100644 index fa522ddd7..000000000 --- a/usr/lib/libc/math/__cosl.c +++ /dev/null @@ -1,96 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/ld80/k_cosl.c */ -/* origin: FreeBSD /usr/src/lib/msun/ld128/k_cosl.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - - -#include "libm.h" - -#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#if LDBL_MANT_DIG == 64 -/* - * ld80 version of __cos.c. See __cos.c for most comments. - */ -/* - * Domain [-0.7854, 0.7854], range ~[-2.43e-23, 2.425e-23]: - * |cos(x) - c(x)| < 2**-75.1 - * - * The coefficients of c(x) were generated by a pari-gp script using - * a Remez algorithm that searches for the best higher coefficients - * after rounding leading coefficients to a specified precision. - * - * Simpler methods like Chebyshev or basic Remez barely suffice for - * cos() in 64-bit precision, because we want the coefficient of x^2 - * to be precisely -0.5 so that multiplying by it is exact, and plain - * rounding of the coefficients of a good polynomial approximation only - * gives this up to about 64-bit precision. Plain rounding also gives - * a mediocre approximation for the coefficient of x^4, but a rounding - * error of 0.5 ulps for this coefficient would only contribute ~0.01 - * ulps to the final error, so this is unimportant. Rounding errors in - * higher coefficients are even less important. - * - * In fact, coefficients above the x^4 one only need to have 53-bit - * precision, and this is more efficient. We get this optimization - * almost for free from the complications needed to search for the best - * higher coefficients. - */ -static const long double -C1 = 0.0416666666666666666136L; /* 0xaaaaaaaaaaaaaa9b.0p-68 */ -static const double -C2 = -0.0013888888888888874, /* -0x16c16c16c16c10.0p-62 */ -C3 = 0.000024801587301571716, /* 0x1a01a01a018e22.0p-68 */ -C4 = -0.00000027557319215507120, /* -0x127e4fb7602f22.0p-74 */ -C5 = 0.0000000020876754400407278, /* 0x11eed8caaeccf1.0p-81 */ -C6 = -1.1470297442401303e-11, /* -0x19393412bd1529.0p-89 */ -C7 = 4.7383039476436467e-14; /* 0x1aac9d9af5c43e.0p-97 */ -#define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*C7))))))) -#elif LDBL_MANT_DIG == 113 -/* - * ld128 version of __cos.c. See __cos.c for most comments. - */ -/* - * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]: - * |cos(x) - c(x))| < 2**-122.0 - * - * 113-bit precision requires more care than 64-bit precision, since - * simple methods give a minimax polynomial with coefficient for x^2 - * that is 1 ulp below 0.5, but we want it to be precisely 0.5. See - * above for more details. - */ -static const long double -C1 = 0.04166666666666666666666666666666658424671L, -C2 = -0.001388888888888888888888888888863490893732L, -C3 = 0.00002480158730158730158730158600795304914210L, -C4 = -0.2755731922398589065255474947078934284324e-6L, -C5 = 0.2087675698786809897659225313136400793948e-8L, -C6 = -0.1147074559772972315817149986812031204775e-10L, -C7 = 0.4779477332386808976875457937252120293400e-13L; -static const double -C8 = -0.1561920696721507929516718307820958119868e-15, -C9 = 0.4110317413744594971475941557607804508039e-18, -C10 = -0.8896592467191938803288521958313920156409e-21, -C11 = 0.1601061435794535138244346256065192782581e-23; -#define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+ \ - z*(C8+z*(C9+z*(C10+z*C11))))))))))) -#endif - -long double __cosl(long double x, long double y) -{ - long double hz,z,r,w; - - z = x*x; - r = POLY(z); - hz = 0.5*z; - w = 1.0-hz; - return w + (((1.0-w)-hz) + (z*r-x*y)); -} -#endif diff --git a/usr/lib/libc/math/__expo2.c b/usr/lib/libc/math/__expo2.c deleted file mode 100644 index 740ac680e..000000000 --- a/usr/lib/libc/math/__expo2.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "libm.h" - -/* k is such that k*ln2 has minimal relative error and x - kln2 > log(DBL_MIN) */ -static const int k = 2043; -static const double kln2 = 0x1.62066151add8bp+10; - -/* exp(x)/2 for x >= log(DBL_MAX), slightly better than 0.5*exp(x/2)*exp(x/2) */ -double __expo2(double x) -{ - double scale; - - /* note that k is odd and scale*scale overflows */ - INSERT_WORDS(scale, (uint32_t)(0x3ff + k/2) << 20, 0); - /* exp(x - k ln2) * 2**(k-1) */ - return exp(x - kln2) * scale * scale; -} diff --git a/usr/lib/libc/math/__expo2f.c b/usr/lib/libc/math/__expo2f.c deleted file mode 100644 index 5163e4180..000000000 --- a/usr/lib/libc/math/__expo2f.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "libm.h" - -/* k is such that k*ln2 has minimal relative error and x - kln2 > log(FLT_MIN) */ -static const int k = 235; -static const float kln2 = 0x1.45c778p+7f; - -/* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */ -float __expo2f(float x) -{ - float scale; - - /* note that k is odd and scale*scale overflows */ - SET_FLOAT_WORD(scale, (uint32_t)(0x7f + k/2) << 23); - /* exp(x - k ln2) * 2**(k-1) */ - return expf(x - kln2) * scale * scale; -} diff --git a/usr/lib/libc/math/__fpclassify.c b/usr/lib/libc/math/__fpclassify.c deleted file mode 100644 index f7c0e2dfa..000000000 --- a/usr/lib/libc/math/__fpclassify.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int __fpclassify(double x) -{ - union {double f; uint64_t i;} u = {x}; - int e = u.i>>52 & 0x7ff; - if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO; - if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE; - return FP_NORMAL; -} diff --git a/usr/lib/libc/math/__fpclassifyf.c b/usr/lib/libc/math/__fpclassifyf.c deleted file mode 100644 index fd00eb1bc..000000000 --- a/usr/lib/libc/math/__fpclassifyf.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int __fpclassifyf(float x) -{ - union {float f; uint32_t i;} u = {x}; - int e = u.i>>23 & 0xff; - if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO; - if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE; - return FP_NORMAL; -} diff --git a/usr/lib/libc/math/__fpclassifyl.c b/usr/lib/libc/math/__fpclassifyl.c deleted file mode 100644 index 481c0b949..000000000 --- a/usr/lib/libc/math/__fpclassifyl.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -int __fpclassifyl(long double x) -{ - return __fpclassify(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -int __fpclassifyl(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - int msb = u.i.m>>63; - if (!e && !msb) - return u.i.m ? FP_SUBNORMAL : FP_ZERO; - if (!msb) - return FP_NAN; - if (e == 0x7fff) - return u.i.m << 1 ? FP_NAN : FP_INFINITE; - return FP_NORMAL; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -int __fpclassifyl(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - u.i.se = 0; - if (!e) - return u.i2.lo | u.i2.hi ? FP_SUBNORMAL : FP_ZERO; - if (e == 0x7fff) - return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE; - return FP_NORMAL; -} -#endif diff --git a/usr/lib/libc/math/__invtrigl.c b/usr/lib/libc/math/__invtrigl.c deleted file mode 100644 index 48f83aaf8..000000000 --- a/usr/lib/libc/math/__invtrigl.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include "__invtrigl.h" - -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -static const long double -pS0 = 1.66666666666666666631e-01L, -pS1 = -4.16313987993683104320e-01L, -pS2 = 3.69068046323246813704e-01L, -pS3 = -1.36213932016738603108e-01L, -pS4 = 1.78324189708471965733e-02L, -pS5 = -2.19216428382605211588e-04L, -pS6 = -7.10526623669075243183e-06L, -qS1 = -2.94788392796209867269e+00L, -qS2 = 3.27309890266528636716e+00L, -qS3 = -1.68285799854822427013e+00L, -qS4 = 3.90699412641738801874e-01L, -qS5 = -3.14365703596053263322e-02L; - -const long double pio2_hi = 1.57079632679489661926L; -const long double pio2_lo = -2.50827880633416601173e-20L; - -/* used in asinl() and acosl() */ -/* R(x^2) is a rational approximation of (asin(x)-x)/x^3 with Remez algorithm */ -long double __invtrigl_R(long double z) -{ - long double p, q; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*(pS5+z*pS6)))))); - q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*qS5)))); - return p/q; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -static const long double -pS0 = 1.66666666666666666666666666666700314e-01L, -pS1 = -7.32816946414566252574527475428622708e-01L, -pS2 = 1.34215708714992334609030036562143589e+00L, -pS3 = -1.32483151677116409805070261790752040e+00L, -pS4 = 7.61206183613632558824485341162121989e-01L, -pS5 = -2.56165783329023486777386833928147375e-01L, -pS6 = 4.80718586374448793411019434585413855e-02L, -pS7 = -4.42523267167024279410230886239774718e-03L, -pS8 = 1.44551535183911458253205638280410064e-04L, -pS9 = -2.10558957916600254061591040482706179e-07L, -qS1 = -4.84690167848739751544716485245697428e+00L, -qS2 = 9.96619113536172610135016921140206980e+00L, -qS3 = -1.13177895428973036660836798461641458e+01L, -qS4 = 7.74004374389488266169304117714658761e+00L, -qS5 = -3.25871986053534084709023539900339905e+00L, -qS6 = 8.27830318881232209752469022352928864e-01L, -qS7 = -1.18768052702942805423330715206348004e-01L, -qS8 = 8.32600764660522313269101537926539470e-03L, -qS9 = -1.99407384882605586705979504567947007e-04L; - -const long double pio2_hi = 1.57079632679489661923132169163975140L; -const long double pio2_lo = 4.33590506506189051239852201302167613e-35L; - -long double __invtrigl_R(long double z) -{ - long double p, q; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*(pS5+z*(pS6+z*(pS7+z*(pS8+z*pS9))))))))); - q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*(qS5+z*(qS6+z*(qS7+z*(qS8+z*qS9)))))))); - return p/q; -} -#endif diff --git a/usr/lib/libc/math/__invtrigl.h b/usr/lib/libc/math/__invtrigl.h deleted file mode 100644 index 91a8a3b61..000000000 --- a/usr/lib/libc/math/__invtrigl.h +++ /dev/null @@ -1,6 +0,0 @@ -/* shared by acosl, asinl and atan2l */ -#define pio2_hi __pio2_hi -#define pio2_lo __pio2_lo -extern const long double pio2_hi, pio2_lo; - -long double __invtrigl_R(long double z); diff --git a/usr/lib/libc/math/__polevll.c b/usr/lib/libc/math/__polevll.c deleted file mode 100644 index ce1a84046..000000000 --- a/usr/lib/libc/math/__polevll.c +++ /dev/null @@ -1,93 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/polevll.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Evaluate polynomial - * - * - * SYNOPSIS: - * - * int N; - * long double x, y, coef[N+1], polevl[]; - * - * y = polevll( x, coef, N ); - * - * - * DESCRIPTION: - * - * Evaluates polynomial of degree N: - * - * 2 N - * y = C + C x + C x +...+ C x - * 0 1 2 N - * - * Coefficients are stored in reverse order: - * - * coef[0] = C , ..., coef[N] = C . - * N 0 - * - * The function p1evll() assumes that coef[N] = 1.0 and is - * omitted from the array. Its calling arguments are - * otherwise the same as polevll(). - * - * - * SPEED: - * - * In the interest of speed, there are no checks for out - * of bounds arithmetic. This routine is used by most of - * the functions in the library. Depending on available - * equipment features, the user may wish to rewrite the - * program in microcode or assembly language. - * - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -#else -/* - * Polynomial evaluator: - * P[0] x^n + P[1] x^(n-1) + ... + P[n] - */ -long double __polevll(long double x, const long double *P, int n) -{ - long double y; - - y = *P++; - do { - y = y * x + *P++; - } while (--n); - - return y; -} - -/* - * Polynomial evaluator: - * x^n + P[0] x^(n-1) + P[1] x^(n-2) + ... + P[n] - */ -long double __p1evll(long double x, const long double *P, int n) -{ - long double y; - - n -= 1; - y = x + *P++; - do { - y = y * x + *P++; - } while (--n); - - return y; -} -#endif diff --git a/usr/lib/libc/math/__rem_pio2.c b/usr/lib/libc/math/__rem_pio2.c deleted file mode 100644 index d403f81c7..000000000 --- a/usr/lib/libc/math/__rem_pio2.c +++ /dev/null @@ -1,177 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - * Optimized by Bruce D. Evans. - */ -/* __rem_pio2(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use __rem_pio2_large() for large x - */ - -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif - -/* - * invpio2: 53 bits of 2/pi - * pio2_1: first 33 bit of pi/2 - * pio2_1t: pi/2 - pio2_1 - * pio2_2: second 33 bit of pi/2 - * pio2_2t: pi/2 - (pio2_1+pio2_2) - * pio2_3: third 33 bit of pi/2 - * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) - */ -static const double -toint = 1.5/EPS, -invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ -pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ -pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ -pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ -pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ -pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ -pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ - -/* caller must handle the case when reduction is not needed: |x| ~<= pi/4 */ -int __rem_pio2(double x, double *y) -{ - union {double f; uint64_t i;} u = {x}; - double_t z,w,t,r,fn; - double tx[3],ty[2]; - uint32_t ix; - int sign, n, ex, ey, i; - - sign = u.i>>63; - ix = u.i>>32 & 0x7fffffff; - if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ - if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ - goto medium; /* cancellation -- use medium case */ - if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ - if (!sign) { - z = x - pio2_1; /* one round good to 85 bits */ - y[0] = z - pio2_1t; - y[1] = (z-y[0]) - pio2_1t; - return 1; - } else { - z = x + pio2_1; - y[0] = z + pio2_1t; - y[1] = (z-y[0]) + pio2_1t; - return -1; - } - } else { - if (!sign) { - z = x - 2*pio2_1; - y[0] = z - 2*pio2_1t; - y[1] = (z-y[0]) - 2*pio2_1t; - return 2; - } else { - z = x + 2*pio2_1; - y[0] = z + 2*pio2_1t; - y[1] = (z-y[0]) + 2*pio2_1t; - return -2; - } - } - } - if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ - if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ - if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ - goto medium; - if (!sign) { - z = x - 3*pio2_1; - y[0] = z - 3*pio2_1t; - y[1] = (z-y[0]) - 3*pio2_1t; - return 3; - } else { - z = x + 3*pio2_1; - y[0] = z + 3*pio2_1t; - y[1] = (z-y[0]) + 3*pio2_1t; - return -3; - } - } else { - if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ - goto medium; - if (!sign) { - z = x - 4*pio2_1; - y[0] = z - 4*pio2_1t; - y[1] = (z-y[0]) - 4*pio2_1t; - return 4; - } else { - z = x + 4*pio2_1; - y[0] = z + 4*pio2_1t; - y[1] = (z-y[0]) + 4*pio2_1t; - return -4; - } - } - } - if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ -medium: - /* rint(x/(pi/2)), Assume round-to-nearest. */ - fn = (double_t)x*invpio2 + toint - toint; - n = (int32_t)fn; - r = x - fn*pio2_1; - w = fn*pio2_1t; /* 1st round, good to 85 bits */ - y[0] = r - w; - u.f = y[0]; - ey = u.i>>52 & 0x7ff; - ex = ix>>20; - if (ex - ey > 16) { /* 2nd round, good to 118 bits */ - t = r; - w = fn*pio2_2; - r = t - w; - w = fn*pio2_2t - ((t-r)-w); - y[0] = r - w; - u.f = y[0]; - ey = u.i>>52 & 0x7ff; - if (ex - ey > 49) { /* 3rd round, good to 151 bits, covers all cases */ - t = r; - w = fn*pio2_3; - r = t - w; - w = fn*pio2_3t - ((t-r)-w); - y[0] = r - w; - } - } - y[1] = (r - y[0]) - w; - return n; - } - /* - * all other (large) arguments - */ - if (ix >= 0x7ff00000) { /* x is inf or NaN */ - y[0] = y[1] = x - x; - return 0; - } - /* set z = scalbn(|x|,-ilogb(x)+23) */ - u.f = x; - u.i &= (uint64_t)-1>>12; - u.i |= (uint64_t)(0x3ff + 23)<<52; - z = u.f; - for (i=0; i < 2; i++) { - tx[i] = (double)(int32_t)z; - z = (z-tx[i])*0x1p24; - } - tx[i] = z; - /* skip zero terms, first term is non-zero */ - while (tx[i] == 0.0) - i--; - n = __rem_pio2_large(tx,ty,(int)(ix>>20)-(0x3ff+23),i+1,1); - if (sign) { - y[0] = -ty[0]; - y[1] = -ty[1]; - return -n; - } - y[0] = ty[0]; - y[1] = ty[1]; - return n; -} diff --git a/usr/lib/libc/math/__rem_pio2_large.c b/usr/lib/libc/math/__rem_pio2_large.c deleted file mode 100644 index 958f28c25..000000000 --- a/usr/lib/libc/math/__rem_pio2_large.c +++ /dev/null @@ -1,442 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_rem_pio2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * __rem_pio2_large(x,y,e0,nx,prec) - * double x[],y[]; int e0,nx,prec; - * - * __rem_pio2_large return the last three digits of N with - * y = x - N*pi/2 - * so that |y| < pi/2. - * - * The method is to compute the integer (mod 8) and fraction parts of - * (2/pi)*x without doing the full multiplication. In general we - * skip the part of the product that are known to be a huge integer ( - * more accurately, = 0 mod 8 ). Thus the number of operations are - * independent of the exponent of the input. - * - * (2/pi) is represented by an array of 24-bit integers in ipio2[]. - * - * Input parameters: - * x[] The input value (must be positive) is broken into nx - * pieces of 24-bit integers in double precision format. - * x[i] will be the i-th 24 bit of x. The scaled exponent - * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 - * match x's up to 24 bits. - * - * Example of breaking a double positive z into x[0]+x[1]+x[2]: - * e0 = ilogb(z)-23 - * z = scalbn(z,-e0) - * for i = 0,1,2 - * x[i] = floor(z) - * z = (z-x[i])*2**24 - * - * - * y[] ouput result in an array of double precision numbers. - * The dimension of y[] is: - * 24-bit precision 1 - * 53-bit precision 2 - * 64-bit precision 2 - * 113-bit precision 3 - * The actual value is the sum of them. Thus for 113-bit - * precison, one may have to do something like: - * - * long double t,w,r_head, r_tail; - * t = (long double)y[2] + (long double)y[1]; - * w = (long double)y[0]; - * r_head = t+w; - * r_tail = w - (r_head - t); - * - * e0 The exponent of x[0]. Must be <= 16360 or you need to - * expand the ipio2 table. - * - * nx dimension of x[] - * - * prec an integer indicating the precision: - * 0 24 bits (single) - * 1 53 bits (double) - * 2 64 bits (extended) - * 3 113 bits (quad) - * - * External function: - * double scalbn(), floor(); - * - * - * Here is the description of some local variables: - * - * jk jk+1 is the initial number of terms of ipio2[] needed - * in the computation. The minimum and recommended value - * for jk is 3,4,4,6 for single, double, extended, and quad. - * jk+1 must be 2 larger than you might expect so that our - * recomputation test works. (Up to 24 bits in the integer - * part (the 24 bits of it that we compute) and 23 bits in - * the fraction part may be lost to cancelation before we - * recompute.) - * - * jz local integer variable indicating the number of - * terms of ipio2[] used. - * - * jx nx - 1 - * - * jv index for pointing to the suitable ipio2[] for the - * computation. In general, we want - * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 - * is an integer. Thus - * e0-3-24*jv >= 0 or (e0-3)/24 >= jv - * Hence jv = max(0,(e0-3)/24). - * - * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. - * - * q[] double array with integral value, representing the - * 24-bits chunk of the product of x and 2/pi. - * - * q0 the corresponding exponent of q[0]. Note that the - * exponent for q[i] would be q0-24*i. - * - * PIo2[] double precision array, obtained by cutting pi/2 - * into 24 bits chunks. - * - * f[] ipio2[] in floating point - * - * iq[] integer array by breaking up q[] in 24-bits chunk. - * - * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] - * - * ih integer. If >0 it indicates q[] is >= 0.5, hence - * it also indicates the *sign* of the result. - * - */ -/* - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "libm.h" - -static const int init_jk[] = {3,4,4,6}; /* initial value for jk */ - -/* - * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi - * - * integer array, contains the (24*i)-th to (24*i+23)-th - * bit of 2/pi after binary point. The corresponding - * floating value is - * - * ipio2[i] * 2^(-24(i+1)). - * - * NB: This table must have at least (e0-3)/24 + jk terms. - * For quad precision (e0 <= 16360, jk = 6), this is 686. - */ -static const int32_t ipio2[] = { -0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, -0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, -0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, -0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, -0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, -0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, -0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, -0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, -0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, -0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, -0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, - -#if LDBL_MAX_EXP > 1024 -0x47C419, 0xC367CD, 0xDCE809, 0x2A8359, 0xC4768B, 0x961CA6, -0xDDAF44, 0xD15719, 0x053EA5, 0xFF0705, 0x3F7E33, 0xE832C2, -0xDE4F98, 0x327DBB, 0xC33D26, 0xEF6B1E, 0x5EF89F, 0x3A1F35, -0xCAF27F, 0x1D87F1, 0x21907C, 0x7C246A, 0xFA6ED5, 0x772D30, -0x433B15, 0xC614B5, 0x9D19C3, 0xC2C4AD, 0x414D2C, 0x5D000C, -0x467D86, 0x2D71E3, 0x9AC69B, 0x006233, 0x7CD2B4, 0x97A7B4, -0xD55537, 0xF63ED7, 0x1810A3, 0xFC764D, 0x2A9D64, 0xABD770, -0xF87C63, 0x57B07A, 0xE71517, 0x5649C0, 0xD9D63B, 0x3884A7, -0xCB2324, 0x778AD6, 0x23545A, 0xB91F00, 0x1B0AF1, 0xDFCE19, -0xFF319F, 0x6A1E66, 0x615799, 0x47FBAC, 0xD87F7E, 0xB76522, -0x89E832, 0x60BFE6, 0xCDC4EF, 0x09366C, 0xD43F5D, 0xD7DE16, -0xDE3B58, 0x929BDE, 0x2822D2, 0xE88628, 0x4D58E2, 0x32CAC6, -0x16E308, 0xCB7DE0, 0x50C017, 0xA71DF3, 0x5BE018, 0x34132E, -0x621283, 0x014883, 0x5B8EF5, 0x7FB0AD, 0xF2E91E, 0x434A48, -0xD36710, 0xD8DDAA, 0x425FAE, 0xCE616A, 0xA4280A, 0xB499D3, -0xF2A606, 0x7F775C, 0x83C2A3, 0x883C61, 0x78738A, 0x5A8CAF, -0xBDD76F, 0x63A62D, 0xCBBFF4, 0xEF818D, 0x67C126, 0x45CA55, -0x36D9CA, 0xD2A828, 0x8D61C2, 0x77C912, 0x142604, 0x9B4612, -0xC459C4, 0x44C5C8, 0x91B24D, 0xF31700, 0xAD43D4, 0xE54929, -0x10D5FD, 0xFCBE00, 0xCC941E, 0xEECE70, 0xF53E13, 0x80F1EC, -0xC3E7B3, 0x28F8C7, 0x940593, 0x3E71C1, 0xB3092E, 0xF3450B, -0x9C1288, 0x7B20AB, 0x9FB52E, 0xC29247, 0x2F327B, 0x6D550C, -0x90A772, 0x1FE76B, 0x96CB31, 0x4A1679, 0xE27941, 0x89DFF4, -0x9794E8, 0x84E6E2, 0x973199, 0x6BED88, 0x365F5F, 0x0EFDBB, -0xB49A48, 0x6CA467, 0x427271, 0x325D8D, 0xB8159F, 0x09E5BC, -0x25318D, 0x3974F7, 0x1C0530, 0x010C0D, 0x68084B, 0x58EE2C, -0x90AA47, 0x02E774, 0x24D6BD, 0xA67DF7, 0x72486E, 0xEF169F, -0xA6948E, 0xF691B4, 0x5153D1, 0xF20ACF, 0x339820, 0x7E4BF5, -0x6863B2, 0x5F3EDD, 0x035D40, 0x7F8985, 0x295255, 0xC06437, -0x10D86D, 0x324832, 0x754C5B, 0xD4714E, 0x6E5445, 0xC1090B, -0x69F52A, 0xD56614, 0x9D0727, 0x50045D, 0xDB3BB4, 0xC576EA, -0x17F987, 0x7D6B49, 0xBA271D, 0x296996, 0xACCCC6, 0x5414AD, -0x6AE290, 0x89D988, 0x50722C, 0xBEA404, 0x940777, 0x7030F3, -0x27FC00, 0xA871EA, 0x49C266, 0x3DE064, 0x83DD97, 0x973FA3, -0xFD9443, 0x8C860D, 0xDE4131, 0x9D3992, 0x8C70DD, 0xE7B717, -0x3BDF08, 0x2B3715, 0xA0805C, 0x93805A, 0x921110, 0xD8E80F, -0xAF806C, 0x4BFFDB, 0x0F9038, 0x761859, 0x15A562, 0xBBCB61, -0xB989C7, 0xBD4010, 0x04F2D2, 0x277549, 0xF6B6EB, 0xBB22DB, -0xAA140A, 0x2F2689, 0x768364, 0x333B09, 0x1A940E, 0xAA3A51, -0xC2A31D, 0xAEEDAF, 0x12265C, 0x4DC26D, 0x9C7A2D, 0x9756C0, -0x833F03, 0xF6F009, 0x8C402B, 0x99316D, 0x07B439, 0x15200C, -0x5BC3D8, 0xC492F5, 0x4BADC6, 0xA5CA4E, 0xCD37A7, 0x36A9E6, -0x9492AB, 0x6842DD, 0xDE6319, 0xEF8C76, 0x528B68, 0x37DBFC, -0xABA1AE, 0x3115DF, 0xA1AE00, 0xDAFB0C, 0x664D64, 0xB705ED, -0x306529, 0xBF5657, 0x3AFF47, 0xB9F96A, 0xF3BE75, 0xDF9328, -0x3080AB, 0xF68C66, 0x15CB04, 0x0622FA, 0x1DE4D9, 0xA4B33D, -0x8F1B57, 0x09CD36, 0xE9424E, 0xA4BE13, 0xB52333, 0x1AAAF0, -0xA8654F, 0xA5C1D2, 0x0F3F0B, 0xCD785B, 0x76F923, 0x048B7B, -0x721789, 0x53A6C6, 0xE26E6F, 0x00EBEF, 0x584A9B, 0xB7DAC4, -0xBA66AA, 0xCFCF76, 0x1D02D1, 0x2DF1B1, 0xC1998C, 0x77ADC3, -0xDA4886, 0xA05DF7, 0xF480C6, 0x2FF0AC, 0x9AECDD, 0xBC5C3F, -0x6DDED0, 0x1FC790, 0xB6DB2A, 0x3A25A3, 0x9AAF00, 0x9353AD, -0x0457B6, 0xB42D29, 0x7E804B, 0xA707DA, 0x0EAA76, 0xA1597B, -0x2A1216, 0x2DB7DC, 0xFDE5FA, 0xFEDB89, 0xFDBE89, 0x6C76E4, -0xFCA906, 0x70803E, 0x156E85, 0xFF87FD, 0x073E28, 0x336761, -0x86182A, 0xEABD4D, 0xAFE7B3, 0x6E6D8F, 0x396795, 0x5BBF31, -0x48D784, 0x16DF30, 0x432DC7, 0x356125, 0xCE70C9, 0xB8CB30, -0xFD6CBF, 0xA200A4, 0xE46C05, 0xA0DD5A, 0x476F21, 0xD21262, -0x845CB9, 0x496170, 0xE0566B, 0x015299, 0x375550, 0xB7D51E, -0xC4F133, 0x5F6E13, 0xE4305D, 0xA92E85, 0xC3B21D, 0x3632A1, -0xA4B708, 0xD4B1EA, 0x21F716, 0xE4698F, 0x77FF27, 0x80030C, -0x2D408D, 0xA0CD4F, 0x99A520, 0xD3A2B3, 0x0A5D2F, 0x42F9B4, -0xCBDA11, 0xD0BE7D, 0xC1DB9B, 0xBD17AB, 0x81A2CA, 0x5C6A08, -0x17552E, 0x550027, 0xF0147F, 0x8607E1, 0x640B14, 0x8D4196, -0xDEBE87, 0x2AFDDA, 0xB6256B, 0x34897B, 0xFEF305, 0x9EBFB9, -0x4F6A68, 0xA82A4A, 0x5AC44F, 0xBCF82D, 0x985AD7, 0x95C7F4, -0x8D4D0D, 0xA63A20, 0x5F57A4, 0xB13F14, 0x953880, 0x0120CC, -0x86DD71, 0xB6DEC9, 0xF560BF, 0x11654D, 0x6B0701, 0xACB08C, -0xD0C0B2, 0x485551, 0x0EFB1E, 0xC37295, 0x3B06A3, 0x3540C0, -0x7BDC06, 0xCC45E0, 0xFA294E, 0xC8CAD6, 0x41F3E8, 0xDE647C, -0xD8649B, 0x31BED9, 0xC397A4, 0xD45877, 0xC5E369, 0x13DAF0, -0x3C3ABA, 0x461846, 0x5F7555, 0xF5BDD2, 0xC6926E, 0x5D2EAC, -0xED440E, 0x423E1C, 0x87C461, 0xE9FD29, 0xF3D6E7, 0xCA7C22, -0x35916F, 0xC5E008, 0x8DD7FF, 0xE26A6E, 0xC6FDB0, 0xC10893, -0x745D7C, 0xB2AD6B, 0x9D6ECD, 0x7B723E, 0x6A11C6, 0xA9CFF7, -0xDF7329, 0xBAC9B5, 0x5100B7, 0x0DB2E2, 0x24BA74, 0x607DE5, -0x8AD874, 0x2C150D, 0x0C1881, 0x94667E, 0x162901, 0x767A9F, -0xBEFDFD, 0xEF4556, 0x367ED9, 0x13D9EC, 0xB9BA8B, 0xFC97C4, -0x27A831, 0xC36EF1, 0x36C594, 0x56A8D8, 0xB5A8B4, 0x0ECCCF, -0x2D8912, 0x34576F, 0x89562C, 0xE3CE99, 0xB920D6, 0xAA5E6B, -0x9C2A3E, 0xCC5F11, 0x4A0BFD, 0xFBF4E1, 0x6D3B8E, 0x2C86E2, -0x84D4E9, 0xA9B4FC, 0xD1EEEF, 0xC9352E, 0x61392F, 0x442138, -0xC8D91B, 0x0AFC81, 0x6A4AFB, 0xD81C2F, 0x84B453, 0x8C994E, -0xCC2254, 0xDC552A, 0xD6C6C0, 0x96190B, 0xB8701A, 0x649569, -0x605A26, 0xEE523F, 0x0F117F, 0x11B5F4, 0xF5CBFC, 0x2DBC34, -0xEEBC34, 0xCC5DE8, 0x605EDD, 0x9B8E67, 0xEF3392, 0xB817C9, -0x9B5861, 0xBC57E1, 0xC68351, 0x103ED8, 0x4871DD, 0xDD1C2D, -0xA118AF, 0x462C21, 0xD7F359, 0x987AD9, 0xC0549E, 0xFA864F, -0xFC0656, 0xAE79E5, 0x362289, 0x22AD38, 0xDC9367, 0xAAE855, -0x382682, 0x9BE7CA, 0xA40D51, 0xB13399, 0x0ED7A9, 0x480569, -0xF0B265, 0xA7887F, 0x974C88, 0x36D1F9, 0xB39221, 0x4A827B, -0x21CF98, 0xDC9F40, 0x5547DC, 0x3A74E1, 0x42EB67, 0xDF9DFE, -0x5FD45E, 0xA4677B, 0x7AACBA, 0xA2F655, 0x23882B, 0x55BA41, -0x086E59, 0x862A21, 0x834739, 0xE6E389, 0xD49EE5, 0x40FB49, -0xE956FF, 0xCA0F1C, 0x8A59C5, 0x2BFA94, 0xC5C1D3, 0xCFC50F, -0xAE5ADB, 0x86C547, 0x624385, 0x3B8621, 0x94792C, 0x876110, -0x7B4C2A, 0x1A2C80, 0x12BF43, 0x902688, 0x893C78, 0xE4C4A8, -0x7BDBE5, 0xC23AC4, 0xEAF426, 0x8A67F7, 0xBF920D, 0x2BA365, -0xB1933D, 0x0B7CBD, 0xDC51A4, 0x63DD27, 0xDDE169, 0x19949A, -0x9529A8, 0x28CE68, 0xB4ED09, 0x209F44, 0xCA984E, 0x638270, -0x237C7E, 0x32B90F, 0x8EF5A7, 0xE75614, 0x08F121, 0x2A9DB5, -0x4D7E6F, 0x5119A5, 0xABF9B5, 0xD6DF82, 0x61DD96, 0x023616, -0x9F3AC4, 0xA1A283, 0x6DED72, 0x7A8D39, 0xA9B882, 0x5C326B, -0x5B2746, 0xED3400, 0x7700D2, 0x55F4FC, 0x4D5901, 0x8071E0, -#endif -}; - -static const double PIo2[] = { - 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ - 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ - 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ - 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ - 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ - 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ - 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ - 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ -}; - -int __rem_pio2_large(double *x, double *y, int e0, int nx, int prec) -{ - int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; - double z,fw,f[20],fq[20],q[20]; - - /* initialize jk*/ - jk = init_jk[prec]; - jp = jk; - - /* determine jx,jv,q0, note that 3>q0 */ - jx = nx-1; - jv = (e0-3)/24; if(jv<0) jv=0; - q0 = e0-24*(jv+1); - - /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ - j = jv-jx; m = jx+jk; - for (i=0; i<=m; i++,j++) - f[i] = j<0 ? 0.0 : (double)ipio2[j]; - - /* compute q[0],q[1],...q[jk] */ - for (i=0; i<=jk; i++) { - for (j=0,fw=0.0; j<=jx; j++) - fw += x[j]*f[jx+i-j]; - q[i] = fw; - } - - jz = jk; -recompute: - /* distill q[] into iq[] reversingly */ - for (i=0,j=jz,z=q[jz]; j>0; i++,j--) { - fw = (double)(int32_t)(0x1p-24*z); - iq[i] = (int32_t)(z - 0x1p24*fw); - z = q[j-1]+fw; - } - - /* compute n */ - z = scalbn(z,q0); /* actual value of z */ - z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ - n = (int32_t)z; - z -= (double)n; - ih = 0; - if (q0 > 0) { /* need iq[jz-1] to determine n */ - i = iq[jz-1]>>(24-q0); n += i; - iq[jz-1] -= i<<(24-q0); - ih = iq[jz-1]>>(23-q0); - } - else if (q0 == 0) ih = iq[jz-1]>>23; - else if (z >= 0.5) ih = 2; - - if (ih > 0) { /* q > 0.5 */ - n += 1; carry = 0; - for (i=0; i 0) { /* rare case: chance is 1 in 12 */ - switch(q0) { - case 1: - iq[jz-1] &= 0x7fffff; break; - case 2: - iq[jz-1] &= 0x3fffff; break; - } - } - if (ih == 2) { - z = 1.0 - z; - if (carry != 0) - z -= scalbn(1.0,q0); - } - } - - /* check if recomputation is needed */ - if (z == 0.0) { - j = 0; - for (i=jz-1; i>=jk; i--) j |= iq[i]; - if (j == 0) { /* need recomputation */ - for (k=1; iq[jk-k]==0; k++); /* k = no. of terms needed */ - - for (i=jz+1; i<=jz+k; i++) { /* add q[jz+1] to q[jz+k] */ - f[jx+i] = (double)ipio2[jv+i]; - for (j=0,fw=0.0; j<=jx; j++) - fw += x[j]*f[jx+i-j]; - q[i] = fw; - } - jz += k; - goto recompute; - } - } - - /* chop off zero terms */ - if (z == 0.0) { - jz -= 1; - q0 -= 24; - while (iq[jz] == 0) { - jz--; - q0 -= 24; - } - } else { /* break z into 24-bit if necessary */ - z = scalbn(z,-q0); - if (z >= 0x1p24) { - fw = (double)(int32_t)(0x1p-24*z); - iq[jz] = (int32_t)(z - 0x1p24*fw); - jz += 1; - q0 += 24; - iq[jz] = (int32_t)fw; - } else - iq[jz] = (int32_t)z; - } - - /* convert integer "bit" chunk to floating-point value */ - fw = scalbn(1.0,q0); - for (i=jz; i>=0; i--) { - q[i] = fw*(double)iq[i]; - fw *= 0x1p-24; - } - - /* compute PIo2[0,...,jp]*q[jz,...,0] */ - for(i=jz; i>=0; i--) { - for (fw=0.0,k=0; k<=jp && k<=jz-i; k++) - fw += PIo2[k]*q[i+k]; - fq[jz-i] = fw; - } - - /* compress fq[] into y[] */ - switch(prec) { - case 0: - fw = 0.0; - for (i=jz; i>=0; i--) - fw += fq[i]; - y[0] = ih==0 ? fw : -fw; - break; - case 1: - case 2: - fw = 0.0; - for (i=jz; i>=0; i--) - fw += fq[i]; - // TODO: drop excess precision here once double_t is used - fw = (double)fw; - y[0] = ih==0 ? fw : -fw; - fw = fq[0]-fw; - for (i=1; i<=jz; i++) - fw += fq[i]; - y[1] = ih==0 ? fw : -fw; - break; - case 3: /* painful */ - for (i=jz; i>0; i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (i=jz; i>1; i--) { - fw = fq[i-1]+fq[i]; - fq[i] += fq[i-1]-fw; - fq[i-1] = fw; - } - for (fw=0.0,i=jz; i>=2; i--) - fw += fq[i]; - if (ih==0) { - y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; - } else { - y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; - } - } - return n&7; -} diff --git a/usr/lib/libc/math/__rem_pio2f.c b/usr/lib/libc/math/__rem_pio2f.c deleted file mode 100644 index 4473c1c42..000000000 --- a/usr/lib/libc/math/__rem_pio2f.c +++ /dev/null @@ -1,75 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2f.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Debugged and optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* __rem_pio2f(x,y) - * - * return the remainder of x rem pi/2 in *y - * use double precision for everything except passing x - * use __rem_pio2_large() for large x - */ - -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif - -/* - * invpio2: 53 bits of 2/pi - * pio2_1: first 25 bits of pi/2 - * pio2_1t: pi/2 - pio2_1 - */ -static const double -toint = 1.5/EPS, -invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ -pio2_1 = 1.57079631090164184570e+00, /* 0x3FF921FB, 0x50000000 */ -pio2_1t = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */ - -int __rem_pio2f(float x, double *y) -{ - union {float f; uint32_t i;} u = {x}; - double tx[1],ty[1]; - double_t fn; - uint32_t ix; - int n, sign, e0; - - ix = u.i & 0x7fffffff; - /* 25+53 bit pi is good enough for medium size */ - if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */ - /* Use a specialized rint() to get fn. Assume round-to-nearest. */ - fn = (double_t)x*invpio2 + toint - toint; - n = (int32_t)fn; - *y = x - fn*pio2_1 - fn*pio2_1t; - return n; - } - if(ix>=0x7f800000) { /* x is inf or NaN */ - *y = x-x; - return 0; - } - /* scale x into [2^23, 2^24-1] */ - sign = u.i>>31; - e0 = (ix>>23) - (0x7f+23); /* e0 = ilogb(|x|)-23, positive */ - u.i = ix - (e0<<23); - tx[0] = u.f; - n = __rem_pio2_large(tx,ty,e0,1,0); - if (sign) { - *y = -ty[0]; - return -n; - } - *y = ty[0]; - return n; -} diff --git a/usr/lib/libc/math/__rem_pio2l.c b/usr/lib/libc/math/__rem_pio2l.c deleted file mode 100644 index 77255bd80..000000000 --- a/usr/lib/libc/math/__rem_pio2l.c +++ /dev/null @@ -1,141 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/ld80/e_rem_pio2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - * Optimized by Bruce D. Evans. - */ -#include "libm.h" -#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -/* ld80 and ld128 version of __rem_pio2(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use __rem_pio2_large() for large x - */ - -static const long double toint = 1.5/LDBL_EPSILON; - -#if LDBL_MANT_DIG == 64 -/* u ~< 0x1p25*pi/2 */ -#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < ((0x3fff + 25)<<16 | 0x921f>>1 | 0x8000)) -#define QUOBITS(x) ((uint32_t)(int32_t)x & 0x7fffffff) -#define ROUND1 22 -#define ROUND2 61 -#define NX 3 -#define NY 2 -/* - * invpio2: 64 bits of 2/pi - * pio2_1: first 39 bits of pi/2 - * pio2_1t: pi/2 - pio2_1 - * pio2_2: second 39 bits of pi/2 - * pio2_2t: pi/2 - (pio2_1+pio2_2) - * pio2_3: third 39 bits of pi/2 - * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) - */ -static const double -pio2_1 = 1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */ -pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */ -pio2_3 = 6.36831716351370313614e-25; /* 0x18a2e037074000.0p-133 */ -static const long double -invpio2 = 6.36619772367581343076e-01L, /* 0xa2f9836e4e44152a.0p-64 */ -pio2_1t = -1.07463465549719416346e-12L, /* -0x973dcb3b399d747f.0p-103 */ -pio2_2t = 6.36831716351095013979e-25L, /* 0xc51701b839a25205.0p-144 */ -pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */ -#elif LDBL_MANT_DIG == 113 -/* u ~< 0x1p45*pi/2 */ -#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.top) < ((0x3fff + 45)<<16 | 0x921f)) -#define QUOBITS(x) ((uint32_t)(int64_t)x & 0x7fffffff) -#define ROUND1 51 -#define ROUND2 119 -#define NX 5 -#define NY 3 -static const long double -invpio2 = 6.3661977236758134307553505349005747e-01L, /* 0x145f306dc9c882a53f84eafa3ea6a.0p-113 */ -pio2_1 = 1.5707963267948966192292994253909555e+00L, /* 0x1921fb54442d18469800000000000.0p-112 */ -pio2_1t = 2.0222662487959507323996846200947577e-21L, /* 0x13198a2e03707344a4093822299f3.0p-181 */ -pio2_2 = 2.0222662487959507323994779168837751e-21L, /* 0x13198a2e03707344a400000000000.0p-181 */ -pio2_2t = 2.0670321098263988236496903051604844e-43L, /* 0x127044533e63a0105df531d89cd91.0p-254 */ -pio2_3 = 2.0670321098263988236499468110329591e-43L, /* 0x127044533e63a0105e00000000000.0p-254 */ -pio2_3t = -2.5650587247459238361625433492959285e-65L; /* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */ -#endif - -int __rem_pio2l(long double x, long double *y) -{ - union ldshape u,uz; - long double z,w,t,r,fn; - double tx[NX],ty[NY]; - int ex,ey,n,i; - - u.f = x; - ex = u.i.se & 0x7fff; - if (SMALL(u)) { - /* rint(x/(pi/2)), Assume round-to-nearest. */ - fn = x*invpio2 + toint - toint; - n = QUOBITS(fn); - r = x-fn*pio2_1; - w = fn*pio2_1t; /* 1st round good to 102/180 bits (ld80/ld128) */ - y[0] = r-w; - u.f = y[0]; - ey = u.i.se & 0x7fff; - if (ex - ey > ROUND1) { /* 2nd iteration needed, good to 141/248 (ld80/ld128) */ - t = r; - w = fn*pio2_2; - r = t-w; - w = fn*pio2_2t-((t-r)-w); - y[0] = r-w; - u.f = y[0]; - ey = u.i.se & 0x7fff; - if (ex - ey > ROUND2) { /* 3rd iteration, good to 180/316 bits */ - t = r; /* will cover all possible cases (not verified for ld128) */ - w = fn*pio2_3; - r = t-w; - w = fn*pio2_3t-((t-r)-w); - y[0] = r-w; - } - } - y[1] = (r - y[0]) - w; - return n; - } - /* - * all other (large) arguments - */ - if (ex == 0x7fff) { /* x is inf or NaN */ - y[0] = y[1] = x - x; - return 0; - } - /* set z = scalbn(|x|,-ilogb(x)+23) */ - uz.f = x; - uz.i.se = 0x3fff + 23; - z = uz.f; - for (i=0; i < NX - 1; i++) { - tx[i] = (double)(int32_t)z; - z = (z-tx[i])*0x1p24; - } - tx[i] = z; - while (tx[i] == 0) - i--; - n = __rem_pio2_large(tx, ty, ex-0x3fff-23, i+1, NY); - w = ty[1]; - if (NY == 3) - w += ty[2]; - r = ty[0] + w; - /* TODO: for ld128 this does not follow the recommendation of the - comments of __rem_pio2_large which seem wrong if |ty[0]| > |ty[1]+ty[2]| */ - w -= r - ty[0]; - if (u.i.se >> 15) { - y[0] = -r; - y[1] = -w; - return -n; - } - y[0] = r; - y[1] = w; - return n; -} -#endif diff --git a/usr/lib/libc/math/__signbit.c b/usr/lib/libc/math/__signbit.c deleted file mode 100644 index e700b6b75..000000000 --- a/usr/lib/libc/math/__signbit.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "libm.h" - -// FIXME: macro in math.h -int __signbit(double x) -{ - union { - double d; - uint64_t i; - } y = { x }; - return y.i>>63; -} - - diff --git a/usr/lib/libc/math/__signbitf.c b/usr/lib/libc/math/__signbitf.c deleted file mode 100644 index 40ad3cfd0..000000000 --- a/usr/lib/libc/math/__signbitf.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "libm.h" - -// FIXME: macro in math.h -int __signbitf(float x) -{ - union { - float f; - uint32_t i; - } y = { x }; - return y.i>>31; -} diff --git a/usr/lib/libc/math/__signbitl.c b/usr/lib/libc/math/__signbitl.c deleted file mode 100644 index 63b3dc5a0..000000000 --- a/usr/lib/libc/math/__signbitl.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "libm.h" - -#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -int __signbitl(long double x) -{ - union ldshape u = {x}; - return u.i.se >> 15; -} -#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -int __signbitl(long double x) -{ - return __signbit(x); -} -#endif diff --git a/usr/lib/libc/math/__sin.c b/usr/lib/libc/math/__sin.c deleted file mode 100644 index 403094966..000000000 --- a/usr/lib/libc/math/__sin.c +++ /dev/null @@ -1,64 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_sin.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* __sin( x, y, iy) - * kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). - * - * Algorithm - * 1. Since sin(-x) = -sin(x), we need only to consider positive x. - * 2. Callers must return sin(-0) = -0 without calling here since our - * odd polynomial is not evaluated in a way that preserves -0. - * Callers may do the optimization sin(x) ~ x for tiny x. - * 3. sin(x) is approximated by a polynomial of degree 13 on - * [0,pi/4] - * 3 13 - * sin(x) ~ x + S1*x + ... + S6*x - * where - * - * |sin(x) 2 4 6 8 10 12 | -58 - * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 - * | x | - * - * 4. sin(x+y) = sin(x) + sin'(x')*y - * ~ sin(x) + (1-x*x/2)*y - * For better accuracy, let - * 3 2 2 2 2 - * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) - * then 3 2 - * sin(x) = x + (S1*x + (x *(r-y/2)+y)) - */ - -#include "libm.h" - -static const double -S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ -S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ -S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ -S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ -S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ -S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ - -double __sin(double x, double y, int iy) -{ - double_t z,r,v,w; - - z = x*x; - w = z*z; - r = S2 + z*(S3 + z*S4) + z*w*(S5 + z*S6); - v = z*x; - if (iy == 0) - return x + v*(S1 + z*r); - else - return x - ((z*(0.5*y - v*r) - y) - v*S1); -} diff --git a/usr/lib/libc/math/__sindf.c b/usr/lib/libc/math/__sindf.c deleted file mode 100644 index 8fec2a3f6..000000000 --- a/usr/lib/libc/math/__sindf.c +++ /dev/null @@ -1,36 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_sinf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -/* |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]). */ -static const double -S1 = -0x15555554cbac77.0p-55, /* -0.166666666416265235595 */ -S2 = 0x111110896efbb2.0p-59, /* 0.0083333293858894631756 */ -S3 = -0x1a00f9e2cae774.0p-65, /* -0.000198393348360966317347 */ -S4 = 0x16cd878c3b46a7.0p-71; /* 0.0000027183114939898219064 */ - -float __sindf(double x) -{ - double_t r, s, w, z; - - /* Try to optimize for parallel evaluation as in __tandf.c. */ - z = x*x; - w = z*z; - r = S3 + z*S4; - s = z*x; - return (x + s*(S1 + z*S2)) + s*w*r; -} diff --git a/usr/lib/libc/math/__sinl.c b/usr/lib/libc/math/__sinl.c deleted file mode 100644 index 2525bbe86..000000000 --- a/usr/lib/libc/math/__sinl.c +++ /dev/null @@ -1,78 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/ld80/k_sinl.c */ -/* origin: FreeBSD /usr/src/lib/msun/ld128/k_sinl.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#if LDBL_MANT_DIG == 64 -/* - * ld80 version of __sin.c. See __sin.c for most comments. - */ -/* - * Domain [-0.7854, 0.7854], range ~[-1.89e-22, 1.915e-22] - * |sin(x)/x - s(x)| < 2**-72.1 - * - * See __cosl.c for more details about the polynomial. - */ -static const long double -S1 = -0.166666666666666666671L; /* -0xaaaaaaaaaaaaaaab.0p-66 */ -static const double -S2 = 0.0083333333333333332, /* 0x11111111111111.0p-59 */ -S3 = -0.00019841269841269427, /* -0x1a01a01a019f81.0p-65 */ -S4 = 0.0000027557319223597490, /* 0x171de3a55560f7.0p-71 */ -S5 = -0.000000025052108218074604, /* -0x1ae64564f16cad.0p-78 */ -S6 = 1.6059006598854211e-10, /* 0x161242b90243b5.0p-85 */ -S7 = -7.6429779983024564e-13, /* -0x1ae42ebd1b2e00.0p-93 */ -S8 = 2.6174587166648325e-15; /* 0x179372ea0b3f64.0p-101 */ -#define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8)))))) -#elif LDBL_MANT_DIG == 113 -/* - * ld128 version of __sin.c. See __sin.c for most comments. - */ -/* - * Domain [-0.7854, 0.7854], range ~[-1.53e-37, 1.659e-37] - * |sin(x)/x - s(x)| < 2**-122.1 - * - * See __cosl.c for more details about the polynomial. - */ -static const long double -S1 = -0.16666666666666666666666666666666666606732416116558L, -S2 = 0.0083333333333333333333333333333331135404851288270047L, -S3 = -0.00019841269841269841269841269839935785325638310428717L, -S4 = 0.27557319223985890652557316053039946268333231205686e-5L, -S5 = -0.25052108385441718775048214826384312253862930064745e-7L, -S6 = 0.16059043836821614596571832194524392581082444805729e-9L, -S7 = -0.76471637318198151807063387954939213287488216303768e-12L, -S8 = 0.28114572543451292625024967174638477283187397621303e-14L; -static const double -S9 = -0.82206352458348947812512122163446202498005154296863e-17, -S10 = 0.19572940011906109418080609928334380560135358385256e-19, -S11 = -0.38680813379701966970673724299207480965452616911420e-22, -S12 = 0.64038150078671872796678569586315881020659912139412e-25; -#define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*(S8+ \ - z*(S9+z*(S10+z*(S11+z*S12)))))))))) -#endif - -long double __sinl(long double x, long double y, int iy) -{ - long double z,r,v; - - z = x*x; - v = z*x; - r = POLY(z); - if (iy == 0) - return x+v*(S1+z*r); - return x-((z*(0.5*y-v*r)-y)-v*S1); -} -#endif diff --git a/usr/lib/libc/math/__tan.c b/usr/lib/libc/math/__tan.c deleted file mode 100644 index 8019844d3..000000000 --- a/usr/lib/libc/math/__tan.c +++ /dev/null @@ -1,110 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_tan.c */ -/* - * ==================================================== - * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* __tan( x, y, k ) - * kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 - * Input x is assumed to be bounded by ~pi/4 in magnitude. - * Input y is the tail of x. - * Input odd indicates whether tan (if odd = 0) or -1/tan (if odd = 1) is returned. - * - * Algorithm - * 1. Since tan(-x) = -tan(x), we need only to consider positive x. - * 2. Callers must return tan(-0) = -0 without calling here since our - * odd polynomial is not evaluated in a way that preserves -0. - * Callers may do the optimization tan(x) ~ x for tiny x. - * 3. tan(x) is approximated by a odd polynomial of degree 27 on - * [0,0.67434] - * 3 27 - * tan(x) ~ x + T1*x + ... + T13*x - * where - * - * |tan(x) 2 4 26 | -59.2 - * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2 - * | x | - * - * Note: tan(x+y) = tan(x) + tan'(x)*y - * ~ tan(x) + (1+x*x)*y - * Therefore, for better accuracy in computing tan(x+y), let - * 3 2 2 2 2 - * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13)))) - * then - * 3 2 - * tan(x+y) = x + (T1*x + (x *(r+y)+y)) - * - * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then - * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) - * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) - */ - -#include "libm.h" - -static const double T[] = { - 3.33333333333334091986e-01, /* 3FD55555, 55555563 */ - 1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */ - 5.39682539762260521377e-02, /* 3FABA1BA, 1BB341FE */ - 2.18694882948595424599e-02, /* 3F9664F4, 8406D637 */ - 8.86323982359930005737e-03, /* 3F8226E3, E96E8493 */ - 3.59207910759131235356e-03, /* 3F6D6D22, C9560328 */ - 1.45620945432529025516e-03, /* 3F57DBC8, FEE08315 */ - 5.88041240820264096874e-04, /* 3F4344D8, F2F26501 */ - 2.46463134818469906812e-04, /* 3F3026F7, 1A8D1068 */ - 7.81794442939557092300e-05, /* 3F147E88, A03792A6 */ - 7.14072491382608190305e-05, /* 3F12B80F, 32F0A7E9 */ - -1.85586374855275456654e-05, /* BEF375CB, DB605373 */ - 2.59073051863633712884e-05, /* 3EFB2A70, 74BF7AD4 */ -}, -pio4 = 7.85398163397448278999e-01, /* 3FE921FB, 54442D18 */ -pio4lo = 3.06161699786838301793e-17; /* 3C81A626, 33145C07 */ - -double __tan(double x, double y, int odd) -{ - double_t z, r, v, w, s, a; - double w0, a0; - uint32_t hx; - int big, sign; - - GET_HIGH_WORD(hx,x); - big = (hx&0x7fffffff) >= 0x3FE59428; /* |x| >= 0.6744 */ - if (big) { - sign = hx>>31; - if (sign) { - x = -x; - y = -y; - } - x = (pio4 - x) + (pio4lo - y); - y = 0.0; - } - z = x * x; - w = z * z; - /* - * Break x^5*(T[1]+x^2*T[2]+...) into - * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + - * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) - */ - r = T[1] + w*(T[3] + w*(T[5] + w*(T[7] + w*(T[9] + w*T[11])))); - v = z*(T[2] + w*(T[4] + w*(T[6] + w*(T[8] + w*(T[10] + w*T[12]))))); - s = z * x; - r = y + z*(s*(r + v) + y) + s*T[0]; - w = x + r; - if (big) { - s = 1 - 2*odd; - v = s - 2.0 * (x + (r - w*w/(w + s))); - return sign ? -v : v; - } - if (!odd) - return w; - /* -1.0/(x+r) has up to 2ulp error, so compute it accurately */ - w0 = w; - SET_LOW_WORD(w0, 0); - v = r - (w0 - x); /* w0+v = r+x */ - a0 = a = -1.0 / w; - SET_LOW_WORD(a0, 0); - return a0 + a*(1.0 + a0*w0 + a0*v); -} diff --git a/usr/lib/libc/math/__tandf.c b/usr/lib/libc/math/__tandf.c deleted file mode 100644 index 25047eeee..000000000 --- a/usr/lib/libc/math/__tandf.c +++ /dev/null @@ -1,54 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/k_tanf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -/* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */ -static const double T[] = { - 0x15554d3418c99f.0p-54, /* 0.333331395030791399758 */ - 0x1112fd38999f72.0p-55, /* 0.133392002712976742718 */ - 0x1b54c91d865afe.0p-57, /* 0.0533812378445670393523 */ - 0x191df3908c33ce.0p-58, /* 0.0245283181166547278873 */ - 0x185dadfcecf44e.0p-61, /* 0.00297435743359967304927 */ - 0x1362b9bf971bcd.0p-59, /* 0.00946564784943673166728 */ -}; - -float __tandf(double x, int odd) -{ - double_t z,r,w,s,t,u; - - z = x*x; - /* - * Split up the polynomial into small independent terms to give - * opportunities for parallel evaluation. The chosen splitting is - * micro-optimized for Athlons (XP, X64). It costs 2 multiplications - * relative to Horner's method on sequential machines. - * - * We add the small terms from lowest degree up for efficiency on - * non-sequential machines (the lowest degree terms tend to be ready - * earlier). Apart from this, we don't care about order of - * operations, and don't need to to care since we have precision to - * spare. However, the chosen splitting is good for accuracy too, - * and would give results as accurate as Horner's method if the - * small terms were added from highest degree down. - */ - r = T[4] + z*T[5]; - t = T[2] + z*T[3]; - w = z*z; - s = z*x; - u = T[0] + z*T[1]; - r = (x + s*u) + (s*w)*(t + w*r); - return odd ? -1.0/r : r; -} diff --git a/usr/lib/libc/math/__tanl.c b/usr/lib/libc/math/__tanl.c deleted file mode 100644 index 54abc3daf..000000000 --- a/usr/lib/libc/math/__tanl.c +++ /dev/null @@ -1,143 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/ld80/k_tanl.c */ -/* origin: FreeBSD /usr/src/lib/msun/ld128/k_tanl.c */ -/* - * ==================================================== - * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. - * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#if LDBL_MANT_DIG == 64 -/* - * ld80 version of __tan.c. See __tan.c for most comments. - */ -/* - * Domain [-0.67434, 0.67434], range ~[-2.25e-22, 1.921e-22] - * |tan(x)/x - t(x)| < 2**-71.9 - * - * See __cosl.c for more details about the polynomial. - */ -static const long double -T3 = 0.333333333333333333180L, /* 0xaaaaaaaaaaaaaaa5.0p-65 */ -T5 = 0.133333333333333372290L, /* 0x88888888888893c3.0p-66 */ -T7 = 0.0539682539682504975744L, /* 0xdd0dd0dd0dc13ba2.0p-68 */ -pio4 = 0.785398163397448309628L, /* 0xc90fdaa22168c235.0p-64 */ -pio4lo = -1.25413940316708300586e-20L; /* -0xece675d1fc8f8cbb.0p-130 */ -static const double -T9 = 0.021869488536312216, /* 0x1664f4882cc1c2.0p-58 */ -T11 = 0.0088632355256619590, /* 0x1226e355c17612.0p-59 */ -T13 = 0.0035921281113786528, /* 0x1d6d3d185d7ff8.0p-61 */ -T15 = 0.0014558334756312418, /* 0x17da354aa3f96b.0p-62 */ -T17 = 0.00059003538700862256, /* 0x13559358685b83.0p-63 */ -T19 = 0.00023907843576635544, /* 0x1f56242026b5be.0p-65 */ -T21 = 0.000097154625656538905, /* 0x1977efc26806f4.0p-66 */ -T23 = 0.000038440165747303162, /* 0x14275a09b3ceac.0p-67 */ -T25 = 0.000018082171885432524, /* 0x12f5e563e5487e.0p-68 */ -T27 = 0.0000024196006108814377, /* 0x144c0d80cc6896.0p-71 */ -T29 = 0.0000078293456938132840, /* 0x106b59141a6cb3.0p-69 */ -T31 = -0.0000032609076735050182, /* -0x1b5abef3ba4b59.0p-71 */ -T33 = 0.0000023261313142559411; /* 0x13835436c0c87f.0p-71 */ -#define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \ - w * (T25 + w * (T29 + w * T33))))))) -#define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \ - w * (T27 + w * T31)))))) -#elif LDBL_MANT_DIG == 113 -/* - * ld128 version of __tan.c. See __tan.c for most comments. - */ -/* - * Domain [-0.67434, 0.67434], range ~[-3.37e-36, 1.982e-37] - * |tan(x)/x - t(x)| < 2**-117.8 (XXX should be ~1e-37) - * - * See __cosl.c for more details about the polynomial. - */ -static const long double -T3 = 0x1.5555555555555555555555555553p-2L, -T5 = 0x1.1111111111111111111111111eb5p-3L, -T7 = 0x1.ba1ba1ba1ba1ba1ba1ba1b694cd6p-5L, -T9 = 0x1.664f4882c10f9f32d6bbe09d8bcdp-6L, -T11 = 0x1.226e355e6c23c8f5b4f5762322eep-7L, -T13 = 0x1.d6d3d0e157ddfb5fed8e84e27b37p-9L, -T15 = 0x1.7da36452b75e2b5fce9ee7c2c92ep-10L, -T17 = 0x1.355824803674477dfcf726649efep-11L, -T19 = 0x1.f57d7734d1656e0aceb716f614c2p-13L, -T21 = 0x1.967e18afcb180ed942dfdc518d6cp-14L, -T23 = 0x1.497d8eea21e95bc7e2aa79b9f2cdp-15L, -T25 = 0x1.0b132d39f055c81be49eff7afd50p-16L, -T27 = 0x1.b0f72d33eff7bfa2fbc1059d90b6p-18L, -T29 = 0x1.5ef2daf21d1113df38d0fbc00267p-19L, -T31 = 0x1.1c77d6eac0234988cdaa04c96626p-20L, -T33 = 0x1.cd2a5a292b180e0bdd701057dfe3p-22L, -T35 = 0x1.75c7357d0298c01a31d0a6f7d518p-23L, -T37 = 0x1.2f3190f4718a9a520f98f50081fcp-24L, -pio4 = 0x1.921fb54442d18469898cc51701b8p-1L, -pio4lo = 0x1.cd129024e088a67cc74020bbea60p-116L; -static const double -T39 = 0.000000028443389121318352, /* 0x1e8a7592977938.0p-78 */ -T41 = 0.000000011981013102001973, /* 0x19baa1b1223219.0p-79 */ -T43 = 0.0000000038303578044958070, /* 0x107385dfb24529.0p-80 */ -T45 = 0.0000000034664378216909893, /* 0x1dc6c702a05262.0p-81 */ -T47 = -0.0000000015090641701997785, /* -0x19ecef3569ebb6.0p-82 */ -T49 = 0.0000000029449552300483952, /* 0x194c0668da786a.0p-81 */ -T51 = -0.0000000022006995706097711, /* -0x12e763b8845268.0p-81 */ -T53 = 0.0000000015468200913196612, /* 0x1a92fc98c29554.0p-82 */ -T55 = -0.00000000061311613386849674, /* -0x151106cbc779a9.0p-83 */ -T57 = 1.4912469681508012e-10; /* 0x147edbdba6f43a.0p-85 */ -#define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \ - w * (T25 + w * (T29 + w * (T33 + w * (T37 + w * (T41 + \ - w * (T45 + w * (T49 + w * (T53 + w * T57))))))))))))) -#define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \ - w * (T27 + w * (T31 + w * (T35 + w * (T39 + w * (T43 + \ - w * (T47 + w * (T51 + w * T55)))))))))))) -#endif - -long double __tanl(long double x, long double y, int odd) { - long double z, r, v, w, s, a, t; - int big, sign; - - big = fabsl(x) >= 0.67434; - if (big) { - sign = 0; - if (x < 0) { - sign = 1; - x = -x; - y = -y; - } - x = (pio4 - x) + (pio4lo - y); - y = 0.0; - } - z = x * x; - w = z * z; - r = RPOLY(w); - v = z * VPOLY(w); - s = z * x; - r = y + z * (s * (r + v) + y) + T3 * s; - w = x + r; - if (big) { - s = 1 - 2*odd; - v = s - 2.0 * (x + (r - w * w / (w + s))); - return sign ? -v : v; - } - if (!odd) - return w; - /* - * if allow error up to 2 ulp, simply return - * -1.0 / (x+r) here - */ - /* compute -1.0 / (x+r) accurately */ - z = w; - z = z + 0x1p32 - 0x1p32; - v = r - (z - x); /* z+v = r+x */ - t = a = -1.0 / w; /* a = -1.0/w */ - t = t + 0x1p32 - 0x1p32; - s = 1.0 + t * z; - return t + a * (s + t * v); -} -#endif diff --git a/usr/lib/libc/math/acos.c b/usr/lib/libc/math/acos.c deleted file mode 100644 index ea9c87bf0..000000000 --- a/usr/lib/libc/math/acos.c +++ /dev/null @@ -1,101 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_acos.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* acos(x) - * Method : - * acos(x) = pi/2 - asin(x) - * acos(-x) = pi/2 + asin(x) - * For |x|<=0.5 - * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) - * For x>0.5 - * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) - * = 2asin(sqrt((1-x)/2)) - * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) - * = 2f + (2c + 2s*z*R(z)) - * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term - * for f so that f+c ~ sqrt(z). - * For x<-0.5 - * acos(x) = pi - 2asin(sqrt((1-|x|)/2)) - * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z) - * - * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. - * - * Function needed: sqrt - */ - -#include "libm.h" - -static const double -pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ -pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ -pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ -pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ -pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ -pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ -pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ -pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ -qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ -qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ -qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ -qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ - -static double R(double z) -{ - double_t p, q; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - return p/q; -} - -double acos(double x) -{ - double z,w,s,c,df; - uint32_t hx,ix; - - GET_HIGH_WORD(hx, x); - ix = hx & 0x7fffffff; - /* |x| >= 1 or nan */ - if (ix >= 0x3ff00000) { - uint32_t lx; - - GET_LOW_WORD(lx,x); - if ((ix-0x3ff00000 | lx) == 0) { - /* acos(1)=0, acos(-1)=pi */ - if (hx >> 31) - return 2*pio2_hi + 0x1p-120f; - return 0; - } - return 0/(x-x); - } - /* |x| < 0.5 */ - if (ix < 0x3fe00000) { - if (ix <= 0x3c600000) /* |x| < 2**-57 */ - return pio2_hi + 0x1p-120f; - return pio2_hi - (x - (pio2_lo-x*R(x*x))); - } - /* x < -0.5 */ - if (hx >> 31) { - z = (1.0+x)*0.5; - s = sqrt(z); - w = R(z)*s-pio2_lo; - return 2*(pio2_hi - (s+w)); - } - /* x > 0.5 */ - z = (1.0-x)*0.5; - s = sqrt(z); - df = s; - SET_LOW_WORD(df,0); - c = (z-df*df)/(s+df); - w = R(z)*s+c; - return 2*(df+w); -} diff --git a/usr/lib/libc/math/acosf.c b/usr/lib/libc/math/acosf.c deleted file mode 100644 index 8ee1a71d0..000000000 --- a/usr/lib/libc/math/acosf.c +++ /dev/null @@ -1,71 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_acosf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float -pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ -pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ -pS0 = 1.6666586697e-01, -pS1 = -4.2743422091e-02, -pS2 = -8.6563630030e-03, -qS1 = -7.0662963390e-01; - -static float R(float z) -{ - float_t p, q; - p = z*(pS0+z*(pS1+z*pS2)); - q = 1.0f+z*qS1; - return p/q; -} - -float acosf(float x) -{ - float z,w,s,c,df; - uint32_t hx,ix; - - GET_FLOAT_WORD(hx, x); - ix = hx & 0x7fffffff; - /* |x| >= 1 or nan */ - if (ix >= 0x3f800000) { - if (ix == 0x3f800000) { - if (hx >> 31) - return 2*pio2_hi + 0x1p-120f; - return 0; - } - return 0/(x-x); - } - /* |x| < 0.5 */ - if (ix < 0x3f000000) { - if (ix <= 0x32800000) /* |x| < 2**-26 */ - return pio2_hi + 0x1p-120f; - return pio2_hi - (x - (pio2_lo-x*R(x*x))); - } - /* x < -0.5 */ - if (hx >> 31) { - z = (1+x)*0.5f; - s = sqrtf(z); - w = R(z)*s-pio2_lo; - return 2*(pio2_hi - (s+w)); - } - /* x > 0.5 */ - z = (1-x)*0.5f; - s = sqrtf(z); - GET_FLOAT_WORD(hx,s); - SET_FLOAT_WORD(df,hx&0xfffff000); - c = (z-df*df)/(s+df); - w = R(z)*s+c; - return 2*(df+w); -} diff --git a/usr/lib/libc/math/acosh.c b/usr/lib/libc/math/acosh.c deleted file mode 100644 index badbf9081..000000000 --- a/usr/lib/libc/math/acosh.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==2 -#undef sqrt -#define sqrt sqrtl -#endif - -/* acosh(x) = log(x + sqrt(x*x-1)) */ -double acosh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - unsigned e = u.i >> 52 & 0x7ff; - - /* x < 1 domain error is handled in the called functions */ - - if (e < 0x3ff + 1) - /* |x| < 2, up to 2ulp error in [1,1.125] */ - return log1p(x-1 + sqrt((x-1)*(x-1)+2*(x-1))); - if (e < 0x3ff + 26) - /* |x| < 0x1p26 */ - return log(2*x - 1/(x+sqrt(x*x-1))); - /* |x| >= 0x1p26 or nan */ - return log(x) + 0.693147180559945309417232121458176568; -} diff --git a/usr/lib/libc/math/acoshf.c b/usr/lib/libc/math/acoshf.c deleted file mode 100644 index 8a4ec4d57..000000000 --- a/usr/lib/libc/math/acoshf.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==2 -#undef sqrtf -#define sqrtf sqrtl -#elif FLT_EVAL_METHOD==1 -#undef sqrtf -#define sqrtf sqrt -#endif - -/* acosh(x) = log(x + sqrt(x*x-1)) */ -float acoshf(float x) -{ - union {float f; uint32_t i;} u = {x}; - uint32_t a = u.i & 0x7fffffff; - - if (a < 0x3f800000+(1<<23)) - /* |x| < 2, invalid if x < 1 or nan */ - /* up to 2ulp error in [1,1.125] */ - return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1))); - if (a < 0x3f800000+(12<<23)) - /* |x| < 0x1p12 */ - return logf(2*x - 1/(x+sqrtf(x*x-1))); - /* x >= 0x1p12 */ - return logf(x) + 0.693147180559945309417232121458176568f; -} diff --git a/usr/lib/libc/math/acoshl.c b/usr/lib/libc/math/acoshl.c deleted file mode 100644 index 8d4b43f64..000000000 --- a/usr/lib/libc/math/acoshl.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double acoshl(long double x) -{ - return acosh(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* acosh(x) = log(x + sqrt(x*x-1)) */ -long double acoshl(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - - if (e < 0x3fff + 1) - /* |x| < 2, invalid if x < 1 or nan */ - return log1pl(x-1 + sqrtl((x-1)*(x-1)+2*(x-1))); - if (e < 0x3fff + 32) - /* |x| < 0x1p32 */ - return logl(2*x - 1/(x+sqrtl(x*x-1))); - return logl(x) + 0.693147180559945309417232121458176568L; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double acoshl(long double x) -{ - return acosh(x); -} -#endif diff --git a/usr/lib/libc/math/acosl.c b/usr/lib/libc/math/acosl.c deleted file mode 100644 index c03bdf023..000000000 --- a/usr/lib/libc/math/acosl.c +++ /dev/null @@ -1,67 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_acosl.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in acos.c. - * Converted to long double by David Schultz . - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double acosl(long double x) -{ - return acos(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#include "__invtrigl.h" -#if LDBL_MANT_DIG == 64 -#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32) -#elif LDBL_MANT_DIG == 113 -#define CLEARBOTTOM(u) (u.i.lo = 0) -#endif - -long double acosl(long double x) -{ - union ldshape u = {x}; - long double z, s, c, f; - uint16_t e = u.i.se & 0x7fff; - - /* |x| >= 1 or nan */ - if (e >= 0x3fff) { - if (x == 1) - return 0; - if (x == -1) - return 2*pio2_hi + 0x1p-120f; - return 0/(x-x); - } - /* |x| < 0.5 */ - if (e < 0x3fff - 1) { - if (e < 0x3fff - LDBL_MANT_DIG - 1) - return pio2_hi + 0x1p-120f; - return pio2_hi - (__invtrigl_R(x*x)*x - pio2_lo + x); - } - /* x < -0.5 */ - if (u.i.se >> 15) { - z = (1 + x)*0.5; - s = sqrtl(z); - return 2*(pio2_hi - (__invtrigl_R(z)*s - pio2_lo + s)); - } - /* x > 0.5 */ - z = (1 - x)*0.5; - s = sqrtl(z); - u.f = s; - CLEARBOTTOM(u); - f = u.f; - c = (z - f*f)/(s + f); - return 2*(__invtrigl_R(z)*s + c + f); -} -#endif diff --git a/usr/lib/libc/math/asin.c b/usr/lib/libc/math/asin.c deleted file mode 100644 index c926b1885..000000000 --- a/usr/lib/libc/math/asin.c +++ /dev/null @@ -1,107 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_asin.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* asin(x) - * Method : - * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... - * we approximate asin(x) on [0,0.5] by - * asin(x) = x + x*x^2*R(x^2) - * where - * R(x^2) is a rational approximation of (asin(x)-x)/x^3 - * and its remez error is bounded by - * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75) - * - * For x in [0.5,1] - * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) - * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2; - * then for x>0.98 - * asin(x) = pi/2 - 2*(s+s*z*R(z)) - * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) - * For x<=0.98, let pio4_hi = pio2_hi/2, then - * f = hi part of s; - * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) - * and - * asin(x) = pi/2 - 2*(s+s*z*R(z)) - * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) - * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) - * - * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. - * - */ - -#include "libm.h" - -static const double -pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ -pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ -/* coefficients for R(x^2) */ -pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ -pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ -pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ -pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ -pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ -pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ -qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ -qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ -qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ -qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ - -static double R(double z) -{ - double_t p, q; - p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); - q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*qS4))); - return p/q; -} - -double asin(double x) -{ - double z,r,s; - uint32_t hx,ix; - - GET_HIGH_WORD(hx, x); - ix = hx & 0x7fffffff; - /* |x| >= 1 or nan */ - if (ix >= 0x3ff00000) { - uint32_t lx; - GET_LOW_WORD(lx, x); - if ((ix-0x3ff00000 | lx) == 0) - /* asin(1) = +-pi/2 with inexact */ - return x*pio2_hi + 0x1p-120f; - return 0/(x-x); - } - /* |x| < 0.5 */ - if (ix < 0x3fe00000) { - /* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */ - if (ix < 0x3e500000 && ix >= 0x00100000) - return x; - return x + x*R(x*x); - } - /* 1 > |x| >= 0.5 */ - z = (1 - fabs(x))*0.5; - s = sqrt(z); - r = R(z); - if (ix >= 0x3fef3333) { /* if |x| > 0.975 */ - x = pio2_hi-(2*(s+s*r)-pio2_lo); - } else { - double f,c; - /* f+c = sqrt(z) */ - f = s; - SET_LOW_WORD(f,0); - c = (z-f*f)/(s+f); - x = 0.5*pio2_hi - (2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f)); - } - if (hx >> 31) - return -x; - return x; -} diff --git a/usr/lib/libc/math/asinf.c b/usr/lib/libc/math/asinf.c deleted file mode 100644 index bcd304a34..000000000 --- a/usr/lib/libc/math/asinf.c +++ /dev/null @@ -1,61 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_asinf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -#include "libm.h" - -static const double -pio2 = 1.570796326794896558e+00; - -static const float -/* coefficients for R(x^2) */ -pS0 = 1.6666586697e-01, -pS1 = -4.2743422091e-02, -pS2 = -8.6563630030e-03, -qS1 = -7.0662963390e-01; - -static float R(float z) -{ - float_t p, q; - p = z*(pS0+z*(pS1+z*pS2)); - q = 1.0f+z*qS1; - return p/q; -} - -float asinf(float x) -{ - double s; - float z; - uint32_t hx,ix; - - GET_FLOAT_WORD(hx, x); - ix = hx & 0x7fffffff; - if (ix >= 0x3f800000) { /* |x| >= 1 */ - if (ix == 0x3f800000) /* |x| == 1 */ - return x*pio2 + 0x1p-120f; /* asin(+-1) = +-pi/2 with inexact */ - return 0/(x-x); /* asin(|x|>1) is NaN */ - } - if (ix < 0x3f000000) { /* |x| < 0.5 */ - /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */ - if (ix < 0x39800000 && ix >= 0x00800000) - return x; - return x + x*R(x*x); - } - /* 1 > |x| >= 0.5 */ - z = (1 - fabsf(x))*0.5f; - s = sqrt(z); - x = pio2 - 2*(s+s*R(z)); - if (hx >> 31) - return -x; - return x; -} diff --git a/usr/lib/libc/math/asinh.c b/usr/lib/libc/math/asinh.c deleted file mode 100644 index 0829f228e..000000000 --- a/usr/lib/libc/math/asinh.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "libm.h" - -/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ -double asinh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - unsigned e = u.i >> 52 & 0x7ff; - unsigned s = u.i >> 63; - - /* |x| */ - u.i &= (uint64_t)-1/2; - x = u.f; - - if (e >= 0x3ff + 26) { - /* |x| >= 0x1p26 or inf or nan */ - x = log(x) + 0.693147180559945309417232121458176568; - } else if (e >= 0x3ff + 1) { - /* |x| >= 2 */ - x = log(2*x + 1/(sqrt(x*x+1)+x)); - } else if (e >= 0x3ff - 26) { - /* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */ - x = log1p(x + x*x/(sqrt(x*x+1)+1)); - } else { - /* |x| < 0x1p-26, raise inexact if x != 0 */ - FORCE_EVAL(x + 0x1p120f); - } - return s ? -x : x; -} diff --git a/usr/lib/libc/math/asinhf.c b/usr/lib/libc/math/asinhf.c deleted file mode 100644 index fc9f0911b..000000000 --- a/usr/lib/libc/math/asinhf.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "libm.h" - -/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ -float asinhf(float x) -{ - union {float f; uint32_t i;} u = {.f = x}; - uint32_t i = u.i & 0x7fffffff; - unsigned s = u.i >> 31; - - /* |x| */ - u.i = i; - x = u.f; - - if (i >= 0x3f800000 + (12<<23)) { - /* |x| >= 0x1p12 or inf or nan */ - x = logf(x) + 0.693147180559945309417232121458176568f; - } else if (i >= 0x3f800000 + (1<<23)) { - /* |x| >= 2 */ - x = logf(2*x + 1/(sqrtf(x*x+1)+x)); - } else if (i >= 0x3f800000 - (12<<23)) { - /* |x| >= 0x1p-12, up to 1.6ulp error in [0.125,0.5] */ - x = log1pf(x + x*x/(sqrtf(x*x+1)+1)); - } else { - /* |x| < 0x1p-12, raise inexact if x!=0 */ - FORCE_EVAL(x + 0x1p120f); - } - return s ? -x : x; -} diff --git a/usr/lib/libc/math/asinhl.c b/usr/lib/libc/math/asinhl.c deleted file mode 100644 index 8635f52e8..000000000 --- a/usr/lib/libc/math/asinhl.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double asinhl(long double x) -{ - return asinh(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ -long double asinhl(long double x) -{ - union ldshape u = {x}; - unsigned e = u.i.se & 0x7fff; - unsigned s = u.i.se >> 15; - - /* |x| */ - u.i.se = e; - x = u.f; - - if (e >= 0x3fff + 32) { - /* |x| >= 0x1p32 or inf or nan */ - x = logl(x) + 0.693147180559945309417232121458176568L; - } else if (e >= 0x3fff + 1) { - /* |x| >= 2 */ - x = logl(2*x + 1/(sqrtl(x*x+1)+x)); - } else if (e >= 0x3fff - 32) { - /* |x| >= 0x1p-32 */ - x = log1pl(x + x*x/(sqrtl(x*x+1)+1)); - } else { - /* |x| < 0x1p-32, raise inexact if x!=0 */ - FORCE_EVAL(x + 0x1p120f); - } - return s ? -x : x; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double asinhl(long double x) -{ - return asinh(x); -} -#endif diff --git a/usr/lib/libc/math/asinl.c b/usr/lib/libc/math/asinl.c deleted file mode 100644 index 347c53568..000000000 --- a/usr/lib/libc/math/asinl.c +++ /dev/null @@ -1,71 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_asinl.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in asin.c. - * Converted to long double by David Schultz . - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double asinl(long double x) -{ - return asin(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#include "__invtrigl.h" -#if LDBL_MANT_DIG == 64 -#define CLOSETO1(u) (u.i.m>>56 >= 0xf7) -#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32) -#elif LDBL_MANT_DIG == 113 -#define CLOSETO1(u) (u.i.top >= 0xee00) -#define CLEARBOTTOM(u) (u.i.lo = 0) -#endif - -long double asinl(long double x) -{ - union ldshape u = {x}; - long double z, r, s; - uint16_t e = u.i.se & 0x7fff; - int sign = u.i.se >> 15; - - if (e >= 0x3fff) { /* |x| >= 1 or nan */ - /* asin(+-1)=+-pi/2 with inexact */ - if (x == 1 || x == -1) - return x*pio2_hi + 0x1p-120f; - return 0/(x-x); - } - if (e < 0x3fff - 1) { /* |x| < 0.5 */ - if (e < 0x3fff - (LDBL_MANT_DIG+1)/2) { - /* return x with inexact if x!=0 */ - FORCE_EVAL(x + 0x1p120f); - return x; - } - return x + x*__invtrigl_R(x*x); - } - /* 1 > |x| >= 0.5 */ - z = (1.0 - fabsl(x))*0.5; - s = sqrtl(z); - r = __invtrigl_R(z); - if (CLOSETO1(u)) { - x = pio2_hi - (2*(s+s*r)-pio2_lo); - } else { - long double f, c; - u.f = s; - CLEARBOTTOM(u); - f = u.f; - c = (z - f*f)/(s + f); - x = 0.5*pio2_hi-(2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f)); - } - return sign ? -x : x; -} -#endif diff --git a/usr/lib/libc/math/atan.c b/usr/lib/libc/math/atan.c deleted file mode 100644 index 63b0ab25e..000000000 --- a/usr/lib/libc/math/atan.c +++ /dev/null @@ -1,116 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_atan.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* atan(x) - * Method - * 1. Reduce x to positive by atan(x) = -atan(-x). - * 2. According to the integer k=4t+0.25 chopped, t=x, the argument - * is further reduced to one of the following intervals and the - * arctangent of t is evaluated by the corresponding formula: - * - * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) - * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) ) - * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) ) - * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) - * [39/16,INF] atan(x) = atan(INF) + atan( -1/t ) - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - - -#include "libm.h" - -static const double atanhi[] = { - 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ - 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ - 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ - 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ -}; - -static const double atanlo[] = { - 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ - 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ - 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ - 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ -}; - -static const double aT[] = { - 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ - -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ - 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ - -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ - 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ - -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ - 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ - -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ - 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ - -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ - 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ -}; - -double atan(double x) -{ - double_t w,s1,s2,z; - uint32_t ix,sign; - int id; - - GET_HIGH_WORD(ix, x); - sign = ix >> 31; - ix &= 0x7fffffff; - if (ix >= 0x44100000) { /* if |x| >= 2^66 */ - if (isnan(x)) - return x; - z = atanhi[3] + 0x1p-120f; - return sign ? -z : z; - } - if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ - if (ix < 0x3e400000) { /* |x| < 2^-27 */ - if (ix < 0x00100000) - /* raise underflow for subnormal x */ - FORCE_EVAL((float)x); - return x; - } - id = -1; - } else { - x = fabs(x); - if (ix < 0x3ff30000) { /* |x| < 1.1875 */ - if (ix < 0x3fe60000) { /* 7/16 <= |x| < 11/16 */ - id = 0; - x = (2.0*x-1.0)/(2.0+x); - } else { /* 11/16 <= |x| < 19/16 */ - id = 1; - x = (x-1.0)/(x+1.0); - } - } else { - if (ix < 0x40038000) { /* |x| < 2.4375 */ - id = 2; - x = (x-1.5)/(1.0+1.5*x); - } else { /* 2.4375 <= |x| < 2^66 */ - id = 3; - x = -1.0/x; - } - } - } - /* end of argument reduction */ - z = x*x; - w = z*z; - /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ - s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); - s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); - if (id < 0) - return x - x*(s1+s2); - z = atanhi[id] - (x*(s1+s2) - atanlo[id] - x); - return sign ? -z : z; -} diff --git a/usr/lib/libc/math/atan2.c b/usr/lib/libc/math/atan2.c deleted file mode 100644 index 5a1903c62..000000000 --- a/usr/lib/libc/math/atan2.c +++ /dev/null @@ -1,107 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ -/* atan2(y,x) - * Method : - * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). - * 2. Reduce x to positive by (if x and y are unexceptional): - * ARG (x+iy) = arctan(y/x) ... if x > 0, - * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, - * - * Special cases: - * - * ATAN2((anything), NaN ) is NaN; - * ATAN2(NAN , (anything) ) is NaN; - * ATAN2(+-0, +(anything but NaN)) is +-0 ; - * ATAN2(+-0, -(anything but NaN)) is +-pi ; - * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; - * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; - * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; - * ATAN2(+-INF,+INF ) is +-pi/4 ; - * ATAN2(+-INF,-INF ) is +-3pi/4; - * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "libm.h" - -static const double -pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ -pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ - -double atan2(double y, double x) -{ - double z; - uint32_t m,lx,ly,ix,iy; - - if (isnan(x) || isnan(y)) - return x+y; - EXTRACT_WORDS(ix, lx, x); - EXTRACT_WORDS(iy, ly, y); - if ((ix-0x3ff00000 | lx) == 0) /* x = 1.0 */ - return atan(y); - m = ((iy>>31)&1) | ((ix>>30)&2); /* 2*sign(x)+sign(y) */ - ix = ix & 0x7fffffff; - iy = iy & 0x7fffffff; - - /* when y = 0 */ - if ((iy|ly) == 0) { - switch(m) { - case 0: - case 1: return y; /* atan(+-0,+anything)=+-0 */ - case 2: return pi; /* atan(+0,-anything) = pi */ - case 3: return -pi; /* atan(-0,-anything) =-pi */ - } - } - /* when x = 0 */ - if ((ix|lx) == 0) - return m&1 ? -pi/2 : pi/2; - /* when x is INF */ - if (ix == 0x7ff00000) { - if (iy == 0x7ff00000) { - switch(m) { - case 0: return pi/4; /* atan(+INF,+INF) */ - case 1: return -pi/4; /* atan(-INF,+INF) */ - case 2: return 3*pi/4; /* atan(+INF,-INF) */ - case 3: return -3*pi/4; /* atan(-INF,-INF) */ - } - } else { - switch(m) { - case 0: return 0.0; /* atan(+...,+INF) */ - case 1: return -0.0; /* atan(-...,+INF) */ - case 2: return pi; /* atan(+...,-INF) */ - case 3: return -pi; /* atan(-...,-INF) */ - } - } - } - /* |y/x| > 0x1p64 */ - if (ix+(64<<20) < iy || iy == 0x7ff00000) - return m&1 ? -pi/2 : pi/2; - - /* z = atan(|y/x|) without spurious underflow */ - if ((m&2) && iy+(64<<20) < ix) /* |y/x| < 0x1p-64, x<0 */ - z = 0; - else - z = atan(fabs(y/x)); - switch (m) { - case 0: return z; /* atan(+,+) */ - case 1: return -z; /* atan(-,+) */ - case 2: return pi - (z-pi_lo); /* atan(+,-) */ - default: /* case 3 */ - return (z-pi_lo) - pi; /* atan(-,-) */ - } -} diff --git a/usr/lib/libc/math/atan2f.c b/usr/lib/libc/math/atan2f.c deleted file mode 100644 index c634d00fc..000000000 --- a/usr/lib/libc/math/atan2f.c +++ /dev/null @@ -1,83 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2f.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float -pi = 3.1415927410e+00, /* 0x40490fdb */ -pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */ - -float atan2f(float y, float x) -{ - float z; - uint32_t m,ix,iy; - - if (isnan(x) || isnan(y)) - return x+y; - GET_FLOAT_WORD(ix, x); - GET_FLOAT_WORD(iy, y); - if (ix == 0x3f800000) /* x=1.0 */ - return atanf(y); - m = ((iy>>31)&1) | ((ix>>30)&2); /* 2*sign(x)+sign(y) */ - ix &= 0x7fffffff; - iy &= 0x7fffffff; - - /* when y = 0 */ - if (iy == 0) { - switch (m) { - case 0: - case 1: return y; /* atan(+-0,+anything)=+-0 */ - case 2: return pi; /* atan(+0,-anything) = pi */ - case 3: return -pi; /* atan(-0,-anything) =-pi */ - } - } - /* when x = 0 */ - if (ix == 0) - return m&1 ? -pi/2 : pi/2; - /* when x is INF */ - if (ix == 0x7f800000) { - if (iy == 0x7f800000) { - switch (m) { - case 0: return pi/4; /* atan(+INF,+INF) */ - case 1: return -pi/4; /* atan(-INF,+INF) */ - case 2: return 3*pi/4; /*atan(+INF,-INF)*/ - case 3: return -3*pi/4; /*atan(-INF,-INF)*/ - } - } else { - switch (m) { - case 0: return 0.0f; /* atan(+...,+INF) */ - case 1: return -0.0f; /* atan(-...,+INF) */ - case 2: return pi; /* atan(+...,-INF) */ - case 3: return -pi; /* atan(-...,-INF) */ - } - } - } - /* |y/x| > 0x1p26 */ - if (ix+(26<<23) < iy || iy == 0x7f800000) - return m&1 ? -pi/2 : pi/2; - - /* z = atan(|y/x|) with correct underflow */ - if ((m&2) && iy+(26<<23) < ix) /*|y/x| < 0x1p-26, x < 0 */ - z = 0.0; - else - z = atanf(fabsf(y/x)); - switch (m) { - case 0: return z; /* atan(+,+) */ - case 1: return -z; /* atan(-,+) */ - case 2: return pi - (z-pi_lo); /* atan(+,-) */ - default: /* case 3 */ - return (z-pi_lo) - pi; /* atan(-,-) */ - } -} diff --git a/usr/lib/libc/math/atan2l.c b/usr/lib/libc/math/atan2l.c deleted file mode 100644 index f0937a979..000000000 --- a/usr/lib/libc/math/atan2l.c +++ /dev/null @@ -1,85 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2l.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ -/* - * See comments in atan2.c. - * Converted to long double by David Schultz . - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double atan2l(long double y, long double x) -{ - return atan2(y, x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#include "__invtrigl.h" - -long double atan2l(long double y, long double x) -{ - union ldshape ux, uy; - long double z; - int m, ex, ey; - - if (isnan(x) || isnan(y)) - return x+y; - if (x == 1) - return atanl(y); - ux.f = x; - uy.f = y; - ex = ux.i.se & 0x7fff; - ey = uy.i.se & 0x7fff; - m = 2*(ux.i.se>>15) | uy.i.se>>15; - if (y == 0) { - switch(m) { - case 0: - case 1: return y; /* atan(+-0,+anything)=+-0 */ - case 2: return 2*pio2_hi; /* atan(+0,-anything) = pi */ - case 3: return -2*pio2_hi; /* atan(-0,-anything) =-pi */ - } - } - if (x == 0) - return m&1 ? -pio2_hi : pio2_hi; - if (ex == 0x7fff) { - if (ey == 0x7fff) { - switch(m) { - case 0: return pio2_hi/2; /* atan(+INF,+INF) */ - case 1: return -pio2_hi/2; /* atan(-INF,+INF) */ - case 2: return 1.5*pio2_hi; /* atan(+INF,-INF) */ - case 3: return -1.5*pio2_hi; /* atan(-INF,-INF) */ - } - } else { - switch(m) { - case 0: return 0.0; /* atan(+...,+INF) */ - case 1: return -0.0; /* atan(-...,+INF) */ - case 2: return 2*pio2_hi; /* atan(+...,-INF) */ - case 3: return -2*pio2_hi; /* atan(-...,-INF) */ - } - } - } - if (ex+120 < ey || ey == 0x7fff) - return m&1 ? -pio2_hi : pio2_hi; - /* z = atan(|y/x|) without spurious underflow */ - if ((m&2) && ey+120 < ex) /* |y/x| < 0x1p-120, x<0 */ - z = 0.0; - else - z = atanl(fabsl(y/x)); - switch (m) { - case 0: return z; /* atan(+,+) */ - case 1: return -z; /* atan(-,+) */ - case 2: return 2*pio2_hi-(z-2*pio2_lo); /* atan(+,-) */ - default: /* case 3 */ - return (z-2*pio2_lo)-2*pio2_hi; /* atan(-,-) */ - } -} -#endif diff --git a/usr/lib/libc/math/atanf.c b/usr/lib/libc/math/atanf.c deleted file mode 100644 index 178341b67..000000000 --- a/usr/lib/libc/math/atanf.c +++ /dev/null @@ -1,94 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_atanf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - - -#include "libm.h" - -static const float atanhi[] = { - 4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */ - 7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */ - 9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */ - 1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */ -}; - -static const float atanlo[] = { - 5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */ - 3.7748947079e-08, /* atan(1.0)lo 0x33222168 */ - 3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */ - 7.5497894159e-08, /* atan(inf)lo 0x33a22168 */ -}; - -static const float aT[] = { - 3.3333328366e-01, - -1.9999158382e-01, - 1.4253635705e-01, - -1.0648017377e-01, - 6.1687607318e-02, -}; - -float atanf(float x) -{ - float_t w,s1,s2,z; - uint32_t ix,sign; - int id; - - GET_FLOAT_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix >= 0x4c800000) { /* if |x| >= 2**26 */ - if (isnan(x)) - return x; - z = atanhi[3] + 0x1p-120f; - return sign ? -z : z; - } - if (ix < 0x3ee00000) { /* |x| < 0.4375 */ - if (ix < 0x39800000) { /* |x| < 2**-12 */ - if (ix < 0x00800000) - /* raise underflow for subnormal x */ - FORCE_EVAL(x*x); - return x; - } - id = -1; - } else { - x = fabsf(x); - if (ix < 0x3f980000) { /* |x| < 1.1875 */ - if (ix < 0x3f300000) { /* 7/16 <= |x| < 11/16 */ - id = 0; - x = (2.0f*x - 1.0f)/(2.0f + x); - } else { /* 11/16 <= |x| < 19/16 */ - id = 1; - x = (x - 1.0f)/(x + 1.0f); - } - } else { - if (ix < 0x401c0000) { /* |x| < 2.4375 */ - id = 2; - x = (x - 1.5f)/(1.0f + 1.5f*x); - } else { /* 2.4375 <= |x| < 2**26 */ - id = 3; - x = -1.0f/x; - } - } - } - /* end of argument reduction */ - z = x*x; - w = z*z; - /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ - s1 = z*(aT[0]+w*(aT[2]+w*aT[4])); - s2 = w*(aT[1]+w*aT[3]); - if (id < 0) - return x - x*(s1+s2); - z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); - return sign ? -z : z; -} diff --git a/usr/lib/libc/math/atanh.c b/usr/lib/libc/math/atanh.c deleted file mode 100644 index 63a035d70..000000000 --- a/usr/lib/libc/math/atanh.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "libm.h" - -/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ -double atanh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - unsigned e = u.i >> 52 & 0x7ff; - unsigned s = u.i >> 63; - double_t y; - - /* |x| */ - u.i &= (uint64_t)-1/2; - y = u.f; - - if (e < 0x3ff - 1) { - if (e < 0x3ff - 32) { - /* handle underflow */ - if (e == 0) - FORCE_EVAL((float)y); - } else { - /* |x| < 0.5, up to 1.7ulp error */ - y = 0.5*log1p(2*y + 2*y*y/(1-y)); - } - } else { - /* avoid overflow */ - y = 0.5*log1p(2*(y/(1-y))); - } - return s ? -y : y; -} diff --git a/usr/lib/libc/math/atanhf.c b/usr/lib/libc/math/atanhf.c deleted file mode 100644 index 65f07c0f4..000000000 --- a/usr/lib/libc/math/atanhf.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "libm.h" - -/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ -float atanhf(float x) -{ - union {float f; uint32_t i;} u = {.f = x}; - unsigned s = u.i >> 31; - float_t y; - - /* |x| */ - u.i &= 0x7fffffff; - y = u.f; - - if (u.i < 0x3f800000 - (1<<23)) { - if (u.i < 0x3f800000 - (32<<23)) { - /* handle underflow */ - if (u.i < (1<<23)) - FORCE_EVAL((float)(y*y)); - } else { - /* |x| < 0.5, up to 1.7ulp error */ - y = 0.5f*log1pf(2*y + 2*y*y/(1-y)); - } - } else { - /* avoid overflow */ - y = 0.5f*log1pf(2*(y/(1-y))); - } - return s ? -y : y; -} diff --git a/usr/lib/libc/math/atanhl.c b/usr/lib/libc/math/atanhl.c deleted file mode 100644 index 87cd1cdb5..000000000 --- a/usr/lib/libc/math/atanhl.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double atanhl(long double x) -{ - return atanh(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ -long double atanhl(long double x) -{ - union ldshape u = {x}; - unsigned e = u.i.se & 0x7fff; - unsigned s = u.i.se >> 15; - - /* |x| */ - u.i.se = e; - x = u.f; - - if (e < 0x3ff - 1) { - if (e < 0x3ff - LDBL_MANT_DIG/2) { - /* handle underflow */ - if (e == 0) - FORCE_EVAL((float)x); - } else { - /* |x| < 0.5, up to 1.7ulp error */ - x = 0.5*log1pl(2*x + 2*x*x/(1-x)); - } - } else { - /* avoid overflow */ - x = 0.5*log1pl(2*(x/(1-x))); - } - return s ? -x : x; -} -#endif diff --git a/usr/lib/libc/math/atanl.c b/usr/lib/libc/math/atanl.c deleted file mode 100644 index 79a3edb80..000000000 --- a/usr/lib/libc/math/atanl.c +++ /dev/null @@ -1,184 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_atanl.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in atan.c. - * Converted to long double by David Schultz . - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double atanl(long double x) -{ - return atan(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -#if LDBL_MANT_DIG == 64 -#define EXPMAN(u) ((u.i.se & 0x7fff)<<8 | (u.i.m>>55 & 0xff)) - -static const long double atanhi[] = { - 4.63647609000806116202e-01L, - 7.85398163397448309628e-01L, - 9.82793723247329067960e-01L, - 1.57079632679489661926e+00L, -}; - -static const long double atanlo[] = { - 1.18469937025062860669e-20L, - -1.25413940316708300586e-20L, - 2.55232234165405176172e-20L, - -2.50827880633416601173e-20L, -}; - -static const long double aT[] = { - 3.33333333333333333017e-01L, - -1.99999999999999632011e-01L, - 1.42857142857046531280e-01L, - -1.11111111100562372733e-01L, - 9.09090902935647302252e-02L, - -7.69230552476207730353e-02L, - 6.66661718042406260546e-02L, - -5.88158892835030888692e-02L, - 5.25499891539726639379e-02L, - -4.70119845393155721494e-02L, - 4.03539201366454414072e-02L, - -2.91303858419364158725e-02L, - 1.24822046299269234080e-02L, -}; - -static long double T_even(long double x) -{ - return aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + - x * (aT[8] + x * (aT[10] + x * aT[12]))))); -} - -static long double T_odd(long double x) -{ - return aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + - x * (aT[9] + x * aT[11])))); -} -#elif LDBL_MANT_DIG == 113 -#define EXPMAN(u) ((u.i.se & 0x7fff)<<8 | u.i.top>>8) - -const long double atanhi[] = { - 4.63647609000806116214256231461214397e-01L, - 7.85398163397448309615660845819875699e-01L, - 9.82793723247329067985710611014666038e-01L, - 1.57079632679489661923132169163975140e+00L, -}; - -const long double atanlo[] = { - 4.89509642257333492668618435220297706e-36L, - 2.16795253253094525619926100651083806e-35L, - -2.31288434538183565909319952098066272e-35L, - 4.33590506506189051239852201302167613e-35L, -}; - -const long double aT[] = { - 3.33333333333333333333333333333333125e-01L, - -1.99999999999999999999999999999180430e-01L, - 1.42857142857142857142857142125269827e-01L, - -1.11111111111111111111110834490810169e-01L, - 9.09090909090909090908522355708623681e-02L, - -7.69230769230769230696553844935357021e-02L, - 6.66666666666666660390096773046256096e-02L, - -5.88235294117646671706582985209643694e-02L, - 5.26315789473666478515847092020327506e-02L, - -4.76190476189855517021024424991436144e-02L, - 4.34782608678695085948531993458097026e-02L, - -3.99999999632663469330634215991142368e-02L, - 3.70370363987423702891250829918659723e-02L, - -3.44827496515048090726669907612335954e-02L, - 3.22579620681420149871973710852268528e-02L, - -3.03020767654269261041647570626778067e-02L, - 2.85641979882534783223403715930946138e-02L, - -2.69824879726738568189929461383741323e-02L, - 2.54194698498808542954187110873675769e-02L, - -2.35083879708189059926183138130183215e-02L, - 2.04832358998165364349957325067131428e-02L, - -1.54489555488544397858507248612362957e-02L, - 8.64492360989278761493037861575248038e-03L, - -2.58521121597609872727919154569765469e-03L, -}; - -static long double T_even(long double x) -{ - return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * (aT[8] + - x * (aT[10] + x * (aT[12] + x * (aT[14] + x * (aT[16] + - x * (aT[18] + x * (aT[20] + x * aT[22]))))))))))); -} - -static long double T_odd(long double x) -{ - return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * (aT[9] + - x * (aT[11] + x * (aT[13] + x * (aT[15] + x * (aT[17] + - x * (aT[19] + x * (aT[21] + x * aT[23]))))))))))); -} -#endif - -long double atanl(long double x) -{ - union ldshape u = {x}; - long double w, s1, s2, z; - int id; - unsigned e = u.i.se & 0x7fff; - unsigned sign = u.i.se >> 15; - unsigned expman; - - if (e >= 0x3fff + LDBL_MANT_DIG + 1) { /* if |x| is large, atan(x)~=pi/2 */ - if (isnan(x)) - return x; - return sign ? -atanhi[3] : atanhi[3]; - } - /* Extract the exponent and the first few bits of the mantissa. */ - expman = EXPMAN(u); - if (expman < ((0x3fff - 2) << 8) + 0xc0) { /* |x| < 0.4375 */ - if (e < 0x3fff - (LDBL_MANT_DIG+1)/2) { /* if |x| is small, atanl(x)~=x */ - /* raise underflow if subnormal */ - if (e == 0) - FORCE_EVAL((float)x); - return x; - } - id = -1; - } else { - x = fabsl(x); - if (expman < (0x3fff << 8) + 0x30) { /* |x| < 1.1875 */ - if (expman < ((0x3fff - 1) << 8) + 0x60) { /* 7/16 <= |x| < 11/16 */ - id = 0; - x = (2.0*x-1.0)/(2.0+x); - } else { /* 11/16 <= |x| < 19/16 */ - id = 1; - x = (x-1.0)/(x+1.0); - } - } else { - if (expman < ((0x3fff + 1) << 8) + 0x38) { /* |x| < 2.4375 */ - id = 2; - x = (x-1.5)/(1.0+1.5*x); - } else { /* 2.4375 <= |x| */ - id = 3; - x = -1.0/x; - } - } - } - /* end of argument reduction */ - z = x*x; - w = z*z; - /* break sum aT[i]z**(i+1) into odd and even poly */ - s1 = z*T_even(w); - s2 = w*T_odd(w); - if (id < 0) - return x - x*(s1+s2); - z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); - return sign ? -z : z; -} -#endif diff --git a/usr/lib/libc/math/cbrt.c b/usr/lib/libc/math/cbrt.c deleted file mode 100644 index 7599d3e37..000000000 --- a/usr/lib/libc/math/cbrt.c +++ /dev/null @@ -1,103 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrt.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - * Optimized by Bruce D. Evans. - */ -/* cbrt(x) - * Return cube root of x - */ - -#include -#include - -static const uint32_t -B1 = 715094163, /* B1 = (1023-1023/3-0.03306235651)*2**20 */ -B2 = 696219795; /* B2 = (1023-1023/3-54/3-0.03306235651)*2**20 */ - -/* |1/cbrt(x) - p(x)| < 2**-23.5 (~[-7.93e-8, 7.929e-8]). */ -static const double -P0 = 1.87595182427177009643, /* 0x3ffe03e6, 0x0f61e692 */ -P1 = -1.88497979543377169875, /* 0xbffe28e0, 0x92f02420 */ -P2 = 1.621429720105354466140, /* 0x3ff9f160, 0x4a49d6c2 */ -P3 = -0.758397934778766047437, /* 0xbfe844cb, 0xbee751d9 */ -P4 = 0.145996192886612446982; /* 0x3fc2b000, 0xd4e4edd7 */ - -double cbrt(double x) -{ - union {double f; uint64_t i;} u = {x}; - double_t r,s,t,w; - uint32_t hx = u.i>>32 & 0x7fffffff; - - if (hx >= 0x7ff00000) /* cbrt(NaN,INF) is itself */ - return x+x; - - /* - * Rough cbrt to 5 bits: - * cbrt(2**e*(1+m) ~= 2**(e/3)*(1+(e%3+m)/3) - * where e is integral and >= 0, m is real and in [0, 1), and "/" and - * "%" are integer division and modulus with rounding towards minus - * infinity. The RHS is always >= the LHS and has a maximum relative - * error of about 1 in 16. Adding a bias of -0.03306235651 to the - * (e%3+m)/3 term reduces the error to about 1 in 32. With the IEEE - * floating point representation, for finite positive normal values, - * ordinary integer divison of the value in bits magically gives - * almost exactly the RHS of the above provided we first subtract the - * exponent bias (1023 for doubles) and later add it back. We do the - * subtraction virtually to keep e >= 0 so that ordinary integer - * division rounds towards minus infinity; this is also efficient. - */ - if (hx < 0x00100000) { /* zero or subnormal? */ - u.f = x*0x1p54; - hx = u.i>>32 & 0x7fffffff; - if (hx == 0) - return x; /* cbrt(0) is itself */ - hx = hx/3 + B2; - } else - hx = hx/3 + B1; - u.i &= 1ULL<<63; - u.i |= (uint64_t)hx << 32; - t = u.f; - - /* - * New cbrt to 23 bits: - * cbrt(x) = t*cbrt(x/t**3) ~= t*P(t**3/x) - * where P(r) is a polynomial of degree 4 that approximates 1/cbrt(r) - * to within 2**-23.5 when |r - 1| < 1/10. The rough approximation - * has produced t such than |t/cbrt(x) - 1| ~< 1/32, and cubing this - * gives us bounds for r = t**3/x. - * - * Try to optimize for parallel evaluation as in __tanf.c. - */ - r = (t*t)*(t/x); - t = t*((P0+r*(P1+r*P2))+((r*r)*r)*(P3+r*P4)); - - /* - * Round t away from zero to 23 bits (sloppily except for ensuring that - * the result is larger in magnitude than cbrt(x) but not much more than - * 2 23-bit ulps larger). With rounding towards zero, the error bound - * would be ~5/6 instead of ~4/6. With a maximum error of 2 23-bit ulps - * in the rounded t, the infinite-precision error in the Newton - * approximation barely affects third digit in the final error - * 0.667; the error in the rounded t can be up to about 3 23-bit ulps - * before the final error is larger than 0.667 ulps. - */ - u.f = t; - u.i = (u.i + 0x80000000) & 0xffffffffc0000000ULL; - t = u.f; - - /* one step Newton iteration to 53 bits with error < 0.667 ulps */ - s = t*t; /* t*t is exact */ - r = x/s; /* error <= 0.5 ulps; |r| < |t| */ - w = t+t; /* t+t is exact */ - r = (r-t)/(w+r); /* r-t is exact; w+r ~= 3*t */ - t = t+t*r; /* error <= 0.5 + 0.5/3 + epsilon */ - return t; -} diff --git a/usr/lib/libc/math/cbrtf.c b/usr/lib/libc/math/cbrtf.c deleted file mode 100644 index 89c2c8655..000000000 --- a/usr/lib/libc/math/cbrtf.c +++ /dev/null @@ -1,66 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Debugged and optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* cbrtf(x) - * Return cube root of x - */ - -#include -#include - -static const unsigned -B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */ -B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */ - -float cbrtf(float x) -{ - double_t r,T; - union {float f; uint32_t i;} u = {x}; - uint32_t hx = u.i & 0x7fffffff; - - if (hx >= 0x7f800000) /* cbrt(NaN,INF) is itself */ - return x + x; - - /* rough cbrt to 5 bits */ - if (hx < 0x00800000) { /* zero or subnormal? */ - if (hx == 0) - return x; /* cbrt(+-0) is itself */ - u.f = x*0x1p24f; - hx = u.i & 0x7fffffff; - hx = hx/3 + B2; - } else - hx = hx/3 + B1; - u.i &= 0x80000000; - u.i |= hx; - - /* - * First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In - * double precision so that its terms can be arranged for efficiency - * without causing overflow or underflow. - */ - T = u.f; - r = T*T*T; - T = T*((double_t)x+x+r)/(x+r+r); - - /* - * Second step Newton iteration to 47 bits. In double precision for - * efficiency and accuracy. - */ - r = T*T*T; - T = T*((double_t)x+x+r)/(x+r+r); - - /* rounding to 24 bits is perfect in round-to-nearest mode */ - return T; -} diff --git a/usr/lib/libc/math/cbrtl.c b/usr/lib/libc/math/cbrtl.c deleted file mode 100644 index ceff9136e..000000000 --- a/usr/lib/libc/math/cbrtl.c +++ /dev/null @@ -1,124 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtl.c */ -/*- - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - * The argument reduction and testing for exceptional cases was - * written by Steven G. Kargl with input from Bruce D. Evans - * and David A. Schultz. - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double cbrtl(long double x) -{ - return cbrt(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -static const unsigned B1 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */ - -long double cbrtl(long double x) -{ - union ldshape u = {x}, v; - union {float f; uint32_t i;} uft; - long double r, s, t, w; - double_t dr, dt, dx; - float_t ft; - int e = u.i.se & 0x7fff; - int sign = u.i.se & 0x8000; - - /* - * If x = +-Inf, then cbrt(x) = +-Inf. - * If x = NaN, then cbrt(x) = NaN. - */ - if (e == 0x7fff) - return x + x; - if (e == 0) { - /* Adjust subnormal numbers. */ - u.f *= 0x1p120; - e = u.i.se & 0x7fff; - /* If x = +-0, then cbrt(x) = +-0. */ - if (e == 0) - return x; - e -= 120; - } - e -= 0x3fff; - u.i.se = 0x3fff; - x = u.f; - switch (e % 3) { - case 1: - case -2: - x *= 2; - e--; - break; - case 2: - case -1: - x *= 4; - e -= 2; - break; - } - v.f = 1.0; - v.i.se = sign | (0x3fff + e/3); - - /* - * The following is the guts of s_cbrtf, with the handling of - * special values removed and extra care for accuracy not taken, - * but with most of the extra accuracy not discarded. - */ - - /* ~5-bit estimate: */ - uft.f = x; - uft.i = (uft.i & 0x7fffffff)/3 + B1; - ft = uft.f; - - /* ~16-bit estimate: */ - dx = x; - dt = ft; - dr = dt * dt * dt; - dt = dt * (dx + dx + dr) / (dx + dr + dr); - - /* ~47-bit estimate: */ - dr = dt * dt * dt; - dt = dt * (dx + dx + dr) / (dx + dr + dr); - -#if LDBL_MANT_DIG == 64 - /* - * dt is cbrtl(x) to ~47 bits (after x has been reduced to 1 <= x < 8). - * Round it away from zero to 32 bits (32 so that t*t is exact, and - * away from zero for technical reasons). - */ - t = dt + (0x1.0p32L + 0x1.0p-31L) - 0x1.0p32; -#elif LDBL_MANT_DIG == 113 - /* - * Round dt away from zero to 47 bits. Since we don't trust the 47, - * add 2 47-bit ulps instead of 1 to round up. Rounding is slow and - * might be avoidable in this case, since on most machines dt will - * have been evaluated in 53-bit precision and the technical reasons - * for rounding up might not apply to either case in cbrtl() since - * dt is much more accurate than needed. - */ - t = dt + 0x2.0p-46 + 0x1.0p60L - 0x1.0p60; -#endif - - /* - * Final step Newton iteration to 64 or 113 bits with - * error < 0.667 ulps - */ - s = t*t; /* t*t is exact */ - r = x/s; /* error <= 0.5 ulps; |r| < |t| */ - w = t+t; /* t+t is exact */ - r = (r-t)/(w+r); /* r-t is exact; w+r ~= 3*t */ - t = t+t*r; /* error <= 0.5 + 0.5/3 + epsilon */ - - t *= v.f; - return t; -} -#endif diff --git a/usr/lib/libc/math/ceil.c b/usr/lib/libc/math/ceil.c deleted file mode 100644 index b13e6f2d6..000000000 --- a/usr/lib/libc/math/ceil.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const double_t toint = 1/EPS; - -double ceil(double x) -{ - union {double f; uint64_t i;} u = {x}; - int e = u.i >> 52 & 0x7ff; - double_t y; - - if (e >= 0x3ff+52 || x == 0) - return x; - /* y = int(x) - x, where int(x) is an integer neighbor of x */ - if (u.i >> 63) - y = x - toint + toint - x; - else - y = x + toint - toint - x; - /* special case because of non-nearest rounding modes */ - if (e <= 0x3ff-1) { - FORCE_EVAL(y); - return u.i >> 63 ? -0.0 : 1; - } - if (y < 0) - return x + y + 1; - return x + y; -} diff --git a/usr/lib/libc/math/ceilf.c b/usr/lib/libc/math/ceilf.c deleted file mode 100644 index 869835f39..000000000 --- a/usr/lib/libc/math/ceilf.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "libm.h" - -float ceilf(float x) -{ - union {float f; uint32_t i;} u = {x}; - int e = (int)(u.i >> 23 & 0xff) - 0x7f; - uint32_t m; - - if (e >= 23) - return x; - if (e >= 0) { - m = 0x007fffff >> e; - if ((u.i & m) == 0) - return x; - FORCE_EVAL(x + 0x1p120f); - if (u.i >> 31 == 0) - u.i += m; - u.i &= ~m; - } else { - FORCE_EVAL(x + 0x1p120f); - if (u.i >> 31) - u.f = -0.0; - else if (u.i << 1) - u.f = 1.0; - } - return u.f; -} diff --git a/usr/lib/libc/math/ceill.c b/usr/lib/libc/math/ceill.c deleted file mode 100644 index 60a83020d..000000000 --- a/usr/lib/libc/math/ceill.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double ceill(long double x) -{ - return ceil(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -static const long double toint = 1/LDBL_EPSILON; - -long double ceill(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - long double y; - - if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0) - return x; - /* y = int(x) - x, where int(x) is an integer neighbor of x */ - if (u.i.se >> 15) - y = x - toint + toint - x; - else - y = x + toint - toint - x; - /* special case because of non-nearest rounding modes */ - if (e <= 0x3fff-1) { - FORCE_EVAL(y); - return u.i.se >> 15 ? -0.0 : 1; - } - if (y < 0) - return x + y + 1; - return x + y; -} -#endif diff --git a/usr/lib/libc/math/copysign.c b/usr/lib/libc/math/copysign.c deleted file mode 100644 index b09331b68..000000000 --- a/usr/lib/libc/math/copysign.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "libm.h" - -double copysign(double x, double y) { - union {double f; uint64_t i;} ux={x}, uy={y}; - ux.i &= -1ULL/2; - ux.i |= uy.i & 1ULL<<63; - return ux.f; -} diff --git a/usr/lib/libc/math/copysignf.c b/usr/lib/libc/math/copysignf.c deleted file mode 100644 index 0af6ae9b2..000000000 --- a/usr/lib/libc/math/copysignf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -float copysignf(float x, float y) -{ - union {float f; uint32_t i;} ux={x}, uy={y}; - ux.i &= 0x7fffffff; - ux.i |= uy.i & 0x80000000; - return ux.f; -} diff --git a/usr/lib/libc/math/copysignl.c b/usr/lib/libc/math/copysignl.c deleted file mode 100644 index 9dd933cfa..000000000 --- a/usr/lib/libc/math/copysignl.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double copysignl(long double x, long double y) -{ - return copysign(x, y); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double copysignl(long double x, long double y) -{ - union ldshape ux = {x}, uy = {y}; - ux.i.se &= 0x7fff; - ux.i.se |= uy.i.se & 0x8000; - return ux.f; -} -#endif diff --git a/usr/lib/libc/math/cos.c b/usr/lib/libc/math/cos.c deleted file mode 100644 index ee97f68bb..000000000 --- a/usr/lib/libc/math/cos.c +++ /dev/null @@ -1,77 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_cos.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* cos(x) - * Return cosine function of x. - * - * kernel function: - * __sin ... sine function on [-pi/4,pi/4] - * __cos ... cosine function on [-pi/4,pi/4] - * __rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include "libm.h" - -double cos(double x) -{ - double y[2]; - uint32_t ix; - unsigned n; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - - /* |x| ~< pi/4 */ - if (ix <= 0x3fe921fb) { - if (ix < 0x3e46a09e) { /* |x| < 2**-27 * sqrt(2) */ - /* raise inexact if x!=0 */ - FORCE_EVAL(x + 0x1p120f); - return 1.0; - } - return __cos(x, 0); - } - - /* cos(Inf or NaN) is NaN */ - if (ix >= 0x7ff00000) - return x-x; - - /* argument reduction */ - n = __rem_pio2(x, y); - switch (n&3) { - case 0: return __cos(y[0], y[1]); - case 1: return -__sin(y[0], y[1], 1); - case 2: return -__cos(y[0], y[1]); - default: - return __sin(y[0], y[1], 1); - } -} diff --git a/usr/lib/libc/math/cosf.c b/usr/lib/libc/math/cosf.c deleted file mode 100644 index 23f3e5bf6..000000000 --- a/usr/lib/libc/math/cosf.c +++ /dev/null @@ -1,78 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_cosf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -/* Small multiples of pi/2 rounded to double precision. */ -static const double -c1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ -c2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ -c3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ -c4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ - -float cosf(float x) -{ - double y; - uint32_t ix; - unsigned n, sign; - - GET_FLOAT_WORD(ix, x); - sign = ix >> 31; - ix &= 0x7fffffff; - - if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ - if (ix < 0x39800000) { /* |x| < 2**-12 */ - /* raise inexact if x != 0 */ - FORCE_EVAL(x + 0x1p120f); - return 1.0f; - } - return __cosdf(x); - } - if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */ - if (ix > 0x4016cbe3) /* |x| ~> 3*pi/4 */ - return -__cosdf(sign ? x+c2pio2 : x-c2pio2); - else { - if (sign) - return __sindf(x + c1pio2); - else - return __sindf(c1pio2 - x); - } - } - if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */ - if (ix > 0x40afeddf) /* |x| ~> 7*pi/4 */ - return __cosdf(sign ? x+c4pio2 : x-c4pio2); - else { - if (sign) - return __sindf(-x - c3pio2); - else - return __sindf(x - c3pio2); - } - } - - /* cos(Inf or NaN) is NaN */ - if (ix >= 0x7f800000) - return x-x; - - /* general argument reduction needed */ - n = __rem_pio2f(x,&y); - switch (n&3) { - case 0: return __cosdf(y); - case 1: return __sindf(-y); - case 2: return -__cosdf(y); - default: - return __sindf(y); - } -} diff --git a/usr/lib/libc/math/cosh.c b/usr/lib/libc/math/cosh.c deleted file mode 100644 index 100f8231d..000000000 --- a/usr/lib/libc/math/cosh.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "libm.h" - -/* cosh(x) = (exp(x) + 1/exp(x))/2 - * = 1 + 0.5*(exp(x)-1)*(exp(x)-1)/exp(x) - * = 1 + x*x/2 + o(x^4) - */ -double cosh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - uint32_t w; - double t; - - /* |x| */ - u.i &= (uint64_t)-1/2; - x = u.f; - w = u.i >> 32; - - /* |x| < log(2) */ - if (w < 0x3fe62e42) { - if (w < 0x3ff00000 - (26<<20)) { - /* raise inexact if x!=0 */ - FORCE_EVAL(x + 0x1p120f); - return 1; - } - t = expm1(x); - return 1 + t*t/(2*(1+t)); - } - - /* |x| < log(DBL_MAX) */ - if (w < 0x40862e42) { - t = exp(x); - /* note: if x>log(0x1p26) then the 1/t is not needed */ - return 0.5*(t + 1/t); - } - - /* |x| > log(DBL_MAX) or nan */ - /* note: the result is stored to handle overflow */ - t = __expo2(x); - return t; -} diff --git a/usr/lib/libc/math/coshf.c b/usr/lib/libc/math/coshf.c deleted file mode 100644 index b09f2ee57..000000000 --- a/usr/lib/libc/math/coshf.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "libm.h" - -float coshf(float x) -{ - union {float f; uint32_t i;} u = {.f = x}; - uint32_t w; - float t; - - /* |x| */ - u.i &= 0x7fffffff; - x = u.f; - w = u.i; - - /* |x| < log(2) */ - if (w < 0x3f317217) { - if (w < 0x3f800000 - (12<<23)) { - FORCE_EVAL(x + 0x1p120f); - return 1; - } - t = expm1f(x); - return 1 + t*t/(2*(1+t)); - } - - /* |x| < log(FLT_MAX) */ - if (w < 0x42b17217) { - t = expf(x); - return 0.5f*(t + 1/t); - } - - /* |x| > log(FLT_MAX) or nan */ - t = __expo2f(x); - return t; -} diff --git a/usr/lib/libc/math/coshl.c b/usr/lib/libc/math/coshl.c deleted file mode 100644 index 06a56fe3b..000000000 --- a/usr/lib/libc/math/coshl.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double coshl(long double x) -{ - return cosh(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -long double coshl(long double x) -{ - union ldshape u = {x}; - unsigned ex = u.i.se & 0x7fff; - uint32_t w; - long double t; - - /* |x| */ - u.i.se = ex; - x = u.f; - w = u.i.m >> 32; - - /* |x| < log(2) */ - if (ex < 0x3fff-1 || (ex == 0x3fff-1 && w < 0xb17217f7)) { - if (ex < 0x3fff-32) { - FORCE_EVAL(x + 0x1p120f); - return 1; - } - t = expm1l(x); - return 1 + t*t/(2*(1+t)); - } - - /* |x| < log(LDBL_MAX) */ - if (ex < 0x3fff+13 || (ex == 0x3fff+13 && w < 0xb17217f7)) { - t = expl(x); - return 0.5*(t + 1/t); - } - - /* |x| > log(LDBL_MAX) or nan */ - t = expl(0.5*x); - return 0.5*t*t; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double coshl(long double x) -{ - return cosh(x); -} -#endif diff --git a/usr/lib/libc/math/cosl.c b/usr/lib/libc/math/cosl.c deleted file mode 100644 index 79c41c77f..000000000 --- a/usr/lib/libc/math/cosl.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double cosl(long double x) { - return cos(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double cosl(long double x) -{ - union ldshape u = {x}; - unsigned n; - long double y[2], hi, lo; - - u.i.se &= 0x7fff; - if (u.i.se == 0x7fff) - return x - x; - x = u.f; - if (x < M_PI_4) { - if (u.i.se < 0x3fff - LDBL_MANT_DIG) - /* raise inexact if x!=0 */ - return 1.0 + x; - return __cosl(x, 0); - } - n = __rem_pio2l(x, y); - hi = y[0]; - lo = y[1]; - switch (n & 3) { - case 0: - return __cosl(hi, lo); - case 1: - return -__sinl(hi, lo, 1); - case 2: - return -__cosl(hi, lo); - case 3: - default: - return __sinl(hi, lo, 1); - } -} -#endif diff --git a/usr/lib/libc/math/erf.c b/usr/lib/libc/math/erf.c deleted file mode 100644 index 2f30a298f..000000000 --- a/usr/lib/libc/math/erf.c +++ /dev/null @@ -1,273 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_erf.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* double erf(double x) - * double erfc(double x) - * x - * 2 |\ - * erf(x) = --------- | exp(-t*t)dt - * sqrt(pi) \| - * 0 - * - * erfc(x) = 1-erf(x) - * Note that - * erf(-x) = -erf(x) - * erfc(-x) = 2 - erfc(x) - * - * Method: - * 1. For |x| in [0, 0.84375] - * erf(x) = x + x*R(x^2) - * erfc(x) = 1 - erf(x) if x in [-.84375,0.25] - * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375] - * where R = P/Q where P is an odd poly of degree 8 and - * Q is an odd poly of degree 10. - * -57.90 - * | R - (erf(x)-x)/x | <= 2 - * - * - * Remark. The formula is derived by noting - * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....) - * and that - * 2/sqrt(pi) = 1.128379167095512573896158903121545171688 - * is close to one. The interval is chosen because the fix - * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is - * near 0.6174), and by some experiment, 0.84375 is chosen to - * guarantee the error is less than one ulp for erf. - * - * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and - * c = 0.84506291151 rounded to single (24 bits) - * erf(x) = sign(x) * (c + P1(s)/Q1(s)) - * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0 - * 1+(c+P1(s)/Q1(s)) if x < 0 - * |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06 - * Remark: here we use the taylor series expansion at x=1. - * erf(1+s) = erf(1) + s*Poly(s) - * = 0.845.. + P1(s)/Q1(s) - * That is, we use rational approximation to approximate - * erf(1+s) - (c = (single)0.84506291151) - * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25] - * where - * P1(s) = degree 6 poly in s - * Q1(s) = degree 6 poly in s - * - * 3. For x in [1.25,1/0.35(~2.857143)], - * erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1) - * erf(x) = 1 - erfc(x) - * where - * R1(z) = degree 7 poly in z, (z=1/x^2) - * S1(z) = degree 8 poly in z - * - * 4. For x in [1/0.35,28] - * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0 - * = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6 x >= 28 - * erf(x) = sign(x) *(1 - tiny) (raise inexact) - * erfc(x) = tiny*tiny (raise underflow) if x > 0 - * = 2 - tiny if x<0 - * - * 7. Special case: - * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1, - * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2, - * erfc/erf(NaN) is NaN - */ - -#include "libm.h" - -static const double -erx = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */ -/* - * Coefficients for approximation to erf on [0,0.84375] - */ -efx8 = 1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */ -pp0 = 1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */ -pp1 = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */ -pp2 = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */ -pp3 = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */ -pp4 = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */ -qq1 = 3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */ -qq2 = 6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */ -qq3 = 5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */ -qq4 = 1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */ -qq5 = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */ -/* - * Coefficients for approximation to erf in [0.84375,1.25] - */ -pa0 = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */ -pa1 = 4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */ -pa2 = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */ -pa3 = 3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */ -pa4 = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */ -pa5 = 3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */ -pa6 = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */ -qa1 = 1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */ -qa2 = 5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */ -qa3 = 7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */ -qa4 = 1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */ -qa5 = 1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */ -qa6 = 1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */ -/* - * Coefficients for approximation to erfc in [1.25,1/0.35] - */ -ra0 = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */ -ra1 = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */ -ra2 = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */ -ra3 = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */ -ra4 = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */ -ra5 = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */ -ra6 = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */ -ra7 = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */ -sa1 = 1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */ -sa2 = 1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */ -sa3 = 4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */ -sa4 = 6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */ -sa5 = 4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */ -sa6 = 1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */ -sa7 = 6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */ -sa8 = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */ -/* - * Coefficients for approximation to erfc in [1/.35,28] - */ -rb0 = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */ -rb1 = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */ -rb2 = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */ -rb3 = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */ -rb4 = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */ -rb5 = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */ -rb6 = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */ -sb1 = 3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */ -sb2 = 3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */ -sb3 = 1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */ -sb4 = 3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */ -sb5 = 2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */ -sb6 = 4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */ -sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */ - -static double erfc1(double x) -{ - double_t s,P,Q; - - s = fabs(x) - 1; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = 1+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - return 1 - erx - P/Q; -} - -static double erfc2(uint32_t ix, double x) -{ - double_t s,R,S; - double z; - - if (ix < 0x3ff40000) /* |x| < 1.25 */ - return erfc1(x); - - x = fabs(x); - s = 1/(x*x); - if (ix < 0x4006db6d) { /* |x| < 1/.35 ~ 2.85714 */ - R = ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S = 1.0+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| > 1/.35 */ - R = rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S = 1.0+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - z = x; - SET_LOW_WORD(z,0); - return exp(-z*z-0.5625)*exp((z-x)*(z+x)+R/S)/x; -} - -double erf(double x) -{ - double r,s,z,y; - uint32_t ix; - int sign; - - GET_HIGH_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix >= 0x7ff00000) { - /* erf(nan)=nan, erf(+-inf)=+-1 */ - return 1-2*sign + 1/x; - } - if (ix < 0x3feb0000) { /* |x| < 0.84375 */ - if (ix < 0x3e300000) { /* |x| < 2**-28 */ - /* avoid underflow */ - return 0.125*(8*x + efx8*x); - } - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = 1.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - return x + x*y; - } - if (ix < 0x40180000) /* 0.84375 <= |x| < 6 */ - y = 1 - erfc2(ix,x); - else - y = 1 - 0x1p-1022; - return sign ? -y : y; -} - -double erfc(double x) -{ - double r,s,z,y; - uint32_t ix; - int sign; - - GET_HIGH_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix >= 0x7ff00000) { - /* erfc(nan)=nan, erfc(+-inf)=0,2 */ - return 2*sign + 1/x; - } - if (ix < 0x3feb0000) { /* |x| < 0.84375 */ - if (ix < 0x3c700000) /* |x| < 2**-56 */ - return 1.0 - x; - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = 1.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - if (sign || ix < 0x3fd00000) { /* x < 1/4 */ - return 1.0 - (x+x*y); - } - return 0.5 - (x - 0.5 + x*y); - } - if (ix < 0x403c0000) { /* 0.84375 <= |x| < 28 */ - return sign ? 2 - erfc2(ix,x) : erfc2(ix,x); - } - return sign ? 2 - 0x1p-1022 : 0x1p-1022*0x1p-1022; -} diff --git a/usr/lib/libc/math/erff.c b/usr/lib/libc/math/erff.c deleted file mode 100644 index ed5f39757..000000000 --- a/usr/lib/libc/math/erff.c +++ /dev/null @@ -1,183 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_erff.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float -erx = 8.4506291151e-01, /* 0x3f58560b */ -/* - * Coefficients for approximation to erf on [0,0.84375] - */ -efx8 = 1.0270333290e+00, /* 0x3f8375d4 */ -pp0 = 1.2837916613e-01, /* 0x3e0375d4 */ -pp1 = -3.2504209876e-01, /* 0xbea66beb */ -pp2 = -2.8481749818e-02, /* 0xbce9528f */ -pp3 = -5.7702702470e-03, /* 0xbbbd1489 */ -pp4 = -2.3763017452e-05, /* 0xb7c756b1 */ -qq1 = 3.9791721106e-01, /* 0x3ecbbbce */ -qq2 = 6.5022252500e-02, /* 0x3d852a63 */ -qq3 = 5.0813062117e-03, /* 0x3ba68116 */ -qq4 = 1.3249473704e-04, /* 0x390aee49 */ -qq5 = -3.9602282413e-06, /* 0xb684e21a */ -/* - * Coefficients for approximation to erf in [0.84375,1.25] - */ -pa0 = -2.3621185683e-03, /* 0xbb1acdc6 */ -pa1 = 4.1485610604e-01, /* 0x3ed46805 */ -pa2 = -3.7220788002e-01, /* 0xbebe9208 */ -pa3 = 3.1834661961e-01, /* 0x3ea2fe54 */ -pa4 = -1.1089469492e-01, /* 0xbde31cc2 */ -pa5 = 3.5478305072e-02, /* 0x3d1151b3 */ -pa6 = -2.1663755178e-03, /* 0xbb0df9c0 */ -qa1 = 1.0642088205e-01, /* 0x3dd9f331 */ -qa2 = 5.4039794207e-01, /* 0x3f0a5785 */ -qa3 = 7.1828655899e-02, /* 0x3d931ae7 */ -qa4 = 1.2617121637e-01, /* 0x3e013307 */ -qa5 = 1.3637083583e-02, /* 0x3c5f6e13 */ -qa6 = 1.1984500103e-02, /* 0x3c445aa3 */ -/* - * Coefficients for approximation to erfc in [1.25,1/0.35] - */ -ra0 = -9.8649440333e-03, /* 0xbc21a093 */ -ra1 = -6.9385856390e-01, /* 0xbf31a0b7 */ -ra2 = -1.0558626175e+01, /* 0xc128f022 */ -ra3 = -6.2375331879e+01, /* 0xc2798057 */ -ra4 = -1.6239666748e+02, /* 0xc322658c */ -ra5 = -1.8460508728e+02, /* 0xc3389ae7 */ -ra6 = -8.1287437439e+01, /* 0xc2a2932b */ -ra7 = -9.8143291473e+00, /* 0xc11d077e */ -sa1 = 1.9651271820e+01, /* 0x419d35ce */ -sa2 = 1.3765776062e+02, /* 0x4309a863 */ -sa3 = 4.3456588745e+02, /* 0x43d9486f */ -sa4 = 6.4538726807e+02, /* 0x442158c9 */ -sa5 = 4.2900814819e+02, /* 0x43d6810b */ -sa6 = 1.0863500214e+02, /* 0x42d9451f */ -sa7 = 6.5702495575e+00, /* 0x40d23f7c */ -sa8 = -6.0424413532e-02, /* 0xbd777f97 */ -/* - * Coefficients for approximation to erfc in [1/.35,28] - */ -rb0 = -9.8649431020e-03, /* 0xbc21a092 */ -rb1 = -7.9928326607e-01, /* 0xbf4c9dd4 */ -rb2 = -1.7757955551e+01, /* 0xc18e104b */ -rb3 = -1.6063638306e+02, /* 0xc320a2ea */ -rb4 = -6.3756646729e+02, /* 0xc41f6441 */ -rb5 = -1.0250950928e+03, /* 0xc480230b */ -rb6 = -4.8351919556e+02, /* 0xc3f1c275 */ -sb1 = 3.0338060379e+01, /* 0x41f2b459 */ -sb2 = 3.2579251099e+02, /* 0x43a2e571 */ -sb3 = 1.5367296143e+03, /* 0x44c01759 */ -sb4 = 3.1998581543e+03, /* 0x4547fdbb */ -sb5 = 2.5530502930e+03, /* 0x451f90ce */ -sb6 = 4.7452853394e+02, /* 0x43ed43a7 */ -sb7 = -2.2440952301e+01; /* 0xc1b38712 */ - -static float erfc1(float x) -{ - float_t s,P,Q; - - s = fabsf(x) - 1; - P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); - Q = 1+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); - return 1 - erx - P/Q; -} - -static float erfc2(uint32_t ix, float x) -{ - float_t s,R,S; - float z; - - if (ix < 0x3fa00000) /* |x| < 1.25 */ - return erfc1(x); - - x = fabsf(x); - s = 1/(x*x); - if (ix < 0x4036db6d) { /* |x| < 1/0.35 */ - R = ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( - ra5+s*(ra6+s*ra7)))))); - S = 1.0f+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( - sa5+s*(sa6+s*(sa7+s*sa8))))))); - } else { /* |x| >= 1/0.35 */ - R = rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( - rb5+s*rb6))))); - S = 1.0f+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( - sb5+s*(sb6+s*sb7)))))); - } - GET_FLOAT_WORD(ix, x); - SET_FLOAT_WORD(z, ix&0xffffe000); - return expf(-z*z - 0.5625f) * expf((z-x)*(z+x) + R/S)/x; -} - -float erff(float x) -{ - float r,s,z,y; - uint32_t ix; - int sign; - - GET_FLOAT_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix >= 0x7f800000) { - /* erf(nan)=nan, erf(+-inf)=+-1 */ - return 1-2*sign + 1/x; - } - if (ix < 0x3f580000) { /* |x| < 0.84375 */ - if (ix < 0x31800000) { /* |x| < 2**-28 */ - /*avoid underflow */ - return 0.125f*(8*x + efx8*x); - } - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = 1+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - return x + x*y; - } - if (ix < 0x40c00000) /* |x| < 6 */ - y = 1 - erfc2(ix,x); - else - y = 1 - 0x1p-120f; - return sign ? -y : y; -} - -float erfcf(float x) -{ - float r,s,z,y; - uint32_t ix; - int sign; - - GET_FLOAT_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix >= 0x7f800000) { - /* erfc(nan)=nan, erfc(+-inf)=0,2 */ - return 2*sign + 1/x; - } - - if (ix < 0x3f580000) { /* |x| < 0.84375 */ - if (ix < 0x23800000) /* |x| < 2**-56 */ - return 1.0f - x; - z = x*x; - r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); - s = 1.0f+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); - y = r/s; - if (sign || ix < 0x3e800000) /* x < 1/4 */ - return 1.0f - (x+x*y); - return 0.5f - (x - 0.5f + x*y); - } - if (ix < 0x41e00000) { /* |x| < 28 */ - return sign ? 2 - erfc2(ix,x) : erfc2(ix,x); - } - return sign ? 2 - 0x1p-120f : 0x1p-120f*0x1p-120f; -} diff --git a/usr/lib/libc/math/erfl.c b/usr/lib/libc/math/erfl.c deleted file mode 100644 index e267c2310..000000000 --- a/usr/lib/libc/math/erfl.c +++ /dev/null @@ -1,353 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_erfl.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* double erf(double x) - * double erfc(double x) - * x - * 2 |\ - * erf(x) = --------- | exp(-t*t)dt - * sqrt(pi) \| - * 0 - * - * erfc(x) = 1-erf(x) - * Note that - * erf(-x) = -erf(x) - * erfc(-x) = 2 - erfc(x) - * - * Method: - * 1. For |x| in [0, 0.84375] - * erf(x) = x + x*R(x^2) - * erfc(x) = 1 - erf(x) if x in [-.84375,0.25] - * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375] - * Remark. The formula is derived by noting - * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....) - * and that - * 2/sqrt(pi) = 1.128379167095512573896158903121545171688 - * is close to one. The interval is chosen because the fix - * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is - * near 0.6174), and by some experiment, 0.84375 is chosen to - * guarantee the error is less than one ulp for erf. - * - * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and - * c = 0.84506291151 rounded to single (24 bits) - * erf(x) = sign(x) * (c + P1(s)/Q1(s)) - * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0 - * 1+(c+P1(s)/Q1(s)) if x < 0 - * Remark: here we use the taylor series expansion at x=1. - * erf(1+s) = erf(1) + s*Poly(s) - * = 0.845.. + P1(s)/Q1(s) - * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25] - * - * 3. For x in [1.25,1/0.35(~2.857143)], - * erfc(x) = (1/x)*exp(-x*x-0.5625+R1(z)/S1(z)) - * z=1/x^2 - * erf(x) = 1 - erfc(x) - * - * 4. For x in [1/0.35,107] - * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0 - * = 2.0 - (1/x)*exp(-x*x-0.5625+R2(z)/S2(z)) - * if -6.666 x >= 107 - * erf(x) = sign(x) *(1 - tiny) (raise inexact) - * erfc(x) = tiny*tiny (raise underflow) if x > 0 - * = 2 - tiny if x<0 - * - * 7. Special case: - * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1, - * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2, - * erfc/erf(NaN) is NaN - */ - - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double erfl(long double x) -{ - return erf(x); -} -long double erfcl(long double x) -{ - return erfc(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -static const long double -erx = 0.845062911510467529296875L, - -/* - * Coefficients for approximation to erf on [0,0.84375] - */ -/* 8 * (2/sqrt(pi) - 1) */ -efx8 = 1.0270333367641005911692712249723613735048E0L, -pp[6] = { - 1.122751350964552113068262337278335028553E6L, - -2.808533301997696164408397079650699163276E6L, - -3.314325479115357458197119660818768924100E5L, - -6.848684465326256109712135497895525446398E4L, - -2.657817695110739185591505062971929859314E3L, - -1.655310302737837556654146291646499062882E2L, -}, -qq[6] = { - 8.745588372054466262548908189000448124232E6L, - 3.746038264792471129367533128637019611485E6L, - 7.066358783162407559861156173539693900031E5L, - 7.448928604824620999413120955705448117056E4L, - 4.511583986730994111992253980546131408924E3L, - 1.368902937933296323345610240009071254014E2L, - /* 1.000000000000000000000000000000000000000E0 */ -}, - -/* - * Coefficients for approximation to erf in [0.84375,1.25] - */ -/* erf(x+1) = 0.845062911510467529296875 + pa(x)/qa(x) - -0.15625 <= x <= +.25 - Peak relative error 8.5e-22 */ -pa[8] = { - -1.076952146179812072156734957705102256059E0L, - 1.884814957770385593365179835059971587220E2L, - -5.339153975012804282890066622962070115606E1L, - 4.435910679869176625928504532109635632618E1L, - 1.683219516032328828278557309642929135179E1L, - -2.360236618396952560064259585299045804293E0L, - 1.852230047861891953244413872297940938041E0L, - 9.394994446747752308256773044667843200719E-2L, -}, -qa[7] = { - 4.559263722294508998149925774781887811255E2L, - 3.289248982200800575749795055149780689738E2L, - 2.846070965875643009598627918383314457912E2L, - 1.398715859064535039433275722017479994465E2L, - 6.060190733759793706299079050985358190726E1L, - 2.078695677795422351040502569964299664233E1L, - 4.641271134150895940966798357442234498546E0L, - /* 1.000000000000000000000000000000000000000E0 */ -}, - -/* - * Coefficients for approximation to erfc in [1.25,1/0.35] - */ -/* erfc(1/x) = x exp (-1/x^2 - 0.5625 + ra(x^2)/sa(x^2)) - 1/2.85711669921875 < 1/x < 1/1.25 - Peak relative error 3.1e-21 */ -ra[] = { - 1.363566591833846324191000679620738857234E-1L, - 1.018203167219873573808450274314658434507E1L, - 1.862359362334248675526472871224778045594E2L, - 1.411622588180721285284945138667933330348E3L, - 5.088538459741511988784440103218342840478E3L, - 8.928251553922176506858267311750789273656E3L, - 7.264436000148052545243018622742770549982E3L, - 2.387492459664548651671894725748959751119E3L, - 2.220916652813908085449221282808458466556E2L, -}, -sa[] = { - -1.382234625202480685182526402169222331847E1L, - -3.315638835627950255832519203687435946482E2L, - -2.949124863912936259747237164260785326692E3L, - -1.246622099070875940506391433635999693661E4L, - -2.673079795851665428695842853070996219632E4L, - -2.880269786660559337358397106518918220991E4L, - -1.450600228493968044773354186390390823713E4L, - -2.874539731125893533960680525192064277816E3L, - -1.402241261419067750237395034116942296027E2L, - /* 1.000000000000000000000000000000000000000E0 */ -}, - -/* - * Coefficients for approximation to erfc in [1/.35,107] - */ -/* erfc(1/x) = x exp (-1/x^2 - 0.5625 + rb(x^2)/sb(x^2)) - 1/6.6666259765625 < 1/x < 1/2.85711669921875 - Peak relative error 4.2e-22 */ -rb[] = { - -4.869587348270494309550558460786501252369E-5L, - -4.030199390527997378549161722412466959403E-3L, - -9.434425866377037610206443566288917589122E-2L, - -9.319032754357658601200655161585539404155E-1L, - -4.273788174307459947350256581445442062291E0L, - -8.842289940696150508373541814064198259278E0L, - -7.069215249419887403187988144752613025255E0L, - -1.401228723639514787920274427443330704764E0L, -}, -sb[] = { - 4.936254964107175160157544545879293019085E-3L, - 1.583457624037795744377163924895349412015E-1L, - 1.850647991850328356622940552450636420484E0L, - 9.927611557279019463768050710008450625415E0L, - 2.531667257649436709617165336779212114570E1L, - 2.869752886406743386458304052862814690045E1L, - 1.182059497870819562441683560749192539345E1L, - /* 1.000000000000000000000000000000000000000E0 */ -}, -/* erfc(1/x) = x exp (-1/x^2 - 0.5625 + rc(x^2)/sc(x^2)) - 1/107 <= 1/x <= 1/6.6666259765625 - Peak relative error 1.1e-21 */ -rc[] = { - -8.299617545269701963973537248996670806850E-5L, - -6.243845685115818513578933902532056244108E-3L, - -1.141667210620380223113693474478394397230E-1L, - -7.521343797212024245375240432734425789409E-1L, - -1.765321928311155824664963633786967602934E0L, - -1.029403473103215800456761180695263439188E0L, -}, -sc[] = { - 8.413244363014929493035952542677768808601E-3L, - 2.065114333816877479753334599639158060979E-1L, - 1.639064941530797583766364412782135680148E0L, - 4.936788463787115555582319302981666347450E0L, - 5.005177727208955487404729933261347679090E0L, - /* 1.000000000000000000000000000000000000000E0 */ -}; - -static long double erfc1(long double x) -{ - long double s,P,Q; - - s = fabsl(x) - 1; - P = pa[0] + s * (pa[1] + s * (pa[2] + - s * (pa[3] + s * (pa[4] + s * (pa[5] + s * (pa[6] + s * pa[7])))))); - Q = qa[0] + s * (qa[1] + s * (qa[2] + - s * (qa[3] + s * (qa[4] + s * (qa[5] + s * (qa[6] + s)))))); - return 1 - erx - P / Q; -} - -static long double erfc2(uint32_t ix, long double x) -{ - union ldshape u; - long double s,z,R,S; - - if (ix < 0x3fffa000) /* 0.84375 <= |x| < 1.25 */ - return erfc1(x); - - x = fabsl(x); - s = 1 / (x * x); - if (ix < 0x4000b6db) { /* 1.25 <= |x| < 2.857 ~ 1/.35 */ - R = ra[0] + s * (ra[1] + s * (ra[2] + s * (ra[3] + s * (ra[4] + - s * (ra[5] + s * (ra[6] + s * (ra[7] + s * ra[8]))))))); - S = sa[0] + s * (sa[1] + s * (sa[2] + s * (sa[3] + s * (sa[4] + - s * (sa[5] + s * (sa[6] + s * (sa[7] + s * (sa[8] + s)))))))); - } else if (ix < 0x4001d555) { /* 2.857 <= |x| < 6.6666259765625 */ - R = rb[0] + s * (rb[1] + s * (rb[2] + s * (rb[3] + s * (rb[4] + - s * (rb[5] + s * (rb[6] + s * rb[7])))))); - S = sb[0] + s * (sb[1] + s * (sb[2] + s * (sb[3] + s * (sb[4] + - s * (sb[5] + s * (sb[6] + s)))))); - } else { /* 6.666 <= |x| < 107 (erfc only) */ - R = rc[0] + s * (rc[1] + s * (rc[2] + s * (rc[3] + - s * (rc[4] + s * rc[5])))); - S = sc[0] + s * (sc[1] + s * (sc[2] + s * (sc[3] + - s * (sc[4] + s)))); - } - u.f = x; - u.i.m &= -1ULL << 40; - z = u.f; - return expl(-z*z - 0.5625) * expl((z - x) * (z + x) + R / S) / x; -} - -long double erfl(long double x) -{ - long double r, s, z, y; - union ldshape u = {x}; - uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48; - int sign = u.i.se >> 15; - - if (ix >= 0x7fff0000) - /* erf(nan)=nan, erf(+-inf)=+-1 */ - return 1 - 2*sign + 1/x; - if (ix < 0x3ffed800) { /* |x| < 0.84375 */ - if (ix < 0x3fde8000) { /* |x| < 2**-33 */ - return 0.125 * (8 * x + efx8 * x); /* avoid underflow */ - } - z = x * x; - r = pp[0] + z * (pp[1] + - z * (pp[2] + z * (pp[3] + z * (pp[4] + z * pp[5])))); - s = qq[0] + z * (qq[1] + - z * (qq[2] + z * (qq[3] + z * (qq[4] + z * (qq[5] + z))))); - y = r / s; - return x + x * y; - } - if (ix < 0x4001d555) /* |x| < 6.6666259765625 */ - y = 1 - erfc2(ix,x); - else - y = 1 - 0x1p-16382L; - return sign ? -y : y; -} - -long double erfcl(long double x) -{ - long double r, s, z, y; - union ldshape u = {x}; - uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48; - int sign = u.i.se >> 15; - - if (ix >= 0x7fff0000) - /* erfc(nan) = nan, erfc(+-inf) = 0,2 */ - return 2*sign + 1/x; - if (ix < 0x3ffed800) { /* |x| < 0.84375 */ - if (ix < 0x3fbe0000) /* |x| < 2**-65 */ - return 1.0 - x; - z = x * x; - r = pp[0] + z * (pp[1] + - z * (pp[2] + z * (pp[3] + z * (pp[4] + z * pp[5])))); - s = qq[0] + z * (qq[1] + - z * (qq[2] + z * (qq[3] + z * (qq[4] + z * (qq[5] + z))))); - y = r / s; - if (ix < 0x3ffd8000) /* x < 1/4 */ - return 1.0 - (x + x * y); - return 0.5 - (x - 0.5 + x * y); - } - if (ix < 0x4005d600) /* |x| < 107 */ - return sign ? 2 - erfc2(ix,x) : erfc2(ix,x); - y = 0x1p-16382L; - return sign ? 2 - y : y*y; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double erfl(long double x) -{ - return erf(x); -} -long double erfcl(long double x) -{ - return erfc(x); -} -#endif diff --git a/usr/lib/libc/math/exp.c b/usr/lib/libc/math/exp.c deleted file mode 100644 index 9ea672fac..000000000 --- a/usr/lib/libc/math/exp.c +++ /dev/null @@ -1,134 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_exp.c */ -/* - * ==================================================== - * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* exp(x) - * Returns the exponential of x. - * - * Method - * 1. Argument reduction: - * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. - * Given x, find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2. - * - * Here r will be represented as r = hi-lo for better - * accuracy. - * - * 2. Approximation of exp(r) by a special rational function on - * the interval [0,0.34658]: - * Write - * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... - * We use a special Remez algorithm on [0,0.34658] to generate - * a polynomial of degree 5 to approximate R. The maximum error - * of this polynomial approximation is bounded by 2**-59. In - * other words, - * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 - * (where z=r*r, and the values of P1 to P5 are listed below) - * and - * | 5 | -59 - * | 2.0+P1*z+...+P5*z - R(z) | <= 2 - * | | - * The computation of exp(r) thus becomes - * 2*r - * exp(r) = 1 + ---------- - * R(r) - r - * r*c(r) - * = 1 + r + ----------- (for better accuracy) - * 2 - c(r) - * where - * 2 4 10 - * c(r) = r - (P1*r + P2*r + ... + P5*r ). - * - * 3. Scale back to obtain exp(x): - * From step 1, we have - * exp(x) = 2^k * exp(r) - * - * Special cases: - * exp(INF) is INF, exp(NaN) is NaN; - * exp(-INF) is 0, and - * for finite argument, only exp(0)=1 is exact. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Misc. info. - * For IEEE double - * if x > 709.782712893383973096 then exp(x) overflows - * if x < -745.133219101941108420 then exp(x) underflows - */ - -#include "libm.h" - -static const double -half[2] = {0.5,-0.5}, -ln2hi = 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ -ln2lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ -invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ - -double exp(double x) -{ - double_t hi, lo, c, xx, y; - int k, sign; - uint32_t hx; - - GET_HIGH_WORD(hx, x); - sign = hx>>31; - hx &= 0x7fffffff; /* high word of |x| */ - - /* special cases */ - if (hx >= 0x4086232b) { /* if |x| >= 708.39... */ - if (isnan(x)) - return x; - if (x > 709.782712893383973096) { - /* overflow if x!=inf */ - x *= 0x1p1023; - return x; - } - if (x < -708.39641853226410622) { - /* underflow if x!=-inf */ - FORCE_EVAL((float)(-0x1p-149/x)); - if (x < -745.13321910194110842) - return 0; - } - } - - /* argument reduction */ - if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if (hx >= 0x3ff0a2b2) /* if |x| >= 1.5 ln2 */ - k = (int)(invln2*x + half[sign]); - else - k = 1 - sign - sign; - hi = x - k*ln2hi; /* k*ln2hi is exact here */ - lo = k*ln2lo; - x = hi - lo; - } else if (hx > 0x3e300000) { /* if |x| > 2**-28 */ - k = 0; - hi = x; - lo = 0; - } else { - /* inexact if x!=0 */ - FORCE_EVAL(0x1p1023 + x); - return 1 + x; - } - - /* x is now in primary range */ - xx = x*x; - c = x - xx*(P1+xx*(P2+xx*(P3+xx*(P4+xx*P5)))); - y = 1 + (x*c/(2-c) - lo + hi); - if (k == 0) - return y; - return scalbn(y, k); -} diff --git a/usr/lib/libc/math/exp10.c b/usr/lib/libc/math/exp10.c deleted file mode 100644 index 9f5e3c2c5..000000000 --- a/usr/lib/libc/math/exp10.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include "libc.h" - -double exp10(double x) -{ - static const double p10[] = { - 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, - 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, - 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15 - }; - double n, y = modf(x, &n); - union {double f; uint64_t i;} u = {n}; - /* fabs(n) < 16 without raising invalid on nan */ - if ((u.i>>52 & 0x7ff) < 0x3ff+4) { - if (!y) return p10[(int)n+15]; - y = exp2(3.32192809488736234787031942948939 * y); - return y * p10[(int)n+15]; - } - return pow(10.0, x); -} - -weak_alias(exp10, pow10); diff --git a/usr/lib/libc/math/exp10f.c b/usr/lib/libc/math/exp10f.c deleted file mode 100644 index 7a8d44703..000000000 --- a/usr/lib/libc/math/exp10f.c +++ /dev/null @@ -1,23 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include "libc.h" - -float exp10f(float x) -{ - static const float p10[] = { - 1e-7f, 1e-6f, 1e-5f, 1e-4f, 1e-3f, 1e-2f, 1e-1f, - 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 - }; - float n, y = modff(x, &n); - union {float f; uint32_t i;} u = {n}; - /* fabsf(n) < 8 without raising invalid on nan */ - if ((u.i>>23 & 0xff) < 0x7f+3) { - if (!y) return p10[(int)n+7]; - y = exp2f(3.32192809488736234787031942948939f * y); - return y * p10[(int)n+7]; - } - return exp2(3.32192809488736234787031942948939 * x); -} - -weak_alias(exp10f, pow10f); diff --git a/usr/lib/libc/math/exp10l.c b/usr/lib/libc/math/exp10l.c deleted file mode 100644 index b758ebffe..000000000 --- a/usr/lib/libc/math/exp10l.c +++ /dev/null @@ -1,33 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include "libc.h" -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double exp10l(long double x) -{ - return exp10(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double exp10l(long double x) -{ - static const long double p10[] = { - 1e-15L, 1e-14L, 1e-13L, 1e-12L, 1e-11L, 1e-10L, - 1e-9L, 1e-8L, 1e-7L, 1e-6L, 1e-5L, 1e-4L, 1e-3L, 1e-2L, 1e-1L, - 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15 - }; - long double n, y = modfl(x, &n); - union ldshape u = {n}; - /* fabsl(n) < 16 without raising invalid on nan */ - if ((u.i.se & 0x7fff) < 0x3fff+4) { - if (!y) return p10[(int)n+15]; - y = exp2l(3.32192809488736234787031942948939L * y); - return y * p10[(int)n+15]; - } - return powl(10.0, x); -} -#endif - -weak_alias(exp10l, pow10l); diff --git a/usr/lib/libc/math/exp2.c b/usr/lib/libc/math/exp2.c deleted file mode 100644 index e14adba53..000000000 --- a/usr/lib/libc/math/exp2.c +++ /dev/null @@ -1,375 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_exp2.c */ -/*- - * Copyright (c) 2005 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "libm.h" - -#define TBLSIZE 256 - -static const double -redux = 0x1.8p52 / TBLSIZE, -P1 = 0x1.62e42fefa39efp-1, -P2 = 0x1.ebfbdff82c575p-3, -P3 = 0x1.c6b08d704a0a6p-5, -P4 = 0x1.3b2ab88f70400p-7, -P5 = 0x1.5d88003875c74p-10; - -static const double tbl[TBLSIZE * 2] = { -/* exp2(z + eps) eps */ - 0x1.6a09e667f3d5dp-1, 0x1.9880p-44, - 0x1.6b052fa751744p-1, 0x1.8000p-50, - 0x1.6c012750bd9fep-1, -0x1.8780p-45, - 0x1.6cfdcddd476bfp-1, 0x1.ec00p-46, - 0x1.6dfb23c651a29p-1, -0x1.8000p-50, - 0x1.6ef9298593ae3p-1, -0x1.c000p-52, - 0x1.6ff7df9519386p-1, -0x1.fd80p-45, - 0x1.70f7466f42da3p-1, -0x1.c880p-45, - 0x1.71f75e8ec5fc3p-1, 0x1.3c00p-46, - 0x1.72f8286eacf05p-1, -0x1.8300p-44, - 0x1.73f9a48a58152p-1, -0x1.0c00p-47, - 0x1.74fbd35d7ccfcp-1, 0x1.f880p-45, - 0x1.75feb564267f1p-1, 0x1.3e00p-47, - 0x1.77024b1ab6d48p-1, -0x1.7d00p-45, - 0x1.780694fde5d38p-1, -0x1.d000p-50, - 0x1.790b938ac1d00p-1, 0x1.3000p-49, - 0x1.7a11473eb0178p-1, -0x1.d000p-49, - 0x1.7b17b0976d060p-1, 0x1.0400p-45, - 0x1.7c1ed0130c133p-1, 0x1.0000p-53, - 0x1.7d26a62ff8636p-1, -0x1.6900p-45, - 0x1.7e2f336cf4e3bp-1, -0x1.2e00p-47, - 0x1.7f3878491c3e8p-1, -0x1.4580p-45, - 0x1.80427543e1b4ep-1, 0x1.3000p-44, - 0x1.814d2add1071ap-1, 0x1.f000p-47, - 0x1.82589994ccd7ep-1, -0x1.1c00p-45, - 0x1.8364c1eb942d0p-1, 0x1.9d00p-45, - 0x1.8471a4623cab5p-1, 0x1.7100p-43, - 0x1.857f4179f5bbcp-1, 0x1.2600p-45, - 0x1.868d99b4491afp-1, -0x1.2c40p-44, - 0x1.879cad931a395p-1, -0x1.3000p-45, - 0x1.88ac7d98a65b8p-1, -0x1.a800p-45, - 0x1.89bd0a4785800p-1, -0x1.d000p-49, - 0x1.8ace5422aa223p-1, 0x1.3280p-44, - 0x1.8be05bad619fap-1, 0x1.2b40p-43, - 0x1.8cf3216b54383p-1, -0x1.ed00p-45, - 0x1.8e06a5e08664cp-1, -0x1.0500p-45, - 0x1.8f1ae99157807p-1, 0x1.8280p-45, - 0x1.902fed0282c0ep-1, -0x1.cb00p-46, - 0x1.9145b0b91ff96p-1, -0x1.5e00p-47, - 0x1.925c353aa2ff9p-1, 0x1.5400p-48, - 0x1.93737b0cdc64ap-1, 0x1.7200p-46, - 0x1.948b82b5f98aep-1, -0x1.9000p-47, - 0x1.95a44cbc852cbp-1, 0x1.5680p-45, - 0x1.96bdd9a766f21p-1, -0x1.6d00p-44, - 0x1.97d829fde4e2ap-1, -0x1.1000p-47, - 0x1.98f33e47a23a3p-1, 0x1.d000p-45, - 0x1.9a0f170ca0604p-1, -0x1.8a40p-44, - 0x1.9b2bb4d53ff89p-1, 0x1.55c0p-44, - 0x1.9c49182a3f15bp-1, 0x1.6b80p-45, - 0x1.9d674194bb8c5p-1, -0x1.c000p-49, - 0x1.9e86319e3238ep-1, 0x1.7d00p-46, - 0x1.9fa5e8d07f302p-1, 0x1.6400p-46, - 0x1.a0c667b5de54dp-1, -0x1.5000p-48, - 0x1.a1e7aed8eb8f6p-1, 0x1.9e00p-47, - 0x1.a309bec4a2e27p-1, 0x1.ad80p-45, - 0x1.a42c980460a5dp-1, -0x1.af00p-46, - 0x1.a5503b23e259bp-1, 0x1.b600p-47, - 0x1.a674a8af46213p-1, 0x1.8880p-44, - 0x1.a799e1330b3a7p-1, 0x1.1200p-46, - 0x1.a8bfe53c12e8dp-1, 0x1.6c00p-47, - 0x1.a9e6b5579fcd2p-1, -0x1.9b80p-45, - 0x1.ab0e521356fb8p-1, 0x1.b700p-45, - 0x1.ac36bbfd3f381p-1, 0x1.9000p-50, - 0x1.ad5ff3a3c2780p-1, 0x1.4000p-49, - 0x1.ae89f995ad2a3p-1, -0x1.c900p-45, - 0x1.afb4ce622f367p-1, 0x1.6500p-46, - 0x1.b0e07298db790p-1, 0x1.fd40p-45, - 0x1.b20ce6c9a89a9p-1, 0x1.2700p-46, - 0x1.b33a2b84f1a4bp-1, 0x1.d470p-43, - 0x1.b468415b747e7p-1, -0x1.8380p-44, - 0x1.b59728de5593ap-1, 0x1.8000p-54, - 0x1.b6c6e29f1c56ap-1, 0x1.ad00p-47, - 0x1.b7f76f2fb5e50p-1, 0x1.e800p-50, - 0x1.b928cf22749b2p-1, -0x1.4c00p-47, - 0x1.ba5b030a10603p-1, -0x1.d700p-47, - 0x1.bb8e0b79a6f66p-1, 0x1.d900p-47, - 0x1.bcc1e904bc1ffp-1, 0x1.2a00p-47, - 0x1.bdf69c3f3a16fp-1, -0x1.f780p-46, - 0x1.bf2c25bd71db8p-1, -0x1.0a00p-46, - 0x1.c06286141b2e9p-1, -0x1.1400p-46, - 0x1.c199bdd8552e0p-1, 0x1.be00p-47, - 0x1.c2d1cd9fa64eep-1, -0x1.9400p-47, - 0x1.c40ab5fffd02fp-1, -0x1.ed00p-47, - 0x1.c544778fafd15p-1, 0x1.9660p-44, - 0x1.c67f12e57d0cbp-1, -0x1.a100p-46, - 0x1.c7ba88988c1b6p-1, -0x1.8458p-42, - 0x1.c8f6d9406e733p-1, -0x1.a480p-46, - 0x1.ca3405751c4dfp-1, 0x1.b000p-51, - 0x1.cb720dcef9094p-1, 0x1.1400p-47, - 0x1.ccb0f2e6d1689p-1, 0x1.0200p-48, - 0x1.cdf0b555dc412p-1, 0x1.3600p-48, - 0x1.cf3155b5bab3bp-1, -0x1.6900p-47, - 0x1.d072d4a0789bcp-1, 0x1.9a00p-47, - 0x1.d1b532b08c8fap-1, -0x1.5e00p-46, - 0x1.d2f87080d8a85p-1, 0x1.d280p-46, - 0x1.d43c8eacaa203p-1, 0x1.1a00p-47, - 0x1.d5818dcfba491p-1, 0x1.f000p-50, - 0x1.d6c76e862e6a1p-1, -0x1.3a00p-47, - 0x1.d80e316c9834ep-1, -0x1.cd80p-47, - 0x1.d955d71ff6090p-1, 0x1.4c00p-48, - 0x1.da9e603db32aep-1, 0x1.f900p-48, - 0x1.dbe7cd63a8325p-1, 0x1.9800p-49, - 0x1.dd321f301b445p-1, -0x1.5200p-48, - 0x1.de7d5641c05bfp-1, -0x1.d700p-46, - 0x1.dfc97337b9aecp-1, -0x1.6140p-46, - 0x1.e11676b197d5ep-1, 0x1.b480p-47, - 0x1.e264614f5a3e7p-1, 0x1.0ce0p-43, - 0x1.e3b333b16ee5cp-1, 0x1.c680p-47, - 0x1.e502ee78b3fb4p-1, -0x1.9300p-47, - 0x1.e653924676d68p-1, -0x1.5000p-49, - 0x1.e7a51fbc74c44p-1, -0x1.7f80p-47, - 0x1.e8f7977cdb726p-1, -0x1.3700p-48, - 0x1.ea4afa2a490e8p-1, 0x1.5d00p-49, - 0x1.eb9f4867ccae4p-1, 0x1.61a0p-46, - 0x1.ecf482d8e680dp-1, 0x1.5500p-48, - 0x1.ee4aaa2188514p-1, 0x1.6400p-51, - 0x1.efa1bee615a13p-1, -0x1.e800p-49, - 0x1.f0f9c1cb64106p-1, -0x1.a880p-48, - 0x1.f252b376bb963p-1, -0x1.c900p-45, - 0x1.f3ac948dd7275p-1, 0x1.a000p-53, - 0x1.f50765b6e4524p-1, -0x1.4f00p-48, - 0x1.f6632798844fdp-1, 0x1.a800p-51, - 0x1.f7bfdad9cbe38p-1, 0x1.abc0p-48, - 0x1.f91d802243c82p-1, -0x1.4600p-50, - 0x1.fa7c1819e908ep-1, -0x1.b0c0p-47, - 0x1.fbdba3692d511p-1, -0x1.0e00p-51, - 0x1.fd3c22b8f7194p-1, -0x1.0de8p-46, - 0x1.fe9d96b2a23eep-1, 0x1.e430p-49, - 0x1.0000000000000p+0, 0x0.0000p+0, - 0x1.00b1afa5abcbep+0, -0x1.3400p-52, - 0x1.0163da9fb3303p+0, -0x1.2170p-46, - 0x1.02168143b0282p+0, 0x1.a400p-52, - 0x1.02c9a3e77806cp+0, 0x1.f980p-49, - 0x1.037d42e11bbcap+0, -0x1.7400p-51, - 0x1.04315e86e7f89p+0, 0x1.8300p-50, - 0x1.04e5f72f65467p+0, -0x1.a3f0p-46, - 0x1.059b0d315855ap+0, -0x1.2840p-47, - 0x1.0650a0e3c1f95p+0, 0x1.1600p-48, - 0x1.0706b29ddf71ap+0, 0x1.5240p-46, - 0x1.07bd42b72a82dp+0, -0x1.9a00p-49, - 0x1.0874518759bd0p+0, 0x1.6400p-49, - 0x1.092bdf66607c8p+0, -0x1.0780p-47, - 0x1.09e3ecac6f383p+0, -0x1.8000p-54, - 0x1.0a9c79b1f3930p+0, 0x1.fa00p-48, - 0x1.0b5586cf988fcp+0, -0x1.ac80p-48, - 0x1.0c0f145e46c8ap+0, 0x1.9c00p-50, - 0x1.0cc922b724816p+0, 0x1.5200p-47, - 0x1.0d83b23395dd8p+0, -0x1.ad00p-48, - 0x1.0e3ec32d3d1f3p+0, 0x1.bac0p-46, - 0x1.0efa55fdfa9a6p+0, -0x1.4e80p-47, - 0x1.0fb66affed2f0p+0, -0x1.d300p-47, - 0x1.1073028d7234bp+0, 0x1.1500p-48, - 0x1.11301d0125b5bp+0, 0x1.c000p-49, - 0x1.11edbab5e2af9p+0, 0x1.6bc0p-46, - 0x1.12abdc06c31d5p+0, 0x1.8400p-49, - 0x1.136a814f2047dp+0, -0x1.ed00p-47, - 0x1.1429aaea92de9p+0, 0x1.8e00p-49, - 0x1.14e95934f3138p+0, 0x1.b400p-49, - 0x1.15a98c8a58e71p+0, 0x1.5300p-47, - 0x1.166a45471c3dfp+0, 0x1.3380p-47, - 0x1.172b83c7d5211p+0, 0x1.8d40p-45, - 0x1.17ed48695bb9fp+0, -0x1.5d00p-47, - 0x1.18af9388c8d93p+0, -0x1.c880p-46, - 0x1.1972658375d66p+0, 0x1.1f00p-46, - 0x1.1a35beb6fcba7p+0, 0x1.0480p-46, - 0x1.1af99f81387e3p+0, -0x1.7390p-43, - 0x1.1bbe084045d54p+0, 0x1.4e40p-45, - 0x1.1c82f95281c43p+0, -0x1.a200p-47, - 0x1.1d4873168b9b2p+0, 0x1.3800p-49, - 0x1.1e0e75eb44031p+0, 0x1.ac00p-49, - 0x1.1ed5022fcd938p+0, 0x1.1900p-47, - 0x1.1f9c18438cdf7p+0, -0x1.b780p-46, - 0x1.2063b88628d8fp+0, 0x1.d940p-45, - 0x1.212be3578a81ep+0, 0x1.8000p-50, - 0x1.21f49917ddd41p+0, 0x1.b340p-45, - 0x1.22bdda2791323p+0, 0x1.9f80p-46, - 0x1.2387a6e7561e7p+0, -0x1.9c80p-46, - 0x1.2451ffb821427p+0, 0x1.2300p-47, - 0x1.251ce4fb2a602p+0, -0x1.3480p-46, - 0x1.25e85711eceb0p+0, 0x1.2700p-46, - 0x1.26b4565e27d16p+0, 0x1.1d00p-46, - 0x1.2780e341de00fp+0, 0x1.1ee0p-44, - 0x1.284dfe1f5633ep+0, -0x1.4c00p-46, - 0x1.291ba7591bb30p+0, -0x1.3d80p-46, - 0x1.29e9df51fdf09p+0, 0x1.8b00p-47, - 0x1.2ab8a66d10e9bp+0, -0x1.27c0p-45, - 0x1.2b87fd0dada3ap+0, 0x1.a340p-45, - 0x1.2c57e39771af9p+0, -0x1.0800p-46, - 0x1.2d285a6e402d9p+0, -0x1.ed00p-47, - 0x1.2df961f641579p+0, -0x1.4200p-48, - 0x1.2ecafa93e2ecfp+0, -0x1.4980p-45, - 0x1.2f9d24abd8822p+0, -0x1.6300p-46, - 0x1.306fe0a31b625p+0, -0x1.2360p-44, - 0x1.31432edeea50bp+0, -0x1.0df8p-40, - 0x1.32170fc4cd7b8p+0, -0x1.2480p-45, - 0x1.32eb83ba8e9a2p+0, -0x1.5980p-45, - 0x1.33c08b2641766p+0, 0x1.ed00p-46, - 0x1.3496266e3fa27p+0, -0x1.c000p-50, - 0x1.356c55f929f0fp+0, -0x1.0d80p-44, - 0x1.36431a2de88b9p+0, 0x1.2c80p-45, - 0x1.371a7373aaa39p+0, 0x1.0600p-45, - 0x1.37f26231e74fep+0, -0x1.6600p-46, - 0x1.38cae6d05d838p+0, -0x1.ae00p-47, - 0x1.39a401b713ec3p+0, -0x1.4720p-43, - 0x1.3a7db34e5a020p+0, 0x1.8200p-47, - 0x1.3b57fbfec6e95p+0, 0x1.e800p-44, - 0x1.3c32dc313a8f2p+0, 0x1.f800p-49, - 0x1.3d0e544ede122p+0, -0x1.7a00p-46, - 0x1.3dea64c1234bbp+0, 0x1.6300p-45, - 0x1.3ec70df1c4eccp+0, -0x1.8a60p-43, - 0x1.3fa4504ac7e8cp+0, -0x1.cdc0p-44, - 0x1.40822c367a0bbp+0, 0x1.5b80p-45, - 0x1.4160a21f72e95p+0, 0x1.ec00p-46, - 0x1.423fb27094646p+0, -0x1.3600p-46, - 0x1.431f5d950a920p+0, 0x1.3980p-45, - 0x1.43ffa3f84b9ebp+0, 0x1.a000p-48, - 0x1.44e0860618919p+0, -0x1.6c00p-48, - 0x1.45c2042a7d201p+0, -0x1.bc00p-47, - 0x1.46a41ed1d0016p+0, -0x1.2800p-46, - 0x1.4786d668b3326p+0, 0x1.0e00p-44, - 0x1.486a2b5c13c00p+0, -0x1.d400p-45, - 0x1.494e1e192af04p+0, 0x1.c200p-47, - 0x1.4a32af0d7d372p+0, -0x1.e500p-46, - 0x1.4b17dea6db801p+0, 0x1.7800p-47, - 0x1.4bfdad53629e1p+0, -0x1.3800p-46, - 0x1.4ce41b817c132p+0, 0x1.0800p-47, - 0x1.4dcb299fddddbp+0, 0x1.c700p-45, - 0x1.4eb2d81d8ab96p+0, -0x1.ce00p-46, - 0x1.4f9b2769d2d02p+0, 0x1.9200p-46, - 0x1.508417f4531c1p+0, -0x1.8c00p-47, - 0x1.516daa2cf662ap+0, -0x1.a000p-48, - 0x1.5257de83f51eap+0, 0x1.a080p-43, - 0x1.5342b569d4edap+0, -0x1.6d80p-45, - 0x1.542e2f4f6ac1ap+0, -0x1.2440p-44, - 0x1.551a4ca5d94dbp+0, 0x1.83c0p-43, - 0x1.56070dde9116bp+0, 0x1.4b00p-45, - 0x1.56f4736b529dep+0, 0x1.15a0p-43, - 0x1.57e27dbe2c40ep+0, -0x1.9e00p-45, - 0x1.58d12d497c76fp+0, -0x1.3080p-45, - 0x1.59c0827ff0b4cp+0, 0x1.dec0p-43, - 0x1.5ab07dd485427p+0, -0x1.4000p-51, - 0x1.5ba11fba87af4p+0, 0x1.0080p-44, - 0x1.5c9268a59460bp+0, -0x1.6c80p-45, - 0x1.5d84590998e3fp+0, 0x1.69a0p-43, - 0x1.5e76f15ad20e1p+0, -0x1.b400p-46, - 0x1.5f6a320dcebcap+0, 0x1.7700p-46, - 0x1.605e1b976dcb8p+0, 0x1.6f80p-45, - 0x1.6152ae6cdf715p+0, 0x1.1000p-47, - 0x1.6247eb03a5531p+0, -0x1.5d00p-46, - 0x1.633dd1d1929b5p+0, -0x1.2d00p-46, - 0x1.6434634ccc313p+0, -0x1.a800p-49, - 0x1.652b9febc8efap+0, -0x1.8600p-45, - 0x1.6623882553397p+0, 0x1.1fe0p-40, - 0x1.671c1c708328ep+0, -0x1.7200p-44, - 0x1.68155d44ca97ep+0, 0x1.6800p-49, - 0x1.690f4b19e9471p+0, -0x1.9780p-45, -}; - -/* - * exp2(x): compute the base 2 exponential of x - * - * Accuracy: Peak error < 0.503 ulp for normalized results. - * - * Method: (accurate tables) - * - * Reduce x: - * x = k + y, for integer k and |y| <= 1/2. - * Thus we have exp2(x) = 2**k * exp2(y). - * - * Reduce y: - * y = i/TBLSIZE + z - eps[i] for integer i near y * TBLSIZE. - * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z - eps[i]), - * with |z - eps[i]| <= 2**-9 + 2**-39 for the table used. - * - * We compute exp2(i/TBLSIZE) via table lookup and exp2(z - eps[i]) via - * a degree-5 minimax polynomial with maximum error under 1.3 * 2**-61. - * The values in exp2t[] and eps[] are chosen such that - * exp2t[i] = exp2(i/TBLSIZE + eps[i]), and eps[i] is a small offset such - * that exp2t[i] is accurate to 2**-64. - * - * Note that the range of i is +-TBLSIZE/2, so we actually index the tables - * by i0 = i + TBLSIZE/2. For cache efficiency, exp2t[] and eps[] are - * virtual tables, interleaved in the real table tbl[]. - * - * This method is due to Gal, with many details due to Gal and Bachelis: - * - * Gal, S. and Bachelis, B. An Accurate Elementary Mathematical Library - * for the IEEE Floating Point Standard. TOMS 17(1), 26-46 (1991). - */ -double exp2(double x) -{ - double_t r, t, z; - uint32_t ix, i0; - union {double f; uint64_t i;} u = {x}; - union {uint32_t u; int32_t i;} k; - - /* Filter out exceptional cases. */ - ix = u.i>>32 & 0x7fffffff; - if (ix >= 0x408ff000) { /* |x| >= 1022 or nan */ - if (ix >= 0x40900000 && u.i>>63 == 0) { /* x >= 1024 or nan */ - /* overflow */ - x *= 0x1p1023; - return x; - } - if (ix >= 0x7ff00000) /* -inf or -nan */ - return -1/x; - if (u.i>>63) { /* x <= -1022 */ - /* underflow */ - if (x <= -1075 || x - 0x1p52 + 0x1p52 != x) - FORCE_EVAL((float)(-0x1p-149/x)); - if (x <= -1075) - return 0; - } - } else if (ix < 0x3c900000) { /* |x| < 0x1p-54 */ - return 1.0 + x; - } - - /* Reduce x, computing z, i0, and k. */ - u.f = x + redux; - i0 = u.i; - i0 += TBLSIZE / 2; - k.u = i0 / TBLSIZE * TBLSIZE; - k.i /= TBLSIZE; - i0 %= TBLSIZE; - u.f -= redux; - z = x - u.f; - - /* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */ - t = tbl[2*i0]; /* exp2t[i0] */ - z -= tbl[2*i0 + 1]; /* eps[i0] */ - r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5)))); - - return scalbn(r, k.i); -} diff --git a/usr/lib/libc/math/exp2f.c b/usr/lib/libc/math/exp2f.c deleted file mode 100644 index 296b63436..000000000 --- a/usr/lib/libc/math/exp2f.c +++ /dev/null @@ -1,126 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_exp2f.c */ -/*- - * Copyright (c) 2005 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "libm.h" - -#define TBLSIZE 16 - -static const float -redux = 0x1.8p23f / TBLSIZE, -P1 = 0x1.62e430p-1f, -P2 = 0x1.ebfbe0p-3f, -P3 = 0x1.c6b348p-5f, -P4 = 0x1.3b2c9cp-7f; - -static const double exp2ft[TBLSIZE] = { - 0x1.6a09e667f3bcdp-1, - 0x1.7a11473eb0187p-1, - 0x1.8ace5422aa0dbp-1, - 0x1.9c49182a3f090p-1, - 0x1.ae89f995ad3adp-1, - 0x1.c199bdd85529cp-1, - 0x1.d5818dcfba487p-1, - 0x1.ea4afa2a490dap-1, - 0x1.0000000000000p+0, - 0x1.0b5586cf9890fp+0, - 0x1.172b83c7d517bp+0, - 0x1.2387a6e756238p+0, - 0x1.306fe0a31b715p+0, - 0x1.3dea64c123422p+0, - 0x1.4bfdad5362a27p+0, - 0x1.5ab07dd485429p+0, -}; - -/* - * exp2f(x): compute the base 2 exponential of x - * - * Accuracy: Peak error < 0.501 ulp; location of peak: -0.030110927. - * - * Method: (equally-spaced tables) - * - * Reduce x: - * x = k + y, for integer k and |y| <= 1/2. - * Thus we have exp2f(x) = 2**k * exp2(y). - * - * Reduce y: - * y = i/TBLSIZE + z for integer i near y * TBLSIZE. - * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z), - * with |z| <= 2**-(TBLSIZE+1). - * - * We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a - * degree-4 minimax polynomial with maximum error under 1.4 * 2**-33. - * Using double precision for everything except the reduction makes - * roundoff error insignificant and simplifies the scaling step. - * - * This method is due to Tang, but I do not use his suggested parameters: - * - * Tang, P. Table-driven Implementation of the Exponential Function - * in IEEE Floating-Point Arithmetic. TOMS 15(2), 144-157 (1989). - */ -float exp2f(float x) -{ - double_t t, r, z; - union {float f; uint32_t i;} u = {x}; - union {double f; uint64_t i;} uk; - uint32_t ix, i0, k; - - /* Filter out exceptional cases. */ - ix = u.i & 0x7fffffff; - if (ix > 0x42fc0000) { /* |x| > 126 */ - if (ix > 0x7f800000) /* NaN */ - return x; - if (u.i >= 0x43000000 && u.i < 0x80000000) { /* x >= 128 */ - x *= 0x1p127f; - return x; - } - if (u.i >= 0x80000000) { /* x < -126 */ - if (u.i >= 0xc3160000 || (u.i & 0x0000ffff)) - FORCE_EVAL(-0x1p-149f/x); - if (u.i >= 0xc3160000) /* x <= -150 */ - return 0; - } - } else if (ix <= 0x33000000) { /* |x| <= 0x1p-25 */ - return 1.0f + x; - } - - /* Reduce x, computing z, i0, and k. */ - u.f = x + redux; - i0 = u.i; - i0 += TBLSIZE / 2; - k = i0 / TBLSIZE; - uk.i = (uint64_t)(0x3ff + k)<<52; - i0 &= TBLSIZE - 1; - u.f -= redux; - z = x - u.f; - /* Compute r = exp2(y) = exp2ft[i0] * p(z). */ - r = exp2ft[i0]; - t = r * z; - r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4); - - /* Scale by 2**k */ - return r * uk.f; -} diff --git a/usr/lib/libc/math/exp2l.c b/usr/lib/libc/math/exp2l.c deleted file mode 100644 index 3565c1e67..000000000 --- a/usr/lib/libc/math/exp2l.c +++ /dev/null @@ -1,619 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/ld80/s_exp2l.c and /usr/src/lib/msun/ld128/s_exp2l.c */ -/*- - * Copyright (c) 2005-2008 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double exp2l(long double x) -{ - return exp2(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -#define TBLBITS 7 -#define TBLSIZE (1 << TBLBITS) - -static const double -redux = 0x1.8p63 / TBLSIZE, -P1 = 0x1.62e42fefa39efp-1, -P2 = 0x1.ebfbdff82c58fp-3, -P3 = 0x1.c6b08d7049fap-5, -P4 = 0x1.3b2ab6fba4da5p-7, -P5 = 0x1.5d8804780a736p-10, -P6 = 0x1.430918835e33dp-13; - -static const double tbl[TBLSIZE * 2] = { - 0x1.6a09e667f3bcdp-1, -0x1.bdd3413b2648p-55, - 0x1.6c012750bdabfp-1, -0x1.2895667ff0cp-57, - 0x1.6dfb23c651a2fp-1, -0x1.bbe3a683c88p-58, - 0x1.6ff7df9519484p-1, -0x1.83c0f25860fp-56, - 0x1.71f75e8ec5f74p-1, -0x1.16e4786887bp-56, - 0x1.73f9a48a58174p-1, -0x1.0a8d96c65d5p-55, - 0x1.75feb564267c9p-1, -0x1.0245957316ep-55, - 0x1.780694fde5d3fp-1, 0x1.866b80a0216p-55, - 0x1.7a11473eb0187p-1, -0x1.41577ee0499p-56, - 0x1.7c1ed0130c132p-1, 0x1.f124cd1164ep-55, - 0x1.7e2f336cf4e62p-1, 0x1.05d02ba157ap-57, - 0x1.80427543e1a12p-1, -0x1.27c86626d97p-55, - 0x1.82589994cce13p-1, -0x1.d4c1dd41533p-55, - 0x1.8471a4623c7adp-1, -0x1.8d684a341cep-56, - 0x1.868d99b4492edp-1, -0x1.fc6f89bd4f68p-55, - 0x1.88ac7d98a6699p-1, 0x1.994c2f37cb5p-55, - 0x1.8ace5422aa0dbp-1, 0x1.6e9f156864bp-55, - 0x1.8cf3216b5448cp-1, -0x1.0d55e32e9e4p-57, - 0x1.8f1ae99157736p-1, 0x1.5cc13a2e397p-56, - 0x1.9145b0b91ffc6p-1, -0x1.dd6792e5825p-55, - 0x1.93737b0cdc5e5p-1, -0x1.75fc781b58p-58, - 0x1.95a44cbc8520fp-1, -0x1.64b7c96a5fp-57, - 0x1.97d829fde4e5p-1, -0x1.d185b7c1b86p-55, - 0x1.9a0f170ca07bap-1, -0x1.173bd91cee6p-55, - 0x1.9c49182a3f09p-1, 0x1.c7c46b071f2p-57, - 0x1.9e86319e32323p-1, 0x1.824ca78e64cp-57, - 0x1.a0c667b5de565p-1, -0x1.359495d1cd5p-55, - 0x1.a309bec4a2d33p-1, 0x1.6305c7ddc368p-55, - 0x1.a5503b23e255dp-1, -0x1.d2f6edb8d42p-55, - 0x1.a799e1330b358p-1, 0x1.bcb7ecac564p-55, - 0x1.a9e6b5579fdbfp-1, 0x1.0fac90ef7fdp-55, - 0x1.ac36bbfd3f37ap-1, -0x1.f9234cae76dp-56, - 0x1.ae89f995ad3adp-1, 0x1.7a1cd345dcc8p-55, - 0x1.b0e07298db666p-1, -0x1.bdef54c80e4p-55, - 0x1.b33a2b84f15fbp-1, -0x1.2805e3084d8p-58, - 0x1.b59728de5593ap-1, -0x1.c71dfbbba6ep-55, - 0x1.b7f76f2fb5e47p-1, -0x1.5584f7e54acp-57, - 0x1.ba5b030a1064ap-1, -0x1.efcd30e5429p-55, - 0x1.bcc1e904bc1d2p-1, 0x1.23dd07a2d9fp-56, - 0x1.bf2c25bd71e09p-1, -0x1.efdca3f6b9c8p-55, - 0x1.c199bdd85529cp-1, 0x1.11065895049p-56, - 0x1.c40ab5fffd07ap-1, 0x1.b4537e083c6p-55, - 0x1.c67f12e57d14bp-1, 0x1.2884dff483c8p-55, - 0x1.c8f6d9406e7b5p-1, 0x1.1acbc48805cp-57, - 0x1.cb720dcef9069p-1, 0x1.503cbd1e94ap-57, - 0x1.cdf0b555dc3fap-1, -0x1.dd83b53829dp-56, - 0x1.d072d4a07897cp-1, -0x1.cbc3743797a8p-55, - 0x1.d2f87080d89f2p-1, -0x1.d487b719d858p-55, - 0x1.d5818dcfba487p-1, 0x1.2ed02d75b37p-56, - 0x1.d80e316c98398p-1, -0x1.11ec18bedep-55, - 0x1.da9e603db3285p-1, 0x1.c2300696db5p-55, - 0x1.dd321f301b46p-1, 0x1.2da5778f019p-55, - 0x1.dfc97337b9b5fp-1, -0x1.1a5cd4f184b8p-55, - 0x1.e264614f5a129p-1, -0x1.7b627817a148p-55, - 0x1.e502ee78b3ff6p-1, 0x1.39e8980a9cdp-56, - 0x1.e7a51fbc74c83p-1, 0x1.2d522ca0c8ep-55, - 0x1.ea4afa2a490dap-1, -0x1.e9c23179c288p-55, - 0x1.ecf482d8e67f1p-1, -0x1.c93f3b411ad8p-55, - 0x1.efa1bee615a27p-1, 0x1.dc7f486a4b68p-55, - 0x1.f252b376bba97p-1, 0x1.3a1a5bf0d8e8p-55, - 0x1.f50765b6e454p-1, 0x1.9d3e12dd8a18p-55, - 0x1.f7bfdad9cbe14p-1, -0x1.dbb12d00635p-55, - 0x1.fa7c1819e90d8p-1, 0x1.74853f3a593p-56, - 0x1.fd3c22b8f71f1p-1, 0x1.2eb74966578p-58, - 0x1p+0, 0x0p+0, - 0x1.0163da9fb3335p+0, 0x1.b61299ab8cd8p-54, - 0x1.02c9a3e778061p+0, -0x1.19083535b08p-56, - 0x1.04315e86e7f85p+0, -0x1.0a31c1977c98p-54, - 0x1.059b0d3158574p+0, 0x1.d73e2a475b4p-55, - 0x1.0706b29ddf6dep+0, -0x1.c91dfe2b13cp-55, - 0x1.0874518759bc8p+0, 0x1.186be4bb284p-57, - 0x1.09e3ecac6f383p+0, 0x1.14878183161p-54, - 0x1.0b5586cf9890fp+0, 0x1.8a62e4adc61p-54, - 0x1.0cc922b7247f7p+0, 0x1.01edc16e24f8p-54, - 0x1.0e3ec32d3d1a2p+0, 0x1.03a1727c58p-59, - 0x1.0fb66affed31bp+0, -0x1.b9bedc44ebcp-57, - 0x1.11301d0125b51p+0, -0x1.6c51039449bp-54, - 0x1.12abdc06c31ccp+0, -0x1.1b514b36ca8p-58, - 0x1.1429aaea92dep+0, -0x1.32fbf9af1368p-54, - 0x1.15a98c8a58e51p+0, 0x1.2406ab9eeabp-55, - 0x1.172b83c7d517bp+0, -0x1.19041b9d78ap-55, - 0x1.18af9388c8deap+0, -0x1.11023d1970f8p-54, - 0x1.1a35beb6fcb75p+0, 0x1.e5b4c7b4969p-55, - 0x1.1bbe084045cd4p+0, -0x1.95386352ef6p-54, - 0x1.1d4873168b9aap+0, 0x1.e016e00a264p-54, - 0x1.1ed5022fcd91dp+0, -0x1.1df98027bb78p-54, - 0x1.2063b88628cd6p+0, 0x1.dc775814a85p-55, - 0x1.21f49917ddc96p+0, 0x1.2a97e9494a6p-55, - 0x1.2387a6e756238p+0, 0x1.9b07eb6c7058p-54, - 0x1.251ce4fb2a63fp+0, 0x1.ac155bef4f5p-55, - 0x1.26b4565e27cddp+0, 0x1.2bd339940eap-55, - 0x1.284dfe1f56381p+0, -0x1.a4c3a8c3f0d8p-54, - 0x1.29e9df51fdee1p+0, 0x1.612e8afad12p-55, - 0x1.2b87fd0dad99p+0, -0x1.10adcd6382p-59, - 0x1.2d285a6e4030bp+0, 0x1.0024754db42p-54, - 0x1.2ecafa93e2f56p+0, 0x1.1ca0f45d524p-56, - 0x1.306fe0a31b715p+0, 0x1.6f46ad23183p-55, - 0x1.32170fc4cd831p+0, 0x1.a9ce78e1804p-55, - 0x1.33c08b26416ffp+0, 0x1.327218436598p-54, - 0x1.356c55f929ff1p+0, -0x1.b5cee5c4e46p-55, - 0x1.371a7373aa9cbp+0, -0x1.63aeabf42ebp-54, - 0x1.38cae6d05d866p+0, -0x1.e958d3c99048p-54, - 0x1.3a7db34e59ff7p+0, -0x1.5e436d661f6p-56, - 0x1.3c32dc313a8e5p+0, -0x1.efff8375d2ap-54, - 0x1.3dea64c123422p+0, 0x1.ada0911f09fp-55, - 0x1.3fa4504ac801cp+0, -0x1.7d023f956fap-54, - 0x1.4160a21f72e2ap+0, -0x1.ef3691c309p-58, - 0x1.431f5d950a897p+0, -0x1.1c7dde35f7ap-55, - 0x1.44e086061892dp+0, 0x1.89b7a04ef8p-59, - 0x1.46a41ed1d0057p+0, 0x1.c944bd1648a8p-54, - 0x1.486a2b5c13cdp+0, 0x1.3c1a3b69062p-56, - 0x1.4a32af0d7d3dep+0, 0x1.9cb62f3d1be8p-54, - 0x1.4bfdad5362a27p+0, 0x1.d4397afec42p-56, - 0x1.4dcb299fddd0dp+0, 0x1.8ecdbbc6a78p-54, - 0x1.4f9b2769d2ca7p+0, -0x1.4b309d25958p-54, - 0x1.516daa2cf6642p+0, -0x1.f768569bd94p-55, - 0x1.5342b569d4f82p+0, -0x1.07abe1db13dp-55, - 0x1.551a4ca5d920fp+0, -0x1.d689cefede6p-55, - 0x1.56f4736b527dap+0, 0x1.9bb2c011d938p-54, - 0x1.58d12d497c7fdp+0, 0x1.295e15b9a1ep-55, - 0x1.5ab07dd485429p+0, 0x1.6324c0546478p-54, - 0x1.5c9268a5946b7p+0, 0x1.c4b1b81698p-60, - 0x1.5e76f15ad2148p+0, 0x1.ba6f93080e68p-54, - 0x1.605e1b976dc09p+0, -0x1.3e2429b56de8p-54, - 0x1.6247eb03a5585p+0, -0x1.383c17e40b48p-54, - 0x1.6434634ccc32p+0, -0x1.c483c759d89p-55, - 0x1.6623882552225p+0, -0x1.bb60987591cp-54, - 0x1.68155d44ca973p+0, 0x1.038ae44f74p-57, -}; - -/* - * exp2l(x): compute the base 2 exponential of x - * - * Accuracy: Peak error < 0.511 ulp. - * - * Method: (equally-spaced tables) - * - * Reduce x: - * x = 2**k + y, for integer k and |y| <= 1/2. - * Thus we have exp2l(x) = 2**k * exp2(y). - * - * Reduce y: - * y = i/TBLSIZE + z for integer i near y * TBLSIZE. - * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z), - * with |z| <= 2**-(TBLBITS+1). - * - * We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a - * degree-6 minimax polynomial with maximum error under 2**-69. - * The table entries each have 104 bits of accuracy, encoded as - * a pair of double precision values. - */ -long double exp2l(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - long double r, z; - uint32_t i0; - union {uint32_t u; int32_t i;} k; - - /* Filter out exceptional cases. */ - if (e >= 0x3fff + 13) { /* |x| >= 8192 or x is NaN */ - if (u.i.se >= 0x3fff + 14 && u.i.se >> 15 == 0) - /* overflow */ - return x * 0x1p16383L; - if (e == 0x7fff) /* -inf or -nan */ - return -1/x; - if (x < -16382) { - if (x <= -16446 || x - 0x1p63 + 0x1p63 != x) - /* underflow */ - FORCE_EVAL((float)(-0x1p-149/x)); - if (x <= -16446) - return 0; - } - } else if (e < 0x3fff - 64) { - return 1 + x; - } - - /* - * Reduce x, computing z, i0, and k. The low bits of x + redux - * contain the 16-bit integer part of the exponent (k) followed by - * TBLBITS fractional bits (i0). We use bit tricks to extract these - * as integers, then set z to the remainder. - * - * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8. - * Then the low-order word of x + redux is 0x000abc12, - * We split this into k = 0xabc and i0 = 0x12 (adjusted to - * index into the table), then we compute z = 0x0.003456p0. - */ - u.f = x + redux; - i0 = u.i.m + TBLSIZE / 2; - k.u = i0 / TBLSIZE * TBLSIZE; - k.i /= TBLSIZE; - i0 %= TBLSIZE; - u.f -= redux; - z = x - u.f; - - /* Compute r = exp2l(y) = exp2lt[i0] * p(z). */ - long double t_hi = tbl[2*i0]; - long double t_lo = tbl[2*i0 + 1]; - /* XXX This gives > 1 ulp errors outside of FE_TONEAREST mode */ - r = t_lo + (t_hi + t_lo) * z * (P1 + z * (P2 + z * (P3 + z * (P4 - + z * (P5 + z * P6))))) + t_hi; - - return scalbnl(r, k.i); -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -#define TBLBITS 7 -#define TBLSIZE (1 << TBLBITS) - -static const long double - P1 = 0x1.62e42fefa39ef35793c7673007e6p-1L, - P2 = 0x1.ebfbdff82c58ea86f16b06ec9736p-3L, - P3 = 0x1.c6b08d704a0bf8b33a762bad3459p-5L, - P4 = 0x1.3b2ab6fba4e7729ccbbe0b4f3fc2p-7L, - P5 = 0x1.5d87fe78a67311071dee13fd11d9p-10L, - P6 = 0x1.430912f86c7876f4b663b23c5fe5p-13L; - -static const double - P7 = 0x1.ffcbfc588b041p-17, - P8 = 0x1.62c0223a5c7c7p-20, - P9 = 0x1.b52541ff59713p-24, - P10 = 0x1.e4cf56a391e22p-28, - redux = 0x1.8p112 / TBLSIZE; - -static const long double tbl[TBLSIZE] = { - 0x1.6a09e667f3bcc908b2fb1366dfeap-1L, - 0x1.6c012750bdabeed76a99800f4edep-1L, - 0x1.6dfb23c651a2ef220e2cbe1bc0d4p-1L, - 0x1.6ff7df9519483cf87e1b4f3e1e98p-1L, - 0x1.71f75e8ec5f73dd2370f2ef0b148p-1L, - 0x1.73f9a48a58173bd5c9a4e68ab074p-1L, - 0x1.75feb564267c8bf6e9aa33a489a8p-1L, - 0x1.780694fde5d3f619ae02808592a4p-1L, - 0x1.7a11473eb0186d7d51023f6ccb1ap-1L, - 0x1.7c1ed0130c1327c49334459378dep-1L, - 0x1.7e2f336cf4e62105d02ba1579756p-1L, - 0x1.80427543e1a11b60de67649a3842p-1L, - 0x1.82589994cce128acf88afab34928p-1L, - 0x1.8471a4623c7acce52f6b97c6444cp-1L, - 0x1.868d99b4492ec80e41d90ac2556ap-1L, - 0x1.88ac7d98a669966530bcdf2d4cc0p-1L, - 0x1.8ace5422aa0db5ba7c55a192c648p-1L, - 0x1.8cf3216b5448bef2aa1cd161c57ap-1L, - 0x1.8f1ae991577362b982745c72eddap-1L, - 0x1.9145b0b91ffc588a61b469f6b6a0p-1L, - 0x1.93737b0cdc5e4f4501c3f2540ae8p-1L, - 0x1.95a44cbc8520ee9b483695a0e7fep-1L, - 0x1.97d829fde4e4f8b9e920f91e8eb6p-1L, - 0x1.9a0f170ca07b9ba3109b8c467844p-1L, - 0x1.9c49182a3f0901c7c46b071f28dep-1L, - 0x1.9e86319e323231824ca78e64c462p-1L, - 0x1.a0c667b5de564b29ada8b8cabbacp-1L, - 0x1.a309bec4a2d3358c171f770db1f4p-1L, - 0x1.a5503b23e255c8b424491caf88ccp-1L, - 0x1.a799e1330b3586f2dfb2b158f31ep-1L, - 0x1.a9e6b5579fdbf43eb243bdff53a2p-1L, - 0x1.ac36bbfd3f379c0db966a3126988p-1L, - 0x1.ae89f995ad3ad5e8734d17731c80p-1L, - 0x1.b0e07298db66590842acdfc6fb4ep-1L, - 0x1.b33a2b84f15faf6bfd0e7bd941b0p-1L, - 0x1.b59728de559398e3881111648738p-1L, - 0x1.b7f76f2fb5e46eaa7b081ab53ff6p-1L, - 0x1.ba5b030a10649840cb3c6af5b74cp-1L, - 0x1.bcc1e904bc1d2247ba0f45b3d06cp-1L, - 0x1.bf2c25bd71e088408d7025190cd0p-1L, - 0x1.c199bdd85529c2220cb12a0916bap-1L, - 0x1.c40ab5fffd07a6d14df820f17deap-1L, - 0x1.c67f12e57d14b4a2137fd20f2a26p-1L, - 0x1.c8f6d9406e7b511acbc48805c3f6p-1L, - 0x1.cb720dcef90691503cbd1e949d0ap-1L, - 0x1.cdf0b555dc3f9c44f8958fac4f12p-1L, - 0x1.d072d4a07897b8d0f22f21a13792p-1L, - 0x1.d2f87080d89f18ade123989ea50ep-1L, - 0x1.d5818dcfba48725da05aeb66dff8p-1L, - 0x1.d80e316c98397bb84f9d048807a0p-1L, - 0x1.da9e603db3285708c01a5b6d480cp-1L, - 0x1.dd321f301b4604b695de3c0630c0p-1L, - 0x1.dfc97337b9b5eb968cac39ed284cp-1L, - 0x1.e264614f5a128a12761fa17adc74p-1L, - 0x1.e502ee78b3ff6273d130153992d0p-1L, - 0x1.e7a51fbc74c834b548b2832378a4p-1L, - 0x1.ea4afa2a490d9858f73a18f5dab4p-1L, - 0x1.ecf482d8e67f08db0312fb949d50p-1L, - 0x1.efa1bee615a27771fd21a92dabb6p-1L, - 0x1.f252b376bba974e8696fc3638f24p-1L, - 0x1.f50765b6e4540674f84b762861a6p-1L, - 0x1.f7bfdad9cbe138913b4bfe72bd78p-1L, - 0x1.fa7c1819e90d82e90a7e74b26360p-1L, - 0x1.fd3c22b8f71f10975ba4b32bd006p-1L, - 0x1.0000000000000000000000000000p+0L, - 0x1.0163da9fb33356d84a66ae336e98p+0L, - 0x1.02c9a3e778060ee6f7caca4f7a18p+0L, - 0x1.04315e86e7f84bd738f9a20da442p+0L, - 0x1.059b0d31585743ae7c548eb68c6ap+0L, - 0x1.0706b29ddf6ddc6dc403a9d87b1ep+0L, - 0x1.0874518759bc808c35f25d942856p+0L, - 0x1.09e3ecac6f3834521e060c584d5cp+0L, - 0x1.0b5586cf9890f6298b92b7184200p+0L, - 0x1.0cc922b7247f7407b705b893dbdep+0L, - 0x1.0e3ec32d3d1a2020742e4f8af794p+0L, - 0x1.0fb66affed31af232091dd8a169ep+0L, - 0x1.11301d0125b50a4ebbf1aed9321cp+0L, - 0x1.12abdc06c31cbfb92bad324d6f84p+0L, - 0x1.1429aaea92ddfb34101943b2588ep+0L, - 0x1.15a98c8a58e512480d573dd562aep+0L, - 0x1.172b83c7d517adcdf7c8c50eb162p+0L, - 0x1.18af9388c8de9bbbf70b9a3c269cp+0L, - 0x1.1a35beb6fcb753cb698f692d2038p+0L, - 0x1.1bbe084045cd39ab1e72b442810ep+0L, - 0x1.1d4873168b9aa7805b8028990be8p+0L, - 0x1.1ed5022fcd91cb8819ff61121fbep+0L, - 0x1.2063b88628cd63b8eeb0295093f6p+0L, - 0x1.21f49917ddc962552fd29294bc20p+0L, - 0x1.2387a6e75623866c1fadb1c159c0p+0L, - 0x1.251ce4fb2a63f3582ab7de9e9562p+0L, - 0x1.26b4565e27cdd257a673281d3068p+0L, - 0x1.284dfe1f5638096cf15cf03c9fa0p+0L, - 0x1.29e9df51fdee12c25d15f5a25022p+0L, - 0x1.2b87fd0dad98ffddea46538fca24p+0L, - 0x1.2d285a6e4030b40091d536d0733ep+0L, - 0x1.2ecafa93e2f5611ca0f45d5239a4p+0L, - 0x1.306fe0a31b7152de8d5a463063bep+0L, - 0x1.32170fc4cd8313539cf1c3009330p+0L, - 0x1.33c08b26416ff4c9c8610d96680ep+0L, - 0x1.356c55f929ff0c94623476373be4p+0L, - 0x1.371a7373aa9caa7145502f45452ap+0L, - 0x1.38cae6d05d86585a9cb0d9bed530p+0L, - 0x1.3a7db34e59ff6ea1bc9299e0a1fep+0L, - 0x1.3c32dc313a8e484001f228b58cf0p+0L, - 0x1.3dea64c12342235b41223e13d7eep+0L, - 0x1.3fa4504ac801ba0bf701aa417b9cp+0L, - 0x1.4160a21f72e29f84325b8f3dbacap+0L, - 0x1.431f5d950a896dc704439410b628p+0L, - 0x1.44e086061892d03136f409df0724p+0L, - 0x1.46a41ed1d005772512f459229f0ap+0L, - 0x1.486a2b5c13cd013c1a3b69062f26p+0L, - 0x1.4a32af0d7d3de672d8bcf46f99b4p+0L, - 0x1.4bfdad5362a271d4397afec42e36p+0L, - 0x1.4dcb299fddd0d63b36ef1a9e19dep+0L, - 0x1.4f9b2769d2ca6ad33d8b69aa0b8cp+0L, - 0x1.516daa2cf6641c112f52c84d6066p+0L, - 0x1.5342b569d4f81df0a83c49d86bf4p+0L, - 0x1.551a4ca5d920ec52ec620243540cp+0L, - 0x1.56f4736b527da66ecb004764e61ep+0L, - 0x1.58d12d497c7fd252bc2b7343d554p+0L, - 0x1.5ab07dd48542958c93015191e9a8p+0L, - 0x1.5c9268a5946b701c4b1b81697ed4p+0L, - 0x1.5e76f15ad21486e9be4c20399d12p+0L, - 0x1.605e1b976dc08b076f592a487066p+0L, - 0x1.6247eb03a5584b1f0fa06fd2d9eap+0L, - 0x1.6434634ccc31fc76f8714c4ee122p+0L, - 0x1.66238825522249127d9e29b92ea2p+0L, - 0x1.68155d44ca973081c57227b9f69ep+0L, -}; - -static const float eps[TBLSIZE] = { - -0x1.5c50p-101, - -0x1.5d00p-106, - 0x1.8e90p-102, - -0x1.5340p-103, - 0x1.1bd0p-102, - -0x1.4600p-105, - -0x1.7a40p-104, - 0x1.d590p-102, - -0x1.d590p-101, - 0x1.b100p-103, - -0x1.0d80p-105, - 0x1.6b00p-103, - -0x1.9f00p-105, - 0x1.c400p-103, - 0x1.e120p-103, - -0x1.c100p-104, - -0x1.9d20p-103, - 0x1.a800p-108, - 0x1.4c00p-106, - -0x1.9500p-106, - 0x1.6900p-105, - -0x1.29d0p-100, - 0x1.4c60p-103, - 0x1.13a0p-102, - -0x1.5b60p-103, - -0x1.1c40p-103, - 0x1.db80p-102, - 0x1.91a0p-102, - 0x1.dc00p-105, - 0x1.44c0p-104, - 0x1.9710p-102, - 0x1.8760p-103, - -0x1.a720p-103, - 0x1.ed20p-103, - -0x1.49c0p-102, - -0x1.e000p-111, - 0x1.86a0p-103, - 0x1.2b40p-103, - -0x1.b400p-108, - 0x1.1280p-99, - -0x1.02d8p-102, - -0x1.e3d0p-103, - -0x1.b080p-105, - -0x1.f100p-107, - -0x1.16c0p-105, - -0x1.1190p-103, - -0x1.a7d2p-100, - 0x1.3450p-103, - -0x1.67c0p-105, - 0x1.4b80p-104, - -0x1.c4e0p-103, - 0x1.6000p-108, - -0x1.3f60p-105, - 0x1.93f0p-104, - 0x1.5fe0p-105, - 0x1.6f80p-107, - -0x1.7600p-106, - 0x1.21e0p-106, - -0x1.3a40p-106, - -0x1.40c0p-104, - -0x1.9860p-105, - -0x1.5d40p-108, - -0x1.1d70p-106, - 0x1.2760p-105, - 0x0.0000p+0, - 0x1.21e2p-104, - -0x1.9520p-108, - -0x1.5720p-106, - -0x1.4810p-106, - -0x1.be00p-109, - 0x1.0080p-105, - -0x1.5780p-108, - -0x1.d460p-105, - -0x1.6140p-105, - 0x1.4630p-104, - 0x1.ad50p-103, - 0x1.82e0p-105, - 0x1.1d3cp-101, - 0x1.6100p-107, - 0x1.ec30p-104, - 0x1.f200p-108, - 0x1.0b40p-103, - 0x1.3660p-102, - 0x1.d9d0p-103, - -0x1.02d0p-102, - 0x1.b070p-103, - 0x1.b9c0p-104, - -0x1.01c0p-103, - -0x1.dfe0p-103, - 0x1.1b60p-104, - -0x1.ae94p-101, - -0x1.3340p-104, - 0x1.b3d8p-102, - -0x1.6e40p-105, - -0x1.3670p-103, - 0x1.c140p-104, - 0x1.1840p-101, - 0x1.1ab0p-102, - -0x1.a400p-104, - 0x1.1f00p-104, - -0x1.7180p-103, - 0x1.4ce0p-102, - 0x1.9200p-107, - -0x1.54c0p-103, - 0x1.1b80p-105, - -0x1.1828p-101, - 0x1.5720p-102, - -0x1.a060p-100, - 0x1.9160p-102, - 0x1.a280p-104, - 0x1.3400p-107, - 0x1.2b20p-102, - 0x1.7800p-108, - 0x1.cfd0p-101, - 0x1.2ef0p-102, - -0x1.2760p-99, - 0x1.b380p-104, - 0x1.0048p-101, - -0x1.60b0p-102, - 0x1.a1ccp-100, - -0x1.a640p-104, - -0x1.08a0p-101, - 0x1.7e60p-102, - 0x1.22c0p-103, - -0x1.7200p-106, - 0x1.f0f0p-102, - 0x1.eb4ep-99, - 0x1.c6e0p-103, -}; - -/* - * exp2l(x): compute the base 2 exponential of x - * - * Accuracy: Peak error < 0.502 ulp. - * - * Method: (accurate tables) - * - * Reduce x: - * x = 2**k + y, for integer k and |y| <= 1/2. - * Thus we have exp2(x) = 2**k * exp2(y). - * - * Reduce y: - * y = i/TBLSIZE + z - eps[i] for integer i near y * TBLSIZE. - * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z - eps[i]), - * with |z - eps[i]| <= 2**-8 + 2**-98 for the table used. - * - * We compute exp2(i/TBLSIZE) via table lookup and exp2(z - eps[i]) via - * a degree-10 minimax polynomial with maximum error under 2**-120. - * The values in exp2t[] and eps[] are chosen such that - * exp2t[i] = exp2(i/TBLSIZE + eps[i]), and eps[i] is a small offset such - * that exp2t[i] is accurate to 2**-122. - * - * Note that the range of i is +-TBLSIZE/2, so we actually index the tables - * by i0 = i + TBLSIZE/2. - * - * This method is due to Gal, with many details due to Gal and Bachelis: - * - * Gal, S. and Bachelis, B. An Accurate Elementary Mathematical Library - * for the IEEE Floating Point Standard. TOMS 17(1), 26-46 (1991). - */ -long double -exp2l(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - long double r, z, t; - uint32_t i0; - union {uint32_t u; int32_t i;} k; - - /* Filter out exceptional cases. */ - if (e >= 0x3fff + 14) { /* |x| >= 16384 or x is NaN */ - if (u.i.se >= 0x3fff + 15 && u.i.se >> 15 == 0) - /* overflow */ - return x * 0x1p16383L; - if (e == 0x7fff) /* -inf or -nan */ - return -1/x; - if (x < -16382) { - if (x <= -16495 || x - 0x1p112 + 0x1p112 != x) - /* underflow */ - FORCE_EVAL((float)(-0x1p-149/x)); - if (x <= -16446) - return 0; - } - } else if (e < 0x3fff - 114) { - return 1 + x; - } - - /* - * Reduce x, computing z, i0, and k. The low bits of x + redux - * contain the 16-bit integer part of the exponent (k) followed by - * TBLBITS fractional bits (i0). We use bit tricks to extract these - * as integers, then set z to the remainder. - * - * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8. - * Then the low-order word of x + redux is 0x000abc12, - * We split this into k = 0xabc and i0 = 0x12 (adjusted to - * index into the table), then we compute z = 0x0.003456p0. - */ - u.f = x + redux; - i0 = u.i2.lo + TBLSIZE / 2; - k.u = i0 / TBLSIZE * TBLSIZE; - k.i /= TBLSIZE; - i0 %= TBLSIZE; - u.f -= redux; - z = x - u.f; - - /* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */ - t = tbl[i0]; - z -= eps[i0]; - r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * (P5 + z * (P6 - + z * (P7 + z * (P8 + z * (P9 + z * P10))))))))); - - return scalbnl(r, k.i); -} -#endif diff --git a/usr/lib/libc/math/expf.c b/usr/lib/libc/math/expf.c deleted file mode 100644 index feee2b0ed..000000000 --- a/usr/lib/libc/math/expf.c +++ /dev/null @@ -1,83 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_expf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float -half[2] = {0.5,-0.5}, -ln2hi = 6.9314575195e-1f, /* 0x3f317200 */ -ln2lo = 1.4286067653e-6f, /* 0x35bfbe8e */ -invln2 = 1.4426950216e+0f, /* 0x3fb8aa3b */ -/* - * Domain [-0.34568, 0.34568], range ~[-4.278e-9, 4.447e-9]: - * |x*(exp(x)+1)/(exp(x)-1) - p(x)| < 2**-27.74 - */ -P1 = 1.6666625440e-1f, /* 0xaaaa8f.0p-26 */ -P2 = -2.7667332906e-3f; /* -0xb55215.0p-32 */ - -float expf(float x) -{ - float_t hi, lo, c, xx, y; - int k, sign; - uint32_t hx; - - GET_FLOAT_WORD(hx, x); - sign = hx >> 31; /* sign bit of x */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* special cases */ - if (hx >= 0x42aeac50) { /* if |x| >= -87.33655f or NaN */ - if (hx > 0x7f800000) /* NaN */ - return x; - if (hx >= 0x42b17218 && !sign) { /* x >= 88.722839f */ - /* overflow */ - x *= 0x1p127f; - return x; - } - if (sign) { - /* underflow */ - FORCE_EVAL(-0x1p-149f/x); - if (hx >= 0x42cff1b5) /* x <= -103.972084f */ - return 0; - } - } - - /* argument reduction */ - if (hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */ - if (hx > 0x3f851592) /* if |x| > 1.5 ln2 */ - k = invln2*x + half[sign]; - else - k = 1 - sign - sign; - hi = x - k*ln2hi; /* k*ln2hi is exact here */ - lo = k*ln2lo; - x = hi - lo; - } else if (hx > 0x39000000) { /* |x| > 2**-14 */ - k = 0; - hi = x; - lo = 0; - } else { - /* raise inexact */ - FORCE_EVAL(0x1p127f + x); - return 1 + x; - } - - /* x is now in primary range */ - xx = x*x; - c = x - xx*(P1+xx*P2); - y = 1 + (x*c/(2-c) - lo + hi); - if (k == 0) - return y; - return scalbnf(y, k); -} diff --git a/usr/lib/libc/math/expl.c b/usr/lib/libc/math/expl.c deleted file mode 100644 index 0a7f44f68..000000000 --- a/usr/lib/libc/math/expl.c +++ /dev/null @@ -1,128 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_expl.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Exponential function, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, expl(); - * - * y = expl( x ); - * - * - * DESCRIPTION: - * - * Returns e (2.71828...) raised to the x power. - * - * Range reduction is accomplished by separating the argument - * into an integer k and fraction f such that - * - * x k f - * e = 2 e. - * - * A Pade' form of degree 5/6 is used to approximate exp(f) - 1 - * in the basic range [-0.5 ln 2, 0.5 ln 2]. - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE +-10000 50000 1.12e-19 2.81e-20 - * - * - * Error amplification in the exponential function can be - * a serious matter. The error propagation involves - * exp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ), - * which shows that a 1 lsb error in representing X produces - * a relative error of X times 1 lsb in the function. - * While the routine gives an accurate result for arguments - * that are exactly represented by a long double precision - * computer number, the result contains amplified roundoff - * error for large arguments not exactly represented. - * - * - * ERROR MESSAGES: - * - * message condition value returned - * exp underflow x < MINLOG 0.0 - * exp overflow x > MAXLOG MAXNUM - * - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double expl(long double x) -{ - return exp(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - -static const long double P[3] = { - 1.2617719307481059087798E-4L, - 3.0299440770744196129956E-2L, - 9.9999999999999999991025E-1L, -}; -static const long double Q[4] = { - 3.0019850513866445504159E-6L, - 2.5244834034968410419224E-3L, - 2.2726554820815502876593E-1L, - 2.0000000000000000000897E0L, -}; -static const long double -LN2HI = 6.9314575195312500000000E-1L, -LN2LO = 1.4286068203094172321215E-6L, -LOG2E = 1.4426950408889634073599E0L; - -long double expl(long double x) -{ - long double px, xx; - int k; - - if (isnan(x)) - return x; - if (x > 11356.5234062941439488L) /* x > ln(2^16384 - 0.5) */ - return x * 0x1p16383L; - if (x < -11399.4985314888605581L) /* x < ln(2^-16446) */ - return -0x1p-16445L/x; - - /* Express e**x = e**f 2**k - * = e**(f + k ln(2)) - */ - px = floorl(LOG2E * x + 0.5); - k = px; - x -= px * LN2HI; - x -= px * LN2LO; - - /* rational approximation of the fractional part: - * e**x = 1 + 2x P(x**2)/(Q(x**2) - x P(x**2)) - */ - xx = x * x; - px = x * __polevll(xx, P, 2); - x = px/(__polevll(xx, Q, 3) - px); - x = 1.0 + 2.0 * x; - return scalbnl(x, k); -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double expl(long double x) -{ - return exp(x); -} -#endif diff --git a/usr/lib/libc/math/expm1.c b/usr/lib/libc/math/expm1.c deleted file mode 100644 index ac1e61e4f..000000000 --- a/usr/lib/libc/math/expm1.c +++ /dev/null @@ -1,201 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_expm1.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* expm1(x) - * Returns exp(x)-1, the exponential of x minus 1. - * - * Method - * 1. Argument reduction: - * Given x, find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658 - * - * Here a correction term c will be computed to compensate - * the error in r when rounded to a floating-point number. - * - * 2. Approximating expm1(r) by a special rational function on - * the interval [0,0.34658]: - * Since - * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ... - * we define R1(r*r) by - * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r) - * That is, - * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r) - * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) - * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ... - * We use a special Remez algorithm on [0,0.347] to generate - * a polynomial of degree 5 in r*r to approximate R1. The - * maximum error of this polynomial approximation is bounded - * by 2**-61. In other words, - * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5 - * where Q1 = -1.6666666666666567384E-2, - * Q2 = 3.9682539681370365873E-4, - * Q3 = -9.9206344733435987357E-6, - * Q4 = 2.5051361420808517002E-7, - * Q5 = -6.2843505682382617102E-9; - * z = r*r, - * with error bounded by - * | 5 | -61 - * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 - * | | - * - * expm1(r) = exp(r)-1 is then computed by the following - * specific way which minimize the accumulation rounding error: - * 2 3 - * r r [ 3 - (R1 + R1*r/2) ] - * expm1(r) = r + --- + --- * [--------------------] - * 2 2 [ 6 - r*(3 - R1*r/2) ] - * - * To compensate the error in the argument reduction, we use - * expm1(r+c) = expm1(r) + c + expm1(r)*c - * ~ expm1(r) + c + r*c - * Thus c+r*c will be added in as the correction terms for - * expm1(r+c). Now rearrange the term to avoid optimization - * screw up: - * ( 2 2 ) - * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r ) - * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- ) - * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 ) - * ( ) - * - * = r - E - * 3. Scale back to obtain expm1(x): - * From step 1, we have - * expm1(x) = either 2^k*[expm1(r)+1] - 1 - * = or 2^k*[expm1(r) + (1-2^-k)] - * 4. Implementation notes: - * (A). To save one multiplication, we scale the coefficient Qi - * to Qi*2^i, and replace z by (x^2)/2. - * (B). To achieve maximum accuracy, we compute expm1(x) by - * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf) - * (ii) if k=0, return r-E - * (iii) if k=-1, return 0.5*(r-E)-0.5 - * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) - * else return 1.0+2.0*(r-E); - * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) - * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else - * (vii) return 2^k(1-((E+2^-k)-r)) - * - * Special cases: - * expm1(INF) is INF, expm1(NaN) is NaN; - * expm1(-INF) is -1, and - * for finite argument, only expm1(0)=0 is exact. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Misc. info. - * For IEEE double - * if x > 7.09782712893383973096e+02 then expm1(x) overflow - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "libm.h" - -static const double -o_threshold = 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ -ln2_hi = 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ -invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ -/* Scaled Q's: Qn_here = 2**n * Qn_above, for R(2*z) where z = hxs = x*x/2: */ -Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */ -Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ -Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ -Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ -Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ - -double expm1(double x) -{ - double_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk; - union {double f; uint64_t i;} u = {x}; - uint32_t hx = u.i>>32 & 0x7fffffff; - int k, sign = u.i>>63; - - /* filter out huge and non-finite argument */ - if (hx >= 0x4043687A) { /* if |x|>=56*ln2 */ - if (isnan(x)) - return x; - if (sign) - return -1; - if (x > o_threshold) { - x *= 0x1p1023; - return x; - } - } - - /* argument reduction */ - if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ - if (!sign) { - hi = x - ln2_hi; - lo = ln2_lo; - k = 1; - } else { - hi = x + ln2_hi; - lo = -ln2_lo; - k = -1; - } - } else { - k = invln2*x + (sign ? -0.5 : 0.5); - t = k; - hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ - lo = t*ln2_lo; - } - x = hi-lo; - c = (hi-x)-lo; - } else if (hx < 0x3c900000) { /* |x| < 2**-54, return x */ - if (hx < 0x00100000) - FORCE_EVAL((float)x); - return x; - } else - k = 0; - - /* x is now in primary range */ - hfx = 0.5*x; - hxs = x*hfx; - r1 = 1.0+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); - t = 3.0-r1*hfx; - e = hxs*((r1-t)/(6.0 - x*t)); - if (k == 0) /* c is 0 */ - return x - (x*e-hxs); - e = x*(e-c) - c; - e -= hxs; - /* exp(x) ~ 2^k (x_reduced - e + 1) */ - if (k == -1) - return 0.5*(x-e) - 0.5; - if (k == 1) { - if (x < -0.25) - return -2.0*(e-(x+0.5)); - return 1.0+2.0*(x-e); - } - u.i = (uint64_t)(0x3ff + k)<<52; /* 2^k */ - twopk = u.f; - if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */ - y = x - e + 1.0; - if (k == 1024) - y = y*2.0*0x1p1023; - else - y = y*twopk; - return y - 1.0; - } - u.i = (uint64_t)(0x3ff - k)<<52; /* 2^-k */ - if (k < 20) - y = (x-e+(1-u.f))*twopk; - else - y = (x-(e+u.f)+1)*twopk; - return y; -} diff --git a/usr/lib/libc/math/expm1f.c b/usr/lib/libc/math/expm1f.c deleted file mode 100644 index 297e0b44a..000000000 --- a/usr/lib/libc/math/expm1f.c +++ /dev/null @@ -1,111 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_expm1f.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float -o_threshold = 8.8721679688e+01, /* 0x42b17180 */ -ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ -ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ -invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */ -/* - * Domain [-0.34568, 0.34568], range ~[-6.694e-10, 6.696e-10]: - * |6 / x * (1 + 2 * (1 / (exp(x) - 1) - 1 / x)) - q(x)| < 2**-30.04 - * Scaled coefficients: Qn_here = 2**n * Qn_for_q (see s_expm1.c): - */ -Q1 = -3.3333212137e-2, /* -0x888868.0p-28 */ -Q2 = 1.5807170421e-3; /* 0xcf3010.0p-33 */ - -float expm1f(float x) -{ - float_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk; - union {float f; uint32_t i;} u = {x}; - uint32_t hx = u.i & 0x7fffffff; - int k, sign = u.i >> 31; - - /* filter out huge and non-finite argument */ - if (hx >= 0x4195b844) { /* if |x|>=27*ln2 */ - if (hx > 0x7f800000) /* NaN */ - return x; - if (sign) - return -1; - if (x > o_threshold) { - x *= 0x1p127f; - return x; - } - } - - /* argument reduction */ - if (hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */ - if (hx < 0x3F851592) { /* and |x| < 1.5 ln2 */ - if (!sign) { - hi = x - ln2_hi; - lo = ln2_lo; - k = 1; - } else { - hi = x + ln2_hi; - lo = -ln2_lo; - k = -1; - } - } else { - k = invln2*x + (sign ? -0.5f : 0.5f); - t = k; - hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ - lo = t*ln2_lo; - } - x = hi-lo; - c = (hi-x)-lo; - } else if (hx < 0x33000000) { /* when |x|<2**-25, return x */ - if (hx < 0x00800000) - FORCE_EVAL(x*x); - return x; - } else - k = 0; - - /* x is now in primary range */ - hfx = 0.5f*x; - hxs = x*hfx; - r1 = 1.0f+hxs*(Q1+hxs*Q2); - t = 3.0f - r1*hfx; - e = hxs*((r1-t)/(6.0f - x*t)); - if (k == 0) /* c is 0 */ - return x - (x*e-hxs); - e = x*(e-c) - c; - e -= hxs; - /* exp(x) ~ 2^k (x_reduced - e + 1) */ - if (k == -1) - return 0.5f*(x-e) - 0.5f; - if (k == 1) { - if (x < -0.25f) - return -2.0f*(e-(x+0.5f)); - return 1.0f + 2.0f*(x-e); - } - u.i = (0x7f+k)<<23; /* 2^k */ - twopk = u.f; - if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */ - y = x - e + 1.0f; - if (k == 128) - y = y*2.0f*0x1p127f; - else - y = y*twopk; - return y - 1.0f; - } - u.i = (0x7f-k)<<23; /* 2^-k */ - if (k < 23) - y = (x-e+(1-u.f))*twopk; - else - y = (x-(e+u.f)+1)*twopk; - return y; -} diff --git a/usr/lib/libc/math/expm1l.c b/usr/lib/libc/math/expm1l.c deleted file mode 100644 index d17150785..000000000 --- a/usr/lib/libc/math/expm1l.c +++ /dev/null @@ -1,123 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_expm1l.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Exponential function, minus 1 - * Long double precision - * - * - * SYNOPSIS: - * - * long double x, y, expm1l(); - * - * y = expm1l( x ); - * - * - * DESCRIPTION: - * - * Returns e (2.71828...) raised to the x power, minus 1. - * - * Range reduction is accomplished by separating the argument - * into an integer k and fraction f such that - * - * x k f - * e = 2 e. - * - * An expansion x + .5 x^2 + x^3 R(x) approximates exp(f) - 1 - * in the basic range [-0.5 ln 2, 0.5 ln 2]. - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE -45,+maxarg 200,000 1.2e-19 2.5e-20 - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double expm1l(long double x) -{ - return expm1(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - -/* exp(x) - 1 = x + 0.5 x^2 + x^3 P(x)/Q(x) - -.5 ln 2 < x < .5 ln 2 - Theoretical peak relative error = 3.4e-22 */ -static const long double -P0 = -1.586135578666346600772998894928250240826E4L, -P1 = 2.642771505685952966904660652518429479531E3L, -P2 = -3.423199068835684263987132888286791620673E2L, -P3 = 1.800826371455042224581246202420972737840E1L, -P4 = -5.238523121205561042771939008061958820811E-1L, -Q0 = -9.516813471998079611319047060563358064497E4L, -Q1 = 3.964866271411091674556850458227710004570E4L, -Q2 = -7.207678383830091850230366618190187434796E3L, -Q3 = 7.206038318724600171970199625081491823079E2L, -Q4 = -4.002027679107076077238836622982900945173E1L, -/* Q5 = 1.000000000000000000000000000000000000000E0 */ -/* C1 + C2 = ln 2 */ -C1 = 6.93145751953125E-1L, -C2 = 1.428606820309417232121458176568075500134E-6L, -/* ln 2^-65 */ -minarg = -4.5054566736396445112120088E1L, -/* ln 2^16384 */ -maxarg = 1.1356523406294143949492E4L; - -long double expm1l(long double x) -{ - long double px, qx, xx; - int k; - - if (isnan(x)) - return x; - if (x > maxarg) - return x*0x1p16383L; /* overflow, unless x==inf */ - if (x == 0.0) - return x; - if (x < minarg) - return -1.0; - - xx = C1 + C2; - /* Express x = ln 2 (k + remainder), remainder not exceeding 1/2. */ - px = floorl(0.5 + x / xx); - k = px; - /* remainder times ln 2 */ - x -= px * C1; - x -= px * C2; - - /* Approximate exp(remainder ln 2).*/ - px = (((( P4 * x + P3) * x + P2) * x + P1) * x + P0) * x; - qx = (((( x + Q4) * x + Q3) * x + Q2) * x + Q1) * x + Q0; - xx = x * x; - qx = x + (0.5 * xx + xx * px / qx); - - /* exp(x) = exp(k ln 2) exp(remainder ln 2) = 2^k exp(remainder ln 2). - We have qx = exp(remainder ln 2) - 1, so - exp(x) - 1 = 2^k (qx + 1) - 1 = 2^k qx + 2^k - 1. */ - px = scalbnl(1.0, k); - x = px * qx + (px - 1.0); - return x; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double expm1l(long double x) -{ - return expm1(x); -} -#endif diff --git a/usr/lib/libc/math/fabs.c b/usr/lib/libc/math/fabs.c deleted file mode 100644 index e8258cfdb..000000000 --- a/usr/lib/libc/math/fabs.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -double fabs(double x) -{ - union {double f; uint64_t i;} u = {x}; - u.i &= -1ULL/2; - return u.f; -} diff --git a/usr/lib/libc/math/fabsf.c b/usr/lib/libc/math/fabsf.c deleted file mode 100644 index 4efc8d686..000000000 --- a/usr/lib/libc/math/fabsf.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -float fabsf(float x) -{ - union {float f; uint32_t i;} u = {x}; - u.i &= 0x7fffffff; - return u.f; -} diff --git a/usr/lib/libc/math/fabsl.c b/usr/lib/libc/math/fabsl.c deleted file mode 100644 index c4f36ec28..000000000 --- a/usr/lib/libc/math/fabsl.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "libm.h" -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fabsl(long double x) -{ - return fabs(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double fabsl(long double x) -{ - union ldshape u = {x}; - - u.i.se &= 0x7fff; - return u.f; -} -#endif diff --git a/usr/lib/libc/math/fdim.c b/usr/lib/libc/math/fdim.c deleted file mode 100644 index 958546064..000000000 --- a/usr/lib/libc/math/fdim.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -double fdim(double x, double y) -{ - if (isnan(x)) - return x; - if (isnan(y)) - return y; - return x > y ? x - y : 0; -} diff --git a/usr/lib/libc/math/fdimf.c b/usr/lib/libc/math/fdimf.c deleted file mode 100644 index 543c3648e..000000000 --- a/usr/lib/libc/math/fdimf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -float fdimf(float x, float y) -{ - if (isnan(x)) - return x; - if (isnan(y)) - return y; - return x > y ? x - y : 0; -} diff --git a/usr/lib/libc/math/fdiml.c b/usr/lib/libc/math/fdiml.c deleted file mode 100644 index 62e29b7df..000000000 --- a/usr/lib/libc/math/fdiml.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fdiml(long double x, long double y) -{ - return fdim(x, y); -} -#else -long double fdiml(long double x, long double y) -{ - if (isnan(x)) - return x; - if (isnan(y)) - return y; - return x > y ? x - y : 0; -} -#endif diff --git a/usr/lib/libc/math/finite.c b/usr/lib/libc/math/finite.c deleted file mode 100644 index 25a0575fb..000000000 --- a/usr/lib/libc/math/finite.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -int finite(double x) -{ - return isfinite(x); -} diff --git a/usr/lib/libc/math/finitef.c b/usr/lib/libc/math/finitef.c deleted file mode 100644 index 2c4c77146..000000000 --- a/usr/lib/libc/math/finitef.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -int finitef(float x) -{ - return isfinite(x); -} diff --git a/usr/lib/libc/math/floor.c b/usr/lib/libc/math/floor.c deleted file mode 100644 index 7f9d70197..000000000 --- a/usr/lib/libc/math/floor.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const double_t toint = 1/EPS; - -double floor(double x) -{ - union {double f; uint64_t i;} u = {x}; - int e = u.i >> 52 & 0x7ff; - double_t y; - - if (e >= 0x3ff+52 || x == 0) - return x; - /* y = int(x) - x, where int(x) is an integer neighbor of x */ - if (u.i >> 63) - y = x - toint + toint - x; - else - y = x + toint - toint - x; - /* special case because of non-nearest rounding modes */ - if (e <= 0x3ff-1) { -#if 0 - FORCE_EVAL(y); -#endif - return u.i >> 63 ? -1 : 0; - } - if (y > 0) - return x + y - 1; - return x + y; -} diff --git a/usr/lib/libc/math/floorf.c b/usr/lib/libc/math/floorf.c deleted file mode 100644 index dceec739d..000000000 --- a/usr/lib/libc/math/floorf.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "libm.h" - -float floorf(float x) -{ - union {float f; uint32_t i;} u = {x}; - int e = (int)(u.i >> 23 & 0xff) - 0x7f; - uint32_t m; - - if (e >= 23) - return x; - if (e >= 0) { - m = 0x007fffff >> e; - if ((u.i & m) == 0) - return x; - FORCE_EVAL(x + 0x1p120f); - if (u.i >> 31) - u.i += m; - u.i &= ~m; - } else { - FORCE_EVAL(x + 0x1p120f); - if (u.i >> 31 == 0) - u.i = 0; - else if (u.i << 1) - u.f = -1.0; - } - return u.f; -} diff --git a/usr/lib/libc/math/floorl.c b/usr/lib/libc/math/floorl.c deleted file mode 100644 index 16aaec48e..000000000 --- a/usr/lib/libc/math/floorl.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double floorl(long double x) -{ - return floor(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -static const long double toint = 1/LDBL_EPSILON; - -long double floorl(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - long double y; - - if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0) - return x; - /* y = int(x) - x, where int(x) is an integer neighbor of x */ - if (u.i.se >> 15) - y = x - toint + toint - x; - else - y = x + toint - toint - x; - /* special case because of non-nearest rounding modes */ - if (e <= 0x3fff-1) { - FORCE_EVAL(y); - return u.i.se >> 15 ? -1 : 0; - } - if (y > 0) - return x + y - 1; - return x + y; -} -#endif diff --git a/usr/lib/libc/math/fma.c b/usr/lib/libc/math/fma.c deleted file mode 100644 index 741ccd757..000000000 --- a/usr/lib/libc/math/fma.c +++ /dev/null @@ -1,460 +0,0 @@ -#include -#include "libm.h" - -#if LDBL_MANT_DIG==64 && LDBL_MAX_EXP==16384 -/* exact add, assumes exponent_x >= exponent_y */ -static void add(long double *hi, long double *lo, long double x, long double y) -{ - long double r; - - r = x + y; - *hi = r; - r -= x; - *lo = y - r; -} - -/* exact mul, assumes no over/underflow */ -static void mul(long double *hi, long double *lo, long double x, long double y) -{ - static const long double c = 1.0 + 0x1p32L; - long double cx, xh, xl, cy, yh, yl; - - cx = c*x; - xh = (x - cx) + cx; - xl = x - xh; - cy = c*y; - yh = (y - cy) + cy; - yl = y - yh; - *hi = x*y; - *lo = (xh*yh - *hi) + xh*yl + xl*yh + xl*yl; -} - -/* -assume (long double)(hi+lo) == hi -return an adjusted hi so that rounding it to double (or less) precision is correct -*/ -static long double adjust(long double hi, long double lo) -{ - union ldshape uhi, ulo; - - if (lo == 0) - return hi; - uhi.f = hi; - if (uhi.i.m & 0x3ff) - return hi; - ulo.f = lo; - if ((uhi.i.se & 0x8000) == (ulo.i.se & 0x8000)) - uhi.i.m++; - else { - /* handle underflow and take care of ld80 implicit msb */ - if (uhi.i.m << 1 == 0) { - uhi.i.m = 0; - uhi.i.se--; - } - uhi.i.m--; - } - return uhi.f; -} - -/* adjusted add so the result is correct when rounded to double (or less) precision */ -static long double dadd(long double x, long double y) -{ - add(&x, &y, x, y); - return adjust(x, y); -} - -/* adjusted mul so the result is correct when rounded to double (or less) precision */ -static long double dmul(long double x, long double y) -{ - mul(&x, &y, x, y); - return adjust(x, y); -} - -static int getexp(long double x) -{ - union ldshape u; - u.f = x; - return u.i.se & 0x7fff; -} - -double fma(double x, double y, double z) -{ - #pragma STDC FENV_ACCESS ON - long double hi, lo1, lo2, xy; - int round, ez, exy; - - /* handle +-inf,nan */ - if (!isfinite(x) || !isfinite(y)) - return x*y + z; - if (!isfinite(z)) - return z; - /* handle +-0 */ - if (x == 0.0 || y == 0.0) - return x*y + z; - round = fegetround(); - if (z == 0.0) { - if (round == FE_TONEAREST) - return dmul(x, y); - return x*y; - } - - /* exact mul and add require nearest rounding */ - /* spurious inexact exceptions may be raised */ - fesetround(FE_TONEAREST); - mul(&xy, &lo1, x, y); - exy = getexp(xy); - ez = getexp(z); - if (ez > exy) { - add(&hi, &lo2, z, xy); - } else if (ez > exy - 12) { - add(&hi, &lo2, xy, z); - if (hi == 0) { - /* - xy + z is 0, but it should be calculated with the - original rounding mode so the sign is correct, if the - compiler does not support FENV_ACCESS ON it does not - know about the changed rounding mode and eliminates - the xy + z below without the volatile memory access - */ - volatile double z_; - fesetround(round); - z_ = z; - return (xy + z_) + lo1; - } - } else { - /* - ez <= exy - 12 - the 12 extra bits (1guard, 11round+sticky) are needed so with - lo = dadd(lo1, lo2) - elo <= ehi - 11, and we use the last 10 bits in adjust so - dadd(hi, lo) - gives correct result when rounded to double - */ - hi = xy; - lo2 = z; - } - /* - the result is stored before return for correct precision and exceptions - - one corner case is when the underflow flag should be raised because - the precise result is an inexact subnormal double, but the calculated - long double result is an exact subnormal double - (so rounding to double does not raise exceptions) - - in nearest rounding mode dadd takes care of this: the last bit of the - result is adjusted so rounding sees an inexact value when it should - - in non-nearest rounding mode fenv is used for the workaround - */ - fesetround(round); - if (round == FE_TONEAREST) - z = dadd(hi, dadd(lo1, lo2)); - else { -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - int e = fetestexcept(FE_INEXACT); - feclearexcept(FE_INEXACT); -#endif - z = hi + (lo1 + lo2); -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - if (getexp(z) < 0x3fff-1022 && fetestexcept(FE_INEXACT)) - feraiseexcept(FE_UNDERFLOW); - else if (e) - feraiseexcept(FE_INEXACT); -#endif - } - return z; -} -#else -/* origin: FreeBSD /usr/src/lib/msun/src/s_fma.c */ -/*- - * Copyright (c) 2005-2011 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * A struct dd represents a floating-point number with twice the precision - * of a double. We maintain the invariant that "hi" stores the 53 high-order - * bits of the result. - */ -struct dd { - double hi; - double lo; -}; - -/* - * Compute a+b exactly, returning the exact result in a struct dd. We assume - * that both a and b are finite, but make no assumptions about their relative - * magnitudes. - */ -static inline struct dd dd_add(double a, double b) -{ - struct dd ret; - double s; - - ret.hi = a + b; - s = ret.hi - a; - ret.lo = (a - (ret.hi - s)) + (b - s); - return (ret); -} - -/* - * Compute a+b, with a small tweak: The least significant bit of the - * result is adjusted into a sticky bit summarizing all the bits that - * were lost to rounding. This adjustment negates the effects of double - * rounding when the result is added to another number with a higher - * exponent. For an explanation of round and sticky bits, see any reference - * on FPU design, e.g., - * - * J. Coonen. An Implementation Guide to a Proposed Standard for - * Floating-Point Arithmetic. Computer, vol. 13, no. 1, Jan 1980. - */ -static inline double add_adjusted(double a, double b) -{ - struct dd sum; - union {double f; uint64_t i;} uhi, ulo; - - sum = dd_add(a, b); - if (sum.lo != 0) { - uhi.f = sum.hi; - if ((uhi.i & 1) == 0) { - /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */ - ulo.f = sum.lo; - uhi.i += 1 - ((uhi.i ^ ulo.i) >> 62); - sum.hi = uhi.f; - } - } - return (sum.hi); -} - -/* - * Compute ldexp(a+b, scale) with a single rounding error. It is assumed - * that the result will be subnormal, and care is taken to ensure that - * double rounding does not occur. - */ -static inline double add_and_denormalize(double a, double b, int scale) -{ - struct dd sum; - union {double f; uint64_t i;} uhi, ulo; - int bits_lost; - - sum = dd_add(a, b); - - /* - * If we are losing at least two bits of accuracy to denormalization, - * then the first lost bit becomes a round bit, and we adjust the - * lowest bit of sum.hi to make it a sticky bit summarizing all the - * bits in sum.lo. With the sticky bit adjusted, the hardware will - * break any ties in the correct direction. - * - * If we are losing only one bit to denormalization, however, we must - * break the ties manually. - */ - if (sum.lo != 0) { - uhi.f = sum.hi; - bits_lost = -((int)(uhi.i >> 52) & 0x7ff) - scale + 1; - if ((bits_lost != 1) ^ (int)(uhi.i & 1)) { - /* hibits += (int)copysign(1.0, sum.hi * sum.lo) */ - ulo.f = sum.lo; - uhi.i += 1 - (((uhi.i ^ ulo.i) >> 62) & 2); - sum.hi = uhi.f; - } - } - return scalbn(sum.hi, scale); -} - -/* - * Compute a*b exactly, returning the exact result in a struct dd. We assume - * that both a and b are normalized, so no underflow or overflow will occur. - * The current rounding mode must be round-to-nearest. - */ -static inline struct dd dd_mul(double a, double b) -{ - static const double split = 0x1p27 + 1.0; - struct dd ret; - double ha, hb, la, lb, p, q; - - p = a * split; - ha = a - p; - ha += p; - la = a - ha; - - p = b * split; - hb = b - p; - hb += p; - lb = b - hb; - - p = ha * hb; - q = ha * lb + la * hb; - - ret.hi = p + q; - ret.lo = p - ret.hi + q + la * lb; - return (ret); -} - -/* - * Fused multiply-add: Compute x * y + z with a single rounding error. - * - * We use scaling to avoid overflow/underflow, along with the - * canonical precision-doubling technique adapted from: - * - * Dekker, T. A Floating-Point Technique for Extending the - * Available Precision. Numer. Math. 18, 224-242 (1971). - * - * This algorithm is sensitive to the rounding precision. FPUs such - * as the i387 must be set in double-precision mode if variables are - * to be stored in FP registers in order to avoid incorrect results. - * This is the default on FreeBSD, but not on many other systems. - * - * Hardware instructions should be used on architectures that support it, - * since this implementation will likely be several times slower. - */ -double fma(double x, double y, double z) -{ - #pragma STDC FENV_ACCESS ON - double xs, ys, zs, adj; - struct dd xy, r; - int oround; - int ex, ey, ez; - int spread; - - /* - * Handle special cases. The order of operations and the particular - * return values here are crucial in handling special cases involving - * infinities, NaNs, overflows, and signed zeroes correctly. - */ - if (!isfinite(x) || !isfinite(y)) - return (x * y + z); - if (!isfinite(z)) - return (z); - if (x == 0.0 || y == 0.0) - return (x * y + z); - if (z == 0.0) - return (x * y); - - xs = frexp(x, &ex); - ys = frexp(y, &ey); - zs = frexp(z, &ez); - oround = fegetround(); - spread = ex + ey - ez; - - /* - * If x * y and z are many orders of magnitude apart, the scaling - * will overflow, so we handle these cases specially. Rounding - * modes other than FE_TONEAREST are painful. - */ - if (spread < -DBL_MANT_DIG) { -#ifdef FE_INEXACT - feraiseexcept(FE_INEXACT); -#endif -#ifdef FE_UNDERFLOW - if (!isnormal(z)) - feraiseexcept(FE_UNDERFLOW); -#endif - switch (oround) { - default: /* FE_TONEAREST */ - return (z); -#ifdef FE_TOWARDZERO - case FE_TOWARDZERO: - if (x > 0.0 ^ y < 0.0 ^ z < 0.0) - return (z); - else - return (nextafter(z, 0)); -#endif -#ifdef FE_DOWNWARD - case FE_DOWNWARD: - if (x > 0.0 ^ y < 0.0) - return (z); - else - return (nextafter(z, -INFINITY)); -#endif -#ifdef FE_UPWARD - case FE_UPWARD: - if (x > 0.0 ^ y < 0.0) - return (nextafter(z, INFINITY)); - else - return (z); -#endif - } - } - if (spread <= DBL_MANT_DIG * 2) - zs = scalbn(zs, -spread); - else - zs = copysign(DBL_MIN, zs); - - fesetround(FE_TONEAREST); - - /* - * Basic approach for round-to-nearest: - * - * (xy.hi, xy.lo) = x * y (exact) - * (r.hi, r.lo) = xy.hi + z (exact) - * adj = xy.lo + r.lo (inexact; low bit is sticky) - * result = r.hi + adj (correctly rounded) - */ - xy = dd_mul(xs, ys); - r = dd_add(xy.hi, zs); - - spread = ex + ey; - - if (r.hi == 0.0) { - /* - * When the addends cancel to 0, ensure that the result has - * the correct sign. - */ - fesetround(oround); - volatile double vzs = zs; /* XXX gcc CSE bug workaround */ - return xy.hi + vzs + scalbn(xy.lo, spread); - } - - if (oround != FE_TONEAREST) { - /* - * There is no need to worry about double rounding in directed - * rounding modes. - * But underflow may not be raised properly, example in downward rounding: - * fma(0x1.000000001p-1000, 0x1.000000001p-30, -0x1p-1066) - */ - double ret; -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - int e = fetestexcept(FE_INEXACT); - feclearexcept(FE_INEXACT); -#endif - fesetround(oround); - adj = r.lo + xy.lo; - ret = scalbn(r.hi + adj, spread); -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - if (ilogb(ret) < -1022 && fetestexcept(FE_INEXACT)) - feraiseexcept(FE_UNDERFLOW); - else if (e) - feraiseexcept(FE_INEXACT); -#endif - return ret; - } - - adj = add_adjusted(r.lo, xy.lo); - if (spread + ilogb(r.hi) > -1023) - return scalbn(r.hi + adj, spread); - else - return add_and_denormalize(r.hi, adj, spread); -} -#endif diff --git a/usr/lib/libc/math/fmaf.c b/usr/lib/libc/math/fmaf.c deleted file mode 100644 index aa57feb69..000000000 --- a/usr/lib/libc/math/fmaf.c +++ /dev/null @@ -1,93 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_fmaf.c */ -/*- - * Copyright (c) 2005-2011 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -/* - * Fused multiply-add: Compute x * y + z with a single rounding error. - * - * A double has more than twice as much precision than a float, so - * direct double-precision arithmetic suffices, except where double - * rounding occurs. - */ -float fmaf(float x, float y, float z) -{ - #pragma STDC FENV_ACCESS ON - double xy, result; - union {double f; uint64_t i;} u; - int e; - - xy = (double)x * y; - result = xy + z; - u.f = result; - e = u.i>>52 & 0x7ff; - /* Common case: The double precision result is fine. */ - if ((u.i & 0x1fffffff) != 0x10000000 || /* not a halfway case */ - e == 0x7ff || /* NaN */ - result - xy == z || /* exact */ - fegetround() != FE_TONEAREST) /* not round-to-nearest */ - { - /* - underflow may not be raised correctly, example: - fmaf(0x1p-120f, 0x1p-120f, 0x1p-149f) - */ -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - if (e < 0x3ff-126 && e >= 0x3ff-149 && fetestexcept(FE_INEXACT)) { - feclearexcept(FE_INEXACT); - /* TODO: gcc and clang bug workaround */ - volatile float vz = z; - result = xy + vz; - if (fetestexcept(FE_INEXACT)) - feraiseexcept(FE_UNDERFLOW); - else - feraiseexcept(FE_INEXACT); - } -#endif - z = result; - return z; - } - - /* - * If result is inexact, and exactly halfway between two float values, - * we need to adjust the low-order bit in the direction of the error. - */ -#ifdef FE_TOWARDZERO - fesetround(FE_TOWARDZERO); -#endif - volatile double vxy = xy; /* XXX work around gcc CSE bug */ - double adjusted_result = vxy + z; - fesetround(FE_TONEAREST); - if (result == adjusted_result) { - u.f = adjusted_result; - u.i++; - adjusted_result = u.f; - } - z = adjusted_result; - return z; -} diff --git a/usr/lib/libc/math/fmal.c b/usr/lib/libc/math/fmal.c deleted file mode 100644 index 4506aac6f..000000000 --- a/usr/lib/libc/math/fmal.c +++ /dev/null @@ -1,293 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_fmal.c */ -/*- - * Copyright (c) 2005-2011 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "libm.h" -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fmal(long double x, long double y, long double z) -{ - return fma(x, y, z); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#include -#if LDBL_MANT_DIG == 64 -#define LASTBIT(u) (u.i.m & 1) -#define SPLIT (0x1p32L + 1) -#elif LDBL_MANT_DIG == 113 -#define LASTBIT(u) (u.i.lo & 1) -#define SPLIT (0x1p57L + 1) -#endif - -/* - * A struct dd represents a floating-point number with twice the precision - * of a long double. We maintain the invariant that "hi" stores the high-order - * bits of the result. - */ -struct dd { - long double hi; - long double lo; -}; - -/* - * Compute a+b exactly, returning the exact result in a struct dd. We assume - * that both a and b are finite, but make no assumptions about their relative - * magnitudes. - */ -static inline struct dd dd_add(long double a, long double b) -{ - struct dd ret; - long double s; - - ret.hi = a + b; - s = ret.hi - a; - ret.lo = (a - (ret.hi - s)) + (b - s); - return (ret); -} - -/* - * Compute a+b, with a small tweak: The least significant bit of the - * result is adjusted into a sticky bit summarizing all the bits that - * were lost to rounding. This adjustment negates the effects of double - * rounding when the result is added to another number with a higher - * exponent. For an explanation of round and sticky bits, see any reference - * on FPU design, e.g., - * - * J. Coonen. An Implementation Guide to a Proposed Standard for - * Floating-Point Arithmetic. Computer, vol. 13, no. 1, Jan 1980. - */ -static inline long double add_adjusted(long double a, long double b) -{ - struct dd sum; - union ldshape u; - - sum = dd_add(a, b); - if (sum.lo != 0) { - u.f = sum.hi; - if (!LASTBIT(u)) - sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); - } - return (sum.hi); -} - -/* - * Compute ldexp(a+b, scale) with a single rounding error. It is assumed - * that the result will be subnormal, and care is taken to ensure that - * double rounding does not occur. - */ -static inline long double add_and_denormalize(long double a, long double b, int scale) -{ - struct dd sum; - int bits_lost; - union ldshape u; - - sum = dd_add(a, b); - - /* - * If we are losing at least two bits of accuracy to denormalization, - * then the first lost bit becomes a round bit, and we adjust the - * lowest bit of sum.hi to make it a sticky bit summarizing all the - * bits in sum.lo. With the sticky bit adjusted, the hardware will - * break any ties in the correct direction. - * - * If we are losing only one bit to denormalization, however, we must - * break the ties manually. - */ - if (sum.lo != 0) { - u.f = sum.hi; - bits_lost = -u.i.se - scale + 1; - if ((bits_lost != 1) ^ LASTBIT(u)) - sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); - } - return scalbnl(sum.hi, scale); -} - -/* - * Compute a*b exactly, returning the exact result in a struct dd. We assume - * that both a and b are normalized, so no underflow or overflow will occur. - * The current rounding mode must be round-to-nearest. - */ -static inline struct dd dd_mul(long double a, long double b) -{ - struct dd ret; - long double ha, hb, la, lb, p, q; - - p = a * SPLIT; - ha = a - p; - ha += p; - la = a - ha; - - p = b * SPLIT; - hb = b - p; - hb += p; - lb = b - hb; - - p = ha * hb; - q = ha * lb + la * hb; - - ret.hi = p + q; - ret.lo = p - ret.hi + q + la * lb; - return (ret); -} - -/* - * Fused multiply-add: Compute x * y + z with a single rounding error. - * - * We use scaling to avoid overflow/underflow, along with the - * canonical precision-doubling technique adapted from: - * - * Dekker, T. A Floating-Point Technique for Extending the - * Available Precision. Numer. Math. 18, 224-242 (1971). - */ -long double fmal(long double x, long double y, long double z) -{ - #pragma STDC FENV_ACCESS ON - long double xs, ys, zs, adj; - struct dd xy, r; - int oround; - int ex, ey, ez; - int spread; - - /* - * Handle special cases. The order of operations and the particular - * return values here are crucial in handling special cases involving - * infinities, NaNs, overflows, and signed zeroes correctly. - */ - if (!isfinite(x) || !isfinite(y)) - return (x * y + z); - if (!isfinite(z)) - return (z); - if (x == 0.0 || y == 0.0) - return (x * y + z); - if (z == 0.0) - return (x * y); - - xs = frexpl(x, &ex); - ys = frexpl(y, &ey); - zs = frexpl(z, &ez); - oround = fegetround(); - spread = ex + ey - ez; - - /* - * If x * y and z are many orders of magnitude apart, the scaling - * will overflow, so we handle these cases specially. Rounding - * modes other than FE_TONEAREST are painful. - */ - if (spread < -LDBL_MANT_DIG) { -#ifdef FE_INEXACT - feraiseexcept(FE_INEXACT); -#endif -#ifdef FE_UNDERFLOW - if (!isnormal(z)) - feraiseexcept(FE_UNDERFLOW); -#endif - switch (oround) { - default: /* FE_TONEAREST */ - return (z); -#ifdef FE_TOWARDZERO - case FE_TOWARDZERO: - if (x > 0.0 ^ y < 0.0 ^ z < 0.0) - return (z); - else - return (nextafterl(z, 0)); -#endif -#ifdef FE_DOWNWARD - case FE_DOWNWARD: - if (x > 0.0 ^ y < 0.0) - return (z); - else - return (nextafterl(z, -INFINITY)); -#endif -#ifdef FE_UPWARD - case FE_UPWARD: - if (x > 0.0 ^ y < 0.0) - return (nextafterl(z, INFINITY)); - else - return (z); -#endif - } - } - if (spread <= LDBL_MANT_DIG * 2) - zs = scalbnl(zs, -spread); - else - zs = copysignl(LDBL_MIN, zs); - - fesetround(FE_TONEAREST); - - /* - * Basic approach for round-to-nearest: - * - * (xy.hi, xy.lo) = x * y (exact) - * (r.hi, r.lo) = xy.hi + z (exact) - * adj = xy.lo + r.lo (inexact; low bit is sticky) - * result = r.hi + adj (correctly rounded) - */ - xy = dd_mul(xs, ys); - r = dd_add(xy.hi, zs); - - spread = ex + ey; - - if (r.hi == 0.0) { - /* - * When the addends cancel to 0, ensure that the result has - * the correct sign. - */ - fesetround(oround); - volatile long double vzs = zs; /* XXX gcc CSE bug workaround */ - return xy.hi + vzs + scalbnl(xy.lo, spread); - } - - if (oround != FE_TONEAREST) { - /* - * There is no need to worry about double rounding in directed - * rounding modes. - * But underflow may not be raised correctly, example in downward rounding: - * fmal(0x1.0000000001p-16000L, 0x1.0000000001p-400L, -0x1p-16440L) - */ - long double ret; -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - int e = fetestexcept(FE_INEXACT); - feclearexcept(FE_INEXACT); -#endif - fesetround(oround); - adj = r.lo + xy.lo; - ret = scalbnl(r.hi + adj, spread); -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - if (ilogbl(ret) < -16382 && fetestexcept(FE_INEXACT)) - feraiseexcept(FE_UNDERFLOW); - else if (e) - feraiseexcept(FE_INEXACT); -#endif - return ret; - } - - adj = add_adjusted(r.lo, xy.lo); - if (spread + ilogbl(r.hi) > -16383) - return scalbnl(r.hi + adj, spread); - else - return add_and_denormalize(r.hi, adj, spread); -} -#endif diff --git a/usr/lib/libc/math/fmax.c b/usr/lib/libc/math/fmax.c deleted file mode 100644 index 94f0caa17..000000000 --- a/usr/lib/libc/math/fmax.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -double fmax(double x, double y) -{ - if (isnan(x)) - return y; - if (isnan(y)) - return x; - /* handle signed zeros, see C99 Annex F.9.9.2 */ - if (signbit(x) != signbit(y)) - return signbit(x) ? y : x; - return x < y ? y : x; -} diff --git a/usr/lib/libc/math/fmaxf.c b/usr/lib/libc/math/fmaxf.c deleted file mode 100644 index 695d8179c..000000000 --- a/usr/lib/libc/math/fmaxf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -float fmaxf(float x, float y) -{ - if (isnan(x)) - return y; - if (isnan(y)) - return x; - /* handle signed zeroes, see C99 Annex F.9.9.2 */ - if (signbit(x) != signbit(y)) - return signbit(x) ? y : x; - return x < y ? y : x; -} diff --git a/usr/lib/libc/math/fmaxl.c b/usr/lib/libc/math/fmaxl.c deleted file mode 100644 index 4b03158e0..000000000 --- a/usr/lib/libc/math/fmaxl.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fmaxl(long double x, long double y) -{ - return fmax(x, y); -} -#else -long double fmaxl(long double x, long double y) -{ - if (isnan(x)) - return y; - if (isnan(y)) - return x; - /* handle signed zeros, see C99 Annex F.9.9.2 */ - if (signbit(x) != signbit(y)) - return signbit(x) ? y : x; - return x < y ? y : x; -} -#endif diff --git a/usr/lib/libc/math/fmin.c b/usr/lib/libc/math/fmin.c deleted file mode 100644 index 08a8fd17f..000000000 --- a/usr/lib/libc/math/fmin.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -double fmin(double x, double y) -{ - if (isnan(x)) - return y; - if (isnan(y)) - return x; - /* handle signed zeros, see C99 Annex F.9.9.2 */ - if (signbit(x) != signbit(y)) - return signbit(x) ? x : y; - return x < y ? x : y; -} diff --git a/usr/lib/libc/math/fminf.c b/usr/lib/libc/math/fminf.c deleted file mode 100644 index 3573c7de7..000000000 --- a/usr/lib/libc/math/fminf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -float fminf(float x, float y) -{ - if (isnan(x)) - return y; - if (isnan(y)) - return x; - /* handle signed zeros, see C99 Annex F.9.9.2 */ - if (signbit(x) != signbit(y)) - return signbit(x) ? x : y; - return x < y ? x : y; -} diff --git a/usr/lib/libc/math/fminl.c b/usr/lib/libc/math/fminl.c deleted file mode 100644 index 69bc24a79..000000000 --- a/usr/lib/libc/math/fminl.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fminl(long double x, long double y) -{ - return fmin(x, y); -} -#else -long double fminl(long double x, long double y) -{ - if (isnan(x)) - return y; - if (isnan(y)) - return x; - /* handle signed zeros, see C99 Annex F.9.9.2 */ - if (signbit(x) != signbit(y)) - return signbit(x) ? x : y; - return x < y ? x : y; -} -#endif diff --git a/usr/lib/libc/math/fmod.c b/usr/lib/libc/math/fmod.c deleted file mode 100644 index 6849722ba..000000000 --- a/usr/lib/libc/math/fmod.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -double fmod(double x, double y) -{ - union {double f; uint64_t i;} ux = {x}, uy = {y}; - int ex = ux.i>>52 & 0x7ff; - int ey = uy.i>>52 & 0x7ff; - int sx = ux.i>>63; - uint64_t i; - - /* in the followings uxi should be ux.i, but then gcc wrongly adds */ - /* float load/store to inner loops ruining performance and code size */ - uint64_t uxi = ux.i; - - if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff) - return (x*y)/(x*y); - if (uxi<<1 <= uy.i<<1) { - if (uxi<<1 == uy.i<<1) - return 0*x; - return x; - } - - /* normalize x and y */ - if (!ex) { - for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1); - uxi <<= -ex + 1; - } else { - uxi &= -1ULL >> 12; - uxi |= 1ULL << 52; - } - if (!ey) { - for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1); - uy.i <<= -ey + 1; - } else { - uy.i &= -1ULL >> 12; - uy.i |= 1ULL << 52; - } - - /* x mod y */ - for (; ex > ey; ex--) { - i = uxi - uy.i; - if (i >> 63 == 0) { - if (i == 0) - return 0*x; - uxi = i; - } - uxi <<= 1; - } - i = uxi - uy.i; - if (i >> 63 == 0) { - if (i == 0) - return 0*x; - uxi = i; - } - for (; uxi>>52 == 0; uxi <<= 1, ex--); - - /* scale result */ - if (ex > 0) { - uxi -= 1ULL << 52; - uxi |= (uint64_t)ex << 52; - } else { - uxi >>= -ex + 1; - } - uxi |= (uint64_t)sx << 63; - ux.i = uxi; - return ux.f; -} diff --git a/usr/lib/libc/math/fmodf.c b/usr/lib/libc/math/fmodf.c deleted file mode 100644 index ff58f9336..000000000 --- a/usr/lib/libc/math/fmodf.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include - -float fmodf(float x, float y) -{ - union {float f; uint32_t i;} ux = {x}, uy = {y}; - int ex = ux.i>>23 & 0xff; - int ey = uy.i>>23 & 0xff; - uint32_t sx = ux.i & 0x80000000; - uint32_t i; - uint32_t uxi = ux.i; - - if (uy.i<<1 == 0 || isnan(y) || ex == 0xff) - return (x*y)/(x*y); - if (uxi<<1 <= uy.i<<1) { - if (uxi<<1 == uy.i<<1) - return 0*x; - return x; - } - - /* normalize x and y */ - if (!ex) { - for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1); - uxi <<= -ex + 1; - } else { - uxi &= -1U >> 9; - uxi |= 1U << 23; - } - if (!ey) { - for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1); - uy.i <<= -ey + 1; - } else { - uy.i &= -1U >> 9; - uy.i |= 1U << 23; - } - - /* x mod y */ - for (; ex > ey; ex--) { - i = uxi - uy.i; - if (i >> 31 == 0) { - if (i == 0) - return 0*x; - uxi = i; - } - uxi <<= 1; - } - i = uxi - uy.i; - if (i >> 31 == 0) { - if (i == 0) - return 0*x; - uxi = i; - } - for (; uxi>>23 == 0; uxi <<= 1, ex--); - - /* scale result up */ - if (ex > 0) { - uxi -= 1U << 23; - uxi |= (uint32_t)ex << 23; - } else { - uxi >>= -ex + 1; - } - uxi |= sx; - ux.i = uxi; - return ux.f; -} diff --git a/usr/lib/libc/math/fmodl.c b/usr/lib/libc/math/fmodl.c deleted file mode 100644 index 9f5b87393..000000000 --- a/usr/lib/libc/math/fmodl.c +++ /dev/null @@ -1,105 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fmodl(long double x, long double y) -{ - return fmod(x, y); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double fmodl(long double x, long double y) -{ - union ldshape ux = {x}, uy = {y}; - int ex = ux.i.se & 0x7fff; - int ey = uy.i.se & 0x7fff; - int sx = ux.i.se & 0x8000; - - if (y == 0 || isnan(y) || ex == 0x7fff) - return (x*y)/(x*y); - ux.i.se = ex; - uy.i.se = ey; - if (ux.f <= uy.f) { - if (ux.f == uy.f) - return 0*x; - return x; - } - - /* normalize x and y */ - if (!ex) { - ux.f *= 0x1p120f; - ex = ux.i.se - 120; - } - if (!ey) { - uy.f *= 0x1p120f; - ey = uy.i.se - 120; - } - - /* x mod y */ -#if LDBL_MANT_DIG == 64 - uint64_t i, mx, my; - mx = ux.i.m; - my = uy.i.m; - for (; ex > ey; ex--) { - i = mx - my; - if (mx >= my) { - if (i == 0) - return 0*x; - mx = 2*i; - } else if (2*mx < mx) { - mx = 2*mx - my; - } else { - mx = 2*mx; - } - } - i = mx - my; - if (mx >= my) { - if (i == 0) - return 0*x; - mx = i; - } - for (; mx >> 63 == 0; mx *= 2, ex--); - ux.i.m = mx; -#elif LDBL_MANT_DIG == 113 - uint64_t hi, lo, xhi, xlo, yhi, ylo; - xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48; - yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48; - xlo = ux.i2.lo; - ylo = uy.i2.lo; - for (; ex > ey; ex--) { - hi = xhi - yhi; - lo = xlo - ylo; - if (xlo < ylo) - hi -= 1; - if (hi >> 63 == 0) { - if ((hi|lo) == 0) - return 0*x; - xhi = 2*hi + (lo>>63); - xlo = 2*lo; - } else { - xhi = 2*xhi + (xlo>>63); - xlo = 2*xlo; - } - } - hi = xhi - yhi; - lo = xlo - ylo; - if (xlo < ylo) - hi -= 1; - if (hi >> 63 == 0) { - if ((hi|lo) == 0) - return 0*x; - xhi = hi; - xlo = lo; - } - for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--); - ux.i2.hi = xhi; - ux.i2.lo = xlo; -#endif - - /* scale result */ - if (ex <= 0) { - ux.i.se = (ex+120)|sx; - ux.f *= 0x1p-120f; - } else - ux.i.se = ex|sx; - return ux.f; -} -#endif diff --git a/usr/lib/libc/math/frexp.c b/usr/lib/libc/math/frexp.c deleted file mode 100644 index 27b6266ed..000000000 --- a/usr/lib/libc/math/frexp.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -double frexp(double x, int *e) -{ - union { double d; uint64_t i; } y = { x }; - int ee = y.i>>52 & 0x7ff; - - if (!ee) { - if (x) { - x = frexp(x*0x1p64, e); - *e -= 64; - } else *e = 0; - return x; - } else if (ee == 0x7ff) { - return x; - } - - *e = ee - 0x3fe; - y.i &= 0x800fffffffffffffull; - y.i |= 0x3fe0000000000000ull; - return y.d; -} diff --git a/usr/lib/libc/math/frexpf.c b/usr/lib/libc/math/frexpf.c deleted file mode 100644 index 078709752..000000000 --- a/usr/lib/libc/math/frexpf.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -float frexpf(float x, int *e) -{ - union { float f; uint32_t i; } y = { x }; - int ee = y.i>>23 & 0xff; - - if (!ee) { - if (x) { - x = frexpf(x*0x1p64, e); - *e -= 64; - } else *e = 0; - return x; - } else if (ee == 0xff) { - return x; - } - - *e = ee - 0x7e; - y.i &= 0x807ffffful; - y.i |= 0x3f000000ul; - return y.f; -} diff --git a/usr/lib/libc/math/frexpl.c b/usr/lib/libc/math/frexpl.c deleted file mode 100644 index 3c1b55374..000000000 --- a/usr/lib/libc/math/frexpl.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double frexpl(long double x, int *e) -{ - return frexp(x, e); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double frexpl(long double x, int *e) -{ - union ldshape u = {x}; - int ee = u.i.se & 0x7fff; - - if (!ee) { - if (x) { - x = frexpl(x*0x1p120, e); - *e -= 120; - } else *e = 0; - return x; - } else if (ee == 0x7fff) { - return x; - } - - *e = ee - 0x3ffe; - u.i.se &= 0x8000; - u.i.se |= 0x3ffe; - return u.f; -} -#endif diff --git a/usr/lib/libc/math/hypot.c b/usr/lib/libc/math/hypot.c deleted file mode 100644 index 6071bf1e2..000000000 --- a/usr/lib/libc/math/hypot.c +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#include - -#if FLT_EVAL_METHOD > 1U && LDBL_MANT_DIG == 64 -#define SPLIT (0x1p32 + 1) -#else -#define SPLIT (0x1p27 + 1) -#endif - -static void sq(double_t *hi, double_t *lo, double x) -{ - double_t xh, xl, xc; - - xc = (double_t)x*SPLIT; - xh = x - xc + xc; - xl = x - xh; - *hi = (double_t)x*x; - *lo = xh*xh - *hi + 2*xh*xl + xl*xl; -} - -double hypot(double x, double y) -{ - union {double f; uint64_t i;} ux = {x}, uy = {y}, ut; - int ex, ey; - double_t hx, lx, hy, ly, z; - - /* arrange |x| >= |y| */ - ux.i &= -1ULL>>1; - uy.i &= -1ULL>>1; - if (ux.i < uy.i) { - ut = ux; - ux = uy; - uy = ut; - } - - /* special cases */ - ex = ux.i>>52; - ey = uy.i>>52; - x = ux.f; - y = uy.f; - /* note: hypot(inf,nan) == inf */ - if (ey == 0x7ff) - return y; - if (ex == 0x7ff || uy.i == 0) - return x; - /* note: hypot(x,y) ~= x + y*y/x/2 with inexact for small y/x */ - /* 64 difference is enough for ld80 double_t */ - if (ex - ey > 64) - return x + y; - - /* precise sqrt argument in nearest rounding mode without overflow */ - /* xh*xh must not overflow and xl*xl must not underflow in sq */ - z = 1; - if (ex > 0x3ff+510) { - z = 0x1p700; - x *= 0x1p-700; - y *= 0x1p-700; - } else if (ey < 0x3ff-450) { - z = 0x1p-700; - x *= 0x1p700; - y *= 0x1p700; - } - sq(&hx, &lx, x); - sq(&hy, &ly, y); - return z*sqrt(ly+lx+hy+hx); -} diff --git a/usr/lib/libc/math/hypotf.c b/usr/lib/libc/math/hypotf.c deleted file mode 100644 index 2fc214b72..000000000 --- a/usr/lib/libc/math/hypotf.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -float hypotf(float x, float y) -{ - union {float f; uint32_t i;} ux = {x}, uy = {y}, ut; - float_t z; - - ux.i &= -1U>>1; - uy.i &= -1U>>1; - if (ux.i < uy.i) { - ut = ux; - ux = uy; - uy = ut; - } - - x = ux.f; - y = uy.f; - if (uy.i == 0xff<<23) - return y; - if (ux.i >= 0xff<<23 || uy.i == 0 || ux.i - uy.i >= 25<<23) - return x + y; - - z = 1; - if (ux.i >= (0x7f+60)<<23) { - z = 0x1p90f; - x *= 0x1p-90f; - y *= 0x1p-90f; - } else if (uy.i < (0x7f-60)<<23) { - z = 0x1p-90f; - x *= 0x1p90f; - y *= 0x1p90f; - } - return z*sqrtf((double)x*x + (double)y*y); -} diff --git a/usr/lib/libc/math/hypotl.c b/usr/lib/libc/math/hypotl.c deleted file mode 100644 index 479aa92c3..000000000 --- a/usr/lib/libc/math/hypotl.c +++ /dev/null @@ -1,66 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double hypotl(long double x, long double y) -{ - return hypot(x, y); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#if LDBL_MANT_DIG == 64 -#define SPLIT (0x1p32L+1) -#elif LDBL_MANT_DIG == 113 -#define SPLIT (0x1p57L+1) -#endif - -static void sq(long double *hi, long double *lo, long double x) -{ - long double xh, xl, xc; - xc = x*SPLIT; - xh = x - xc + xc; - xl = x - xh; - *hi = x*x; - *lo = xh*xh - *hi + 2*xh*xl + xl*xl; -} - -long double hypotl(long double x, long double y) -{ - union ldshape ux = {x}, uy = {y}; - int ex, ey; - long double hx, lx, hy, ly, z; - - ux.i.se &= 0x7fff; - uy.i.se &= 0x7fff; - if (ux.i.se < uy.i.se) { - ex = uy.i.se; - ey = ux.i.se; - x = uy.f; - y = ux.f; - } else { - ex = ux.i.se; - ey = uy.i.se; - x = ux.f; - y = uy.f; - } - - if (ex == 0x7fff && isinf(y)) - return y; - if (ex == 0x7fff || y == 0) - return x; - if (ex - ey > LDBL_MANT_DIG) - return x + y; - - z = 1; - if (ex > 0x3fff+8000) { - z = 0x1p10000L; - x *= 0x1p-10000L; - y *= 0x1p-10000L; - } else if (ey < 0x3fff-8000) { - z = 0x1p-10000L; - x *= 0x1p10000L; - y *= 0x1p10000L; - } - sq(&hx, &lx, x); - sq(&hy, &ly, y); - return z*sqrtl(ly+lx+hy+hx); -} -#endif diff --git a/usr/lib/libc/math/ilogb.c b/usr/lib/libc/math/ilogb.c deleted file mode 100644 index 64d40154d..000000000 --- a/usr/lib/libc/math/ilogb.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "libm.h" - -int ilogb(double x) -{ - #pragma STDC FENV_ACCESS ON - union {double f; uint64_t i;} u = {x}; - uint64_t i = u.i; - int e = i>>52 & 0x7ff; - - if (!e) { - i <<= 12; - if (i == 0) { - FORCE_EVAL(0/0.0f); - return FP_ILOGB0; - } - /* subnormal x */ - for (e = -0x3ff; i>>63 == 0; e--, i<<=1); - return e; - } - if (e == 0x7ff) { - FORCE_EVAL(0/0.0f); - return i<<12 ? FP_ILOGBNAN : INT_MAX; - } - return e - 0x3ff; -} diff --git a/usr/lib/libc/math/ilogbf.c b/usr/lib/libc/math/ilogbf.c deleted file mode 100644 index e23ba209e..000000000 --- a/usr/lib/libc/math/ilogbf.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "libm.h" - -int ilogbf(float x) -{ - #pragma STDC FENV_ACCESS ON - union {float f; uint32_t i;} u = {x}; - uint32_t i = u.i; - int e = i>>23 & 0xff; - - if (!e) { - i <<= 9; - if (i == 0) { - FORCE_EVAL(0/0.0f); - return FP_ILOGB0; - } - /* subnormal x */ - for (e = -0x7f; i>>31 == 0; e--, i<<=1); - return e; - } - if (e == 0xff) { - FORCE_EVAL(0/0.0f); - return i<<9 ? FP_ILOGBNAN : INT_MAX; - } - return e - 0x7f; -} diff --git a/usr/lib/libc/math/ilogbl.c b/usr/lib/libc/math/ilogbl.c deleted file mode 100644 index 7b1a9cf8d..000000000 --- a/usr/lib/libc/math/ilogbl.c +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -int ilogbl(long double x) -{ - return ilogb(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -int ilogbl(long double x) -{ - #pragma STDC FENV_ACCESS ON - union ldshape u = {x}; - uint64_t m = u.i.m; - int e = u.i.se & 0x7fff; - - if (!e) { - if (m == 0) { - FORCE_EVAL(0/0.0f); - return FP_ILOGB0; - } - /* subnormal x */ - for (e = -0x3fff+1; m>>63 == 0; e--, m<<=1); - return e; - } - if (e == 0x7fff) { - FORCE_EVAL(0/0.0f); - return m<<1 ? FP_ILOGBNAN : INT_MAX; - } - return e - 0x3fff; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -int ilogbl(long double x) -{ - #pragma STDC FENV_ACCESS ON - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - - if (!e) { - if (x == 0) { - FORCE_EVAL(0/0.0f); - return FP_ILOGB0; - } - /* subnormal x */ - x *= 0x1p120; - return ilogbl(x) - 120; - } - if (e == 0x7fff) { - FORCE_EVAL(0/0.0f); - u.i.se = 0; - return u.f ? FP_ILOGBNAN : INT_MAX; - } - return e - 0x3fff; -} -#endif diff --git a/usr/lib/libc/math/j0.c b/usr/lib/libc/math/j0.c deleted file mode 100644 index d722d9428..000000000 --- a/usr/lib/libc/math/j0.c +++ /dev/null @@ -1,375 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_j0.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* j0(x), y0(x) - * Bessel function of the first and second kinds of order zero. - * Method -- j0(x): - * 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ... - * 2. Reduce x to |x| since j0(x)=j0(-x), and - * for x in (0,2) - * j0(x) = 1-z/4+ z^2*R0/S0, where z = x*x; - * (precision: |j0-1+z/4-z^2R0/S0 |<2**-63.67 ) - * for x in (2,inf) - * j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0)) - * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0) - * as follow: - * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4) - * = 1/sqrt(2) * (cos(x) + sin(x)) - * sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4) - * = 1/sqrt(2) * (sin(x) - cos(x)) - * (To avoid cancellation, use - * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) - * to compute the worse one.) - * - * 3 Special cases - * j0(nan)= nan - * j0(0) = 1 - * j0(inf) = 0 - * - * Method -- y0(x): - * 1. For x<2. - * Since - * y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...) - * therefore y0(x)-2/pi*j0(x)*ln(x) is an even function. - * We use the following function to approximate y0, - * y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2 - * where - * U(z) = u00 + u01*z + ... + u06*z^6 - * V(z) = 1 + v01*z + ... + v04*z^4 - * with absolute approximation error bounded by 2**-72. - * Note: For tiny x, U/V = u0 and j0(x)~1, hence - * y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27) - * 2. For x>=2. - * y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0)) - * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0) - * by the method mentioned above. - * 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0. - */ - -#include "libm.h" - -static double pzero(double), qzero(double); - -static const double -invsqrtpi = 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */ -tpi = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */ - -/* common method when |x|>=2 */ -static double common(uint32_t ix, double x, int y0) -{ - double s,c,ss,cc,z; - - /* - * j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x-pi/4)-q0(x)*sin(x-pi/4)) - * y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x-pi/4)+q0(x)*cos(x-pi/4)) - * - * sin(x-pi/4) = (sin(x) - cos(x))/sqrt(2) - * cos(x-pi/4) = (sin(x) + cos(x))/sqrt(2) - * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) - */ - s = sin(x); - c = cos(x); - if (y0) - c = -c; - cc = s+c; - /* avoid overflow in 2*x, big ulp error when x>=0x1p1023 */ - if (ix < 0x7fe00000) { - ss = s-c; - z = -cos(2*x); - if (s*c < 0) - cc = z/ss; - else - ss = z/cc; - if (ix < 0x48000000) { - if (y0) - ss = -ss; - cc = pzero(x)*cc-qzero(x)*ss; - } - } - return invsqrtpi*cc/sqrt(x); -} - -/* R0/S0 on [0, 2.00] */ -static const double -R02 = 1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */ -R03 = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */ -R04 = 1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */ -R05 = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */ -S01 = 1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */ -S02 = 1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */ -S03 = 5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */ -S04 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */ - -double j0(double x) -{ - double z,r,s; - uint32_t ix; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - - /* j0(+-inf)=0, j0(nan)=nan */ - if (ix >= 0x7ff00000) - return 1/(x*x); - x = fabs(x); - - if (ix >= 0x40000000) { /* |x| >= 2 */ - /* large ulp error near zeros: 2.4, 5.52, 8.6537,.. */ - return common(ix,x,0); - } - - /* 1 - x*x/4 + x*x*R(x^2)/S(x^2) */ - if (ix >= 0x3f200000) { /* |x| >= 2**-13 */ - /* up to 4ulp error close to 2 */ - z = x*x; - r = z*(R02+z*(R03+z*(R04+z*R05))); - s = 1+z*(S01+z*(S02+z*(S03+z*S04))); - return (1+x/2)*(1-x/2) + z*(r/s); - } - - /* 1 - x*x/4 */ - /* prevent underflow */ - /* inexact should be raised when x!=0, this is not done correctly */ - if (ix >= 0x38000000) /* |x| >= 2**-127 */ - x = 0.25*x*x; - return 1 - x; -} - -static const double -u00 = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */ -u01 = 1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */ -u02 = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */ -u03 = 3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */ -u04 = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */ -u05 = 1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */ -u06 = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */ -v01 = 1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */ -v02 = 7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */ -v03 = 2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */ -v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */ - -double y0(double x) -{ - double z,u,v; - uint32_t ix,lx; - - EXTRACT_WORDS(ix, lx, x); - - /* y0(nan)=nan, y0(<0)=nan, y0(0)=-inf, y0(inf)=0 */ - if ((ix<<1 | lx) == 0) - return -1/0.0; - if (ix>>31) - return 0/0.0; - if (ix >= 0x7ff00000) - return 1/x; - - if (ix >= 0x40000000) { /* x >= 2 */ - /* large ulp errors near zeros: 3.958, 7.086,.. */ - return common(ix,x,1); - } - - /* U(x^2)/V(x^2) + (2/pi)*j0(x)*log(x) */ - if (ix >= 0x3e400000) { /* x >= 2**-27 */ - /* large ulp error near the first zero, x ~= 0.89 */ - z = x*x; - u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06))))); - v = 1.0+z*(v01+z*(v02+z*(v03+z*v04))); - return u/v + tpi*(j0(x)*log(x)); - } - return u00 + tpi*log(x); -} - -/* The asymptotic expansions of pzero is - * 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x. - * For x >= 2, We approximate pzero by - * pzero(x) = 1 + (R/S) - * where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10 - * S = 1 + pS0*s^2 + ... + pS4*s^10 - * and - * | pzero(x)-1-R/S | <= 2 ** ( -60.26) - */ -static const double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ - -7.03124999999900357484e-02, /* 0xBFB1FFFF, 0xFFFFFD32 */ - -8.08167041275349795626e+00, /* 0xC02029D0, 0xB44FA779 */ - -2.57063105679704847262e+02, /* 0xC0701102, 0x7B19E863 */ - -2.48521641009428822144e+03, /* 0xC0A36A6E, 0xCD4DCAFC */ - -5.25304380490729545272e+03, /* 0xC0B4850B, 0x36CC643D */ -}; -static const double pS8[5] = { - 1.16534364619668181717e+02, /* 0x405D2233, 0x07A96751 */ - 3.83374475364121826715e+03, /* 0x40ADF37D, 0x50596938 */ - 4.05978572648472545552e+04, /* 0x40E3D2BB, 0x6EB6B05F */ - 1.16752972564375915681e+05, /* 0x40FC810F, 0x8F9FA9BD */ - 4.76277284146730962675e+04, /* 0x40E74177, 0x4F2C49DC */ -}; - -static const double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - -1.14125464691894502584e-11, /* 0xBDA918B1, 0x47E495CC */ - -7.03124940873599280078e-02, /* 0xBFB1FFFF, 0xE69AFBC6 */ - -4.15961064470587782438e+00, /* 0xC010A370, 0xF90C6BBF */ - -6.76747652265167261021e+01, /* 0xC050EB2F, 0x5A7D1783 */ - -3.31231299649172967747e+02, /* 0xC074B3B3, 0x6742CC63 */ - -3.46433388365604912451e+02, /* 0xC075A6EF, 0x28A38BD7 */ -}; -static const double pS5[5] = { - 6.07539382692300335975e+01, /* 0x404E6081, 0x0C98C5DE */ - 1.05125230595704579173e+03, /* 0x40906D02, 0x5C7E2864 */ - 5.97897094333855784498e+03, /* 0x40B75AF8, 0x8FBE1D60 */ - 9.62544514357774460223e+03, /* 0x40C2CCB8, 0xFA76FA38 */ - 2.40605815922939109441e+03, /* 0x40A2CC1D, 0xC70BE864 */ -}; - -static const double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ - -2.54704601771951915620e-09, /* 0xBE25E103, 0x6FE1AA86 */ - -7.03119616381481654654e-02, /* 0xBFB1FFF6, 0xF7C0E24B */ - -2.40903221549529611423e+00, /* 0xC00345B2, 0xAEA48074 */ - -2.19659774734883086467e+01, /* 0xC035F74A, 0x4CB94E14 */ - -5.80791704701737572236e+01, /* 0xC04D0A22, 0x420A1A45 */ - -3.14479470594888503854e+01, /* 0xC03F72AC, 0xA892D80F */ -}; -static const double pS3[5] = { - 3.58560338055209726349e+01, /* 0x4041ED92, 0x84077DD3 */ - 3.61513983050303863820e+02, /* 0x40769839, 0x464A7C0E */ - 1.19360783792111533330e+03, /* 0x4092A66E, 0x6D1061D6 */ - 1.12799679856907414432e+03, /* 0x40919FFC, 0xB8C39B7E */ - 1.73580930813335754692e+02, /* 0x4065B296, 0xFC379081 */ -}; - -static const double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - -8.87534333032526411254e-08, /* 0xBE77D316, 0xE927026D */ - -7.03030995483624743247e-02, /* 0xBFB1FF62, 0x495E1E42 */ - -1.45073846780952986357e+00, /* 0xBFF73639, 0x8A24A843 */ - -7.63569613823527770791e+00, /* 0xC01E8AF3, 0xEDAFA7F3 */ - -1.11931668860356747786e+01, /* 0xC02662E6, 0xC5246303 */ - -3.23364579351335335033e+00, /* 0xC009DE81, 0xAF8FE70F */ -}; -static const double pS2[5] = { - 2.22202997532088808441e+01, /* 0x40363865, 0x908B5959 */ - 1.36206794218215208048e+02, /* 0x4061069E, 0x0EE8878F */ - 2.70470278658083486789e+02, /* 0x4070E786, 0x42EA079B */ - 1.53875394208320329881e+02, /* 0x40633C03, 0x3AB6FAFF */ - 1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */ -}; - -static double pzero(double x) -{ - const double *p,*q; - double_t z,r,s; - uint32_t ix; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x40200000){p = pR8; q = pS8;} - else if (ix >= 0x40122E8B){p = pR5; q = pS5;} - else if (ix >= 0x4006DB6D){p = pR3; q = pS3;} - else /*ix >= 0x40000000*/ {p = pR2; q = pS2;} - z = 1.0/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); - return 1.0 + r/s; -} - - -/* For x >= 8, the asymptotic expansions of qzero is - * -1/8 s + 75/1024 s^3 - ..., where s = 1/x. - * We approximate pzero by - * qzero(x) = s*(-1.25 + (R/S)) - * where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10 - * S = 1 + qS0*s^2 + ... + qS5*s^12 - * and - * | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22) - */ -static const double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ - 7.32421874999935051953e-02, /* 0x3FB2BFFF, 0xFFFFFE2C */ - 1.17682064682252693899e+01, /* 0x40278952, 0x5BB334D6 */ - 5.57673380256401856059e+02, /* 0x40816D63, 0x15301825 */ - 8.85919720756468632317e+03, /* 0x40C14D99, 0x3E18F46D */ - 3.70146267776887834771e+04, /* 0x40E212D4, 0x0E901566 */ -}; -static const double qS8[6] = { - 1.63776026895689824414e+02, /* 0x406478D5, 0x365B39BC */ - 8.09834494656449805916e+03, /* 0x40BFA258, 0x4E6B0563 */ - 1.42538291419120476348e+05, /* 0x41016652, 0x54D38C3F */ - 8.03309257119514397345e+05, /* 0x412883DA, 0x83A52B43 */ - 8.40501579819060512818e+05, /* 0x4129A66B, 0x28DE0B3D */ - -3.43899293537866615225e+05, /* 0xC114FD6D, 0x2C9530C5 */ -}; - -static const double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - 1.84085963594515531381e-11, /* 0x3DB43D8F, 0x29CC8CD9 */ - 7.32421766612684765896e-02, /* 0x3FB2BFFF, 0xD172B04C */ - 5.83563508962056953777e+00, /* 0x401757B0, 0xB9953DD3 */ - 1.35111577286449829671e+02, /* 0x4060E392, 0x0A8788E9 */ - 1.02724376596164097464e+03, /* 0x40900CF9, 0x9DC8C481 */ - 1.98997785864605384631e+03, /* 0x409F17E9, 0x53C6E3A6 */ -}; -static const double qS5[6] = { - 8.27766102236537761883e+01, /* 0x4054B1B3, 0xFB5E1543 */ - 2.07781416421392987104e+03, /* 0x40A03BA0, 0xDA21C0CE */ - 1.88472887785718085070e+04, /* 0x40D267D2, 0x7B591E6D */ - 5.67511122894947329769e+04, /* 0x40EBB5E3, 0x97E02372 */ - 3.59767538425114471465e+04, /* 0x40E19118, 0x1F7A54A0 */ - -5.35434275601944773371e+03, /* 0xC0B4EA57, 0xBEDBC609 */ -}; - -static const double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ - 4.37741014089738620906e-09, /* 0x3E32CD03, 0x6ADECB82 */ - 7.32411180042911447163e-02, /* 0x3FB2BFEE, 0x0E8D0842 */ - 3.34423137516170720929e+00, /* 0x400AC0FC, 0x61149CF5 */ - 4.26218440745412650017e+01, /* 0x40454F98, 0x962DAEDD */ - 1.70808091340565596283e+02, /* 0x406559DB, 0xE25EFD1F */ - 1.66733948696651168575e+02, /* 0x4064D77C, 0x81FA21E0 */ -}; -static const double qS3[6] = { - 4.87588729724587182091e+01, /* 0x40486122, 0xBFE343A6 */ - 7.09689221056606015736e+02, /* 0x40862D83, 0x86544EB3 */ - 3.70414822620111362994e+03, /* 0x40ACF04B, 0xE44DFC63 */ - 6.46042516752568917582e+03, /* 0x40B93C6C, 0xD7C76A28 */ - 2.51633368920368957333e+03, /* 0x40A3A8AA, 0xD94FB1C0 */ - -1.49247451836156386662e+02, /* 0xC062A7EB, 0x201CF40F */ -}; - -static const double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - 1.50444444886983272379e-07, /* 0x3E84313B, 0x54F76BDB */ - 7.32234265963079278272e-02, /* 0x3FB2BEC5, 0x3E883E34 */ - 1.99819174093815998816e+00, /* 0x3FFFF897, 0xE727779C */ - 1.44956029347885735348e+01, /* 0x402CFDBF, 0xAAF96FE5 */ - 3.16662317504781540833e+01, /* 0x403FAA8E, 0x29FBDC4A */ - 1.62527075710929267416e+01, /* 0x403040B1, 0x71814BB4 */ -}; -static const double qS2[6] = { - 3.03655848355219184498e+01, /* 0x403E5D96, 0xF7C07AED */ - 2.69348118608049844624e+02, /* 0x4070D591, 0xE4D14B40 */ - 8.44783757595320139444e+02, /* 0x408A6645, 0x22B3BF22 */ - 8.82935845112488550512e+02, /* 0x408B977C, 0x9C5CC214 */ - 2.12666388511798828631e+02, /* 0x406A9553, 0x0E001365 */ - -5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */ -}; - -static double qzero(double x) -{ - const double *p,*q; - double_t s,r,z; - uint32_t ix; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x40200000){p = qR8; q = qS8;} - else if (ix >= 0x40122E8B){p = qR5; q = qS5;} - else if (ix >= 0x4006DB6D){p = qR3; q = qS3;} - else /*ix >= 0x40000000*/ {p = qR2; q = qS2;} - z = 1.0/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); - return (-.125 + r/s)/x; -} diff --git a/usr/lib/libc/math/j0f.c b/usr/lib/libc/math/j0f.c deleted file mode 100644 index fab554a31..000000000 --- a/usr/lib/libc/math/j0f.c +++ /dev/null @@ -1,314 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_j0f.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#define _GNU_SOURCE -#include "libm.h" - -static float pzerof(float), qzerof(float); - -static const float -invsqrtpi = 5.6418961287e-01, /* 0x3f106ebb */ -tpi = 6.3661974669e-01; /* 0x3f22f983 */ - -static float common(uint32_t ix, float x, int y0) -{ - float z,s,c,ss,cc; - /* - * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x) - * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x) - */ - s = sinf(x); - c = cosf(x); - if (y0) - c = -c; - cc = s+c; - if (ix < 0x7f000000) { - ss = s-c; - z = -cosf(2*x); - if (s*c < 0) - cc = z/ss; - else - ss = z/cc; - if (ix < 0x58800000) { - if (y0) - ss = -ss; - cc = pzerof(x)*cc-qzerof(x)*ss; - } - } - return invsqrtpi*cc/sqrtf(x); -} - -/* R0/S0 on [0, 2.00] */ -static const float -R02 = 1.5625000000e-02, /* 0x3c800000 */ -R03 = -1.8997929874e-04, /* 0xb947352e */ -R04 = 1.8295404516e-06, /* 0x35f58e88 */ -R05 = -4.6183270541e-09, /* 0xb19eaf3c */ -S01 = 1.5619102865e-02, /* 0x3c7fe744 */ -S02 = 1.1692678527e-04, /* 0x38f53697 */ -S03 = 5.1354652442e-07, /* 0x3509daa6 */ -S04 = 1.1661400734e-09; /* 0x30a045e8 */ - -float j0f(float x) -{ - float z,r,s; - uint32_t ix; - - GET_FLOAT_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x7f800000) - return 1/(x*x); - x = fabsf(x); - - if (ix >= 0x40000000) { /* |x| >= 2 */ - /* large ulp error near zeros */ - return common(ix, x, 0); - } - if (ix >= 0x3a000000) { /* |x| >= 2**-11 */ - /* up to 4ulp error near 2 */ - z = x*x; - r = z*(R02+z*(R03+z*(R04+z*R05))); - s = 1+z*(S01+z*(S02+z*(S03+z*S04))); - return (1+x/2)*(1-x/2) + z*(r/s); - } - if (ix >= 0x21800000) /* |x| >= 2**-60 */ - x = 0.25f*x*x; - return 1 - x; -} - -static const float -u00 = -7.3804296553e-02, /* 0xbd9726b5 */ -u01 = 1.7666645348e-01, /* 0x3e34e80d */ -u02 = -1.3818567619e-02, /* 0xbc626746 */ -u03 = 3.4745343146e-04, /* 0x39b62a69 */ -u04 = -3.8140706238e-06, /* 0xb67ff53c */ -u05 = 1.9559013964e-08, /* 0x32a802ba */ -u06 = -3.9820518410e-11, /* 0xae2f21eb */ -v01 = 1.2730483897e-02, /* 0x3c509385 */ -v02 = 7.6006865129e-05, /* 0x389f65e0 */ -v03 = 2.5915085189e-07, /* 0x348b216c */ -v04 = 4.4111031494e-10; /* 0x2ff280c2 */ - -float y0f(float x) -{ - float z,u,v; - uint32_t ix; - - GET_FLOAT_WORD(ix, x); - if ((ix & 0x7fffffff) == 0) - return -1/0.0f; - if (ix>>31) - return 0/0.0f; - if (ix >= 0x7f800000) - return 1/x; - if (ix >= 0x40000000) { /* |x| >= 2.0 */ - /* large ulp error near zeros */ - return common(ix,x,1); - } - if (ix >= 0x39000000) { /* x >= 2**-13 */ - /* large ulp error at x ~= 0.89 */ - z = x*x; - u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06))))); - v = 1+z*(v01+z*(v02+z*(v03+z*v04))); - return u/v + tpi*(j0f(x)*logf(x)); - } - return u00 + tpi*logf(x); -} - -/* The asymptotic expansions of pzero is - * 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x. - * For x >= 2, We approximate pzero by - * pzero(x) = 1 + (R/S) - * where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10 - * S = 1 + pS0*s^2 + ... + pS4*s^10 - * and - * | pzero(x)-1-R/S | <= 2 ** ( -60.26) - */ -static const float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.0000000000e+00, /* 0x00000000 */ - -7.0312500000e-02, /* 0xbd900000 */ - -8.0816707611e+00, /* 0xc1014e86 */ - -2.5706311035e+02, /* 0xc3808814 */ - -2.4852163086e+03, /* 0xc51b5376 */ - -5.2530439453e+03, /* 0xc5a4285a */ -}; -static const float pS8[5] = { - 1.1653436279e+02, /* 0x42e91198 */ - 3.8337448730e+03, /* 0x456f9beb */ - 4.0597855469e+04, /* 0x471e95db */ - 1.1675296875e+05, /* 0x47e4087c */ - 4.7627726562e+04, /* 0x473a0bba */ -}; -static const float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - -1.1412546255e-11, /* 0xad48c58a */ - -7.0312492549e-02, /* 0xbd8fffff */ - -4.1596107483e+00, /* 0xc0851b88 */ - -6.7674766541e+01, /* 0xc287597b */ - -3.3123129272e+02, /* 0xc3a59d9b */ - -3.4643338013e+02, /* 0xc3ad3779 */ -}; -static const float pS5[5] = { - 6.0753936768e+01, /* 0x42730408 */ - 1.0512523193e+03, /* 0x44836813 */ - 5.9789707031e+03, /* 0x45bad7c4 */ - 9.6254453125e+03, /* 0x461665c8 */ - 2.4060581055e+03, /* 0x451660ee */ -}; - -static const float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ - -2.5470459075e-09, /* 0xb12f081b */ - -7.0311963558e-02, /* 0xbd8fffb8 */ - -2.4090321064e+00, /* 0xc01a2d95 */ - -2.1965976715e+01, /* 0xc1afba52 */ - -5.8079170227e+01, /* 0xc2685112 */ - -3.1447946548e+01, /* 0xc1fb9565 */ -}; -static const float pS3[5] = { - 3.5856033325e+01, /* 0x420f6c94 */ - 3.6151397705e+02, /* 0x43b4c1ca */ - 1.1936077881e+03, /* 0x44953373 */ - 1.1279968262e+03, /* 0x448cffe6 */ - 1.7358093262e+02, /* 0x432d94b8 */ -}; - -static const float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - -8.8753431271e-08, /* 0xb3be98b7 */ - -7.0303097367e-02, /* 0xbd8ffb12 */ - -1.4507384300e+00, /* 0xbfb9b1cc */ - -7.6356959343e+00, /* 0xc0f4579f */ - -1.1193166733e+01, /* 0xc1331736 */ - -3.2336456776e+00, /* 0xc04ef40d */ -}; -static const float pS2[5] = { - 2.2220300674e+01, /* 0x41b1c32d */ - 1.3620678711e+02, /* 0x430834f0 */ - 2.7047027588e+02, /* 0x43873c32 */ - 1.5387539673e+02, /* 0x4319e01a */ - 1.4657617569e+01, /* 0x416a859a */ -}; - -static float pzerof(float x) -{ - const float *p,*q; - float_t z,r,s; - uint32_t ix; - - GET_FLOAT_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x41000000){p = pR8; q = pS8;} - else if (ix >= 0x409173eb){p = pR5; q = pS5;} - else if (ix >= 0x4036d917){p = pR3; q = pS3;} - else /*ix >= 0x40000000*/ {p = pR2; q = pS2;} - z = 1.0f/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); - return 1.0f + r/s; -} - - -/* For x >= 8, the asymptotic expansions of qzero is - * -1/8 s + 75/1024 s^3 - ..., where s = 1/x. - * We approximate pzero by - * qzero(x) = s*(-1.25 + (R/S)) - * where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10 - * S = 1 + qS0*s^2 + ... + qS5*s^12 - * and - * | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22) - */ -static const float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.0000000000e+00, /* 0x00000000 */ - 7.3242187500e-02, /* 0x3d960000 */ - 1.1768206596e+01, /* 0x413c4a93 */ - 5.5767340088e+02, /* 0x440b6b19 */ - 8.8591972656e+03, /* 0x460a6cca */ - 3.7014625000e+04, /* 0x471096a0 */ -}; -static const float qS8[6] = { - 1.6377603149e+02, /* 0x4323c6aa */ - 8.0983447266e+03, /* 0x45fd12c2 */ - 1.4253829688e+05, /* 0x480b3293 */ - 8.0330925000e+05, /* 0x49441ed4 */ - 8.4050156250e+05, /* 0x494d3359 */ - -3.4389928125e+05, /* 0xc8a7eb69 */ -}; - -static const float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - 1.8408595828e-11, /* 0x2da1ec79 */ - 7.3242180049e-02, /* 0x3d95ffff */ - 5.8356351852e+00, /* 0x40babd86 */ - 1.3511157227e+02, /* 0x43071c90 */ - 1.0272437744e+03, /* 0x448067cd */ - 1.9899779053e+03, /* 0x44f8bf4b */ -}; -static const float qS5[6] = { - 8.2776611328e+01, /* 0x42a58da0 */ - 2.0778142090e+03, /* 0x4501dd07 */ - 1.8847289062e+04, /* 0x46933e94 */ - 5.6751113281e+04, /* 0x475daf1d */ - 3.5976753906e+04, /* 0x470c88c1 */ - -5.3543427734e+03, /* 0xc5a752be */ -}; - -static const float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ - 4.3774099900e-09, /* 0x3196681b */ - 7.3241114616e-02, /* 0x3d95ff70 */ - 3.3442313671e+00, /* 0x405607e3 */ - 4.2621845245e+01, /* 0x422a7cc5 */ - 1.7080809021e+02, /* 0x432acedf */ - 1.6673394775e+02, /* 0x4326bbe4 */ -}; -static const float qS3[6] = { - 4.8758872986e+01, /* 0x42430916 */ - 7.0968920898e+02, /* 0x44316c1c */ - 3.7041481934e+03, /* 0x4567825f */ - 6.4604252930e+03, /* 0x45c9e367 */ - 2.5163337402e+03, /* 0x451d4557 */ - -1.4924745178e+02, /* 0xc3153f59 */ -}; - -static const float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - 1.5044444979e-07, /* 0x342189db */ - 7.3223426938e-02, /* 0x3d95f62a */ - 1.9981917143e+00, /* 0x3fffc4bf */ - 1.4495602608e+01, /* 0x4167edfd */ - 3.1666231155e+01, /* 0x41fd5471 */ - 1.6252708435e+01, /* 0x4182058c */ -}; -static const float qS2[6] = { - 3.0365585327e+01, /* 0x41f2ecb8 */ - 2.6934811401e+02, /* 0x4386ac8f */ - 8.4478375244e+02, /* 0x44533229 */ - 8.8293585205e+02, /* 0x445cbbe5 */ - 2.1266638184e+02, /* 0x4354aa98 */ - -5.3109550476e+00, /* 0xc0a9f358 */ -}; - -static float qzerof(float x) -{ - const float *p,*q; - float_t s,r,z; - uint32_t ix; - - GET_FLOAT_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x41000000){p = qR8; q = qS8;} - else if (ix >= 0x409173eb){p = qR5; q = qS5;} - else if (ix >= 0x4036d917){p = qR3; q = qS3;} - else /*ix >= 0x40000000*/ {p = qR2; q = qS2;} - z = 1.0f/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); - return (-.125f + r/s)/x; -} diff --git a/usr/lib/libc/math/j1.c b/usr/lib/libc/math/j1.c deleted file mode 100644 index df724d172..000000000 --- a/usr/lib/libc/math/j1.c +++ /dev/null @@ -1,362 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_j1.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* j1(x), y1(x) - * Bessel function of the first and second kinds of order zero. - * Method -- j1(x): - * 1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ... - * 2. Reduce x to |x| since j1(x)=-j1(-x), and - * for x in (0,2) - * j1(x) = x/2 + x*z*R0/S0, where z = x*x; - * (precision: |j1/x - 1/2 - R0/S0 |<2**-61.51 ) - * for x in (2,inf) - * j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1)) - * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1)) - * where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1) - * as follow: - * cos(x1) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4) - * = 1/sqrt(2) * (sin(x) - cos(x)) - * sin(x1) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4) - * = -1/sqrt(2) * (sin(x) + cos(x)) - * (To avoid cancellation, use - * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) - * to compute the worse one.) - * - * 3 Special cases - * j1(nan)= nan - * j1(0) = 0 - * j1(inf) = 0 - * - * Method -- y1(x): - * 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN - * 2. For x<2. - * Since - * y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...) - * therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function. - * We use the following function to approximate y1, - * y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2 - * where for x in [0,2] (abs err less than 2**-65.89) - * U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4 - * V(z) = 1 + v0[0]*z + ... + v0[4]*z^5 - * Note: For tiny x, 1/x dominate y1 and hence - * y1(tiny) = -2/pi/tiny, (choose tiny<2**-54) - * 3. For x>=2. - * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1)) - * where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1) - * by method mentioned above. - */ - -#include "libm.h" - -static double pone(double), qone(double); - -static const double -invsqrtpi = 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */ -tpi = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */ - -static double common(uint32_t ix, double x, int y1, int sign) -{ - double z,s,c,ss,cc; - - /* - * j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x-3pi/4)-q1(x)*sin(x-3pi/4)) - * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x-3pi/4)+q1(x)*cos(x-3pi/4)) - * - * sin(x-3pi/4) = -(sin(x) + cos(x))/sqrt(2) - * cos(x-3pi/4) = (sin(x) - cos(x))/sqrt(2) - * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) - */ - s = sin(x); - if (y1) - s = -s; - c = cos(x); - cc = s-c; - if (ix < 0x7fe00000) { - /* avoid overflow in 2*x */ - ss = -s-c; - z = cos(2*x); - if (s*c > 0) - cc = z/ss; - else - ss = z/cc; - if (ix < 0x48000000) { - if (y1) - ss = -ss; - cc = pone(x)*cc-qone(x)*ss; - } - } - if (sign) - cc = -cc; - return invsqrtpi*cc/sqrt(x); -} - -/* R0/S0 on [0,2] */ -static const double -r00 = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */ -r01 = 1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */ -r02 = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */ -r03 = 4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */ -s01 = 1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */ -s02 = 1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */ -s03 = 1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */ -s04 = 5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */ -s05 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */ - -double j1(double x) -{ - double z,r,s; - uint32_t ix; - int sign; - - GET_HIGH_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix >= 0x7ff00000) - return 1/(x*x); - if (ix >= 0x40000000) /* |x| >= 2 */ - return common(ix, fabs(x), 0, sign); - if (ix >= 0x38000000) { /* |x| >= 2**-127 */ - z = x*x; - r = z*(r00+z*(r01+z*(r02+z*r03))); - s = 1+z*(s01+z*(s02+z*(s03+z*(s04+z*s05)))); - z = r/s; - } else - /* avoid underflow, raise inexact if x!=0 */ - z = x; - return (0.5 + z)*x; -} - -static const double U0[5] = { - -1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */ - 5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */ - -1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */ - 2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */ - -9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */ -}; -static const double V0[5] = { - 1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */ - 2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */ - 1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */ - 6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */ - 1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */ -}; - -double y1(double x) -{ - double z,u,v; - uint32_t ix,lx; - - EXTRACT_WORDS(ix, lx, x); - /* y1(nan)=nan, y1(<0)=nan, y1(0)=-inf, y1(inf)=0 */ - if ((ix<<1 | lx) == 0) - return -1/0.0; - if (ix>>31) - return 0/0.0; - if (ix >= 0x7ff00000) - return 1/x; - - if (ix >= 0x40000000) /* x >= 2 */ - return common(ix, x, 1, 0); - if (ix < 0x3c900000) /* x < 2**-54 */ - return -tpi/x; - z = x*x; - u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4]))); - v = 1+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4])))); - return x*(u/v) + tpi*(j1(x)*log(x)-1/x); -} - -/* For x >= 8, the asymptotic expansions of pone is - * 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x. - * We approximate pone by - * pone(x) = 1 + (R/S) - * where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10 - * S = 1 + ps0*s^2 + ... + ps4*s^10 - * and - * | pone(x)-1-R/S | <= 2 ** ( -60.06) - */ - -static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ - 1.17187499999988647970e-01, /* 0x3FBDFFFF, 0xFFFFFCCE */ - 1.32394806593073575129e+01, /* 0x402A7A9D, 0x357F7FCE */ - 4.12051854307378562225e+02, /* 0x4079C0D4, 0x652EA590 */ - 3.87474538913960532227e+03, /* 0x40AE457D, 0xA3A532CC */ - 7.91447954031891731574e+03, /* 0x40BEEA7A, 0xC32782DD */ -}; -static const double ps8[5] = { - 1.14207370375678408436e+02, /* 0x405C8D45, 0x8E656CAC */ - 3.65093083420853463394e+03, /* 0x40AC85DC, 0x964D274F */ - 3.69562060269033463555e+04, /* 0x40E20B86, 0x97C5BB7F */ - 9.76027935934950801311e+04, /* 0x40F7D42C, 0xB28F17BB */ - 3.08042720627888811578e+04, /* 0x40DE1511, 0x697A0B2D */ -}; - -static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - 1.31990519556243522749e-11, /* 0x3DAD0667, 0xDAE1CA7D */ - 1.17187493190614097638e-01, /* 0x3FBDFFFF, 0xE2C10043 */ - 6.80275127868432871736e+00, /* 0x401B3604, 0x6E6315E3 */ - 1.08308182990189109773e+02, /* 0x405B13B9, 0x452602ED */ - 5.17636139533199752805e+02, /* 0x40802D16, 0xD052D649 */ - 5.28715201363337541807e+02, /* 0x408085B8, 0xBB7E0CB7 */ -}; -static const double ps5[5] = { - 5.92805987221131331921e+01, /* 0x404DA3EA, 0xA8AF633D */ - 9.91401418733614377743e+02, /* 0x408EFB36, 0x1B066701 */ - 5.35326695291487976647e+03, /* 0x40B4E944, 0x5706B6FB */ - 7.84469031749551231769e+03, /* 0x40BEA4B0, 0xB8A5BB15 */ - 1.50404688810361062679e+03, /* 0x40978030, 0x036F5E51 */ -}; - -static const double pr3[6] = { - 3.02503916137373618024e-09, /* 0x3E29FC21, 0xA7AD9EDD */ - 1.17186865567253592491e-01, /* 0x3FBDFFF5, 0x5B21D17B */ - 3.93297750033315640650e+00, /* 0x400F76BC, 0xE85EAD8A */ - 3.51194035591636932736e+01, /* 0x40418F48, 0x9DA6D129 */ - 9.10550110750781271918e+01, /* 0x4056C385, 0x4D2C1837 */ - 4.85590685197364919645e+01, /* 0x4048478F, 0x8EA83EE5 */ -}; -static const double ps3[5] = { - 3.47913095001251519989e+01, /* 0x40416549, 0xA134069C */ - 3.36762458747825746741e+02, /* 0x40750C33, 0x07F1A75F */ - 1.04687139975775130551e+03, /* 0x40905B7C, 0x5037D523 */ - 8.90811346398256432622e+02, /* 0x408BD67D, 0xA32E31E9 */ - 1.03787932439639277504e+02, /* 0x4059F26D, 0x7C2EED53 */ -}; - -static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - 1.07710830106873743082e-07, /* 0x3E7CE9D4, 0xF65544F4 */ - 1.17176219462683348094e-01, /* 0x3FBDFF42, 0xBE760D83 */ - 2.36851496667608785174e+00, /* 0x4002F2B7, 0xF98FAEC0 */ - 1.22426109148261232917e+01, /* 0x40287C37, 0x7F71A964 */ - 1.76939711271687727390e+01, /* 0x4031B1A8, 0x177F8EE2 */ - 5.07352312588818499250e+00, /* 0x40144B49, 0xA574C1FE */ -}; -static const double ps2[5] = { - 2.14364859363821409488e+01, /* 0x40356FBD, 0x8AD5ECDC */ - 1.25290227168402751090e+02, /* 0x405F5293, 0x14F92CD5 */ - 2.32276469057162813669e+02, /* 0x406D08D8, 0xD5A2DBD9 */ - 1.17679373287147100768e+02, /* 0x405D6B7A, 0xDA1884A9 */ - 8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */ -}; - -static double pone(double x) -{ - const double *p,*q; - double_t z,r,s; - uint32_t ix; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x40200000){p = pr8; q = ps8;} - else if (ix >= 0x40122E8B){p = pr5; q = ps5;} - else if (ix >= 0x4006DB6D){p = pr3; q = ps3;} - else /*ix >= 0x40000000*/ {p = pr2; q = ps2;} - z = 1.0/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); - return 1.0+ r/s; -} - -/* For x >= 8, the asymptotic expansions of qone is - * 3/8 s - 105/1024 s^3 - ..., where s = 1/x. - * We approximate pone by - * qone(x) = s*(0.375 + (R/S)) - * where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10 - * S = 1 + qs1*s^2 + ... + qs6*s^12 - * and - * | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13) - */ - -static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ - -1.02539062499992714161e-01, /* 0xBFBA3FFF, 0xFFFFFDF3 */ - -1.62717534544589987888e+01, /* 0xC0304591, 0xA26779F7 */ - -7.59601722513950107896e+02, /* 0xC087BCD0, 0x53E4B576 */ - -1.18498066702429587167e+04, /* 0xC0C724E7, 0x40F87415 */ - -4.84385124285750353010e+04, /* 0xC0E7A6D0, 0x65D09C6A */ -}; -static const double qs8[6] = { - 1.61395369700722909556e+02, /* 0x40642CA6, 0xDE5BCDE5 */ - 7.82538599923348465381e+03, /* 0x40BE9162, 0xD0D88419 */ - 1.33875336287249578163e+05, /* 0x4100579A, 0xB0B75E98 */ - 7.19657723683240939863e+05, /* 0x4125F653, 0x72869C19 */ - 6.66601232617776375264e+05, /* 0x412457D2, 0x7719AD5C */ - -2.94490264303834643215e+05, /* 0xC111F969, 0x0EA5AA18 */ -}; - -static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - -2.08979931141764104297e-11, /* 0xBDB6FA43, 0x1AA1A098 */ - -1.02539050241375426231e-01, /* 0xBFBA3FFF, 0xCB597FEF */ - -8.05644828123936029840e+00, /* 0xC0201CE6, 0xCA03AD4B */ - -1.83669607474888380239e+02, /* 0xC066F56D, 0x6CA7B9B0 */ - -1.37319376065508163265e+03, /* 0xC09574C6, 0x6931734F */ - -2.61244440453215656817e+03, /* 0xC0A468E3, 0x88FDA79D */ -}; -static const double qs5[6] = { - 8.12765501384335777857e+01, /* 0x405451B2, 0xFF5A11B2 */ - 1.99179873460485964642e+03, /* 0x409F1F31, 0xE77BF839 */ - 1.74684851924908907677e+04, /* 0x40D10F1F, 0x0D64CE29 */ - 4.98514270910352279316e+04, /* 0x40E8576D, 0xAABAD197 */ - 2.79480751638918118260e+04, /* 0x40DB4B04, 0xCF7C364B */ - -4.71918354795128470869e+03, /* 0xC0B26F2E, 0xFCFFA004 */ -}; - -static const double qr3[6] = { - -5.07831226461766561369e-09, /* 0xBE35CFA9, 0xD38FC84F */ - -1.02537829820837089745e-01, /* 0xBFBA3FEB, 0x51AEED54 */ - -4.61011581139473403113e+00, /* 0xC01270C2, 0x3302D9FF */ - -5.78472216562783643212e+01, /* 0xC04CEC71, 0xC25D16DA */ - -2.28244540737631695038e+02, /* 0xC06C87D3, 0x4718D55F */ - -2.19210128478909325622e+02, /* 0xC06B66B9, 0x5F5C1BF6 */ -}; -static const double qs3[6] = { - 4.76651550323729509273e+01, /* 0x4047D523, 0xCCD367E4 */ - 6.73865112676699709482e+02, /* 0x40850EEB, 0xC031EE3E */ - 3.38015286679526343505e+03, /* 0x40AA684E, 0x448E7C9A */ - 5.54772909720722782367e+03, /* 0x40B5ABBA, 0xA61D54A6 */ - 1.90311919338810798763e+03, /* 0x409DBC7A, 0x0DD4DF4B */ - -1.35201191444307340817e+02, /* 0xC060E670, 0x290A311F */ -}; - -static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - -1.78381727510958865572e-07, /* 0xBE87F126, 0x44C626D2 */ - -1.02517042607985553460e-01, /* 0xBFBA3E8E, 0x9148B010 */ - -2.75220568278187460720e+00, /* 0xC0060484, 0x69BB4EDA */ - -1.96636162643703720221e+01, /* 0xC033A9E2, 0xC168907F */ - -4.23253133372830490089e+01, /* 0xC04529A3, 0xDE104AAA */ - -2.13719211703704061733e+01, /* 0xC0355F36, 0x39CF6E52 */ -}; -static const double qs2[6] = { - 2.95333629060523854548e+01, /* 0x403D888A, 0x78AE64FF */ - 2.52981549982190529136e+02, /* 0x406F9F68, 0xDB821CBA */ - 7.57502834868645436472e+02, /* 0x4087AC05, 0xCE49A0F7 */ - 7.39393205320467245656e+02, /* 0x40871B25, 0x48D4C029 */ - 1.55949003336666123687e+02, /* 0x40637E5E, 0x3C3ED8D4 */ - -4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */ -}; - -static double qone(double x) -{ - const double *p,*q; - double_t s,r,z; - uint32_t ix; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x40200000){p = qr8; q = qs8;} - else if (ix >= 0x40122E8B){p = qr5; q = qs5;} - else if (ix >= 0x4006DB6D){p = qr3; q = qs3;} - else /*ix >= 0x40000000*/ {p = qr2; q = qs2;} - z = 1.0/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); - return (.375 + r/s)/x; -} diff --git a/usr/lib/libc/math/j1f.c b/usr/lib/libc/math/j1f.c deleted file mode 100644 index 3434c53dc..000000000 --- a/usr/lib/libc/math/j1f.c +++ /dev/null @@ -1,310 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_j1f.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#define _GNU_SOURCE -#include "libm.h" - -static float ponef(float), qonef(float); - -static const float -invsqrtpi = 5.6418961287e-01, /* 0x3f106ebb */ -tpi = 6.3661974669e-01; /* 0x3f22f983 */ - -static float common(uint32_t ix, float x, int y1, int sign) -{ - double z,s,c,ss,cc; - - s = sinf(x); - if (y1) - s = -s; - c = cosf(x); - cc = s-c; - if (ix < 0x7f000000) { - ss = -s-c; - z = cosf(2*x); - if (s*c > 0) - cc = z/ss; - else - ss = z/cc; - if (ix < 0x58800000) { - if (y1) - ss = -ss; - cc = ponef(x)*cc-qonef(x)*ss; - } - } - if (sign) - cc = -cc; - return invsqrtpi*cc/sqrtf(x); -} - -/* R0/S0 on [0,2] */ -static const float -r00 = -6.2500000000e-02, /* 0xbd800000 */ -r01 = 1.4070566976e-03, /* 0x3ab86cfd */ -r02 = -1.5995563444e-05, /* 0xb7862e36 */ -r03 = 4.9672799207e-08, /* 0x335557d2 */ -s01 = 1.9153760746e-02, /* 0x3c9ce859 */ -s02 = 1.8594678841e-04, /* 0x3942fab6 */ -s03 = 1.1771846857e-06, /* 0x359dffc2 */ -s04 = 5.0463624390e-09, /* 0x31ad6446 */ -s05 = 1.2354227016e-11; /* 0x2d59567e */ - -float j1f(float x) -{ - float z,r,s; - uint32_t ix; - int sign; - - GET_FLOAT_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix >= 0x7f800000) - return 1/(x*x); - if (ix >= 0x40000000) /* |x| >= 2 */ - return common(ix, fabsf(x), 0, sign); - if (ix >= 0x39000000) { /* |x| >= 2**-13 */ - z = x*x; - r = z*(r00+z*(r01+z*(r02+z*r03))); - s = 1+z*(s01+z*(s02+z*(s03+z*(s04+z*s05)))); - z = 0.5f + r/s; - } else - z = 0.5f; - return z*x; -} - -static const float U0[5] = { - -1.9605709612e-01, /* 0xbe48c331 */ - 5.0443872809e-02, /* 0x3d4e9e3c */ - -1.9125689287e-03, /* 0xbafaaf2a */ - 2.3525259166e-05, /* 0x37c5581c */ - -9.1909917899e-08, /* 0xb3c56003 */ -}; -static const float V0[5] = { - 1.9916731864e-02, /* 0x3ca3286a */ - 2.0255257550e-04, /* 0x3954644b */ - 1.3560879779e-06, /* 0x35b602d4 */ - 6.2274145840e-09, /* 0x31d5f8eb */ - 1.6655924903e-11, /* 0x2d9281cf */ -}; - -float y1f(float x) -{ - float z,u,v; - uint32_t ix; - - GET_FLOAT_WORD(ix, x); - if ((ix & 0x7fffffff) == 0) - return -1/0.0f; - if (ix>>31) - return 0/0.0f; - if (ix >= 0x7f800000) - return 1/x; - if (ix >= 0x40000000) /* |x| >= 2.0 */ - return common(ix,x,1,0); - if (ix < 0x33000000) /* x < 2**-25 */ - return -tpi/x; - z = x*x; - u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4]))); - v = 1.0f+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4])))); - return x*(u/v) + tpi*(j1f(x)*logf(x)-1.0f/x); -} - -/* For x >= 8, the asymptotic expansions of pone is - * 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x. - * We approximate pone by - * pone(x) = 1 + (R/S) - * where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10 - * S = 1 + ps0*s^2 + ... + ps4*s^10 - * and - * | pone(x)-1-R/S | <= 2 ** ( -60.06) - */ - -static const float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.0000000000e+00, /* 0x00000000 */ - 1.1718750000e-01, /* 0x3df00000 */ - 1.3239480972e+01, /* 0x4153d4ea */ - 4.1205184937e+02, /* 0x43ce06a3 */ - 3.8747453613e+03, /* 0x45722bed */ - 7.9144794922e+03, /* 0x45f753d6 */ -}; -static const float ps8[5] = { - 1.1420736694e+02, /* 0x42e46a2c */ - 3.6509309082e+03, /* 0x45642ee5 */ - 3.6956207031e+04, /* 0x47105c35 */ - 9.7602796875e+04, /* 0x47bea166 */ - 3.0804271484e+04, /* 0x46f0a88b */ -}; - -static const float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - 1.3199052094e-11, /* 0x2d68333f */ - 1.1718749255e-01, /* 0x3defffff */ - 6.8027510643e+00, /* 0x40d9b023 */ - 1.0830818176e+02, /* 0x42d89dca */ - 5.1763616943e+02, /* 0x440168b7 */ - 5.2871520996e+02, /* 0x44042dc6 */ -}; -static const float ps5[5] = { - 5.9280597687e+01, /* 0x426d1f55 */ - 9.9140142822e+02, /* 0x4477d9b1 */ - 5.3532670898e+03, /* 0x45a74a23 */ - 7.8446904297e+03, /* 0x45f52586 */ - 1.5040468750e+03, /* 0x44bc0180 */ -}; - -static const float pr3[6] = { - 3.0250391081e-09, /* 0x314fe10d */ - 1.1718686670e-01, /* 0x3defffab */ - 3.9329774380e+00, /* 0x407bb5e7 */ - 3.5119403839e+01, /* 0x420c7a45 */ - 9.1055007935e+01, /* 0x42b61c2a */ - 4.8559066772e+01, /* 0x42423c7c */ -}; -static const float ps3[5] = { - 3.4791309357e+01, /* 0x420b2a4d */ - 3.3676245117e+02, /* 0x43a86198 */ - 1.0468714600e+03, /* 0x4482dbe3 */ - 8.9081134033e+02, /* 0x445eb3ed */ - 1.0378793335e+02, /* 0x42cf936c */ -}; - -static const float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - 1.0771083225e-07, /* 0x33e74ea8 */ - 1.1717621982e-01, /* 0x3deffa16 */ - 2.3685150146e+00, /* 0x401795c0 */ - 1.2242610931e+01, /* 0x4143e1bc */ - 1.7693971634e+01, /* 0x418d8d41 */ - 5.0735230446e+00, /* 0x40a25a4d */ -}; -static const float ps2[5] = { - 2.1436485291e+01, /* 0x41ab7dec */ - 1.2529022980e+02, /* 0x42fa9499 */ - 2.3227647400e+02, /* 0x436846c7 */ - 1.1767937469e+02, /* 0x42eb5bd7 */ - 8.3646392822e+00, /* 0x4105d590 */ -}; - -static float ponef(float x) -{ - const float *p,*q; - float_t z,r,s; - uint32_t ix; - - GET_FLOAT_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x41000000){p = pr8; q = ps8;} - else if (ix >= 0x409173eb){p = pr5; q = ps5;} - else if (ix >= 0x4036d917){p = pr3; q = ps3;} - else /*ix >= 0x40000000*/ {p = pr2; q = ps2;} - z = 1.0f/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); - return 1.0f + r/s; -} - -/* For x >= 8, the asymptotic expansions of qone is - * 3/8 s - 105/1024 s^3 - ..., where s = 1/x. - * We approximate pone by - * qone(x) = s*(0.375 + (R/S)) - * where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10 - * S = 1 + qs1*s^2 + ... + qs6*s^12 - * and - * | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13) - */ - -static const float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ - 0.0000000000e+00, /* 0x00000000 */ - -1.0253906250e-01, /* 0xbdd20000 */ - -1.6271753311e+01, /* 0xc1822c8d */ - -7.5960174561e+02, /* 0xc43de683 */ - -1.1849806641e+04, /* 0xc639273a */ - -4.8438511719e+04, /* 0xc73d3683 */ -}; -static const float qs8[6] = { - 1.6139537048e+02, /* 0x43216537 */ - 7.8253862305e+03, /* 0x45f48b17 */ - 1.3387534375e+05, /* 0x4802bcd6 */ - 7.1965775000e+05, /* 0x492fb29c */ - 6.6660125000e+05, /* 0x4922be94 */ - -2.9449025000e+05, /* 0xc88fcb48 */ -}; - -static const float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ - -2.0897993405e-11, /* 0xadb7d219 */ - -1.0253904760e-01, /* 0xbdd1fffe */ - -8.0564479828e+00, /* 0xc100e736 */ - -1.8366960144e+02, /* 0xc337ab6b */ - -1.3731937256e+03, /* 0xc4aba633 */ - -2.6124443359e+03, /* 0xc523471c */ -}; -static const float qs5[6] = { - 8.1276550293e+01, /* 0x42a28d98 */ - 1.9917987061e+03, /* 0x44f8f98f */ - 1.7468484375e+04, /* 0x468878f8 */ - 4.9851425781e+04, /* 0x4742bb6d */ - 2.7948074219e+04, /* 0x46da5826 */ - -4.7191835938e+03, /* 0xc5937978 */ -}; - -static const float qr3[6] = { - -5.0783124372e-09, /* 0xb1ae7d4f */ - -1.0253783315e-01, /* 0xbdd1ff5b */ - -4.6101160049e+00, /* 0xc0938612 */ - -5.7847221375e+01, /* 0xc267638e */ - -2.2824453735e+02, /* 0xc3643e9a */ - -2.1921012878e+02, /* 0xc35b35cb */ -}; -static const float qs3[6] = { - 4.7665153503e+01, /* 0x423ea91e */ - 6.7386511230e+02, /* 0x4428775e */ - 3.3801528320e+03, /* 0x45534272 */ - 5.5477290039e+03, /* 0x45ad5dd5 */ - 1.9031191406e+03, /* 0x44ede3d0 */ - -1.3520118713e+02, /* 0xc3073381 */ -}; - -static const float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ - -1.7838172539e-07, /* 0xb43f8932 */ - -1.0251704603e-01, /* 0xbdd1f475 */ - -2.7522056103e+00, /* 0xc0302423 */ - -1.9663616180e+01, /* 0xc19d4f16 */ - -4.2325313568e+01, /* 0xc2294d1f */ - -2.1371921539e+01, /* 0xc1aaf9b2 */ -}; -static const float qs2[6] = { - 2.9533363342e+01, /* 0x41ec4454 */ - 2.5298155212e+02, /* 0x437cfb47 */ - 7.5750280762e+02, /* 0x443d602e */ - 7.3939318848e+02, /* 0x4438d92a */ - 1.5594900513e+02, /* 0x431bf2f2 */ - -4.9594988823e+00, /* 0xc09eb437 */ -}; - -static float qonef(float x) -{ - const float *p,*q; - float_t s,r,z; - uint32_t ix; - - GET_FLOAT_WORD(ix, x); - ix &= 0x7fffffff; - if (ix >= 0x41000000){p = qr8; q = qs8;} - else if (ix >= 0x409173eb){p = qr5; q = qs5;} - else if (ix >= 0x4036d917){p = qr3; q = qs3;} - else /*ix >= 0x40000000*/ {p = qr2; q = qs2;} - z = 1.0f/(x*x); - r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); - s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); - return (.375f + r/s)/x; -} diff --git a/usr/lib/libc/math/jn.c b/usr/lib/libc/math/jn.c deleted file mode 100644 index 4878a54fe..000000000 --- a/usr/lib/libc/math/jn.c +++ /dev/null @@ -1,280 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_jn.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * jn(n, x), yn(n, x) - * floating point Bessel's function of the 1st and 2nd kind - * of order n - * - * Special cases: - * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; - * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. - * Note 2. About jn(n,x), yn(n,x) - * For n=0, j0(x) is called, - * for n=1, j1(x) is called, - * for n<=x, forward recursion is used starting - * from values of j0(x) and j1(x). - * for n>x, a continued fraction approximation to - * j(n,x)/j(n-1,x) is evaluated and then backward - * recursion is used starting from a supposed value - * for j(n,x). The resulting value of j(0,x) is - * compared with the actual value to correct the - * supposed value of j(n,x). - * - * yn(n,x) is similar in all respects, except - * that forward recursion is used for all - * values of n>1. - */ - -#include "libm.h" - -static const double invsqrtpi = 5.64189583547756279280e-01; /* 0x3FE20DD7, 0x50429B6D */ - -double jn(int n, double x) -{ - uint32_t ix, lx; - int nm1, i, sign; - double a, b, temp; - - EXTRACT_WORDS(ix, lx, x); - sign = ix>>31; - ix &= 0x7fffffff; - - if ((ix | (lx|-lx)>>31) > 0x7ff00000) /* nan */ - return x; - - /* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x) - * Thus, J(-n,x) = J(n,-x) - */ - /* nm1 = |n|-1 is used instead of |n| to handle n==INT_MIN */ - if (n == 0) - return j0(x); - if (n < 0) { - nm1 = -(n+1); - x = -x; - sign ^= 1; - } else - nm1 = n-1; - if (nm1 == 0) - return j1(x); - - sign &= n; /* even n: 0, odd n: signbit(x) */ - x = fabs(x); - if ((ix|lx) == 0 || ix == 0x7ff00000) /* if x is 0 or inf */ - b = 0.0; - else if (nm1 < x) { - /* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ - if (ix >= 0x52d00000) { /* x > 2**302 */ - /* (x >> n**2) - * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) - * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) - * Let s=sin(x), c=cos(x), - * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then - * - * n sin(xn)*sqt2 cos(xn)*sqt2 - * ---------------------------------- - * 0 s-c c+s - * 1 -s-c -c+s - * 2 -s+c -c-s - * 3 s+c c-s - */ - switch(nm1&3) { - case 0: temp = -cos(x)+sin(x); break; - case 1: temp = -cos(x)-sin(x); break; - case 2: temp = cos(x)-sin(x); break; - default: - case 3: temp = cos(x)+sin(x); break; - } - b = invsqrtpi*temp/sqrt(x); - } else { - a = j0(x); - b = j1(x); - for (i=0; i 32) /* underflow */ - b = 0.0; - else { - temp = x*0.5; - b = temp; - a = 1.0; - for (i=2; i<=nm1+1; i++) { - a *= (double)i; /* a = n! */ - b *= temp; /* b = (x/2)^n */ - } - b = b/a; - } - } else { - /* use backward recurrence */ - /* x x^2 x^2 - * J(n,x)/J(n-1,x) = ---- ------ ------ ..... - * 2n - 2(n+1) - 2(n+2) - * - * 1 1 1 - * (for large x) = ---- ------ ------ ..... - * 2n 2(n+1) 2(n+2) - * -- - ------ - ------ - - * x x x - * - * Let w = 2n/x and h=2/x, then the above quotient - * is equal to the continued fraction: - * 1 - * = ----------------------- - * 1 - * w - ----------------- - * 1 - * w+h - --------- - * w+2h - ... - * - * To determine how many terms needed, let - * Q(0) = w, Q(1) = w(w+h) - 1, - * Q(k) = (w+k*h)*Q(k-1) - Q(k-2), - * When Q(k) > 1e4 good for single - * When Q(k) > 1e9 good for double - * When Q(k) > 1e17 good for quadruple - */ - /* determine k */ - double t,q0,q1,w,h,z,tmp,nf; - int k; - - nf = nm1 + 1.0; - w = 2*nf/x; - h = 2/x; - z = w+h; - q0 = w; - q1 = w*z - 1.0; - k = 1; - while (q1 < 1.0e9) { - k += 1; - z += h; - tmp = z*q1 - q0; - q0 = q1; - q1 = tmp; - } - for (t=0.0, i=k; i>=0; i--) - t = 1/(2*(i+nf)/x - t); - a = t; - b = 1.0; - /* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n) - * Hence, if n*(log(2n/x)) > ... - * single 8.8722839355e+01 - * double 7.09782712893383973096e+02 - * long double 1.1356523406294143949491931077970765006170e+04 - * then recurrent value may overflow and the result is - * likely underflow to zero - */ - tmp = nf*log(fabs(w)); - if (tmp < 7.09782712893383973096e+02) { - for (i=nm1; i>0; i--) { - temp = b; - b = b*(2.0*i)/x - a; - a = temp; - } - } else { - for (i=nm1; i>0; i--) { - temp = b; - b = b*(2.0*i)/x - a; - a = temp; - /* scale b to avoid spurious overflow */ - if (b > 0x1p500) { - a /= b; - t /= b; - b = 1.0; - } - } - } - z = j0(x); - w = j1(x); - if (fabs(z) >= fabs(w)) - b = t*z/b; - else - b = t*w/a; - } - } - return sign ? -b : b; -} - - -double yn(int n, double x) -{ - uint32_t ix, lx, ib; - int nm1, sign, i; - double a, b, temp; - - EXTRACT_WORDS(ix, lx, x); - sign = ix>>31; - ix &= 0x7fffffff; - - if ((ix | (lx|-lx)>>31) > 0x7ff00000) /* nan */ - return x; - if (sign && (ix|lx)!=0) /* x < 0 */ - return 0/0.0; - if (ix == 0x7ff00000) - return 0.0; - - if (n == 0) - return y0(x); - if (n < 0) { - nm1 = -(n+1); - sign = n&1; - } else { - nm1 = n-1; - sign = 0; - } - if (nm1 == 0) - return sign ? -y1(x) : y1(x); - - if (ix >= 0x52d00000) { /* x > 2**302 */ - /* (x >> n**2) - * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) - * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) - * Let s=sin(x), c=cos(x), - * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then - * - * n sin(xn)*sqt2 cos(xn)*sqt2 - * ---------------------------------- - * 0 s-c c+s - * 1 -s-c -c+s - * 2 -s+c -c-s - * 3 s+c c-s - */ - switch(nm1&3) { - case 0: temp = -sin(x)-cos(x); break; - case 1: temp = -sin(x)+cos(x); break; - case 2: temp = sin(x)+cos(x); break; - default: - case 3: temp = sin(x)-cos(x); break; - } - b = invsqrtpi*temp/sqrt(x); - } else { - a = y0(x); - b = y1(x); - /* quit if b is -inf */ - GET_HIGH_WORD(ib, b); - for (i=0; i>31; - ix &= 0x7fffffff; - if (ix > 0x7f800000) /* nan */ - return x; - - /* J(-n,x) = J(n,-x), use |n|-1 to avoid overflow in -n */ - if (n == 0) - return j0f(x); - if (n < 0) { - nm1 = -(n+1); - x = -x; - sign ^= 1; - } else - nm1 = n-1; - if (nm1 == 0) - return j1f(x); - - sign &= n; /* even n: 0, odd n: signbit(x) */ - x = fabsf(x); - if (ix == 0 || ix == 0x7f800000) /* if x is 0 or inf */ - b = 0.0f; - else if (nm1 < x) { - /* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ - a = j0f(x); - b = j1f(x); - for (i=0; i 8) /* underflow */ - nm1 = 8; - temp = 0.5f * x; - b = temp; - a = 1.0f; - for (i=2; i<=nm1+1; i++) { - a *= (float)i; /* a = n! */ - b *= temp; /* b = (x/2)^n */ - } - b = b/a; - } else { - /* use backward recurrence */ - /* x x^2 x^2 - * J(n,x)/J(n-1,x) = ---- ------ ------ ..... - * 2n - 2(n+1) - 2(n+2) - * - * 1 1 1 - * (for large x) = ---- ------ ------ ..... - * 2n 2(n+1) 2(n+2) - * -- - ------ - ------ - - * x x x - * - * Let w = 2n/x and h=2/x, then the above quotient - * is equal to the continued fraction: - * 1 - * = ----------------------- - * 1 - * w - ----------------- - * 1 - * w+h - --------- - * w+2h - ... - * - * To determine how many terms needed, let - * Q(0) = w, Q(1) = w(w+h) - 1, - * Q(k) = (w+k*h)*Q(k-1) - Q(k-2), - * When Q(k) > 1e4 good for single - * When Q(k) > 1e9 good for double - * When Q(k) > 1e17 good for quadruple - */ - /* determine k */ - float t,q0,q1,w,h,z,tmp,nf; - int k; - - nf = nm1+1.0f; - w = 2*nf/x; - h = 2/x; - z = w+h; - q0 = w; - q1 = w*z - 1.0f; - k = 1; - while (q1 < 1.0e4f) { - k += 1; - z += h; - tmp = z*q1 - q0; - q0 = q1; - q1 = tmp; - } - for (t=0.0f, i=k; i>=0; i--) - t = 1.0f/(2*(i+nf)/x-t); - a = t; - b = 1.0f; - /* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n) - * Hence, if n*(log(2n/x)) > ... - * single 8.8722839355e+01 - * double 7.09782712893383973096e+02 - * long double 1.1356523406294143949491931077970765006170e+04 - * then recurrent value may overflow and the result is - * likely underflow to zero - */ - tmp = nf*logf(fabsf(w)); - if (tmp < 88.721679688f) { - for (i=nm1; i>0; i--) { - temp = b; - b = 2.0f*i*b/x - a; - a = temp; - } - } else { - for (i=nm1; i>0; i--){ - temp = b; - b = 2.0f*i*b/x - a; - a = temp; - /* scale b to avoid spurious overflow */ - if (b > 0x1p60f) { - a /= b; - t /= b; - b = 1.0f; - } - } - } - z = j0f(x); - w = j1f(x); - if (fabsf(z) >= fabsf(w)) - b = t*z/b; - else - b = t*w/a; - } - } - return sign ? -b : b; -} - -float ynf(int n, float x) -{ - uint32_t ix, ib; - int nm1, sign, i; - float a, b, temp; - - GET_FLOAT_WORD(ix, x); - sign = ix>>31; - ix &= 0x7fffffff; - if (ix > 0x7f800000) /* nan */ - return x; - if (sign && ix != 0) /* x < 0 */ - return 0/0.0f; - if (ix == 0x7f800000) - return 0.0f; - - if (n == 0) - return y0f(x); - if (n < 0) { - nm1 = -(n+1); - sign = n&1; - } else { - nm1 = n-1; - sign = 0; - } - if (nm1 == 0) - return sign ? -y1f(x) : y1f(x); - - a = y0f(x); - b = y1f(x); - /* quit if b is -inf */ - GET_FLOAT_WORD(ib,b); - for (i = 0; i < nm1 && ib != 0xff800000; ) { - i++; - temp = b; - b = (2.0f*i/x)*b - a; - GET_FLOAT_WORD(ib, b); - a = temp; - } - return sign ? -b : b; -} diff --git a/usr/lib/libc/math/ldexp.c b/usr/lib/libc/math/ldexp.c deleted file mode 100644 index f4d1cd6af..000000000 --- a/usr/lib/libc/math/ldexp.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double ldexp(double x, int n) -{ - return scalbn(x, n); -} diff --git a/usr/lib/libc/math/ldexpf.c b/usr/lib/libc/math/ldexpf.c deleted file mode 100644 index 3bad5f393..000000000 --- a/usr/lib/libc/math/ldexpf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -float ldexpf(float x, int n) -{ - return scalbnf(x, n); -} diff --git a/usr/lib/libc/math/ldexpl.c b/usr/lib/libc/math/ldexpl.c deleted file mode 100644 index fd145ccc5..000000000 --- a/usr/lib/libc/math/ldexpl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long double ldexpl(long double x, int n) -{ - return scalbnl(x, n); -} diff --git a/usr/lib/libc/math/lgamma.c b/usr/lib/libc/math/lgamma.c deleted file mode 100644 index e25ec8e60..000000000 --- a/usr/lib/libc/math/lgamma.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -extern int __signgam; -double __lgamma_r(double, int *); - -double lgamma(double x) -{ - return __lgamma_r(x, &__signgam); -} diff --git a/usr/lib/libc/math/lgamma_r.c b/usr/lib/libc/math/lgamma_r.c deleted file mode 100644 index fff565d22..000000000 --- a/usr/lib/libc/math/lgamma_r.c +++ /dev/null @@ -1,284 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_lgamma_r.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - */ -/* lgamma_r(x, signgamp) - * Reentrant version of the logarithm of the Gamma function - * with user provide pointer for the sign of Gamma(x). - * - * Method: - * 1. Argument Reduction for 0 < x <= 8 - * Since gamma(1+s)=s*gamma(s), for x in [0,8], we may - * reduce x to a number in [1.5,2.5] by - * lgamma(1+s) = log(s) + lgamma(s) - * for example, - * lgamma(7.3) = log(6.3) + lgamma(6.3) - * = log(6.3*5.3) + lgamma(5.3) - * = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3) - * 2. Polynomial approximation of lgamma around its - * minimun ymin=1.461632144968362245 to maintain monotonicity. - * On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use - * Let z = x-ymin; - * lgamma(x) = -1.214862905358496078218 + z^2*poly(z) - * where - * poly(z) is a 14 degree polynomial. - * 2. Rational approximation in the primary interval [2,3] - * We use the following approximation: - * s = x-2.0; - * lgamma(x) = 0.5*s + s*P(s)/Q(s) - * with accuracy - * |P/Q - (lgamma(x)-0.5s)| < 2**-61.71 - * Our algorithms are based on the following observation - * - * zeta(2)-1 2 zeta(3)-1 3 - * lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ... - * 2 3 - * - * where Euler = 0.5771... is the Euler constant, which is very - * close to 0.5. - * - * 3. For x>=8, we have - * lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+.... - * (better formula: - * lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...) - * Let z = 1/x, then we approximation - * f(z) = lgamma(x) - (x-0.5)(log(x)-1) - * by - * 3 5 11 - * w = w0 + w1*z + w2*z + w3*z + ... + w6*z - * where - * |w - f(z)| < 2**-58.74 - * - * 4. For negative x, since (G is gamma function) - * -x*G(-x)*G(x) = pi/sin(pi*x), - * we have - * G(x) = pi/(sin(pi*x)*(-x)*G(-x)) - * since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0 - * Hence, for x<0, signgam = sign(sin(pi*x)) and - * lgamma(x) = log(|Gamma(x)|) - * = log(pi/(|x*sin(pi*x)|)) - lgamma(-x); - * Note: one should avoid compute pi*(-x) directly in the - * computation of sin(pi*(-x)). - * - * 5. Special Cases - * lgamma(2+s) ~ s*(1-Euler) for tiny s - * lgamma(1) = lgamma(2) = 0 - * lgamma(x) ~ -log(|x|) for tiny x - * lgamma(0) = lgamma(neg.integer) = inf and raise divide-by-zero - * lgamma(inf) = inf - * lgamma(-inf) = inf (bug for bug compatible with C99!?) - * - */ - -#include "libm.h" -#include "libc.h" - -static const double -pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */ -a0 = 7.72156649015328655494e-02, /* 0x3FB3C467, 0xE37DB0C8 */ -a1 = 3.22467033424113591611e-01, /* 0x3FD4A34C, 0xC4A60FAD */ -a2 = 6.73523010531292681824e-02, /* 0x3FB13E00, 0x1A5562A7 */ -a3 = 2.05808084325167332806e-02, /* 0x3F951322, 0xAC92547B */ -a4 = 7.38555086081402883957e-03, /* 0x3F7E404F, 0xB68FEFE8 */ -a5 = 2.89051383673415629091e-03, /* 0x3F67ADD8, 0xCCB7926B */ -a6 = 1.19270763183362067845e-03, /* 0x3F538A94, 0x116F3F5D */ -a7 = 5.10069792153511336608e-04, /* 0x3F40B6C6, 0x89B99C00 */ -a8 = 2.20862790713908385557e-04, /* 0x3F2CF2EC, 0xED10E54D */ -a9 = 1.08011567247583939954e-04, /* 0x3F1C5088, 0x987DFB07 */ -a10 = 2.52144565451257326939e-05, /* 0x3EFA7074, 0x428CFA52 */ -a11 = 4.48640949618915160150e-05, /* 0x3F07858E, 0x90A45837 */ -tc = 1.46163214496836224576e+00, /* 0x3FF762D8, 0x6356BE3F */ -tf = -1.21486290535849611461e-01, /* 0xBFBF19B9, 0xBCC38A42 */ -/* tt = -(tail of tf) */ -tt = -3.63867699703950536541e-18, /* 0xBC50C7CA, 0xA48A971F */ -t0 = 4.83836122723810047042e-01, /* 0x3FDEF72B, 0xC8EE38A2 */ -t1 = -1.47587722994593911752e-01, /* 0xBFC2E427, 0x8DC6C509 */ -t2 = 6.46249402391333854778e-02, /* 0x3FB08B42, 0x94D5419B */ -t3 = -3.27885410759859649565e-02, /* 0xBFA0C9A8, 0xDF35B713 */ -t4 = 1.79706750811820387126e-02, /* 0x3F9266E7, 0x970AF9EC */ -t5 = -1.03142241298341437450e-02, /* 0xBF851F9F, 0xBA91EC6A */ -t6 = 6.10053870246291332635e-03, /* 0x3F78FCE0, 0xE370E344 */ -t7 = -3.68452016781138256760e-03, /* 0xBF6E2EFF, 0xB3E914D7 */ -t8 = 2.25964780900612472250e-03, /* 0x3F6282D3, 0x2E15C915 */ -t9 = -1.40346469989232843813e-03, /* 0xBF56FE8E, 0xBF2D1AF1 */ -t10 = 8.81081882437654011382e-04, /* 0x3F4CDF0C, 0xEF61A8E9 */ -t11 = -5.38595305356740546715e-04, /* 0xBF41A610, 0x9C73E0EC */ -t12 = 3.15632070903625950361e-04, /* 0x3F34AF6D, 0x6C0EBBF7 */ -t13 = -3.12754168375120860518e-04, /* 0xBF347F24, 0xECC38C38 */ -t14 = 3.35529192635519073543e-04, /* 0x3F35FD3E, 0xE8C2D3F4 */ -u0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */ -u1 = 6.32827064025093366517e-01, /* 0x3FE4401E, 0x8B005DFF */ -u2 = 1.45492250137234768737e+00, /* 0x3FF7475C, 0xD119BD6F */ -u3 = 9.77717527963372745603e-01, /* 0x3FEF4976, 0x44EA8450 */ -u4 = 2.28963728064692451092e-01, /* 0x3FCD4EAE, 0xF6010924 */ -u5 = 1.33810918536787660377e-02, /* 0x3F8B678B, 0xBF2BAB09 */ -v1 = 2.45597793713041134822e+00, /* 0x4003A5D7, 0xC2BD619C */ -v2 = 2.12848976379893395361e+00, /* 0x40010725, 0xA42B18F5 */ -v3 = 7.69285150456672783825e-01, /* 0x3FE89DFB, 0xE45050AF */ -v4 = 1.04222645593369134254e-01, /* 0x3FBAAE55, 0xD6537C88 */ -v5 = 3.21709242282423911810e-03, /* 0x3F6A5ABB, 0x57D0CF61 */ -s0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */ -s1 = 2.14982415960608852501e-01, /* 0x3FCB848B, 0x36E20878 */ -s2 = 3.25778796408930981787e-01, /* 0x3FD4D98F, 0x4F139F59 */ -s3 = 1.46350472652464452805e-01, /* 0x3FC2BB9C, 0xBEE5F2F7 */ -s4 = 2.66422703033638609560e-02, /* 0x3F9B481C, 0x7E939961 */ -s5 = 1.84028451407337715652e-03, /* 0x3F5E26B6, 0x7368F239 */ -s6 = 3.19475326584100867617e-05, /* 0x3F00BFEC, 0xDD17E945 */ -r1 = 1.39200533467621045958e+00, /* 0x3FF645A7, 0x62C4AB74 */ -r2 = 7.21935547567138069525e-01, /* 0x3FE71A18, 0x93D3DCDC */ -r3 = 1.71933865632803078993e-01, /* 0x3FC601ED, 0xCCFBDF27 */ -r4 = 1.86459191715652901344e-02, /* 0x3F9317EA, 0x742ED475 */ -r5 = 7.77942496381893596434e-04, /* 0x3F497DDA, 0xCA41A95B */ -r6 = 7.32668430744625636189e-06, /* 0x3EDEBAF7, 0xA5B38140 */ -w0 = 4.18938533204672725052e-01, /* 0x3FDACFE3, 0x90C97D69 */ -w1 = 8.33333333333329678849e-02, /* 0x3FB55555, 0x5555553B */ -w2 = -2.77777777728775536470e-03, /* 0xBF66C16C, 0x16B02E5C */ -w3 = 7.93650558643019558500e-04, /* 0x3F4A019F, 0x98CF38B6 */ -w4 = -5.95187557450339963135e-04, /* 0xBF4380CB, 0x8C0FE741 */ -w5 = 8.36339918996282139126e-04, /* 0x3F4B67BA, 0x4CDAD5D1 */ -w6 = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */ - -/* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */ -static double sin_pi(double x) -{ - int n; - - /* spurious inexact if odd int */ - x = 2.0*(x*0.5 - floor(x*0.5)); /* x mod 2.0 */ - - n = (int)(x*4.0); - n = (n+1)/2; - x -= n*0.5f; - x *= pi; - - switch (n) { - default: /* case 4: */ - case 0: return __sin(x, 0.0, 0); - case 1: return __cos(x, 0.0); - case 2: return __sin(-x, 0.0, 0); - case 3: return -__cos(x, 0.0); - } -} - -double __lgamma_r(double x, int *signgamp) -{ - union {double f; uint64_t i;} u = {x}; - double_t t,y,z,nadj,p,p1,p2,p3,q,r,w; - uint32_t ix; - int sign,i; - - /* purge off +-inf, NaN, +-0, tiny and negative arguments */ - *signgamp = 1; - sign = u.i>>63; - ix = u.i>>32 & 0x7fffffff; - if (ix >= 0x7ff00000) - return x*x; - if (ix < (0x3ff-70)<<20) { /* |x|<2**-70, return -log(|x|) */ - if(sign) { - x = -x; - *signgamp = -1; - } - return -log(x); - } - if (sign) { - x = -x; - t = sin_pi(x); - if (t == 0.0) /* -integer */ - return 1.0/(x-x); - if (t > 0.0) - *signgamp = -1; - else - t = -t; - nadj = log(pi/(t*x)); - } - - /* purge off 1 and 2 */ - if ((ix == 0x3ff00000 || ix == 0x40000000) && (uint32_t)u.i == 0) - r = 0; - /* for x < 2.0 */ - else if (ix < 0x40000000) { - if (ix <= 0x3feccccc) { /* lgamma(x) = lgamma(x+1)-log(x) */ - r = -log(x); - if (ix >= 0x3FE76944) { - y = 1.0 - x; - i = 0; - } else if (ix >= 0x3FCDA661) { - y = x - (tc-1.0); - i = 1; - } else { - y = x; - i = 2; - } - } else { - r = 0.0; - if (ix >= 0x3FFBB4C3) { /* [1.7316,2] */ - y = 2.0 - x; - i = 0; - } else if(ix >= 0x3FF3B4C4) { /* [1.23,1.73] */ - y = x - tc; - i = 1; - } else { - y = x - 1.0; - i = 2; - } - } - switch (i) { - case 0: - z = y*y; - p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10)))); - p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11))))); - p = y*p1+p2; - r += (p-0.5*y); - break; - case 1: - z = y*y; - w = z*y; - p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */ - p2 = t1+w*(t4+w*(t7+w*(t10+w*t13))); - p3 = t2+w*(t5+w*(t8+w*(t11+w*t14))); - p = z*p1-(tt-w*(p2+y*p3)); - r += tf + p; - break; - case 2: - p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5))))); - p2 = 1.0+y*(v1+y*(v2+y*(v3+y*(v4+y*v5)))); - r += -0.5*y + p1/p2; - } - } else if (ix < 0x40200000) { /* x < 8.0 */ - i = (int)x; - y = x - (double)i; - p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))); - q = 1.0+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6))))); - r = 0.5*y+p/q; - z = 1.0; /* lgamma(1+s) = log(s) + lgamma(s) */ - switch (i) { - case 7: z *= y + 6.0; /* FALLTHRU */ - case 6: z *= y + 5.0; /* FALLTHRU */ - case 5: z *= y + 4.0; /* FALLTHRU */ - case 4: z *= y + 3.0; /* FALLTHRU */ - case 3: z *= y + 2.0; /* FALLTHRU */ - r += log(z); - break; - } - } else if (ix < 0x43900000) { /* 8.0 <= x < 2**58 */ - t = log(x); - z = 1.0/x; - y = z*z; - w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6))))); - r = (x-0.5)*(t-1.0)+w; - } else /* 2**58 <= x <= inf */ - r = x*(log(x)-1.0); - if (sign) - r = nadj - r; - return r; -} - -weak_alias(__lgamma_r, lgamma_r); diff --git a/usr/lib/libc/math/lgammaf.c b/usr/lib/libc/math/lgammaf.c deleted file mode 100644 index badb6dfec..000000000 --- a/usr/lib/libc/math/lgammaf.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -extern int __signgam; -float __lgammaf_r(float, int *); - -float lgammaf(float x) -{ - return __lgammaf_r(x, &__signgam); -} diff --git a/usr/lib/libc/math/lgammaf_r.c b/usr/lib/libc/math/lgammaf_r.c deleted file mode 100644 index c5b43db55..000000000 --- a/usr/lib/libc/math/lgammaf_r.c +++ /dev/null @@ -1,219 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_lgammaf_r.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" -#include "libc.h" - -static const float -pi = 3.1415927410e+00, /* 0x40490fdb */ -a0 = 7.7215664089e-02, /* 0x3d9e233f */ -a1 = 3.2246702909e-01, /* 0x3ea51a66 */ -a2 = 6.7352302372e-02, /* 0x3d89f001 */ -a3 = 2.0580807701e-02, /* 0x3ca89915 */ -a4 = 7.3855509982e-03, /* 0x3bf2027e */ -a5 = 2.8905137442e-03, /* 0x3b3d6ec6 */ -a6 = 1.1927076848e-03, /* 0x3a9c54a1 */ -a7 = 5.1006977446e-04, /* 0x3a05b634 */ -a8 = 2.2086278477e-04, /* 0x39679767 */ -a9 = 1.0801156895e-04, /* 0x38e28445 */ -a10 = 2.5214456400e-05, /* 0x37d383a2 */ -a11 = 4.4864096708e-05, /* 0x383c2c75 */ -tc = 1.4616321325e+00, /* 0x3fbb16c3 */ -tf = -1.2148628384e-01, /* 0xbdf8cdcd */ -/* tt = -(tail of tf) */ -tt = 6.6971006518e-09, /* 0x31e61c52 */ -t0 = 4.8383611441e-01, /* 0x3ef7b95e */ -t1 = -1.4758771658e-01, /* 0xbe17213c */ -t2 = 6.4624942839e-02, /* 0x3d845a15 */ -t3 = -3.2788541168e-02, /* 0xbd064d47 */ -t4 = 1.7970675603e-02, /* 0x3c93373d */ -t5 = -1.0314224288e-02, /* 0xbc28fcfe */ -t6 = 6.1005386524e-03, /* 0x3bc7e707 */ -t7 = -3.6845202558e-03, /* 0xbb7177fe */ -t8 = 2.2596477065e-03, /* 0x3b141699 */ -t9 = -1.4034647029e-03, /* 0xbab7f476 */ -t10 = 8.8108185446e-04, /* 0x3a66f867 */ -t11 = -5.3859531181e-04, /* 0xba0d3085 */ -t12 = 3.1563205994e-04, /* 0x39a57b6b */ -t13 = -3.1275415677e-04, /* 0xb9a3f927 */ -t14 = 3.3552918467e-04, /* 0x39afe9f7 */ -u0 = -7.7215664089e-02, /* 0xbd9e233f */ -u1 = 6.3282704353e-01, /* 0x3f2200f4 */ -u2 = 1.4549225569e+00, /* 0x3fba3ae7 */ -u3 = 9.7771751881e-01, /* 0x3f7a4bb2 */ -u4 = 2.2896373272e-01, /* 0x3e6a7578 */ -u5 = 1.3381091878e-02, /* 0x3c5b3c5e */ -v1 = 2.4559779167e+00, /* 0x401d2ebe */ -v2 = 2.1284897327e+00, /* 0x4008392d */ -v3 = 7.6928514242e-01, /* 0x3f44efdf */ -v4 = 1.0422264785e-01, /* 0x3dd572af */ -v5 = 3.2170924824e-03, /* 0x3b52d5db */ -s0 = -7.7215664089e-02, /* 0xbd9e233f */ -s1 = 2.1498242021e-01, /* 0x3e5c245a */ -s2 = 3.2577878237e-01, /* 0x3ea6cc7a */ -s3 = 1.4635047317e-01, /* 0x3e15dce6 */ -s4 = 2.6642270386e-02, /* 0x3cda40e4 */ -s5 = 1.8402845599e-03, /* 0x3af135b4 */ -s6 = 3.1947532989e-05, /* 0x3805ff67 */ -r1 = 1.3920053244e+00, /* 0x3fb22d3b */ -r2 = 7.2193557024e-01, /* 0x3f38d0c5 */ -r3 = 1.7193385959e-01, /* 0x3e300f6e */ -r4 = 1.8645919859e-02, /* 0x3c98bf54 */ -r5 = 7.7794247773e-04, /* 0x3a4beed6 */ -r6 = 7.3266842264e-06, /* 0x36f5d7bd */ -w0 = 4.1893854737e-01, /* 0x3ed67f1d */ -w1 = 8.3333335817e-02, /* 0x3daaaaab */ -w2 = -2.7777778450e-03, /* 0xbb360b61 */ -w3 = 7.9365057172e-04, /* 0x3a500cfd */ -w4 = -5.9518753551e-04, /* 0xba1c065c */ -w5 = 8.3633989561e-04, /* 0x3a5b3dd2 */ -w6 = -1.6309292987e-03; /* 0xbad5c4e8 */ - -/* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */ -static float sin_pi(float x) -{ - double_t y; - int n; - - /* spurious inexact if odd int */ - x = 2*(x*0.5f - floorf(x*0.5f)); /* x mod 2.0 */ - - n = (int)(x*4); - n = (n+1)/2; - y = x - n*0.5f; - y *= 3.14159265358979323846; - switch (n) { - default: /* case 4: */ - case 0: return __sindf(y); - case 1: return __cosdf(y); - case 2: return __sindf(-y); - case 3: return -__cosdf(y); - } -} - -float __lgammaf_r(float x, int *signgamp) -{ - union {float f; uint32_t i;} u = {x}; - float t,y,z,nadj,p,p1,p2,p3,q,r,w; - uint32_t ix; - int i,sign; - - /* purge off +-inf, NaN, +-0, tiny and negative arguments */ - *signgamp = 1; - sign = u.i>>31; - ix = u.i & 0x7fffffff; - if (ix >= 0x7f800000) - return x*x; - if (ix < 0x35000000) { /* |x| < 2**-21, return -log(|x|) */ - if (sign) { - *signgamp = -1; - x = -x; - } - return -logf(x); - } - if (sign) { - x = -x; - t = sin_pi(x); - if (t == 0.0f) /* -integer */ - return 1.0f/(x-x); - if (t > 0.0f) - *signgamp = -1; - else - t = -t; - nadj = logf(pi/(t*x)); - } - - /* purge off 1 and 2 */ - if (ix == 0x3f800000 || ix == 0x40000000) - r = 0; - /* for x < 2.0 */ - else if (ix < 0x40000000) { - if (ix <= 0x3f666666) { /* lgamma(x) = lgamma(x+1)-log(x) */ - r = -logf(x); - if (ix >= 0x3f3b4a20) { - y = 1.0f - x; - i = 0; - } else if (ix >= 0x3e6d3308) { - y = x - (tc-1.0f); - i = 1; - } else { - y = x; - i = 2; - } - } else { - r = 0.0f; - if (ix >= 0x3fdda618) { /* [1.7316,2] */ - y = 2.0f - x; - i = 0; - } else if (ix >= 0x3F9da620) { /* [1.23,1.73] */ - y = x - tc; - i = 1; - } else { - y = x - 1.0f; - i = 2; - } - } - switch(i) { - case 0: - z = y*y; - p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10)))); - p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11))))); - p = y*p1+p2; - r += p - 0.5f*y; - break; - case 1: - z = y*y; - w = z*y; - p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */ - p2 = t1+w*(t4+w*(t7+w*(t10+w*t13))); - p3 = t2+w*(t5+w*(t8+w*(t11+w*t14))); - p = z*p1-(tt-w*(p2+y*p3)); - r += (tf + p); - break; - case 2: - p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5))))); - p2 = 1.0f+y*(v1+y*(v2+y*(v3+y*(v4+y*v5)))); - r += -0.5f*y + p1/p2; - } - } else if (ix < 0x41000000) { /* x < 8.0 */ - i = (int)x; - y = x - (float)i; - p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))); - q = 1.0f+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6))))); - r = 0.5f*y+p/q; - z = 1.0f; /* lgamma(1+s) = log(s) + lgamma(s) */ - switch (i) { - case 7: z *= y + 6.0f; /* FALLTHRU */ - case 6: z *= y + 5.0f; /* FALLTHRU */ - case 5: z *= y + 4.0f; /* FALLTHRU */ - case 4: z *= y + 3.0f; /* FALLTHRU */ - case 3: z *= y + 2.0f; /* FALLTHRU */ - r += logf(z); - break; - } - } else if (ix < 0x5c800000) { /* 8.0 <= x < 2**58 */ - t = logf(x); - z = 1.0f/x; - y = z*z; - w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6))))); - r = (x-0.5f)*(t-1.0f)+w; - } else /* 2**58 <= x <= inf */ - r = x*(logf(x)-1.0f); - if (sign) - r = nadj - r; - return r; -} - -weak_alias(__lgammaf_r, lgammaf_r); diff --git a/usr/lib/libc/math/lgammal.c b/usr/lib/libc/math/lgammal.c deleted file mode 100644 index 2b354a7c1..000000000 --- a/usr/lib/libc/math/lgammal.c +++ /dev/null @@ -1,360 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_lgammal.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* lgammal(x) - * Reentrant version of the logarithm of the Gamma function - * with user provide pointer for the sign of Gamma(x). - * - * Method: - * 1. Argument Reduction for 0 < x <= 8 - * Since gamma(1+s)=s*gamma(s), for x in [0,8], we may - * reduce x to a number in [1.5,2.5] by - * lgamma(1+s) = log(s) + lgamma(s) - * for example, - * lgamma(7.3) = log(6.3) + lgamma(6.3) - * = log(6.3*5.3) + lgamma(5.3) - * = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3) - * 2. Polynomial approximation of lgamma around its - * minimun ymin=1.461632144968362245 to maintain monotonicity. - * On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use - * Let z = x-ymin; - * lgamma(x) = -1.214862905358496078218 + z^2*poly(z) - * 2. Rational approximation in the primary interval [2,3] - * We use the following approximation: - * s = x-2.0; - * lgamma(x) = 0.5*s + s*P(s)/Q(s) - * Our algorithms are based on the following observation - * - * zeta(2)-1 2 zeta(3)-1 3 - * lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ... - * 2 3 - * - * where Euler = 0.5771... is the Euler constant, which is very - * close to 0.5. - * - * 3. For x>=8, we have - * lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+.... - * (better formula: - * lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...) - * Let z = 1/x, then we approximation - * f(z) = lgamma(x) - (x-0.5)(log(x)-1) - * by - * 3 5 11 - * w = w0 + w1*z + w2*z + w3*z + ... + w6*z - * - * 4. For negative x, since (G is gamma function) - * -x*G(-x)*G(x) = pi/sin(pi*x), - * we have - * G(x) = pi/(sin(pi*x)*(-x)*G(-x)) - * since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0 - * Hence, for x<0, signgam = sign(sin(pi*x)) and - * lgamma(x) = log(|Gamma(x)|) - * = log(pi/(|x*sin(pi*x)|)) - lgamma(-x); - * Note: one should avoid compute pi*(-x) directly in the - * computation of sin(pi*(-x)). - * - * 5. Special Cases - * lgamma(2+s) ~ s*(1-Euler) for tiny s - * lgamma(1)=lgamma(2)=0 - * lgamma(x) ~ -log(x) for tiny x - * lgamma(0) = lgamma(inf) = inf - * lgamma(-integer) = +-inf - * - */ - -#define _GNU_SOURCE -#include "libm.h" -#include "libc.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -double __lgamma_r(double x, int *sg); - -long double __lgammal_r(long double x, int *sg) -{ - return __lgamma_r(x, sg); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -static const long double -pi = 3.14159265358979323846264L, - -/* lgam(1+x) = 0.5 x + x a(x)/b(x) - -0.268402099609375 <= x <= 0 - peak relative error 6.6e-22 */ -a0 = -6.343246574721079391729402781192128239938E2L, -a1 = 1.856560238672465796768677717168371401378E3L, -a2 = 2.404733102163746263689288466865843408429E3L, -a3 = 8.804188795790383497379532868917517596322E2L, -a4 = 1.135361354097447729740103745999661157426E2L, -a5 = 3.766956539107615557608581581190400021285E0L, - -b0 = 8.214973713960928795704317259806842490498E3L, -b1 = 1.026343508841367384879065363925870888012E4L, -b2 = 4.553337477045763320522762343132210919277E3L, -b3 = 8.506975785032585797446253359230031874803E2L, -b4 = 6.042447899703295436820744186992189445813E1L, -/* b5 = 1.000000000000000000000000000000000000000E0 */ - - -tc = 1.4616321449683623412626595423257213284682E0L, -tf = -1.2148629053584961146050602565082954242826E-1, /* double precision */ -/* tt = (tail of tf), i.e. tf + tt has extended precision. */ -tt = 3.3649914684731379602768989080467587736363E-18L, -/* lgam ( 1.4616321449683623412626595423257213284682E0 ) = --1.2148629053584960809551455717769158215135617312999903886372437313313530E-1 */ - -/* lgam (x + tc) = tf + tt + x g(x)/h(x) - -0.230003726999612341262659542325721328468 <= x - <= 0.2699962730003876587373404576742786715318 - peak relative error 2.1e-21 */ -g0 = 3.645529916721223331888305293534095553827E-18L, -g1 = 5.126654642791082497002594216163574795690E3L, -g2 = 8.828603575854624811911631336122070070327E3L, -g3 = 5.464186426932117031234820886525701595203E3L, -g4 = 1.455427403530884193180776558102868592293E3L, -g5 = 1.541735456969245924860307497029155838446E2L, -g6 = 4.335498275274822298341872707453445815118E0L, - -h0 = 1.059584930106085509696730443974495979641E4L, -h1 = 2.147921653490043010629481226937850618860E4L, -h2 = 1.643014770044524804175197151958100656728E4L, -h3 = 5.869021995186925517228323497501767586078E3L, -h4 = 9.764244777714344488787381271643502742293E2L, -h5 = 6.442485441570592541741092969581997002349E1L, -/* h6 = 1.000000000000000000000000000000000000000E0 */ - - -/* lgam (x+1) = -0.5 x + x u(x)/v(x) - -0.100006103515625 <= x <= 0.231639862060546875 - peak relative error 1.3e-21 */ -u0 = -8.886217500092090678492242071879342025627E1L, -u1 = 6.840109978129177639438792958320783599310E2L, -u2 = 2.042626104514127267855588786511809932433E3L, -u3 = 1.911723903442667422201651063009856064275E3L, -u4 = 7.447065275665887457628865263491667767695E2L, -u5 = 1.132256494121790736268471016493103952637E2L, -u6 = 4.484398885516614191003094714505960972894E0L, - -v0 = 1.150830924194461522996462401210374632929E3L, -v1 = 3.399692260848747447377972081399737098610E3L, -v2 = 3.786631705644460255229513563657226008015E3L, -v3 = 1.966450123004478374557778781564114347876E3L, -v4 = 4.741359068914069299837355438370682773122E2L, -v5 = 4.508989649747184050907206782117647852364E1L, -/* v6 = 1.000000000000000000000000000000000000000E0 */ - - -/* lgam (x+2) = .5 x + x s(x)/r(x) - 0 <= x <= 1 - peak relative error 7.2e-22 */ -s0 = 1.454726263410661942989109455292824853344E6L, -s1 = -3.901428390086348447890408306153378922752E6L, -s2 = -6.573568698209374121847873064292963089438E6L, -s3 = -3.319055881485044417245964508099095984643E6L, -s4 = -7.094891568758439227560184618114707107977E5L, -s5 = -6.263426646464505837422314539808112478303E4L, -s6 = -1.684926520999477529949915657519454051529E3L, - -r0 = -1.883978160734303518163008696712983134698E7L, -r1 = -2.815206082812062064902202753264922306830E7L, -r2 = -1.600245495251915899081846093343626358398E7L, -r3 = -4.310526301881305003489257052083370058799E6L, -r4 = -5.563807682263923279438235987186184968542E5L, -r5 = -3.027734654434169996032905158145259713083E4L, -r6 = -4.501995652861105629217250715790764371267E2L, -/* r6 = 1.000000000000000000000000000000000000000E0 */ - - -/* lgam(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x w(1/x^2) - x >= 8 - Peak relative error 1.51e-21 -w0 = LS2PI - 0.5 */ -w0 = 4.189385332046727417803e-1L, -w1 = 8.333333333333331447505E-2L, -w2 = -2.777777777750349603440E-3L, -w3 = 7.936507795855070755671E-4L, -w4 = -5.952345851765688514613E-4L, -w5 = 8.412723297322498080632E-4L, -w6 = -1.880801938119376907179E-3L, -w7 = 4.885026142432270781165E-3L; - -/* sin(pi*x) assuming x > 2^-1000, if sin(pi*x)==0 the sign is arbitrary */ -static long double sin_pi(long double x) -{ - int n; - - /* spurious inexact if odd int */ - x *= 0.5; - x = 2.0*(x - floorl(x)); /* x mod 2.0 */ - - n = (int)(x*4.0); - n = (n+1)/2; - x -= n*0.5f; - x *= pi; - - switch (n) { - default: /* case 4: */ - case 0: return __sinl(x, 0.0, 0); - case 1: return __cosl(x, 0.0); - case 2: return __sinl(-x, 0.0, 0); - case 3: return -__cosl(x, 0.0); - } -} - -long double __lgammal_r(long double x, int *sg) { - long double t, y, z, nadj, p, p1, p2, q, r, w; - union ldshape u = {x}; - uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48; - int sign = u.i.se >> 15; - int i; - - *sg = 1; - - /* purge off +-inf, NaN, +-0, tiny and negative arguments */ - if (ix >= 0x7fff0000) - return x * x; - if (ix < 0x3fc08000) { /* |x|<2**-63, return -log(|x|) */ - if (sign) { - *sg = -1; - x = -x; - } - return -logl(x); - } - if (sign) { - x = -x; - t = sin_pi(x); - if (t == 0.0) - return 1.0 / (x-x); /* -integer */ - if (t > 0.0) - *sg = -1; - else - t = -t; - nadj = logl(pi / (t * x)); - } - - /* purge off 1 and 2 (so the sign is ok with downward rounding) */ - if ((ix == 0x3fff8000 || ix == 0x40008000) && u.i.m == 0) { - r = 0; - } else if (ix < 0x40008000) { /* x < 2.0 */ - if (ix <= 0x3ffee666) { /* 8.99993896484375e-1 */ - /* lgamma(x) = lgamma(x+1) - log(x) */ - r = -logl(x); - if (ix >= 0x3ffebb4a) { /* 7.31597900390625e-1 */ - y = x - 1.0; - i = 0; - } else if (ix >= 0x3ffced33) { /* 2.31639862060546875e-1 */ - y = x - (tc - 1.0); - i = 1; - } else { /* x < 0.23 */ - y = x; - i = 2; - } - } else { - r = 0.0; - if (ix >= 0x3fffdda6) { /* 1.73162841796875 */ - /* [1.7316,2] */ - y = x - 2.0; - i = 0; - } else if (ix >= 0x3fff9da6) { /* 1.23162841796875 */ - /* [1.23,1.73] */ - y = x - tc; - i = 1; - } else { - /* [0.9, 1.23] */ - y = x - 1.0; - i = 2; - } - } - switch (i) { - case 0: - p1 = a0 + y * (a1 + y * (a2 + y * (a3 + y * (a4 + y * a5)))); - p2 = b0 + y * (b1 + y * (b2 + y * (b3 + y * (b4 + y)))); - r += 0.5 * y + y * p1/p2; - break; - case 1: - p1 = g0 + y * (g1 + y * (g2 + y * (g3 + y * (g4 + y * (g5 + y * g6))))); - p2 = h0 + y * (h1 + y * (h2 + y * (h3 + y * (h4 + y * (h5 + y))))); - p = tt + y * p1/p2; - r += (tf + p); - break; - case 2: - p1 = y * (u0 + y * (u1 + y * (u2 + y * (u3 + y * (u4 + y * (u5 + y * u6)))))); - p2 = v0 + y * (v1 + y * (v2 + y * (v3 + y * (v4 + y * (v5 + y))))); - r += (-0.5 * y + p1 / p2); - } - } else if (ix < 0x40028000) { /* 8.0 */ - /* x < 8.0 */ - i = (int)x; - y = x - (double)i; - p = y * (s0 + y * (s1 + y * (s2 + y * (s3 + y * (s4 + y * (s5 + y * s6)))))); - q = r0 + y * (r1 + y * (r2 + y * (r3 + y * (r4 + y * (r5 + y * (r6 + y)))))); - r = 0.5 * y + p / q; - z = 1.0; - /* lgamma(1+s) = log(s) + lgamma(s) */ - switch (i) { - case 7: - z *= (y + 6.0); /* FALLTHRU */ - case 6: - z *= (y + 5.0); /* FALLTHRU */ - case 5: - z *= (y + 4.0); /* FALLTHRU */ - case 4: - z *= (y + 3.0); /* FALLTHRU */ - case 3: - z *= (y + 2.0); /* FALLTHRU */ - r += logl(z); - break; - } - } else if (ix < 0x40418000) { /* 2^66 */ - /* 8.0 <= x < 2**66 */ - t = logl(x); - z = 1.0 / x; - y = z * z; - w = w0 + z * (w1 + y * (w2 + y * (w3 + y * (w4 + y * (w5 + y * (w6 + y * w7)))))); - r = (x - 0.5) * (t - 1.0) + w; - } else /* 2**66 <= x <= inf */ - r = x * (logl(x) - 1.0); - if (sign) - r = nadj - r; - return r; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -double __lgamma_r(double x, int *sg); - -long double __lgammal_r(long double x, int *sg) -{ - return __lgamma_r(x, sg); -} -#endif - -extern int __signgam; - -long double lgammal(long double x) -{ - return __lgammal_r(x, &__signgam); -} - -weak_alias(__lgammal_r, lgammal_r); diff --git a/usr/lib/libc/math/llrint.c b/usr/lib/libc/math/llrint.c deleted file mode 100644 index 4f583ae55..000000000 --- a/usr/lib/libc/math/llrint.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -/* uses LLONG_MAX > 2^53, see comments in lrint.c */ - -long long llrint(double x) -{ - return rint(x); -} diff --git a/usr/lib/libc/math/llrintf.c b/usr/lib/libc/math/llrintf.c deleted file mode 100644 index 96949a006..000000000 --- a/usr/lib/libc/math/llrintf.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -/* uses LLONG_MAX > 2^24, see comments in lrint.c */ - -long long llrintf(float x) -{ - return rintf(x); -} diff --git a/usr/lib/libc/math/llrintl.c b/usr/lib/libc/math/llrintl.c deleted file mode 100644 index 3449f6f2b..000000000 --- a/usr/lib/libc/math/llrintl.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include "libm.h" - - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long long llrintl(long double x) -{ - return llrint(x); -} -#elif defined(FE_INEXACT) -/* -see comments in lrint.c - -Note that if LLONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64 -then x == 2**63 - 0.5 is the only input that overflows and -raises inexact (with tonearest or upward rounding mode) -*/ -long long llrintl(long double x) -{ - #pragma STDC FENV_ACCESS ON - int e; - - e = fetestexcept(FE_INEXACT); - x = rintl(x); - if (!e && (x > LLONG_MAX || x < LLONG_MIN)) - feclearexcept(FE_INEXACT); - /* conversion */ - return x; -} -#else -long long llrintl(long double x) -{ - return rintl(x); -} -#endif diff --git a/usr/lib/libc/math/llround.c b/usr/lib/libc/math/llround.c deleted file mode 100644 index 4d94787d6..000000000 --- a/usr/lib/libc/math/llround.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long long llround(double x) -{ - return round(x); -} diff --git a/usr/lib/libc/math/llroundf.c b/usr/lib/libc/math/llroundf.c deleted file mode 100644 index 19eb77ee3..000000000 --- a/usr/lib/libc/math/llroundf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long long llroundf(float x) -{ - return roundf(x); -} diff --git a/usr/lib/libc/math/llroundl.c b/usr/lib/libc/math/llroundl.c deleted file mode 100644 index 2c2ee5ecd..000000000 --- a/usr/lib/libc/math/llroundl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long long llroundl(long double x) -{ - return roundl(x); -} diff --git a/usr/lib/libc/math/log.c b/usr/lib/libc/math/log.c deleted file mode 100644 index e61e113d4..000000000 --- a/usr/lib/libc/math/log.c +++ /dev/null @@ -1,118 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* log(x) - * Return the logarithm of x - * - * Method : - * 1. Argument Reduction: find k and f such that - * x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * 2. Approximation of log(1+f). - * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) - * = 2s + 2/3 s**3 + 2/5 s**5 + ....., - * = 2s + s*R - * We use a special Remez algorithm on [0,0.1716] to generate - * a polynomial of degree 14 to approximate R The maximum error - * of this polynomial approximation is bounded by 2**-58.45. In - * other words, - * 2 4 6 8 10 12 14 - * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s - * (the values of Lg1 to Lg7 are listed in the program) - * and - * | 2 14 | -58.45 - * | Lg1*s +...+Lg7*s - R(z) | <= 2 - * | | - * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. - * In order to guarantee error in log below 1ulp, we compute log - * by - * log(1+f) = f - s*(f - R) (if f is not too large) - * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) - * - * 3. Finally, log(x) = k*ln2 + log(1+f). - * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) - * Here ln2 is split into two floating point number: - * ln2_hi + ln2_lo, - * where n*ln2_hi is always exact for |n| < 2000. - * - * Special cases: - * log(x) is NaN with signal if x < 0 (including -INF) ; - * log(+INF) is +INF; log(0) is -INF with signal; - * log(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include -#include - -static const double -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -double log(double x) -{ - union {double f; uint64_t i;} u = {x}; - double_t hfsq,f,s,z,R,w,t1,t2,dk; - uint32_t hx; - int k; - - hx = u.i>>32; - k = 0; - if (hx < 0x00100000 || hx>>31) { - if (u.i<<1 == 0) - return -1/(x*x); /* log(+-0)=-inf */ - if (hx>>31) - return (x-x)/0.0; /* log(-#) = NaN */ - /* subnormal number, scale x up */ - k -= 54; - x *= 0x1p54; - u.f = x; - hx = u.i>>32; - } else if (hx >= 0x7ff00000) { - return x; - } else if (hx == 0x3ff00000 && u.i<<32 == 0) - return 0; - - /* reduce x into [sqrt(2)/2, sqrt(2)] */ - hx += 0x3ff00000 - 0x3fe6a09e; - k += (int)(hx>>20) - 0x3ff; - hx = (hx&0x000fffff) + 0x3fe6a09e; - u.i = (uint64_t)hx<<32 | (u.i&0xffffffff); - x = u.f; - - f = x - 1.0; - hfsq = 0.5*f*f; - s = f/(2.0+f); - z = s*s; - w = z*z; - t1 = w*(Lg2+w*(Lg4+w*Lg6)); - t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - R = t2 + t1; - dk = k; - return s*(hfsq+R) + dk*ln2_lo - hfsq + f + dk*ln2_hi; -} diff --git a/usr/lib/libc/math/log10.c b/usr/lib/libc/math/log10.c deleted file mode 100644 index 81026876b..000000000 --- a/usr/lib/libc/math/log10.c +++ /dev/null @@ -1,101 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log10.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * Return the base 10 logarithm of x. See log.c for most comments. - * - * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2 - * as in log.c, then combine and scale in extra precision: - * log10(x) = (f - f*f/2 + r)/log(10) + k*log10(2) - */ - -#include -#include - -static const double -ivln10hi = 4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */ -ivln10lo = 2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */ -log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ -log10_2lo = 3.69423907715893078616e-13, /* 0x3D59FEF3, 0x11F12B36 */ -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -double log10(double x) -{ - union {double f; uint64_t i;} u = {x}; - double_t hfsq,f,s,z,R,w,t1,t2,dk,y,hi,lo,val_hi,val_lo; - uint32_t hx; - int k; - - hx = u.i>>32; - k = 0; - if (hx < 0x00100000 || hx>>31) { - if (u.i<<1 == 0) - return -1/(x*x); /* log(+-0)=-inf */ - if (hx>>31) - return (x-x)/0.0; /* log(-#) = NaN */ - /* subnormal number, scale x up */ - k -= 54; - x *= 0x1p54; - u.f = x; - hx = u.i>>32; - } else if (hx >= 0x7ff00000) { - return x; - } else if (hx == 0x3ff00000 && u.i<<32 == 0) - return 0; - - /* reduce x into [sqrt(2)/2, sqrt(2)] */ - hx += 0x3ff00000 - 0x3fe6a09e; - k += (int)(hx>>20) - 0x3ff; - hx = (hx&0x000fffff) + 0x3fe6a09e; - u.i = (uint64_t)hx<<32 | (u.i&0xffffffff); - x = u.f; - - f = x - 1.0; - hfsq = 0.5*f*f; - s = f/(2.0+f); - z = s*s; - w = z*z; - t1 = w*(Lg2+w*(Lg4+w*Lg6)); - t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - R = t2 + t1; - - /* See log2.c for details. */ - /* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */ - hi = f - hfsq; - u.f = hi; - u.i &= (uint64_t)-1<<32; - hi = u.f; - lo = f - hi - hfsq + s*(hfsq+R); - - /* val_hi+val_lo ~ log10(1+f) + k*log10(2) */ - val_hi = hi*ivln10hi; - dk = k; - y = dk*log10_2hi; - val_lo = dk*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi; - - /* - * Extra precision in for adding y is not strictly needed - * since there is no very large cancellation near x = sqrt(2) or - * x = 1/sqrt(2), but we do it anyway since it costs little on CPUs - * with some parallelism and it reduces the error for many args. - */ - w = y + val_hi; - val_lo += (y - w) + val_hi; - val_hi = w; - - return val_lo + val_hi; -} diff --git a/usr/lib/libc/math/log10f.c b/usr/lib/libc/math/log10f.c deleted file mode 100644 index 9ca2f017d..000000000 --- a/usr/lib/libc/math/log10f.c +++ /dev/null @@ -1,77 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in log10.c. - */ - -#include -#include - -static const float -ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */ -ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */ -log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ -log10_2lo = 7.9034151668e-07, /* 0x355427db */ -/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ -Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ -Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ -Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ -Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ - -float log10f(float x) -{ - union {float f; uint32_t i;} u = {x}; - float_t hfsq,f,s,z,R,w,t1,t2,dk,hi,lo; - uint32_t ix; - int k; - - ix = u.i; - k = 0; - if (ix < 0x00800000 || ix>>31) { /* x < 2**-126 */ - if (ix<<1 == 0) - return -1/(x*x); /* log(+-0)=-inf */ - if (ix>>31) - return (x-x)/0.0f; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 25; - x *= 0x1p25f; - u.f = x; - ix = u.i; - } else if (ix >= 0x7f800000) { - return x; - } else if (ix == 0x3f800000) - return 0; - - /* reduce x into [sqrt(2)/2, sqrt(2)] */ - ix += 0x3f800000 - 0x3f3504f3; - k += (int)(ix>>23) - 0x7f; - ix = (ix&0x007fffff) + 0x3f3504f3; - u.i = ix; - x = u.f; - - f = x - 1.0f; - s = f/(2.0f + f); - z = s*s; - w = z*z; - t1= w*(Lg2+w*Lg4); - t2= z*(Lg1+w*Lg3); - R = t2 + t1; - hfsq = 0.5f*f*f; - - hi = f - hfsq; - u.f = hi; - u.i &= 0xfffff000; - hi = u.f; - lo = f - hi - hfsq + s*(hfsq+R); - dk = k; - return dk*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi + dk*log10_2hi; -} diff --git a/usr/lib/libc/math/log10l.c b/usr/lib/libc/math/log10l.c deleted file mode 100644 index 63dcc286d..000000000 --- a/usr/lib/libc/math/log10l.c +++ /dev/null @@ -1,191 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log10l.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Common logarithm, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, log10l(); - * - * y = log10l( x ); - * - * - * DESCRIPTION: - * - * Returns the base 10 logarithm of x. - * - * The argument is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the logarithm - * of the fraction is approximated by - * - * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/x+1), - * - * log(x) = z + z**3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0.5, 2.0 30000 9.0e-20 2.6e-20 - * IEEE exp(+-10000) 30000 6.0e-20 2.3e-20 - * - * In the tests over the interval exp(+-10000), the logarithms - * of the random arguments were uniformly distributed over - * [-10000, +10000]. - * - * ERROR MESSAGES: - * - * log singularity: x = 0; returns MINLOG - * log domain: x < 0; returns MINLOG - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double log10l(long double x) -{ - return log10(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.2e-22 - */ -static const long double P[] = { - 4.9962495940332550844739E-1L, - 1.0767376367209449010438E1L, - 7.7671073698359539859595E1L, - 2.5620629828144409632571E2L, - 4.2401812743503691187826E2L, - 3.4258224542413922935104E2L, - 1.0747524399916215149070E2L, -}; -static const long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 2.3479774160285863271658E1L, - 1.9444210022760132894510E2L, - 7.7952888181207260646090E2L, - 1.6911722418503949084863E3L, - 2.0307734695595183428202E3L, - 1.2695660352705325274404E3L, - 3.2242573199748645407652E2L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static const long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static const long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -/* log10(2) */ -#define L102A 0.3125L -#define L102B -1.1470004336018804786261e-2L -/* log10(e) */ -#define L10EA 0.5L -#define L10EB -6.5705518096748172348871e-2L - -#define SQRTH 0.70710678118654752440L - -long double log10l(long double x) -{ - long double y, z; - int e; - - if (isnan(x)) - return x; - if(x <= 0.0) { - if(x == 0.0) - return -1.0 / (x*x); - return (x - x) / 0.0; - } - if (x == INFINITY) - return INFINITY; - /* separate mantissa from exponent */ - /* Note, frexp is used so that denormal numbers - * will be handled properly. - */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z**3 P(z)/Q(z), - * where z = 2(x-1)/x+1) - */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5; - y = 0.5 * z + 0.5; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5; - z -= 0.5; - y = 0.5 * x + 0.5; - } - x = z / y; - z = x*x; - y = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - goto done; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - x = 2.0*x - 1.0; - } else { - x = x - 1.0; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 7)); - y = y - 0.5*z; - -done: - /* Multiply log of fraction by log10(e) - * and base 2 exponent by log10(2). - * - * ***CAUTION*** - * - * This sequence of operations is critical and it may - * be horribly defeated by some compiler optimizers. - */ - z = y * (L10EB); - z += x * (L10EB); - z += e * (L102B); - z += y * (L10EA); - z += x * (L10EA); - z += e * (L102A); - return z; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double log10l(long double x) -{ - return log10(x); -} -#endif diff --git a/usr/lib/libc/math/log1p.c b/usr/lib/libc/math/log1p.c deleted file mode 100644 index 009713494..000000000 --- a/usr/lib/libc/math/log1p.c +++ /dev/null @@ -1,122 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_log1p.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* double log1p(double x) - * Return the natural logarithm of 1+x. - * - * Method : - * 1. Argument Reduction: find k and f such that - * 1+x = 2^k * (1+f), - * where sqrt(2)/2 < 1+f < sqrt(2) . - * - * Note. If k=0, then f=x is exact. However, if k!=0, then f - * may not be representable exactly. In that case, a correction - * term is need. Let u=1+x rounded. Let c = (1+x)-u, then - * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), - * and add back the correction term c/u. - * (Note: when x > 2**53, one can simply return log(x)) - * - * 2. Approximation of log(1+f): See log.c - * - * 3. Finally, log1p(x) = k*ln2 + log(1+f) + c/u. See log.c - * - * Special cases: - * log1p(x) is NaN with signal if x < -1 (including -INF) ; - * log1p(+INF) is +INF; log1p(-1) is -INF with signal; - * log1p(NaN) is that NaN with no signal. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - * - * Note: Assuming log() return accurate answer, the following - * algorithm can be used to compute log1p(x) to within a few ULP: - * - * u = 1+x; - * if(u==1.0) return x ; else - * return log(u)*(x/(u-1.0)); - * - * See HP-15C Advanced Functions Handbook, p.193. - */ - -#include "libm.h" - -static const double -ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ -ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -double log1p(double x) -{ - union {double f; uint64_t i;} u = {x}; - double_t hfsq,f,c,s,z,R,w,t1,t2,dk; - uint32_t hx,hu; - int k; - - hx = u.i>>32; - k = 1; - if (hx < 0x3fda827a || hx>>31) { /* 1+x < sqrt(2)+ */ - if (hx >= 0xbff00000) { /* x <= -1.0 */ - if (x == -1) - return x/0.0; /* log1p(-1) = -inf */ - return (x-x)/0.0; /* log1p(x<-1) = NaN */ - } - if (hx<<1 < 0x3ca00000<<1) { /* |x| < 2**-53 */ - /* underflow if subnormal */ - if ((hx&0x7ff00000) == 0) - FORCE_EVAL((float)x); - return x; - } - if (hx <= 0xbfd2bec4) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ - k = 0; - c = 0; - f = x; - } - } else if (hx >= 0x7ff00000) - return x; - if (k) { - u.f = 1 + x; - hu = u.i>>32; - hu += 0x3ff00000 - 0x3fe6a09e; - k = (int)(hu>>20) - 0x3ff; - /* correction term ~ log(1+x)-log(u), avoid underflow in c/u */ - if (k < 54) { - c = k >= 2 ? 1-(u.f-x) : x-(u.f-1); - c /= u.f; - } else - c = 0; - /* reduce u into [sqrt(2)/2, sqrt(2)] */ - hu = (hu&0x000fffff) + 0x3fe6a09e; - u.i = (uint64_t)hu<<32 | (u.i&0xffffffff); - f = u.f - 1; - } - hfsq = 0.5*f*f; - s = f/(2.0+f); - z = s*s; - w = z*z; - t1 = w*(Lg2+w*(Lg4+w*Lg6)); - t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - R = t2 + t1; - dk = k; - return s*(hfsq+R) + (dk*ln2_lo+c) - hfsq + f + dk*ln2_hi; -} diff --git a/usr/lib/libc/math/log1pf.c b/usr/lib/libc/math/log1pf.c deleted file mode 100644 index 23985c356..000000000 --- a/usr/lib/libc/math/log1pf.c +++ /dev/null @@ -1,77 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_log1pf.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float -ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ -ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ -/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ -Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ -Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ -Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ -Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ - -float log1pf(float x) -{ - union {float f; uint32_t i;} u = {x}; - float_t hfsq,f,c,s,z,R,w,t1,t2,dk; - uint32_t ix,iu; - int k; - - ix = u.i; - k = 1; - if (ix < 0x3ed413d0 || ix>>31) { /* 1+x < sqrt(2)+ */ - if (ix >= 0xbf800000) { /* x <= -1.0 */ - if (x == -1) - return x/0.0f; /* log1p(-1)=+inf */ - return (x-x)/0.0f; /* log1p(x<-1)=NaN */ - } - if (ix<<1 < 0x33800000<<1) { /* |x| < 2**-24 */ - /* underflow if subnormal */ - if ((ix&0x7f800000) == 0) - FORCE_EVAL(x*x); - return x; - } - if (ix <= 0xbe95f619) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ - k = 0; - c = 0; - f = x; - } - } else if (ix >= 0x7f800000) - return x; - if (k) { - u.f = 1 + x; - iu = u.i; - iu += 0x3f800000 - 0x3f3504f3; - k = (int)(iu>>23) - 0x7f; - /* correction term ~ log(1+x)-log(u), avoid underflow in c/u */ - if (k < 25) { - c = k >= 2 ? 1-(u.f-x) : x-(u.f-1); - c /= u.f; - } else - c = 0; - /* reduce u into [sqrt(2)/2, sqrt(2)] */ - iu = (iu&0x007fffff) + 0x3f3504f3; - u.i = iu; - f = u.f - 1; - } - s = f/(2.0f + f); - z = s*s; - w = z*z; - t1= w*(Lg2+w*Lg4); - t2= z*(Lg1+w*Lg3); - R = t2 + t1; - hfsq = 0.5f*f*f; - dk = k; - return s*(hfsq+R) + (dk*ln2_lo+c) - hfsq + f + dk*ln2_hi; -} diff --git a/usr/lib/libc/math/log1pl.c b/usr/lib/libc/math/log1pl.c deleted file mode 100644 index 141b5f0b0..000000000 --- a/usr/lib/libc/math/log1pl.c +++ /dev/null @@ -1,177 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/s_log1pl.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Relative error logarithm - * Natural logarithm of 1+x, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, log1pl(); - * - * y = log1pl( x ); - * - * - * DESCRIPTION: - * - * Returns the base e (2.718...) logarithm of 1+x. - * - * The argument 1+x is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the logarithm - * of the fraction is approximated by - * - * log(1+x) = x - 0.5 x^2 + x^3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/x+1), - * - * log(x) = z + z^3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE -1.0, 9.0 100000 8.2e-20 2.5e-20 - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double log1pl(long double x) -{ - return log1p(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for log(1+x) = x - x^2 / 2 + x^3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 2.32e-20 - */ -static const long double P[] = { - 4.5270000862445199635215E-5L, - 4.9854102823193375972212E-1L, - 6.5787325942061044846969E0L, - 2.9911919328553073277375E1L, - 6.0949667980987787057556E1L, - 5.7112963590585538103336E1L, - 2.0039553499201281259648E1L, -}; -static const long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 1.5062909083469192043167E1L, - 8.3047565967967209469434E1L, - 2.2176239823732856465394E2L, - 3.0909872225312059774938E2L, - 2.1642788614495947685003E2L, - 6.0118660497603843919306E1L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static const long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static const long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -static const long double C1 = 6.9314575195312500000000E-1L; -static const long double C2 = 1.4286068203094172321215E-6L; - -#define SQRTH 0.70710678118654752440L - -long double log1pl(long double xm1) -{ - long double x, y, z; - int e; - - if (isnan(xm1)) - return xm1; - if (xm1 == INFINITY) - return xm1; - if (xm1 == 0.0) - return xm1; - - x = xm1 + 1.0; - - /* Test for domain errors. */ - if (x <= 0.0) { - if (x == 0.0) - return -1/(x*x); /* -inf with divbyzero */ - return 0/0.0f; /* nan with invalid */ - } - - /* Separate mantissa from exponent. - Use frexp so that denormal numbers will be handled properly. */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z^3 P(z)/Q(z), - where z = 2(x-1)/x+1) */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5; - y = 0.5 * z + 0.5; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5; - z -= 0.5; - y = 0.5 * x + 0.5; - } - x = z / y; - z = x*x; - z = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - z = z + e * C2; - z = z + x; - z = z + e * C1; - return z; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - if (e != 0) - x = 2.0 * x - 1.0; - else - x = xm1; - } else { - if (e != 0) - x = x - 1.0; - else - x = xm1; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 6)); - y = y + e * C2; - z = y - 0.5 * z; - z = z + x; - z = z + e * C1; - return z; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double log1pl(long double x) -{ - return log1p(x); -} -#endif diff --git a/usr/lib/libc/math/log2.c b/usr/lib/libc/math/log2.c deleted file mode 100644 index 0aafad4b8..000000000 --- a/usr/lib/libc/math/log2.c +++ /dev/null @@ -1,122 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * Return the base 2 logarithm of x. See log.c for most comments. - * - * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2 - * as in log.c, then combine and scale in extra precision: - * log2(x) = (f - f*f/2 + r)/log(2) + k - */ - -#include -#include - -static const double -ivln2hi = 1.44269504072144627571e+00, /* 0x3ff71547, 0x65200000 */ -ivln2lo = 1.67517131648865118353e-10, /* 0x3de705fc, 0x2eefa200 */ -Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ -Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ -Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ -Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ -Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ -Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ -Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - -double log2(double x) -{ - union {double f; uint64_t i;} u = {x}; - double_t hfsq,f,s,z,R,w,t1,t2,y,hi,lo,val_hi,val_lo; - uint32_t hx; - int k; - - hx = u.i>>32; - k = 0; - if (hx < 0x00100000 || hx>>31) { - if (u.i<<1 == 0) - return -1/(x*x); /* log(+-0)=-inf */ - if (hx>>31) - return (x-x)/0.0; /* log(-#) = NaN */ - /* subnormal number, scale x up */ - k -= 54; - x *= 0x1p54; - u.f = x; - hx = u.i>>32; - } else if (hx >= 0x7ff00000) { - return x; - } else if (hx == 0x3ff00000 && u.i<<32 == 0) - return 0; - - /* reduce x into [sqrt(2)/2, sqrt(2)] */ - hx += 0x3ff00000 - 0x3fe6a09e; - k += (int)(hx>>20) - 0x3ff; - hx = (hx&0x000fffff) + 0x3fe6a09e; - u.i = (uint64_t)hx<<32 | (u.i&0xffffffff); - x = u.f; - - f = x - 1.0; - hfsq = 0.5*f*f; - s = f/(2.0+f); - z = s*s; - w = z*z; - t1 = w*(Lg2+w*(Lg4+w*Lg6)); - t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); - R = t2 + t1; - - /* - * f-hfsq must (for args near 1) be evaluated in extra precision - * to avoid a large cancellation when x is near sqrt(2) or 1/sqrt(2). - * This is fairly efficient since f-hfsq only depends on f, so can - * be evaluated in parallel with R. Not combining hfsq with R also - * keeps R small (though not as small as a true `lo' term would be), - * so that extra precision is not needed for terms involving R. - * - * Compiler bugs involving extra precision used to break Dekker's - * theorem for spitting f-hfsq as hi+lo, unless double_t was used - * or the multi-precision calculations were avoided when double_t - * has extra precision. These problems are now automatically - * avoided as a side effect of the optimization of combining the - * Dekker splitting step with the clear-low-bits step. - * - * y must (for args near sqrt(2) and 1/sqrt(2)) be added in extra - * precision to avoid a very large cancellation when x is very near - * these values. Unlike the above cancellations, this problem is - * specific to base 2. It is strange that adding +-1 is so much - * harder than adding +-ln2 or +-log10_2. - * - * This uses Dekker's theorem to normalize y+val_hi, so the - * compiler bugs are back in some configurations, sigh. And I - * don't want to used double_t to avoid them, since that gives a - * pessimization and the support for avoiding the pessimization - * is not yet available. - * - * The multi-precision calculations for the multiplications are - * routine. - */ - - /* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */ - hi = f - hfsq; - u.f = hi; - u.i &= (uint64_t)-1<<32; - hi = u.f; - lo = f - hi - hfsq + s*(hfsq+R); - - val_hi = hi*ivln2hi; - val_lo = (lo+hi)*ivln2lo + lo*ivln2hi; - - /* spadd(val_hi, val_lo, y), except for not using double_t: */ - y = k; - w = y + val_hi; - val_lo += (y - w) + val_hi; - val_hi = w; - - return val_lo + val_hi; -} diff --git a/usr/lib/libc/math/log2f.c b/usr/lib/libc/math/log2f.c deleted file mode 100644 index b3e305fe2..000000000 --- a/usr/lib/libc/math/log2f.c +++ /dev/null @@ -1,74 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_log2f.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * See comments in log2.c. - */ - -#include -#include - -static const float -ivln2hi = 1.4428710938e+00, /* 0x3fb8b000 */ -ivln2lo = -1.7605285393e-04, /* 0xb9389ad4 */ -/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ -Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ -Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ -Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ -Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ - -float log2f(float x) -{ - union {float f; uint32_t i;} u = {x}; - float_t hfsq,f,s,z,R,w,t1,t2,hi,lo; - uint32_t ix; - int k; - - ix = u.i; - k = 0; - if (ix < 0x00800000 || ix>>31) { /* x < 2**-126 */ - if (ix<<1 == 0) - return -1/(x*x); /* log(+-0)=-inf */ - if (ix>>31) - return (x-x)/0.0f; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 25; - x *= 0x1p25f; - u.f = x; - ix = u.i; - } else if (ix >= 0x7f800000) { - return x; - } else if (ix == 0x3f800000) - return 0; - - /* reduce x into [sqrt(2)/2, sqrt(2)] */ - ix += 0x3f800000 - 0x3f3504f3; - k += (int)(ix>>23) - 0x7f; - ix = (ix&0x007fffff) + 0x3f3504f3; - u.i = ix; - x = u.f; - - f = x - 1.0f; - s = f/(2.0f + f); - z = s*s; - w = z*z; - t1= w*(Lg2+w*Lg4); - t2= z*(Lg1+w*Lg3); - R = t2 + t1; - hfsq = 0.5f*f*f; - - hi = f - hfsq; - u.f = hi; - u.i &= 0xfffff000; - hi = u.f; - lo = f - hi - hfsq + s*(hfsq+R); - return (lo+hi)*ivln2lo + lo*ivln2hi + hi*ivln2hi + k; -} diff --git a/usr/lib/libc/math/log2l.c b/usr/lib/libc/math/log2l.c deleted file mode 100644 index 722b451a0..000000000 --- a/usr/lib/libc/math/log2l.c +++ /dev/null @@ -1,182 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log2l.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Base 2 logarithm, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, log2l(); - * - * y = log2l( x ); - * - * - * DESCRIPTION: - * - * Returns the base 2 logarithm of x. - * - * The argument is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the (natural) - * logarithm of the fraction is approximated by - * - * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/x+1), - * - * log(x) = z + z**3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0.5, 2.0 30000 9.8e-20 2.7e-20 - * IEEE exp(+-10000) 70000 5.4e-20 2.3e-20 - * - * In the tests over the interval exp(+-10000), the logarithms - * of the random arguments were uniformly distributed over - * [-10000, +10000]. - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double log2l(long double x) -{ - return log2(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for ln(1+x) = x - x**2/2 + x**3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.2e-22 - */ -static const long double P[] = { - 4.9962495940332550844739E-1L, - 1.0767376367209449010438E1L, - 7.7671073698359539859595E1L, - 2.5620629828144409632571E2L, - 4.2401812743503691187826E2L, - 3.4258224542413922935104E2L, - 1.0747524399916215149070E2L, -}; -static const long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 2.3479774160285863271658E1L, - 1.9444210022760132894510E2L, - 7.7952888181207260646090E2L, - 1.6911722418503949084863E3L, - 2.0307734695595183428202E3L, - 1.2695660352705325274404E3L, - 3.2242573199748645407652E2L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static const long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static const long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -/* log2(e) - 1 */ -#define LOG2EA 4.4269504088896340735992e-1L - -#define SQRTH 0.70710678118654752440L - -long double log2l(long double x) -{ - long double y, z; - int e; - - if (isnan(x)) - return x; - if (x == INFINITY) - return x; - if (x <= 0.0) { - if (x == 0.0) - return -1/(x*x); /* -inf with divbyzero */ - return 0/0.0f; /* nan with invalid */ - } - - /* separate mantissa from exponent */ - /* Note, frexp is used so that denormal numbers - * will be handled properly. - */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z**3 P(z)/Q(z), - * where z = 2(x-1)/x+1) - */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5; - y = 0.5 * z + 0.5; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5; - z -= 0.5; - y = 0.5 * x + 0.5; - } - x = z / y; - z = x*x; - y = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - goto done; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - x = 2.0*x - 1.0; - } else { - x = x - 1.0; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 7)); - y = y - 0.5*z; - -done: - /* Multiply log of fraction by log2(e) - * and base 2 exponent by 1 - * - * ***CAUTION*** - * - * This sequence of operations is critical and it may - * be horribly defeated by some compiler optimizers. - */ - z = y * LOG2EA; - z += x * LOG2EA; - z += y; - z += x; - z += e; - return z; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double log2l(long double x) -{ - return log2(x); -} -#endif diff --git a/usr/lib/libc/math/logb.c b/usr/lib/libc/math/logb.c deleted file mode 100644 index 7f8bdfae1..000000000 --- a/usr/lib/libc/math/logb.c +++ /dev/null @@ -1,17 +0,0 @@ -#include - -/* -special cases: - logb(+-0) = -inf, and raise divbyzero - logb(+-inf) = +inf - logb(nan) = nan -*/ - -double logb(double x) -{ - if (!isfinite(x)) - return x * x; - if (x == 0) - return -1/(x*x); - return ilogb(x); -} diff --git a/usr/lib/libc/math/logbf.c b/usr/lib/libc/math/logbf.c deleted file mode 100644 index a0a0b5ed5..000000000 --- a/usr/lib/libc/math/logbf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -float logbf(float x) -{ - if (!isfinite(x)) - return x * x; - if (x == 0) - return -1/(x*x); - return ilogbf(x); -} diff --git a/usr/lib/libc/math/logbl.c b/usr/lib/libc/math/logbl.c deleted file mode 100644 index 962973a7b..000000000 --- a/usr/lib/libc/math/logbl.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double logbl(long double x) -{ - return logb(x); -} -#else -long double logbl(long double x) -{ - if (!isfinite(x)) - return x * x; - if (x == 0) - return -1/(x*x); - return ilogbl(x); -} -#endif diff --git a/usr/lib/libc/math/logf.c b/usr/lib/libc/math/logf.c deleted file mode 100644 index 52230a1bd..000000000 --- a/usr/lib/libc/math/logf.c +++ /dev/null @@ -1,69 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_logf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include -#include - -static const float -ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ -ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ -/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ -Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ -Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ -Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ -Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ - -float logf(float x) -{ - union {float f; uint32_t i;} u = {x}; - float_t hfsq,f,s,z,R,w,t1,t2,dk; - uint32_t ix; - int k; - - ix = u.i; - k = 0; - if (ix < 0x00800000 || ix>>31) { /* x < 2**-126 */ - if (ix<<1 == 0) - return -1/(x*x); /* log(+-0)=-inf */ - if (ix>>31) - return (x-x)/0.0f; /* log(-#) = NaN */ - /* subnormal number, scale up x */ - k -= 25; - x *= 0x1p25f; - u.f = x; - ix = u.i; - } else if (ix >= 0x7f800000) { - return x; - } else if (ix == 0x3f800000) - return 0; - - /* reduce x into [sqrt(2)/2, sqrt(2)] */ - ix += 0x3f800000 - 0x3f3504f3; - k += (int)(ix>>23) - 0x7f; - ix = (ix&0x007fffff) + 0x3f3504f3; - u.i = ix; - x = u.f; - - f = x - 1.0f; - s = f/(2.0f + f); - z = s*s; - w = z*z; - t1= w*(Lg2+w*Lg4); - t2= z*(Lg1+w*Lg3); - R = t2 + t1; - hfsq = 0.5f*f*f; - dk = k; - return s*(hfsq+R) + dk*ln2_lo - hfsq + f + dk*ln2_hi; -} diff --git a/usr/lib/libc/math/logl.c b/usr/lib/libc/math/logl.c deleted file mode 100644 index 5d5365929..000000000 --- a/usr/lib/libc/math/logl.c +++ /dev/null @@ -1,175 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_logl.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Natural logarithm, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, logl(); - * - * y = logl( x ); - * - * - * DESCRIPTION: - * - * Returns the base e (2.718...) logarithm of x. - * - * The argument is separated into its exponent and fractional - * parts. If the exponent is between -1 and +1, the logarithm - * of the fraction is approximated by - * - * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). - * - * Otherwise, setting z = 2(x-1)/(x+1), - * - * log(x) = log(1+z/2) - log(1-z/2) = z + z**3 P(z)/Q(z). - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE 0.5, 2.0 150000 8.71e-20 2.75e-20 - * IEEE exp(+-10000) 100000 5.39e-20 2.34e-20 - * - * In the tests over the interval exp(+-10000), the logarithms - * of the random arguments were uniformly distributed over - * [-10000, +10000]. - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double logl(long double x) -{ - return log(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 2.32e-20 - */ -static const long double P[] = { - 4.5270000862445199635215E-5L, - 4.9854102823193375972212E-1L, - 6.5787325942061044846969E0L, - 2.9911919328553073277375E1L, - 6.0949667980987787057556E1L, - 5.7112963590585538103336E1L, - 2.0039553499201281259648E1L, -}; -static const long double Q[] = { -/* 1.0000000000000000000000E0,*/ - 1.5062909083469192043167E1L, - 8.3047565967967209469434E1L, - 2.2176239823732856465394E2L, - 3.0909872225312059774938E2L, - 2.1642788614495947685003E2L, - 6.0118660497603843919306E1L, -}; - -/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), - * where z = 2(x-1)/(x+1) - * 1/sqrt(2) <= x < sqrt(2) - * Theoretical peak relative error = 6.16e-22 - */ -static const long double R[4] = { - 1.9757429581415468984296E-3L, --7.1990767473014147232598E-1L, - 1.0777257190312272158094E1L, --3.5717684488096787370998E1L, -}; -static const long double S[4] = { -/* 1.00000000000000000000E0L,*/ --2.6201045551331104417768E1L, - 1.9361891836232102174846E2L, --4.2861221385716144629696E2L, -}; -static const long double C1 = 6.9314575195312500000000E-1L; -static const long double C2 = 1.4286068203094172321215E-6L; - -#define SQRTH 0.70710678118654752440L - -long double logl(long double x) -{ - long double y, z; - int e; - - if (isnan(x)) - return x; - if (x == INFINITY) - return x; - if (x <= 0.0) { - if (x == 0.0) - return -1/(x*x); /* -inf with divbyzero */ - return 0/0.0f; /* nan with invalid */ - } - - /* separate mantissa from exponent */ - /* Note, frexp is used so that denormal numbers - * will be handled properly. - */ - x = frexpl(x, &e); - - /* logarithm using log(x) = z + z**3 P(z)/Q(z), - * where z = 2(x-1)/(x+1) - */ - if (e > 2 || e < -2) { - if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ - e -= 1; - z = x - 0.5; - y = 0.5 * z + 0.5; - } else { /* 2 (x-1)/(x+1) */ - z = x - 0.5; - z -= 0.5; - y = 0.5 * x + 0.5; - } - x = z / y; - z = x*x; - z = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); - z = z + e * C2; - z = z + x; - z = z + e * C1; - return z; - } - - /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ - if (x < SQRTH) { - e -= 1; - x = 2.0*x - 1.0; - } else { - x = x - 1.0; - } - z = x*x; - y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 6)); - y = y + e * C2; - z = y - 0.5*z; - /* Note, the sum of above terms does not exceed x/4, - * so it contributes at most about 1/4 lsb to the error. - */ - z = z + x; - z = z + e * C1; /* This sum has an error of 1/2 lsb. */ - return z; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double logl(long double x) -{ - return log(x); -} -#endif diff --git a/usr/lib/libc/math/lrint.c b/usr/lib/libc/math/lrint.c deleted file mode 100644 index bdca8b7cb..000000000 --- a/usr/lib/libc/math/lrint.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include "libm.h" - -/* -If the result cannot be represented (overflow, nan), then -lrint raises the invalid exception. - -Otherwise if the input was not an integer then the inexact -exception is raised. - -C99 is a bit vague about whether inexact exception is -allowed to be raised when invalid is raised. -(F.9 explicitly allows spurious inexact exceptions, F.9.6.5 -does not make it clear if that rule applies to lrint, but -IEEE 754r 7.8 seems to forbid spurious inexact exception in -the ineger conversion functions) - -So we try to make sure that no spurious inexact exception is -raised in case of an overflow. - -If the bit size of long > precision of double, then there -cannot be inexact rounding in case the result overflows, -otherwise LONG_MAX and LONG_MIN can be represented exactly -as a double. -*/ - -#if LONG_MAX < 1U<<53 && defined(FE_INEXACT) -long lrint(double x) -{ - #pragma STDC FENV_ACCESS ON - int e; - - e = fetestexcept(FE_INEXACT); - x = rint(x); - if (!e && (x > LONG_MAX || x < LONG_MIN)) - feclearexcept(FE_INEXACT); - /* conversion */ - return x; -} -#else -long lrint(double x) -{ - return rint(x); -} -#endif diff --git a/usr/lib/libc/math/lrintf.c b/usr/lib/libc/math/lrintf.c deleted file mode 100644 index ca0b6a46a..000000000 --- a/usr/lib/libc/math/lrintf.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -/* uses LONG_MAX > 2^24, see comments in lrint.c */ - -long lrintf(float x) -{ - return rintf(x); -} diff --git a/usr/lib/libc/math/lrintl.c b/usr/lib/libc/math/lrintl.c deleted file mode 100644 index b2a8106d7..000000000 --- a/usr/lib/libc/math/lrintl.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include "libm.h" - - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long lrintl(long double x) -{ - return lrint(x); -} -#elif defined(FE_INEXACT) -/* -see comments in lrint.c - -Note that if LONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64 -then x == 2**63 - 0.5 is the only input that overflows and -raises inexact (with tonearest or upward rounding mode) -*/ -long lrintl(long double x) -{ - #pragma STDC FENV_ACCESS ON - int e; - - e = fetestexcept(FE_INEXACT); - x = rintl(x); - if (!e && (x > LONG_MAX || x < LONG_MIN)) - feclearexcept(FE_INEXACT); - /* conversion */ - return x; -} -#else -long lrintl(long double x) -{ - return rintl(x); -} -#endif diff --git a/usr/lib/libc/math/lround.c b/usr/lib/libc/math/lround.c deleted file mode 100644 index b8b795470..000000000 --- a/usr/lib/libc/math/lround.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long lround(double x) -{ - return round(x); -} diff --git a/usr/lib/libc/math/lroundf.c b/usr/lib/libc/math/lroundf.c deleted file mode 100644 index c4707e7db..000000000 --- a/usr/lib/libc/math/lroundf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long lroundf(float x) -{ - return roundf(x); -} diff --git a/usr/lib/libc/math/lroundl.c b/usr/lib/libc/math/lroundl.c deleted file mode 100644 index 094fdf648..000000000 --- a/usr/lib/libc/math/lroundl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long lroundl(long double x) -{ - return roundl(x); -} diff --git a/usr/lib/libc/math/modf.c b/usr/lib/libc/math/modf.c deleted file mode 100644 index 1c8a1db90..000000000 --- a/usr/lib/libc/math/modf.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libm.h" - -double modf(double x, double *iptr) -{ - union {double f; uint64_t i;} u = {x}; - uint64_t mask; - int e = (int)(u.i>>52 & 0x7ff) - 0x3ff; - - /* no fractional part */ - if (e >= 52) { - *iptr = x; - if (e == 0x400 && u.i<<12 != 0) /* nan */ - return x; - u.i &= 1ULL<<63; - return u.f; - } - - /* no integral part*/ - if (e < 0) { - u.i &= 1ULL<<63; - *iptr = u.f; - return x; - } - - mask = -1ULL>>12>>e; - if ((u.i & mask) == 0) { - *iptr = x; - u.i &= 1ULL<<63; - return u.f; - } - u.i &= ~mask; - *iptr = u.f; - return x - u.f; -} diff --git a/usr/lib/libc/math/modff.c b/usr/lib/libc/math/modff.c deleted file mode 100644 index 639514eff..000000000 --- a/usr/lib/libc/math/modff.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libm.h" - -float modff(float x, float *iptr) -{ - union {float f; uint32_t i;} u = {x}; - uint32_t mask; - int e = (int)(u.i>>23 & 0xff) - 0x7f; - - /* no fractional part */ - if (e >= 23) { - *iptr = x; - if (e == 0x80 && u.i<<9 != 0) { /* nan */ - return x; - } - u.i &= 0x80000000; - return u.f; - } - /* no integral part */ - if (e < 0) { - u.i &= 0x80000000; - *iptr = u.f; - return x; - } - - mask = 0x007fffff>>e; - if ((u.i & mask) == 0) { - *iptr = x; - u.i &= 0x80000000; - return u.f; - } - u.i &= ~mask; - *iptr = u.f; - return x - u.f; -} diff --git a/usr/lib/libc/math/modfl.c b/usr/lib/libc/math/modfl.c deleted file mode 100644 index a47b1924f..000000000 --- a/usr/lib/libc/math/modfl.c +++ /dev/null @@ -1,53 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double modfl(long double x, long double *iptr) -{ - double d; - long double r; - - r = modf(x, &d); - *iptr = d; - return r; -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -static const long double toint = 1/LDBL_EPSILON; - -long double modfl(long double x, long double *iptr) -{ - union ldshape u = {x}; - int e = (u.i.se & 0x7fff) - 0x3fff; - int s = u.i.se >> 15; - long double absx; - long double y; - - /* no fractional part */ - if (e >= LDBL_MANT_DIG-1) { - *iptr = x; - if (isnan(x)) - return x; - return s ? -0.0 : 0.0; - } - - /* no integral part*/ - if (e < 0) { - *iptr = s ? -0.0 : 0.0; - return x; - } - - /* raises spurious inexact */ - absx = s ? -x : x; - y = absx + toint - toint - absx; - if (y == 0) { - *iptr = x; - return s ? -0.0 : 0.0; - } - if (y > 0) - y -= 1; - if (s) - y = -y; - *iptr = x + y; - return -y; -} -#endif diff --git a/usr/lib/libc/math/nan.c b/usr/lib/libc/math/nan.c deleted file mode 100644 index 9e0826c77..000000000 --- a/usr/lib/libc/math/nan.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double nan(const char *s) -{ - return NAN; -} diff --git a/usr/lib/libc/math/nanf.c b/usr/lib/libc/math/nanf.c deleted file mode 100644 index 752ce5463..000000000 --- a/usr/lib/libc/math/nanf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -float nanf(const char *s) -{ - return NAN; -} diff --git a/usr/lib/libc/math/nanl.c b/usr/lib/libc/math/nanl.c deleted file mode 100644 index 969af5641..000000000 --- a/usr/lib/libc/math/nanl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long double nanl(const char *s) -{ - return NAN; -} diff --git a/usr/lib/libc/math/nearbyint.c b/usr/lib/libc/math/nearbyint.c deleted file mode 100644 index f4e8aac4f..000000000 --- a/usr/lib/libc/math/nearbyint.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -/* nearbyint is the same as rint, but it must not raise the inexact exception */ - -double nearbyint(double x) -{ -#ifdef FE_INEXACT - #pragma STDC FENV_ACCESS ON - int e; - - e = fetestexcept(FE_INEXACT); -#endif - x = rint(x); -#ifdef FE_INEXACT - if (!e) - feclearexcept(FE_INEXACT); -#endif - return x; -} diff --git a/usr/lib/libc/math/nearbyintf.c b/usr/lib/libc/math/nearbyintf.c deleted file mode 100644 index 092e9ffae..000000000 --- a/usr/lib/libc/math/nearbyintf.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -float nearbyintf(float x) -{ -#ifdef FE_INEXACT - #pragma STDC FENV_ACCESS ON - int e; - - e = fetestexcept(FE_INEXACT); -#endif - x = rintf(x); -#ifdef FE_INEXACT - if (!e) - feclearexcept(FE_INEXACT); -#endif - return x; -} diff --git a/usr/lib/libc/math/nearbyintl.c b/usr/lib/libc/math/nearbyintl.c deleted file mode 100644 index 82852492f..000000000 --- a/usr/lib/libc/math/nearbyintl.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double nearbyintl(long double x) -{ - return nearbyint(x); -} -#else -#include -long double nearbyintl(long double x) -{ -#ifdef FE_INEXACT - #pragma STDC FENV_ACCESS ON - int e; - - e = fetestexcept(FE_INEXACT); -#endif - x = rintl(x); -#ifdef FE_INEXACT - if (!e) - feclearexcept(FE_INEXACT); -#endif - return x; -} -#endif diff --git a/usr/lib/libc/math/nextafter.c b/usr/lib/libc/math/nextafter.c deleted file mode 100644 index ab5795a47..000000000 --- a/usr/lib/libc/math/nextafter.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "libm.h" - -double nextafter(double x, double y) -{ - union {double f; uint64_t i;} ux={x}, uy={y}; - uint64_t ax, ay; - int e; - - if (isnan(x) || isnan(y)) - return x + y; - if (ux.i == uy.i) - return y; - ax = ux.i & -1ULL/2; - ay = uy.i & -1ULL/2; - if (ax == 0) { - if (ay == 0) - return y; - ux.i = (uy.i & 1ULL<<63) | 1; - } else if (ax > ay || ((ux.i ^ uy.i) & 1ULL<<63)) - ux.i--; - else - ux.i++; - e = ux.i >> 52 & 0x7ff; - /* raise overflow if ux.f is infinite and x is finite */ - if (e == 0x7ff) - FORCE_EVAL(x+x); - /* raise underflow if ux.f is subnormal or zero */ - if (e == 0) - FORCE_EVAL(x*x + ux.f*ux.f); - return ux.f; -} diff --git a/usr/lib/libc/math/nextafterf.c b/usr/lib/libc/math/nextafterf.c deleted file mode 100644 index 75a09f7d1..000000000 --- a/usr/lib/libc/math/nextafterf.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "libm.h" - -float nextafterf(float x, float y) -{ - union {float f; uint32_t i;} ux={x}, uy={y}; - uint32_t ax, ay, e; - - if (isnan(x) || isnan(y)) - return x + y; - if (ux.i == uy.i) - return y; - ax = ux.i & 0x7fffffff; - ay = uy.i & 0x7fffffff; - if (ax == 0) { - if (ay == 0) - return y; - ux.i = (uy.i & 0x80000000) | 1; - } else if (ax > ay || ((ux.i ^ uy.i) & 0x80000000)) - ux.i--; - else - ux.i++; - e = ux.i & 0x7f800000; - /* raise overflow if ux.f is infinite and x is finite */ - if (e == 0x7f800000) - FORCE_EVAL(x+x); - /* raise underflow if ux.f is subnormal or zero */ - if (e == 0) - FORCE_EVAL(x*x + ux.f*ux.f); - return ux.f; -} diff --git a/usr/lib/libc/math/nextafterl.c b/usr/lib/libc/math/nextafterl.c deleted file mode 100644 index 37e858fb4..000000000 --- a/usr/lib/libc/math/nextafterl.c +++ /dev/null @@ -1,75 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double nextafterl(long double x, long double y) -{ - return nextafter(x, y); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -long double nextafterl(long double x, long double y) -{ - union ldshape ux, uy; - - if (isnan(x) || isnan(y)) - return x + y; - if (x == y) - return y; - ux.f = x; - if (x == 0) { - uy.f = y; - ux.i.m = 1; - ux.i.se = uy.i.se & 0x8000; - } else if ((x < y) == !(ux.i.se & 0x8000)) { - ux.i.m++; - if (ux.i.m << 1 == 0) { - ux.i.m = 1ULL << 63; - ux.i.se++; - } - } else { - if (ux.i.m << 1 == 0) { - ux.i.se--; - if (ux.i.se) - ux.i.m = 0; - } - ux.i.m--; - } - /* raise overflow if ux is infinite and x is finite */ - if ((ux.i.se & 0x7fff) == 0x7fff) - return x + x; - /* raise underflow if ux is subnormal or zero */ - if ((ux.i.se & 0x7fff) == 0) - FORCE_EVAL(x*x + ux.f*ux.f); - return ux.f; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -long double nextafterl(long double x, long double y) -{ - union ldshape ux, uy; - - if (isnan(x) || isnan(y)) - return x + y; - if (x == y) - return y; - ux.f = x; - if (x == 0) { - uy.f = y; - ux.i.lo = 1; - ux.i.se = uy.i.se & 0x8000; - } else if ((x < y) == !(ux.i.se & 0x8000)) { - ux.i2.lo++; - if (ux.i2.lo == 0) - ux.i2.hi++; - } else { - if (ux.i2.lo == 0) - ux.i2.hi--; - ux.i2.lo--; - } - /* raise overflow if ux is infinite and x is finite */ - if ((ux.i.se & 0x7fff) == 0x7fff) - return x + x; - /* raise underflow if ux is subnormal or zero */ - if ((ux.i.se & 0x7fff) == 0) - FORCE_EVAL(x*x + ux.f*ux.f); - return ux.f; -} -#endif diff --git a/usr/lib/libc/math/nexttoward.c b/usr/lib/libc/math/nexttoward.c deleted file mode 100644 index 827ee5c3c..000000000 --- a/usr/lib/libc/math/nexttoward.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -double nexttoward(double x, long double y) -{ - return nextafter(x, y); -} -#else -double nexttoward(double x, long double y) -{ - union {double f; uint64_t i;} ux = {x}; - int e; - - if (isnan(x) || isnan(y)) - return x + y; - if (x == y) - return y; - if (x == 0) { - ux.i = 1; - if (signbit(y)) - ux.i |= 1ULL<<63; - } else if (x < y) { - if (signbit(x)) - ux.i--; - else - ux.i++; - } else { - if (signbit(x)) - ux.i++; - else - ux.i--; - } - e = ux.i>>52 & 0x7ff; - /* raise overflow if ux.f is infinite and x is finite */ - if (e == 0x7ff) - FORCE_EVAL(x+x); - /* raise underflow if ux.f is subnormal or zero */ - if (e == 0) - FORCE_EVAL(x*x + ux.f*ux.f); - return ux.f; -} -#endif diff --git a/usr/lib/libc/math/nexttowardf.c b/usr/lib/libc/math/nexttowardf.c deleted file mode 100644 index bbf172f9e..000000000 --- a/usr/lib/libc/math/nexttowardf.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "libm.h" - -float nexttowardf(float x, long double y) -{ - union {float f; uint32_t i;} ux = {x}; - uint32_t e; - - if (isnan(x) || isnan(y)) - return x + y; - if (x == y) - return y; - if (x == 0) { - ux.i = 1; - if (signbit(y)) - ux.i |= 0x80000000; - } else if (x < y) { - if (signbit(x)) - ux.i--; - else - ux.i++; - } else { - if (signbit(x)) - ux.i++; - else - ux.i--; - } - e = ux.i & 0x7f800000; - /* raise overflow if ux.f is infinite and x is finite */ - if (e == 0x7f800000) - FORCE_EVAL(x+x); - /* raise underflow if ux.f is subnormal or zero */ - if (e == 0) - FORCE_EVAL(x*x + ux.f*ux.f); - return ux.f; -} diff --git a/usr/lib/libc/math/nexttowardl.c b/usr/lib/libc/math/nexttowardl.c deleted file mode 100644 index 67a634039..000000000 --- a/usr/lib/libc/math/nexttowardl.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -long double nexttowardl(long double x, long double y) -{ - return nextafterl(x, y); -} diff --git a/usr/lib/libc/math/pow.c b/usr/lib/libc/math/pow.c deleted file mode 100644 index 3ddc1b6ff..000000000 --- a/usr/lib/libc/math/pow.c +++ /dev/null @@ -1,328 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_pow.c */ -/* - * ==================================================== - * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. - * - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* pow(x,y) return x**y - * - * n - * Method: Let x = 2 * (1+f) - * 1. Compute and return log2(x) in two pieces: - * log2(x) = w1 + w2, - * where w1 has 53-24 = 29 bit trailing zeros. - * 2. Perform y*log2(x) = n+y' by simulating muti-precision - * arithmetic, where |y'|<=0.5. - * 3. Return x**y = 2**n*exp(y'*log2) - * - * Special cases: - * 1. (anything) ** 0 is 1 - * 2. 1 ** (anything) is 1 - * 3. (anything except 1) ** NAN is NAN - * 4. NAN ** (anything except 0) is NAN - * 5. +-(|x| > 1) ** +INF is +INF - * 6. +-(|x| > 1) ** -INF is +0 - * 7. +-(|x| < 1) ** +INF is +0 - * 8. +-(|x| < 1) ** -INF is +INF - * 9. -1 ** +-INF is 1 - * 10. +0 ** (+anything except 0, NAN) is +0 - * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 - * 12. +0 ** (-anything except 0, NAN) is +INF, raise divbyzero - * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF, raise divbyzero - * 14. -0 ** (+odd integer) is -0 - * 15. -0 ** (-odd integer) is -INF, raise divbyzero - * 16. +INF ** (+anything except 0,NAN) is +INF - * 17. +INF ** (-anything except 0,NAN) is +0 - * 18. -INF ** (+odd integer) is -INF - * 19. -INF ** (anything) = -0 ** (-anything), (anything except odd integer) - * 20. (anything) ** 1 is (anything) - * 21. (anything) ** -1 is 1/(anything) - * 22. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) - * 23. (-anything except 0 and inf) ** (non-integer) is NAN - * - * Accuracy: - * pow(x,y) returns x**y nearly rounded. In particular - * pow(integer,integer) - * always returns the correct integer provided it is - * representable. - * - * Constants : - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "libm.h" - -static const double -bp[] = {1.0, 1.5,}, -dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */ -dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */ -two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ -huge = 1.0e300, -tiny = 1.0e-300, -/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ -L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ -L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ -L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ -L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ -L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ -L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ -lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ -lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ -lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ -ovt = 8.0085662595372944372e-017, /* -(1024-log2(ovfl+.5ulp)) */ -cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ -cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ -cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ -ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ -ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ -ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ - -double pow(double x, double y) -{ - double z,ax,z_h,z_l,p_h,p_l; - double y1,t1,t2,r,s,t,u,v,w; - int32_t i,j,k,yisint,n; - int32_t hx,hy,ix,iy; - uint32_t lx,ly; - - EXTRACT_WORDS(hx, lx, x); - EXTRACT_WORDS(hy, ly, y); - ix = hx & 0x7fffffff; - iy = hy & 0x7fffffff; - - /* x**0 = 1, even if x is NaN */ - if ((iy|ly) == 0) - return 1.0; - /* 1**y = 1, even if y is NaN */ - if (hx == 0x3ff00000 && lx == 0) - return 1.0; - /* NaN if either arg is NaN */ - if (ix > 0x7ff00000 || (ix == 0x7ff00000 && lx != 0) || - iy > 0x7ff00000 || (iy == 0x7ff00000 && ly != 0)) - return x + y; - - /* determine if y is an odd int when x < 0 - * yisint = 0 ... y is not an integer - * yisint = 1 ... y is an odd int - * yisint = 2 ... y is an even int - */ - yisint = 0; - if (hx < 0) { - if (iy >= 0x43400000) - yisint = 2; /* even integer y */ - else if (iy >= 0x3ff00000) { - k = (iy>>20) - 0x3ff; /* exponent */ - if (k > 20) { - uint32_t j = ly>>(52-k); - if ((j<<(52-k)) == ly) - yisint = 2 - (j&1); - } else if (ly == 0) { - uint32_t j = iy>>(20-k); - if ((j<<(20-k)) == iy) - yisint = 2 - (j&1); - } - } - } - - /* special value of y */ - if (ly == 0) { - if (iy == 0x7ff00000) { /* y is +-inf */ - if (((ix-0x3ff00000)|lx) == 0) /* (-1)**+-inf is 1 */ - return 1.0; - else if (ix >= 0x3ff00000) /* (|x|>1)**+-inf = inf,0 */ - return hy >= 0 ? y : 0.0; - else /* (|x|<1)**+-inf = 0,inf */ - return hy >= 0 ? 0.0 : -y; - } - if (iy == 0x3ff00000) { /* y is +-1 */ - if (hy >= 0) - return x; - y = 1/x; -#if FLT_EVAL_METHOD!=0 - { - union {double f; uint64_t i;} u = {y}; - uint64_t i = u.i & -1ULL/2; - if (i>>52 == 0 && (i&(i-1))) - FORCE_EVAL((float)y); - } -#endif - return y; - } - if (hy == 0x40000000) /* y is 2 */ - return x*x; - if (hy == 0x3fe00000) { /* y is 0.5 */ - if (hx >= 0) /* x >= +0 */ - return sqrt(x); - } - } - - ax = fabs(x); - /* special value of x */ - if (lx == 0) { - if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) { /* x is +-0,+-inf,+-1 */ - z = ax; - if (hy < 0) /* z = (1/|x|) */ - z = 1.0/z; - if (hx < 0) { - if (((ix-0x3ff00000)|yisint) == 0) { - z = (z-z)/(z-z); /* (-1)**non-int is NaN */ - } else if (yisint == 1) - z = -z; /* (x<0)**odd = -(|x|**odd) */ - } - return z; - } - } - - s = 1.0; /* sign of result */ - if (hx < 0) { - if (yisint == 0) /* (x<0)**(non-int) is NaN */ - return (x-x)/(x-x); - if (yisint == 1) /* (x<0)**(odd int) */ - s = -1.0; - } - - /* |y| is huge */ - if (iy > 0x41e00000) { /* if |y| > 2**31 */ - if (iy > 0x43f00000) { /* if |y| > 2**64, must o/uflow */ - if (ix <= 0x3fefffff) - return hy < 0 ? huge*huge : tiny*tiny; - if (ix >= 0x3ff00000) - return hy > 0 ? huge*huge : tiny*tiny; - } - /* over/underflow if x is not close to one */ - if (ix < 0x3fefffff) - return hy < 0 ? s*huge*huge : s*tiny*tiny; - if (ix > 0x3ff00000) - return hy > 0 ? s*huge*huge : s*tiny*tiny; - /* now |1-x| is tiny <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ - t = ax - 1.0; /* t has 20 trailing zeros */ - w = (t*t)*(0.5 - t*(0.3333333333333333333333-t*0.25)); - u = ivln2_h*t; /* ivln2_h has 21 sig. bits */ - v = t*ivln2_l - w*ivln2; - t1 = u + v; - SET_LOW_WORD(t1, 0); - t2 = v - (t1-u); - } else { - double ss,s2,s_h,s_l,t_h,t_l; - n = 0; - /* take care subnormal number */ - if (ix < 0x00100000) { - ax *= two53; - n -= 53; - GET_HIGH_WORD(ix,ax); - } - n += ((ix)>>20) - 0x3ff; - j = ix & 0x000fffff; - /* determine interval */ - ix = j | 0x3ff00000; /* normalize ix */ - if (j <= 0x3988E) /* |x|>1)|0x20000000) + 0x00080000 + (k<<18)); - t_l = ax - (t_h-bp[k]); - s_l = v*((u-s_h*t_h)-s_h*t_l); - /* compute log(ax) */ - s2 = ss*ss; - r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); - r += s_l*(s_h+ss); - s2 = s_h*s_h; - t_h = 3.0 + s2 + r; - SET_LOW_WORD(t_h, 0); - t_l = r - ((t_h-3.0)-s2); - /* u+v = ss*(1+...) */ - u = s_h*t_h; - v = s_l*t_h + t_l*ss; - /* 2/(3log2)*(ss+...) */ - p_h = u + v; - SET_LOW_WORD(p_h, 0); - p_l = v - (p_h-u); - z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ - z_l = cp_l*p_h+p_l*cp + dp_l[k]; - /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */ - t = (double)n; - t1 = ((z_h + z_l) + dp_h[k]) + t; - SET_LOW_WORD(t1, 0); - t2 = z_l - (((t1 - t) - dp_h[k]) - z_h); - } - - /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ - y1 = y; - SET_LOW_WORD(y1, 0); - p_l = (y-y1)*t1 + y*t2; - p_h = y1*t1; - z = p_l + p_h; - EXTRACT_WORDS(j, i, z); - if (j >= 0x40900000) { /* z >= 1024 */ - if (((j-0x40900000)|i) != 0) /* if z > 1024 */ - return s*huge*huge; /* overflow */ - if (p_l + ovt > z - p_h) - return s*huge*huge; /* overflow */ - } else if ((j&0x7fffffff) >= 0x4090cc00) { /* z <= -1075 */ // FIXME: instead of abs(j) use unsigned j - if (((j-0xc090cc00)|i) != 0) /* z < -1075 */ - return s*tiny*tiny; /* underflow */ - if (p_l <= z - p_h) - return s*tiny*tiny; /* underflow */ - } - /* - * compute 2**(p_h+p_l) - */ - i = j & 0x7fffffff; - k = (i>>20) - 0x3ff; - n = 0; - if (i > 0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ - n = j + (0x00100000>>(k+1)); - k = ((n&0x7fffffff)>>20) - 0x3ff; /* new k for n */ - t = 0.0; - SET_HIGH_WORD(t, n & ~(0x000fffff>>k)); - n = ((n&0x000fffff)|0x00100000)>>(20-k); - if (j < 0) - n = -n; - p_h -= t; - } - t = p_l + p_h; - SET_LOW_WORD(t, 0); - u = t*lg2_h; - v = (p_l-(t-p_h))*lg2 + t*lg2_l; - z = u + v; - w = v - (z-u); - t = z*z; - t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - r = (z*t1)/(t1-2.0) - (w + z*w); - z = 1.0 - (r-z); - GET_HIGH_WORD(j, z); - j += n<<20; - if ((j>>20) <= 0) /* subnormal output */ - z = scalbn(z,n); - else - SET_HIGH_WORD(z, j); - return s*z; -} diff --git a/usr/lib/libc/math/powf.c b/usr/lib/libc/math/powf.c deleted file mode 100644 index 427c8965b..000000000 --- a/usr/lib/libc/math/powf.c +++ /dev/null @@ -1,259 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_powf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float -bp[] = {1.0, 1.5,}, -dp_h[] = { 0.0, 5.84960938e-01,}, /* 0x3f15c000 */ -dp_l[] = { 0.0, 1.56322085e-06,}, /* 0x35d1cfdc */ -two24 = 16777216.0, /* 0x4b800000 */ -huge = 1.0e30, -tiny = 1.0e-30, -/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ -L1 = 6.0000002384e-01, /* 0x3f19999a */ -L2 = 4.2857143283e-01, /* 0x3edb6db7 */ -L3 = 3.3333334327e-01, /* 0x3eaaaaab */ -L4 = 2.7272811532e-01, /* 0x3e8ba305 */ -L5 = 2.3066075146e-01, /* 0x3e6c3255 */ -L6 = 2.0697501302e-01, /* 0x3e53f142 */ -P1 = 1.6666667163e-01, /* 0x3e2aaaab */ -P2 = -2.7777778450e-03, /* 0xbb360b61 */ -P3 = 6.6137559770e-05, /* 0x388ab355 */ -P4 = -1.6533901999e-06, /* 0xb5ddea0e */ -P5 = 4.1381369442e-08, /* 0x3331bb4c */ -lg2 = 6.9314718246e-01, /* 0x3f317218 */ -lg2_h = 6.93145752e-01, /* 0x3f317200 */ -lg2_l = 1.42860654e-06, /* 0x35bfbe8c */ -ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */ -cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */ -cp_h = 9.6191406250e-01, /* 0x3f764000 =12b cp */ -cp_l = -1.1736857402e-04, /* 0xb8f623c6 =tail of cp_h */ -ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */ -ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/ -ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ - -float powf(float x, float y) -{ - float z,ax,z_h,z_l,p_h,p_l; - float y1,t1,t2,r,s,sn,t,u,v,w; - int32_t i,j,k,yisint,n; - int32_t hx,hy,ix,iy,is; - - GET_FLOAT_WORD(hx, x); - GET_FLOAT_WORD(hy, y); - ix = hx & 0x7fffffff; - iy = hy & 0x7fffffff; - - /* x**0 = 1, even if x is NaN */ - if (iy == 0) - return 1.0f; - /* 1**y = 1, even if y is NaN */ - if (hx == 0x3f800000) - return 1.0f; - /* NaN if either arg is NaN */ - if (ix > 0x7f800000 || iy > 0x7f800000) - return x + y; - - /* determine if y is an odd int when x < 0 - * yisint = 0 ... y is not an integer - * yisint = 1 ... y is an odd int - * yisint = 2 ... y is an even int - */ - yisint = 0; - if (hx < 0) { - if (iy >= 0x4b800000) - yisint = 2; /* even integer y */ - else if (iy >= 0x3f800000) { - k = (iy>>23) - 0x7f; /* exponent */ - j = iy>>(23-k); - if ((j<<(23-k)) == iy) - yisint = 2 - (j & 1); - } - } - - /* special value of y */ - if (iy == 0x7f800000) { /* y is +-inf */ - if (ix == 0x3f800000) /* (-1)**+-inf is 1 */ - return 1.0f; - else if (ix > 0x3f800000) /* (|x|>1)**+-inf = inf,0 */ - return hy >= 0 ? y : 0.0f; - else /* (|x|<1)**+-inf = 0,inf */ - return hy >= 0 ? 0.0f: -y; - } - if (iy == 0x3f800000) /* y is +-1 */ - return hy >= 0 ? x : 1.0f/x; - if (hy == 0x40000000) /* y is 2 */ - return x*x; - if (hy == 0x3f000000) { /* y is 0.5 */ - if (hx >= 0) /* x >= +0 */ - return sqrtf(x); - } - - ax = fabsf(x); - /* special value of x */ - if (ix == 0x7f800000 || ix == 0 || ix == 0x3f800000) { /* x is +-0,+-inf,+-1 */ - z = ax; - if (hy < 0) /* z = (1/|x|) */ - z = 1.0f/z; - if (hx < 0) { - if (((ix-0x3f800000)|yisint) == 0) { - z = (z-z)/(z-z); /* (-1)**non-int is NaN */ - } else if (yisint == 1) - z = -z; /* (x<0)**odd = -(|x|**odd) */ - } - return z; - } - - sn = 1.0f; /* sign of result */ - if (hx < 0) { - if (yisint == 0) /* (x<0)**(non-int) is NaN */ - return (x-x)/(x-x); - if (yisint == 1) /* (x<0)**(odd int) */ - sn = -1.0f; - } - - /* |y| is huge */ - if (iy > 0x4d000000) { /* if |y| > 2**27 */ - /* over/underflow if x is not close to one */ - if (ix < 0x3f7ffff8) - return hy < 0 ? sn*huge*huge : sn*tiny*tiny; - if (ix > 0x3f800007) - return hy > 0 ? sn*huge*huge : sn*tiny*tiny; - /* now |1-x| is tiny <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ - t = ax - 1; /* t has 20 trailing zeros */ - w = (t*t)*(0.5f - t*(0.333333333333f - t*0.25f)); - u = ivln2_h*t; /* ivln2_h has 16 sig. bits */ - v = t*ivln2_l - w*ivln2; - t1 = u + v; - GET_FLOAT_WORD(is, t1); - SET_FLOAT_WORD(t1, is & 0xfffff000); - t2 = v - (t1-u); - } else { - float s2,s_h,s_l,t_h,t_l; - n = 0; - /* take care subnormal number */ - if (ix < 0x00800000) { - ax *= two24; - n -= 24; - GET_FLOAT_WORD(ix, ax); - } - n += ((ix)>>23) - 0x7f; - j = ix & 0x007fffff; - /* determine interval */ - ix = j | 0x3f800000; /* normalize ix */ - if (j <= 0x1cc471) /* |x|>1) & 0xfffff000) | 0x20000000; - SET_FLOAT_WORD(t_h, is + 0x00400000 + (k<<21)); - t_l = ax - (t_h - bp[k]); - s_l = v*((u - s_h*t_h) - s_h*t_l); - /* compute log(ax) */ - s2 = s*s; - r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); - r += s_l*(s_h+s); - s2 = s_h*s_h; - t_h = 3.0f + s2 + r; - GET_FLOAT_WORD(is, t_h); - SET_FLOAT_WORD(t_h, is & 0xfffff000); - t_l = r - ((t_h - 3.0f) - s2); - /* u+v = s*(1+...) */ - u = s_h*t_h; - v = s_l*t_h + t_l*s; - /* 2/(3log2)*(s+...) */ - p_h = u + v; - GET_FLOAT_WORD(is, p_h); - SET_FLOAT_WORD(p_h, is & 0xfffff000); - p_l = v - (p_h - u); - z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ - z_l = cp_l*p_h + p_l*cp+dp_l[k]; - /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ - t = (float)n; - t1 = (((z_h + z_l) + dp_h[k]) + t); - GET_FLOAT_WORD(is, t1); - SET_FLOAT_WORD(t1, is & 0xfffff000); - t2 = z_l - (((t1 - t) - dp_h[k]) - z_h); - } - - /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ - GET_FLOAT_WORD(is, y); - SET_FLOAT_WORD(y1, is & 0xfffff000); - p_l = (y-y1)*t1 + y*t2; - p_h = y1*t1; - z = p_l + p_h; - GET_FLOAT_WORD(j, z); - if (j > 0x43000000) /* if z > 128 */ - return sn*huge*huge; /* overflow */ - else if (j == 0x43000000) { /* if z == 128 */ - if (p_l + ovt > z - p_h) - return sn*huge*huge; /* overflow */ - } else if ((j&0x7fffffff) > 0x43160000) /* z < -150 */ // FIXME: check should be (uint32_t)j > 0xc3160000 - return sn*tiny*tiny; /* underflow */ - else if (j == 0xc3160000) { /* z == -150 */ - if (p_l <= z-p_h) - return sn*tiny*tiny; /* underflow */ - } - /* - * compute 2**(p_h+p_l) - */ - i = j & 0x7fffffff; - k = (i>>23) - 0x7f; - n = 0; - if (i > 0x3f000000) { /* if |z| > 0.5, set n = [z+0.5] */ - n = j + (0x00800000>>(k+1)); - k = ((n&0x7fffffff)>>23) - 0x7f; /* new k for n */ - SET_FLOAT_WORD(t, n & ~(0x007fffff>>k)); - n = ((n&0x007fffff)|0x00800000)>>(23-k); - if (j < 0) - n = -n; - p_h -= t; - } - t = p_l + p_h; - GET_FLOAT_WORD(is, t); - SET_FLOAT_WORD(t, is & 0xffff8000); - u = t*lg2_h; - v = (p_l-(t-p_h))*lg2 + t*lg2_l; - z = u + v; - w = v - (z - u); - t = z*z; - t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - r = (z*t1)/(t1-2.0f) - (w+z*w); - z = 1.0f - (r - z); - GET_FLOAT_WORD(j, z); - j += n<<23; - if ((j>>23) <= 0) /* subnormal output */ - z = scalbnf(z, n); - else - SET_FLOAT_WORD(z, j); - return sn*z; -} diff --git a/usr/lib/libc/math/powl.c b/usr/lib/libc/math/powl.c deleted file mode 100644 index 5b6da07b2..000000000 --- a/usr/lib/libc/math/powl.c +++ /dev/null @@ -1,522 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_powl.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* powl.c - * - * Power function, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, z, powl(); - * - * z = powl( x, y ); - * - * - * DESCRIPTION: - * - * Computes x raised to the yth power. Analytically, - * - * x**y = exp( y log(x) ). - * - * Following Cody and Waite, this program uses a lookup table - * of 2**-i/32 and pseudo extended precision arithmetic to - * obtain several extra bits of accuracy in both the logarithm - * and the exponential. - * - * - * ACCURACY: - * - * The relative error of pow(x,y) can be estimated - * by y dl ln(2), where dl is the absolute error of - * the internally computed base 2 logarithm. At the ends - * of the approximation interval the logarithm equal 1/32 - * and its relative error is about 1 lsb = 1.1e-19. Hence - * the predicted relative error in the result is 2.3e-21 y . - * - * Relative error: - * arithmetic domain # trials peak rms - * - * IEEE +-1000 40000 2.8e-18 3.7e-19 - * .001 < x < 1000, with log(x) uniformly distributed. - * -1000 < y < 1000, y uniformly distributed. - * - * IEEE 0,8700 60000 6.5e-18 1.0e-18 - * 0.99 < x < 1.01, 0 < y < 8700, uniformly distributed. - * - * - * ERROR MESSAGES: - * - * message condition value returned - * pow overflow x**y > MAXNUM INFINITY - * pow underflow x**y < 1/MAXNUM 0.0 - * pow domain x<0 and y noninteger 0.0 - * - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double powl(long double x, long double y) -{ - return pow(x, y); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - -/* Table size */ -#define NXT 32 - -/* log(1+x) = x - .5x^2 + x^3 * P(z)/Q(z) - * on the domain 2^(-1/32) - 1 <= x <= 2^(1/32) - 1 - */ -static const long double P[] = { - 8.3319510773868690346226E-4L, - 4.9000050881978028599627E-1L, - 1.7500123722550302671919E0L, - 1.4000100839971580279335E0L, -}; -static const long double Q[] = { -/* 1.0000000000000000000000E0L,*/ - 5.2500282295834889175431E0L, - 8.4000598057587009834666E0L, - 4.2000302519914740834728E0L, -}; -/* A[i] = 2^(-i/32), rounded to IEEE long double precision. - * If i is even, A[i] + B[i/2] gives additional accuracy. - */ -static const long double A[33] = { - 1.0000000000000000000000E0L, - 9.7857206208770013448287E-1L, - 9.5760328069857364691013E-1L, - 9.3708381705514995065011E-1L, - 9.1700404320467123175367E-1L, - 8.9735453750155359320742E-1L, - 8.7812608018664974155474E-1L, - 8.5930964906123895780165E-1L, - 8.4089641525371454301892E-1L, - 8.2287773907698242225554E-1L, - 8.0524516597462715409607E-1L, - 7.8799042255394324325455E-1L, - 7.7110541270397041179298E-1L, - 7.5458221379671136985669E-1L, - 7.3841307296974965571198E-1L, - 7.2259040348852331001267E-1L, - 7.0710678118654752438189E-1L, - 6.9195494098191597746178E-1L, - 6.7712777346844636413344E-1L, - 6.6261832157987064729696E-1L, - 6.4841977732550483296079E-1L, - 6.3452547859586661129850E-1L, - 6.2092890603674202431705E-1L, - 6.0762367999023443907803E-1L, - 5.9460355750136053334378E-1L, - 5.8186242938878875689693E-1L, - 5.6939431737834582684856E-1L, - 5.5719337129794626814472E-1L, - 5.4525386633262882960438E-1L, - 5.3357020033841180906486E-1L, - 5.2213689121370692017331E-1L, - 5.1094857432705833910408E-1L, - 5.0000000000000000000000E-1L, -}; -static const long double B[17] = { - 0.0000000000000000000000E0L, - 2.6176170809902549338711E-20L, --1.0126791927256478897086E-20L, - 1.3438228172316276937655E-21L, - 1.2207982955417546912101E-20L, --6.3084814358060867200133E-21L, - 1.3164426894366316434230E-20L, --1.8527916071632873716786E-20L, - 1.8950325588932570796551E-20L, - 1.5564775779538780478155E-20L, - 6.0859793637556860974380E-21L, --2.0208749253662532228949E-20L, - 1.4966292219224761844552E-20L, - 3.3540909728056476875639E-21L, --8.6987564101742849540743E-22L, --1.2327176863327626135542E-20L, - 0.0000000000000000000000E0L, -}; - -/* 2^x = 1 + x P(x), - * on the interval -1/32 <= x <= 0 - */ -static const long double R[] = { - 1.5089970579127659901157E-5L, - 1.5402715328927013076125E-4L, - 1.3333556028915671091390E-3L, - 9.6181291046036762031786E-3L, - 5.5504108664798463044015E-2L, - 2.4022650695910062854352E-1L, - 6.9314718055994530931447E-1L, -}; - -#define MEXP (NXT*16384.0L) -/* The following if denormal numbers are supported, else -MEXP: */ -#define MNEXP (-NXT*(16384.0L+64.0L)) -/* log2(e) - 1 */ -#define LOG2EA 0.44269504088896340735992L - -#define F W -#define Fa Wa -#define Fb Wb -#define G W -#define Ga Wa -#define Gb u -#define H W -#define Ha Wb -#define Hb Wb - -static const long double MAXLOGL = 1.1356523406294143949492E4L; -static const long double MINLOGL = -1.13994985314888605586758E4L; -static const long double LOGE2L = 6.9314718055994530941723E-1L; -static const long double huge = 0x1p10000L; -/* XXX Prevent gcc from erroneously constant folding this. */ -static const volatile long double twom10000 = 0x1p-10000L; - -static long double reducl(long double); -static long double powil(long double, int); - -long double powl(long double x, long double y) -{ - /* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */ - int i, nflg, iyflg, yoddint; - long e; - volatile long double z=0; - long double w=0, W=0, Wa=0, Wb=0, ya=0, yb=0, u=0; - - /* make sure no invalid exception is raised by nan comparision */ - if (isnan(x)) { - if (!isnan(y) && y == 0.0) - return 1.0; - return x; - } - if (isnan(y)) { - if (x == 1.0) - return 1.0; - return y; - } - if (x == 1.0) - return 1.0; /* 1**y = 1, even if y is nan */ - if (x == -1.0 && !isfinite(y)) - return 1.0; /* -1**inf = 1 */ - if (y == 0.0) - return 1.0; /* x**0 = 1, even if x is nan */ - if (y == 1.0) - return x; - if (y >= LDBL_MAX) { - if (x > 1.0 || x < -1.0) - return INFINITY; - if (x != 0.0) - return 0.0; - } - if (y <= -LDBL_MAX) { - if (x > 1.0 || x < -1.0) - return 0.0; - if (x != 0.0 || y == -INFINITY) - return INFINITY; - } - if (x >= LDBL_MAX) { - if (y > 0.0) - return INFINITY; - return 0.0; - } - - w = floorl(y); - - /* Set iyflg to 1 if y is an integer. */ - iyflg = 0; - if (w == y) - iyflg = 1; - - /* Test for odd integer y. */ - yoddint = 0; - if (iyflg) { - ya = fabsl(y); - ya = floorl(0.5 * ya); - yb = 0.5 * fabsl(w); - if( ya != yb ) - yoddint = 1; - } - - if (x <= -LDBL_MAX) { - if (y > 0.0) { - if (yoddint) - return -INFINITY; - return INFINITY; - } - if (y < 0.0) { - if (yoddint) - return -0.0; - return 0.0; - } - } - nflg = 0; /* (x<0)**(odd int) */ - if (x <= 0.0) { - if (x == 0.0) { - if (y < 0.0) { - if (signbit(x) && yoddint) - /* (-0.0)**(-odd int) = -inf, divbyzero */ - return -1.0/0.0; - /* (+-0.0)**(negative) = inf, divbyzero */ - return 1.0/0.0; - } - if (signbit(x) && yoddint) - return -0.0; - return 0.0; - } - if (iyflg == 0) - return (x - x) / (x - x); /* (x<0)**(non-int) is NaN */ - /* (x<0)**(integer) */ - if (yoddint) - nflg = 1; /* negate result */ - x = -x; - } - /* (+integer)**(integer) */ - if (iyflg && floorl(x) == x && fabsl(y) < 32768.0) { - w = powil(x, (int)y); - return nflg ? -w : w; - } - - /* separate significand from exponent */ - x = frexpl(x, &i); - e = i; - - /* find significand in antilog table A[] */ - i = 1; - if (x <= A[17]) - i = 17; - if (x <= A[i+8]) - i += 8; - if (x <= A[i+4]) - i += 4; - if (x <= A[i+2]) - i += 2; - if (x >= A[1]) - i = -1; - i += 1; - - /* Find (x - A[i])/A[i] - * in order to compute log(x/A[i]): - * - * log(x) = log( a x/a ) = log(a) + log(x/a) - * - * log(x/a) = log(1+v), v = x/a - 1 = (x-a)/a - */ - x -= A[i]; - x -= B[i/2]; - x /= A[i]; - - /* rational approximation for log(1+v): - * - * log(1+v) = v - v**2/2 + v**3 P(v) / Q(v) - */ - z = x*x; - w = x * (z * __polevll(x, P, 3) / __p1evll(x, Q, 3)); - w = w - 0.5*z; - - /* Convert to base 2 logarithm: - * multiply by log2(e) = 1 + LOG2EA - */ - z = LOG2EA * w; - z += w; - z += LOG2EA * x; - z += x; - - /* Compute exponent term of the base 2 logarithm. */ - w = -i; - w /= NXT; - w += e; - /* Now base 2 log of x is w + z. */ - - /* Multiply base 2 log by y, in extended precision. */ - - /* separate y into large part ya - * and small part yb less than 1/NXT - */ - ya = reducl(y); - yb = y - ya; - - /* (w+z)(ya+yb) - * = w*ya + w*yb + z*y - */ - F = z * y + w * yb; - Fa = reducl(F); - Fb = F - Fa; - - G = Fa + w * ya; - Ga = reducl(G); - Gb = G - Ga; - - H = Fb + Gb; - Ha = reducl(H); - w = (Ga + Ha) * NXT; - - /* Test the power of 2 for overflow */ - if (w > MEXP) - return huge * huge; /* overflow */ - if (w < MNEXP) - return twom10000 * twom10000; /* underflow */ - - e = w; - Hb = H - Ha; - - if (Hb > 0.0) { - e += 1; - Hb -= 1.0/NXT; /*0.0625L;*/ - } - - /* Now the product y * log2(x) = Hb + e/NXT. - * - * Compute base 2 exponential of Hb, - * where -0.0625 <= Hb <= 0. - */ - z = Hb * __polevll(Hb, R, 6); /* z = 2**Hb - 1 */ - - /* Express e/NXT as an integer plus a negative number of (1/NXT)ths. - * Find lookup table entry for the fractional power of 2. - */ - if (e < 0) - i = 0; - else - i = 1; - i = e/NXT + i; - e = NXT*i - e; - w = A[e]; - z = w * z; /* 2**-e * ( 1 + (2**Hb-1) ) */ - z = z + w; - z = scalbnl(z, i); /* multiply by integer power of 2 */ - - if (nflg) - z = -z; - return z; -} - - -/* Find a multiple of 1/NXT that is within 1/NXT of x. */ -static long double reducl(long double x) -{ - long double t; - - t = x * NXT; - t = floorl(t); - t = t / NXT; - return t; -} - -/* - * Positive real raised to integer power, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, powil(); - * int n; - * - * y = powil( x, n ); - * - * - * DESCRIPTION: - * - * Returns argument x>0 raised to the nth power. - * The routine efficiently decomposes n as a sum of powers of - * two. The desired power is a product of two-to-the-kth - * powers of x. Thus to compute the 32767 power of x requires - * 28 multiplications instead of 32767 multiplications. - * - * - * ACCURACY: - * - * Relative error: - * arithmetic x domain n domain # trials peak rms - * IEEE .001,1000 -1022,1023 50000 4.3e-17 7.8e-18 - * IEEE 1,2 -1022,1023 20000 3.9e-17 7.6e-18 - * IEEE .99,1.01 0,8700 10000 3.6e-16 7.2e-17 - * - * Returns MAXNUM on overflow, zero on underflow. - */ - -static long double powil(long double x, int nn) -{ - long double ww, y; - long double s; - int n, e, sign, lx; - - if (nn == 0) - return 1.0; - - if (nn < 0) { - sign = -1; - n = -nn; - } else { - sign = 1; - n = nn; - } - - /* Overflow detection */ - - /* Calculate approximate logarithm of answer */ - s = x; - s = frexpl( s, &lx); - e = (lx - 1)*n; - if ((e == 0) || (e > 64) || (e < -64)) { - s = (s - 7.0710678118654752e-1L) / (s + 7.0710678118654752e-1L); - s = (2.9142135623730950L * s - 0.5 + lx) * nn * LOGE2L; - } else { - s = LOGE2L * e; - } - - if (s > MAXLOGL) - return huge * huge; /* overflow */ - - if (s < MINLOGL) - return twom10000 * twom10000; /* underflow */ - /* Handle tiny denormal answer, but with less accuracy - * since roundoff error in 1.0/x will be amplified. - * The precise demarcation should be the gradual underflow threshold. - */ - if (s < -MAXLOGL+2.0) { - x = 1.0/x; - sign = -sign; - } - - /* First bit of the power */ - if (n & 1) - y = x; - else - y = 1.0; - - ww = x; - n >>= 1; - while (n) { - ww = ww * ww; /* arg to the 2-to-the-kth power */ - if (n & 1) /* if that bit is set, then include in product */ - y *= ww; - n >>= 1; - } - - if (sign < 0) - y = 1.0/y; - return y; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double powl(long double x, long double y) -{ - return pow(x, y); -} -#endif diff --git a/usr/lib/libc/math/remainder.c b/usr/lib/libc/math/remainder.c deleted file mode 100644 index 6cd089c46..000000000 --- a/usr/lib/libc/math/remainder.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "libc.h" - -double remainder(double x, double y) -{ - int q; - return remquo(x, y, &q); -} - -weak_alias(remainder, drem); diff --git a/usr/lib/libc/math/remainderf.c b/usr/lib/libc/math/remainderf.c deleted file mode 100644 index 420d3bfc4..000000000 --- a/usr/lib/libc/math/remainderf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "libc.h" - -float remainderf(float x, float y) -{ - int q; - return remquof(x, y, &q); -} - -weak_alias(remainderf, dremf); diff --git a/usr/lib/libc/math/remainderl.c b/usr/lib/libc/math/remainderl.c deleted file mode 100644 index 2a13c1d5a..000000000 --- a/usr/lib/libc/math/remainderl.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double remainderl(long double x, long double y) -{ - return remainder(x, y); -} -#else -long double remainderl(long double x, long double y) -{ - int q; - return remquol(x, y, &q); -} -#endif diff --git a/usr/lib/libc/math/remquo.c b/usr/lib/libc/math/remquo.c deleted file mode 100644 index 59d5ad57e..000000000 --- a/usr/lib/libc/math/remquo.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include - -double remquo(double x, double y, int *quo) -{ - union {double f; uint64_t i;} ux = {x}, uy = {y}; - int ex = ux.i>>52 & 0x7ff; - int ey = uy.i>>52 & 0x7ff; - int sx = ux.i>>63; - int sy = uy.i>>63; - uint32_t q; - uint64_t i; - uint64_t uxi = ux.i; - - *quo = 0; - if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff) - return (x*y)/(x*y); - if (ux.i<<1 == 0) - return x; - - /* normalize x and y */ - if (!ex) { - for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1); - uxi <<= -ex + 1; - } else { - uxi &= -1ULL >> 12; - uxi |= 1ULL << 52; - } - if (!ey) { - for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1); - uy.i <<= -ey + 1; - } else { - uy.i &= -1ULL >> 12; - uy.i |= 1ULL << 52; - } - - q = 0; - if (ex < ey) { - if (ex+1 == ey) - goto end; - return x; - } - - /* x mod y */ - for (; ex > ey; ex--) { - i = uxi - uy.i; - if (i >> 63 == 0) { - uxi = i; - q++; - } - uxi <<= 1; - q <<= 1; - } - i = uxi - uy.i; - if (i >> 63 == 0) { - uxi = i; - q++; - } - if (uxi == 0) - ex = -60; - else - for (; uxi>>52 == 0; uxi <<= 1, ex--); -end: - /* scale result and decide between |x| and |x|-|y| */ - if (ex > 0) { - uxi -= 1ULL << 52; - uxi |= (uint64_t)ex << 52; - } else { - uxi >>= -ex + 1; - } - ux.i = uxi; - x = ux.f; - if (sy) - y = -y; - if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { - x -= y; - q++; - } - q &= 0x7fffffff; - *quo = sx^sy ? -(int)q : (int)q; - return sx ? -x : x; -} diff --git a/usr/lib/libc/math/remquof.c b/usr/lib/libc/math/remquof.c deleted file mode 100644 index 2f41ff706..000000000 --- a/usr/lib/libc/math/remquof.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include - -float remquof(float x, float y, int *quo) -{ - union {float f; uint32_t i;} ux = {x}, uy = {y}; - int ex = ux.i>>23 & 0xff; - int ey = uy.i>>23 & 0xff; - int sx = ux.i>>31; - int sy = uy.i>>31; - uint32_t q; - uint32_t i; - uint32_t uxi = ux.i; - - *quo = 0; - if (uy.i<<1 == 0 || isnan(y) || ex == 0xff) - return (x*y)/(x*y); - if (ux.i<<1 == 0) - return x; - - /* normalize x and y */ - if (!ex) { - for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1); - uxi <<= -ex + 1; - } else { - uxi &= -1U >> 9; - uxi |= 1U << 23; - } - if (!ey) { - for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1); - uy.i <<= -ey + 1; - } else { - uy.i &= -1U >> 9; - uy.i |= 1U << 23; - } - - q = 0; - if (ex < ey) { - if (ex+1 == ey) - goto end; - return x; - } - - /* x mod y */ - for (; ex > ey; ex--) { - i = uxi - uy.i; - if (i >> 31 == 0) { - uxi = i; - q++; - } - uxi <<= 1; - q <<= 1; - } - i = uxi - uy.i; - if (i >> 31 == 0) { - uxi = i; - q++; - } - if (uxi == 0) - ex = -30; - else - for (; uxi>>23 == 0; uxi <<= 1, ex--); -end: - /* scale result and decide between |x| and |x|-|y| */ - if (ex > 0) { - uxi -= 1U << 23; - uxi |= (uint32_t)ex << 23; - } else { - uxi >>= -ex + 1; - } - ux.i = uxi; - x = ux.f; - if (sy) - y = -y; - if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { - x -= y; - q++; - } - q &= 0x7fffffff; - *quo = sx^sy ? -(int)q : (int)q; - return sx ? -x : x; -} diff --git a/usr/lib/libc/math/remquol.c b/usr/lib/libc/math/remquol.c deleted file mode 100644 index 9b065c007..000000000 --- a/usr/lib/libc/math/remquol.c +++ /dev/null @@ -1,124 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double remquol(long double x, long double y, int *quo) -{ - return remquo(x, y, quo); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double remquol(long double x, long double y, int *quo) -{ - union ldshape ux = {x}, uy = {y}; - int ex = ux.i.se & 0x7fff; - int ey = uy.i.se & 0x7fff; - int sx = ux.i.se >> 15; - int sy = uy.i.se >> 15; - uint32_t q; - - *quo = 0; - if (y == 0 || isnan(y) || ex == 0x7fff) - return (x*y)/(x*y); - if (x == 0) - return x; - - /* normalize x and y */ - if (!ex) { - ux.i.se = ex; - ux.f *= 0x1p120f; - ex = ux.i.se - 120; - } - if (!ey) { - uy.i.se = ey; - uy.f *= 0x1p120f; - ey = uy.i.se - 120; - } - - q = 0; - if (ex >= ey) { - /* x mod y */ -#if LDBL_MANT_DIG == 64 - uint64_t i, mx, my; - mx = ux.i.m; - my = uy.i.m; - for (; ex > ey; ex--) { - i = mx - my; - if (mx >= my) { - mx = 2*i; - q++; - q <<= 1; - } else if (2*mx < mx) { - mx = 2*mx - my; - q <<= 1; - q++; - } else { - mx = 2*mx; - q <<= 1; - } - } - i = mx - my; - if (mx >= my) { - mx = i; - q++; - } - if (mx == 0) - ex = -120; - else - for (; mx >> 63 == 0; mx *= 2, ex--); - ux.i.m = mx; -#elif LDBL_MANT_DIG == 113 - uint64_t hi, lo, xhi, xlo, yhi, ylo; - xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48; - yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48; - xlo = ux.i2.lo; - ylo = ux.i2.lo; - for (; ex > ey; ex--) { - hi = xhi - yhi; - lo = xlo - ylo; - if (xlo < ylo) - hi -= 1; - if (hi >> 63 == 0) { - xhi = 2*hi + (lo>>63); - xlo = 2*lo; - q++; - } else { - xhi = 2*xhi + (xlo>>63); - xlo = 2*xlo; - } - q <<= 1; - } - hi = xhi - yhi; - lo = xlo - ylo; - if (xlo < ylo) - hi -= 1; - if (hi >> 63 == 0) { - xhi = hi; - xlo = lo; - q++; - } - if ((xhi|xlo) == 0) - ex = -120; - else - for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--); - ux.i2.hi = xhi; - ux.i2.lo = xlo; -#endif - } - - /* scale result and decide between |x| and |x|-|y| */ - if (ex <= 0) { - ux.i.se = ex + 120; - ux.f *= 0x1p-120f; - } else - ux.i.se = ex; - x = ux.f; - if (sy) - y = -y; - if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { - x -= y; - q++; - } - q &= 0x7fffffff; - *quo = sx^sy ? -(int)q : (int)q; - return sx ? -x : x; -} -#endif diff --git a/usr/lib/libc/math/rint.c b/usr/lib/libc/math/rint.c deleted file mode 100644 index fbba390e7..000000000 --- a/usr/lib/libc/math/rint.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const double_t toint = 1/EPS; - -double rint(double x) -{ - union {double f; uint64_t i;} u = {x}; - int e = u.i>>52 & 0x7ff; - int s = u.i>>63; - double_t y; - - if (e >= 0x3ff+52) - return x; - if (s) - y = x - toint + toint; - else - y = x + toint - toint; - if (y == 0) - return s ? -0.0 : 0; - return y; -} diff --git a/usr/lib/libc/math/rintf.c b/usr/lib/libc/math/rintf.c deleted file mode 100644 index 9047688d2..000000000 --- a/usr/lib/libc/math/rintf.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -#if FLT_EVAL_METHOD==0 -#define EPS FLT_EPSILON -#elif FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const float_t toint = 1/EPS; - -float rintf(float x) -{ - union {float f; uint32_t i;} u = {x}; - int e = u.i>>23 & 0xff; - int s = u.i>>31; - float_t y; - - if (e >= 0x7f+23) - return x; - if (s) - y = x - toint + toint; - else - y = x + toint - toint; - if (y == 0) - return s ? -0.0f : 0.0f; - return y; -} diff --git a/usr/lib/libc/math/rintl.c b/usr/lib/libc/math/rintl.c deleted file mode 100644 index 374327db2..000000000 --- a/usr/lib/libc/math/rintl.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double rintl(long double x) -{ - return rint(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -static const long double toint = 1/LDBL_EPSILON; - -long double rintl(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - int s = u.i.se >> 15; - long double y; - - if (e >= 0x3fff+LDBL_MANT_DIG-1) - return x; - if (s) - y = x - toint + toint; - else - y = x + toint - toint; - if (y == 0) - return 0*x; - return y; -} -#endif diff --git a/usr/lib/libc/math/round.c b/usr/lib/libc/math/round.c deleted file mode 100644 index 130d58d25..000000000 --- a/usr/lib/libc/math/round.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const double_t toint = 1/EPS; - -double round(double x) -{ - union {double f; uint64_t i;} u = {x}; - int e = u.i >> 52 & 0x7ff; - double_t y; - - if (e >= 0x3ff+52) - return x; - if (u.i >> 63) - x = -x; - if (e < 0x3ff-1) { - /* raise inexact if x!=0 */ - FORCE_EVAL(x + toint); - return 0*u.f; - } - y = x + toint - toint - x; - if (y > 0.5) - y = y + x - 1; - else if (y <= -0.5) - y = y + x + 1; - else - y = y + x; - if (u.i >> 63) - y = -y; - return y; -} diff --git a/usr/lib/libc/math/roundf.c b/usr/lib/libc/math/roundf.c deleted file mode 100644 index e8210af56..000000000 --- a/usr/lib/libc/math/roundf.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "libm.h" - -#if FLT_EVAL_METHOD==0 -#define EPS FLT_EPSILON -#elif FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif -static const float_t toint = 1/EPS; - -float roundf(float x) -{ - union {float f; uint32_t i;} u = {x}; - int e = u.i >> 23 & 0xff; - float_t y; - - if (e >= 0x7f+23) - return x; - if (u.i >> 31) - x = -x; - if (e < 0x7f-1) { - FORCE_EVAL(x + toint); - return 0*u.f; - } - y = x + toint - toint - x; - if (y > 0.5f) - y = y + x - 1; - else if (y <= -0.5f) - y = y + x + 1; - else - y = y + x; - if (u.i >> 31) - y = -y; - return y; -} diff --git a/usr/lib/libc/math/roundl.c b/usr/lib/libc/math/roundl.c deleted file mode 100644 index f4ff6820a..000000000 --- a/usr/lib/libc/math/roundl.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double roundl(long double x) -{ - return round(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -static const long double toint = 1/LDBL_EPSILON; - -long double roundl(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - long double y; - - if (e >= 0x3fff+LDBL_MANT_DIG-1) - return x; - if (u.i.se >> 15) - x = -x; - if (e < 0x3fff-1) { - FORCE_EVAL(x + toint); - return 0*u.f; - } - y = x + toint - toint - x; - if (y > 0.5) - y = y + x - 1; - else if (y <= -0.5) - y = y + x + 1; - else - y = y + x; - if (u.i.se >> 15) - y = -y; - return y; -} -#endif diff --git a/usr/lib/libc/math/scalb.c b/usr/lib/libc/math/scalb.c deleted file mode 100644 index efe69e60c..000000000 --- a/usr/lib/libc/math/scalb.c +++ /dev/null @@ -1,35 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_scalb.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* - * scalb(x, fn) is provide for - * passing various standard test suite. One - * should use scalbn() instead. - */ - -#define _GNU_SOURCE -#include - -double scalb(double x, double fn) -{ - if (isnan(x) || isnan(fn)) - return x*fn; - if (!isfinite(fn)) { - if (fn > 0.0) - return x*fn; - else - return x/(-fn); - } - if (rint(fn) != fn) return (fn-fn)/(fn-fn); - if ( fn > 65000.0) return scalbn(x, 65000); - if (-fn > 65000.0) return scalbn(x,-65000); - return scalbn(x,(int)fn); -} diff --git a/usr/lib/libc/math/scalbf.c b/usr/lib/libc/math/scalbf.c deleted file mode 100644 index f44ed5b64..000000000 --- a/usr/lib/libc/math/scalbf.c +++ /dev/null @@ -1,32 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_scalbf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#define _GNU_SOURCE -#include - -float scalbf(float x, float fn) -{ - if (isnan(x) || isnan(fn)) return x*fn; - if (!isfinite(fn)) { - if (fn > 0.0f) - return x*fn; - else - return x/(-fn); - } - if (rintf(fn) != fn) return (fn-fn)/(fn-fn); - if ( fn > 65000.0f) return scalbnf(x, 65000); - if (-fn > 65000.0f) return scalbnf(x,-65000); - return scalbnf(x,(int)fn); -} diff --git a/usr/lib/libc/math/scalbln.c b/usr/lib/libc/math/scalbln.c deleted file mode 100644 index e6f3f195c..000000000 --- a/usr/lib/libc/math/scalbln.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -double scalbln(double x, long n) -{ - if (n > INT_MAX) - n = INT_MAX; - else if (n < INT_MIN) - n = INT_MIN; - return scalbn(x, n); -} diff --git a/usr/lib/libc/math/scalblnf.c b/usr/lib/libc/math/scalblnf.c deleted file mode 100644 index d8e8166b1..000000000 --- a/usr/lib/libc/math/scalblnf.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -float scalblnf(float x, long n) -{ - if (n > INT_MAX) - n = INT_MAX; - else if (n < INT_MIN) - n = INT_MIN; - return scalbnf(x, n); -} diff --git a/usr/lib/libc/math/scalblnl.c b/usr/lib/libc/math/scalblnl.c deleted file mode 100644 index 854c51c4c..000000000 --- a/usr/lib/libc/math/scalblnl.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double scalblnl(long double x, long n) -{ - return scalbln(x, n); -} -#else -long double scalblnl(long double x, long n) -{ - if (n > INT_MAX) - n = INT_MAX; - else if (n < INT_MIN) - n = INT_MIN; - return scalbnl(x, n); -} -#endif diff --git a/usr/lib/libc/math/scalbn.c b/usr/lib/libc/math/scalbn.c deleted file mode 100644 index 182f56106..000000000 --- a/usr/lib/libc/math/scalbn.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -double scalbn(double x, int n) -{ - union {double f; uint64_t i;} u; - double_t y = x; - - if (n > 1023) { - y *= 0x1p1023; - n -= 1023; - if (n > 1023) { - y *= 0x1p1023; - n -= 1023; - if (n > 1023) - n = 1023; - } - } else if (n < -1022) { - /* make sure final n < -53 to avoid double - rounding in the subnormal range */ - y *= 0x1p-1022 * 0x1p53; - n += 1022 - 53; - if (n < -1022) { - y *= 0x1p-1022 * 0x1p53; - n += 1022 - 53; - if (n < -1022) - n = -1022; - } - } - u.i = (uint64_t)(0x3ff+n)<<52; - x = y * u.f; - return x; -} diff --git a/usr/lib/libc/math/scalbnf.c b/usr/lib/libc/math/scalbnf.c deleted file mode 100644 index a5ad208b6..000000000 --- a/usr/lib/libc/math/scalbnf.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -float scalbnf(float x, int n) -{ - union {float f; uint32_t i;} u; - float_t y = x; - - if (n > 127) { - y *= 0x1p127f; - n -= 127; - if (n > 127) { - y *= 0x1p127f; - n -= 127; - if (n > 127) - n = 127; - } - } else if (n < -126) { - y *= 0x1p-126f * 0x1p24f; - n += 126 - 24; - if (n < -126) { - y *= 0x1p-126f * 0x1p24f; - n += 126 - 24; - if (n < -126) - n = -126; - } - } - u.i = (uint32_t)(0x7f+n)<<23; - x = y * u.f; - return x; -} diff --git a/usr/lib/libc/math/scalbnl.c b/usr/lib/libc/math/scalbnl.c deleted file mode 100644 index db44dab06..000000000 --- a/usr/lib/libc/math/scalbnl.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double scalbnl(long double x, int n) -{ - return scalbn(x, n); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double scalbnl(long double x, int n) -{ - union ldshape u; - - if (n > 16383) { - x *= 0x1p16383L; - n -= 16383; - if (n > 16383) { - x *= 0x1p16383L; - n -= 16383; - if (n > 16383) - n = 16383; - } - } else if (n < -16382) { - x *= 0x1p-16382L * 0x1p113L; - n += 16382 - 113; - if (n < -16382) { - x *= 0x1p-16382L * 0x1p113L; - n += 16382 - 113; - if (n < -16382) - n = -16382; - } - } - u.f = 1.0; - u.i.se = 0x3fff + n; - return x * u.f; -} -#endif diff --git a/usr/lib/libc/math/signgam.c b/usr/lib/libc/math/signgam.c deleted file mode 100644 index cd728001b..000000000 --- a/usr/lib/libc/math/signgam.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include "libc.h" - -int __signgam = 0; - -weak_alias(__signgam, signgam); diff --git a/usr/lib/libc/math/significand.c b/usr/lib/libc/math/significand.c deleted file mode 100644 index 40d9aa9f4..000000000 --- a/usr/lib/libc/math/significand.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -double significand(double x) -{ - return scalbn(x, -ilogb(x)); -} diff --git a/usr/lib/libc/math/significandf.c b/usr/lib/libc/math/significandf.c deleted file mode 100644 index 8a697e1aa..000000000 --- a/usr/lib/libc/math/significandf.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -float significandf(float x) -{ - return scalbnf(x, -ilogbf(x)); -} diff --git a/usr/lib/libc/math/sin.c b/usr/lib/libc/math/sin.c deleted file mode 100644 index 055e215bc..000000000 --- a/usr/lib/libc/math/sin.c +++ /dev/null @@ -1,78 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* sin(x) - * Return sine function of x. - * - * kernel function: - * __sin ... sine function on [-pi/4,pi/4] - * __cos ... cose function on [-pi/4,pi/4] - * __rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include "libm.h" - -double sin(double x) -{ - double y[2]; - uint32_t ix; - unsigned n; - - /* High word of x. */ - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - - /* |x| ~< pi/4 */ - if (ix <= 0x3fe921fb) { - if (ix < 0x3e500000) { /* |x| < 2**-26 */ - /* raise inexact if x != 0 and underflow if subnormal*/ - FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); - return x; - } - return __sin(x, 0.0, 0); - } - - /* sin(Inf or NaN) is NaN */ - if (ix >= 0x7ff00000) - return x - x; - - /* argument reduction needed */ - n = __rem_pio2(x, y); - switch (n&3) { - case 0: return __sin(y[0], y[1], 1); - case 1: return __cos(y[0], y[1]); - case 2: return -__sin(y[0], y[1], 1); - default: - return -__cos(y[0], y[1]); - } -} diff --git a/usr/lib/libc/math/sincos.c b/usr/lib/libc/math/sincos.c deleted file mode 100644 index 35b2d9239..000000000 --- a/usr/lib/libc/math/sincos.c +++ /dev/null @@ -1,69 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#define _GNU_SOURCE -#include "libm.h" - -void sincos(double x, double *sin, double *cos) -{ - double y[2], s, c; - uint32_t ix; - unsigned n; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - - /* |x| ~< pi/4 */ - if (ix <= 0x3fe921fb) { - /* if |x| < 2**-27 * sqrt(2) */ - if (ix < 0x3e46a09e) { - /* raise inexact if x!=0 and underflow if subnormal */ - FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); - *sin = x; - *cos = 1.0; - return; - } - *sin = __sin(x, 0.0, 0); - *cos = __cos(x, 0.0); - return; - } - - /* sincos(Inf or NaN) is NaN */ - if (ix >= 0x7ff00000) { - *sin = *cos = x - x; - return; - } - - /* argument reduction needed */ - n = __rem_pio2(x, y); - s = __sin(y[0], y[1], 1); - c = __cos(y[0], y[1]); - switch (n&3) { - case 0: - *sin = s; - *cos = c; - break; - case 1: - *sin = c; - *cos = -s; - break; - case 2: - *sin = -s; - *cos = -c; - break; - case 3: - default: - *sin = -c; - *cos = s; - break; - } -} diff --git a/usr/lib/libc/math/sincosf.c b/usr/lib/libc/math/sincosf.c deleted file mode 100644 index f8ca7232c..000000000 --- a/usr/lib/libc/math/sincosf.c +++ /dev/null @@ -1,117 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#define _GNU_SOURCE -#include "libm.h" - -/* Small multiples of pi/2 rounded to double precision. */ -static const double -s1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ -s2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ -s3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ -s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ - -void sincosf(float x, float *sin, float *cos) -{ - double y; - float_t s, c; - uint32_t ix; - unsigned n, sign; - - GET_FLOAT_WORD(ix, x); - sign = ix >> 31; - ix &= 0x7fffffff; - - /* |x| ~<= pi/4 */ - if (ix <= 0x3f490fda) { - /* |x| < 2**-12 */ - if (ix < 0x39800000) { - /* raise inexact if x!=0 and underflow if subnormal */ - FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); - *sin = x; - *cos = 1.0f; - return; - } - *sin = __sindf(x); - *cos = __cosdf(x); - return; - } - - /* |x| ~<= 5*pi/4 */ - if (ix <= 0x407b53d1) { - if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */ - if (sign) { - *sin = -__cosdf(x + s1pio2); - *cos = __sindf(x + s1pio2); - } else { - *sin = __cosdf(s1pio2 - x); - *cos = __sindf(s1pio2 - x); - } - return; - } - /* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */ - *sin = -__sindf(sign ? x + s2pio2 : x - s2pio2); - *cos = -__cosdf(sign ? x + s2pio2 : x - s2pio2); - return; - } - - /* |x| ~<= 9*pi/4 */ - if (ix <= 0x40e231d5) { - if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */ - if (sign) { - *sin = __cosdf(x + s3pio2); - *cos = -__sindf(x + s3pio2); - } else { - *sin = -__cosdf(x - s3pio2); - *cos = __sindf(x - s3pio2); - } - return; - } - *sin = __sindf(sign ? x + s4pio2 : x - s4pio2); - *cos = __cosdf(sign ? x + s4pio2 : x - s4pio2); - return; - } - - /* sin(Inf or NaN) is NaN */ - if (ix >= 0x7f800000) { - *sin = *cos = x - x; - return; - } - - /* general argument reduction needed */ - n = __rem_pio2f(x, &y); - s = __sindf(y); - c = __cosdf(y); - switch (n&3) { - case 0: - *sin = s; - *cos = c; - break; - case 1: - *sin = c; - *cos = -s; - break; - case 2: - *sin = -s; - *cos = -c; - break; - case 3: - default: - *sin = -c; - *cos = s; - break; - } -} diff --git a/usr/lib/libc/math/sincosl.c b/usr/lib/libc/math/sincosl.c deleted file mode 100644 index d3ac1c4c8..000000000 --- a/usr/lib/libc/math/sincosl.c +++ /dev/null @@ -1,60 +0,0 @@ -#define _GNU_SOURCE -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -void sincosl(long double x, long double *sin, long double *cos) -{ - double sind, cosd; - sincos(x, &sind, &cosd); - *sin = sind; - *cos = cosd; -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -void sincosl(long double x, long double *sin, long double *cos) -{ - union ldshape u = {x}; - unsigned n; - long double y[2], s, c; - - u.i.se &= 0x7fff; - if (u.i.se == 0x7fff) { - *sin = *cos = x - x; - return; - } - if (u.f < M_PI_4) { - if (u.i.se < 0x3fff - LDBL_MANT_DIG) { - /* raise underflow if subnormal */ - if (u.i.se == 0) FORCE_EVAL(x*0x1p-120f); - *sin = x; - /* raise inexact if x!=0 */ - *cos = 1.0 + x; - return; - } - *sin = __sinl(x, 0, 0); - *cos = __cosl(x, 0); - return; - } - n = __rem_pio2l(x, y); - s = __sinl(y[0], y[1], 1); - c = __cosl(y[0], y[1]); - switch (n & 3) { - case 0: - *sin = s; - *cos = c; - break; - case 1: - *sin = c; - *cos = -s; - break; - case 2: - *sin = -s; - *cos = -c; - break; - case 3: - default: - *sin = -c; - *cos = s; - break; - } -} -#endif diff --git a/usr/lib/libc/math/sinf.c b/usr/lib/libc/math/sinf.c deleted file mode 100644 index 64e39f501..000000000 --- a/usr/lib/libc/math/sinf.c +++ /dev/null @@ -1,76 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -/* Small multiples of pi/2 rounded to double precision. */ -static const double -s1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ -s2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ -s3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ -s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ - -float sinf(float x) -{ - double y; - uint32_t ix; - int n, sign; - - GET_FLOAT_WORD(ix, x); - sign = ix >> 31; - ix &= 0x7fffffff; - - if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ - if (ix < 0x39800000) { /* |x| < 2**-12 */ - /* raise inexact if x!=0 and underflow if subnormal */ - FORCE_EVAL(ix < 0x00800000 ? x/0x1p120f : x+0x1p120f); - return x; - } - return __sindf(x); - } - if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */ - if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */ - if (sign) - return -__cosdf(x + s1pio2); - else - return __cosdf(x - s1pio2); - } - return __sindf(sign ? -(x + s2pio2) : -(x - s2pio2)); - } - if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */ - if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */ - if (sign) - return __cosdf(x + s3pio2); - else - return -__cosdf(x - s3pio2); - } - return __sindf(sign ? x + s4pio2 : x - s4pio2); - } - - /* sin(Inf or NaN) is NaN */ - if (ix >= 0x7f800000) - return x - x; - - /* general argument reduction needed */ - n = __rem_pio2f(x, &y); - switch (n&3) { - case 0: return __sindf(y); - case 1: return __cosdf(y); - case 2: return __sindf(-y); - default: - return -__cosdf(y); - } -} diff --git a/usr/lib/libc/math/sinh.c b/usr/lib/libc/math/sinh.c deleted file mode 100644 index 00022c4e6..000000000 --- a/usr/lib/libc/math/sinh.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "libm.h" - -/* sinh(x) = (exp(x) - 1/exp(x))/2 - * = (exp(x)-1 + (exp(x)-1)/exp(x))/2 - * = x + x^3/6 + o(x^5) - */ -double sinh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - uint32_t w; - double t, h, absx; - - h = 0.5; - if (u.i >> 63) - h = -h; - /* |x| */ - u.i &= (uint64_t)-1/2; - absx = u.f; - w = u.i >> 32; - - /* |x| < log(DBL_MAX) */ - if (w < 0x40862e42) { - t = expm1(absx); - if (w < 0x3ff00000) { - if (w < 0x3ff00000 - (26<<20)) - /* note: inexact and underflow are raised by expm1 */ - /* note: this branch avoids spurious underflow */ - return x; - return h*(2*t - t*t/(t+1)); - } - /* note: |x|>log(0x1p26)+eps could be just h*exp(x) */ - return h*(t + t/(t+1)); - } - - /* |x| > log(DBL_MAX) or nan */ - /* note: the result is stored to handle overflow */ - t = 2*h*__expo2(absx); - return t; -} diff --git a/usr/lib/libc/math/sinhf.c b/usr/lib/libc/math/sinhf.c deleted file mode 100644 index 6ad19ea2b..000000000 --- a/usr/lib/libc/math/sinhf.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "libm.h" - -float sinhf(float x) -{ - union {float f; uint32_t i;} u = {.f = x}; - uint32_t w; - float t, h, absx; - - h = 0.5; - if (u.i >> 31) - h = -h; - /* |x| */ - u.i &= 0x7fffffff; - absx = u.f; - w = u.i; - - /* |x| < log(FLT_MAX) */ - if (w < 0x42b17217) { - t = expm1f(absx); - if (w < 0x3f800000) { - if (w < 0x3f800000 - (12<<23)) - return x; - return h*(2*t - t*t/(t+1)); - } - return h*(t + t/(t+1)); - } - - /* |x| > logf(FLT_MAX) or nan */ - t = 2*h*__expo2f(absx); - return t; -} diff --git a/usr/lib/libc/math/sinhl.c b/usr/lib/libc/math/sinhl.c deleted file mode 100644 index b305d4d2f..000000000 --- a/usr/lib/libc/math/sinhl.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double sinhl(long double x) -{ - return sinh(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -long double sinhl(long double x) -{ - union ldshape u = {x}; - unsigned ex = u.i.se & 0x7fff; - long double h, t, absx; - - h = 0.5; - if (u.i.se & 0x8000) - h = -h; - /* |x| */ - u.i.se = ex; - absx = u.f; - - /* |x| < log(LDBL_MAX) */ - if (ex < 0x3fff+13 || (ex == 0x3fff+13 && u.i.m>>32 < 0xb17217f7)) { - t = expm1l(absx); - if (ex < 0x3fff) { - if (ex < 0x3fff-32) - return x; - return h*(2*t - t*t/(1+t)); - } - return h*(t + t/(t+1)); - } - - /* |x| > log(LDBL_MAX) or nan */ - t = expl(0.5*absx); - return h*t*t; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double sinhl(long double x) -{ - return sinh(x); -} -#endif diff --git a/usr/lib/libc/math/sinl.c b/usr/lib/libc/math/sinl.c deleted file mode 100644 index 9c0b16eed..000000000 --- a/usr/lib/libc/math/sinl.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double sinl(long double x) -{ - return sin(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double sinl(long double x) -{ - union ldshape u = {x}; - unsigned n; - long double y[2], hi, lo; - - u.i.se &= 0x7fff; - if (u.i.se == 0x7fff) - return x - x; - if (u.f < M_PI_4) { - if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) { - /* raise inexact if x!=0 and underflow if subnormal */ - FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f); - return x; - } - return __sinl(x, 0.0, 0); - } - n = __rem_pio2l(x, y); - hi = y[0]; - lo = y[1]; - switch (n & 3) { - case 0: - return __sinl(hi, lo, 1); - case 1: - return __cosl(hi, lo); - case 2: - return -__sinl(hi, lo, 1); - case 3: - default: - return -__cosl(hi, lo); - } -} -#endif diff --git a/usr/lib/libc/math/sqrt.c b/usr/lib/libc/math/sqrt.c deleted file mode 100644 index b27756738..000000000 --- a/usr/lib/libc/math/sqrt.c +++ /dev/null @@ -1,185 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_sqrt.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* sqrt(x) - * Return correctly rounded sqrt. - * ------------------------------------------ - * | Use the hardware sqrt if you have one | - * ------------------------------------------ - * Method: - * Bit by bit method using integer arithmetic. (Slow, but portable) - * 1. Normalization - * Scale x to y in [1,4) with even powers of 2: - * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then - * sqrt(x) = 2^k * sqrt(y) - * 2. Bit by bit computation - * Let q = sqrt(y) truncated to i bit after binary point (q = 1), - * i 0 - * i+1 2 - * s = 2*q , and y = 2 * ( y - q ). (1) - * i i i i - * - * To compute q from q , one checks whether - * i+1 i - * - * -(i+1) 2 - * (q + 2 ) <= y. (2) - * i - * -(i+1) - * If (2) is false, then q = q ; otherwise q = q + 2 . - * i+1 i i+1 i - * - * With some algebric manipulation, it is not difficult to see - * that (2) is equivalent to - * -(i+1) - * s + 2 <= y (3) - * i i - * - * The advantage of (3) is that s and y can be computed by - * i i - * the following recurrence formula: - * if (3) is false - * - * s = s , y = y ; (4) - * i+1 i i+1 i - * - * otherwise, - * -i -(i+1) - * s = s + 2 , y = y - s - 2 (5) - * i+1 i i+1 i i - * - * One may easily use induction to prove (4) and (5). - * Note. Since the left hand side of (3) contain only i+2 bits, - * it does not necessary to do a full (53-bit) comparison - * in (3). - * 3. Final rounding - * After generating the 53 bits result, we compute one more bit. - * Together with the remainder, we can decide whether the - * result is exact, bigger than 1/2ulp, or less than 1/2ulp - * (it will never equal to 1/2ulp). - * The rounding mode can be detected by checking whether - * huge + tiny is equal to huge, and whether huge - tiny is - * equal to huge for some floating point number "huge" and "tiny". - * - * Special cases: - * sqrt(+-0) = +-0 ... exact - * sqrt(inf) = inf - * sqrt(-ve) = NaN ... with invalid signal - * sqrt(NaN) = NaN ... with invalid signal for signaling NaN - */ - -#include "libm.h" - -static const double tiny = 1.0e-300; - -double sqrt(double x) -{ - double z; - int32_t sign = (int)0x80000000; - int32_t ix0,s0,q,m,t,i; - uint32_t r,t1,s1,ix1,q1; - - EXTRACT_WORDS(ix0, ix1, x); - - /* take care of Inf and NaN */ - if ((ix0&0x7ff00000) == 0x7ff00000) { - return x*x + x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf, sqrt(-inf)=sNaN */ - } - /* take care of zero */ - if (ix0 <= 0) { - if (((ix0&~sign)|ix1) == 0) - return x; /* sqrt(+-0) = +-0 */ - if (ix0 < 0) - return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ - } - /* normalize x */ - m = ix0>>20; - if (m == 0) { /* subnormal x */ - while (ix0 == 0) { - m -= 21; - ix0 |= (ix1>>11); - ix1 <<= 21; - } - for (i=0; (ix0&0x00100000) == 0; i++) - ix0<<=1; - m -= i - 1; - ix0 |= ix1>>(32-i); - ix1 <<= i; - } - m -= 1023; /* unbias exponent */ - ix0 = (ix0&0x000fffff)|0x00100000; - if (m & 1) { /* odd m, double x to make it even */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - } - m >>= 1; /* m = [m/2] */ - - /* generate sqrt(x) bit by bit */ - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */ - r = 0x00200000; /* r = moving bit from right to left */ - - while (r != 0) { - t = s0 + r; - if (t <= ix0) { - s0 = t + r; - ix0 -= t; - q += r; - } - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - r >>= 1; - } - - r = sign; - while (r != 0) { - t1 = s1 + r; - t = s0; - if (t < ix0 || (t == ix0 && t1 <= ix1)) { - s1 = t1 + r; - if ((t1&sign) == sign && (s1&sign) == 0) - s0++; - ix0 -= t; - if (ix1 < t1) - ix0--; - ix1 -= t1; - q1 += r; - } - ix0 += ix0 + ((ix1&sign)>>31); - ix1 += ix1; - r >>= 1; - } - - /* use floating add to find out rounding direction */ - if ((ix0|ix1) != 0) { - z = 1.0 - tiny; /* raise inexact flag */ - if (z >= 1.0) { - z = 1.0 + tiny; - if (q1 == (uint32_t)0xffffffff) { - q1 = 0; - q++; - } else if (z > 1.0) { - if (q1 == (uint32_t)0xfffffffe) - q++; - q1 += 2; - } else - q1 += q1 & 1; - } - } - ix0 = (q>>1) + 0x3fe00000; - ix1 = q1>>1; - if (q&1) - ix1 |= sign; - ix0 += m << 20; - INSERT_WORDS(z, ix0, ix1); - return z; -} diff --git a/usr/lib/libc/math/sqrtf.c b/usr/lib/libc/math/sqrtf.c deleted file mode 100644 index 28cb4ad37..000000000 --- a/usr/lib/libc/math/sqrtf.c +++ /dev/null @@ -1,84 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_sqrtf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -static const float tiny = 1.0e-30; - -float sqrtf(float x) -{ - float z; - int32_t sign = (int)0x80000000; - int32_t ix,s,q,m,t,i; - uint32_t r; - - GET_FLOAT_WORD(ix, x); - - /* take care of Inf and NaN */ - if ((ix&0x7f800000) == 0x7f800000) - return x*x + x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf, sqrt(-inf)=sNaN */ - - /* take care of zero */ - if (ix <= 0) { - if ((ix&~sign) == 0) - return x; /* sqrt(+-0) = +-0 */ - if (ix < 0) - return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ - } - /* normalize x */ - m = ix>>23; - if (m == 0) { /* subnormal x */ - for (i = 0; (ix&0x00800000) == 0; i++) - ix<<=1; - m -= i - 1; - } - m -= 127; /* unbias exponent */ - ix = (ix&0x007fffff)|0x00800000; - if (m&1) /* odd m, double x to make it even */ - ix += ix; - m >>= 1; /* m = [m/2] */ - - /* generate sqrt(x) bit by bit */ - ix += ix; - q = s = 0; /* q = sqrt(x) */ - r = 0x01000000; /* r = moving bit from right to left */ - - while (r != 0) { - t = s + r; - if (t <= ix) { - s = t+r; - ix -= t; - q += r; - } - ix += ix; - r >>= 1; - } - - /* use floating add to find out rounding direction */ - if (ix != 0) { - z = 1.0f - tiny; /* raise inexact flag */ - if (z >= 1.0f) { - z = 1.0f + tiny; - if (z > 1.0f) - q += 2; - else - q += q & 1; - } - } - ix = (q>>1) + 0x3f000000; - ix += m << 23; - SET_FLOAT_WORD(z, ix); - return z; -} diff --git a/usr/lib/libc/math/sqrtl.c b/usr/lib/libc/math/sqrtl.c deleted file mode 100644 index 83a8f80c9..000000000 --- a/usr/lib/libc/math/sqrtl.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -long double sqrtl(long double x) -{ - /* FIXME: implement in C, this is for LDBL_MANT_DIG == 64 only */ - return sqrt(x); -} diff --git a/usr/lib/libc/math/tan.c b/usr/lib/libc/math/tan.c deleted file mode 100644 index 9c724a45a..000000000 --- a/usr/lib/libc/math/tan.c +++ /dev/null @@ -1,70 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* tan(x) - * Return tangent function of x. - * - * kernel function: - * __tan ... tangent function on [-pi/4,pi/4] - * __rem_pio2 ... argument reduction routine - * - * Method. - * Let S,C and T denote the sin, cos and tan respectively on - * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 - * in [-pi/4 , +pi/4], and let n = k mod 4. - * We have - * - * n sin(x) cos(x) tan(x) - * ---------------------------------------------------------- - * 0 S C T - * 1 C -S -1/T - * 2 -S -C T - * 3 -C S -1/T - * ---------------------------------------------------------- - * - * Special cases: - * Let trig be any of sin, cos, or tan. - * trig(+-INF) is NaN, with signals; - * trig(NaN) is that NaN; - * - * Accuracy: - * TRIG(x) returns trig(x) nearly rounded - */ - -#include "libm.h" - -double tan(double x) -{ - double y[2]; - uint32_t ix; - unsigned n; - - GET_HIGH_WORD(ix, x); - ix &= 0x7fffffff; - - /* |x| ~< pi/4 */ - if (ix <= 0x3fe921fb) { - if (ix < 0x3e400000) { /* |x| < 2**-27 */ - /* raise inexact if x!=0 and underflow if subnormal */ - FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); - return x; - } - return __tan(x, 0.0, 0); - } - - /* tan(Inf or NaN) is NaN */ - if (ix >= 0x7ff00000) - return x - x; - - /* argument reduction */ - n = __rem_pio2(x, y); - return __tan(y[0], y[1], n&1); -} diff --git a/usr/lib/libc/math/tanf.c b/usr/lib/libc/math/tanf.c deleted file mode 100644 index aba197777..000000000 --- a/usr/lib/libc/math/tanf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_tanf.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ - -#include "libm.h" - -/* Small multiples of pi/2 rounded to double precision. */ -static const double -t1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ -t2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ -t3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ -t4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ - -float tanf(float x) -{ - double y; - uint32_t ix; - unsigned n, sign; - - GET_FLOAT_WORD(ix, x); - sign = ix >> 31; - ix &= 0x7fffffff; - - if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ - if (ix < 0x39800000) { /* |x| < 2**-12 */ - /* raise inexact if x!=0 and underflow if subnormal */ - FORCE_EVAL(ix < 0x00800000 ? x/0x1p120f : x+0x1p120f); - return x; - } - return __tandf(x, 0); - } - if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */ - if (ix <= 0x4016cbe3) /* |x| ~<= 3pi/4 */ - return __tandf((sign ? x+t1pio2 : x-t1pio2), 1); - else - return __tandf((sign ? x+t2pio2 : x-t2pio2), 0); - } - if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */ - if (ix <= 0x40afeddf) /* |x| ~<= 7*pi/4 */ - return __tandf((sign ? x+t3pio2 : x-t3pio2), 1); - else - return __tandf((sign ? x+t4pio2 : x-t4pio2), 0); - } - - /* tan(Inf or NaN) is NaN */ - if (ix >= 0x7f800000) - return x - x; - - /* argument reduction */ - n = __rem_pio2f(x, &y); - return __tandf(y, n&1); -} diff --git a/usr/lib/libc/math/tanh.c b/usr/lib/libc/math/tanh.c deleted file mode 100644 index 20d6dbcf4..000000000 --- a/usr/lib/libc/math/tanh.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "libm.h" - -/* tanh(x) = (exp(x) - exp(-x))/(exp(x) + exp(-x)) - * = (exp(2*x) - 1)/(exp(2*x) - 1 + 2) - * = (1 - exp(-2*x))/(exp(-2*x) - 1 + 2) - */ -double tanh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - uint32_t w; - int sign; - double_t t; - - /* x = |x| */ - sign = u.i >> 63; - u.i &= (uint64_t)-1/2; - x = u.f; - w = u.i >> 32; - - if (w > 0x3fe193ea) { - /* |x| > log(3)/2 ~= 0.5493 or nan */ - if (w > 0x40340000) { - /* |x| > 20 or nan */ - /* note: this branch avoids raising overflow */ - t = 1 - 0/x; - } else { - t = expm1(2*x); - t = 1 - 2/(t+2); - } - } else if (w > 0x3fd058ae) { - /* |x| > log(5/3)/2 ~= 0.2554 */ - t = expm1(2*x); - t = t/(t+2); - } else if (w >= 0x00100000) { - /* |x| >= 0x1p-1022, up to 2ulp error in [0.1,0.2554] */ - t = expm1(-2*x); - t = -t/(t+2); - } else { - /* |x| is subnormal */ - /* note: the branch above would not raise underflow in [0x1p-1023,0x1p-1022) */ - FORCE_EVAL((float)x); - t = x; - } - return sign ? -t : t; -} diff --git a/usr/lib/libc/math/tanhf.c b/usr/lib/libc/math/tanhf.c deleted file mode 100644 index 10636fbd7..000000000 --- a/usr/lib/libc/math/tanhf.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "libm.h" - -float tanhf(float x) -{ - union {float f; uint32_t i;} u = {.f = x}; - uint32_t w; - int sign; - float t; - - /* x = |x| */ - sign = u.i >> 31; - u.i &= 0x7fffffff; - x = u.f; - w = u.i; - - if (w > 0x3f0c9f54) { - /* |x| > log(3)/2 ~= 0.5493 or nan */ - if (w > 0x41200000) { - /* |x| > 10 */ - t = 1 + 0/x; - } else { - t = expm1f(2*x); - t = 1 - 2/(t+2); - } - } else if (w > 0x3e82c578) { - /* |x| > log(5/3)/2 ~= 0.2554 */ - t = expm1f(2*x); - t = t/(t+2); - } else if (w >= 0x00800000) { - /* |x| >= 0x1p-126 */ - t = expm1f(-2*x); - t = -t/(t+2); - } else { - /* |x| is subnormal */ - FORCE_EVAL(x*x); - t = x; - } - return sign ? -t : t; -} diff --git a/usr/lib/libc/math/tanhl.c b/usr/lib/libc/math/tanhl.c deleted file mode 100644 index 4e1aa9f87..000000000 --- a/usr/lib/libc/math/tanhl.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double tanhl(long double x) -{ - return tanh(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -long double tanhl(long double x) -{ - union ldshape u = {x}; - unsigned ex = u.i.se & 0x7fff; - unsigned sign = u.i.se & 0x8000; - uint32_t w; - long double t; - - /* x = |x| */ - u.i.se = ex; - x = u.f; - w = u.i.m >> 32; - - if (ex > 0x3ffe || (ex == 0x3ffe && w > 0x8c9f53d5)) { - /* |x| > log(3)/2 ~= 0.5493 or nan */ - if (ex >= 0x3fff+5) { - /* |x| >= 32 */ - t = 1 + 0/(x + 0x1p-120f); - } else { - t = expm1l(2*x); - t = 1 - 2/(t+2); - } - } else if (ex > 0x3ffd || (ex == 0x3ffd && w > 0x82c577d4)) { - /* |x| > log(5/3)/2 ~= 0.2554 */ - t = expm1l(2*x); - t = t/(t+2); - } else { - /* |x| is small */ - t = expm1l(-2*x); - t = -t/(t+2); - } - return sign ? -t : t; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double tanhl(long double x) -{ - return tanh(x); -} -#endif diff --git a/usr/lib/libc/math/tanl.c b/usr/lib/libc/math/tanl.c deleted file mode 100644 index 6af067127..000000000 --- a/usr/lib/libc/math/tanl.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double tanl(long double x) -{ - return tan(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -long double tanl(long double x) -{ - union ldshape u = {x}; - long double y[2]; - unsigned n; - - u.i.se &= 0x7fff; - if (u.i.se == 0x7fff) - return x - x; - if (u.f < M_PI_4) { - if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) { - /* raise inexact if x!=0 and underflow if subnormal */ - FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f); - return x; - } - return __tanl(x, 0, 0); - } - n = __rem_pio2l(x, y); - return __tanl(y[0], y[1], n&1); -} -#endif diff --git a/usr/lib/libc/math/tgamma.c b/usr/lib/libc/math/tgamma.c deleted file mode 100644 index 28f6e0f83..000000000 --- a/usr/lib/libc/math/tgamma.c +++ /dev/null @@ -1,222 +0,0 @@ -/* -"A Precision Approximation of the Gamma Function" - Cornelius Lanczos (1964) -"Lanczos Implementation of the Gamma Function" - Paul Godfrey (2001) -"An Analysis of the Lanczos Gamma Approximation" - Glendon Ralph Pugh (2004) - -approximation method: - - (x - 0.5) S(x) -Gamma(x) = (x + g - 0.5) * ---------------- - exp(x + g - 0.5) - -with - a1 a2 a3 aN -S(x) ~= [ a0 + ----- + ----- + ----- + ... + ----- ] - x + 1 x + 2 x + 3 x + N - -with a0, a1, a2, a3,.. aN constants which depend on g. - -for x < 0 the following reflection formula is used: - -Gamma(x)*Gamma(-x) = -pi/(x sin(pi x)) - -most ideas and constants are from boost and python -*/ -#include "libm.h" - -static const double pi = 3.141592653589793238462643383279502884; - -/* sin(pi x) with x > 0x1p-100, if sin(pi*x)==0 the sign is arbitrary */ -static double sinpi(double x) -{ - int n; - - /* argument reduction: x = |x| mod 2 */ - /* spurious inexact when x is odd int */ - x = x * 0.5; - x = 2 * (x - floor(x)); - - /* reduce x into [-.25,.25] */ - n = 4 * x; - n = (n+1)/2; - x -= n * 0.5; - - x *= pi; - switch (n) { - default: /* case 4 */ - case 0: - return __sin(x, 0, 0); - case 1: - return __cos(x, 0); - case 2: - return __sin(-x, 0, 0); - case 3: - return -__cos(x, 0); - } -} - -#define N 12 -//static const double g = 6.024680040776729583740234375; -static const double gmhalf = 5.524680040776729583740234375; -static const double Snum[N+1] = { - 23531376880.410759688572007674451636754734846804940, - 42919803642.649098768957899047001988850926355848959, - 35711959237.355668049440185451547166705960488635843, - 17921034426.037209699919755754458931112671403265390, - 6039542586.3520280050642916443072979210699388420708, - 1439720407.3117216736632230727949123939715485786772, - 248874557.86205415651146038641322942321632125127801, - 31426415.585400194380614231628318205362874684987640, - 2876370.6289353724412254090516208496135991145378768, - 186056.26539522349504029498971604569928220784236328, - 8071.6720023658162106380029022722506138218516325024, - 210.82427775157934587250973392071336271166969580291, - 2.5066282746310002701649081771338373386264310793408, -}; -static const double Sden[N+1] = { - 0, 39916800, 120543840, 150917976, 105258076, 45995730, 13339535, - 2637558, 357423, 32670, 1925, 66, 1, -}; -/* n! for small integer n */ -static const double fact[] = { - 1, 1, 2, 6, 24, 120, 720, 5040.0, 40320.0, 362880.0, 3628800.0, 39916800.0, - 479001600.0, 6227020800.0, 87178291200.0, 1307674368000.0, 20922789888000.0, - 355687428096000.0, 6402373705728000.0, 121645100408832000.0, - 2432902008176640000.0, 51090942171709440000.0, 1124000727777607680000.0, -}; - -/* S(x) rational function for positive x */ -static double S(double x) -{ - double_t num = 0, den = 0; - int i; - - /* to avoid overflow handle large x differently */ - if (x < 8) - for (i = N; i >= 0; i--) { - num = num * x + Snum[i]; - den = den * x + Sden[i]; - } - else - for (i = 0; i <= N; i++) { - num = num / x + Snum[i]; - den = den / x + Sden[i]; - } - return num/den; -} - -double tgamma(double x) -{ - union {double f; uint64_t i;} u = {x}; - double absx, y; - double_t dy, z, r; - uint32_t ix = u.i>>32 & 0x7fffffff; - int sign = u.i>>63; - - /* special cases */ - if (ix >= 0x7ff00000) - /* tgamma(nan)=nan, tgamma(inf)=inf, tgamma(-inf)=nan with invalid */ - return x + INFINITY; - if (ix < (0x3ff-54)<<20) - /* |x| < 2^-54: tgamma(x) ~ 1/x, +-0 raises div-by-zero */ - return 1/x; - - /* integer arguments */ - /* raise inexact when non-integer */ - if (x == floor(x)) { - if (sign) - return 0/0.0; - if (x <= sizeof fact/sizeof *fact) - return fact[(int)x - 1]; - } - - /* x >= 172: tgamma(x)=inf with overflow */ - /* x =< -184: tgamma(x)=+-0 with underflow */ - if (ix >= 0x40670000) { /* |x| >= 184 */ - if (sign) { - FORCE_EVAL((float)(0x1p-126/x)); - if (floor(x) * 0.5 == floor(x * 0.5)) - return 0; - return -0.0; - } - x *= 0x1p1023; - return x; - } - - absx = sign ? -x : x; - - /* handle the error of x + g - 0.5 */ - y = absx + gmhalf; - if (absx > gmhalf) { - dy = y - absx; - dy -= gmhalf; - } else { - dy = y - gmhalf; - dy -= absx; - } - - z = absx - 0.5; - r = S(absx) * exp(-y); - if (x < 0) { - /* reflection formula for negative x */ - /* sinpi(absx) is not 0, integers are already handled */ - r = -pi / (sinpi(absx) * absx * r); - dy = -dy; - z = -z; - } - r += dy * (gmhalf+0.5) * r / y; - z = pow(y, 0.5*z); - y = r * z * z; - return y; -} - -#if 0 -double __lgamma_r(double x, int *sign) -{ - double r, absx; - - *sign = 1; - - /* special cases */ - if (!isfinite(x)) - /* lgamma(nan)=nan, lgamma(+-inf)=inf */ - return x*x; - - /* integer arguments */ - if (x == floor(x) && x <= 2) { - /* n <= 0: lgamma(n)=inf with divbyzero */ - /* n == 1,2: lgamma(n)=0 */ - if (x <= 0) - return 1/0.0; - return 0; - } - - absx = fabs(x); - - /* lgamma(x) ~ -log(|x|) for tiny |x| */ - if (absx < 0x1p-54) { - *sign = 1 - 2*!!signbit(x); - return -log(absx); - } - - /* use tgamma for smaller |x| */ - if (absx < 128) { - x = tgamma(x); - *sign = 1 - 2*!!signbit(x); - return log(fabs(x)); - } - - /* second term (log(S)-g) could be more precise here.. */ - /* or with stirling: (|x|-0.5)*(log(|x|)-1) + poly(1/|x|) */ - r = (absx-0.5)*(log(absx+gmhalf)-1) + (log(S(absx)) - (gmhalf+0.5)); - if (x < 0) { - /* reflection formula for negative x */ - x = sinpi(absx); - *sign = 2*!!signbit(x) - 1; - r = log(pi/(fabs(x)*absx)) - r; - } - return r; -} - -weak_alias(__lgamma_r, lgamma_r); -#endif diff --git a/usr/lib/libc/math/tgammaf.c b/usr/lib/libc/math/tgammaf.c deleted file mode 100644 index b4ca51c9f..000000000 --- a/usr/lib/libc/math/tgammaf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -float tgammaf(float x) -{ - return tgamma(x); -} diff --git a/usr/lib/libc/math/tgammal.c b/usr/lib/libc/math/tgammal.c deleted file mode 100644 index 5336c5b19..000000000 --- a/usr/lib/libc/math/tgammal.c +++ /dev/null @@ -1,281 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_tgammal.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Gamma function - * - * - * SYNOPSIS: - * - * long double x, y, tgammal(); - * - * y = tgammal( x ); - * - * - * DESCRIPTION: - * - * Returns gamma function of the argument. The result is - * correctly signed. - * - * Arguments |x| <= 13 are reduced by recurrence and the function - * approximated by a rational function of degree 7/8 in the - * interval (2,3). Large arguments are handled by Stirling's - * formula. Large negative arguments are made positive using - * a reflection formula. - * - * - * ACCURACY: - * - * Relative error: - * arithmetic domain # trials peak rms - * IEEE -40,+40 10000 3.6e-19 7.9e-20 - * IEEE -1755,+1755 10000 4.8e-18 6.5e-19 - * - * Accuracy for large arguments is dominated by error in powl(). - * - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double tgammal(long double x) -{ - return tgamma(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 -/* -tgamma(x+2) = tgamma(x+2) P(x)/Q(x) -0 <= x <= 1 -Relative error -n=7, d=8 -Peak error = 1.83e-20 -Relative error spread = 8.4e-23 -*/ -static const long double P[8] = { - 4.212760487471622013093E-5L, - 4.542931960608009155600E-4L, - 4.092666828394035500949E-3L, - 2.385363243461108252554E-2L, - 1.113062816019361559013E-1L, - 3.629515436640239168939E-1L, - 8.378004301573126728826E-1L, - 1.000000000000000000009E0L, -}; -static const long double Q[9] = { --1.397148517476170440917E-5L, - 2.346584059160635244282E-4L, --1.237799246653152231188E-3L, --7.955933682494738320586E-4L, - 2.773706565840072979165E-2L, --4.633887671244534213831E-2L, --2.243510905670329164562E-1L, - 4.150160950588455434583E-1L, - 9.999999999999999999908E-1L, -}; - -/* -static const long double P[] = { --3.01525602666895735709e0L, --3.25157411956062339893e1L, --2.92929976820724030353e2L, --1.70730828800510297666e3L, --7.96667499622741999770e3L, --2.59780216007146401957e4L, --5.99650230220855581642e4L, --7.15743521530849602425e4L -}; -static const long double Q[] = { - 1.00000000000000000000e0L, --1.67955233807178858919e1L, - 8.85946791747759881659e1L, - 5.69440799097468430177e1L, --1.98526250512761318471e3L, - 3.31667508019495079814e3L, - 1.60577839621734713377e4L, --2.97045081369399940529e4L, --7.15743521530849602412e4L -}; -*/ -#define MAXGAML 1755.455L -/*static const long double LOGPI = 1.14472988584940017414L;*/ - -/* Stirling's formula for the gamma function -tgamma(x) = sqrt(2 pi) x^(x-.5) exp(-x) (1 + 1/x P(1/x)) -z(x) = x -13 <= x <= 1024 -Relative error -n=8, d=0 -Peak error = 9.44e-21 -Relative error spread = 8.8e-4 -*/ -static const long double STIR[9] = { - 7.147391378143610789273E-4L, --2.363848809501759061727E-5L, --5.950237554056330156018E-4L, - 6.989332260623193171870E-5L, - 7.840334842744753003862E-4L, --2.294719747873185405699E-4L, --2.681327161876304418288E-3L, - 3.472222222230075327854E-3L, - 8.333333333333331800504E-2L, -}; - -#define MAXSTIR 1024.0L -static const long double SQTPI = 2.50662827463100050242E0L; - -/* 1/tgamma(x) = z P(z) - * z(x) = 1/x - * 0 < x < 0.03125 - * Peak relative error 4.2e-23 - */ -static const long double S[9] = { --1.193945051381510095614E-3L, - 7.220599478036909672331E-3L, --9.622023360406271645744E-3L, --4.219773360705915470089E-2L, - 1.665386113720805206758E-1L, --4.200263503403344054473E-2L, --6.558780715202540684668E-1L, - 5.772156649015328608253E-1L, - 1.000000000000000000000E0L, -}; - -/* 1/tgamma(-x) = z P(z) - * z(x) = 1/x - * 0 < x < 0.03125 - * Peak relative error 5.16e-23 - * Relative error spread = 2.5e-24 - */ -static const long double SN[9] = { - 1.133374167243894382010E-3L, - 7.220837261893170325704E-3L, - 9.621911155035976733706E-3L, --4.219773343731191721664E-2L, --1.665386113944413519335E-1L, --4.200263503402112910504E-2L, - 6.558780715202536547116E-1L, - 5.772156649015328608727E-1L, --1.000000000000000000000E0L, -}; - -static const long double PIL = 3.1415926535897932384626L; - -/* Gamma function computed by Stirling's formula. - */ -static long double stirf(long double x) -{ - long double y, w, v; - - w = 1.0/x; - /* For large x, use rational coefficients from the analytical expansion. */ - if (x > 1024.0) - w = (((((6.97281375836585777429E-5L * w - + 7.84039221720066627474E-4L) * w - - 2.29472093621399176955E-4L) * w - - 2.68132716049382716049E-3L) * w - + 3.47222222222222222222E-3L) * w - + 8.33333333333333333333E-2L) * w - + 1.0; - else - w = 1.0 + w * __polevll(w, STIR, 8); - y = expl(x); - if (x > MAXSTIR) { /* Avoid overflow in pow() */ - v = powl(x, 0.5L * x - 0.25L); - y = v * (v / y); - } else { - y = powl(x, x - 0.5L) / y; - } - y = SQTPI * y * w; - return y; -} - -long double tgammal(long double x) -{ - long double p, q, z; - - if (!isfinite(x)) - return x + INFINITY; - - q = fabsl(x); - if (q > 13.0) { - if (x < 0.0) { - p = floorl(q); - z = q - p; - if (z == 0) - return 0 / z; - if (q > MAXGAML) { - z = 0; - } else { - if (z > 0.5) { - p += 1.0; - z = q - p; - } - z = q * sinl(PIL * z); - z = fabsl(z) * stirf(q); - z = PIL/z; - } - if (0.5 * p == floorl(q * 0.5)) - z = -z; - } else if (x > MAXGAML) { - z = x * 0x1p16383L; - } else { - z = stirf(x); - } - return z; - } - - z = 1.0; - while (x >= 3.0) { - x -= 1.0; - z *= x; - } - while (x < -0.03125L) { - z /= x; - x += 1.0; - } - if (x <= 0.03125L) - goto small; - while (x < 2.0) { - z /= x; - x += 1.0; - } - if (x == 2.0) - return z; - - x -= 2.0; - p = __polevll(x, P, 7); - q = __polevll(x, Q, 8); - z = z * p / q; - return z; - -small: - /* z==1 if x was originally +-0 */ - if (x == 0 && z != 1) - return x / x; - if (x < 0.0) { - x = -x; - q = z / (x * __polevll(x, SN, 8)); - } else - q = z / (x * __polevll(x, S, 8)); - return q; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double tgammal(long double x) -{ - return tgamma(x); -} -#endif diff --git a/usr/lib/libc/math/trunc.c b/usr/lib/libc/math/trunc.c deleted file mode 100644 index d13711b50..000000000 --- a/usr/lib/libc/math/trunc.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "libm.h" - -double trunc(double x) -{ - union {double f; uint64_t i;} u = {x}; - int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12; - uint64_t m; - - if (e >= 52 + 12) - return x; - if (e < 12) - e = 1; - m = -1ULL >> e; - if ((u.i & m) == 0) - return x; - FORCE_EVAL(x + 0x1p120f); - u.i &= ~m; - return u.f; -} diff --git a/usr/lib/libc/math/truncf.c b/usr/lib/libc/math/truncf.c deleted file mode 100644 index 1a7d03c3b..000000000 --- a/usr/lib/libc/math/truncf.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "libm.h" - -float truncf(float x) -{ - union {float f; uint32_t i;} u = {x}; - int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9; - uint32_t m; - - if (e >= 23 + 9) - return x; - if (e < 9) - e = 1; - m = -1U >> e; - if ((u.i & m) == 0) - return x; - FORCE_EVAL(x + 0x1p120f); - u.i &= ~m; - return u.f; -} diff --git a/usr/lib/libc/math/truncl.c b/usr/lib/libc/math/truncl.c deleted file mode 100644 index f07b19340..000000000 --- a/usr/lib/libc/math/truncl.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double truncl(long double x) -{ - return trunc(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - -static const long double toint = 1/LDBL_EPSILON; - -long double truncl(long double x) -{ - union ldshape u = {x}; - int e = u.i.se & 0x7fff; - int s = u.i.se >> 15; - long double y; - - if (e >= 0x3fff+LDBL_MANT_DIG-1) - return x; - if (e <= 0x3fff-1) { - FORCE_EVAL(x + 0x1p120f); - return x*0; - } - /* y = int(|x|) - |x|, where int(|x|) is an integer neighbor of |x| */ - if (s) - x = -x; - y = x + toint - toint - x; - if (y > 0) - y -= 1; - x += y; - return s ? -x : x; -} -#endif diff --git a/usr/lib/libc/mbsinit.c b/usr/lib/libc/mbsinit.c deleted file mode 100644 index c608194a0..000000000 --- a/usr/lib/libc/mbsinit.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int mbsinit(const mbstate_t *st) -{ - return !st || !*(unsigned *)st; -} diff --git a/usr/lib/libc/misc/CMakeLists.txt b/usr/lib/libc/misc/CMakeLists.txt deleted file mode 100644 index ef3737bd1..000000000 --- a/usr/lib/libc/misc/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -target_sources(c - PRIVATE - ioctl.c - stat.c -) diff --git a/usr/lib/libc/misc/a64l.c b/usr/lib/libc/misc/a64l.c deleted file mode 100644 index 605577104..000000000 --- a/usr/lib/libc/misc/a64l.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -static const char digits[] = - "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -long a64l(const char *s) -{ - int e; - uint32_t x = 0; - for (e=0; e<36 && *s; e+=6, s++) { - const char *d = strchr(digits, *s); - if (!d) break; - x |= (uint32_t)(d-digits)<>=6) - *p = digits[x&63]; - *p = 0; - return s; -} diff --git a/usr/lib/libc/misc/basename.c b/usr/lib/libc/misc/basename.c deleted file mode 100644 index cc4f778c5..000000000 --- a/usr/lib/libc/misc/basename.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include "libc.h" - -char *basename(char *s) -{ - size_t i; - if (!s || !*s) return "."; - i = strlen(s)-1; - for (; i&&s[i]=='/'; i--) s[i] = 0; - for (; i&&s[i-1]!='/'; i--); - return s+i; -} - -weak_alias(basename, __xpg_basename); diff --git a/usr/lib/libc/misc/dirname.c b/usr/lib/libc/misc/dirname.c deleted file mode 100644 index dd570883d..000000000 --- a/usr/lib/libc/misc/dirname.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -char *dirname(char *s) -{ - size_t i; - if (!s || !*s) return "."; - i = strlen(s)-1; - for (; s[i]=='/'; i--) if (!i) return "/"; - for (; s[i]!='/'; i--) if (!i) return "."; - for (; s[i]=='/'; i--) if (!i) return "/"; - s[i+1] = 0; - return s; -} diff --git a/usr/lib/libc/misc/ffs.c b/usr/lib/libc/misc/ffs.c deleted file mode 100644 index 673ce5a97..000000000 --- a/usr/lib/libc/misc/ffs.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "atomic.h" - -int ffs(int i) -{ - return i ? a_ctz_l(i)+1 : 0; -} diff --git a/usr/lib/libc/misc/ffsl.c b/usr/lib/libc/misc/ffsl.c deleted file mode 100644 index 0105c66af..000000000 --- a/usr/lib/libc/misc/ffsl.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "atomic.h" - -int ffsl(long i) -{ - return i ? a_ctz_l(i)+1 : 0; -} diff --git a/usr/lib/libc/misc/ffsll.c b/usr/lib/libc/misc/ffsll.c deleted file mode 100644 index 0c5ced826..000000000 --- a/usr/lib/libc/misc/ffsll.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "atomic.h" - -int ffsll(long long i) -{ - return i ? a_ctz_64(i)+1 : 0; -} diff --git a/usr/lib/libc/misc/fmtmsg.c b/usr/lib/libc/misc/fmtmsg.c deleted file mode 100644 index 69170b254..000000000 --- a/usr/lib/libc/misc/fmtmsg.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Public domain fmtmsg() - * Written by Isaac Dunham, 2014 - */ -#include -#include -#include -#include -#include -#include -#include - -/* - * If lstr is the first part of bstr, check that the next char in bstr - * is either \0 or : - */ -static int _strcolcmp(const char *lstr, const char *bstr) -{ - size_t i = 0; - while (lstr[i] && bstr[i] && (bstr[i] == lstr[i])) i++; - if ( lstr[i] || (bstr[i] && bstr[i] != ':')) return 1; - return 0; -} - -int fmtmsg(long classification, const char *label, int severity, - const char *text, const char *action, const char *tag) -{ - int ret = 0, i, consolefd, verb = 0; - char *errstring = MM_NULLSEV, *cmsg = getenv("MSGVERB"); - char *const msgs[] = { - "label", "severity", "text", "action", "tag", NULL - }; - int cs; - - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - - if (severity == MM_HALT) errstring = "HALT: "; - else if (severity == MM_ERROR) errstring = "ERROR: "; - else if (severity == MM_WARNING) errstring = "WARNING: "; - else if (severity == MM_INFO) errstring = "INFO: "; - - if (classification & MM_CONSOLE) { - consolefd = open("/dev/console", O_WRONLY); - if (consolefd < 0) { - ret = MM_NOCON; - } else { - if (dprintf(consolefd, "%s%s%s%s%s%s%s%s\n", - label?label:"", label?": ":"", - severity?errstring:"", text?text:"", - action?"\nTO FIX: ":"", - action?action:"", action?" ":"", - tag?tag:"" )<1) - ret = MM_NOCON; - close(consolefd); - } - } - - if (classification & MM_PRINT) { - while (cmsg && cmsg[0]) { - for(i=0; msgs[i]; i++) { - if (!_strcolcmp(msgs[i], cmsg)) break; - } - if (msgs[i] == NULL) { - //ignore MSGVERB-unrecognized component - verb = 0xFF; - break; - } else { - verb |= (1 << i); - cmsg = strchr(cmsg, ':'); - if (cmsg) cmsg++; - } - } - if (!verb) verb = 0xFF; - if (dprintf(2, "%s%s%s%s%s%s%s%s\n", - (verb&1 && label) ? label : "", - (verb&1 && label) ? ": " : "", - (verb&2 && severity) ? errstring : "", - (verb&4 && text) ? text : "", - (verb&8 && action) ? "\nTO FIX: " : "", - (verb&8 && action) ? action : "", - (verb&8 && action) ? " " : "", - (verb&16 && tag) ? tag : "" ) < 1) - ret |= MM_NOMSG; - } - if ((ret & (MM_NOCON|MM_NOMSG)) == (MM_NOCON|MM_NOMSG)) - ret = MM_NOTOK; - - pthread_setcancelstate(cs, 0); - - return ret; -} diff --git a/usr/lib/libc/misc/forkpty.c b/usr/lib/libc/misc/forkpty.c deleted file mode 100644 index caf13adbf..000000000 --- a/usr/lib/libc/misc/forkpty.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws) -{ - int m, s, ec=0, p[2], cs; - pid_t pid=-1; - sigset_t set, oldset; - - if (openpty(&m, &s, name, tio, ws) < 0) return -1; - - sigfillset(&set); - pthread_sigmask(SIG_BLOCK, &set, &oldset); - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - - if (pipe2(p, O_CLOEXEC)) { - close(s); - goto out; - } - - pid = fork(); - if (!pid) { - close(m); - close(p[0]); - if (login_tty(s)) { - write(p[1], &errno, sizeof errno); - _exit(127); - } - close(p[1]); - pthread_setcancelstate(cs, 0); - pthread_sigmask(SIG_SETMASK, &oldset, 0); - return 0; - } - close(s); - close(p[1]); - if (read(p[0], &ec, sizeof ec) > 0) { - int status; - waitpid(pid, &status, 0); - pid = -1; - errno = ec; - } - close(p[0]); - -out: - if (pid > 0) *pm = m; - else close(m); - - pthread_setcancelstate(cs, 0); - pthread_sigmask(SIG_SETMASK, &oldset, 0); - - return pid; -} diff --git a/usr/lib/libc/misc/get_current_dir_name.c b/usr/lib/libc/misc/get_current_dir_name.c deleted file mode 100644 index 782cddcd8..000000000 --- a/usr/lib/libc/misc/get_current_dir_name.c +++ /dev/null @@ -1,15 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include - -char *get_current_dir_name(void) { - struct stat a, b; - char *res = getenv("PWD"); - if (res && *res && !stat(res, &a) && !stat(".", &b) - && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino)) - return strdup(res); - return getcwd(0, 0); -} diff --git a/usr/lib/libc/misc/getauxval.c b/usr/lib/libc/misc/getauxval.c deleted file mode 100644 index b846c80fd..000000000 --- a/usr/lib/libc/misc/getauxval.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "libc.h" - -unsigned long getauxval(unsigned long item) -{ - size_t *auxv = libc.auxv; - if (item == AT_SECURE) return libc.secure; - for (; *auxv; auxv+=2) - if (*auxv==item) return auxv[1]; - errno = ENOENT; - return 0; -} diff --git a/usr/lib/libc/misc/getdomainname.c b/usr/lib/libc/misc/getdomainname.c deleted file mode 100644 index 59df566d9..000000000 --- a/usr/lib/libc/misc/getdomainname.c +++ /dev/null @@ -1,17 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include - -int getdomainname(char *name, size_t len) -{ - struct utsname temp; - uname(&temp); - if (!len || strlen(temp.domainname) >= len) { - errno = EINVAL; - return -1; - } - strcpy(name, temp.domainname); - return 0; -} diff --git a/usr/lib/libc/misc/gethostid.c b/usr/lib/libc/misc/gethostid.c deleted file mode 100644 index ea65611ab..000000000 --- a/usr/lib/libc/misc/gethostid.c +++ /dev/null @@ -1,4 +0,0 @@ -long gethostid() -{ - return 0; -} diff --git a/usr/lib/libc/misc/getopt.c b/usr/lib/libc/misc/getopt.c deleted file mode 100644 index e9bab41cc..000000000 --- a/usr/lib/libc/misc/getopt.c +++ /dev/null @@ -1,104 +0,0 @@ -#include -#include -#include -#include -#include -#include "libc.h" -#include "locale_impl.h" - -char *optarg; -int optind=1, opterr=1, optopt, __optpos, __optreset=0; - -#define optpos __optpos -weak_alias(__optreset, optreset); - -void __getopt_msg(const char *a, const char *b, const char *c, size_t l) -{ - FILE *f = stderr; - b = __lctrans_cur(b); - flockfile(f); - fputs(a, f)>=0 - && fwrite(b, strlen(b), 1, f) - && fwrite(c, 1, l, f)==l - && putc('\n', f); - funlockfile(f); -} - -int getopt(int argc, char * const argv[], const char *optstring) -{ - int i; - wchar_t c, d; - int k, l; - char *optchar; - - if (!optind || __optreset) { - __optreset = 0; - __optpos = 0; - optind = 1; - } - - if (optind >= argc || !argv[optind]) - return -1; - - if (argv[optind][0] != '-') { - if (optstring[0] == '-') { - optarg = argv[optind++]; - return 1; - } - return -1; - } - - if (!argv[optind][1]) - return -1; - - if (argv[optind][1] == '-' && !argv[optind][2]) - return optind++, -1; - - if (!optpos) optpos++; - if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) { - k = 1; - c = 0xfffd; /* replacement char */ - } - optchar = argv[optind]+optpos; - optpos += k; - - if (!argv[optind][optpos]) { - optind++; - optpos = 0; - } - - if (optstring[0] == '-' || optstring[0] == '+') - optstring++; - - i = 0; - d = 0; - do { - l = mbtowc(&d, optstring+i, MB_LEN_MAX); - if (l>0) i+=l; else i++; - } while (l && d != c); - - if (d != c) { - optopt = c; - if (optstring[0] != ':' && opterr) - __getopt_msg(argv[0], ": unrecognized option: ", optchar, k); - return '?'; - } - if (optstring[i] == ':') { - if (optstring[i+1] == ':') optarg = 0; - else if (optind >= argc) { - optopt = c; - if (optstring[0] == ':') return ':'; - if (opterr) __getopt_msg(argv[0], - ": option requires an argument: ", - optchar, k); - return '?'; - } - if (optstring[i+1] != ':' || optpos) { - optarg = argv[optind++] + optpos; - optpos = 0; - } - } - return c; -} - -weak_alias(getopt, __posix_getopt); diff --git a/usr/lib/libc/misc/getopt_long.c b/usr/lib/libc/misc/getopt_long.c deleted file mode 100644 index 568ae7ba9..000000000 --- a/usr/lib/libc/misc/getopt_long.c +++ /dev/null @@ -1,133 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include - -extern int __optpos, __optreset; - -static void permute(char *const *argv, int dest, int src) -{ - char **av = (char **)argv; - char *tmp = av[src]; - int i; - for (i=src; i>dest; i--) - av[i] = av[i-1]; - av[dest] = tmp; -} - -void __getopt_msg(const char *, const char *, const char *, size_t); - -static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly); - -static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) -{ - int ret, skipped, resumed; - if (!optind || __optreset) { - __optreset = 0; - __optpos = 0; - optind = 1; - } - if (optind >= argc || !argv[optind]) return -1; - skipped = optind; - if (optstring[0] != '+' && optstring[0] != '-') { - int i; - for (i=optind; ; i++) { - if (i >= argc || !argv[i]) return -1; - if (argv[i][0] == '-' && argv[i][1]) break; - } - optind = i; - } - resumed = optind; - ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly); - if (resumed > skipped) { - int i, cnt = optind-resumed; - for (i=0; i -#include "syscall.h" - -int getpriority(int which, id_t who) -{ - int ret = syscall(SYS_getpriority, which, who); - if (ret < 0) return ret; - return 20-ret; -} diff --git a/usr/lib/libc/misc/getresgid.c b/usr/lib/libc/misc/getresgid.c deleted file mode 100644 index d00d9a99d..000000000 --- a/usr/lib/libc/misc/getresgid.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" - -int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid) -{ - return syscall(SYS_getresgid, rgid, egid, sgid); -} diff --git a/usr/lib/libc/misc/getresuid.c b/usr/lib/libc/misc/getresuid.c deleted file mode 100644 index d75d5d408..000000000 --- a/usr/lib/libc/misc/getresuid.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" - -int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid) -{ - return syscall(SYS_getresuid, ruid, euid, suid); -} diff --git a/usr/lib/libc/misc/getrlimit.c b/usr/lib/libc/misc/getrlimit.c deleted file mode 100644 index b073677f1..000000000 --- a/usr/lib/libc/misc/getrlimit.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0) - -int getrlimit(int resource, struct rlimit *rlim) -{ - unsigned long k_rlim[2]; - int ret = syscall(SYS_prlimit64, 0, resource, 0, rlim); - if (!ret) { - FIX(rlim->rlim_cur); - FIX(rlim->rlim_max); - } - if (!ret || errno != ENOSYS) - return ret; - if (syscall(SYS_getrlimit, resource, k_rlim) < 0) - return -1; - rlim->rlim_cur = k_rlim[0] == -1UL ? RLIM_INFINITY : k_rlim[0]; - rlim->rlim_max = k_rlim[1] == -1UL ? RLIM_INFINITY : k_rlim[1]; - FIX(rlim->rlim_cur); - FIX(rlim->rlim_max); - return 0; -} - -LFS64(getrlimit); diff --git a/usr/lib/libc/misc/getrusage.c b/usr/lib/libc/misc/getrusage.c deleted file mode 100644 index 0aaf0ac72..000000000 --- a/usr/lib/libc/misc/getrusage.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getrusage(int who, struct rusage *ru) -{ - return syscall(SYS_getrusage, who, ru); -} diff --git a/usr/lib/libc/misc/getsubopt.c b/usr/lib/libc/misc/getsubopt.c deleted file mode 100644 index 53ee9573f..000000000 --- a/usr/lib/libc/misc/getsubopt.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -int getsubopt(char **opt, char *const *keys, char **val) -{ - char *s = *opt; - int i; - - *val = NULL; - *opt = strchr(s, ','); - if (*opt) *(*opt)++ = 0; - else *opt = s + strlen(s); - - for (i=0; keys[i]; i++) { - size_t l = strlen(keys[i]); - if (strncmp(keys[i], s, l)) continue; - if (s[l] == '=') - *val = s + l + 1; - else if (s[l]) continue; - return i; - } - return -1; -} diff --git a/usr/lib/libc/misc/initgroups.c b/usr/lib/libc/misc/initgroups.c deleted file mode 100644 index 922a95814..000000000 --- a/usr/lib/libc/misc/initgroups.c +++ /dev/null @@ -1,11 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -int initgroups(const char *user, gid_t gid) -{ - gid_t groups[NGROUPS_MAX]; - int count = NGROUPS_MAX; - if (getgrouplist(user, gid, groups, &count) < 0) return -1; - return setgroups(count, groups); -} diff --git a/usr/lib/libc/misc/ioctl.c b/usr/lib/libc/misc/ioctl.c deleted file mode 100644 index 46841bacc..000000000 --- a/usr/lib/libc/misc/ioctl.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include - -int ioctl(int fd, int req, ...) -{ - void *arg; - va_list ap; - va_start(ap, req); - arg = va_arg(ap, void *); - va_end(ap); - return __syscall_ret(sys_ioctl(fd, req, arg)); -#if 0 - return syscall(SYS_ioctl, fd, req, arg); -#endif -} diff --git a/usr/lib/libc/misc/issetugid.c b/usr/lib/libc/misc/issetugid.c deleted file mode 100644 index 6ffd9300d..000000000 --- a/usr/lib/libc/misc/issetugid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "libc.h" - -int issetugid(void) -{ - return libc.secure; -} diff --git a/usr/lib/libc/misc/lockf.c b/usr/lib/libc/misc/lockf.c deleted file mode 100644 index d8f82efd3..000000000 --- a/usr/lib/libc/misc/lockf.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include "libc.h" - -int lockf(int fd, int op, off_t size) -{ - struct flock l = { - .l_type = F_WRLCK, - .l_whence = SEEK_CUR, - .l_len = size, - }; - switch (op) { - case F_TEST: - l.l_type = F_RDLCK; - if (fcntl(fd, F_GETLK, &l) < 0) - return -1; - if (l.l_type == F_UNLCK || l.l_pid == getpid()) - return 0; - errno = EACCES; - return -1; - case F_ULOCK: - l.l_type = F_UNLCK; - case F_TLOCK: - return fcntl(fd, F_SETLK, &l); - case F_LOCK: - return fcntl(fd, F_SETLKW, &l); - } - errno = EINVAL; - return -1; -} - -LFS64(lockf); diff --git a/usr/lib/libc/misc/login_tty.c b/usr/lib/libc/misc/login_tty.c deleted file mode 100644 index f0be0a09a..000000000 --- a/usr/lib/libc/misc/login_tty.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -int login_tty(int fd) -{ - setsid(); - if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1; - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - if (fd>2) close(fd); - return 0; -} diff --git a/usr/lib/libc/misc/mntent.c b/usr/lib/libc/misc/mntent.c deleted file mode 100644 index eabb8200b..000000000 --- a/usr/lib/libc/misc/mntent.c +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include -#include - -static char *internal_buf; -static size_t internal_bufsize; - -#define SENTINEL (char *)&internal_buf - -FILE *setmntent(const char *name, const char *mode) -{ - return fopen(name, mode); -} - -int endmntent(FILE *f) -{ - if (f) fclose(f); - return 1; -} - -struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen) -{ - int cnt, n[8], use_internal = (linebuf == SENTINEL); - - mnt->mnt_freq = 0; - mnt->mnt_passno = 0; - - do { - if (use_internal) { - getline(&internal_buf, &internal_bufsize, f); - linebuf = internal_buf; - } else { - fgets(linebuf, buflen, f); - } - if (feof(f) || ferror(f)) return 0; - if (!strchr(linebuf, '\n')) { - fscanf(f, "%*[^\n]%*[\n]"); - errno = ERANGE; - return 0; - } - cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d", - n, n+1, n+2, n+3, n+4, n+5, n+6, n+7, - &mnt->mnt_freq, &mnt->mnt_passno); - } while (cnt < 2 || linebuf[n[0]] == '#'); - - linebuf[n[1]] = 0; - linebuf[n[3]] = 0; - linebuf[n[5]] = 0; - linebuf[n[7]] = 0; - - mnt->mnt_fsname = linebuf+n[0]; - mnt->mnt_dir = linebuf+n[2]; - mnt->mnt_type = linebuf+n[4]; - mnt->mnt_opts = linebuf+n[6]; - - return mnt; -} - -struct mntent *getmntent(FILE *f) -{ - static struct mntent mnt; - return getmntent_r(f, &mnt, SENTINEL, 0); -} - -int addmntent(FILE *f, const struct mntent *mnt) -{ - if (fseek(f, 0, SEEK_END)) return 1; - return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n", - mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts, - mnt->mnt_freq, mnt->mnt_passno) < 0; -} - -char *hasmntopt(const struct mntent *mnt, const char *opt) -{ - return strstr(mnt->mnt_opts, opt); -} diff --git a/usr/lib/libc/misc/nftw.c b/usr/lib/libc/misc/nftw.c deleted file mode 100644 index efb2b8952..000000000 --- a/usr/lib/libc/misc/nftw.c +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -struct history -{ - struct history *chain; - dev_t dev; - ino_t ino; - int level; - int base; -}; - -#undef dirfd -#define dirfd(d) (*(int *)d) - -static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags, struct history *h) -{ - size_t l = strlen(path), j = l && path[l-1]=='/' ? l-1 : l; - struct stat st; - struct history new; - int type; - int r; - struct FTW lev; - char *name; - - if ((flags & FTW_PHYS) ? lstat(path, &st) : stat(path, &st) < 0) { - if (!(flags & FTW_PHYS) && errno==ENOENT && !lstat(path, &st)) - type = FTW_SLN; - else if (errno != EACCES) return -1; - else type = FTW_NS; - } else if (S_ISDIR(st.st_mode)) { - if (access(path, R_OK) < 0) type = FTW_DNR; - else if (flags & FTW_DEPTH) type = FTW_DP; - else type = FTW_D; - } else if (S_ISLNK(st.st_mode)) { - if (flags & FTW_PHYS) type = FTW_SL; - else type = FTW_SLN; - } else { - type = FTW_F; - } - - if ((flags & FTW_MOUNT) && h && st.st_dev != h->dev) - return 0; - - new.chain = h; - new.dev = st.st_dev; - new.ino = st.st_ino; - new.level = h ? h->level+1 : 0; - new.base = l+1; - - lev.level = new.level; - lev.base = h ? h->base : (name=strrchr(path, '/')) ? name-path : 0; - - if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) - return r; - - for (; h; h = h->chain) - if (h->dev == st.st_dev && h->ino == st.st_ino) - return 0; - - if ((type == FTW_D || type == FTW_DP) && fd_limit) { - DIR *d = opendir(path); - if (d) { - struct dirent *de; - while ((de = readdir(d))) { - if (de->d_name[0] == '.' - && (!de->d_name[1] - || (de->d_name[1]=='.' - && !de->d_name[2]))) continue; - if (strlen(de->d_name) >= PATH_MAX-l) { - errno = ENAMETOOLONG; - closedir(d); - return -1; - } - path[j]='/'; - strcpy(path+j+1, de->d_name); - if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) { - closedir(d); - return r; - } - } - closedir(d); - } else if (errno != EACCES) { - return -1; - } - } - - path[l] = 0; - if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) - return r; - - return 0; -} - -int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags) -{ - int r, cs; - size_t l; - char pathbuf[PATH_MAX+1]; - - if (fd_limit <= 0) return 0; - - l = strlen(path); - if (l > PATH_MAX) { - errno = ENAMETOOLONG; - return -1; - } - memcpy(pathbuf, path, l+1); - - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - r = do_nftw(pathbuf, fn, fd_limit, flags, NULL); - pthread_setcancelstate(cs, 0); - return r; -} - -LFS64(nftw); diff --git a/usr/lib/libc/misc/openpty.c b/usr/lib/libc/misc/openpty.c deleted file mode 100644 index c10740606..000000000 --- a/usr/lib/libc/misc/openpty.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* Nonstandard, but vastly superior to the standard functions */ - -int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struct winsize *ws) -{ - int m, s, n=0, cs; - char buf[20]; - - m = open("/dev/ptmx", O_RDWR|O_NOCTTY); - if (m < 0) return -1; - - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - - if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n)) - goto fail; - - if (!name) name = buf; - snprintf(name, sizeof buf, "/dev/pts/%d", n); - if ((s = open(name, O_RDWR|O_NOCTTY)) < 0) - goto fail; - - if (tio) tcsetattr(s, TCSANOW, tio); - if (ws) ioctl(s, TIOCSWINSZ, ws); - - *pm = m; - *ps = s; - - pthread_setcancelstate(cs, 0); - return 0; -fail: - close(m); - pthread_setcancelstate(cs, 0); - return -1; -} diff --git a/usr/lib/libc/misc/ptsname.c b/usr/lib/libc/misc/ptsname.c deleted file mode 100644 index a34779276..000000000 --- a/usr/lib/libc/misc/ptsname.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -int __ptsname_r(int, char *, size_t); - -char *ptsname(int fd) -{ - static char buf[9 + sizeof(int)*3 + 1]; - int err = __ptsname_r(fd, buf, sizeof buf); - if (err) { - errno = err; - return 0; - } - return buf; -} diff --git a/usr/lib/libc/misc/pty.c b/usr/lib/libc/misc/pty.c deleted file mode 100644 index b395d2c09..000000000 --- a/usr/lib/libc/misc/pty.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -#include -#include -#include "libc.h" -#include "syscall.h" - -int posix_openpt(int flags) -{ - return open("/dev/ptmx", flags); -} - -int grantpt(int fd) -{ - return 0; -} - -int unlockpt(int fd) -{ - int unlock = 0; - return ioctl(fd, TIOCSPTLCK, &unlock); -} - -int __ptsname_r(int fd, char *buf, size_t len) -{ - int pty, err; - if (!buf) len = 0; - if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err; - if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE; - return 0; -} - -weak_alias(__ptsname_r, ptsname_r); diff --git a/usr/lib/libc/misc/realpath.c b/usr/lib/libc/misc/realpath.c deleted file mode 100644 index 88c849cda..000000000 --- a/usr/lib/libc/misc/realpath.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "syscall.h" - -void __procfdname(char *, unsigned); - -char *realpath(const char *restrict filename, char *restrict resolved) -{ - int fd; - ssize_t r; - struct stat st1, st2; - char buf[15+3*sizeof(int)]; - char tmp[PATH_MAX]; - - if (!filename) { - errno = EINVAL; - return 0; - } - - fd = sys_open(filename, O_PATH|O_NONBLOCK|O_CLOEXEC); - if (fd < 0) return 0; - __procfdname(buf, fd); - - r = readlink(buf, tmp, sizeof tmp - 1); - if (r < 0) goto err; - tmp[r] = 0; - - fstat(fd, &st1); - r = stat(tmp, &st2); - if (r<0 || st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) { - if (!r) errno = ELOOP; - goto err; - } - - __syscall(SYS_close, fd); - return resolved ? strcpy(resolved, tmp) : strdup(tmp); -err: - __syscall(SYS_close, fd); - return 0; -} diff --git a/usr/lib/libc/misc/setdomainname.c b/usr/lib/libc/misc/setdomainname.c deleted file mode 100644 index 22d3f7463..000000000 --- a/usr/lib/libc/misc/setdomainname.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" - -int setdomainname(const char *name, size_t len) -{ - return syscall(SYS_setdomainname, name, len); -} diff --git a/usr/lib/libc/misc/setpriority.c b/usr/lib/libc/misc/setpriority.c deleted file mode 100644 index 3098cdf4d..000000000 --- a/usr/lib/libc/misc/setpriority.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int setpriority(int which, id_t who, int prio) -{ - return syscall(SYS_setpriority, which, who, prio); -} diff --git a/usr/lib/libc/misc/setrlimit.c b/usr/lib/libc/misc/setrlimit.c deleted file mode 100644 index 7130d719e..000000000 --- a/usr/lib/libc/misc/setrlimit.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -#define MIN(a, b) ((a)<(b) ? (a) : (b)) -#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0) - -int __setrlimit(int resource, const struct rlimit *rlim) -{ - unsigned long k_rlim[2]; - struct rlimit tmp; - if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) { - tmp = *rlim; - FIX(tmp.rlim_cur); - FIX(tmp.rlim_max); - rlim = &tmp; - } - int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0); - if (ret != -ENOSYS) return ret; - k_rlim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY)); - k_rlim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY)); - return __syscall(SYS_setrlimit, resource, k_rlim); -} - -struct ctx { - const struct rlimit *rlim; - int res; - int err; -}; - -static void do_setrlimit(void *p) -{ - struct ctx *c = p; - if (c->err>0) return; - c->err = -__setrlimit(c->res, c->rlim); -} - -int setrlimit(int resource, const struct rlimit *rlim) -{ - struct ctx c = { .res = resource, .rlim = rlim, .err = -1 }; - __synccall(do_setrlimit, &c); - if (c.err) { - if (c.err>0) errno = c.err; - return -1; - } - return 0; -} - -LFS64(setrlimit); diff --git a/usr/lib/libc/misc/stat.c b/usr/lib/libc/misc/stat.c deleted file mode 100644 index 952f8dc8d..000000000 --- a/usr/lib/libc/misc/stat.c +++ /dev/null @@ -1,8 +0,0 @@ - -#include -#include - -int stat(const char *pathname, struct stat *statbuf) -{ - return __syscall_ret(sys_stat(pathname, statbuf)); -} diff --git a/usr/lib/libc/misc/syslog.c b/usr/lib/libc/misc/syslog.c deleted file mode 100644 index 9dd1ddb58..000000000 --- a/usr/lib/libc/misc/syslog.c +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -static volatile int lock[2]; -static char log_ident[32]; -static int log_opt; -static int log_facility = LOG_USER; -static int log_mask = 0xff; -static int log_fd = -1; - -int setlogmask(int maskpri) -{ - LOCK(lock); - int ret = log_mask; - if (maskpri) log_mask = maskpri; - UNLOCK(lock); - return ret; -} - -static const struct { - short sun_family; - char sun_path[9]; -} log_addr = { - AF_UNIX, - "/dev/log" -}; - -void closelog(void) -{ - int cs; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - LOCK(lock); - close(log_fd); - log_fd = -1; - UNLOCK(lock); - pthread_setcancelstate(cs, 0); -} - -static void __openlog() -{ - log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); - if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr); -} - -void openlog(const char *ident, int opt, int facility) -{ - int cs; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - LOCK(lock); - - if (ident) { - size_t n = strnlen(ident, sizeof log_ident - 1); - memcpy(log_ident, ident, n); - log_ident[n] = 0; - } else { - log_ident[0] = 0; - } - log_opt = opt; - log_facility = facility; - - if ((opt & LOG_NDELAY) && log_fd<0) __openlog(); - - UNLOCK(lock); - pthread_setcancelstate(cs, 0); -} - -static int is_lost_conn(int e) -{ - return e==ECONNREFUSED || e==ECONNRESET || e==ENOTCONN || e==EPIPE; -} - -static void _vsyslog(int priority, const char *message, va_list ap) -{ - char timebuf[16]; - time_t now; - struct tm tm; - char buf[1024]; - int errno_save = errno; - int pid; - int l, l2; - int hlen; - int fd; - - if (log_fd < 0) __openlog(); - - if (!(priority & LOG_FACMASK)) priority |= log_facility; - - now = time(NULL); - gmtime_r(&now, &tm); - strftime(timebuf, sizeof timebuf, "%b %e %T", &tm); - - pid = (log_opt & LOG_PID) ? getpid() : 0; - l = snprintf(buf, sizeof buf, "<%d>%s %n%s%s%.0d%s: ", - priority, timebuf, &hlen, log_ident, "["+!pid, pid, "]"+!pid); - errno = errno_save; - l2 = vsnprintf(buf+l, sizeof buf - l, message, ap); - if (l2 >= 0) { - if (l2 >= sizeof buf - l) l = sizeof buf - 1; - else l += l2; - if (buf[l-1] != '\n') buf[l++] = '\n'; - if (send(log_fd, buf, l, 0) < 0 && (!is_lost_conn(errno) - || connect(log_fd, (void *)&log_addr, sizeof log_addr) < 0 - || send(log_fd, buf, l, 0) < 0) - && (log_opt & LOG_CONS)) { - fd = open("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC); - if (fd >= 0) { - dprintf(fd, "%.*s", l-hlen, buf+hlen); - close(fd); - } - } - if (log_opt & LOG_PERROR) dprintf(2, "%.*s", l-hlen, buf+hlen); - } -} - -void __vsyslog(int priority, const char *message, va_list ap) -{ - int cs; - if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - LOCK(lock); - _vsyslog(priority, message, ap); - UNLOCK(lock); - pthread_setcancelstate(cs, 0); -} - -void syslog(int priority, const char *message, ...) -{ - va_list ap; - va_start(ap, message); - __vsyslog(priority, message, ap); - va_end(ap); -} - -weak_alias(__vsyslog, vsyslog); diff --git a/usr/lib/libc/misc/uname.c b/usr/lib/libc/misc/uname.c deleted file mode 100644 index 55ea34202..000000000 --- a/usr/lib/libc/misc/uname.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int uname(struct utsname *uts) -{ - return syscall(SYS_uname, uts); -} diff --git a/usr/lib/libc/misc/wordexp.c b/usr/lib/libc/misc/wordexp.c deleted file mode 100644 index db39b5b8a..000000000 --- a/usr/lib/libc/misc/wordexp.c +++ /dev/null @@ -1,193 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "pthread_impl.h" - -static void reap(pid_t pid) -{ - int status; - for (;;) { - if (waitpid(pid, &status, 0) < 0) { - if (errno != EINTR) return; - } else { - if (WIFEXITED(status)) return; - } - } -} - -static char *getword(FILE *f) -{ - char *s = 0; - return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s; -} - -static int do_wordexp(const char *s, wordexp_t *we, int flags) -{ - size_t i, l; - int sq=0, dq=0; - size_t np=0; - char *w, **tmp; - char *redir = (flags & WRDE_SHOWERR) ? "" : "2>/dev/null"; - int err = 0; - FILE *f; - size_t wc = 0; - char **wv = 0; - int p[2]; - pid_t pid; - sigset_t set; - - if (flags & WRDE_REUSE) wordfree(we); - - if (flags & WRDE_NOCMD) for (i=0; s[i]; i++) switch (s[i]) { - case '\\': - if (!sq) i++; - break; - case '\'': - if (!dq) sq^=1; - break; - case '"': - if (!sq) dq^=1; - break; - case '(': - if (np) { - np++; - break; - } - case ')': - if (np) { - np--; - break; - } - case '\n': - case '|': - case '&': - case ';': - case '<': - case '>': - case '{': - case '}': - if (!(sq|dq|np)) return WRDE_BADCHAR; - break; - case '$': - if (sq) break; - if (s[i+1]=='(' && s[i+2]=='(') { - i += 2; - np += 2; - break; - } else if (s[i+1] != '(') break; - case '`': - if (sq) break; - return WRDE_CMDSUB; - } - - if (flags & WRDE_APPEND) { - wc = we->we_wordc; - wv = we->we_wordv; - } - - i = wc; - if (flags & WRDE_DOOFFS) { - if (we->we_offs > SIZE_MAX/sizeof(void *)/4) - goto nospace; - i += we->we_offs; - } else { - we->we_offs = 0; - } - - if (pipe2(p, O_CLOEXEC) < 0) goto nospace; - __block_all_sigs(&set); - pid = fork(); - __restore_sigs(&set); - if (pid < 0) { - close(p[0]); - close(p[1]); - goto nospace; - } - if (!pid) { - if (p[1] == 1) fcntl(1, F_SETFD, 0); - else dup2(p[1], 1); - execl("/bin/sh", "sh", "-c", - "eval \"printf %s\\\\\\\\0 x $1 $2\"", - "sh", s, redir, (char *)0); - _exit(1); - } - close(p[1]); - - f = fdopen(p[0], "r"); - if (!f) { - close(p[0]); - kill(pid, SIGKILL); - reap(pid); - goto nospace; - } - - l = wv ? i+1 : 0; - - free(getword(f)); - if (feof(f)) { - fclose(f); - reap(pid); - return WRDE_SYNTAX; - } - - while ((w = getword(f))) { - if (i+1 >= l) { - l += l/2+10; - tmp = realloc(wv, l*sizeof(char *)); - if (!tmp) break; - wv = tmp; - } - wv[i++] = w; - wv[i] = 0; - } - if (!feof(f)) err = WRDE_NOSPACE; - - fclose(f); - reap(pid); - - if (!wv) wv = calloc(i+1, sizeof *wv); - - we->we_wordv = wv; - we->we_wordc = i; - - if (flags & WRDE_DOOFFS) { - if (wv) for (i=we->we_offs; i; i--) - we->we_wordv[i-1] = 0; - we->we_wordc -= we->we_offs; - } - return err; - -nospace: - if (!(flags & WRDE_APPEND)) { - we->we_wordc = 0; - we->we_wordv = 0; - } - return WRDE_NOSPACE; -} - -int wordexp(const char *restrict s, wordexp_t *restrict we, int flags) -{ - int r, cs; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - r = do_wordexp(s, we, flags); - pthread_setcancelstate(cs, 0); - return r; -} - -void wordfree(wordexp_t *we) -{ - size_t i; - if (!we->we_wordv) return; - for (i=0; iwe_wordc; i++) free(we->we_wordv[we->we_offs+i]); - free(we->we_wordv); - we->we_wordv = 0; - we->we_wordc = 0; -} diff --git a/usr/lib/libc/mman/CMakeLists.txt b/usr/lib/libc/mman/CMakeLists.txt deleted file mode 100644 index bd772e0f7..000000000 --- a/usr/lib/libc/mman/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -target_sources(c - PRIVATE - mmap.c -) diff --git a/usr/lib/libc/mman/madvise.c b/usr/lib/libc/mman/madvise.c deleted file mode 100644 index f80926bec..000000000 --- a/usr/lib/libc/mman/madvise.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int __madvise(void *addr, size_t len, int advice) -{ - return syscall(SYS_madvise, addr, len, advice); -} - -weak_alias(__madvise, madvise); diff --git a/usr/lib/libc/mman/mincore.c b/usr/lib/libc/mman/mincore.c deleted file mode 100644 index 4bb19f857..000000000 --- a/usr/lib/libc/mman/mincore.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" - -int mincore (void *addr, size_t len, unsigned char *vec) -{ - return syscall(SYS_mincore, addr, len, vec); -} diff --git a/usr/lib/libc/mman/mlock.c b/usr/lib/libc/mman/mlock.c deleted file mode 100644 index e683a44ae..000000000 --- a/usr/lib/libc/mman/mlock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mlock(const void *addr, size_t len) -{ - return syscall(SYS_mlock, addr, len); -} diff --git a/usr/lib/libc/mman/mlockall.c b/usr/lib/libc/mman/mlockall.c deleted file mode 100644 index 0ba4e662c..000000000 --- a/usr/lib/libc/mman/mlockall.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int mlockall(int flags) -{ - return syscall(SYS_mlockall, flags); -} diff --git a/usr/lib/libc/mman/mmap.c b/usr/lib/libc/mman/mmap.c deleted file mode 100644 index 744e506e3..000000000 --- a/usr/lib/libc/mman/mmap.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#if 0 /* original musl implementation */ -static void dummy(void) { } -weak_alias(dummy, __vm_wait); - -#define UNIT SYSCALL_MMAP2_UNIT -#define OFF_MASK ((-0x2000ULL << (8*sizeof(syscall_arg_t)-1)) | (UNIT-1)) -#endif - -void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) -{ - - if (start || flags) { - /* Issue warning for unsupported parameters. */ - printf("%s: start and flags parameters are not supported.\n", __func__); - } - - if (!start) - start = sbrk(0) + HEAP_SIZE; - - return (void *) __syscall_ret(sys_mmap((unsigned long) start, len, prot, fd, off)); - -#if 0 /* original musl implementation */ - if (off & OFF_MASK) { - errno = EINVAL; - return MAP_FAILED; - } - if (len >= PTRDIFF_MAX) { - errno = ENOMEM; - return MAP_FAILED; - } - if (flags & MAP_FIXED) { - __vm_wait(); - } -#ifdef SYS_mmap2 - return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT); -#else - return (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off); -#endif -#endif -} - -weak_alias(__mmap, mmap); - diff --git a/usr/lib/libc/mman/mprotect.c b/usr/lib/libc/mman/mprotect.c deleted file mode 100644 index 535787b9e..000000000 --- a/usr/lib/libc/mman/mprotect.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "libc.h" -#include "syscall.h" - -int __mprotect(void *addr, size_t len, int prot) -{ - size_t start, end; - start = (size_t)addr & -PAGE_SIZE; - end = (size_t)((char *)addr + len + PAGE_SIZE-1) & -PAGE_SIZE; - return syscall(SYS_mprotect, start, end-start, prot); -} - -weak_alias(__mprotect, mprotect); diff --git a/usr/lib/libc/mman/mremap.c b/usr/lib/libc/mman/mremap.c deleted file mode 100644 index ce4e8ea13..000000000 --- a/usr/lib/libc/mman/mremap.c +++ /dev/null @@ -1,33 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -static void dummy(void) { } -weak_alias(dummy, __vm_wait); - -void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...) -{ - va_list ap; - void *new_addr = 0; - - if (new_len >= PTRDIFF_MAX) { - errno = ENOMEM; - return MAP_FAILED; - } - - if (flags & MREMAP_FIXED) { - __vm_wait(); - va_start(ap, flags); - new_addr = va_arg(ap, void *); - va_end(ap); - } - - return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr); -} - -weak_alias(__mremap, mremap); diff --git a/usr/lib/libc/mman/msync.c b/usr/lib/libc/mman/msync.c deleted file mode 100644 index fcd8cdf9f..000000000 --- a/usr/lib/libc/mman/msync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int msync(void *start, size_t len, int flags) -{ - return syscall_cp(SYS_msync, start, len, flags); -} diff --git a/usr/lib/libc/mman/munlock.c b/usr/lib/libc/mman/munlock.c deleted file mode 100644 index 2cccef0c5..000000000 --- a/usr/lib/libc/mman/munlock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int munlock(const void *addr, size_t len) -{ - return syscall(SYS_munlock, addr, len); -} diff --git a/usr/lib/libc/mman/munlockall.c b/usr/lib/libc/mman/munlockall.c deleted file mode 100644 index 6e9d39d68..000000000 --- a/usr/lib/libc/mman/munlockall.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int munlockall(void) -{ - return syscall(SYS_munlockall); -} diff --git a/usr/lib/libc/mman/munmap.c b/usr/lib/libc/mman/munmap.c deleted file mode 100644 index 3f711ee50..000000000 --- a/usr/lib/libc/mman/munmap.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -static void dummy(void) { } -weak_alias(dummy, __vm_wait); - -int __munmap(void *start, size_t len) -{ - __vm_wait(); - return syscall(SYS_munmap, start, len); -} - -weak_alias(__munmap, munmap); diff --git a/usr/lib/libc/mman/posix_madvise.c b/usr/lib/libc/mman/posix_madvise.c deleted file mode 100644 index e5e5acb84..000000000 --- a/usr/lib/libc/mman/posix_madvise.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" - -int posix_madvise(void *addr, size_t len, int advice) -{ - if (advice == MADV_DONTNEED) return 0; - return -__syscall(SYS_madvise, addr, len, advice); -} diff --git a/usr/lib/libc/mman/shm_open.c b/usr/lib/libc/mman/shm_open.c deleted file mode 100644 index d042a5a88..000000000 --- a/usr/lib/libc/mman/shm_open.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -char *__strchrnul(const char *, int); - -char *__shm_mapname(const char *name, char *buf) -{ - char *p; - while (*name == '/') name++; - if (*(p = __strchrnul(name, '/')) || p==name || - (p-name <= 2 && name[0]=='.' && p[-1]=='.')) { - errno = EINVAL; - return 0; - } - if (p-name > NAME_MAX) { - errno = ENAMETOOLONG; - return 0; - } - memcpy(buf, "/dev/shm/", 9); - memcpy(buf+9, name, p-name+1); - return buf; -} - -int shm_open(const char *name, int flag, mode_t mode) -{ - int cs; - char buf[NAME_MAX+10]; - if (!(name = __shm_mapname(name, buf))) return -1; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode); - pthread_setcancelstate(cs, 0); - return fd; -} - -int shm_unlink(const char *name) -{ - char buf[NAME_MAX+10]; - if (!(name = __shm_mapname(name, buf))) return -1; - return unlink(name); -} diff --git a/usr/lib/libc/multibyte/CMakeLists.txt b/usr/lib/libc/multibyte/CMakeLists.txt deleted file mode 100644 index 0524b7c1d..000000000 --- a/usr/lib/libc/multibyte/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -target_sources(c - PRIVATE - wctomb.c - wcrtomb.c - mbsinit.c - mbrtowc.c - internal.c -) diff --git a/usr/lib/libc/multibyte/btowc.c b/usr/lib/libc/multibyte/btowc.c deleted file mode 100644 index 8acd0a2cf..000000000 --- a/usr/lib/libc/multibyte/btowc.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include -#include "internal.h" - -wint_t btowc(int c) -{ - int b = (unsigned char)c; - return b<128U ? b : (MB_CUR_MAX==1 && c!=EOF) ? CODEUNIT(c) : WEOF; -} diff --git a/usr/lib/libc/multibyte/c16rtomb.c b/usr/lib/libc/multibyte/c16rtomb.c deleted file mode 100644 index 39ca3758f..000000000 --- a/usr/lib/libc/multibyte/c16rtomb.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include - -size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps) -{ - static unsigned internal_state; - if (!ps) ps = (void *)&internal_state; - unsigned *x = (unsigned *)ps; - wchar_t wc; - - if (!s) { - if (*x) goto ilseq; - return 1; - } - - if (!*x && c16 - 0xd800u < 0x400) { - *x = c16 - 0xd7c0 << 10; - return 0; - } - - if (*x) { - if (c16 - 0xdc00u >= 0x400) goto ilseq; - else wc = *x + c16 - 0xdc00; - *x = 0; - } else { - wc = c16; - } - return wcrtomb(s, wc, 0); - -ilseq: - *x = 0; - errno = EILSEQ; - return -1; -} diff --git a/usr/lib/libc/multibyte/c32rtomb.c b/usr/lib/libc/multibyte/c32rtomb.c deleted file mode 100644 index 67851328e..000000000 --- a/usr/lib/libc/multibyte/c32rtomb.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -size_t c32rtomb(char *restrict s, char32_t c32, mbstate_t *restrict ps) -{ - return wcrtomb(s, c32, ps); -} diff --git a/usr/lib/libc/multibyte/internal.c b/usr/lib/libc/multibyte/internal.c deleted file mode 100644 index 7e1b1c034..000000000 --- a/usr/lib/libc/multibyte/internal.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "internal.h" - -#define C(x) ( x<2 ? -1 : ( R(0x80,0xc0) | x ) ) -#define D(x) C((x+16)) -#define E(x) ( ( x==0 ? R(0xa0,0xc0) : \ - x==0xd ? R(0x80,0xa0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | x ) -#define F(x) ( ( x>=5 ? 0 : \ - x==0 ? R(0x90,0xc0) : \ - x==4 ? R(0x80,0xa0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | x ) - -const uint32_t bittab[] = { - C(0x2),C(0x3),C(0x4),C(0x5),C(0x6),C(0x7), - C(0x8),C(0x9),C(0xa),C(0xb),C(0xc),C(0xd),C(0xe),C(0xf), - D(0x0),D(0x1),D(0x2),D(0x3),D(0x4),D(0x5),D(0x6),D(0x7), - D(0x8),D(0x9),D(0xa),D(0xb),D(0xc),D(0xd),D(0xe),D(0xf), - E(0x0),E(0x1),E(0x2),E(0x3),E(0x4),E(0x5),E(0x6),E(0x7), - E(0x8),E(0x9),E(0xa),E(0xb),E(0xc),E(0xd),E(0xe),E(0xf), - F(0x0),F(0x1),F(0x2),F(0x3),F(0x4) -}; diff --git a/usr/lib/libc/multibyte/internal.h b/usr/lib/libc/multibyte/internal.h deleted file mode 100644 index 828f1617d..000000000 --- a/usr/lib/libc/multibyte/internal.h +++ /dev/null @@ -1,28 +0,0 @@ - - -#define bittab __fsmu8 - -#include - -#ifdef __PIC__ -__attribute__((__visibility__("hidden"))) -#endif -extern const uint32_t bittab[]; - -/* Upper 6 state bits are a negative integer offset to bound-check next byte */ -/* equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f */ -#define OOB(c,b) (((((b)>>3)-0x10)|(((b)>>3)+((int32_t)(c)>>26))) & ~7) - -/* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */ -#define R(a,b) ((uint32_t)((a==0x80 ? 0x40u-b : 0u-a) << 23)) -#define FAILSTATE R(0x80,0x80) - -#define SA 0xc2u -#define SB 0xf4u - -/* Arbitrary encoding for representing code units instead of characters. */ -#define CODEUNIT(c) (0xdfff & (signed char)(c)) -#define IS_CODEUNIT(c) ((unsigned)(c)-0xdf80 < 0x80) - -/* Get inline definition of MB_CUR_MAX. */ -#include "locale_impl.h" diff --git a/usr/lib/libc/multibyte/mblen.c b/usr/lib/libc/multibyte/mblen.c deleted file mode 100644 index a4304bf5a..000000000 --- a/usr/lib/libc/multibyte/mblen.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int mblen(const char *s, size_t n) -{ - return mbtowc(0, s, n); -} diff --git a/usr/lib/libc/multibyte/mbrlen.c b/usr/lib/libc/multibyte/mbrlen.c deleted file mode 100644 index accf4b331..000000000 --- a/usr/lib/libc/multibyte/mbrlen.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -size_t mbrlen(const char *restrict s, size_t n, mbstate_t *restrict st) -{ - static unsigned internal; - return mbrtowc(0, s, n, st ? st : (mbstate_t *)&internal); -} diff --git a/usr/lib/libc/multibyte/mbrtoc16.c b/usr/lib/libc/multibyte/mbrtoc16.c deleted file mode 100644 index 765ff9037..000000000 --- a/usr/lib/libc/multibyte/mbrtoc16.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -size_t mbrtoc16(char16_t *restrict pc16, const char *restrict s, size_t n, mbstate_t *restrict ps) -{ - static unsigned internal_state; - if (!ps) ps = (void *)&internal_state; - unsigned *pending = (unsigned *)ps; - - if (!s) return mbrtoc16(0, "", 1, ps); - - /* mbrtowc states for partial UTF-8 characters have the high bit set; - * we use nonzero states without high bit for pending surrogates. */ - if ((int)*pending > 0) { - if (pc16) *pc16 = *pending; - *pending = 0; - return -3; - } - - wchar_t wc; - size_t ret = mbrtowc(&wc, s, n, ps); - if (ret <= 4) { - if (wc >= 0x10000) { - *pending = (wc & 0x3ff) + 0xdc00; - wc = 0xd7c0 + (wc >> 10); - } - if (pc16) *pc16 = wc; - } - return ret; -} diff --git a/usr/lib/libc/multibyte/mbrtoc32.c b/usr/lib/libc/multibyte/mbrtoc32.c deleted file mode 100644 index 9b6b23673..000000000 --- a/usr/lib/libc/multibyte/mbrtoc32.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -size_t mbrtoc32(char32_t *restrict pc32, const char *restrict s, size_t n, mbstate_t *restrict ps) -{ - static unsigned internal_state; - if (!ps) ps = (void *)&internal_state; - if (!s) return mbrtoc32(0, "", 1, ps); - wchar_t wc; - size_t ret = mbrtowc(&wc, s, n, ps); - if (ret <= 4 && pc32) *pc32 = wc; - return ret; -} diff --git a/usr/lib/libc/multibyte/mbrtowc.c b/usr/lib/libc/multibyte/mbrtowc.c deleted file mode 100644 index 58e68ce15..000000000 --- a/usr/lib/libc/multibyte/mbrtowc.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include "internal.h" - -size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate_t *restrict st) -{ - static unsigned internal_state; - unsigned c; - const unsigned char *s = (const void *)src; - const unsigned N = n; - wchar_t dummy; - - if (!st) st = (void *)&internal_state; - c = *(unsigned *)st; - - if (!s) { - if (c) goto ilseq; - return 0; - } else if (!wc) wc = &dummy; - - if (!n) return -2; - if (!c) { - if (*s < 0x80) return !!(*wc = *s); - if (MB_CUR_MAX==1) return (*wc = CODEUNIT(*s)), 1; - if (*s-SA > SB-SA) goto ilseq; - c = bittab[*s++-SA]; n--; - } - - if (n) { - if (OOB(c,*s)) goto ilseq; -loop: - c = (c<<6) | (*s++-0x80); n--; - if (!(c&(1U<<31))) { - *(unsigned *)st = 0; - *wc = c; - return N-n; - } - if (n) { - if (*s-0x80u >= 0x40) goto ilseq; - goto loop; - } - } - - *(unsigned *)st = c; - return -2; -ilseq: - *(unsigned *)st = 0; - errno = EILSEQ; - return -1; -} diff --git a/usr/lib/libc/multibyte/mbsinit.c b/usr/lib/libc/multibyte/mbsinit.c deleted file mode 100644 index c608194a0..000000000 --- a/usr/lib/libc/multibyte/mbsinit.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int mbsinit(const mbstate_t *st) -{ - return !st || !*(unsigned *)st; -} diff --git a/usr/lib/libc/multibyte/mbsnrtowcs.c b/usr/lib/libc/multibyte/mbsnrtowcs.c deleted file mode 100644 index cae4caa2a..000000000 --- a/usr/lib/libc/multibyte/mbsnrtowcs.c +++ /dev/null @@ -1,53 +0,0 @@ -#include - -size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, size_t wn, mbstate_t *restrict st) -{ - size_t l, cnt=0, n2; - wchar_t *ws, wbuf[256]; - const char *s = *src; - - if (!wcs) ws = wbuf, wn = sizeof wbuf / sizeof *wbuf; - else ws = wcs; - - /* making sure output buffer size is at most n/4 will ensure - * that mbsrtowcs never reads more than n input bytes. thus - * we can use mbsrtowcs as long as it's practical.. */ - - while ( s && wn && ( (n2=n/4)>=wn || n2>32 ) ) { - if (n2>=wn) n2=wn; - n -= n2; - l = mbsrtowcs(ws, &s, n2, st); - if (!(l+1)) { - cnt = l; - wn = 0; - break; - } - if (ws != wbuf) { - ws += l; - wn -= l; - } - cnt += l; - } - if (s) while (wn && n) { - l = mbrtowc(ws, s, n, st); - if (l+2<=2) { - if (!(l+1)) { - cnt = l; - break; - } - if (!l) { - s = 0; - break; - } - /* have to roll back partial character */ - *(unsigned *)st = 0; - break; - } - s += l; n -= l; - /* safe - this loop runs fewer than sizeof(wbuf)/8 times */ - ws++; wn--; - cnt++; - } - if (wcs) *src = s; - return cnt; -} diff --git a/usr/lib/libc/multibyte/mbsrtowcs.c b/usr/lib/libc/multibyte/mbsrtowcs.c deleted file mode 100644 index 0ee8b69cb..000000000 --- a/usr/lib/libc/multibyte/mbsrtowcs.c +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include -#include -#include -#include "internal.h" - -size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st) -{ - const unsigned char *s = (const void *)*src; - size_t wn0 = wn; - unsigned c = 0; - - if (st && (c = *(unsigned *)st)) { - if (ws) { - *(unsigned *)st = 0; - goto resume; - } else { - goto resume0; - } - } - - if (MB_CUR_MAX==1) { - if (!ws) return strlen((const char *)s); - for (;;) { - if (!wn) { - *src = (const void *)s; - return wn0; - } - if (!*s) break; - c = *s++; - *ws++ = CODEUNIT(c); - wn--; - } - *ws = 0; - *src = 0; - return wn0-wn; - } - - if (!ws) for (;;) { - if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) { - while (!(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) { - s += 4; - wn -= 4; - } - } - if (*s-1u < 0x7f) { - s++; - wn--; - continue; - } - if (*s-SA > SB-SA) break; - c = bittab[*s++-SA]; -resume0: - if (OOB(c,*s)) { s--; break; } - s++; - if (c&(1U<<25)) { - if (*s-0x80u >= 0x40) { s-=2; break; } - s++; - if (c&(1U<<19)) { - if (*s-0x80u >= 0x40) { s-=3; break; } - s++; - } - } - wn--; - c = 0; - } else for (;;) { - if (!wn) { - *src = (const void *)s; - return wn0; - } - if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) { - while (wn>=5 && !(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) { - *ws++ = *s++; - *ws++ = *s++; - *ws++ = *s++; - *ws++ = *s++; - wn -= 4; - } - } - if (*s-1u < 0x7f) { - *ws++ = *s++; - wn--; - continue; - } - if (*s-SA > SB-SA) break; - c = bittab[*s++-SA]; -resume: - if (OOB(c,*s)) { s--; break; } - c = (c<<6) | *s++-0x80; - if (c&(1U<<31)) { - if (*s-0x80u >= 0x40) { s-=2; break; } - c = (c<<6) | *s++-0x80; - if (c&(1U<<31)) { - if (*s-0x80u >= 0x40) { s-=3; break; } - c = (c<<6) | *s++-0x80; - } - } - *ws++ = c; - wn--; - c = 0; - } - - if (!c && !*s) { - if (ws) { - *ws = 0; - *src = 0; - } - return wn0-wn; - } - errno = EILSEQ; - if (ws) *src = (const void *)s; - return -1; -} diff --git a/usr/lib/libc/multibyte/mbstowcs.c b/usr/lib/libc/multibyte/mbstowcs.c deleted file mode 100644 index dc0d45948..000000000 --- a/usr/lib/libc/multibyte/mbstowcs.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -size_t mbstowcs(wchar_t *restrict ws, const char *restrict s, size_t wn) -{ - return mbsrtowcs(ws, (void*)&s, wn, 0); -} diff --git a/usr/lib/libc/multibyte/mbtowc.c b/usr/lib/libc/multibyte/mbtowc.c deleted file mode 100644 index 8168e243d..000000000 --- a/usr/lib/libc/multibyte/mbtowc.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include "internal.h" - -int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n) -{ - unsigned c; - const unsigned char *s = (const void *)src; - wchar_t dummy; - - if (!s) return 0; - if (!n) goto ilseq; - if (!wc) wc = &dummy; - - if (*s < 0x80) return !!(*wc = *s); - if (MB_CUR_MAX==1) return (*wc = CODEUNIT(*s)), 1; - if (*s-SA > SB-SA) goto ilseq; - c = bittab[*s++-SA]; - - /* Avoid excessive checks against n: If shifting the state n-1 - * times does not clear the high bit, then the value of n is - * insufficient to read a character */ - if (n<4 && ((c<<(6*n-6)) & (1U<<31))) goto ilseq; - - if (OOB(c,*s)) goto ilseq; - c = c<<6 | *s++-0x80; - if (!(c&(1U<<31))) { - *wc = c; - return 2; - } - - if ((*s-0x80u) >= 0x40) goto ilseq; - c = c<<6 | *s++-0x80; - if (!(c&(1U<<31))) { - *wc = c; - return 3; - } - - if (*s-0x80u >= 0x40) goto ilseq; - *wc = c<<6 | *s++-0x80; - return 4; - -ilseq: - errno = EILSEQ; - return -1; -} diff --git a/usr/lib/libc/multibyte/wcrtomb.c b/usr/lib/libc/multibyte/wcrtomb.c deleted file mode 100644 index 8e34926ed..000000000 --- a/usr/lib/libc/multibyte/wcrtomb.c +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include -#include -#include "internal.h" - -size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st) -{ - if (!s) return 1; - if ((unsigned)wc < 0x80) { - *s = wc; - return 1; - } else if (MB_CUR_MAX == 1) { - if (!IS_CODEUNIT(wc)) { - errno = EILSEQ; - return -1; - } - *s = wc; - return 1; - } else if ((unsigned)wc < 0x800) { - *s++ = 0xc0 | (wc>>6); - *s = 0x80 | (wc&0x3f); - return 2; - } else if ((unsigned)wc < 0xd800 || (unsigned)wc-0xe000 < 0x2000) { - *s++ = 0xe0 | (wc>>12); - *s++ = 0x80 | ((wc>>6)&0x3f); - *s = 0x80 | (wc&0x3f); - return 3; - } else if ((unsigned)wc-0x10000 < 0x100000) { - *s++ = 0xf0 | (wc>>18); - *s++ = 0x80 | ((wc>>12)&0x3f); - *s++ = 0x80 | ((wc>>6)&0x3f); - *s = 0x80 | (wc&0x3f); - return 4; - } - errno = EILSEQ; - return -1; -} diff --git a/usr/lib/libc/multibyte/wcsnrtombs.c b/usr/lib/libc/multibyte/wcsnrtombs.c deleted file mode 100644 index 640cbbeb5..000000000 --- a/usr/lib/libc/multibyte/wcsnrtombs.c +++ /dev/null @@ -1,41 +0,0 @@ -#include - -size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st) -{ - size_t l, cnt=0, n2; - char *s, buf[256]; - const wchar_t *ws = *wcs; - - if (!dst) s = buf, n = sizeof buf; - else s = dst; - - while ( ws && n && ( (n2=wn)>=n || n2>32 ) ) { - if (n2>=n) n2=n; - wn -= n2; - l = wcsrtombs(s, &ws, n2, 0); - if (!(l+1)) { - cnt = l; - n = 0; - break; - } - if (s != buf) { - s += l; - n -= l; - } - cnt += l; - } - if (ws) while (n && wn) { - l = wcrtomb(s, *ws, 0); - if ((l+1)<=1) { - if (!l) ws = 0; - else cnt = l; - break; - } - ws++; wn--; - /* safe - this loop runs fewer than sizeof(buf) times */ - s+=l; n-=l; - cnt += l; - } - if (dst) *wcs = ws; - return cnt; -} diff --git a/usr/lib/libc/multibyte/wcsrtombs.c b/usr/lib/libc/multibyte/wcsrtombs.c deleted file mode 100644 index b5713aeac..000000000 --- a/usr/lib/libc/multibyte/wcsrtombs.c +++ /dev/null @@ -1,55 +0,0 @@ -#include - -size_t wcsrtombs(char *restrict s, const wchar_t **restrict ws, size_t n, mbstate_t *restrict st) -{ - const wchar_t *ws2; - char buf[4]; - size_t N = n, l; - if (!s) { - for (n=0, ws2=*ws; *ws2; ws2++) { - if (*ws2 >= 0x80u) { - l = wcrtomb(buf, *ws2, 0); - if (!(l+1)) return -1; - n += l; - } else n++; - } - return n; - } - while (n>=4) { - if (**ws-1u >= 0x7fu) { - if (!**ws) { - *s = 0; - *ws = 0; - return N-n; - } - l = wcrtomb(s, **ws, 0); - if (!(l+1)) return -1; - s += l; - n -= l; - } else { - *s++ = **ws; - n--; - } - (*ws)++; - } - while (n) { - if (**ws-1u >= 0x7fu) { - if (!**ws) { - *s = 0; - *ws = 0; - return N-n; - } - l = wcrtomb(buf, **ws, 0); - if (!(l+1)) return -1; - if (l>n) return N-n; - wcrtomb(s, **ws, 0); - s += l; - n -= l; - } else { - *s++ = **ws; - n--; - } - (*ws)++; - } - return N; -} diff --git a/usr/lib/libc/multibyte/wcstombs.c b/usr/lib/libc/multibyte/wcstombs.c deleted file mode 100644 index ab152874d..000000000 --- a/usr/lib/libc/multibyte/wcstombs.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -size_t wcstombs(char *restrict s, const wchar_t *restrict ws, size_t n) -{ - return wcsrtombs(s, &(const wchar_t *){ws}, n, 0); -} diff --git a/usr/lib/libc/multibyte/wctob.c b/usr/lib/libc/multibyte/wctob.c deleted file mode 100644 index b484a3fd0..000000000 --- a/usr/lib/libc/multibyte/wctob.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include -#include "internal.h" - -int wctob(wint_t c) -{ - if (c < 128U) return c; - if (MB_CUR_MAX==1 && IS_CODEUNIT(c)) return (unsigned char)c; - return EOF; -} diff --git a/usr/lib/libc/multibyte/wctomb.c b/usr/lib/libc/multibyte/wctomb.c deleted file mode 100644 index bad41c5ed..000000000 --- a/usr/lib/libc/multibyte/wctomb.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -int wctomb(char *s, wchar_t wc) -{ - if (!s) return 0; - return wcrtomb(s, wc, 0); -} diff --git a/usr/lib/libc/mutex.c b/usr/lib/libc/mutex.c deleted file mode 100644 index 221063a4e..000000000 --- a/usr/lib/libc/mutex.c +++ /dev/null @@ -1,12 +0,0 @@ - -#include - -void mutex_lock(int lock_idx) { - sys_mutex_lock(lock_idx); -} - -void mutex_unlock(int lock_idx) { - sys_mutex_unlock(lock_idx); -} - - diff --git a/usr/lib/libc/network/CMakeLists.txt b/usr/lib/libc/network/CMakeLists.txt deleted file mode 100644 index 68d9cbc89..000000000 --- a/usr/lib/libc/network/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ - -target_sources(c - PRIVATE - socket.c - inet_ntoa.c - send.c - sendto.c - inet_pton.c - inet_ntop.c - recv.c - recvfrom.c - setsockopt.c - htonl.c - htons.c - bind.c - listen.c - accept.c - connect.c - ntohs.c - ntohl.c -) diff --git a/usr/lib/libc/network/accept.c b/usr/lib/libc/network/accept.c deleted file mode 100644 index 17ee350bb..000000000 --- a/usr/lib/libc/network/accept.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) -{ - return __syscall_ret(sys_accept(fd, addr, len)); -} diff --git a/usr/lib/libc/network/accept4.c b/usr/lib/libc/network/accept4.c deleted file mode 100644 index 285d85887..000000000 --- a/usr/lib/libc/network/accept4.c +++ /dev/null @@ -1,20 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int flg) -{ - if (!flg) return accept(fd, addr, len); - int ret = socketcall_cp(accept4, fd, addr, len, flg, 0, 0); - if (ret>=0 || (errno != ENOSYS && errno != EINVAL)) return ret; - ret = accept(fd, addr, len); - if (ret<0) return ret; - if (flg & SOCK_CLOEXEC) - __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); - if (flg & SOCK_NONBLOCK) - __syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK); - return ret; -} diff --git a/usr/lib/libc/network/bind.c b/usr/lib/libc/network/bind.c deleted file mode 100644 index 86f806325..000000000 --- a/usr/lib/libc/network/bind.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int bind(int fd, const struct sockaddr *addr, socklen_t len) -{ - return __syscall_ret(sys_bind(fd, addr, len)); -} diff --git a/usr/lib/libc/network/connect.c b/usr/lib/libc/network/connect.c deleted file mode 100644 index a1a06da90..000000000 --- a/usr/lib/libc/network/connect.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int connect(int fd, const struct sockaddr *addr, socklen_t len) -{ - return __syscall_ret(sys_connect(fd, addr, len)); -} diff --git a/usr/lib/libc/network/dn_comp.c b/usr/lib/libc/network/dn_comp.c deleted file mode 100644 index a17d434dc..000000000 --- a/usr/lib/libc/network/dn_comp.c +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include -#include "libc.h" - -/* RFC 1035 message compression */ - -/* label start offsets of a compressed domain name s */ -static int getoffs(short *offs, const unsigned char *base, const unsigned char *s) -{ - int i=0; - for (;;) { - while (*s & 0xc0) { - if ((*s & 0xc0) != 0xc0) return 0; - s = base + ((s[0]&0x3f)<<8 | s[1]); - } - if (!*s) return i; - if (s-base >= 0x4000) return 0; - offs[i++] = s-base; - s += *s + 1; - } -} - -/* label lengths of an ascii domain name s */ -static int getlens(unsigned char *lens, const char *s, int l) -{ - int i=0,j=0,k=0; - for (;;) { - for (; j 62) return 0; - lens[i++] = j-k; - if (j==l) return i; - k = ++j; - } -} - -/* longest suffix match of an ascii domain with a compressed domain name dn */ -static int match(int *offset, const unsigned char *base, const unsigned char *dn, - const char *end, const unsigned char *lens, int nlen) -{ - int l, o, m=0; - short offs[128]; - int noff = getoffs(offs, base, dn); - if (!noff) return 0; - for (;;) { - l = lens[--nlen]; - o = offs[--noff]; - end -= l; - if (l != base[o] || memcmp(base+o+1, end, l)) - return m; - *offset = o; - m += l; - if (nlen) m++; - if (!nlen || !noff) return m; - end--; - } -} - -int __dn_comp(const char *src, unsigned char *dst, int space, unsigned char **dnptrs, unsigned char **lastdnptr) -{ - int i, j, n, m=0, offset, bestlen=0, bestoff; - unsigned char lens[127]; - unsigned char **p; - const char *end; - size_t l = strnlen(src, 255); - if (l && src[l-1] == '.') l--; - if (l>253 || space<=0) return -1; - if (!l) { - *dst = 0; - return 1; - } - end = src+l; - n = getlens(lens, src, l); - if (!n) return -1; - - p = dnptrs; - if (p && *p) for (p++; *p; p++) { - m = match(&offset, *dnptrs, *p, end, lens, n); - if (m > bestlen) { - bestlen = m; - bestoff = offset; - if (m == l) - break; - } - } - - /* encode unmatched part */ - if (space < l-bestlen+2+(bestlen-1 < l-1)) return -1; - memcpy(dst+1, src, l-bestlen); - for (i=j=0; i>8; - dst[i++] = bestoff; - } else - dst[i++] = 0; - - /* save dst pointer */ - if (i>2 && lastdnptr && dnptrs && *dnptrs) { - while (*p) p++; - if (p+1 < lastdnptr) { - *p++ = dst; - *p=0; - } - } - return i; -} - -weak_alias(__dn_comp, dn_comp); diff --git a/usr/lib/libc/network/dn_expand.c b/usr/lib/libc/network/dn_expand.c deleted file mode 100644 index d9b339365..000000000 --- a/usr/lib/libc/network/dn_expand.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include "libc.h" - -int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space) -{ - const unsigned char *p = src; - char *dend, *dbegin = dest; - int len = -1, i, j; - if (p==end || space <= 0) return -1; - dend = dest + (space > 254 ? 254 : space); - /* detect reference loop using an iteration counter */ - for (i=0; i < end-base; i+=2) { - /* loop invariants: p= end-base) return -1; - p = base+j; - } else if (*p) { - if (dest != dbegin) *dest++ = '.'; - j = *p++; - if (j >= end-p || j >= dend-dest) return -1; - while (j--) *dest++ = *p++; - } else { - *dest = 0; - if (len < 0) len = p+1-src; - return len; - } - } - return -1; -} - -weak_alias(__dn_expand, dn_expand); diff --git a/usr/lib/libc/network/dn_skipname.c b/usr/lib/libc/network/dn_skipname.c deleted file mode 100644 index d54c2e5d0..000000000 --- a/usr/lib/libc/network/dn_skipname.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int dn_skipname(const unsigned char *s, const unsigned char *end) -{ - const unsigned char *p; - for (p=s; p=192) - if (p+1 - -int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, const void *, int, const void *), void *ctx) -{ - int qdcount, ancount; - const unsigned char *p; - int len; - - if (rlen<12) return -1; - if ((r[3]&15)) return 0; - p = r+12; - qdcount = r[4]*256 + r[5]; - ancount = r[6]*256 + r[7]; - if (qdcount+ancount > 64) return -1; - while (qdcount--) { - while (p-r < rlen && *p-1U < 127) p++; - if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6) - return -1; - p += 5 + !!*p; - } - while (ancount--) { - while (p-r < rlen && *p-1U < 127) p++; - if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6) - return -1; - p += 1 + !!*p; - len = p[8]*256 + p[9]; - if (p+len > r+rlen) return -1; - if (callback(ctx, p[1], p+10, len, r) < 0) return -1; - p += 10 + len; - } - return 0; -} diff --git a/usr/lib/libc/network/ent.c b/usr/lib/libc/network/ent.c deleted file mode 100644 index ececdc486..000000000 --- a/usr/lib/libc/network/ent.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "libc.h" - -void sethostent(int x) -{ -} - -void *gethostent() -{ - return 0; -} - -void endhostent(void) -{ -} - -weak_alias(sethostent, setnetent); -weak_alias(gethostent, getnetent); -weak_alias(endhostent, endnetent); diff --git a/usr/lib/libc/network/ether.c b/usr/lib/libc/network/ether.c deleted file mode 100644 index 4304a972f..000000000 --- a/usr/lib/libc/network/ether.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include - -struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a) -{ - struct ether_addr a; - char *y; - for (int ii = 0; ii < 6; ii++) { - unsigned long int n; - if (ii != 0) { - if (x[0] != ':') return 0; /* bad format */ - else x++; - } - n = strtoul (x, &y, 16); - x = y; - if (n > 0xFF) return 0; /* bad byte */ - a.ether_addr_octet[ii] = n; - } - if (x[0] != 0) return 0; /* bad format */ - *p_a = a; - return p_a; -} - -struct ether_addr *ether_aton (const char *x) -{ - static struct ether_addr a; - return ether_aton_r (x, &a); -} - -char *ether_ntoa_r (const struct ether_addr *p_a, char *x) { - char *y; - y = x; - for (int ii = 0; ii < 6; ii++) { - x += sprintf (x, ii == 0 ? "%.2X" : ":%.2X", p_a->ether_addr_octet[ii]); - } - return y; -} - -char *ether_ntoa (const struct ether_addr *p_a) { - static char x[18]; - return ether_ntoa_r (p_a, x); -} - -int ether_line(const char *l, struct ether_addr *e, char *hostname) -{ - return -1; -} - -int ether_ntohost(char *hostname, const struct ether_addr *e) -{ - return -1; -} - -int ether_hostton(const char *hostname, struct ether_addr *e) -{ - return -1; -} diff --git a/usr/lib/libc/network/freeaddrinfo.c b/usr/lib/libc/network/freeaddrinfo.c deleted file mode 100644 index df3798ae7..000000000 --- a/usr/lib/libc/network/freeaddrinfo.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void freeaddrinfo(struct addrinfo *p) -{ - free(p); -} diff --git a/usr/lib/libc/network/gai_strerror.c b/usr/lib/libc/network/gai_strerror.c deleted file mode 100644 index 9596580e9..000000000 --- a/usr/lib/libc/network/gai_strerror.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include "locale_impl.h" - -static const char msgs[] = - "Invalid flags\0" - "Name does not resolve\0" - "Try again\0" - "Non-recoverable error\0" - "Unknown error\0" - "Unrecognized address family or invalid length\0" - "Unrecognized socket type\0" - "Unrecognized service\0" - "Unknown error\0" - "Out of memory\0" - "System error\0" - "Overflow\0" - "\0Unknown error"; - -const char *gai_strerror(int ecode) -{ - const char *s; - for (s=msgs, ecode++; ecode && *s; ecode++, s++) for (; *s; s++); - if (!*s) s++; - return LCTRANS_CUR(s); -} diff --git a/usr/lib/libc/network/getaddrinfo.c b/usr/lib/libc/network/getaddrinfo.c deleted file mode 100644 index b9439f776..000000000 --- a/usr/lib/libc/network/getaddrinfo.c +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include -#include -#include -#include "lookup.h" - -int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res) -{ - struct service ports[MAXSERVS]; - struct address addrs[MAXADDRS]; - char canon[256], *outcanon; - int nservs, naddrs, nais, canon_len, i, j, k; - int family = AF_UNSPEC, flags = 0, proto = 0, socktype = 0; - struct aibuf { - struct addrinfo ai; - union sa { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } sa; - } *out; - - if (!host && !serv) return EAI_NONAME; - - if (hint) { - family = hint->ai_family; - flags = hint->ai_flags; - proto = hint->ai_protocol; - socktype = hint->ai_socktype; - - const int mask = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | - AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG | AI_NUMERICSERV; - if ((flags & mask) != flags) - return EAI_BADFLAGS; - - switch (family) { - case AF_INET: - case AF_INET6: - case AF_UNSPEC: - break; - default: - return EAI_FAMILY; - } - } - - nservs = __lookup_serv(ports, serv, proto, socktype, flags); - if (nservs < 0) return nservs; - - naddrs = __lookup_name(addrs, canon, host, family, flags); - if (naddrs < 0) return naddrs; - - nais = nservs * naddrs; - canon_len = strlen(canon); - out = calloc(1, nais * sizeof(*out) + canon_len + 1); - if (!out) return EAI_MEMORY; - - if (canon_len) { - outcanon = (void *)&out[nais]; - memcpy(outcanon, canon, canon_len+1); - } else { - outcanon = 0; - } - - for (k=i=0; iai; - return 0; -} diff --git a/usr/lib/libc/network/gethostbyaddr.c b/usr/lib/libc/network/gethostbyaddr.c deleted file mode 100644 index 598e2241a..000000000 --- a/usr/lib/libc/network/gethostbyaddr.c +++ /dev/null @@ -1,24 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include - -struct hostent *gethostbyaddr(const void *a, socklen_t l, int af) -{ - static struct hostent *h; - size_t size = 63; - struct hostent *res; - int err; - do { - free(h); - h = malloc(size+=size+1); - if (!h) { - h_errno = NO_RECOVERY; - return 0; - } - err = gethostbyaddr_r(a, l, af, h, - (void *)(h+1), size-sizeof *h, &res, &h_errno); - } while (err == ERANGE); - return err ? 0 : h; -} diff --git a/usr/lib/libc/network/gethostbyaddr_r.c b/usr/lib/libc/network/gethostbyaddr_r.c deleted file mode 100644 index 0f1e61aa0..000000000 --- a/usr/lib/libc/network/gethostbyaddr_r.c +++ /dev/null @@ -1,71 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include - -int gethostbyaddr_r(const void *a, socklen_t l, int af, - struct hostent *h, char *buf, size_t buflen, - struct hostent **res, int *err) -{ - union { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } sa = { .sin.sin_family = af }; - socklen_t sl = af==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin; - int i; - - *res = 0; - - /* Load address argument into sockaddr structure */ - if (af==AF_INET6 && l==16) memcpy(&sa.sin6.sin6_addr, a, 16); - else if (af==AF_INET && l==4) memcpy(&sa.sin.sin_addr, a, 4); - else { - *err = NO_RECOVERY; - return EINVAL; - } - - /* Align buffer and check for space for pointers and ip address */ - i = (uintptr_t)buf & sizeof(char *)-1; - if (!i) i = sizeof(char *); - if (buflen <= 5*sizeof(char *)-i + l) return ERANGE; - buf += sizeof(char *)-i; - buflen -= 5*sizeof(char *)-i + l; - - h->h_addr_list = (void *)buf; - buf += 2*sizeof(char *); - h->h_aliases = (void *)buf; - buf += 2*sizeof(char *); - - h->h_addr_list[0] = buf; - memcpy(h->h_addr_list[0], a, l); - buf += l; - h->h_addr_list[1] = 0; - h->h_aliases[0] = buf; - h->h_aliases[1] = 0; - - switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) { - case EAI_AGAIN: - *err = TRY_AGAIN; - return EAGAIN; - case EAI_OVERFLOW: - return ERANGE; - default: - case EAI_MEMORY: - case EAI_SYSTEM: - case EAI_FAIL: - *err = NO_RECOVERY; - return errno; - case 0: - break; - } - - h->h_addrtype = af; - h->h_length = l; - h->h_name = h->h_aliases[0]; - *res = h; - return 0; -} diff --git a/usr/lib/libc/network/gethostbyname.c b/usr/lib/libc/network/gethostbyname.c deleted file mode 100644 index bfedf52ad..000000000 --- a/usr/lib/libc/network/gethostbyname.c +++ /dev/null @@ -1,11 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include - -struct hostent *gethostbyname(const char *name) -{ - return gethostbyname2(name, AF_INET); -} diff --git a/usr/lib/libc/network/gethostbyname2.c b/usr/lib/libc/network/gethostbyname2.c deleted file mode 100644 index dc9d6621b..000000000 --- a/usr/lib/libc/network/gethostbyname2.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include - -struct hostent *gethostbyname2(const char *name, int af) -{ - static struct hostent *h; - size_t size = 63; - struct hostent *res; - int err; - do { - free(h); - h = malloc(size+=size+1); - if (!h) { - h_errno = NO_RECOVERY; - return 0; - } - err = gethostbyname2_r(name, af, h, - (void *)(h+1), size-sizeof *h, &res, &h_errno); - } while (err == ERANGE); - return err ? 0 : h; -} diff --git a/usr/lib/libc/network/gethostbyname2_r.c b/usr/lib/libc/network/gethostbyname2_r.c deleted file mode 100644 index fc8948776..000000000 --- a/usr/lib/libc/network/gethostbyname2_r.c +++ /dev/null @@ -1,80 +0,0 @@ -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include "lookup.h" - -int gethostbyname2_r(const char *name, int af, - struct hostent *h, char *buf, size_t buflen, - struct hostent **res, int *err) -{ - struct address addrs[MAXADDRS]; - char canon[256]; - int i, cnt; - size_t align, need; - - *res = 0; - cnt = __lookup_name(addrs, canon, name, af, AI_CANONNAME); - if (cnt<0) switch (cnt) { - case EAI_NONAME: - *err = HOST_NOT_FOUND; - return ENOENT; - case EAI_AGAIN: - *err = TRY_AGAIN; - return EAGAIN; - default: - case EAI_FAIL: - *err = NO_RECOVERY; - return EBADMSG; - case EAI_MEMORY: - case EAI_SYSTEM: - *err = NO_RECOVERY; - return errno; - } - - h->h_addrtype = af; - h->h_length = af==AF_INET6 ? 16 : 4; - - /* Align buffer */ - align = -(uintptr_t)buf & sizeof(char *)-1; - - need = 4*sizeof(char *); - need += (cnt + 1) * (sizeof(char *) + h->h_length); - need += strlen(name)+1; - need += strlen(canon)+1; - need += align; - - if (need > buflen) return ERANGE; - - buf += align; - h->h_aliases = (void *)buf; - buf += 3*sizeof(char *); - h->h_addr_list = (void *)buf; - buf += (cnt+1)*sizeof(char *); - - for (i=0; ih_addr_list[i] = (void *)buf; - buf += h->h_length; - memcpy(h->h_addr_list[i], addrs[i].addr, h->h_length); - } - h->h_addr_list[i] = 0; - - h->h_name = h->h_aliases[0] = buf; - strcpy(h->h_name, canon); - buf += strlen(h->h_name)+1; - - if (strcmp(h->h_name, name)) { - h->h_aliases[1] = buf; - strcpy(h->h_aliases[1], name); - buf += strlen(h->h_aliases[1])+1; - } else h->h_aliases[1] = 0; - - h->h_aliases[2] = 0; - - *res = h; - return 0; -} diff --git a/usr/lib/libc/network/gethostbyname_r.c b/usr/lib/libc/network/gethostbyname_r.c deleted file mode 100644 index cd8725417..000000000 --- a/usr/lib/libc/network/gethostbyname_r.c +++ /dev/null @@ -1,11 +0,0 @@ -#define _GNU_SOURCE - -#include -#include - -int gethostbyname_r(const char *name, - struct hostent *h, char *buf, size_t buflen, - struct hostent **res, int *err) -{ - return gethostbyname2_r(name, AF_INET, h, buf, buflen, res, err); -} diff --git a/usr/lib/libc/network/getifaddrs.c b/usr/lib/libc/network/getifaddrs.c deleted file mode 100644 index fed75bd8d..000000000 --- a/usr/lib/libc/network/getifaddrs.c +++ /dev/null @@ -1,216 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include "netlink.h" - -#define IFADDRS_HASH_SIZE 64 - -/* getifaddrs() reports hardware addresses with PF_PACKET that implies - * struct sockaddr_ll. But e.g. Infiniband socket address length is - * longer than sockaddr_ll.ssl_addr[8] can hold. Use this hack struct - * to extend ssl_addr - callers should be able to still use it. */ -struct sockaddr_ll_hack { - unsigned short sll_family, sll_protocol; - int sll_ifindex; - unsigned short sll_hatype; - unsigned char sll_pkttype, sll_halen; - unsigned char sll_addr[24]; -}; - -union sockany { - struct sockaddr sa; - struct sockaddr_ll_hack ll; - struct sockaddr_in v4; - struct sockaddr_in6 v6; -}; - -struct ifaddrs_storage { - struct ifaddrs ifa; - struct ifaddrs_storage *hash_next; - union sockany addr, netmask, ifu; - unsigned int index; - char name[IFNAMSIZ+1]; -}; - -struct ifaddrs_ctx { - struct ifaddrs_storage *first; - struct ifaddrs_storage *last; - struct ifaddrs_storage *hash[IFADDRS_HASH_SIZE]; -}; - -void freeifaddrs(struct ifaddrs *ifp) -{ - struct ifaddrs *n; - while (ifp) { - n = ifp->ifa_next; - free(ifp); - ifp = n; - } -} - -static void copy_addr(struct sockaddr **r, int af, union sockany *sa, void *addr, size_t addrlen, int ifindex) -{ - uint8_t *dst; - int len; - - switch (af) { - case AF_INET: - dst = (uint8_t*) &sa->v4.sin_addr; - len = 4; - break; - case AF_INET6: - dst = (uint8_t*) &sa->v6.sin6_addr; - len = 16; - if (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr)) - sa->v6.sin6_scope_id = ifindex; - break; - default: - return; - } - if (addrlen < len) return; - sa->sa.sa_family = af; - memcpy(dst, addr, len); - *r = &sa->sa; -} - -static void gen_netmask(struct sockaddr **r, int af, union sockany *sa, int prefixlen) -{ - uint8_t addr[16] = {0}; - int i; - - if (prefixlen > 8*sizeof(addr)) prefixlen = 8*sizeof(addr); - i = prefixlen / 8; - memset(addr, 0xff, i); - if (i < sizeof(addr)) addr[i++] = 0xff << (8 - (prefixlen % 8)); - copy_addr(r, af, sa, addr, sizeof(addr), 0); -} - -static void copy_lladdr(struct sockaddr **r, union sockany *sa, void *addr, size_t addrlen, int ifindex, unsigned short hatype) -{ - if (addrlen > sizeof(sa->ll.sll_addr)) return; - sa->ll.sll_family = AF_PACKET; - sa->ll.sll_ifindex = ifindex; - sa->ll.sll_hatype = hatype; - sa->ll.sll_halen = addrlen; - memcpy(sa->ll.sll_addr, addr, addrlen); - *r = &sa->sa; -} - -static int netlink_msg_to_ifaddr(void *pctx, struct nlmsghdr *h) -{ - struct ifaddrs_ctx *ctx = pctx; - struct ifaddrs_storage *ifs, *ifs0; - struct ifinfomsg *ifi = NLMSG_DATA(h); - struct ifaddrmsg *ifa = NLMSG_DATA(h); - struct rtattr *rta; - int stats_len = 0; - - if (h->nlmsg_type == RTM_NEWLINK) { - for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { - if (rta->rta_type != IFLA_STATS) continue; - stats_len = RTA_DATALEN(rta); - break; - } - } else { - for (ifs0 = ctx->hash[ifa->ifa_index % IFADDRS_HASH_SIZE]; ifs0; ifs0 = ifs0->hash_next) - if (ifs0->index == ifa->ifa_index) - break; - if (!ifs0) return 0; - } - - ifs = calloc(1, sizeof(struct ifaddrs_storage) + stats_len); - if (ifs == 0) return -1; - - if (h->nlmsg_type == RTM_NEWLINK) { - ifs->index = ifi->ifi_index; - ifs->ifa.ifa_flags = ifi->ifi_flags; - - for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { - switch (rta->rta_type) { - case IFLA_IFNAME: - if (RTA_DATALEN(rta) < sizeof(ifs->name)) { - memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta)); - ifs->ifa.ifa_name = ifs->name; - } - break; - case IFLA_ADDRESS: - copy_lladdr(&ifs->ifa.ifa_addr, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type); - break; - case IFLA_BROADCAST: - copy_lladdr(&ifs->ifa.ifa_broadaddr, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type); - break; - case IFLA_STATS: - ifs->ifa.ifa_data = (void*)(ifs+1); - memcpy(ifs->ifa.ifa_data, RTA_DATA(rta), RTA_DATALEN(rta)); - break; - } - } - if (ifs->ifa.ifa_name) { - unsigned int bucket = ifs->index % IFADDRS_HASH_SIZE; - ifs->hash_next = ctx->hash[bucket]; - ctx->hash[bucket] = ifs; - } - } else { - ifs->ifa.ifa_name = ifs0->ifa.ifa_name; - ifs->ifa.ifa_flags = ifs0->ifa.ifa_flags; - for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { - switch (rta->rta_type) { - case IFA_ADDRESS: - /* If ifa_addr is already set we, received an IFA_LOCAL before - * so treat this as destination address */ - if (ifs->ifa.ifa_addr) - copy_addr(&ifs->ifa.ifa_dstaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); - else - copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); - break; - case IFA_BROADCAST: - copy_addr(&ifs->ifa.ifa_broadaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); - break; - case IFA_LOCAL: - /* If ifa_addr is set and we get IFA_LOCAL, assume we have - * a point-to-point network. Move address to correct field. */ - if (ifs->ifa.ifa_addr) { - ifs->ifu = ifs->addr; - ifs->ifa.ifa_dstaddr = &ifs->ifu.sa; - memset(&ifs->addr, 0, sizeof(ifs->addr)); - } - copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); - break; - case IFA_LABEL: - if (RTA_DATALEN(rta) < sizeof(ifs->name)) { - memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta)); - ifs->ifa.ifa_name = ifs->name; - } - break; - } - } - if (ifs->ifa.ifa_addr) - gen_netmask(&ifs->ifa.ifa_netmask, ifa->ifa_family, &ifs->netmask, ifa->ifa_prefixlen); - } - - if (ifs->ifa.ifa_name) { - if (!ctx->first) ctx->first = ifs; - if (ctx->last) ctx->last->ifa.ifa_next = &ifs->ifa; - ctx->last = ifs; - } else { - free(ifs); - } - return 0; -} - -int getifaddrs(struct ifaddrs **ifap) -{ - struct ifaddrs_ctx _ctx, *ctx = &_ctx; - int r; - memset(ctx, 0, sizeof *ctx); - r = __rtnetlink_enumerate(AF_UNSPEC, AF_UNSPEC, netlink_msg_to_ifaddr, ctx); - if (r == 0) *ifap = &ctx->first->ifa; - else freeifaddrs(&ctx->first->ifa); - return r; -} diff --git a/usr/lib/libc/network/getnameinfo.c b/usr/lib/libc/network/getnameinfo.c deleted file mode 100644 index 5e6fae3ed..000000000 --- a/usr/lib/libc/network/getnameinfo.c +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "lookup.h" -#include "stdio_impl.h" - -int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *); -int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); -int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int); -int __res_send(const unsigned char *, int, unsigned char *, int); - -#define PTR_MAX (64 + sizeof ".in-addr.arpa") -#define RR_PTR 12 - -static char *itoa(char *p, unsigned x) { - p += 3*sizeof(int); - *--p = 0; - do { - *--p = '0' + x % 10; - x /= 10; - } while (x); - return p; -} - -static void mkptr4(char *s, const unsigned char *ip) -{ - sprintf(s, "%d.%d.%d.%d.in-addr.arpa", - ip[3], ip[2], ip[1], ip[0]); -} - -static void mkptr6(char *s, const unsigned char *ip) -{ - static const char xdigits[] = "0123456789abcdef"; - int i; - for (i=15; i>=0; i--) { - *s++ = xdigits[ip[i]&15]; *s++ = '.'; - *s++ = xdigits[ip[i]>>4]; *s++ = '.'; - } - strcpy(s, "ip6.arpa"); -} - -static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, int family) -{ - char line[512], *p, *z; - unsigned char _buf[1032], atmp[16]; - struct address iplit; - FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); - if (!f) return; - if (family == AF_INET) { - memcpy(atmp+12, a, 4); - memcpy(atmp, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); - a = atmp; - } - while (fgets(line, sizeof line, f)) { - if ((p=strchr(line, '#'))) *p++='\n', *p=0; - - for (p=line; *p && !isspace(*p); p++); - *p++ = 0; - if (__lookup_ipliteral(&iplit, line, AF_UNSPEC)<=0) - continue; - - if (iplit.family == AF_INET) { - memcpy(iplit.addr+12, iplit.addr, 4); - memcpy(iplit.addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); - iplit.scopeid = 0; - } - - if (memcmp(a, iplit.addr, 16) || iplit.scopeid != scopeid) - continue; - - for (; *p && isspace(*p); p++); - for (z=p; *z && !isspace(*z); z++); - *z = 0; - if (z-p < 256) { - memcpy(buf, p, z-p+1); - break; - } - } - __fclose_ca(f); -} - -static void reverse_services(char *buf, int port, int dgram) -{ - unsigned long svport; - char line[128], *p, *z; - unsigned char _buf[1032]; - FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); - if (!f) return; - while (fgets(line, sizeof line, f)) { - if ((p=strchr(line, '#'))) *p++='\n', *p=0; - - for (p=line; *p && !isspace(*p); p++); - if (!*p) continue; - *p++ = 0; - svport = strtoul(p, &z, 10); - - if (svport != port || z==p) continue; - if (dgram && strncmp(z, "/udp", 4)) continue; - if (!dgram && strncmp(z, "/tcp", 4)) continue; - if (p-line > 32) continue; - - memcpy(buf, line, p-line); - break; - } - __fclose_ca(f); -} - -static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet) -{ - if (rr != RR_PTR) return 0; - if (__dn_expand(packet, (const unsigned char *)packet + 512, - data, c, 256) <= 0) - *(char *)c = 0; - return 0; - -} - -int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl, - char *restrict node, socklen_t nodelen, - char *restrict serv, socklen_t servlen, - int flags) -{ - char ptr[PTR_MAX]; - char buf[256], num[3*sizeof(int)+1]; - int af = sa->sa_family; - unsigned char *a; - unsigned scopeid; - - switch (af) { - case AF_INET: - a = (void *)&((struct sockaddr_in *)sa)->sin_addr; - if (sl < sizeof(struct sockaddr_in)) return EAI_FAMILY; - mkptr4(ptr, a); - scopeid = 0; - break; - case AF_INET6: - a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr; - if (sl < sizeof(struct sockaddr_in6)) return EAI_FAMILY; - if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12)) - mkptr6(ptr, a); - else - mkptr4(ptr, a+12); - scopeid = ((struct sockaddr_in6 *)sa)->sin6_scope_id; - break; - default: - return EAI_FAMILY; - } - - if (node && nodelen) { - buf[0] = 0; - if (!(flags & NI_NUMERICHOST)) { - reverse_hosts(buf, a, scopeid, af); - } - if (!*buf && !(flags & NI_NUMERICHOST)) { - unsigned char query[18+PTR_MAX], reply[512]; - int qlen = __res_mkquery(0, ptr, 1, RR_PTR, - 0, 0, 0, query, sizeof query); - int rlen = __res_send(query, qlen, reply, sizeof reply); - buf[0] = 0; - if (rlen > 0) - __dns_parse(reply, rlen, dns_parse_callback, buf); - } - if (!*buf) { - if (flags & NI_NAMEREQD) return EAI_NONAME; - inet_ntop(af, a, buf, sizeof buf); - if (scopeid) { - char *p = 0, tmp[IF_NAMESIZE+1]; - if (!(flags & NI_NUMERICSCOPE) && - (IN6_IS_ADDR_LINKLOCAL(a) || - IN6_IS_ADDR_MC_LINKLOCAL(a))) - p = if_indextoname(scopeid, tmp+1); - if (!p) - p = itoa(num, scopeid); - *--p = '%'; - strcat(buf, p); - } - } - if (strlen(buf) >= nodelen) return EAI_OVERFLOW; - strcpy(node, buf); - } - - if (serv && servlen) { - char *p = buf; - int port = ntohs(((struct sockaddr_in *)sa)->sin_port); - buf[0] = 0; - if (!(flags & NI_NUMERICSERV)) - reverse_services(buf, port, flags & NI_DGRAM); - if (!*p) - p = itoa(num, port); - if (strlen(p) >= servlen) - return EAI_OVERFLOW; - strcpy(serv, p); - } - - return 0; -} diff --git a/usr/lib/libc/network/getpeername.c b/usr/lib/libc/network/getpeername.c deleted file mode 100644 index 6567b4519..000000000 --- a/usr/lib/libc/network/getpeername.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) -{ - return socketcall(getpeername, fd, addr, len, 0, 0, 0); -} diff --git a/usr/lib/libc/network/getservbyname.c b/usr/lib/libc/network/getservbyname.c deleted file mode 100644 index dd3037678..000000000 --- a/usr/lib/libc/network/getservbyname.c +++ /dev/null @@ -1,12 +0,0 @@ -#define _GNU_SOURCE -#include - -struct servent *getservbyname(const char *name, const char *prots) -{ - static struct servent se; - static char *buf[2]; - struct servent *res; - if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res)) - return 0; - return &se; -} diff --git a/usr/lib/libc/network/getservbyname_r.c b/usr/lib/libc/network/getservbyname_r.c deleted file mode 100644 index ad3d6164c..000000000 --- a/usr/lib/libc/network/getservbyname_r.c +++ /dev/null @@ -1,49 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include "lookup.h" - -#define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *)) - -int getservbyname_r(const char *name, const char *prots, - struct servent *se, char *buf, size_t buflen, struct servent **res) -{ - struct service servs[MAXSERVS]; - int cnt, proto, align; - - *res = 0; - - /* Align buffer */ - align = -(uintptr_t)buf & ALIGN-1; - if (buflen < 2*sizeof(char *)+align) - return ERANGE; - buf += align; - - if (!prots) proto = 0; - else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP; - else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP; - else return EINVAL; - - cnt = __lookup_serv(servs, name, proto, 0, 0); - if (cnt<0) switch (cnt) { - case EAI_MEMORY: - case EAI_SYSTEM: - return ENOMEM; - default: - return ENOENT; - } - - se->s_name = (char *)name; - se->s_aliases = (void *)buf; - se->s_aliases[0] = se->s_name; - se->s_aliases[1] = 0; - se->s_port = htons(servs[0].port); - se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp"; - - *res = se; - return 0; -} diff --git a/usr/lib/libc/network/getservbyport.c b/usr/lib/libc/network/getservbyport.c deleted file mode 100644 index c9ecbb11c..000000000 --- a/usr/lib/libc/network/getservbyport.c +++ /dev/null @@ -1,12 +0,0 @@ -#define _GNU_SOURCE -#include - -struct servent *getservbyport(int port, const char *prots) -{ - static struct servent se; - static long buf[32/sizeof(long)]; - struct servent *res; - if (getservbyport_r(port, prots, &se, (void *)buf, sizeof buf, &res)) - return 0; - return &se; -} diff --git a/usr/lib/libc/network/getservbyport_r.c b/usr/lib/libc/network/getservbyport_r.c deleted file mode 100644 index 0ae0e4158..000000000 --- a/usr/lib/libc/network/getservbyport_r.c +++ /dev/null @@ -1,56 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include - -int getservbyport_r(int port, const char *prots, - struct servent *se, char *buf, size_t buflen, struct servent **res) -{ - int i; - struct sockaddr_in sin = { - .sin_family = AF_INET, - .sin_port = port, - }; - - if (!prots) { - int r = getservbyport_r(port, "tcp", se, buf, buflen, res); - if (r) r = getservbyport_r(port, "udp", se, buf, buflen, res); - return r; - } - *res = 0; - - /* Align buffer */ - i = (uintptr_t)buf & sizeof(char *)-1; - if (!i) i = sizeof(char *); - if (buflen < 3*sizeof(char *)-i) - return ERANGE; - buf += sizeof(char *)-i; - buflen -= sizeof(char *)-i; - - if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return EINVAL; - - se->s_port = port; - se->s_proto = (char *)prots; - se->s_aliases = (void *)buf; - buf += 2*sizeof(char *); - buflen -= 2*sizeof(char *); - se->s_aliases[1] = 0; - se->s_aliases[0] = se->s_name = buf; - - switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen, - strcmp(prots, "udp") ? 0 : NI_DGRAM)) { - case EAI_MEMORY: - case EAI_SYSTEM: - return ENOMEM; - default: - return ENOENT; - case 0: - break; - } - - *res = se; - return 0; -} diff --git a/usr/lib/libc/network/getsockname.c b/usr/lib/libc/network/getsockname.c deleted file mode 100644 index 7885fc13b..000000000 --- a/usr/lib/libc/network/getsockname.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) -{ - return socketcall(getsockname, fd, addr, len, 0, 0, 0); -} diff --git a/usr/lib/libc/network/getsockopt.c b/usr/lib/libc/network/getsockopt.c deleted file mode 100644 index 28079d8c0..000000000 --- a/usr/lib/libc/network/getsockopt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getsockopt(int fd, int level, int optname, void *restrict optval, socklen_t *restrict optlen) -{ - return socketcall(getsockopt, fd, level, optname, optval, optlen, 0); -} diff --git a/usr/lib/libc/network/h_errno.c b/usr/lib/libc/network/h_errno.c deleted file mode 100644 index 4f700ceaf..000000000 --- a/usr/lib/libc/network/h_errno.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#undef h_errno -int h_errno; - -int *__h_errno_location(void) -{ - return &h_errno; -} diff --git a/usr/lib/libc/network/herror.c b/usr/lib/libc/network/herror.c deleted file mode 100644 index 65f25ff3f..000000000 --- a/usr/lib/libc/network/herror.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -void herror(const char *msg) -{ - fprintf(stderr, "%s%s%s", msg?msg:"", msg?": ":"", hstrerror(h_errno)); -} diff --git a/usr/lib/libc/network/hstrerror.c b/usr/lib/libc/network/hstrerror.c deleted file mode 100644 index a4d001c53..000000000 --- a/usr/lib/libc/network/hstrerror.c +++ /dev/null @@ -1,18 +0,0 @@ -#define _GNU_SOURCE -#include -#include "locale_impl.h" - -static const char msgs[] = - "Host not found\0" - "Try again\0" - "Non-recoverable error\0" - "Address not available\0" - "\0Unknown error"; - -const char *hstrerror(int ecode) -{ - const char *s; - for (s=msgs, ecode--; ecode && *s; ecode--, s++) for (; *s; s++); - if (!*s) s++; - return LCTRANS_CUR(s); -} diff --git a/usr/lib/libc/network/htonl.c b/usr/lib/libc/network/htonl.c deleted file mode 100644 index 251ed27df..000000000 --- a/usr/lib/libc/network/htonl.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include - -uint32_t htonl(uint32_t n) -{ - union { int i; char c; } u = { 1 }; - return u.c ? bswap_32(n) : n; -} diff --git a/usr/lib/libc/network/htons.c b/usr/lib/libc/network/htons.c deleted file mode 100644 index 03a3a1d59..000000000 --- a/usr/lib/libc/network/htons.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -uint16_t htons(uint16_t n) -{ - union { int i; char c; } u = { 1 }; - return u.c ? bswap_16(n) : n; -} diff --git a/usr/lib/libc/network/if_freenameindex.c b/usr/lib/libc/network/if_freenameindex.c deleted file mode 100644 index 89bafcc0c..000000000 --- a/usr/lib/libc/network/if_freenameindex.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void if_freenameindex(struct if_nameindex *idx) -{ - free(idx); -} diff --git a/usr/lib/libc/network/if_indextoname.c b/usr/lib/libc/network/if_indextoname.c deleted file mode 100644 index 3b368bf0d..000000000 --- a/usr/lib/libc/network/if_indextoname.c +++ /dev/null @@ -1,23 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include "syscall.h" - -char *if_indextoname(unsigned index, char *name) -{ - struct ifreq ifr; - int fd, r; - - if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0; - ifr.ifr_ifindex = index; - r = ioctl(fd, SIOCGIFNAME, &ifr); - __syscall(SYS_close, fd); - if (r < 0) { - if (errno == ENODEV) errno = ENXIO; - return 0; - } - return strncpy(name, ifr.ifr_name, IF_NAMESIZE); -} diff --git a/usr/lib/libc/network/if_nameindex.c b/usr/lib/libc/network/if_nameindex.c deleted file mode 100644 index 2deaef769..000000000 --- a/usr/lib/libc/network/if_nameindex.c +++ /dev/null @@ -1,114 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include "netlink.h" - -#define IFADDRS_HASH_SIZE 64 - -struct ifnamemap { - unsigned int hash_next; - unsigned int index; - unsigned char namelen; - char name[IFNAMSIZ]; -}; - -struct ifnameindexctx { - unsigned int num, allocated, str_bytes; - struct ifnamemap *list; - unsigned int hash[IFADDRS_HASH_SIZE]; -}; - -static int netlink_msg_to_nameindex(void *pctx, struct nlmsghdr *h) -{ - struct ifnameindexctx *ctx = pctx; - struct ifnamemap *map; - struct rtattr *rta; - unsigned int i; - int index, type, namelen, bucket; - - if (h->nlmsg_type == RTM_NEWLINK) { - struct ifinfomsg *ifi = NLMSG_DATA(h); - index = ifi->ifi_index; - type = IFLA_IFNAME; - rta = NLMSG_RTA(h, sizeof(*ifi)); - } else { - struct ifaddrmsg *ifa = NLMSG_DATA(h); - index = ifa->ifa_index; - type = IFA_LABEL; - rta = NLMSG_RTA(h, sizeof(*ifa)); - } - for (; NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { - if (rta->rta_type != type) continue; - - namelen = RTA_DATALEN(rta) - 1; - if (namelen > IFNAMSIZ) return 0; - - /* suppress duplicates */ - bucket = index % IFADDRS_HASH_SIZE; - i = ctx->hash[bucket]; - while (i) { - map = &ctx->list[i-1]; - if (map->index == index && - map->namelen == namelen && - memcmp(map->name, RTA_DATA(rta), namelen) == 0) - return 0; - i = map->hash_next; - } - - if (ctx->num >= ctx->allocated) { - size_t a = ctx->allocated ? ctx->allocated * 2 + 1 : 8; - if (a > SIZE_MAX/sizeof *map) return -1; - map = realloc(ctx->list, a * sizeof *map); - if (!map) return -1; - ctx->list = map; - ctx->allocated = a; - } - map = &ctx->list[ctx->num]; - map->index = index; - map->namelen = namelen; - memcpy(map->name, RTA_DATA(rta), namelen); - ctx->str_bytes += namelen + 1; - ctx->num++; - map->hash_next = ctx->hash[bucket]; - ctx->hash[bucket] = ctx->num; - return 0; - } - return 0; -} - -struct if_nameindex *if_nameindex() -{ - struct ifnameindexctx _ctx, *ctx = &_ctx; - struct if_nameindex *ifs = 0, *d; - struct ifnamemap *s; - char *p; - int i; - int cs; - - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - memset(ctx, 0, sizeof(*ctx)); - if (__rtnetlink_enumerate(AF_UNSPEC, AF_INET, netlink_msg_to_nameindex, ctx) < 0) goto err; - - ifs = malloc(sizeof(struct if_nameindex[ctx->num+1]) + ctx->str_bytes); - if (!ifs) goto err; - - p = (char*)(ifs + ctx->num + 1); - for (i = ctx->num, d = ifs, s = ctx->list; i; i--, s++, d++) { - d->if_index = s->index; - d->if_name = p; - memcpy(p, s->name, s->namelen); - p += s->namelen; - *p++ = 0; - } - d->if_index = 0; - d->if_name = 0; -err: - pthread_setcancelstate(cs, 0); - free(ctx->list); - errno = ENOBUFS; - return ifs; -} diff --git a/usr/lib/libc/network/if_nametoindex.c b/usr/lib/libc/network/if_nametoindex.c deleted file mode 100644 index 331413c68..000000000 --- a/usr/lib/libc/network/if_nametoindex.c +++ /dev/null @@ -1,18 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include "syscall.h" - -unsigned if_nametoindex(const char *name) -{ - struct ifreq ifr; - int fd, r; - - if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0; - strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); - r = ioctl(fd, SIOCGIFINDEX, &ifr); - __syscall(SYS_close, fd); - return r < 0 ? 0 : ifr.ifr_ifindex; -} diff --git a/usr/lib/libc/network/in6addr_any.c b/usr/lib/libc/network/in6addr_any.c deleted file mode 100644 index 995387fae..000000000 --- a/usr/lib/libc/network/in6addr_any.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; diff --git a/usr/lib/libc/network/in6addr_loopback.c b/usr/lib/libc/network/in6addr_loopback.c deleted file mode 100644 index b96005b81..000000000 --- a/usr/lib/libc/network/in6addr_loopback.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; diff --git a/usr/lib/libc/network/inet_addr.c b/usr/lib/libc/network/inet_addr.c deleted file mode 100644 index 10b21f211..000000000 --- a/usr/lib/libc/network/inet_addr.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include - -int __inet_aton(const char *, struct in_addr *); - -in_addr_t inet_addr(const char *p) -{ - struct in_addr a; - if (!__inet_aton(p, &a)) return -1; - return a.s_addr; -} diff --git a/usr/lib/libc/network/inet_aton.c b/usr/lib/libc/network/inet_aton.c deleted file mode 100644 index 0f9a45f66..000000000 --- a/usr/lib/libc/network/inet_aton.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include "libc.h" - -int __inet_aton(const char *s0, struct in_addr *dest) -{ - const char *s = s0; - unsigned char *d = (void *)dest; - unsigned long a[4] = { 0 }; - char *z; - int i; - - for (i=0; i<4; i++) { - a[i] = strtoul(s, &z, 0); - if (z==s || (*z && *z != '.') || !isdigit(*s)) - return 0; - if (!*z) break; - s=z+1; - } - if (i==4) return 0; - switch (i) { - case 0: - a[1] = a[0] & 0xffffff; - a[0] >>= 24; - case 1: - a[2] = a[1] & 0xffff; - a[1] >>= 16; - case 2: - a[3] = a[2] & 0xff; - a[2] >>= 8; - } - for (i=0; i<4; i++) { - if (a[i] > 255) return 0; - d[i] = a[i]; - } - return 1; -} - -weak_alias(__inet_aton, inet_aton); diff --git a/usr/lib/libc/network/inet_legacy.c b/usr/lib/libc/network/inet_legacy.c deleted file mode 100644 index 621b47b05..000000000 --- a/usr/lib/libc/network/inet_legacy.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -in_addr_t inet_network(const char *p) -{ - return ntohl(inet_addr(p)); -} - -struct in_addr inet_makeaddr(in_addr_t n, in_addr_t h) -{ - if (n < 256) h |= n<<24; - else if (n < 65536) h |= n<<16; - else h |= n<<8; - return (struct in_addr){ h }; -} - -in_addr_t inet_lnaof(struct in_addr in) -{ - uint32_t h = in.s_addr; - if (h>>24 < 128) return h & 0xffffff; - if (h>>24 < 192) return h & 0xffff; - return h & 0xff; -} - -in_addr_t inet_netof(struct in_addr in) -{ - uint32_t h = in.s_addr; - if (h>>24 < 128) return h >> 24; - if (h>>24 < 192) return h >> 16; - return h >> 8; -} diff --git a/usr/lib/libc/network/inet_ntoa.c b/usr/lib/libc/network/inet_ntoa.c deleted file mode 100644 index 71411e0b5..000000000 --- a/usr/lib/libc/network/inet_ntoa.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -char *inet_ntoa(struct in_addr in) -{ - static char buf[16]; - unsigned char *a = (void *)∈ - snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); - return buf; -} diff --git a/usr/lib/libc/network/inet_ntop.c b/usr/lib/libc/network/inet_ntop.c deleted file mode 100644 index 14f9f4c40..000000000 --- a/usr/lib/libc/network/inet_ntop.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include -#include -#include - -const char *inet_ntop(int af, const void *restrict a0, char *restrict s, socklen_t l) -{ - const unsigned char *a = a0; - int i, j, max, best; - char buf[100]; - - switch (af) { - case AF_INET: - if (snprintf(s, l, "%d.%d.%d.%d", a[0],a[1],a[2],a[3]) < l) - return s; - break; - case AF_INET6: - if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\377\377", 12)) - snprintf(buf, sizeof buf, - "%x:%x:%x:%x:%x:%x:%x:%x", - 256*a[0]+a[1],256*a[2]+a[3], - 256*a[4]+a[5],256*a[6]+a[7], - 256*a[8]+a[9],256*a[10]+a[11], - 256*a[12]+a[13],256*a[14]+a[15]); - else - snprintf(buf, sizeof buf, - "%x:%x:%x:%x:%x:%x:%d.%d.%d.%d", - 256*a[0]+a[1],256*a[2]+a[3], - 256*a[4]+a[5],256*a[6]+a[7], - 256*a[8]+a[9],256*a[10]+a[11], - a[12],a[13],a[14],a[15]); - /* Replace longest /(^0|:)[:0]{2,}/ with "::" */ - for (i=best=0, max=2; buf[i]; i++) { - if (i && buf[i] != ':') continue; - j = strspn(buf+i, ":0"); - if (j>max) best=i, max=j; - } - if (max>2) { - buf[best] = buf[best+1] = ':'; - memmove(buf+best+2, buf+best+max, i-best-max+1); - } - if (strlen(buf) < l) { - strcpy(s, buf); - return s; - } - break; - default: - errno = EAFNOSUPPORT; - return 0; - } - errno = ENOSPC; - return 0; -} diff --git a/usr/lib/libc/network/inet_pton.c b/usr/lib/libc/network/inet_pton.c deleted file mode 100644 index d36c36891..000000000 --- a/usr/lib/libc/network/inet_pton.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include -#include - -static int hexval(unsigned c) -{ - if (c-'0'<10) return c-'0'; - c |= 32; - if (c-'a'<6) return c-'a'+10; - return -1; -} - -int inet_pton(int af, const char *restrict s, void *restrict a0) -{ - uint16_t ip[8]; - unsigned char *a = a0; - int i, j, v, d, brk=-1, need_v4=0; - - if (af==AF_INET) { - for (i=0; i<4; i++) { - for (v=j=0; j<3 && isdigit(s[j]); j++) - v = 10*v + s[j]-'0'; - if (j==0 || (j>1 && s[0]=='0') || v>255) return 0; - a[i] = v; - if (s[j]==0 && i==3) return 1; - if (s[j]!='.') return 0; - s += j+1; - } - return 0; - } else if (af!=AF_INET6) { - errno = EAFNOSUPPORT; - return -1; - } - - if (*s==':' && *++s!=':') return 0; - - for (i=0; ; i++) { - if (s[0]==':' && brk<0) { - brk=i; - ip[i&7]=0; - if (!*++s) break; - if (i==7) return 0; - continue; - } - for (v=j=0; j<4 && (d=hexval(s[j]))>=0; j++) - v=16*v+d; - if (j==0) return 0; - ip[i&7] = v; - if (!s[j] && (brk>=0 || i==7)) break; - if (i==7) return 0; - if (s[j]!=':') { - if (s[j]!='.' || (i<6 && brk<0)) return 0; - need_v4=1; - i++; - break; - } - s += j+1; - } - if (brk>=0) { - memmove(ip+brk+7-i, ip+brk, 2*(i+1-brk)); - for (j=0; j<7-i; j++) ip[brk+j] = 0; - } - for (j=0; j<8; j++) { - *a++ = ip[j]>>8; - *a++ = ip[j]; - } - if (need_v4 && inet_pton(AF_INET, (void *)s, a-4) <= 0) return 0; - return 1; -} diff --git a/usr/lib/libc/network/listen.c b/usr/lib/libc/network/listen.c deleted file mode 100644 index dd19aec57..000000000 --- a/usr/lib/libc/network/listen.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int listen(int fd, int backlog) -{ - return __syscall_ret(sys_listen(fd, backlog)); -} diff --git a/usr/lib/libc/network/lookup.h b/usr/lib/libc/network/lookup.h deleted file mode 100644 index 0468edbc6..000000000 --- a/usr/lib/libc/network/lookup.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef LOOKUP_H -#define LOOKUP_H - -#include -#include - -struct address { - int family; - unsigned scopeid; - uint8_t addr[16]; - int sortkey; -}; - -struct service { - uint16_t port; - unsigned char proto, socktype; -}; - -#define MAXNS 3 - -struct resolvconf { - struct address ns[MAXNS]; - unsigned nns, attempts, ndots; - unsigned timeout; -}; - -/* The limit of 48 results is a non-sharp bound on the number of addresses - * that can fit in one 512-byte DNS packet full of v4 results and a second - * packet full of v6 results. Due to headers, the actual limit is lower. */ -#define MAXADDRS 48 -#define MAXSERVS 2 - -int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags); -int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags); -int __lookup_ipliteral(struct address buf[static 1], const char *name, int family); - -int __get_resolv_conf(struct resolvconf *, char *, size_t); - -#endif diff --git a/usr/lib/libc/network/lookup_ipliteral.c b/usr/lib/libc/network/lookup_ipliteral.c deleted file mode 100644 index 8ed146052..000000000 --- a/usr/lib/libc/network/lookup_ipliteral.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "lookup.h" - -int __inet_aton(const char *, struct in_addr *); - -int __lookup_ipliteral(struct address buf[static 1], const char *name, int family) -{ - struct in_addr a4; - struct in6_addr a6; - if (__inet_aton(name, &a4) > 0) { - if (family == AF_INET6) /* wrong family */ - return EAI_NONAME; - memcpy(&buf[0].addr, &a4, sizeof a4); - buf[0].family = AF_INET; - buf[0].scopeid = 0; - return 1; - } - - char tmp[64]; - char *p = strchr(name, '%'), *z; - unsigned long long scopeid = 0; - if (p && p-name < 64) { - memcpy(tmp, name, p-name); - tmp[p-name] = 0; - name = tmp; - } - - if (inet_pton(AF_INET6, name, &a6) <= 0) - return 0; - if (family == AF_INET) /* wrong family */ - return EAI_NONAME; - - memcpy(&buf[0].addr, &a6, sizeof a6); - buf[0].family = AF_INET6; - if (p) { - if (isdigit(*++p)) scopeid = strtoull(p, &z, 10); - else z = p-1; - if (*z) { - if (!IN6_IS_ADDR_LINKLOCAL(&a6) && - !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) - return EAI_NONAME; - scopeid = if_nametoindex(p); - if (!scopeid) return EAI_NONAME; - } - if (scopeid > UINT_MAX) return EAI_NONAME; - } - buf[0].scopeid = scopeid; - return 1; -} diff --git a/usr/lib/libc/network/lookup_name.c b/usr/lib/libc/network/lookup_name.c deleted file mode 100644 index 066be4d52..000000000 --- a/usr/lib/libc/network/lookup_name.c +++ /dev/null @@ -1,398 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "lookup.h" -#include "stdio_impl.h" -#include "syscall.h" - -static int is_valid_hostname(const char *host) -{ - const unsigned char *s; - if (strnlen(host, 255)-1 >= 254 || mbstowcs(0, host, 0) == -1) return 0; - for (s=(void *)host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++); - return !*s; -} - -static int name_from_null(struct address buf[static 2], const char *name, int family, int flags) -{ - int cnt = 0; - if (name) return 0; - if (flags & AI_PASSIVE) { - if (family != AF_INET6) - buf[cnt++] = (struct address){ .family = AF_INET }; - if (family != AF_INET) - buf[cnt++] = (struct address){ .family = AF_INET6 }; - } else { - if (family != AF_INET6) - buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } }; - if (family != AF_INET) - buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } }; - } - return cnt; -} - -static int name_from_numeric(struct address buf[static 1], const char *name, int family) -{ - return __lookup_ipliteral(buf, name, family); -} - -static int name_from_hosts(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) -{ - char line[512]; - size_t l = strlen(name); - int cnt = 0, badfam = 0; - unsigned char _buf[1032]; - FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); - if (!f) switch (errno) { - case ENOENT: - case ENOTDIR: - case EACCES: - return 0; - default: - return EAI_SYSTEM; - } - while (fgets(line, sizeof line, f) && cnt < MAXADDRS) { - char *p, *z; - - if ((p=strchr(line, '#'))) *p++='\n', *p=0; - for(p=line+1; (p=strstr(p, name)) && - (!isspace(p[-1]) || !isspace(p[l])); p++); - if (!p) continue; - - /* Isolate IP address to parse */ - for (p=line; *p && !isspace(*p); p++); - *p++ = 0; - switch (name_from_numeric(buf+cnt, line, family)) { - case 1: - cnt++; - break; - case 0: - continue; - default: - badfam = EAI_NONAME; - continue; - } - - /* Extract first name as canonical name */ - for (; *p && isspace(*p); p++); - for (z=p; *z && !isspace(*z); z++); - *z = 0; - if (is_valid_hostname(p)) memcpy(canon, p, z-p+1); - } - __fclose_ca(f); - return cnt ? cnt : badfam; -} - -struct dpc_ctx { - struct address *addrs; - char *canon; - int cnt; -}; - -int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *); -int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); -int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int); -int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *); - -#define RR_A 1 -#define RR_CNAME 5 -#define RR_AAAA 28 - -static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet) -{ - char tmp[256]; - struct dpc_ctx *ctx = c; - switch (rr) { - case RR_A: - if (len != 4) return -1; - ctx->addrs[ctx->cnt].family = AF_INET; - ctx->addrs[ctx->cnt].scopeid = 0; - memcpy(ctx->addrs[ctx->cnt++].addr, data, 4); - break; - case RR_AAAA: - if (len != 16) return -1; - ctx->addrs[ctx->cnt].family = AF_INET6; - ctx->addrs[ctx->cnt].scopeid = 0; - memcpy(ctx->addrs[ctx->cnt++].addr, data, 16); - break; - case RR_CNAME: - if (__dn_expand(packet, (const unsigned char *)packet + 512, - data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp)) - strcpy(ctx->canon, tmp); - break; - } - return 0; -} - -static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf) -{ - unsigned char qbuf[2][280], abuf[2][512]; - const unsigned char *qp[2] = { qbuf[0], qbuf[1] }; - unsigned char *ap[2] = { abuf[0], abuf[1] }; - int qlens[2], alens[2]; - int i, nq = 0; - struct dpc_ctx ctx = { .addrs = buf, .canon = canon }; - static const struct { int af; int rr; } afrr[2] = { - { .af = AF_INET6, .rr = RR_A }, - { .af = AF_INET, .rr = RR_AAAA }, - }; - - for (i=0; i<2; i++) { - if (family != afrr[i].af) { - qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr, - 0, 0, 0, qbuf[nq], sizeof *qbuf); - if (qlens[nq] == -1) - return EAI_NONAME; - nq++; - } - } - - if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0) - return EAI_SYSTEM; - - for (i=0; i=ndots or name ends in - * a dot, which is an explicit request for global scope. */ - for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++; - if (dots >= conf.ndots || name[l-1]=='.') *search = 0; - - /* This can never happen; the caller already checked length. */ - if (l >= 256) return EAI_NONAME; - - /* Name with search domain appended is setup in canon[]. This both - * provides the desired default canonical name (if the requested - * name is not a CNAME record) and serves as a buffer for passing - * the full requested name to name_from_dns. */ - memcpy(canon, name, l); - canon[l] = '.'; - - for (p=search; *p; p=z) { - for (; isspace(*p); p++); - for (z=p; *z && !isspace(*z); z++); - if (z==p) break; - if (z-p < 256 - l - 1) { - memcpy(canon+l+1, p, z-p); - canon[z-p+1+l] = 0; - int cnt = name_from_dns(buf, canon, canon, family, &conf); - if (cnt) return cnt; - } - } - - canon[l] = 0; - return name_from_dns(buf, canon, name, family, &conf); -} - -static const struct policy { - unsigned char addr[16]; - unsigned char len, mask; - unsigned char prec, label; -} defpolicy[] = { - { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", 15, 0xff, 50, 0 }, - { "\0\0\0\0\0\0\0\0\0\0\xff\xff", 11, 0xff, 35, 4 }, - { "\x20\2", 1, 0xff, 30, 2 }, - { "\x20\1", 3, 0xff, 5, 5 }, - { "\xfc", 0, 0xfe, 3, 13 }, -#if 0 - /* These are deprecated and/or returned to the address - * pool, so despite the RFC, treating them as special - * is probably wrong. */ - { "", 11, 0xff, 1, 3 }, - { "\xfe\xc0", 1, 0xc0, 1, 11 }, - { "\x3f\xfe", 1, 0xff, 1, 12 }, -#endif - /* Last rule must match all addresses to stop loop. */ - { "", 0, 0, 40, 1 }, -}; - -static const struct policy *policyof(const struct in6_addr *a) -{ - int i; - for (i=0; ; i++) { - if (memcmp(a->s6_addr, defpolicy[i].addr, defpolicy[i].len)) - continue; - if ((a->s6_addr[defpolicy[i].len] & defpolicy[i].mask) - != defpolicy[i].addr[defpolicy[i].len]) - continue; - return defpolicy+i; - } -} - -static int labelof(const struct in6_addr *a) -{ - return policyof(a)->label; -} - -static int scopeof(const struct in6_addr *a) -{ - if (IN6_IS_ADDR_MULTICAST(a)) return a->s6_addr[1] & 15; - if (IN6_IS_ADDR_LINKLOCAL(a)) return 2; - if (IN6_IS_ADDR_LOOPBACK(a)) return 2; - if (IN6_IS_ADDR_SITELOCAL(a)) return 5; - return 14; -} - -static int prefixmatch(const struct in6_addr *s, const struct in6_addr *d) -{ - /* FIXME: The common prefix length should be limited to no greater - * than the nominal length of the prefix portion of the source - * address. However the definition of the source prefix length is - * not clear and thus this limiting is not yet implemented. */ - unsigned i; - for (i=0; i<128 && !((s->s6_addr[i/8]^d->s6_addr[i/8])&(128>>(i%8))); i++); - return i; -} - -#define DAS_USABLE 0x40000000 -#define DAS_MATCHINGSCOPE 0x20000000 -#define DAS_MATCHINGLABEL 0x10000000 -#define DAS_PREC_SHIFT 20 -#define DAS_SCOPE_SHIFT 16 -#define DAS_PREFIX_SHIFT 8 -#define DAS_ORDER_SHIFT 0 - -static int addrcmp(const void *_a, const void *_b) -{ - const struct address *a = _a, *b = _b; - return b->sortkey - a->sortkey; -} - -int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags) -{ - int cnt = 0, i, j; - - *canon = 0; - if (name) { - /* reject empty name and check len so it fits into temp bufs */ - size_t l = strnlen(name, 255); - if (l-1 >= 254) - return EAI_NONAME; - memcpy(canon, name, l+1); - } - - /* Procedurally, a request for v6 addresses with the v4-mapped - * flag set is like a request for unspecified family, followed - * by filtering of the results. */ - if (flags & AI_V4MAPPED) { - if (family == AF_INET6) family = AF_UNSPEC; - else flags -= AI_V4MAPPED; - } - - /* Try each backend until there's at least one result. */ - cnt = name_from_null(buf, name, family, flags); - if (!cnt) cnt = name_from_numeric(buf, name, family); - if (!cnt && !(flags & AI_NUMERICHOST)) { - cnt = name_from_hosts(buf, canon, name, family); - if (!cnt) cnt = name_from_dns_search(buf, canon, name, family); - } - if (cnt<=0) return cnt ? cnt : EAI_NONAME; - - /* Filter/transform results for v4-mapped lookup, if requested. */ - if (flags & AI_V4MAPPED) { - if (!(flags & AI_ALL)) { - /* If any v6 results exist, remove v4 results. */ - for (i=0; ilabel; - int dprec = dpolicy->prec; - int prefixlen = 0; - int fd = socket(AF_INET6, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP); - if (fd >= 0) { - if (!connect(fd, (void *)&da, sizeof da)) { - key |= DAS_USABLE; - if (!getsockname(fd, (void *)&sa, - &(socklen_t){sizeof sa})) { - if (dscope == scopeof(&sa.sin6_addr)) - key |= DAS_MATCHINGSCOPE; - if (dlabel == labelof(&sa.sin6_addr)) - key |= DAS_MATCHINGLABEL; - prefixlen = prefixmatch(&sa.sin6_addr, - &da.sin6_addr); - } - } - close(fd); - } - key |= dprec << DAS_PREC_SHIFT; - key |= (15-dscope) << DAS_SCOPE_SHIFT; - key |= prefixlen << DAS_PREFIX_SHIFT; - key |= (MAXADDRS-i) << DAS_ORDER_SHIFT; - buf[i].sortkey = key; - } - qsort(buf, cnt, sizeof *buf, addrcmp); - - pthread_setcancelstate(cs, 0); - - return cnt; -} diff --git a/usr/lib/libc/network/lookup_serv.c b/usr/lib/libc/network/lookup_serv.c deleted file mode 100644 index 66ebaea25..000000000 --- a/usr/lib/libc/network/lookup_serv.c +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "lookup.h" -#include "stdio_impl.h" - -int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags) -{ - char line[128]; - int cnt = 0; - char *p, *z = ""; - unsigned long port = 0; - - switch (socktype) { - case SOCK_STREAM: - switch (proto) { - case 0: - proto = IPPROTO_TCP; - case IPPROTO_TCP: - break; - default: - return EAI_SERVICE; - } - break; - case SOCK_DGRAM: - switch (proto) { - case 0: - proto = IPPROTO_UDP; - case IPPROTO_UDP: - break; - default: - return EAI_SERVICE; - } - case 0: - break; - default: - if (name) return EAI_SERVICE; - buf[0].port = 0; - buf[0].proto = proto; - buf[0].socktype = socktype; - return 1; - } - - if (name) { - if (!*name) return EAI_SERVICE; - port = strtoul(name, &z, 10); - } - if (!*z) { - if (port > 65535) return EAI_SERVICE; - if (proto != IPPROTO_UDP) { - buf[cnt].port = port; - buf[cnt].socktype = SOCK_STREAM; - buf[cnt++].proto = IPPROTO_TCP; - } - if (proto != IPPROTO_TCP) { - buf[cnt].port = port; - buf[cnt].socktype = SOCK_DGRAM; - buf[cnt++].proto = IPPROTO_UDP; - } - return cnt; - } - - if (flags & AI_NUMERICSERV) return EAI_SERVICE; - - size_t l = strlen(name); - - unsigned char _buf[1032]; - FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); - if (!f) switch (errno) { - case ENOENT: - case ENOTDIR: - case EACCES: - return EAI_SERVICE; - default: - return EAI_SYSTEM; - } - - while (fgets(line, sizeof line, f) && cnt < MAXSERVS) { - if ((p=strchr(line, '#'))) *p++='\n', *p=0; - - /* Find service name */ - for(p=line; (p=strstr(p, name)); p++) { - if (p>line && !isspace(p[-1])) continue; - if (p[l] && !isspace(p[l])) continue; - break; - } - if (!p) continue; - - /* Skip past canonical name at beginning of line */ - for (p=line; *p && !isspace(*p); p++); - - port = strtoul(p, &z, 10); - if (port > 65535 || z==p) continue; - if (!strncmp(z, "/udp", 4)) { - if (proto == IPPROTO_TCP) continue; - buf[cnt].port = port; - buf[cnt].socktype = SOCK_DGRAM; - buf[cnt++].proto = IPPROTO_UDP; - } - if (!strncmp(z, "/tcp", 4)) { - if (proto == IPPROTO_UDP) continue; - buf[cnt].port = port; - buf[cnt].socktype = SOCK_STREAM; - buf[cnt++].proto = IPPROTO_TCP; - } - } - __fclose_ca(f); - return cnt > 0 ? cnt : EAI_SERVICE; -} diff --git a/usr/lib/libc/network/netlink.c b/usr/lib/libc/network/netlink.c deleted file mode 100644 index 94dba7f5c..000000000 --- a/usr/lib/libc/network/netlink.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include -#include -#include "netlink.h" - -static int __netlink_enumerate(int fd, unsigned int seq, int type, int af, - int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx) -{ - struct nlmsghdr *h; - union { - uint8_t buf[8192]; - struct { - struct nlmsghdr nlh; - struct rtgenmsg g; - } req; - struct nlmsghdr reply; - } u; - int r, ret; - - memset(&u.req, 0, sizeof(u.req)); - u.req.nlh.nlmsg_len = sizeof(u.req); - u.req.nlh.nlmsg_type = type; - u.req.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; - u.req.nlh.nlmsg_seq = seq; - u.req.g.rtgen_family = af; - r = send(fd, &u.req, sizeof(u.req), 0); - if (r < 0) return r; - - while (1) { - r = recv(fd, u.buf, sizeof(u.buf), MSG_DONTWAIT); - if (r <= 0) return -1; - for (h = &u.reply; NLMSG_OK(h, (void*)&u.buf[r]); h = NLMSG_NEXT(h)) { - if (h->nlmsg_type == NLMSG_DONE) return 0; - if (h->nlmsg_type == NLMSG_ERROR) return -1; - ret = cb(ctx, h); - if (ret) return ret; - } - } -} - -int __rtnetlink_enumerate(int link_af, int addr_af, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx) -{ - int fd, r; - - fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE); - if (fd < 0) return -1; - r = __netlink_enumerate(fd, 1, RTM_GETLINK, link_af, cb, ctx); - if (!r) r = __netlink_enumerate(fd, 2, RTM_GETADDR, addr_af, cb, ctx); - __syscall(SYS_close,fd); - return r; -} diff --git a/usr/lib/libc/network/netlink.h b/usr/lib/libc/network/netlink.h deleted file mode 100644 index 20700ac5b..000000000 --- a/usr/lib/libc/network/netlink.h +++ /dev/null @@ -1,94 +0,0 @@ -#include - -/* linux/netlink.h */ - -#define NETLINK_ROUTE 0 - -struct nlmsghdr { - uint32_t nlmsg_len; - uint16_t nlmsg_type; - uint16_t nlmsg_flags; - uint32_t nlmsg_seq; - uint32_t nlmsg_pid; -}; - -#define NLM_F_REQUEST 1 -#define NLM_F_MULTI 2 -#define NLM_F_ACK 4 - -#define NLM_F_ROOT 0x100 -#define NLM_F_MATCH 0x200 -#define NLM_F_ATOMIC 0x400 -#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) - -#define NLMSG_NOOP 0x1 -#define NLMSG_ERROR 0x2 -#define NLMSG_DONE 0x3 -#define NLMSG_OVERRUN 0x4 - -/* linux/rtnetlink.h */ - -#define RTM_NEWLINK 16 -#define RTM_GETLINK 18 -#define RTM_NEWADDR 20 -#define RTM_GETADDR 22 - -struct rtattr { - unsigned short rta_len; - unsigned short rta_type; -}; - -struct rtgenmsg { - unsigned char rtgen_family; -}; - -struct ifinfomsg { - unsigned char ifi_family; - unsigned char __ifi_pad; - unsigned short ifi_type; - int ifi_index; - unsigned ifi_flags; - unsigned ifi_change; -}; - -/* linux/if_link.h */ - -#define IFLA_ADDRESS 1 -#define IFLA_BROADCAST 2 -#define IFLA_IFNAME 3 -#define IFLA_STATS 7 - -/* linux/if_addr.h */ - -struct ifaddrmsg { - uint8_t ifa_family; - uint8_t ifa_prefixlen; - uint8_t ifa_flags; - uint8_t ifa_scope; - uint32_t ifa_index; -}; - -#define IFA_ADDRESS 1 -#define IFA_LOCAL 2 -#define IFA_LABEL 3 -#define IFA_BROADCAST 4 - -/* musl */ - -#define NETLINK_ALIGN(len) (((len)+3) & ~3) -#define NLMSG_DATA(nlh) ((void*)((char*)(nlh)+sizeof(struct nlmsghdr))) -#define NLMSG_DATALEN(nlh) ((nlh)->nlmsg_len-sizeof(struct nlmsghdr)) -#define NLMSG_DATAEND(nlh) ((char*)(nlh)+(nlh)->nlmsg_len) -#define NLMSG_NEXT(nlh) (struct nlmsghdr*)((char*)(nlh)+NETLINK_ALIGN((nlh)->nlmsg_len)) -#define NLMSG_OK(nlh,end) ((char*)(end)-(char*)(nlh) >= sizeof(struct nlmsghdr)) - -#define RTA_DATA(rta) ((void*)((char*)(rta)+sizeof(struct rtattr))) -#define RTA_DATALEN(rta) ((rta)->rta_len-sizeof(struct rtattr)) -#define RTA_DATAEND(rta) ((char*)(rta)+(rta)->rta_len) -#define RTA_NEXT(rta) (struct rtattr*)((char*)(rta)+NETLINK_ALIGN((rta)->rta_len)) -#define RTA_OK(nlh,end) ((char*)(end)-(char*)(rta) >= sizeof(struct rtattr)) - -#define NLMSG_RTA(nlh,len) ((void*)((char*)(nlh)+sizeof(struct nlmsghdr)+NETLINK_ALIGN(len))) -#define NLMSG_RTAOK(rta,nlh) RTA_OK(rta,NLMSG_DATAEND(nlh)) - -int __rtnetlink_enumerate(int link_af, int addr_af, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx); diff --git a/usr/lib/libc/network/netname.c b/usr/lib/libc/network/netname.c deleted file mode 100644 index ba6e66568..000000000 --- a/usr/lib/libc/network/netname.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -struct netent *getnetbyaddr(uint32_t net, int type) -{ - return 0; -} - -struct netent *getnetbyname(const char *name) -{ - return 0; -} - diff --git a/usr/lib/libc/network/ns_parse.c b/usr/lib/libc/network/ns_parse.c deleted file mode 100644 index d01da47a3..000000000 --- a/usr/lib/libc/network/ns_parse.c +++ /dev/null @@ -1,171 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include -#include - -const struct _ns_flagdata _ns_flagdata[16] = { - { 0x8000, 15 }, - { 0x7800, 11 }, - { 0x0400, 10 }, - { 0x0200, 9 }, - { 0x0100, 8 }, - { 0x0080, 7 }, - { 0x0040, 6 }, - { 0x0020, 5 }, - { 0x0010, 4 }, - { 0x000f, 0 }, - { 0x0000, 0 }, - { 0x0000, 0 }, - { 0x0000, 0 }, - { 0x0000, 0 }, - { 0x0000, 0 }, - { 0x0000, 0 }, -}; - -unsigned ns_get16(const unsigned char *cp) -{ - return cp[0]<<8 | cp[1]; -} - -unsigned long ns_get32(const unsigned char *cp) -{ - return (unsigned)cp[0]<<24 | cp[1]<<16 | cp[2]<<8 | cp[3]; -} - -void ns_put16(unsigned s, unsigned char *cp) -{ - *cp++ = s>>8; - *cp++ = s; -} - -void ns_put32(unsigned long l, unsigned char *cp) -{ - *cp++ = l>>24; - *cp++ = l>>16; - *cp++ = l>>8; - *cp++ = l; -} - -int ns_initparse(const unsigned char *msg, int msglen, ns_msg *handle) -{ - int i, r; - - handle->_msg = msg; - handle->_eom = msg + msglen; - if (msglen < (2 + ns_s_max) * NS_INT16SZ) goto bad; - NS_GET16(handle->_id, msg); - NS_GET16(handle->_flags, msg); - for (i = 0; i < ns_s_max; i++) NS_GET16(handle->_counts[i], msg); - for (i = 0; i < ns_s_max; i++) { - if (handle->_counts[i]) { - handle->_sections[i] = msg; - r = ns_skiprr(msg, handle->_eom, i, handle->_counts[i]); - if (r < 0) return -1; - msg += r; - } else { - handle->_sections[i] = NULL; - } - } - if (msg != handle->_eom) goto bad; - handle->_sect = ns_s_max; - handle->_rrnum = -1; - handle->_msg_ptr = NULL; - return 0; -bad: - errno = EMSGSIZE; - return -1; -} - -int ns_skiprr(const unsigned char *ptr, const unsigned char *eom, ns_sect section, int count) -{ - const unsigned char *p = ptr; - int r; - - while (count--) { - r = dn_skipname(p, eom); - if (r < 0) goto bad; - if (r + 2 * NS_INT16SZ > eom - p) goto bad; - p += r + 2 * NS_INT16SZ; - if (section != ns_s_qd) { - if (NS_INT32SZ + NS_INT16SZ > eom - p) goto bad; - p += NS_INT32SZ; - NS_GET16(r, p); - if (r > eom - p) goto bad; - p += r; - } - } - return p - ptr; -bad: - errno = EMSGSIZE; - return -1; -} - -int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) -{ - int r; - - if (section < 0 || section >= ns_s_max) goto bad; - if (section != handle->_sect) { - handle->_sect = section; - handle->_rrnum = 0; - handle->_msg_ptr = handle->_sections[section]; - } - if (rrnum == -1) rrnum = handle->_rrnum; - if (rrnum < 0 || rrnum >= handle->_counts[section]) goto bad; - if (rrnum < handle->_rrnum) { - handle->_rrnum = 0; - handle->_msg_ptr = handle->_sections[section]; - } - if (rrnum > handle->_rrnum) { - r = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum); - if (r < 0) return -1; - handle->_msg_ptr += r; - handle->_rrnum = rrnum; - } - r = ns_name_uncompress(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME); - if (r < 0) return -1; - handle->_msg_ptr += r; - if (2 * NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size; - NS_GET16(rr->type, handle->_msg_ptr); - NS_GET16(rr->rr_class, handle->_msg_ptr); - if (section != ns_s_qd) { - if (NS_INT32SZ + NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size; - NS_GET32(rr->ttl, handle->_msg_ptr); - NS_GET16(rr->rdlength, handle->_msg_ptr); - if (rr->rdlength > handle->_eom - handle->_msg_ptr) goto size; - rr->rdata = handle->_msg_ptr; - handle->_msg_ptr += rr->rdlength; - } else { - rr->ttl = 0; - rr->rdlength = 0; - rr->rdata = NULL; - } - handle->_rrnum++; - if (handle->_rrnum > handle->_counts[section]) { - handle->_sect = section + 1; - if (handle->_sect == ns_s_max) { - handle->_rrnum = -1; - handle->_msg_ptr = NULL; - } else { - handle->_rrnum = 0; - } - } - return 0; -bad: - errno = ENODEV; - return -1; -size: - errno = EMSGSIZE; - return -1; -} - -int ns_name_uncompress(const unsigned char *msg, const unsigned char *eom, - const unsigned char *src, char *dst, size_t dstsiz) -{ - int r; - r = dn_expand(msg, eom, src, dst, dstsiz); - if (r < 0) errno = EMSGSIZE; - return r; -} - diff --git a/usr/lib/libc/network/ntohl.c b/usr/lib/libc/network/ntohl.c deleted file mode 100644 index d6fce4590..000000000 --- a/usr/lib/libc/network/ntohl.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -uint32_t ntohl(uint32_t n) -{ - union { int i; char c; } u = { 1 }; - return u.c ? bswap_32(n) : n; -} diff --git a/usr/lib/libc/network/ntohs.c b/usr/lib/libc/network/ntohs.c deleted file mode 100644 index 745cef425..000000000 --- a/usr/lib/libc/network/ntohs.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -uint16_t ntohs(uint16_t n) -{ - union { int i; char c; } u = { 1 }; - return u.c ? bswap_16(n) : n; -} diff --git a/usr/lib/libc/network/proto.c b/usr/lib/libc/network/proto.c deleted file mode 100644 index c4fd34efb..000000000 --- a/usr/lib/libc/network/proto.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include - -/* do we really need all these?? */ - -static int idx; -static const unsigned char protos[] = { - "\000ip\0" - "\001icmp\0" - "\002igmp\0" - "\003ggp\0" - "\004ipencap\0" - "\005st\0" - "\006tcp\0" - "\010egp\0" - "\014pup\0" - "\021udp\0" - "\024hmp\0" - "\026xns-idp\0" - "\033rdp\0" - "\035iso-tp4\0" - "\044xtp\0" - "\045ddp\0" - "\046idpr-cmtp\0" - "\051ipv6\0" - "\053ipv6-route\0" - "\054ipv6-frag\0" - "\055idrp\0" - "\056rsvp\0" - "\057gre\0" - "\062esp\0" - "\063ah\0" - "\071skip\0" - "\072ipv6-icmp\0" - "\073ipv6-nonxt\0" - "\074ipv6-opts\0" - "\111rspf\0" - "\121vmtp\0" - "\131ospf\0" - "\136ipip\0" - "\142encap\0" - "\147pim\0" - "\377raw" -}; - -void endprotoent(void) -{ - idx = 0; -} - -void setprotoent(int stayopen) -{ - idx = 0; -} - -struct protoent *getprotoent(void) -{ - static struct protoent p; - static const char *aliases; - if (idx >= sizeof protos) return NULL; - p.p_proto = protos[idx]; - p.p_name = (char *)&protos[idx+1]; - p.p_aliases = (char **)&aliases; - idx += strlen(p.p_name) + 2; - return &p; -} - -struct protoent *getprotobyname(const char *name) -{ - struct protoent *p; - endprotoent(); - do p = getprotoent(); - while (p && strcmp(name, p->p_name)); - return p; -} - -struct protoent *getprotobynumber(int num) -{ - struct protoent *p; - endprotoent(); - do p = getprotoent(); - while (p && p->p_proto != num); - return p; -} diff --git a/usr/lib/libc/network/recv.c b/usr/lib/libc/network/recv.c deleted file mode 100644 index 59700485b..000000000 --- a/usr/lib/libc/network/recv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -ssize_t recv(int fd, void *buf, size_t len, int flags) -{ - return recvfrom(fd, buf, len, flags, 0, 0); -} diff --git a/usr/lib/libc/network/recvfrom.c b/usr/lib/libc/network/recvfrom.c deleted file mode 100644 index 2d990ed84..000000000 --- a/usr/lib/libc/network/recvfrom.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen) -{ - return __syscall_ret(sys_recvfrom(fd, buf, len, flags, addr, alen)); -} diff --git a/usr/lib/libc/network/recvmmsg.c b/usr/lib/libc/network/recvmmsg.c deleted file mode 100644 index 58b1b2f63..000000000 --- a/usr/lib/libc/network/recvmmsg.c +++ /dev/null @@ -1,15 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include "syscall.h" - -int recvmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags, struct timespec *timeout) -{ -#if LONG_MAX > INT_MAX - struct mmsghdr *mh = msgvec; - unsigned int i; - for (i = vlen; i; i--, mh++) - mh->msg_hdr.__pad1 = mh->msg_hdr.__pad2 = 0; -#endif - return syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, timeout); -} diff --git a/usr/lib/libc/network/recvmsg.c b/usr/lib/libc/network/recvmsg.c deleted file mode 100644 index 4f5266591..000000000 --- a/usr/lib/libc/network/recvmsg.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -ssize_t recvmsg(int fd, struct msghdr *msg, int flags) -{ - ssize_t r; -#if LONG_MAX > INT_MAX - struct msghdr h, *orig = msg; - if (msg) { - h = *msg; - h.__pad1 = h.__pad2 = 0; - msg = &h; - } -#endif - r = socketcall_cp(recvmsg, fd, msg, flags, 0, 0, 0); -#if LONG_MAX > INT_MAX - if (orig) *orig = h; -#endif - return r; -} diff --git a/usr/lib/libc/network/res_init.c b/usr/lib/libc/network/res_init.c deleted file mode 100644 index 5dba9dfc3..000000000 --- a/usr/lib/libc/network/res_init.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int res_init() -{ - return 0; -} diff --git a/usr/lib/libc/network/res_mkquery.c b/usr/lib/libc/network/res_mkquery.c deleted file mode 100644 index ec4568acb..000000000 --- a/usr/lib/libc/network/res_mkquery.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include "libc.h" - -int __res_mkquery(int op, const char *dname, int class, int type, - const unsigned char *data, int datalen, - const unsigned char *newrr, unsigned char *buf, int buflen) -{ - int id, i, j; - unsigned char q[280]; - struct timespec ts; - size_t l = strnlen(dname, 255); - int n; - - if (l && dname[l-1]=='.') l--; - n = 17+l+!!l; - if (l>253 || buflen15u || class>255u || type>255u) - return -1; - - /* Construct query template - ID will be filled later */ - memset(q, 0, n); - q[2] = op*8 + 1; - q[5] = 1; - memcpy((char *)q+13, dname, l); - for (i=13; q[i]; i=j+1) { - for (j=i; q[j] && q[j] != '.'; j++); - if (j-i-1u > 62u) return -1; - q[i-1] = j-i; - } - q[i+1] = type; - q[i+3] = class; - - /* Make a reasonably unpredictable id */ - clock_gettime(CLOCK_REALTIME, &ts); - id = ts.tv_nsec + ts.tv_nsec/65536UL & 0xffff; - q[0] = id/256; - q[1] = id; - - memcpy(buf, q, n); - return n; -} - -weak_alias(__res_mkquery, res_mkquery); diff --git a/usr/lib/libc/network/res_msend.c b/usr/lib/libc/network/res_msend.c deleted file mode 100644 index 3e018009e..000000000 --- a/usr/lib/libc/network/res_msend.c +++ /dev/null @@ -1,188 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "stdio_impl.h" -#include "syscall.h" -#include "lookup.h" - -static void cleanup(void *p) -{ - __syscall(SYS_close, (intptr_t)p); -} - -static unsigned long mtime() -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - return (unsigned long)ts.tv_sec * 1000 - + ts.tv_nsec / 1000000; -} - -int __res_msend_rc(int nqueries, const unsigned char *const *queries, - const int *qlens, unsigned char *const *answers, int *alens, int asize, - const struct resolvconf *conf) -{ - int fd; - int timeout, attempts, retry_interval, servfail_retry; - union { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } sa = {0}, ns[MAXNS] = {{0}}; - socklen_t sl = sizeof sa.sin; - int nns = 0; - int family = AF_INET; - int rlen; - int next; - int i, j; - int cs; - struct pollfd pfd; - unsigned long t0, t1, t2; - - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - - timeout = 1000*conf->timeout; - attempts = conf->attempts; - - for (nns=0; nnsnns; nns++) { - const struct address *iplit = &conf->ns[nns]; - if (iplit->family == AF_INET) { - memcpy(&ns[nns].sin.sin_addr, iplit->addr, 4); - ns[nns].sin.sin_port = htons(53); - ns[nns].sin.sin_family = AF_INET; - } else { - sl = sizeof sa.sin6; - memcpy(&ns[nns].sin6.sin6_addr, iplit->addr, 16); - ns[nns].sin6.sin6_port = htons(53); - ns[nns].sin6.sin6_scope_id = iplit->scopeid; - ns[nns].sin6.sin6_family = family = AF_INET6; - } - } - - /* Get local address and open/bind a socket */ - sa.sin.sin_family = family; - fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); - - /* Handle case where system lacks IPv6 support */ - if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) { - fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); - family = AF_INET; - } - if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) { - if (fd >= 0) close(fd); - pthread_setcancelstate(cs, 0); - return -1; - } - - /* Past this point, there are no errors. Each individual query will - * yield either no reply (indicated by zero length) or an answer - * packet which is up to the caller to interpret. */ - - pthread_cleanup_push(cleanup, (void *)(intptr_t)fd); - pthread_setcancelstate(cs, 0); - - /* Convert any IPv4 addresses in a mixed environment to v4-mapped */ - if (family == AF_INET6) { - setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0); - for (i=0; i= retry_interval) { - /* Query all configured namservers in parallel */ - for (i=0; i= 0) { - - /* Ignore non-identifiable packets */ - if (rlen < 4) continue; - - /* Ignore replies from addresses we didn't send to */ - for (j=0; j -#include -#include "libc.h" - -int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int); -int __res_send(const unsigned char *, int, unsigned char *, int); - -int __res_query(const char *name, int class, int type, unsigned char *dest, int len) -{ - unsigned char q[280]; - int ql = __res_mkquery(0, name, class, type, 0, 0, 0, q, sizeof q); - if (ql < 0) return ql; - return __res_send(q, ql, dest, len); -} - -weak_alias(__res_query, res_query); -weak_alias(__res_query, res_search); diff --git a/usr/lib/libc/network/res_querydomain.c b/usr/lib/libc/network/res_querydomain.c deleted file mode 100644 index 727e6f6ba..000000000 --- a/usr/lib/libc/network/res_querydomain.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int res_querydomain(const char *name, const char *domain, int class, int type, unsigned char *dest, int len) -{ - char tmp[255]; - size_t nl = strnlen(name, 255); - size_t dl = strnlen(domain, 255); - if (nl+dl+1 > 254) return -1; - memcpy(tmp, name, nl); - tmp[nl] = '.'; - memcpy(tmp+nl+1, domain, dl+1); - return res_query(tmp, class, type, dest, len); -} diff --git a/usr/lib/libc/network/res_send.c b/usr/lib/libc/network/res_send.c deleted file mode 100644 index 19cfe0f6b..000000000 --- a/usr/lib/libc/network/res_send.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "libc.h" - -int __res_msend(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int); - -int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen) -{ - int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen); - return r<0 ? r : anslen; -} - -weak_alias(__res_send, res_send); diff --git a/usr/lib/libc/network/res_state.c b/usr/lib/libc/network/res_state.c deleted file mode 100644 index 5c42cda5c..000000000 --- a/usr/lib/libc/network/res_state.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -/* This is completely unused, and exists purely to satisfy broken apps. */ - -struct __res_state *__res_state() -{ - static struct __res_state res; - return &res; -} diff --git a/usr/lib/libc/network/resolvconf.c b/usr/lib/libc/network/resolvconf.c deleted file mode 100644 index 4c3e4c4b1..000000000 --- a/usr/lib/libc/network/resolvconf.c +++ /dev/null @@ -1,93 +0,0 @@ -#include "lookup.h" -#include "stdio_impl.h" -#include -#include -#include -#include - -int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz) -{ - char line[256]; - unsigned char _buf[256]; - FILE *f, _f; - int nns = 0; - - conf->ndots = 1; - conf->timeout = 5; - conf->attempts = 2; - if (search) *search = 0; - - f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf); - if (!f) switch (errno) { - case ENOENT: - case ENOTDIR: - case EACCES: - goto no_resolv_conf; - default: - return -1; - } - - while (fgets(line, sizeof line, f)) { - char *p, *z; - if (!strchr(line, '\n') && !feof(f)) { - /* Ignore lines that get truncated rather than - * potentially misinterpreting them. */ - int c; - do c = getc(f); - while (c != '\n' && c != EOF); - continue; - } - if (!strncmp(line, "options", 7) && isspace(line[7])) { - p = strstr(line, "ndots:"); - if (p && isdigit(p[6])) { - p += 6; - unsigned long x = strtoul(p, &z, 10); - if (z != p) conf->ndots = x > 15 ? 15 : x; - } - p = strstr(line, "attempts:"); - if (p && isdigit(p[9])) { - p += 9; - unsigned long x = strtoul(p, &z, 10); - if (z != p) conf->attempts = x > 10 ? 10 : x; - } - p = strstr(line, "timeout:"); - if (p && (isdigit(p[8]) || p[8]=='.')) { - p += 8; - unsigned long x = strtoul(p, &z, 10); - if (z != p) conf->timeout = x > 60 ? 60 : x; - } - continue; - } - if (!strncmp(line, "nameserver", 10) && isspace(line[10])) { - if (nns >= MAXNS) continue; - for (p=line+11; isspace(*p); p++); - for (z=p; *z && !isspace(*z); z++); - *z=0; - if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0) - nns++; - continue; - } - - if (!search) continue; - if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6)) - || !isspace(line[6])) - continue; - for (p=line+7; isspace(*p); p++); - size_t l = strlen(p); - /* This can never happen anyway with chosen buffer sizes. */ - if (l >= search_sz) continue; - memcpy(search, p, l+1); - } - - __fclose_ca(f); - -no_resolv_conf: - if (!nns) { - __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC); - nns = 1; - } - - conf->nns = nns; - - return 0; -} diff --git a/usr/lib/libc/network/send.c b/usr/lib/libc/network/send.c deleted file mode 100644 index 9f1049773..000000000 --- a/usr/lib/libc/network/send.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -ssize_t send(int fd, const void *buf, size_t len, int flags) -{ - return sendto(fd, buf, len, flags, 0, 0); -} diff --git a/usr/lib/libc/network/sendmmsg.c b/usr/lib/libc/network/sendmmsg.c deleted file mode 100644 index eeae1d0a5..000000000 --- a/usr/lib/libc/network/sendmmsg.c +++ /dev/null @@ -1,30 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include "syscall.h" - -int sendmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags) -{ -#if LONG_MAX > INT_MAX - /* Can't use the syscall directly because the kernel has the wrong - * idea for the types of msg_iovlen, msg_controllen, and cmsg_len, - * and the cmsg blocks cannot be modified in-place. */ - int i; - if (vlen > IOV_MAX) vlen = IOV_MAX; /* This matches the kernel. */ - if (!vlen) return 0; - for (i=0; i -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) -{ -#if LONG_MAX > INT_MAX - struct msghdr h; - struct cmsghdr chbuf[1024/sizeof(struct cmsghdr)+1], *c; - if (msg) { - h = *msg; - h.__pad1 = h.__pad2 = 0; - msg = &h; - if (h.msg_controllen) { - if (h.msg_controllen > 1024) { - errno = ENOMEM; - return -1; - } - memcpy(chbuf, h.msg_control, h.msg_controllen); - h.msg_control = chbuf; - for (c=CMSG_FIRSTHDR(&h); c; c=CMSG_NXTHDR(&h,c)) - c->__pad1 = 0; - } - } -#endif - return socketcall_cp(sendmsg, fd, msg, flags, 0, 0, 0); -} diff --git a/usr/lib/libc/network/sendto.c b/usr/lib/libc/network/sendto.c deleted file mode 100644 index 2f51114f8..000000000 --- a/usr/lib/libc/network/sendto.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include - -ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen) -{ - return __syscall_ret(sys_sendto(fd, buf, len, flags, addr, alen)); - -#if 0 - return socketcall_cp(sendto, fd, buf, len, flags, addr, alen); -#endif -} diff --git a/usr/lib/libc/network/serv.c b/usr/lib/libc/network/serv.c deleted file mode 100644 index 41424e806..000000000 --- a/usr/lib/libc/network/serv.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -void endservent(void) -{ -} - -void setservent(int stayopen) -{ -} - -struct servent *getservent(void) -{ - return 0; -} diff --git a/usr/lib/libc/network/setsockopt.c b/usr/lib/libc/network/setsockopt.c deleted file mode 100644 index f6681bb11..000000000 --- a/usr/lib/libc/network/setsockopt.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) -{ - return __syscall_ret(sys_setsockopt(fd, level, optname, optval, optlen)); -} diff --git a/usr/lib/libc/network/shutdown.c b/usr/lib/libc/network/shutdown.c deleted file mode 100644 index 10ca21aa3..000000000 --- a/usr/lib/libc/network/shutdown.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int shutdown(int fd, int how) -{ - return socketcall(shutdown, fd, how, 0, 0, 0, 0); -} diff --git a/usr/lib/libc/network/sockatmark.c b/usr/lib/libc/network/sockatmark.c deleted file mode 100644 index f474551aa..000000000 --- a/usr/lib/libc/network/sockatmark.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int sockatmark(int s) -{ - int ret; - if (ioctl(s, SIOCATMARK, &ret) < 0) - return -1; - return ret; -} diff --git a/usr/lib/libc/network/socket.c b/usr/lib/libc/network/socket.c deleted file mode 100644 index 3e99e2317..000000000 --- a/usr/lib/libc/network/socket.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -int socket(int domain, int type, int protocol) -{ - /*TODO int s = socketcall(socket, domain, type, protocol, 0, 0, 0); - if (s<0 && (errno==EINVAL || errno==EPROTONOSUPPORT) - && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { - s = socketcall(socket, domain, - type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), - protocol, 0, 0, 0); - if (s < 0) return s; - if (type & SOCK_CLOEXEC) - sys_socket(SYS_fcntl, s, F_SETFD, FD_CLOEXEC); - if (type & SOCK_NONBLOCK) - sys_socket(SYS_fcntl, s, F_SETFL, O_NONBLOCK); - }*/ - int s = sys_socket(domain, type, protocol); - return __syscall_ret(s); -} diff --git a/usr/lib/libc/network/socketpair.c b/usr/lib/libc/network/socketpair.c deleted file mode 100644 index f34896211..000000000 --- a/usr/lib/libc/network/socketpair.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -int socketpair(int domain, int type, int protocol, int fd[2]) -{ - int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0); - if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT) - && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { - r = socketcall(socketpair, domain, - type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), - protocol, fd, 0, 0); - if (r < 0) return r; - if (type & SOCK_CLOEXEC) { - __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); - __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); - } - if (type & SOCK_NONBLOCK) { - __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); - __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); - } - } - return r; -} diff --git a/usr/lib/libc/prng/CMakeLists.txt b/usr/lib/libc/prng/CMakeLists.txt deleted file mode 100644 index 2d9912218..000000000 --- a/usr/lib/libc/prng/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -target_sources(c - PRIVATE - random.c - rand.c -) diff --git a/usr/lib/libc/prng/__rand48_step.c b/usr/lib/libc/prng/__rand48_step.c deleted file mode 100644 index 961d30fc9..000000000 --- a/usr/lib/libc/prng/__rand48_step.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc) -{ - uint64_t a, x; - x = xi[0] | xi[1]+0U<<16 | xi[2]+0ULL<<32; - a = lc[0] | lc[1]+0U<<16 | lc[2]+0ULL<<32; - x = a*x + lc[3]; - xi[0] = x; - xi[1] = x>>16; - xi[2] = x>>32; - return x & 0xffffffffffffull; -} diff --git a/usr/lib/libc/prng/__seed48.c b/usr/lib/libc/prng/__seed48.c deleted file mode 100644 index 05a4539e4..000000000 --- a/usr/lib/libc/prng/__seed48.c +++ /dev/null @@ -1 +0,0 @@ -unsigned short __seed48[7] = { 0, 0, 0, 0xe66d, 0xdeec, 0x5, 0xb }; diff --git a/usr/lib/libc/prng/drand48.c b/usr/lib/libc/prng/drand48.c deleted file mode 100644 index d808353c9..000000000 --- a/usr/lib/libc/prng/drand48.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc); -extern unsigned short __seed48[7]; - -double erand48(unsigned short s[3]) -{ - union { - uint64_t u; - double f; - } x = { 0x3ff0000000000000ULL | __rand48_step(s, __seed48+3)<<4 }; - return x.f - 1.0; -} - -double drand48(void) -{ - return erand48(__seed48); -} diff --git a/usr/lib/libc/prng/lcong48.c b/usr/lib/libc/prng/lcong48.c deleted file mode 100644 index 32b27d423..000000000 --- a/usr/lib/libc/prng/lcong48.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -extern unsigned short __seed48[7]; - -void lcong48(unsigned short p[7]) -{ - memcpy(__seed48, p, sizeof __seed48); -} diff --git a/usr/lib/libc/prng/lrand48.c b/usr/lib/libc/prng/lrand48.c deleted file mode 100644 index a3c4e4e2b..000000000 --- a/usr/lib/libc/prng/lrand48.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc); -extern unsigned short __seed48[7]; - -long nrand48(unsigned short s[3]) -{ - return __rand48_step(s, __seed48+3) >> 17; -} - -long lrand48(void) -{ - return nrand48(__seed48); -} diff --git a/usr/lib/libc/prng/mrand48.c b/usr/lib/libc/prng/mrand48.c deleted file mode 100644 index 0519d6676..000000000 --- a/usr/lib/libc/prng/mrand48.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -uint64_t __rand48_step(unsigned short *xi, unsigned short *lc); -extern unsigned short __seed48[7]; - -long jrand48(unsigned short s[3]) -{ - return (int32_t)(__rand48_step(s, __seed48+3) >> 16); -} - -long mrand48(void) -{ - return jrand48(__seed48); -} diff --git a/usr/lib/libc/prng/rand.c b/usr/lib/libc/prng/rand.c deleted file mode 100644 index c000cd248..000000000 --- a/usr/lib/libc/prng/rand.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -static uint64_t seed; - -void srand(unsigned s) -{ - seed = s-1; -} - -int rand(void) -{ - seed = 6364136223846793005ULL*seed + 1; - return seed>>33; -} diff --git a/usr/lib/libc/prng/rand_r.c b/usr/lib/libc/prng/rand_r.c deleted file mode 100644 index 638614c86..000000000 --- a/usr/lib/libc/prng/rand_r.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -static unsigned temper(unsigned x) -{ - x ^= x>>11; - x ^= x<<7 & 0x9D2C5680; - x ^= x<<15 & 0xEFC60000; - x ^= x>>18; - return x; -} - -int rand_r(unsigned *seed) -{ - return temper(*seed = *seed * 1103515245 + 12345)/2; -} diff --git a/usr/lib/libc/prng/random.c b/usr/lib/libc/prng/random.c deleted file mode 100644 index 811c98771..000000000 --- a/usr/lib/libc/prng/random.c +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include -#include - -/* -this code uses the same lagged fibonacci generator as the -original bsd random implementation except for the seeding -which was broken in the original -*/ - -static uint32_t init[] = { -0x00000000,0x5851f42d,0xc0b18ccf,0xcbb5f646, -0xc7033129,0x30705b04,0x20fd5db4,0x9a8b7f78, -0x502959d8,0xab894868,0x6c0356a7,0x88cdb7ff, -0xb477d43f,0x70a3a52b,0xa8e4baf1,0xfd8341fc, -0x8ae16fd9,0x742d2f7a,0x0d1f0796,0x76035e09, -0x40f7702c,0x6fa72ca5,0xaaa84157,0x58a0df74, -0xc74a0364,0xae533cc4,0x04185faf,0x6de3b115, -0x0cab8628,0xf043bfa4,0x398150e9,0x37521657}; - -static int n = 31; -static int i = 3; -static int j = 0; -static uint32_t *x = init+1; -static volatile int lock[2]; - -static uint32_t lcg31(uint32_t x) { - return (1103515245*x + 12345) & 0x7fffffff; -} - -static uint64_t lcg64(uint64_t x) { - return 6364136223846793005ull*x + 1; -} - -static void *savestate() { - x[-1] = (n<<16)|(i<<8)|j; - return x-1; -} - -static void loadstate(uint32_t *state) { - x = state+1; - n = x[-1]>>16; - i = (x[-1]>>8)&0xff; - j = x[-1]&0xff; -} - -static void __srandom(unsigned seed) { - int k; - uint64_t s = seed; - - if (n == 0) { - x[0] = s; - return; - } - i = n == 31 || n == 7 ? 3 : 1; - j = 0; - for (k = 0; k < n; k++) { - s = lcg64(s); - x[k] = s>>32; - } - /* make sure x contains at least one odd number */ - x[0] |= 1; -} - -void srandom(unsigned seed) { - LOCK(lock); - __srandom(seed); - UNLOCK(lock); -} - -char *initstate(unsigned seed, char *state, size_t size) { - void *old; - - if (size < 8) - return 0; - LOCK(lock); - old = savestate(); - if (size < 32) - n = 0; - else if (size < 64) - n = 7; - else if (size < 128) - n = 15; - else if (size < 256) - n = 31; - else - n = 63; - x = (uint32_t*)state + 1; - __srandom(seed); - savestate(); - UNLOCK(lock); - return old; -} - -char *setstate(char *state) { - void *old; - - LOCK(lock); - old = savestate(); - loadstate((uint32_t*)state); - UNLOCK(lock); - return old; -} - -long random(void) { - long k; - - LOCK(lock); - if (n == 0) { - k = x[0] = lcg31(x[0]); - goto end; - } - x[i] += x[j]; - k = x[i]>>1; - if (++i == n) - i = 0; - if (++j == n) - j = 0; -end: - UNLOCK(lock); - return k; -} diff --git a/usr/lib/libc/prng/seed48.c b/usr/lib/libc/prng/seed48.c deleted file mode 100644 index e0699c092..000000000 --- a/usr/lib/libc/prng/seed48.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -extern unsigned short __seed48[7]; - -unsigned short *seed48(unsigned short *s) -{ - static unsigned short p[3]; - memcpy(p, __seed48, sizeof p); - memcpy(__seed48, s, sizeof p); - return p; -} diff --git a/usr/lib/libc/prng/srand48.c b/usr/lib/libc/prng/srand48.c deleted file mode 100644 index 0a56f6a07..000000000 --- a/usr/lib/libc/prng/srand48.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void srand48(long seed) -{ - seed48((unsigned short [3]){ 0x330e, seed, seed>>16 }); -} diff --git a/usr/lib/libc/process/CMakeLists.txt b/usr/lib/libc/process/CMakeLists.txt deleted file mode 100644 index ce8b61245..000000000 --- a/usr/lib/libc/process/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ - -target_sources(c - PRIVATE - execl.c - execle.c - execve.c - execv.c - execvp.c - execlp.c - ptrace.c - fork.c - waitpid.c -) diff --git a/usr/lib/libc/process/execl.c b/usr/lib/libc/process/execl.c deleted file mode 100644 index 5ee5c81e3..000000000 --- a/usr/lib/libc/process/execl.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -int execl(const char *path, const char *argv0, ...) -{ - int argc; - va_list ap; - va_start(ap, argv0); - for (argc=1; va_arg(ap, const char *); argc++); - va_end(ap); - { - int i; - char *argv[argc+1]; - va_start(ap, argv0); - argv[0] = (char *)argv0; - for (i=1; i -#include - -int execle(const char *path, const char *argv0, ...) -{ - int argc; - va_list ap; - va_start(ap, argv0); - for (argc=1; va_arg(ap, const char *); argc++); - va_end(ap); - { - int i; - char *argv[argc+1]; - char **envp; - va_start(ap, argv0); - argv[0] = (char *)argv0; - for (i=1; i<=argc; i++) - argv[i] = va_arg(ap, char *); - envp = va_arg(ap, char **); - va_end(ap); - return execve(path, argv, envp); - } -} diff --git a/usr/lib/libc/process/execlp.c b/usr/lib/libc/process/execlp.c deleted file mode 100644 index 5eed886e7..000000000 --- a/usr/lib/libc/process/execlp.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -int execlp(const char *file, const char *argv0, ...) -{ - int argc; - va_list ap; - va_start(ap, argv0); - for (argc=1; va_arg(ap, const char *); argc++); - va_end(ap); - { - int i; - char *argv[argc+1]; - va_start(ap, argv0); - argv[0] = (char *)argv0; - for (i=1; i - -extern char **__environ; - -int execv(const char *path, char *const argv[]) -{ - return execve(path, argv, __environ); -} diff --git a/usr/lib/libc/process/execve.c b/usr/lib/libc/process/execve.c deleted file mode 100644 index afa75feee..000000000 --- a/usr/lib/libc/process/execve.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int execve(const char *path, char *const argv[], char *const envp[]) -{ - /* do we need to use environ if envp is null? */ -#if 0 - return syscall(SYS_execve, path, argv, envp); -#endif - return __syscall_ret(sys_execve(path, argv, envp)); -} diff --git a/usr/lib/libc/process/execvp.c b/usr/lib/libc/process/execvp.c deleted file mode 100644 index 3a8bbe832..000000000 --- a/usr/lib/libc/process/execvp.c +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include -#include -#include -#include "libc.h" - -extern char **__environ; - -int __execvpe(const char *file, char *const argv[], char *const envp[]) -{ - const char *p, *z, *path = getenv("PATH"); - size_t l, k; - int seen_eacces = 0; - - errno = ENOENT; - if (!*file) return -1; - - if (strchr(file, '/')) - return execve(file, argv, envp); - - if (!path) path = "/usr/local/bin:/bin:/usr/bin"; - k = strnlen(file, NAME_MAX+1); - if (k > NAME_MAX) { - errno = ENAMETOOLONG; - return -1; - } - l = strnlen(path, PATH_MAX-1)+1; - - for(p=path; ; p=z) { - char b[l+k+1]; - z = strchr(p, ':'); - if (!z) z = p+strlen(p); - if (z-p >= l) { - if (!*z++) break; - continue; - } - memcpy(b, p, z-p); - b[z-p] = '/'; - memcpy(b+(z-p)+(z>p), file, k+1); - execve(b, argv, envp); - if (errno == EACCES) seen_eacces = 1; - else if (errno != ENOENT) return -1; - if (!*z++) break; - } - if (seen_eacces) errno = EACCES; - return -1; -} - -int execvp(const char *file, char *const argv[]) -{ - return __execvpe(file, argv, __environ); -} - -weak_alias(__execvpe, execvpe); diff --git a/usr/lib/libc/process/fexecve.c b/usr/lib/libc/process/fexecve.c deleted file mode 100644 index 6507b4294..000000000 --- a/usr/lib/libc/process/fexecve.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -void __procfdname(char *, unsigned); - -int fexecve(int fd, char *const argv[], char *const envp[]) -{ - char buf[15 + 3*sizeof(int)]; - __procfdname(buf, fd); - execve(buf, argv, envp); - if (errno == ENOENT) errno = EBADF; - return -1; -} diff --git a/usr/lib/libc/process/fork.c b/usr/lib/libc/process/fork.c deleted file mode 100644 index 7b3b57a82..000000000 --- a/usr/lib/libc/process/fork.c +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include "syscall.h" -#include "libc.h" -#include "pthread_impl.h" - -static void dummy(int x) -{ -} - -weak_alias(dummy, __fork_handler); - -pid_t fork(void) -{ - pid_t ret; -#if 0 /* Not used at the moment in so3 */ - sigset_t set; - - __fork_handler(-1); - __block_all_sigs(&set); -#endif /* 0 */ - - ret = __syscall_ret(sys_fork()); -#if 0 -#ifdef SYS_fork - ret = syscall(SYS_fork); -#else - ret = syscall(SYS_clone, SIGCHLD, 0); -#endif -#endif -#if 0 - if (!ret) { - pthread_t self = __pthread_self(); - self->tid = __syscall(SYS_gettid); - self->robust_list.off = 0; - self->robust_list.pending = 0; - libc.threads_minus_1 = 0; - } - __restore_sigs(&set); - __fork_handler(!ret); -#endif - return ret; -} diff --git a/usr/lib/libc/process/posix_spawn.c b/usr/lib/libc/process/posix_spawn.c deleted file mode 100644 index ea5d29982..000000000 --- a/usr/lib/libc/process/posix_spawn.c +++ /dev/null @@ -1,199 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include "syscall.h" -#include "pthread_impl.h" -#include "fdop.h" -#include "libc.h" - -struct args { - int p[2]; - sigset_t oldmask; - const char *path; - int (*exec)(const char *, char *const *, char *const *); - const posix_spawn_file_actions_t *fa; - const posix_spawnattr_t *restrict attr; - char *const *argv, *const *envp; -}; - -void __get_handler_set(sigset_t *); - -static int __sys_dup2(int old, int new) -{ -#ifdef SYS_dup2 - return __syscall(SYS_dup2, old, new); -#else - if (old==new) { - int r = __syscall(SYS_fcntl, old, F_GETFD); - return r<0 ? r : old; - } else { - return __syscall(SYS_dup3, old, new, 0); - } -#endif -} - -static int child(void *args_vp) -{ - int i, ret; - struct sigaction sa = {0}; - struct args *args = args_vp; - int p = args->p[1]; - const posix_spawn_file_actions_t *fa = args->fa; - const posix_spawnattr_t *restrict attr = args->attr; - sigset_t hset; - - close(args->p[0]); - - /* All signal dispositions must be either SIG_DFL or SIG_IGN - * before signals are unblocked. Otherwise a signal handler - * from the parent might get run in the child while sharing - * memory, with unpredictable and dangerous results. To - * reduce overhead, sigaction has tracked for us which signals - * potentially have a signal handler. */ - __get_handler_set(&hset); - for (i=1; i<_NSIG; i++) { - if ((attr->__flags & POSIX_SPAWN_SETSIGDEF) - && sigismember(&attr->__def, i)) { - sa.sa_handler = SIG_DFL; - } else if (sigismember(&hset, i)) { - if (i-32<3U) { - sa.sa_handler = SIG_IGN; - } else { - __libc_sigaction(i, 0, &sa); - if (sa.sa_handler==SIG_IGN) continue; - sa.sa_handler = SIG_DFL; - } - } else { - continue; - } - __libc_sigaction(i, &sa, 0); - } - - if (attr->__flags & POSIX_SPAWN_SETSID) - if ((ret=__syscall(SYS_setsid)) < 0) - goto fail; - - if (attr->__flags & POSIX_SPAWN_SETPGROUP) - if ((ret=__syscall(SYS_setpgid, 0, attr->__pgrp))) - goto fail; - - /* Use syscalls directly because the library functions attempt - * to do a multi-threaded synchronized id-change, which would - * trash the parent's state. */ - if (attr->__flags & POSIX_SPAWN_RESETIDS) - if ((ret=__syscall(SYS_setgid, __syscall(SYS_getgid))) || - (ret=__syscall(SYS_setuid, __syscall(SYS_getuid))) ) - goto fail; - - if (fa && fa->__actions) { - struct fdop *op; - int fd; - for (op = fa->__actions; op->next; op = op->next); - for (; op; op = op->prev) { - /* It's possible that a file operation would clobber - * the pipe fd used for synchronizing with the - * parent. To avoid that, we dup the pipe onto - * an unoccupied fd. */ - if (op->fd == p) { - ret = __syscall(SYS_dup, p); - if (ret < 0) goto fail; - __syscall(SYS_close, p); - p = ret; - } - switch(op->cmd) { - case FDOP_CLOSE: - __syscall(SYS_close, op->fd); - break; - case FDOP_DUP2: - if ((ret=__sys_dup2(op->srcfd, op->fd))<0) - goto fail; - break; - case FDOP_OPEN: - fd = __sys_open(op->path, op->oflag, op->mode); - if ((ret=fd) < 0) goto fail; - if (fd != op->fd) { - if ((ret=__sys_dup2(fd, op->fd))<0) - goto fail; - __syscall(SYS_close, fd); - } - break; - } - } - } - - /* Close-on-exec flag may have been lost if we moved the pipe - * to a different fd. We don't use F_DUPFD_CLOEXEC above because - * it would fail on older kernels and atomicity is not needed -- - * in this process there are no threads or signal handlers. */ - __syscall(SYS_fcntl, p, F_SETFD, FD_CLOEXEC); - - pthread_sigmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK) - ? &attr->__mask : &args->oldmask, 0); - - args->exec(args->path, args->argv, args->envp); - ret = -errno; - -fail: - /* Since sizeof errno < PIPE_BUF, the write is atomic. */ - ret = -ret; - if (ret) while (__syscall(SYS_write, p, &ret, sizeof ret) < 0); - _exit(127); -} - - -int __posix_spawnx(pid_t *restrict res, const char *restrict path, - int (*exec)(const char *, char *const *, char *const *), - const posix_spawn_file_actions_t *fa, - const posix_spawnattr_t *restrict attr, - char *const argv[restrict], char *const envp[restrict]) -{ - pid_t pid; - char stack[1024]; - int ec=0, cs; - struct args args; - - if (pipe2(args.p, O_CLOEXEC)) - return errno; - - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - - args.path = path; - args.exec = exec; - args.fa = fa; - args.attr = attr ? attr : &(const posix_spawnattr_t){0}; - args.argv = argv; - args.envp = envp; - pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask); - - pid = __clone(child, stack+sizeof stack, - CLONE_VM|CLONE_VFORK|SIGCHLD, &args); - close(args.p[1]); - - if (pid > 0) { - if (read(args.p[0], &ec, sizeof ec) != sizeof ec) ec = 0; - else waitpid(pid, &(int){0}, 0); - } else { - ec = -pid; - } - - close(args.p[0]); - - if (!ec && res) *res = pid; - - pthread_sigmask(SIG_SETMASK, &args.oldmask, 0); - pthread_setcancelstate(cs, 0); - - return ec; -} - -int posix_spawn(pid_t *restrict res, const char *restrict path, - const posix_spawn_file_actions_t *fa, - const posix_spawnattr_t *restrict attr, - char *const argv[restrict], char *const envp[restrict]) -{ - return __posix_spawnx(res, path, execve, fa, attr, argv, envp); -} diff --git a/usr/lib/libc/process/posix_spawn_file_actions_addclose.c b/usr/lib/libc/process/posix_spawn_file_actions_addclose.c deleted file mode 100644 index cdda59799..000000000 --- a/usr/lib/libc/process/posix_spawn_file_actions_addclose.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -#include "fdop.h" - -int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd) -{ - struct fdop *op = malloc(sizeof *op); - if (!op) return ENOMEM; - op->cmd = FDOP_CLOSE; - op->fd = fd; - if ((op->next = fa->__actions)) op->next->prev = op; - op->prev = 0; - fa->__actions = op; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawn_file_actions_adddup2.c b/usr/lib/libc/process/posix_spawn_file_actions_adddup2.c deleted file mode 100644 index 0367498fd..000000000 --- a/usr/lib/libc/process/posix_spawn_file_actions_adddup2.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include "fdop.h" - -int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd) -{ - struct fdop *op = malloc(sizeof *op); - if (!op) return ENOMEM; - op->cmd = FDOP_DUP2; - op->srcfd = srcfd; - op->fd = fd; - if ((op->next = fa->__actions)) op->next->prev = op; - op->prev = 0; - fa->__actions = op; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawn_file_actions_addopen.c b/usr/lib/libc/process/posix_spawn_file_actions_addopen.c deleted file mode 100644 index 368922c76..000000000 --- a/usr/lib/libc/process/posix_spawn_file_actions_addopen.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include -#include -#include "fdop.h" - -int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode) -{ - struct fdop *op = malloc(sizeof *op + strlen(path) + 1); - if (!op) return ENOMEM; - op->cmd = FDOP_OPEN; - op->fd = fd; - op->oflag = flags; - op->mode = mode; - strcpy(op->path, path); - if ((op->next = fa->__actions)) op->next->prev = op; - op->prev = 0; - fa->__actions = op; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawn_file_actions_destroy.c b/usr/lib/libc/process/posix_spawn_file_actions_destroy.c deleted file mode 100644 index 3251babb5..000000000 --- a/usr/lib/libc/process/posix_spawn_file_actions_destroy.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include "fdop.h" - -int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *fa) -{ - struct fdop *op = fa->__actions, *next; - while (op) { - next = op->next; - free(op); - op = next; - } - return 0; -} diff --git a/usr/lib/libc/process/posix_spawn_file_actions_init.c b/usr/lib/libc/process/posix_spawn_file_actions_init.c deleted file mode 100644 index 89d5e1278..000000000 --- a/usr/lib/libc/process/posix_spawn_file_actions_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawn_file_actions_init(posix_spawn_file_actions_t *fa) -{ - fa->__actions = 0; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_destroy.c b/usr/lib/libc/process/posix_spawnattr_destroy.c deleted file mode 100644 index fc714a1b2..000000000 --- a/usr/lib/libc/process/posix_spawnattr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int posix_spawnattr_destroy(posix_spawnattr_t *attr) -{ - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_getflags.c b/usr/lib/libc/process/posix_spawnattr_getflags.c deleted file mode 100644 index aa635ddaf..000000000 --- a/usr/lib/libc/process/posix_spawnattr_getflags.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags) -{ - *flags = attr->__flags; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_getpgroup.c b/usr/lib/libc/process/posix_spawnattr_getpgroup.c deleted file mode 100644 index 0480527d6..000000000 --- a/usr/lib/libc/process/posix_spawnattr_getpgroup.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict attr, pid_t *restrict pgrp) -{ - *pgrp = attr->__pgrp; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_getsigdefault.c b/usr/lib/libc/process/posix_spawnattr_getsigdefault.c deleted file mode 100644 index a49050aa4..000000000 --- a/usr/lib/libc/process/posix_spawnattr_getsigdefault.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict attr, sigset_t *restrict def) -{ - *def = attr->__def; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_getsigmask.c b/usr/lib/libc/process/posix_spawnattr_getsigmask.c deleted file mode 100644 index f60ad7f37..000000000 --- a/usr/lib/libc/process/posix_spawnattr_getsigmask.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict attr, sigset_t *restrict mask) -{ - *mask = attr->__mask; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_init.c b/usr/lib/libc/process/posix_spawnattr_init.c deleted file mode 100644 index 0dcd868f3..000000000 --- a/usr/lib/libc/process/posix_spawnattr_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_init(posix_spawnattr_t *attr) -{ - *attr = (posix_spawnattr_t){ 0 }; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_sched.c b/usr/lib/libc/process/posix_spawnattr_sched.c deleted file mode 100644 index 3143635ba..000000000 --- a/usr/lib/libc/process/posix_spawnattr_sched.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include - -int posix_spawnattr_getschedparam(const posix_spawnattr_t *restrict attr, - struct sched_param *restrict schedparam) -{ - return ENOSYS; -} - -int posix_spawnattr_setschedparam(posix_spawnattr_t *restrict attr, - const struct sched_param *restrict schedparam) -{ - return ENOSYS; -} - -int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict attr, int *restrict policy) -{ - return ENOSYS; -} - -int posix_spawnattr_setschedpolicy(posix_spawnattr_t *attr, int policy) -{ - return ENOSYS; -} diff --git a/usr/lib/libc/process/posix_spawnattr_setflags.c b/usr/lib/libc/process/posix_spawnattr_setflags.c deleted file mode 100644 index 687809921..000000000 --- a/usr/lib/libc/process/posix_spawnattr_setflags.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags) -{ - const unsigned all_flags = - POSIX_SPAWN_RESETIDS | - POSIX_SPAWN_SETPGROUP | - POSIX_SPAWN_SETSIGDEF | - POSIX_SPAWN_SETSIGMASK | - POSIX_SPAWN_SETSCHEDPARAM | - POSIX_SPAWN_SETSCHEDULER | - POSIX_SPAWN_USEVFORK | - POSIX_SPAWN_SETSID; - if (flags & ~all_flags) return EINVAL; - attr->__flags = flags; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_setpgroup.c b/usr/lib/libc/process/posix_spawnattr_setpgroup.c deleted file mode 100644 index f39596a6e..000000000 --- a/usr/lib/libc/process/posix_spawnattr_setpgroup.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_setpgroup(posix_spawnattr_t *attr, pid_t pgrp) -{ - attr->__pgrp = pgrp; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_setsigdefault.c b/usr/lib/libc/process/posix_spawnattr_setsigdefault.c deleted file mode 100644 index 568697267..000000000 --- a/usr/lib/libc/process/posix_spawnattr_setsigdefault.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict attr, const sigset_t *restrict def) -{ - attr->__def = *def; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnattr_setsigmask.c b/usr/lib/libc/process/posix_spawnattr_setsigmask.c deleted file mode 100644 index f2532f8e0..000000000 --- a/usr/lib/libc/process/posix_spawnattr_setsigmask.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict attr, const sigset_t *restrict mask) -{ - attr->__mask = *mask; - return 0; -} diff --git a/usr/lib/libc/process/posix_spawnp.c b/usr/lib/libc/process/posix_spawnp.c deleted file mode 100644 index 37360001d..000000000 --- a/usr/lib/libc/process/posix_spawnp.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -int __execvpe(const char *, char *const *, char *const *); - -int __posix_spawnx(pid_t *restrict, const char *restrict, - int (*)(const char *, char *const *, char *const *), - const posix_spawn_file_actions_t *, - const posix_spawnattr_t *restrict, char *const *restrict, char *const *restrict); - -int posix_spawnp(pid_t *restrict res, const char *restrict file, - const posix_spawn_file_actions_t *fa, - const posix_spawnattr_t *restrict attr, - char *const argv[restrict], char *const envp[restrict]) -{ - return __posix_spawnx(res, file, __execvpe, fa, attr, argv, envp); -} diff --git a/usr/lib/libc/process/ptrace.c b/usr/lib/libc/process/ptrace.c deleted file mode 100644 index 2d15b4b12..000000000 --- a/usr/lib/libc/process/ptrace.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include - -long ptrace(int req, ...) -{ - va_list ap; - pid_t pid; - void *addr, *data; - long ret, result; - - va_start(ap, req); - pid = va_arg(ap, pid_t); - addr = va_arg(ap, void *); - data = va_arg(ap, void *); - va_end(ap); - - if (req-1U < 3) data = &result; -#if 0 - ret = syscall(SYS_ptrace, req, pid, addr, data, addr2); -#endif - ret = __syscall_ret(sys_ptrace(req, pid, addr, data)); - - if (ret < 0 || req-1U >= 3) return ret; - return result; -} diff --git a/usr/lib/libc/process/system.c b/usr/lib/libc/process/system.c deleted file mode 100644 index 8cbdda060..000000000 --- a/usr/lib/libc/process/system.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "pthread_impl.h" -#include "libc.h" - -extern char **__environ; - -int system(const char *cmd) -{ - pid_t pid; - sigset_t old, reset; - struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit; - int status = 0x7f00, ret; - posix_spawnattr_t attr; - - pthread_testcancel(); - - if (!cmd) return 1; - - sigaction(SIGINT, &sa, &oldint); - sigaction(SIGQUIT, &sa, &oldquit); - sigaddset(&sa.sa_mask, SIGCHLD); - sigprocmask(SIG_BLOCK, &sa.sa_mask, &old); - - sigemptyset(&reset); - if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT); - if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT); - posix_spawnattr_init(&attr); - posix_spawnattr_setsigmask(&attr, &old); - posix_spawnattr_setsigdefault(&attr, &reset); - posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK); - ret = posix_spawn(&pid, "/bin/sh", 0, &attr, - (char *[]){"sh", "-c", (char *)cmd, 0}, __environ); - posix_spawnattr_destroy(&attr); - - if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR); - sigaction(SIGINT, &oldint, NULL); - sigaction(SIGQUIT, &oldquit, NULL); - sigprocmask(SIG_SETMASK, &old, NULL); - - if (ret) errno = ret; - return status; -} diff --git a/usr/lib/libc/process/vfork.c b/usr/lib/libc/process/vfork.c deleted file mode 100644 index ac954651b..000000000 --- a/usr/lib/libc/process/vfork.c +++ /dev/null @@ -1,17 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include "syscall.h" -#include "libc.h" - -pid_t __vfork(void) -{ - /* vfork syscall cannot be made from C code */ -#ifdef SYS_fork - return syscall(SYS_fork); -#else - return syscall(SYS_clone, SIGCHLD, 0); -#endif -} - -weak_alias(__vfork, vfork); diff --git a/usr/lib/libc/process/wait.c b/usr/lib/libc/process/wait.c deleted file mode 100644 index 34da102d5..000000000 --- a/usr/lib/libc/process/wait.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -pid_t wait(int *status) -{ - return waitpid((pid_t)-1, status, 0); -} diff --git a/usr/lib/libc/process/waitid.c b/usr/lib/libc/process/waitid.c deleted file mode 100644 index c67feac38..000000000 --- a/usr/lib/libc/process/waitid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int waitid(idtype_t type, id_t id, siginfo_t *info, int options) -{ - return syscall_cp(SYS_waitid, type, id, info, options, 0); -} diff --git a/usr/lib/libc/process/waitpid.c b/usr/lib/libc/process/waitpid.c deleted file mode 100644 index 3b9ed8662..000000000 --- a/usr/lib/libc/process/waitpid.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -#include - -pid_t waitpid(pid_t pid, int *status, int options) -{ - return __syscall_ret(sys_waitpid(pid, status, options)); -#if 0 - return syscall_cp(SYS_wait4, pid, status, options, 0); -#endif -} diff --git a/usr/lib/libc/pthread.c b/usr/lib/libc/pthread.c deleted file mode 100644 index eec3d419f..000000000 --- a/usr/lib/libc/pthread.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2014-2018 Daniel Rossier - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include -#include -#include -#include -#include - -void *(*__thread_fn)(void *) = NULL; - -void *__thread_routine(void *args) { - void *(*____thread_fn)(void *); - - ____thread_fn = __thread_fn; - __thread_fn = NULL; - - ____thread_fn(args); - - sys_thread_exit(NULL); - - /* We should never be here ... */ - - assert(0); - - return NULL; -} - -/* Yield to another thread */ -int pthread_yield(void) { - sys_thread_yield(); - - return 0; -} - -/* Thread creation */ -int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { - int ret; - - while (__thread_fn != NULL) - pthread_yield(); - - __thread_fn = start_routine; - ret = sys_thread_create(thread, attr, __thread_routine, arg); - - return ret; -} - -/* Thread join / synchronisation */ -int pthread_join(pthread_t thread, void **value_ptr) { - - return sys_thread_join(thread, value_ptr); -} - -/* Modify thread priority */ -int pthread_setschedprio(pthread_t thread, int prio) { - return sys_sched_setparam(thread, prio); -} - -/* Thread exit */ -void pthread_exit(void *value_ptr) { - sys_thread_exit(value_ptr); -} - -void pthread_mutex_lock(void) { - sys_mutex_lock(2); -} - -void pthread_mutex_unlock(void) { - sys_mutex_unlock(2); -} diff --git a/usr/lib/libc/sbrk.c b/usr/lib/libc/sbrk.c deleted file mode 100644 index de030a05d..000000000 --- a/usr/lib/libc/sbrk.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include -#include - -void *sbrk(intptr_t inc) -{ - return (void *) __syscall_ret(sys_sbrk(0)); -#if 0 - if (inc) return (void *)__syscall_ret(-ENOMEM); - return (void *)__syscall(SYS_brk, 0); -#endif -} - - diff --git a/usr/lib/libc/setjmp.S b/usr/lib/libc/setjmp.S deleted file mode 100644 index edc55dd19..000000000 --- a/usr/lib/libc/setjmp.S +++ /dev/null @@ -1,83 +0,0 @@ -#ifdef __ARM__ - -.syntax unified -.global __setjmp -.global _setjmp -.global setjmp -.type __setjmp,%function -.type _setjmp,%function -.type setjmp,%function -__setjmp: -_setjmp: -setjmp: - mov ip,r0 - stmia ip!,{v1,v2,v3,v4,v5,v6,sl,fp} - mov r2,sp - stmia ip!,{r2,lr} - mov r0,#0 - - adr r1,1f - ldr r2,1f - ldr r1,[r1,r2] - -#if __ARM_ARCH < 8 - tst r1,#0x260 - beq 3f - // HWCAP_ARM_FPA - tst r1,#0x20 - beq 2f - stc p2, cr4, [ip], #48 -#endif -2: tst r1,#0x40 - beq 2f - .fpu vfp - vstmia ip!, {d8-d15} - .fpu softvfp - .eabi_attribute 10, 0 - .eabi_attribute 27, 0 -#if __ARM_ARCH < 8 - // HWCAP_ARM_IWMMXT -2: tst r1,#0x200 - beq 3f - stcl p1, cr10, [ip], #8 - stcl p1, cr11, [ip], #8 - stcl p1, cr12, [ip], #8 - stcl p1, cr13, [ip], #8 - stcl p1, cr14, [ip], #8 - stcl p1, cr15, [ip], #8 -#endif -2: -3: bx lr - -.hidden __hwcap -.align 2 -1: .word __hwcap-1b - -#else /* __ARM64__ */ - -.global __setjmp -.global _setjmp -.global setjmp -.type __setjmp,@function -.type _setjmp,@function -.type setjmp,@function -__setjmp: -_setjmp: -setjmp: - // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers - stp x19, x20, [x0,#0] - stp x21, x22, [x0,#16] - stp x23, x24, [x0,#32] - stp x25, x26, [x0,#48] - stp x27, x28, [x0,#64] - stp x29, x30, [x0,#80] - mov x2, sp - str x2, [x0,#104] - stp d8, d9, [x0,#112] - stp d10, d11, [x0,#128] - stp d12, d13, [x0,#144] - stp d14, d15, [x0,#160] - mov x0, #0 - ret - -#endif /* __ARM__ */ diff --git a/usr/lib/libc/shgetc.c b/usr/lib/libc/shgetc.c deleted file mode 100644 index af903c50a..000000000 --- a/usr/lib/libc/shgetc.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "shgetc.h" - -void __shlim(FILE *f, off_t lim) -{ - f->shlim = lim; - f->shcnt = f->rend - f->rpos; - if (lim && f->shcnt > lim) - f->shend = f->rpos + lim; - else - f->shend = f->rend; -} - -int __shgetc(FILE *f) -{ - int c; - if ((f->shlim && (f->shcnt >= f->shlim)) || (c=__uflow(f)) < 0) { - f->shend = 0; - return EOF; - } - if (f->shlim && f->rend - f->rpos > f->shlim - f->shcnt - 1) - f->shend = f->rpos + (f->shlim - f->shcnt - 1); - else - f->shend = f->rend; - if (f->rend) f->shcnt += f->rend - f->rpos + 1; - if (f->rpos[-1] != c) f->rpos[-1] = c; - - /* (SO3) Immediately return the echo */ - if ((c == '\n') || (c == '\r')) - putchar('\n'); - else - putchar(c); - - return c; -} diff --git a/usr/lib/libc/signal/CMakeLists.txt b/usr/lib/libc/signal/CMakeLists.txt deleted file mode 100644 index d5314f8d3..000000000 --- a/usr/lib/libc/signal/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ - -target_sources(c - PRIVATE - signal.c - sigaction.c - kill.c -) diff --git a/usr/lib/libc/signal/block.c b/usr/lib/libc/signal/block.c deleted file mode 100644 index d7f610013..000000000 --- a/usr/lib/libc/signal/block.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "pthread_impl.h" -#include "syscall.h" -#include - -static const unsigned long all_mask[] = { -#if ULONG_MAX == 0xffffffff && _NSIG == 129 - -1UL, -1UL, -1UL, -1UL -#elif ULONG_MAX == 0xffffffff - -1UL, -1UL -#else - -1UL -#endif -}; - -static const unsigned long app_mask[] = { -#if ULONG_MAX == 0xffffffff -#if _NSIG == 65 - 0x7fffffff, 0xfffffffc -#else - 0x7fffffff, 0xfffffffc, -1UL, -1UL -#endif -#else -#if _NSIG == 65 - 0xfffffffc7fffffff -#else - 0xfffffffc7fffffff, -1UL -#endif -#endif -}; - -void __block_all_sigs(void *set) -{ - __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &all_mask, set, _NSIG/8); -} - -void __block_app_sigs(void *set) -{ - __syscall(SYS_rt_sigprocmask, SIG_BLOCK, &app_mask, set, _NSIG/8); -} - -void __restore_sigs(void *set) -{ - __syscall(SYS_rt_sigprocmask, SIG_SETMASK, set, 0, _NSIG/8); -} diff --git a/usr/lib/libc/signal/getitimer.c b/usr/lib/libc/signal/getitimer.c deleted file mode 100644 index 8a8046a76..000000000 --- a/usr/lib/libc/signal/getitimer.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getitimer(int which, struct itimerval *old) -{ - return syscall(SYS_getitimer, which, old); -} diff --git a/usr/lib/libc/signal/handler b/usr/lib/libc/signal/handler deleted file mode 100644 index e69de29bb..000000000 diff --git a/usr/lib/libc/signal/kill.c b/usr/lib/libc/signal/kill.c deleted file mode 100644 index dbc9fdb8a..000000000 --- a/usr/lib/libc/signal/kill.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int kill(pid_t pid, int sig) -{ - return __syscall_ret(sys_kill(pid, sig)); - -#if 0 /* SO3 */ - return syscall(SYS_kill, pid, sig); -#endif -} diff --git a/usr/lib/libc/signal/killpg.c b/usr/lib/libc/signal/killpg.c deleted file mode 100644 index 315ed4474..000000000 --- a/usr/lib/libc/signal/killpg.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int killpg(pid_t pgid, int sig) -{ - if (pgid < 0) { - errno = EINVAL; - return -1; - } - return kill(-pgid, sig); -} diff --git a/usr/lib/libc/signal/psiginfo.c b/usr/lib/libc/signal/psiginfo.c deleted file mode 100644 index 57be34cd0..000000000 --- a/usr/lib/libc/signal/psiginfo.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -void psiginfo(const siginfo_t *si, const char *msg) -{ - char *s = strsignal(si->si_signo); - if (msg) fprintf(stderr, "%s: %s\n", msg, s); - else fprintf(stderr, "%s\n", s); -} diff --git a/usr/lib/libc/signal/psignal.c b/usr/lib/libc/signal/psignal.c deleted file mode 100644 index 02f1c7609..000000000 --- a/usr/lib/libc/signal/psignal.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -void psignal(int sig, const char *msg) -{ - char *s = strsignal(sig); - if (msg) fprintf(stderr, "%s: %s\n", msg, s); - else fprintf(stderr, "%s\n", s); -} diff --git a/usr/lib/libc/signal/raise.c b/usr/lib/libc/signal/raise.c deleted file mode 100644 index 717b1c917..000000000 --- a/usr/lib/libc/signal/raise.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include "syscall.h" -#include "pthread_impl.h" - -int raise(int sig) -{ - int tid, ret; - sigset_t set; - __block_app_sigs(&set); - tid = __syscall(SYS_gettid); - ret = syscall(SYS_tkill, tid, sig); - __restore_sigs(&set); - return ret; -} diff --git a/usr/lib/libc/signal/restore.c b/usr/lib/libc/signal/restore.c deleted file mode 100644 index 873b867e6..000000000 --- a/usr/lib/libc/signal/restore.c +++ /dev/null @@ -1,10 +0,0 @@ -/* These functions will not work, but suffice for targets where the - * kernel sigaction structure does not actually use sa_restorer. */ - -void __restore() -{ -} - -void __restore_rt() -{ -} diff --git a/usr/lib/libc/signal/setitimer.c b/usr/lib/libc/signal/setitimer.c deleted file mode 100644 index 21b1f45da..000000000 --- a/usr/lib/libc/signal/setitimer.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old) -{ - return syscall(SYS_setitimer, which, new, old); -} diff --git a/usr/lib/libc/signal/sigaction.c b/usr/lib/libc/signal/sigaction.c deleted file mode 100644 index a051c36a8..000000000 --- a/usr/lib/libc/signal/sigaction.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#if 0 /* unused in SO3 */ -static int unmask_done; -#endif - -static unsigned long handler_set[_NSIG/(8*sizeof(long))]; - -void __get_handler_set(sigset_t *set) -{ - memcpy(set, handler_set, sizeof handler_set); -} - -typedef void (*sigaction_handler_t)(int); - -/* SO3 */ -/* - * Trampoline function to call the handler - */ -void __restore(int signum, void *handler) { - sigaction_handler_t __handler; - - /* First call the handler, then back to the kernel */ - __handler = (sigaction_handler_t) handler; - __handler(signum); - - sys_sigreturn(); -} - -void __restore_rt(int signum, void *handler) { - __restore(signum, handler); -} - -int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) -{ - struct k_sigaction ksa, ksa_old; - if (sa) { - if ((uintptr_t)sa->sa_handler > 1UL) { - a_or_l(handler_set+(sig-1)/(8*sizeof(long)), - 1UL<<(sig-1)%(8*sizeof(long))); - - /* If pthread_create has not yet been called, - * implementation-internal signals might not - * yet have been unblocked. They must be - * unblocked before any signal handler is - * installed, so that an application cannot - * receive an illegal sigset_t (with them - * blocked) as part of the ucontext_t passed - * to the signal handler. */ -#if 0 /* Not set available on SO3 */ - if (!libc.threaded && !unmask_done) { - - - __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, - SIGPT_SET, 0, _NSIG/8); - - unmask_done = 1; - } -#endif /* 0 */ - } - - ksa.handler = sa->sa_handler; - ksa.flags = sa->sa_flags | SA_RESTORER; - ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore; - memcpy(&ksa.mask, &sa->sa_mask, sizeof ksa.mask); - } - - /* SO3 */ - - sys_sigaction(sig, sa ? &ksa : 0, old ? &ksa_old : 0); - - if (old) { - old->sa_handler = ksa_old.handler; - old->sa_flags = ksa_old.flags; - memcpy(&old->sa_mask, &ksa_old.mask, sizeof ksa_old.mask); - } - return 0; -} - -int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) -{ - if (sig-32U < 3 || sig-1U >= _NSIG-1) { - errno = EINVAL; - return -1; - } - return __libc_sigaction(sig, sa, old); -} - -weak_alias(__sigaction, sigaction); diff --git a/usr/lib/libc/signal/sigaddset.c b/usr/lib/libc/signal/sigaddset.c deleted file mode 100644 index 085d1f4ab..000000000 --- a/usr/lib/libc/signal/sigaddset.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int sigaddset(sigset_t *set, int sig) -{ - unsigned s = sig-1; - if (s >= _NSIG-1 || sig-32U < 3) { - errno = EINVAL; - return -1; - } - set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); - return 0; -} diff --git a/usr/lib/libc/signal/sigaltstack.c b/usr/lib/libc/signal/sigaltstack.c deleted file mode 100644 index 62cb81adf..000000000 --- a/usr/lib/libc/signal/sigaltstack.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include "syscall.h" - -int sigaltstack(const stack_t *restrict ss, stack_t *restrict old) -{ - if (ss) { - if (ss->ss_size < MINSIGSTKSZ) { - errno = ENOMEM; - return -1; - } - if (ss->ss_flags & ~SS_DISABLE) { - errno = EINVAL; - return -1; - } - } - return syscall(SYS_sigaltstack, ss, old); -} diff --git a/usr/lib/libc/signal/sigandset.c b/usr/lib/libc/signal/sigandset.c deleted file mode 100644 index 974186f3d..000000000 --- a/usr/lib/libc/signal/sigandset.c +++ /dev/null @@ -1,12 +0,0 @@ -#define _GNU_SOURCE -#include - -#define SST_SIZE (_NSIG/8/sizeof(long)) - -int sigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right) -{ - unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right; - for(; i < SST_SIZE; i++) d[i] = l[i] & r[i]; - return 0; -} - diff --git a/usr/lib/libc/signal/sigdelset.c b/usr/lib/libc/signal/sigdelset.c deleted file mode 100644 index ce69280e0..000000000 --- a/usr/lib/libc/signal/sigdelset.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int sigdelset(sigset_t *set, int sig) -{ - unsigned s = sig-1; - if (s >= _NSIG-1 || sig-32U < 3) { - errno = EINVAL; - return -1; - } - set->__bits[s/8/sizeof *set->__bits] &=~(1UL<<(s&8*sizeof *set->__bits-1)); - return 0; -} diff --git a/usr/lib/libc/signal/sigemptyset.c b/usr/lib/libc/signal/sigemptyset.c deleted file mode 100644 index 1d07471da..000000000 --- a/usr/lib/libc/signal/sigemptyset.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int sigemptyset(sigset_t *set) -{ - set->__bits[0] = 0; - if (sizeof(long)==4 || _NSIG > 65) set->__bits[1] = 0; - if (sizeof(long)==4 && _NSIG > 65) { - set->__bits[2] = 0; - set->__bits[3] = 0; - } - return 0; -} diff --git a/usr/lib/libc/signal/sigfillset.c b/usr/lib/libc/signal/sigfillset.c deleted file mode 100644 index 16e7b4f5b..000000000 --- a/usr/lib/libc/signal/sigfillset.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -int sigfillset(sigset_t *set) -{ -#if ULONG_MAX == 0xffffffff - set->__bits[0] = 0x7ffffffful; - set->__bits[1] = 0xfffffffcul; - if (_NSIG > 65) { - set->__bits[2] = 0xfffffffful; - set->__bits[3] = 0xfffffffful; - } -#else - set->__bits[0] = 0xfffffffc7ffffffful; - if (_NSIG > 65) set->__bits[1] = 0xfffffffffffffffful; -#endif - return 0; -} diff --git a/usr/lib/libc/signal/sighold.c b/usr/lib/libc/signal/sighold.c deleted file mode 100644 index cfa2306c1..000000000 --- a/usr/lib/libc/signal/sighold.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int sighold(int sig) -{ - sigset_t mask; - - sigemptyset(&mask); - if (sigaddset(&mask, sig) < 0) return -1; - return sigprocmask(SIG_BLOCK, &mask, 0); -} diff --git a/usr/lib/libc/signal/sigignore.c b/usr/lib/libc/signal/sigignore.c deleted file mode 100644 index 5ba05e129..000000000 --- a/usr/lib/libc/signal/sigignore.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int sigignore(int sig) -{ - struct sigaction sa; - - sigemptyset(&sa.sa_mask); - sa.sa_handler = SIG_IGN; - sa.sa_flags = 0; - return sigaction(sig, &sa, 0); -} diff --git a/usr/lib/libc/signal/siginterrupt.c b/usr/lib/libc/signal/siginterrupt.c deleted file mode 100644 index 700634003..000000000 --- a/usr/lib/libc/signal/siginterrupt.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int siginterrupt(int sig, int flag) -{ - struct sigaction sa; - - sigaction(sig, 0, &sa); - if (flag) sa.sa_flags &= ~SA_RESTART; - else sa.sa_flags |= SA_RESTART; - - return sigaction(sig, &sa, 0); -} diff --git a/usr/lib/libc/signal/sigisemptyset.c b/usr/lib/libc/signal/sigisemptyset.c deleted file mode 100644 index 312c66cf8..000000000 --- a/usr/lib/libc/signal/sigisemptyset.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -int sigisemptyset(const sigset_t *set) -{ - static const unsigned long zeroset[_NSIG/8/sizeof(long)]; - return !memcmp(set, &zeroset, _NSIG/8); -} diff --git a/usr/lib/libc/signal/sigismember.c b/usr/lib/libc/signal/sigismember.c deleted file mode 100644 index ab87d6224..000000000 --- a/usr/lib/libc/signal/sigismember.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int sigismember(const sigset_t *set, int sig) -{ - unsigned s = sig-1; - if (s >= _NSIG-1) return 0; - return !!(set->__bits[s/8/sizeof *set->__bits] & 1UL<<(s&8*sizeof *set->__bits-1)); -} diff --git a/usr/lib/libc/signal/siglongjmp.c b/usr/lib/libc/signal/siglongjmp.c deleted file mode 100644 index bc317acce..000000000 --- a/usr/lib/libc/signal/siglongjmp.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include "syscall.h" -#include "pthread_impl.h" - -_Noreturn void siglongjmp(sigjmp_buf buf, int ret) -{ - longjmp(buf, ret); -} diff --git a/usr/lib/libc/signal/signal.c b/usr/lib/libc/signal/signal.c deleted file mode 100644 index af4b78232..000000000 --- a/usr/lib/libc/signal/signal.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include - -int __sigaction(int, const struct sigaction *, struct sigaction *); - -void (*signal(int sig, void (*func)(int)))(int) -{ - struct sigaction sa_old, sa = { .sa_handler = func, .sa_flags = SA_RESTART }; - if (__sigaction(sig, &sa, &sa_old) < 0) - return SIG_ERR; - return sa_old.sa_handler; -} - -weak_alias(signal, bsd_signal); -weak_alias(signal, __sysv_signal); diff --git a/usr/lib/libc/signal/sigorset.c b/usr/lib/libc/signal/sigorset.c deleted file mode 100644 index ed488738c..000000000 --- a/usr/lib/libc/signal/sigorset.c +++ /dev/null @@ -1,12 +0,0 @@ -#define _GNU_SOURCE -#include - -#define SST_SIZE (_NSIG/8/sizeof(long)) - -int sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right) -{ - unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right; - for(; i < SST_SIZE; i++) d[i] = l[i] | r[i]; - return 0; -} - diff --git a/usr/lib/libc/signal/sigpause.c b/usr/lib/libc/signal/sigpause.c deleted file mode 100644 index 363d2fec2..000000000 --- a/usr/lib/libc/signal/sigpause.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int sigpause(int sig) -{ - sigset_t mask; - sigprocmask(0, 0, &mask); - sigdelset(&mask, sig); - return sigsuspend(&mask); -} diff --git a/usr/lib/libc/signal/sigpending.c b/usr/lib/libc/signal/sigpending.c deleted file mode 100644 index 3d193df83..000000000 --- a/usr/lib/libc/signal/sigpending.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int sigpending(sigset_t *set) -{ - return syscall(SYS_rt_sigpending, set, _NSIG/8); -} diff --git a/usr/lib/libc/signal/sigprocmask.c b/usr/lib/libc/signal/sigprocmask.c deleted file mode 100644 index 297e20c65..000000000 --- a/usr/lib/libc/signal/sigprocmask.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old) -{ - int r = pthread_sigmask(how, set, old); - if (!r) return r; - errno = r; - return -1; -} diff --git a/usr/lib/libc/signal/sigqueue.c b/usr/lib/libc/signal/sigqueue.c deleted file mode 100644 index b75f0c5ce..000000000 --- a/usr/lib/libc/signal/sigqueue.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include "syscall.h" -#include "pthread_impl.h" - -int sigqueue(pid_t pid, int sig, const union sigval value) -{ - siginfo_t si; - sigset_t set; - int r; - memset(&si, 0, sizeof si); - si.si_signo = sig; - si.si_code = SI_QUEUE; - si.si_value = value; - si.si_uid = getuid(); - __block_app_sigs(&set); - si.si_pid = getpid(); - r = syscall(SYS_rt_sigqueueinfo, pid, sig, &si); - __restore_sigs(&set); - return r; -} diff --git a/usr/lib/libc/signal/sigrelse.c b/usr/lib/libc/signal/sigrelse.c deleted file mode 100644 index b4c5a00f1..000000000 --- a/usr/lib/libc/signal/sigrelse.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int sigrelse(int sig) -{ - sigset_t mask; - - sigemptyset(&mask); - if (sigaddset(&mask, sig) < 0) return -1; - return sigprocmask(SIG_UNBLOCK, &mask, 0); -} diff --git a/usr/lib/libc/signal/sigrtmax.c b/usr/lib/libc/signal/sigrtmax.c deleted file mode 100644 index 44dc88ff2..000000000 --- a/usr/lib/libc/signal/sigrtmax.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int __libc_current_sigrtmax() -{ - return _NSIG-1; -} diff --git a/usr/lib/libc/signal/sigrtmin.c b/usr/lib/libc/signal/sigrtmin.c deleted file mode 100644 index d0e769bbc..000000000 --- a/usr/lib/libc/signal/sigrtmin.c +++ /dev/null @@ -1,4 +0,0 @@ -int __libc_current_sigrtmin() -{ - return 35; -} diff --git a/usr/lib/libc/signal/sigset.c b/usr/lib/libc/signal/sigset.c deleted file mode 100644 index 0d7b45646..000000000 --- a/usr/lib/libc/signal/sigset.c +++ /dev/null @@ -1,27 +0,0 @@ -#include - -void (*sigset(int sig, void (*handler)(int)))(int) -{ - struct sigaction sa, sa_old; - sigset_t mask; - - sigemptyset(&mask); - if (sigaddset(&mask, sig) < 0) - return SIG_ERR; - - if (handler == SIG_HOLD) { - if (sigaction(sig, 0, &sa_old) < 0) - return SIG_ERR; - if (sigprocmask(SIG_BLOCK, &mask, &mask) < 0) - return SIG_ERR; - } else { - sa.sa_handler = handler; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - if (sigaction(sig, &sa, &sa_old) < 0) - return SIG_ERR; - if (sigprocmask(SIG_UNBLOCK, &mask, &mask) < 0) - return SIG_ERR; - } - return sigismember(&mask, sig) ? SIG_HOLD : sa_old.sa_handler; -} diff --git a/usr/lib/libc/signal/sigsetjmp.c b/usr/lib/libc/signal/sigsetjmp.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/usr/lib/libc/signal/sigsetjmp_tail.c b/usr/lib/libc/signal/sigsetjmp_tail.c deleted file mode 100644 index 78762aa2b..000000000 --- a/usr/lib/libc/signal/sigsetjmp_tail.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "syscall.h" - -__attribute__((__visibility__("hidden"))) -int __sigsetjmp_tail(sigjmp_buf jb, int ret) -{ - void *p = jb->__ss; - __syscall(SYS_rt_sigprocmask, SIG_SETMASK, ret?p:0, ret?0:p, _NSIG/8); - return ret; -} diff --git a/usr/lib/libc/signal/sigsuspend.c b/usr/lib/libc/signal/sigsuspend.c deleted file mode 100644 index 0b42725ac..000000000 --- a/usr/lib/libc/signal/sigsuspend.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int sigsuspend(const sigset_t *mask) -{ - return syscall_cp(SYS_rt_sigsuspend, mask, _NSIG/8); -} diff --git a/usr/lib/libc/signal/sigtimedwait.c b/usr/lib/libc/signal/sigtimedwait.c deleted file mode 100644 index 0739986b1..000000000 --- a/usr/lib/libc/signal/sigtimedwait.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -int sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict timeout) -{ - int ret; - do ret = syscall_cp(SYS_rt_sigtimedwait, mask, - si, timeout, _NSIG/8); - while (ret<0 && errno==EINTR); - return ret; -} diff --git a/usr/lib/libc/signal/sigwait.c b/usr/lib/libc/signal/sigwait.c deleted file mode 100644 index c8822eea4..000000000 --- a/usr/lib/libc/signal/sigwait.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int sigwait(const sigset_t *restrict mask, int *restrict sig) -{ - siginfo_t si; - if (sigtimedwait(mask, &si, 0) < 0) - return -1; - *sig = si.si_signo; - return 0; -} diff --git a/usr/lib/libc/signal/sigwaitinfo.c b/usr/lib/libc/signal/sigwaitinfo.c deleted file mode 100644 index bb51f8b52..000000000 --- a/usr/lib/libc/signal/sigwaitinfo.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int sigwaitinfo(const sigset_t *restrict mask, siginfo_t *restrict si) -{ - return sigtimedwait(mask, si, 0); -} diff --git a/usr/lib/libc/stdarg.h b/usr/lib/libc/stdarg.h deleted file mode 100644 index 24f338319..000000000 --- a/usr/lib/libc/stdarg.h +++ /dev/null @@ -1,205 +0,0 @@ -/* stdarg.h for GNU. - Note that the type used in va_arg is supposed to match the - actual type **after default promotions**. - Thus, va_arg (..., short) is not valid. */ - -#ifndef _STDARG_H -#ifndef _ANSI_STDARG_H_ -#ifndef __need___va_list -#define _STDARG_H -#define _ANSI_STDARG_H_ -#endif /* not __need___va_list */ -#undef __need___va_list - -#ifdef __clipper__ -#include "va-clipper.h" -#else -#ifdef __m88k__ -#include "va-m88k.h" -#else -#ifdef __i860__ -#include "va-i860.h" -#else -#ifdef __hppa__ -#include "va-pa.h" -#else -#ifdef __mips__ -#include "va-mips.h" -#else -#ifdef __sparc__ -#include "va-sparc.h" -#else -#ifdef __i960__ -#include "va-i960.h" -#else -#ifdef __alpha__ -#include "va-alpha.h" -#else -#if defined (__H8300__) || defined (__H8300H__) || defined (__H8300S__) -#include "va-h8300.h" -#else -#if defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32)) -#include "va-ppc.h" -#else -#ifdef __arc__ -#include "va-arc.h" -#else -#ifdef __M32R__ -#include "va-m32r.h" -#else -#ifdef __sh__ -#include "va-sh.h" -#else -#ifdef __mn10300__ -#include "va-mn10300.h" -#else -#ifdef __mn10200__ -#include "va-mn10200.h" -#else -#ifdef __v850__ -#include "va-v850.h" -#else - -/* Define __gnuc_va_list. */ - -#ifndef __GNUC_VA_LIST -#define __GNUC_VA_LIST -#if defined(__svr4__) || defined(_AIX) || defined(_M_UNIX) || defined(__NetBSD__) -typedef char *__gnuc_va_list; -#else -typedef void *__gnuc_va_list; -#endif -#endif - -/* Define the standard macros for the user, - if this invocation was from the user program. */ -#ifdef _STDARG_H - -/* Amount of space required in an argument list for an arg of type TYPE. - TYPE may alternatively be an expression whose type is used. */ - -#if defined(sysV68) -#define __va_rounded_size(TYPE) \ - (((sizeof (TYPE) + sizeof (short) - 1) / sizeof (short)) * sizeof (short)) -#else -#define __va_rounded_size(TYPE) \ - (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) -#endif - -#define va_start(AP, LASTARG) \ - (AP = ((__gnuc_va_list) __builtin_next_arg (LASTARG))) - -#undef va_end -void va_end (__gnuc_va_list); /* Defined in libgcc.a */ -#define va_end(AP) ((void)0) - -/* We cast to void * and then to TYPE * because this avoids - a warning about increasing the alignment requirement. */ - -#if (defined (__arm__) && ! defined (__ARMEB__)) || defined (__i386__) || defined (__i860__) || defined (__ns32000__) || defined (__vax__) -/* This is for little-endian machines; small args are padded upward. */ -#define va_arg(AP, TYPE) \ - (AP = (__gnuc_va_list) ((char *) (AP) + __va_rounded_size (TYPE)), \ - *((TYPE *) (void *) ((char *) (AP) - __va_rounded_size (TYPE)))) -#else /* big-endian */ -/* This is for big-endian machines; small args are padded downward. */ -#define va_arg(AP, TYPE) \ - (AP = (__gnuc_va_list) ((char *) (AP) + __va_rounded_size (TYPE)), \ - *((TYPE *) (void *) ((char *) (AP) \ - - ((sizeof (TYPE) < __va_rounded_size (char) \ - ? sizeof (TYPE) : __va_rounded_size (TYPE)))))) -#endif /* big-endian */ - -/* Copy __gnuc_va_list into another variable of this type. */ -#define __va_copy(dest, src) (dest) = (src) - -#endif /* _STDARG_H */ - -#endif /* not v850 */ -#endif /* not mn10200 */ -#endif /* not mn10300 */ -#endif /* not sh */ -#endif /* not m32r */ -#endif /* not arc */ -#endif /* not powerpc with V.4 calling sequence */ -#endif /* not h8300 */ -#endif /* not alpha */ -#endif /* not i960 */ -#endif /* not sparc */ -#endif /* not mips */ -#endif /* not hppa */ -#endif /* not i860 */ -#endif /* not m88k */ -#endif /* not clipper */ - -#ifdef _STDARG_H -/* Define va_list, if desired, from __gnuc_va_list. */ -/* We deliberately do not define va_list when called from - stdio.h, because ANSI C says that stdio.h is not supposed to define - va_list. stdio.h needs to have access to that data type, - but must not use that name. It should use the name __gnuc_va_list, - which is safe because it is reserved for the implementation. */ - -#ifdef _HIDDEN_VA_LIST /* On OSF1, this means varargs.h is "half-loaded". */ -#undef _VA_LIST -#endif - -#ifdef _BSD_VA_LIST -#undef _BSD_VA_LIST -#endif - -#if defined(__svr4__) || (defined(_SCO_DS) && !defined(__VA_LIST)) -/* SVR4.2 uses _VA_LIST for an internal alias for va_list, - so we must avoid testing it and setting it here. - SVR4 uses _VA_LIST as a flag in stdarg.h, but we should - have no conflict with that. */ -#ifndef _VA_LIST_ -#define _VA_LIST_ -#ifdef __i860__ -#ifndef _VA_LIST -#define _VA_LIST va_list -#endif -#endif /* __i860__ */ -typedef __gnuc_va_list va_list; -#ifdef _SCO_DS -#define __VA_LIST -#endif -#endif /* _VA_LIST_ */ -#else /* not __svr4__ || _SCO_DS */ - -/* The macro _VA_LIST_ is the same thing used by this file in Ultrix. - But on BSD NET2 we must not test or define or undef it. - (Note that the comments in NET 2's ansi.h - are incorrect for _VA_LIST_--see stdio.h!) */ -#if !defined (_VA_LIST_) || defined (__BSD_NET2__) || defined (____386BSD____) || defined (__bsdi__) || defined (__sequent__) || defined (__FreeBSD__) || defined(WINNT) -/* The macro _VA_LIST_DEFINED is used in Windows NT 3.5 */ -#ifndef _VA_LIST_DEFINED -/* The macro _VA_LIST is used in SCO Unix 3.2. */ -#ifndef _VA_LIST -/* The macro _VA_LIST_T_H is used in the Bull dpx2 */ -#ifndef _VA_LIST_T_H -typedef __gnuc_va_list va_list; -#endif /* not _VA_LIST_T_H */ -#endif /* not _VA_LIST */ -#endif /* not _VA_LIST_DEFINED */ -#if !(defined (__BSD_NET2__) || defined (____386BSD____) || defined (__bsdi__) || defined (__sequent__) || defined (__FreeBSD__)) -#define _VA_LIST_ -#endif -#ifndef _VA_LIST -#define _VA_LIST -#endif -#ifndef _VA_LIST_DEFINED -#define _VA_LIST_DEFINED -#endif -#ifndef _VA_LIST_T_H -#define _VA_LIST_T_H -#endif - -#endif /* not _VA_LIST_, except on certain systems */ - -#endif /* not __svr4__ */ - -#endif /* _STDARG_H */ - -#endif /* not _ANSI_STDARG_H_ */ -#endif /* not _STDARG_H */ diff --git a/usr/lib/libc/stdio/CMakeLists.txt b/usr/lib/libc/stdio/CMakeLists.txt deleted file mode 100644 index b54fd7e4a..000000000 --- a/usr/lib/libc/stdio/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ - -target_sources(c - PRIVATE - printf.c - fprintf.c - sprintf.c - vprintf.c - vsprintf.c - vsnprintf.c - snprintf.c - stdin.c - stdout.c - stderr.c - getchar.c - putchar.c - vfprintf.c - putc.c - getc.c - puts.c - gets.c - scanf.c - vscanf.c - vfscanf.c - fopen.c - fread.c - fwrite.c - fclose.c - fgetc.c - fputc.c - fputs.c - fgets.c - fseek.c - ftell.c - fileno.c - perror.c - ofl_add.c - __stdio_exit.c - __stdio_write.c - __stdout_write.c - __stdio_close.c - __stdio_read.c - __stdio_seek.c - __uflow.c - __lockfile.c - __towrite.c - __toread.c - __fmodeflags.c - __fdopen.c - ofl.c - __overflow.c - fflush.c - sscanf.c - vsscanf.c - __string_read.c -) diff --git a/usr/lib/libc/stdio/__fclose_ca.c b/usr/lib/libc/stdio/__fclose_ca.c deleted file mode 100644 index e0b12a15a..000000000 --- a/usr/lib/libc/stdio/__fclose_ca.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int __fclose_ca(FILE *f) -{ - return f->close(f); -} diff --git a/usr/lib/libc/stdio/__fdopen.c b/usr/lib/libc/stdio/__fdopen.c deleted file mode 100644 index aa2467924..000000000 --- a/usr/lib/libc/stdio/__fdopen.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include -#include - -FILE *__fdopen(int fd, const char *mode) -{ - FILE *f; - struct winsize wsz; - - /* Check for valid initial mode character */ - if (!strchr("rwa", *mode)) { - errno = EINVAL; - return 0; - } - - /* Allocate FILE+buffer or fail */ - if (!(f=malloc(sizeof *f + UNGET + BUFSIZ))) return 0; - - /* Zero-fill only the struct, not the buffer */ - memset(f, 0, sizeof *f); - - /* Impose mode restrictions */ - if (!strchr(mode, '+')) f->flags = (*mode == 'r') ? F_NOWR : F_NORD; - - /* Apply close-on-exec flag */ - if (strchr(mode, 'e')) sys_fcntl(fd, F_SETFD, (void *) FD_CLOEXEC); -#if 0 - if (strchr(mode, 'e')) __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); -#endif - - /* Set append mode on fd if opened for append */ - if (*mode == 'a') { -#if 0 - int flags = __syscall(SYS_fcntl, fd, F_GETFL); -#endif - long flags = sys_fcntl(fd, F_GETFL, NULL); - - if (!(flags & O_APPEND)) -#if 0 - __syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND); -#endif - sys_fcntl(fd, F_SETFL, (void *) (flags | O_APPEND)); - - f->flags |= F_APP; - } - - f->fd = fd; - f->buf = (unsigned char *)f + sizeof *f + UNGET; - f->buf_size = BUFSIZ; - - /* Activate line buffered mode for terminals */ - f->lbf = EOF; -#if 0 - if (!(f->flags & F_NOWR) && !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz)) -#endif - if (!(f->flags & F_NOWR) && !sys_ioctl(fd, TIOCGWINSZ, &wsz)) - f->lbf = '\n'; - - /* Initialize op ptrs. No problem if some are unneeded. */ - f->read = __stdio_read; - f->write = __stdio_write; - f->seek = __stdio_seek; - f->close = __stdio_close; - -#if 0 - if (!libc.threaded) f->lock = -1; -#endif - - /* Add new FILE to open file list */ - return __ofl_add(f); -} - -weak_alias(__fdopen, fdopen); diff --git a/usr/lib/libc/stdio/__fmodeflags.c b/usr/lib/libc/stdio/__fmodeflags.c deleted file mode 100644 index da9f23b63..000000000 --- a/usr/lib/libc/stdio/__fmodeflags.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -int __fmodeflags(const char *mode) -{ - int flags; - if (strchr(mode, '+')) flags = O_RDWR; - else if (*mode == 'r') flags = O_RDONLY; - else flags = O_WRONLY; - if (strchr(mode, 'x')) flags |= O_EXCL; - if (strchr(mode, 'e')) flags |= O_CLOEXEC; - if (*mode != 'r') flags |= O_CREAT; - if (*mode == 'w') flags |= O_TRUNC; - if (*mode == 'a') flags |= O_APPEND; - return flags; -} diff --git a/usr/lib/libc/stdio/__fopen_rb_ca.c b/usr/lib/libc/stdio/__fopen_rb_ca.c deleted file mode 100644 index 183a5d553..000000000 --- a/usr/lib/libc/stdio/__fopen_rb_ca.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "stdio_impl.h" -#include -#include - -FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t len) -{ - memset(f, 0, sizeof *f); - - f->fd = sys_open(filename, O_RDONLY|O_CLOEXEC); - if (f->fd < 0) return 0; - __syscall(SYS_fcntl, f->fd, F_SETFD, FD_CLOEXEC); - - f->flags = F_NOWR | F_PERM; - f->buf = buf + UNGET; - f->buf_size = len - UNGET; - f->read = __stdio_read; - f->seek = __stdio_seek; - f->close = __stdio_close; - f->lock = -1; - - return f; -} diff --git a/usr/lib/libc/stdio/__lockfile.c b/usr/lib/libc/stdio/__lockfile.c deleted file mode 100644 index 6910d2872..000000000 --- a/usr/lib/libc/stdio/__lockfile.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -int __lockfile(FILE *f) -{ -#if 0 - int owner, tid = __pthread_self()->tid; - if (f->lock == tid) - return 0; - while ((owner = a_cas(&f->lock, 0, tid))) - __wait(&f->lock, &f->waiters, owner, 1); -#endif - mutex_lock((f == stdin) ? 0 : 1); - - return 1; -} - -void __unlockfile(FILE *f) -{ -#if 0 - a_store(&f->lock, 0); - - /* The following read is technically invalid under situations - * of self-synchronized destruction. Another thread may have - * called fclose as soon as the above store has completed. - * Nonetheless, since FILE objects always live in memory - * obtained by malloc from the heap, it's safe to assume - * the dereferences below will not fault. In the worst case, - * a spurious syscall will be made. If the implementation of - * malloc changes, this assumption needs revisiting. */ - - if (f->waiters) __wake(&f->lock, 1, 1); -#endif - mutex_unlock((f == stdin) ? 0 : 1); -} diff --git a/usr/lib/libc/stdio/__overflow.c b/usr/lib/libc/stdio/__overflow.c deleted file mode 100644 index 3bb37923a..000000000 --- a/usr/lib/libc/stdio/__overflow.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" - -int __overflow(FILE *f, int _c) -{ - unsigned char c = _c; - if (!f->wend && __towrite(f)) return EOF; - if (f->wpos < f->wend && c != f->lbf) return *f->wpos++ = c; - if (f->write(f, &c, 1)!=1) return EOF; - return c; -} diff --git a/usr/lib/libc/stdio/__stdio_close.c b/usr/lib/libc/stdio/__stdio_close.c deleted file mode 100644 index 328a43cd0..000000000 --- a/usr/lib/libc/stdio/__stdio_close.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -static int dummy(int fd) -{ - return fd; -} -weak_alias(dummy, __aio_close); - -int __stdio_close(FILE *f) -{ -#if 0 - return syscall(SYS_close, __aio_close(f->fd)); -#endif - return __syscall_ret(sys_close(__aio_close(f->fd))); -} diff --git a/usr/lib/libc/stdio/__stdio_exit.c b/usr/lib/libc/stdio/__stdio_exit.c deleted file mode 100644 index 191b4454a..000000000 --- a/usr/lib/libc/stdio/__stdio_exit.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "stdio_impl.h" - -static FILE *volatile dummy_file = 0; -weak_alias(dummy_file, __stdin_used); -weak_alias(dummy_file, __stdout_used); -weak_alias(dummy_file, __stderr_used); - -static void close_file(FILE *f) -{ - if (!f) return; - FFINALLOCK(f); - if (f->wpos > f->wbase) f->write(f, 0, 0); - if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR); -} - -void __stdio_exit(void) -{ - FILE *f; - for (f=*__ofl_lock(); f; f=f->next) close_file(f); - close_file(__stdin_used); - close_file(__stdout_used); -} - -weak_alias(__stdio_exit, __stdio_exit_needed); diff --git a/usr/lib/libc/stdio/__stdio_read.c b/usr/lib/libc/stdio/__stdio_read.c deleted file mode 100644 index 1a9a9e0d0..000000000 --- a/usr/lib/libc/stdio/__stdio_read.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include - -size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) -{ -#if 0 - struct iovec iov[2] = { - { .iov_base = buf, .iov_len = len - !!f->buf_size }, - { .iov_base = f->buf, .iov_len = f->buf_size } - }; - ssize_t cnt; - - - cnt = syscall(SYS_readv, f->fd, iov, 2); -#endif - - len = __syscall_ret(sys_read(f->fd, buf, len)); - -#if 0 - if (cnt <= 0) { - f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt); - return cnt; - } - if (cnt <= iov[0].iov_len) return cnt; - cnt -= iov[0].iov_len; - f->rpos = f->buf; - f->rend = f->buf + cnt; - if (f->buf_size) buf[len-1] = *f->rpos++; - -#endif - return len; -} diff --git a/usr/lib/libc/stdio/__stdio_seek.c b/usr/lib/libc/stdio/__stdio_seek.c deleted file mode 100644 index f61a8423f..000000000 --- a/usr/lib/libc/stdio/__stdio_seek.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -off_t __stdio_seek(FILE *f, off_t off, int whence) -{ - - off_t ret; - -#ifdef SYS__llseek - if (syscall(SYS__llseek, f->fd, off>>32, off, &ret, whence)<0) - ret = -1; -#else - ret = __syscall_ret(sys_lseek(f->fd, off, whence)); -#if 0 - ret = syscall(SYS_lseek, f->fd, off, whence); -#endif -#endif - - return ret; - - return 0; -} diff --git a/usr/lib/libc/stdio/__stdio_write.c b/usr/lib/libc/stdio/__stdio_write.c deleted file mode 100644 index f820844f4..000000000 --- a/usr/lib/libc/stdio/__stdio_write.c +++ /dev/null @@ -1,47 +0,0 @@ -#include - -#include -#include - -size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) -{ - struct iovec iovs[2] = { - { .iov_base = f->wbase, .iov_len = f->wpos-f->wbase }, - { .iov_base = (void *)buf, .iov_len = len } - }; - struct iovec *iov = iovs; - size_t rem = iov[0].iov_len + iov[1].iov_len; - int iovcnt = 2; - ssize_t cnt; - - for (;;) { - -#if 0 - cnt = syscall(SYS_writev, f->fd, iov, iovcnt); -#endif - cnt = 0; - - if (iov[0].iov_len > 0) - cnt += sys_write(f->fd, iov[0].iov_base, iov[0].iov_len); - if (iov[1].iov_len > 0) - cnt += sys_write(f->fd, iov[1].iov_base, iov[1].iov_len); - - if (cnt == rem) { - f->wend = f->buf + f->buf_size; - f->wpos = f->wbase = f->buf; - return len; - } - if (cnt < 0) { - f->wpos = f->wbase = f->wend = 0; - f->flags |= F_ERR; - return iovcnt == 2 ? 0 : len-iov[0].iov_len; - } - rem -= cnt; - if (cnt > iov[0].iov_len) { - cnt -= iov[0].iov_len; - iov++; iovcnt--; - } - iov[0].iov_base = (char *)iov[0].iov_base + cnt; - iov[0].iov_len -= cnt; - } -} diff --git a/usr/lib/libc/stdio/__stdout_write.c b/usr/lib/libc/stdio/__stdout_write.c deleted file mode 100644 index e6e48421c..000000000 --- a/usr/lib/libc/stdio/__stdout_write.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - - -size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len) -{ -#if 0 - struct winsize wsz; -#endif - - f->write = __stdio_write; - -#if 0 - if (!(f->flags & F_SVB) && __syscall(SYS_ioctl, f->fd, TIOCGWINSZ, &wsz)) - f->lbf = -1; -#endif - - return __stdio_write(f, buf, len); -} diff --git a/usr/lib/libc/stdio/__string_read.c b/usr/lib/libc/stdio/__string_read.c deleted file mode 100644 index 53cb31749..000000000 --- a/usr/lib/libc/stdio/__string_read.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -size_t __string_read(FILE *f, unsigned char *buf, size_t len) -{ - char *src = f->cookie; - size_t k = len+256; - char *end = memchr(src, 0, k); - if (end) k = end-src; - if (k < len) len = k; - memcpy(buf, src, len); - f->rpos = (void *)(src+len); - f->rend = (void *)(src+k); - f->cookie = src+k; - return len; -} diff --git a/usr/lib/libc/stdio/__toread.c b/usr/lib/libc/stdio/__toread.c deleted file mode 100644 index 35f67b8f8..000000000 --- a/usr/lib/libc/stdio/__toread.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -int __toread(FILE *f) -{ - f->mode |= f->mode-1; - if (f->wpos > f->wbase) f->write(f, 0, 0); - f->wpos = f->wbase = f->wend = 0; - if (f->flags & F_NORD) { - f->flags |= F_ERR; - return EOF; - } - f->rpos = f->rend = f->buf + f->buf_size; - return (f->flags & F_EOF) ? EOF : 0; -} - -void __stdio_exit_needed(void); - -void __toread_needs_stdio_exit() -{ - __stdio_exit_needed(); -} diff --git a/usr/lib/libc/stdio/__towrite.c b/usr/lib/libc/stdio/__towrite.c deleted file mode 100644 index 0a69d926d..000000000 --- a/usr/lib/libc/stdio/__towrite.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "stdio_impl.h" - -int __towrite(FILE *f) -{ - f->mode |= f->mode-1; - if (f->flags & (F_NOWR)) { - f->flags |= F_ERR; - return EOF; - } - /* Clear read buffer (easier than summoning nasal demons) */ - f->rpos = f->rend = 0; - - /* Activate write through the buffer. */ - f->wpos = f->wbase = f->buf; - f->wend = f->buf + f->buf_size; - - return 0; -} - -void __stdio_exit_needed(void); - -void __towrite_needs_stdio_exit() -{ - __stdio_exit_needed(); -} diff --git a/usr/lib/libc/stdio/__uflow.c b/usr/lib/libc/stdio/__uflow.c deleted file mode 100644 index 2270aa3ab..000000000 --- a/usr/lib/libc/stdio/__uflow.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -/* This function assumes it will never be called if there is already - * data buffered for reading. */ - -int __uflow(FILE *f) -{ - unsigned char c; - if (!__toread(f) && f->read(f, &c, 1)==1) return c; - return EOF; -} diff --git a/usr/lib/libc/stdio/asprintf.c b/usr/lib/libc/stdio/asprintf.c deleted file mode 100644 index 4ec83534e..000000000 --- a/usr/lib/libc/stdio/asprintf.c +++ /dev/null @@ -1,13 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -int asprintf(char **s, const char *fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vasprintf(s, fmt, ap); - va_end(ap); - return ret; -} diff --git a/usr/lib/libc/stdio/clearerr.c b/usr/lib/libc/stdio/clearerr.c deleted file mode 100644 index 3bf94d307..000000000 --- a/usr/lib/libc/stdio/clearerr.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" - -void clearerr(FILE *f) -{ - FLOCK(f); - f->flags &= ~(F_EOF|F_ERR); - FUNLOCK(f); -} - -weak_alias(clearerr, clearerr_unlocked); diff --git a/usr/lib/libc/stdio/dprintf.c b/usr/lib/libc/stdio/dprintf.c deleted file mode 100644 index 93082ee79..000000000 --- a/usr/lib/libc/stdio/dprintf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int dprintf(int fd, const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vdprintf(fd, fmt, ap); - va_end(ap); - return ret; -} diff --git a/usr/lib/libc/stdio/ext.c b/usr/lib/libc/stdio/ext.c deleted file mode 100644 index 1fd954901..000000000 --- a/usr/lib/libc/stdio/ext.c +++ /dev/null @@ -1,57 +0,0 @@ -#define _GNU_SOURCE -#include "stdio_impl.h" -#include - -void _flushlbf(void) -{ - fflush(0); -} - -int __fsetlocking(FILE *f, int type) -{ - return 0; -} - -int __fwriting(FILE *f) -{ - return (f->flags & F_NORD) || f->wend; -} - -int __freading(FILE *f) -{ - return (f->flags & F_NOWR) || f->rend; -} - -int __freadable(FILE *f) -{ - return !(f->flags & F_NORD); -} - -int __fwritable(FILE *f) -{ - return !(f->flags & F_NOWR); -} - -int __flbf(FILE *f) -{ - return f->lbf >= 0; -} - -size_t __fbufsize(FILE *f) -{ - return f->buf_size; -} - -size_t __fpending(FILE *f) -{ - return f->wend ? f->wpos - f->wbase : 0; -} - -int __fpurge(FILE *f) -{ - f->wpos = f->wbase = f->wend = 0; - f->rpos = f->rend = 0; - return 0; -} - -weak_alias(__fpurge, fpurge); diff --git a/usr/lib/libc/stdio/ext2.c b/usr/lib/libc/stdio/ext2.c deleted file mode 100644 index f359be9af..000000000 --- a/usr/lib/libc/stdio/ext2.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "stdio_impl.h" - -size_t __freadahead(FILE *f) -{ - return f->rend - f->rpos; -} - -const char *__freadptr(FILE *f, size_t *sizep) -{ - size_t size = f->rend - f->rpos; - if (!size) return 0; - *sizep = size; - return (const char *)f->rpos; -} - -void __freadptrinc(FILE *f, size_t inc) -{ - f->rpos += inc; -} - -void __fseterr(FILE *f) -{ - f->flags |= F_ERR; -} diff --git a/usr/lib/libc/stdio/fclose.c b/usr/lib/libc/stdio/fclose.c deleted file mode 100644 index 5872c9159..000000000 --- a/usr/lib/libc/stdio/fclose.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "stdio_impl.h" -#include "libc.h" - -static void dummy(FILE *f) { } -weak_alias(dummy, __unlist_locked_file); - -int fclose(FILE *f) -{ - int r; - - FLOCK(f); - r = fflush(f); - r |= f->close(f); - FUNLOCK(f); - - /* Past this point, f is closed and any further explict access - * to it is undefined. However, it still exists as an entry in - * the open file list and possibly in the thread's locked files - * list, if it was closed while explicitly locked. Functions - * which process these lists must tolerate dead FILE objects - * (which necessarily have inactive buffer pointers) without - * producing any side effects. */ - - if (f->flags & F_PERM) return r; - - __unlist_locked_file(f); - - FILE **head = __ofl_lock(); - if (f->prev) f->prev->next = f->next; - if (f->next) f->next->prev = f->prev; - if (*head == f) *head = f->next; - __ofl_unlock(); - - free(f->getln_buf); - free(f); - - return r; -} diff --git a/usr/lib/libc/stdio/feof.c b/usr/lib/libc/stdio/feof.c deleted file mode 100644 index 56da6b917..000000000 --- a/usr/lib/libc/stdio/feof.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "stdio_impl.h" - -#undef feof - -int feof(FILE *f) -{ - FLOCK(f); - int ret = !!(f->flags & F_EOF); - FUNLOCK(f); - return ret; -} - -weak_alias(feof, feof_unlocked); -weak_alias(feof, _IO_feof_unlocked); diff --git a/usr/lib/libc/stdio/ferror.c b/usr/lib/libc/stdio/ferror.c deleted file mode 100644 index d692eed94..000000000 --- a/usr/lib/libc/stdio/ferror.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "stdio_impl.h" - -#undef ferror - -int ferror(FILE *f) -{ - FLOCK(f); - int ret = !!(f->flags & F_ERR); - FUNLOCK(f); - return ret; -} - -weak_alias(ferror, ferror_unlocked); -weak_alias(ferror, _IO_ferror_unlocked); diff --git a/usr/lib/libc/stdio/fflush.c b/usr/lib/libc/stdio/fflush.c deleted file mode 100644 index c28810659..000000000 --- a/usr/lib/libc/stdio/fflush.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "stdio_impl.h" - -/* stdout.c will override this if linked */ -static FILE *volatile dummy = 0; -weak_alias(dummy, __stdout_used); - -int fflush(FILE *f) -{ - if (!f) { - int r = __stdout_used ? fflush(__stdout_used) : 0; - - for (f=*__ofl_lock(); f; f=f->next) - if (f->wpos > f->wbase) r |= fflush(f); - __ofl_unlock(); - - return r; - } - - FLOCK(f); - - /* If writing, flush output */ - if (f->wpos > f->wbase) { - f->write(f, 0, 0); - if (!f->wpos) { - FUNLOCK(f); - return EOF; - } - } - - /* If reading, sync position, per POSIX */ - if (f->rpos < f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR); - - /* Clear read and write modes */ - f->wpos = f->wbase = f->wend = 0; - f->rpos = f->rend = 0; - - FUNLOCK(f); - return 0; -} - -weak_alias(fflush, fflush_unlocked); diff --git a/usr/lib/libc/stdio/fgetc.c b/usr/lib/libc/stdio/fgetc.c deleted file mode 100644 index 29870dfe8..000000000 --- a/usr/lib/libc/stdio/fgetc.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include - -int fgetc(FILE *f) -{ - int c; - if (f->lock < 0 || !__lockfile(f)) - return getc_unlocked(f); - c = getc_unlocked(f); - __unlockfile(f); - return c; -} diff --git a/usr/lib/libc/stdio/fgetln.c b/usr/lib/libc/stdio/fgetln.c deleted file mode 100644 index afe12b5df..000000000 --- a/usr/lib/libc/stdio/fgetln.c +++ /dev/null @@ -1,21 +0,0 @@ -#define _GNU_SOURCE -#include "stdio_impl.h" -#include - -char *fgetln(FILE *f, size_t *plen) -{ - char *ret = 0, *z; - ssize_t l; - FLOCK(f); - ungetc(getc_unlocked(f), f); - if ((z=memchr(f->rpos, '\n', f->rend - f->rpos))) { - ret = (char *)f->rpos; - *plen = ++z - ret; - f->rpos = (void *)z; - } else if ((l = getline(&f->getln_buf, (size_t[]){0}, f)) > 0) { - *plen = l; - ret = f->getln_buf; - } - FUNLOCK(f); - return ret; -} diff --git a/usr/lib/libc/stdio/fgetpos.c b/usr/lib/libc/stdio/fgetpos.c deleted file mode 100644 index c3fa0eb0a..000000000 --- a/usr/lib/libc/stdio/fgetpos.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "stdio_impl.h" - -int fgetpos(FILE *restrict f, fpos_t *restrict pos) -{ - off_t off = __ftello(f); - if (off < 0) return -1; - *(off_t *)pos = off; - return 0; -} - -LFS64(fgetpos); diff --git a/usr/lib/libc/stdio/fgets.c b/usr/lib/libc/stdio/fgets.c deleted file mode 100644 index af33a7b69..000000000 --- a/usr/lib/libc/stdio/fgets.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -char *fgets(char *restrict s, int n, FILE *restrict f) -{ - char *p = s; - unsigned char *z; - size_t k; - int c; - - FLOCK(f); - - if (n--<=1) { - f->mode |= f->mode-1; - FUNLOCK(f); - if (n) return 0; - *s = 0; - return s; - } - - while (n) { - z = memchr(f->rpos, '\n', f->rend - f->rpos); - k = z ? z - f->rpos + 1 : f->rend - f->rpos; - k = MIN(k, n); - memcpy(p, f->rpos, k); - f->rpos += k; - p += k; - n -= k; - if (z || !n) break; - if ((c = getc_unlocked(f)) < 0) { - if (p==s || !feof(f)) s = 0; - break; - } - - /* (SO3) Immediately return the echo */ - if (f == stdin) { - if ((c == '\n') || (c == '\r')) - putchar('\n'); - else if (c == 127) { /* Delete */ - if (p != s) { /* Start of line ? */ - printf("\b \b"); - fflush(stdout); - p--; - n++; - } - continue; - } else if (c == 3) { /* ctrl/c handling */ - *s = 0; - printf("^C\n"); - return s; - } else - putchar(c); - } - n--; - - if (((*p = c) == '\n') || ((*p = c) == '\r')) break; - p++; - } - if (s) *p = 0; - - FUNLOCK(f); - - return s; -} - -weak_alias(fgets, fgets_unlocked); diff --git a/usr/lib/libc/stdio/fgetwc.c b/usr/lib/libc/stdio/fgetwc.c deleted file mode 100644 index e455cfec4..000000000 --- a/usr/lib/libc/stdio/fgetwc.c +++ /dev/null @@ -1,61 +0,0 @@ -#include "stdio_impl.h" -#include "locale_impl.h" -#include -#include - -static wint_t __fgetwc_unlocked_internal(FILE *f) -{ - mbstate_t st = { 0 }; - wchar_t wc; - int c; - unsigned char b; - size_t l; - - /* Convert character from buffer if possible */ - if (f->rpos < f->rend) { - l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st); - if (l+2 >= 2) { - f->rpos += l + !l; /* l==0 means 1 byte, null */ - return wc; - } - if (l == -1) { - f->rpos++; - return WEOF; - } - } else l = -2; - - /* Convert character byte-by-byte */ - while (l == -2) { - b = c = getc_unlocked(f); - if (c < 0) { - if (!mbsinit(&st)) errno = EILSEQ; - return WEOF; - } - l = mbrtowc(&wc, (void *)&b, 1, &st); - if (l == -1) return WEOF; - } - - return wc; -} - -wint_t __fgetwc_unlocked(FILE *f) -{ - locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; - if (f->mode <= 0) fwide(f, 1); - *ploc = f->locale; - wchar_t wc = __fgetwc_unlocked_internal(f); - *ploc = loc; - return wc; -} - -wint_t fgetwc(FILE *f) -{ - wint_t c; - FLOCK(f); - c = __fgetwc_unlocked(f); - FUNLOCK(f); - return c; -} - -weak_alias(__fgetwc_unlocked, fgetwc_unlocked); -weak_alias(__fgetwc_unlocked, getwc_unlocked); diff --git a/usr/lib/libc/stdio/fgetws.c b/usr/lib/libc/stdio/fgetws.c deleted file mode 100644 index 195cb4355..000000000 --- a/usr/lib/libc/stdio/fgetws.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "stdio_impl.h" -#include - -wint_t __fgetwc_unlocked(FILE *); - -wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) -{ - wchar_t *p = s; - - if (!n--) return s; - - FLOCK(f); - - for (; n; n--) { - wint_t c = __fgetwc_unlocked(f); - if (c == WEOF) break; - *p++ = c; - if (c == '\n') break; - } - *p = 0; - if (ferror(f)) p = s; - - FUNLOCK(f); - - return (p == s) ? NULL : s; -} - -weak_alias(fgetws, fgetws_unlocked); diff --git a/usr/lib/libc/stdio/fileno.c b/usr/lib/libc/stdio/fileno.c deleted file mode 100644 index ba7f9391b..000000000 --- a/usr/lib/libc/stdio/fileno.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" - -int fileno(FILE *f) -{ - /* f->fd never changes, but the lock must be obtained and released - * anyway since this function cannot return while another thread - * holds the lock. */ - FLOCK(f); - FUNLOCK(f); - return f->fd; -} - -weak_alias(fileno, fileno_unlocked); diff --git a/usr/lib/libc/stdio/flockfile.c b/usr/lib/libc/stdio/flockfile.c deleted file mode 100644 index a196c1efe..000000000 --- a/usr/lib/libc/stdio/flockfile.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" -#include "pthread_impl.h" - -void flockfile(FILE *f) -{ - while (ftrylockfile(f)) { - int owner = f->lock; - if (owner) __wait(&f->lock, &f->waiters, owner, 1); - } -} diff --git a/usr/lib/libc/stdio/fmemopen.c b/usr/lib/libc/stdio/fmemopen.c deleted file mode 100644 index 7c193a579..000000000 --- a/usr/lib/libc/stdio/fmemopen.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include - -struct cookie { - size_t pos, len, size; - unsigned char *buf; - int mode; -}; - -static off_t mseek(FILE *f, off_t off, int whence) -{ - ssize_t base; - struct cookie *c = f->cookie; - if (whence>2U) { -fail: - errno = EINVAL; - return -1; - } - base = (size_t [3]){0, c->pos, c->len}[whence]; - if (off < -base || off > (ssize_t)c->size-base) goto fail; - return c->pos = base+off; -} - -static size_t mread(FILE *f, unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t rem = c->len - c->pos; - if (c->pos > c->len) rem = 0; - if (len > rem) { - len = rem; - f->flags |= F_EOF; - } - memcpy(buf, c->buf+c->pos, len); - c->pos += len; - rem -= len; - if (rem > f->buf_size) rem = f->buf_size; - f->rpos = f->buf; - f->rend = f->buf + rem; - memcpy(f->rpos, c->buf+c->pos, rem); - c->pos += rem; - return len; -} - -static size_t mwrite(FILE *f, const unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t rem; - size_t len2 = f->wpos - f->wbase; - if (len2) { - f->wpos = f->wbase; - if (mwrite(f, f->wpos, len2) < len2) return 0; - } - if (c->mode == 'a') c->pos = c->len; - rem = c->size - c->pos; - if (len > rem) len = rem; - memcpy(c->buf+c->pos, buf, len); - c->pos += len; - if (c->pos > c->len) { - c->len = c->pos; - if (c->len < c->size) c->buf[c->len] = 0; - else if ((f->flags&F_NORD) && c->size) c->buf[c->size-1] = 0; - } - return len; -} - -static int mclose(FILE *m) -{ - return 0; -} - -FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode) -{ - FILE *f; - struct cookie *c; - int plus = !!strchr(mode, '+'); - - if (!size || !strchr("rwa", *mode)) { - errno = EINVAL; - return 0; - } - - if (!buf && size > SIZE_MAX-sizeof(FILE)-BUFSIZ-UNGET) { - errno = ENOMEM; - return 0; - } - - f = calloc(sizeof *f + sizeof *c + UNGET + BUFSIZ + (buf?0:size), 1); - if (!f) return 0; - f->cookie = c = (void *)(f+1); - f->fd = -1; - f->lbf = EOF; - f->buf = (unsigned char *)(c+1) + UNGET; - f->buf_size = BUFSIZ; - if (!buf) buf = f->buf + BUFSIZ; - - c->buf = buf; - c->size = size; - c->mode = *mode; - - if (!plus) f->flags = (*mode == 'r') ? F_NOWR : F_NORD; - if (*mode == 'r') c->len = size; - else if (*mode == 'a') c->len = c->pos = strnlen(buf, size); - - f->read = mread; - f->write = mwrite; - f->seek = mseek; - f->close = mclose; - - if (!libc.threaded) f->lock = -1; - - return __ofl_add(f); -} diff --git a/usr/lib/libc/stdio/fopen.c b/usr/lib/libc/stdio/fopen.c deleted file mode 100644 index 0abe9c9f5..000000000 --- a/usr/lib/libc/stdio/fopen.c +++ /dev/null @@ -1,44 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include - -FILE *fopen(const char *restrict filename, const char *restrict mode) -{ - FILE *f; - int fd; - int flags; - - /* Check for valid initial mode character */ - if (!strchr("rwa", *mode)) { - errno = EINVAL; - return 0; - } - - /* Compute the flags to pass to open() */ - flags = __fmodeflags(mode); - - fd = __syscall_ret(sys_open(filename, flags, 0666)); - if (fd < 0) return 0; - - - if (flags & O_CLOEXEC) -#if 0 - __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); -#endif - sys_fcntl(fd, F_SETFD, (void *) FD_CLOEXEC); - - f = __fdopen(fd, mode); - if (f) return f; - - sys_close(fd); -#if 0 - __syscall(SYS_close, fd); -#endif - return 0; -} - -#if 0 -LFS64(fopen); -#endif diff --git a/usr/lib/libc/stdio/fprintf.c b/usr/lib/libc/stdio/fprintf.c deleted file mode 100644 index 948743f7c..000000000 --- a/usr/lib/libc/stdio/fprintf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int fprintf(FILE *restrict f, const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfprintf(f, fmt, ap); - va_end(ap); - return ret; -} diff --git a/usr/lib/libc/stdio/fputc.c b/usr/lib/libc/stdio/fputc.c deleted file mode 100644 index 92762c98f..000000000 --- a/usr/lib/libc/stdio/fputc.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" - -int fputc(int c, FILE *f) -{ - if (f->lock < 0 || !__lockfile(f)) - return putc_unlocked(c, f); - c = putc_unlocked(c, f); - __unlockfile(f); - return c; -} diff --git a/usr/lib/libc/stdio/fputs.c b/usr/lib/libc/stdio/fputs.c deleted file mode 100644 index 1cf344f28..000000000 --- a/usr/lib/libc/stdio/fputs.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" -#include - -int fputs(const char *restrict s, FILE *restrict f) -{ - size_t l = strlen(s); - return (fwrite(s, 1, l, f)==l) - 1; -} - -weak_alias(fputs, fputs_unlocked); diff --git a/usr/lib/libc/stdio/fputwc.c b/usr/lib/libc/stdio/fputwc.c deleted file mode 100644 index 789fe9c90..000000000 --- a/usr/lib/libc/stdio/fputwc.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "stdio_impl.h" -#include "locale_impl.h" -#include -#include -#include - -wint_t __fputwc_unlocked(wchar_t c, FILE *f) -{ - char mbc[MB_LEN_MAX]; - int l; - locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; - - if (f->mode <= 0) fwide(f, 1); - *ploc = f->locale; - - if (isascii(c)) { - c = putc_unlocked(c, f); - } else if (f->wpos + MB_LEN_MAX < f->wend) { - l = wctomb((void *)f->wpos, c); - if (l < 0) c = WEOF; - else f->wpos += l; - } else { - l = wctomb(mbc, c); - if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF; - } - if (c==WEOF) f->flags |= F_ERR; - *ploc = loc; - return c; -} - -wint_t fputwc(wchar_t c, FILE *f) -{ - FLOCK(f); - c = __fputwc_unlocked(c, f); - FUNLOCK(f); - return c; -} - -weak_alias(__fputwc_unlocked, fputwc_unlocked); -weak_alias(__fputwc_unlocked, putwc_unlocked); diff --git a/usr/lib/libc/stdio/fputws.c b/usr/lib/libc/stdio/fputws.c deleted file mode 100644 index 0ed02f1c0..000000000 --- a/usr/lib/libc/stdio/fputws.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "stdio_impl.h" -#include "locale_impl.h" -#include - -int fputws(const wchar_t *restrict ws, FILE *restrict f) -{ - unsigned char buf[BUFSIZ]; - size_t l=0; - locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; - - FLOCK(f); - - fwide(f, 1); - *ploc = f->locale; - - while (ws && (l = wcsrtombs((void *)buf, (void*)&ws, sizeof buf, 0))+1 > 1) - if (__fwritex(buf, l, f) < l) { - FUNLOCK(f); - *ploc = loc; - return -1; - } - - FUNLOCK(f); - - *ploc = loc; - return l; /* 0 or -1 */ -} - -weak_alias(fputws, fputws_unlocked); diff --git a/usr/lib/libc/stdio/fread.c b/usr/lib/libc/stdio/fread.c deleted file mode 100644 index aef75f737..000000000 --- a/usr/lib/libc/stdio/fread.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "stdio_impl.h" -#include - -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f) -{ - unsigned char *dest = destv; - size_t len = size*nmemb, l = len, k; - if (!size) nmemb = 0; - - FLOCK(f); - - f->mode |= f->mode-1; - - if (f->rend - f->rpos > 0) { - /* First exhaust the buffer. */ - k = MIN(f->rend - f->rpos, l); - memcpy(dest, f->rpos, k); - f->rpos += k; - dest += k; - l -= k; - } - - /* Read the remainder directly */ - for (; l; l-=k, dest+=k) { - k = __toread(f) ? 0 : f->read(f, dest, l); - if (k+1<=1) { - FUNLOCK(f); - return (len-l)/size; - } - } - - FUNLOCK(f); - return nmemb; -} - -weak_alias(fread, fread_unlocked); diff --git a/usr/lib/libc/stdio/freopen.c b/usr/lib/libc/stdio/freopen.c deleted file mode 100644 index 6c1b575f5..000000000 --- a/usr/lib/libc/stdio/freopen.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "stdio_impl.h" -#include - -/* The basic idea of this implementation is to open a new FILE, - * hack the necessary parts of the new FILE into the old one, then - * close the new FILE. */ - -/* Locking IS necessary because another thread may provably hold the - * lock, via flockfile or otherwise, when freopen is called, and in that - * case, freopen cannot act until the lock is released. */ - -int __dup3(int, int, int); - -FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *restrict f) -{ - int fl = __fmodeflags(mode); - FILE *f2; - - FLOCK(f); - - fflush(f); - - if (!filename) { - if (fl&O_CLOEXEC) - __syscall(SYS_fcntl, f->fd, F_SETFD, FD_CLOEXEC); - fl &= ~(O_CREAT|O_EXCL|O_CLOEXEC); - if (syscall(SYS_fcntl, f->fd, F_SETFL, fl) < 0) - goto fail; - } else { - f2 = fopen(filename, mode); - if (!f2) goto fail; - if (f2->fd == f->fd) f2->fd = -1; /* avoid closing in fclose */ - else if (__dup3(f2->fd, f->fd, fl&O_CLOEXEC)<0) goto fail2; - - f->flags = (f->flags & F_PERM) | f2->flags; - f->read = f2->read; - f->write = f2->write; - f->seek = f2->seek; - f->close = f2->close; - - fclose(f2); - } - - FUNLOCK(f); - return f; - -fail2: - fclose(f2); -fail: - fclose(f); - return NULL; -} - -LFS64(freopen); diff --git a/usr/lib/libc/stdio/fscanf.c b/usr/lib/libc/stdio/fscanf.c deleted file mode 100644 index acb8a106c..000000000 --- a/usr/lib/libc/stdio/fscanf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include "libc.h" - -int fscanf(FILE *restrict f, const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfscanf(f, fmt, ap); - va_end(ap); - return ret; -} - -weak_alias(fscanf, __isoc99_fscanf); diff --git a/usr/lib/libc/stdio/fseek.c b/usr/lib/libc/stdio/fseek.c deleted file mode 100644 index 1d1bc0148..000000000 --- a/usr/lib/libc/stdio/fseek.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "stdio_impl.h" - -int __fseeko_unlocked(FILE *f, off_t off, int whence) -{ - /* Adjust relative offset for unread data in buffer, if any. */ - if (whence == SEEK_CUR) off -= f->rend - f->rpos; - - /* Flush write buffer, and report error on failure. */ - if (f->wpos > f->wbase) { - f->write(f, 0, 0); - if (!f->wpos) return -1; - } - - /* Leave writing mode */ - f->wpos = f->wbase = f->wend = 0; - - /* Perform the underlying seek. */ - if (f->seek(f, off, whence) < 0) return -1; - - /* If seek succeeded, file is seekable and we discard read buffer. */ - f->rpos = f->rend = 0; - f->flags &= ~F_EOF; - - return 0; -} - -int __fseeko(FILE *f, off_t off, int whence) -{ - int result; - FLOCK(f); - result = __fseeko_unlocked(f, off, whence); - FUNLOCK(f); - return result; -} - -int fseek(FILE *f, long off, int whence) -{ - return __fseeko(f, off, whence); -} - -weak_alias(__fseeko, fseeko); - -#if 0 -LFS64(fseeko); -#endif diff --git a/usr/lib/libc/stdio/fsetpos.c b/usr/lib/libc/stdio/fsetpos.c deleted file mode 100644 index 5d76c8cd5..000000000 --- a/usr/lib/libc/stdio/fsetpos.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -int fsetpos(FILE *f, const fpos_t *pos) -{ - return __fseeko(f, *(const off_t *)pos, SEEK_SET); -} - -LFS64(fsetpos); diff --git a/usr/lib/libc/stdio/ftell.c b/usr/lib/libc/stdio/ftell.c deleted file mode 100644 index f443580c3..000000000 --- a/usr/lib/libc/stdio/ftell.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "stdio_impl.h" -#include -#include - -off_t __ftello_unlocked(FILE *f) -{ - off_t pos = f->seek(f, 0, - (f->flags & F_APP) && f->wpos > f->wbase - ? SEEK_END : SEEK_CUR); - if (pos < 0) return pos; - - /* Adjust for data in buffer. */ - return pos - (f->rend - f->rpos) + (f->wpos - f->wbase); -} - -off_t __ftello(FILE *f) -{ - off_t pos; - FLOCK(f); - pos = __ftello_unlocked(f); - FUNLOCK(f); - return pos; -} - -long ftell(FILE *f) -{ - off_t pos = __ftello(f); - if (pos > LONG_MAX) { - errno = EOVERFLOW; - return -1; - } - return pos; -} - -weak_alias(__ftello, ftello); - -#if 0 -LFS64(ftello); -#endif diff --git a/usr/lib/libc/stdio/ftrylockfile.c b/usr/lib/libc/stdio/ftrylockfile.c deleted file mode 100644 index eb13c839b..000000000 --- a/usr/lib/libc/stdio/ftrylockfile.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "stdio_impl.h" -#include "pthread_impl.h" -#include - -void __do_orphaned_stdio_locks() -{ - FILE *f; - for (f=__pthread_self()->stdio_locks; f; f=f->next_locked) - a_store(&f->lock, 0x40000000); -} - -void __unlist_locked_file(FILE *f) -{ - if (f->lockcount) { - if (f->next_locked) f->next_locked->prev_locked = f->prev_locked; - if (f->prev_locked) f->prev_locked->next_locked = f->next_locked; - else __pthread_self()->stdio_locks = f->next_locked; - } -} - -int ftrylockfile(FILE *f) -{ - pthread_t self = __pthread_self(); - int tid = self->tid; - if (f->lock == tid) { - if (f->lockcount == LONG_MAX) - return -1; - f->lockcount++; - return 0; - } - if (f->lock < 0) f->lock = 0; - if (f->lock || a_cas(&f->lock, 0, tid)) - return -1; - f->lockcount = 1; - f->prev_locked = 0; - f->next_locked = self->stdio_locks; - if (f->next_locked) f->next_locked->prev_locked = f; - self->stdio_locks = f; - return 0; -} diff --git a/usr/lib/libc/stdio/funlockfile.c b/usr/lib/libc/stdio/funlockfile.c deleted file mode 100644 index 30a07ef4b..000000000 --- a/usr/lib/libc/stdio/funlockfile.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "stdio_impl.h" -#include "pthread_impl.h" - -void __unlist_locked_file(FILE *); - -void funlockfile(FILE *f) -{ - if (f->lockcount == 1) { - __unlist_locked_file(f); - f->lockcount = 0; - __unlockfile(f); - } else { - f->lockcount--; - } -} diff --git a/usr/lib/libc/stdio/fwide.c b/usr/lib/libc/stdio/fwide.c deleted file mode 100644 index 8410b1530..000000000 --- a/usr/lib/libc/stdio/fwide.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "stdio_impl.h" -#include "locale_impl.h" - -int fwide(FILE *f, int mode) -{ - FLOCK(f); - if (mode) { - if (!f->locale) f->locale = MB_CUR_MAX==1 - ? C_LOCALE : UTF8_LOCALE; - if (!f->mode) f->mode = mode>0 ? 1 : -1; - } - mode = f->mode; - FUNLOCK(f); - return mode; -} diff --git a/usr/lib/libc/stdio/fwprintf.c b/usr/lib/libc/stdio/fwprintf.c deleted file mode 100644 index 9ce4f0102..000000000 --- a/usr/lib/libc/stdio/fwprintf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include - -int fwprintf(FILE *restrict f, const wchar_t *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfwprintf(f, fmt, ap); - va_end(ap); - return ret; -} diff --git a/usr/lib/libc/stdio/fwrite.c b/usr/lib/libc/stdio/fwrite.c deleted file mode 100644 index 6f3432919..000000000 --- a/usr/lib/libc/stdio/fwrite.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "stdio_impl.h" -#include -#include - -size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) -{ - size_t i=0; - - if (!f->wend && __towrite(f)) return 0; - - if (l > f->wend - f->wpos) return f->write(f, s, l); - - if (f->lbf >= 0) { - /* Match /^(.*\n|)/ */ - for (i=l; i && s[i-1] != '\n'; i--); - if (i) { - size_t n = f->write(f, s, i); - if (n < i) return n; - s += i; - l -= i; - } - } - - memcpy(f->wpos, s, l); - f->wpos += l; - return l+i; -} - -size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f) -{ - size_t k, l = size*nmemb; - if (!size) nmemb = 0; - FLOCK(f); - k = __fwritex(src, l, f); - FUNLOCK(f); - return k==l ? nmemb : k/size; -} - -weak_alias(fwrite, fwrite_unlocked); diff --git a/usr/lib/libc/stdio/fwscanf.c b/usr/lib/libc/stdio/fwscanf.c deleted file mode 100644 index cb114b39f..000000000 --- a/usr/lib/libc/stdio/fwscanf.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -#include "libc.h" - -int fwscanf(FILE *restrict f, const wchar_t *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfwscanf(f, fmt, ap); - va_end(ap); - return ret; -} - -weak_alias(fwscanf,__isoc99_fwscanf); diff --git a/usr/lib/libc/stdio/getc.c b/usr/lib/libc/stdio/getc.c deleted file mode 100644 index b3f351d1d..000000000 --- a/usr/lib/libc/stdio/getc.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" - -int getc(FILE *f) -{ - int c; - if (f->lock < 0 || !__lockfile(f)) - return getc_unlocked(f); - c = getc_unlocked(f); - __unlockfile(f); - return c; -} - -weak_alias(getc, _IO_getc); diff --git a/usr/lib/libc/stdio/getc_unlocked.c b/usr/lib/libc/stdio/getc_unlocked.c deleted file mode 100644 index b38dad167..000000000 --- a/usr/lib/libc/stdio/getc_unlocked.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "stdio_impl.h" - -int (getc_unlocked)(FILE *f) -{ - return getc_unlocked(f); -} - -weak_alias (getc_unlocked, fgetc_unlocked); -weak_alias (getc_unlocked, _IO_getc_unlocked); diff --git a/usr/lib/libc/stdio/getchar.c b/usr/lib/libc/stdio/getchar.c deleted file mode 100644 index c10126581..000000000 --- a/usr/lib/libc/stdio/getchar.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int getchar(void) -{ - return fgetc(stdin); -} diff --git a/usr/lib/libc/stdio/getchar_unlocked.c b/usr/lib/libc/stdio/getchar_unlocked.c deleted file mode 100644 index 355ac318d..000000000 --- a/usr/lib/libc/stdio/getchar_unlocked.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int getchar_unlocked(void) -{ - return getc_unlocked(stdin); -} diff --git a/usr/lib/libc/stdio/getdelim.c b/usr/lib/libc/stdio/getdelim.c deleted file mode 100644 index 1ccd80292..000000000 --- a/usr/lib/libc/stdio/getdelim.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include - -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restrict f) -{ - char *tmp; - unsigned char *z; - size_t k; - size_t i=0; - int c; - - FLOCK(f); - - if (!n || !s) { - f->flags |= F_ERR; - FUNLOCK(f); - errno = EINVAL; - return -1; - } - - if (!*s) *n=0; - - for (;;) { - z = memchr(f->rpos, delim, f->rend - f->rpos); - k = z ? z - f->rpos + 1 : f->rend - f->rpos; - if (i+k+1 >= *n) { - if (k >= SIZE_MAX/2-i) goto oom; - size_t m = i+k+2; - if (!z && m < SIZE_MAX/4) m += m/2; - tmp = realloc(*s, m); - if (!tmp) { - m = i+k+2; - tmp = realloc(*s, m); - if (!tmp) goto oom; - } - *s = tmp; - *n = m; - } - memcpy(*s+i, f->rpos, k); - f->rpos += k; - i += k; - if (z) break; - if ((c = getc_unlocked(f)) == EOF) { - if (!i || !feof(f)) { - FUNLOCK(f); - return -1; - } - break; - } - if (((*s)[i++] = c) == delim) break; - } - (*s)[i] = 0; - - FUNLOCK(f); - - return i; -oom: - f->flags |= F_ERR; - FUNLOCK(f); - errno = ENOMEM; - return -1; -} - -weak_alias(getdelim, __getdelim); diff --git a/usr/lib/libc/stdio/getline.c b/usr/lib/libc/stdio/getline.c deleted file mode 100644 index 476d0b096..000000000 --- a/usr/lib/libc/stdio/getline.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -ssize_t getline(char **restrict s, size_t *restrict n, FILE *restrict f) -{ - return getdelim(s, n, '\n', f); -} diff --git a/usr/lib/libc/stdio/gets.c b/usr/lib/libc/stdio/gets.c deleted file mode 100644 index e1cc4d7d8..000000000 --- a/usr/lib/libc/stdio/gets.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "stdio_impl.h" -#include -#include - -char *gets(char *s) -{ - char *ret = fgets(s, INT_MAX, stdin); - if (ret && strlen(s) && s[strlen(s)-1] == '\n') s[strlen(s)-1] = 0; - return ret; -} diff --git a/usr/lib/libc/stdio/getw.c b/usr/lib/libc/stdio/getw.c deleted file mode 100644 index 73d2c0d5c..000000000 --- a/usr/lib/libc/stdio/getw.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _GNU_SOURCE -#include - -int getw(FILE *f) -{ - int x; - return fread(&x, sizeof x, 1, f) ? x : EOF; -} diff --git a/usr/lib/libc/stdio/getwc.c b/usr/lib/libc/stdio/getwc.c deleted file mode 100644 index a5008f0e5..000000000 --- a/usr/lib/libc/stdio/getwc.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "stdio_impl.h" -#include - -wint_t getwc(FILE *f) -{ - return fgetwc(f); -} diff --git a/usr/lib/libc/stdio/getwchar.c b/usr/lib/libc/stdio/getwchar.c deleted file mode 100644 index bd89e0ec9..000000000 --- a/usr/lib/libc/stdio/getwchar.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "stdio_impl.h" -#include - -wint_t getwchar(void) -{ - return fgetwc(stdin); -} - -weak_alias(getwchar, getwchar_unlocked); diff --git a/usr/lib/libc/stdio/ofl.c b/usr/lib/libc/stdio/ofl.c deleted file mode 100644 index b143999c2..000000000 --- a/usr/lib/libc/stdio/ofl.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "stdio_impl.h" -#include "libc.h" - -static FILE *ofl_head; -static volatile int ofl_lock[2]; - -FILE **__ofl_lock() -{ - LOCK(ofl_lock); - return &ofl_head; -} - -void __ofl_unlock() -{ - UNLOCK(ofl_lock); -} diff --git a/usr/lib/libc/stdio/ofl_add.c b/usr/lib/libc/stdio/ofl_add.c deleted file mode 100644 index d7de9f15a..000000000 --- a/usr/lib/libc/stdio/ofl_add.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "stdio_impl.h" - -FILE *__ofl_add(FILE *f) -{ - FILE **head = __ofl_lock(); - f->next = *head; - if (*head) (*head)->prev = f; - *head = f; - __ofl_unlock(); - return f; -} diff --git a/usr/lib/libc/stdio/open_memstream.c b/usr/lib/libc/stdio/open_memstream.c deleted file mode 100644 index eab024da6..000000000 --- a/usr/lib/libc/stdio/open_memstream.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include - -struct cookie { - char **bufp; - size_t *sizep; - size_t pos; - char *buf; - size_t len; - size_t space; -}; - -static off_t ms_seek(FILE *f, off_t off, int whence) -{ - ssize_t base; - struct cookie *c = f->cookie; - if (whence>2U) { -fail: - errno = EINVAL; - return -1; - } - base = (size_t [3]){0, c->pos, c->len}[whence]; - if (off < -base || off > SSIZE_MAX-base) goto fail; - return c->pos = base+off; -} - -static size_t ms_write(FILE *f, const unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t len2 = f->wpos - f->wbase; - char *newbuf; - if (len2) { - f->wpos = f->wbase; - if (ms_write(f, f->wbase, len2) < len2) return 0; - } - if (len + c->pos >= c->space) { - len2 = 2*c->space+1 | c->pos+len+1; - newbuf = realloc(c->buf, len2); - if (!newbuf) return 0; - *c->bufp = c->buf = newbuf; - memset(c->buf + c->space, 0, len2 - c->space); - c->space = len2; - } - memcpy(c->buf+c->pos, buf, len); - c->pos += len; - if (c->pos >= c->len) c->len = c->pos; - *c->sizep = c->pos; - return len; -} - -static int ms_close(FILE *f) -{ - return 0; -} - -FILE *open_memstream(char **bufp, size_t *sizep) -{ - FILE *f; - struct cookie *c; - char *buf; - - if (!(f=malloc(sizeof *f + sizeof *c + BUFSIZ))) return 0; - if (!(buf=malloc(sizeof *buf))) { - free(f); - return 0; - } - memset(f, 0, sizeof *f + sizeof *c); - f->cookie = c = (void *)(f+1); - - c->bufp = bufp; - c->sizep = sizep; - c->pos = c->len = c->space = *sizep = 0; - c->buf = *bufp = buf; - *buf = 0; - - f->flags = F_NORD; - f->fd = -1; - f->buf = (void *)(c+1); - f->buf_size = BUFSIZ; - f->lbf = EOF; - f->write = ms_write; - f->seek = ms_seek; - f->close = ms_close; - - if (!libc.threaded) f->lock = -1; - - return __ofl_add(f); -} diff --git a/usr/lib/libc/stdio/open_wmemstream.c b/usr/lib/libc/stdio/open_wmemstream.c deleted file mode 100644 index 4d90cd971..000000000 --- a/usr/lib/libc/stdio/open_wmemstream.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include - -struct cookie { - wchar_t **bufp; - size_t *sizep; - size_t pos; - wchar_t *buf; - size_t len; - size_t space; - mbstate_t mbs; -}; - -static off_t wms_seek(FILE *f, off_t off, int whence) -{ - ssize_t base; - struct cookie *c = f->cookie; - if (whence>2U) { -fail: - errno = EINVAL; - return -1; - } - base = (size_t [3]){0, c->pos, c->len}[whence]; - if (off < -base || off > SSIZE_MAX/4-base) goto fail; - memset(&c->mbs, 0, sizeof c->mbs); - return c->pos = base+off; -} - -static size_t wms_write(FILE *f, const unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t len2; - wchar_t *newbuf; - if (len + c->pos >= c->space) { - len2 = 2*c->space+1 | c->pos+len+1; - if (len2 > SSIZE_MAX/4) return 0; - newbuf = realloc(c->buf, len2*4); - if (!newbuf) return 0; - *c->bufp = c->buf = newbuf; - memset(c->buf + c->space, 0, 4*(len2 - c->space)); - c->space = len2; - } - - len2 = mbsnrtowcs(c->buf+c->pos, (void *)&buf, len, c->space-c->pos, &c->mbs); - if (len2 == -1) return 0; - c->pos += len2; - if (c->pos >= c->len) c->len = c->pos; - *c->sizep = c->pos; - return len; -} - -static int wms_close(FILE *f) -{ - return 0; -} - -FILE *open_wmemstream(wchar_t **bufp, size_t *sizep) -{ - FILE *f; - struct cookie *c; - wchar_t *buf; - - if (!(f=malloc(sizeof *f + sizeof *c))) return 0; - if (!(buf=malloc(sizeof *buf))) { - free(f); - return 0; - } - memset(f, 0, sizeof *f + sizeof *c); - f->cookie = c = (void *)(f+1); - - c->bufp = bufp; - c->sizep = sizep; - c->pos = c->len = c->space = *sizep = 0; - c->buf = *bufp = buf; - *buf = 0; - - f->flags = F_NORD; - f->fd = -1; - f->buf = (void *)(c+1); - f->buf_size = 0; - f->lbf = EOF; - f->write = wms_write; - f->seek = wms_seek; - f->close = wms_close; - - if (!libc.threaded) f->lock = -1; - - return __ofl_add(f); -} diff --git a/usr/lib/libc/stdio/pclose.c b/usr/lib/libc/stdio/pclose.c deleted file mode 100644 index 080a42624..000000000 --- a/usr/lib/libc/stdio/pclose.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" -#include -#include - -int pclose(FILE *f) -{ - int status, r; - pid_t pid = f->pipe_pid; - fclose(f); - while ((r=__syscall(SYS_wait4, pid, &status, 0, 0)) == -EINTR); - if (r<0) return __syscall_ret(r); - return status; -} diff --git a/usr/lib/libc/stdio/perror.c b/usr/lib/libc/stdio/perror.c deleted file mode 100644 index fdcb4d71c..000000000 --- a/usr/lib/libc/stdio/perror.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include "stdio_impl.h" - -void perror(const char *msg) -{ - FILE *f = stderr; - char *errstr = strerror(errno); - - FLOCK(f); - - if (msg && *msg) { - fwrite(msg, strlen(msg), 1, f); - fputc(':', f); - fputc(' ', f); - } - fwrite(errstr, strlen(errstr), 1, f); - fputc('\n', f); - - FUNLOCK(f); -} diff --git a/usr/lib/libc/stdio/popen.c b/usr/lib/libc/stdio/popen.c deleted file mode 100644 index 92cb57ee9..000000000 --- a/usr/lib/libc/stdio/popen.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include -#include "stdio_impl.h" -#include "syscall.h" - -extern char **__environ; - -FILE *popen(const char *cmd, const char *mode) -{ - int p[2], op, e; - pid_t pid; - FILE *f; - posix_spawn_file_actions_t fa; - - if (*mode == 'r') { - op = 0; - } else if (*mode == 'w') { - op = 1; - } else { - errno = EINVAL; - return 0; - } - - if (pipe2(p, O_CLOEXEC)) return NULL; - f = fdopen(p[op], mode); - if (!f) { - __syscall(SYS_close, p[0]); - __syscall(SYS_close, p[1]); - return NULL; - } - FLOCK(f); - - /* If the child's end of the pipe happens to already be on the final - * fd number to which it will be assigned (either 0 or 1), it must - * be moved to a different fd. Otherwise, there is no safe way to - * remove the close-on-exec flag in the child without also creating - * a file descriptor leak race condition in the parent. */ - if (p[1-op] == 1-op) { - int tmp = fcntl(1-op, F_DUPFD_CLOEXEC, 0); - if (tmp < 0) { - e = errno; - goto fail; - } - __syscall(SYS_close, p[1-op]); - p[1-op] = tmp; - } - - e = ENOMEM; - if (!posix_spawn_file_actions_init(&fa)) { - if (!posix_spawn_file_actions_adddup2(&fa, p[1-op], 1-op)) { - if (!(e = posix_spawn(&pid, "/bin/sh", &fa, 0, - (char *[]){ "sh", "-c", (char *)cmd, 0 }, __environ))) { - posix_spawn_file_actions_destroy(&fa); - f->pipe_pid = pid; - if (!strchr(mode, 'e')) - fcntl(p[op], F_SETFD, 0); - __syscall(SYS_close, p[1-op]); - FUNLOCK(f); - return f; - } - } - posix_spawn_file_actions_destroy(&fa); - } -fail: - fclose(f); - __syscall(SYS_close, p[1-op]); - - errno = e; - return 0; -} diff --git a/usr/lib/libc/stdio/printf.c b/usr/lib/libc/stdio/printf.c deleted file mode 100644 index b4d129d61..000000000 --- a/usr/lib/libc/stdio/printf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int printf(const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfprintf(stdout, fmt, ap); - va_end(ap); - - return ret; -} diff --git a/usr/lib/libc/stdio/putc.c b/usr/lib/libc/stdio/putc.c deleted file mode 100644 index fa8934969..000000000 --- a/usr/lib/libc/stdio/putc.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "stdio_impl.h" - -int putc(int c, FILE *f) -{ - if (f->lock < 0 || !__lockfile(f)) - return putc_unlocked(c, f); - c = putc_unlocked(c, f); - __unlockfile(f); - return c; -} - -weak_alias(putc, _IO_putc); diff --git a/usr/lib/libc/stdio/putc_unlocked.c b/usr/lib/libc/stdio/putc_unlocked.c deleted file mode 100644 index 10071312e..000000000 --- a/usr/lib/libc/stdio/putc_unlocked.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "stdio_impl.h" - -int (putc_unlocked)(int c, FILE *f) -{ - return putc_unlocked(c, f); -} - -weak_alias(putc_unlocked, fputc_unlocked); -weak_alias(putc_unlocked, _IO_putc_unlocked); diff --git a/usr/lib/libc/stdio/putchar.c b/usr/lib/libc/stdio/putchar.c deleted file mode 100644 index 588fb1e96..000000000 --- a/usr/lib/libc/stdio/putchar.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int putchar(int c) -{ - int ret; - - ret = fputc(c, stdout); - - /* Flush immediately */ - fflush(stdout); - - return ret; -} diff --git a/usr/lib/libc/stdio/putchar_unlocked.c b/usr/lib/libc/stdio/putchar_unlocked.c deleted file mode 100644 index 8b5d06034..000000000 --- a/usr/lib/libc/stdio/putchar_unlocked.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "stdio_impl.h" - -int putchar_unlocked(int c) -{ - return putc_unlocked(c, stdout); -} diff --git a/usr/lib/libc/stdio/puts.c b/usr/lib/libc/stdio/puts.c deleted file mode 100644 index 90e9f6435..000000000 --- a/usr/lib/libc/stdio/puts.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int puts(const char *s) -{ - int r; - FLOCK(stdout); - r = -(fputs(s, stdout) < 0 || putc_unlocked('\n', stdout) < 0); - FUNLOCK(stdout); - return r; -} diff --git a/usr/lib/libc/stdio/putw.c b/usr/lib/libc/stdio/putw.c deleted file mode 100644 index 0ff9d7fbf..000000000 --- a/usr/lib/libc/stdio/putw.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -int putw(int x, FILE *f) -{ - return (int)fwrite(&x, sizeof x, 1, f)-1; -} diff --git a/usr/lib/libc/stdio/putwc.c b/usr/lib/libc/stdio/putwc.c deleted file mode 100644 index 4bb747334..000000000 --- a/usr/lib/libc/stdio/putwc.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "stdio_impl.h" -#include - -wint_t putwc(wchar_t c, FILE *f) -{ - return fputwc(c, f); -} diff --git a/usr/lib/libc/stdio/putwchar.c b/usr/lib/libc/stdio/putwchar.c deleted file mode 100644 index b249c4ac1..000000000 --- a/usr/lib/libc/stdio/putwchar.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "stdio_impl.h" -#include - -wint_t putwchar(wchar_t c) -{ - return fputwc(c, stdout); -} - -weak_alias(putwchar, putwchar_unlocked); diff --git a/usr/lib/libc/stdio/remove.c b/usr/lib/libc/stdio/remove.c deleted file mode 100644 index 942e301a4..000000000 --- a/usr/lib/libc/stdio/remove.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -int remove(const char *path) -{ -#ifdef SYS_unlink - int r = __syscall(SYS_unlink, path); -#else - int r = __syscall(SYS_unlinkat, AT_FDCWD, path, 0); -#endif -#ifdef SYS_rmdir - if (r==-EISDIR) r = __syscall(SYS_rmdir, path); -#else - if (r==-EISDIR) r = __syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); -#endif - return __syscall_ret(r); -} diff --git a/usr/lib/libc/stdio/rename.c b/usr/lib/libc/stdio/rename.c deleted file mode 100644 index 04c90c013..000000000 --- a/usr/lib/libc/stdio/rename.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int rename(const char *old, const char *new) -{ -#ifdef SYS_rename - return syscall(SYS_rename, old, new); -#else - return syscall(SYS_renameat, AT_FDCWD, old, AT_FDCWD, new); -#endif -} diff --git a/usr/lib/libc/stdio/rewind.c b/usr/lib/libc/stdio/rewind.c deleted file mode 100644 index 6f4b58b54..000000000 --- a/usr/lib/libc/stdio/rewind.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "stdio_impl.h" - -void rewind(FILE *f) -{ - FLOCK(f); - __fseeko_unlocked(f, 0, SEEK_SET); - f->flags &= ~F_ERR; - FUNLOCK(f); -} diff --git a/usr/lib/libc/stdio/scanf.c b/usr/lib/libc/stdio/scanf.c deleted file mode 100644 index 5cbba25c5..000000000 --- a/usr/lib/libc/stdio/scanf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -int scanf(const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vscanf(fmt, ap); - va_end(ap); - return ret; -} - -weak_alias(scanf,__isoc99_scanf); diff --git a/usr/lib/libc/stdio/setbuf.c b/usr/lib/libc/stdio/setbuf.c deleted file mode 100644 index 74ad7834a..000000000 --- a/usr/lib/libc/stdio/setbuf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void setbuf(FILE *restrict f, char *restrict buf) -{ - setvbuf(f, buf, buf ? _IOFBF : _IONBF, BUFSIZ); -} diff --git a/usr/lib/libc/stdio/setbuffer.c b/usr/lib/libc/stdio/setbuffer.c deleted file mode 100644 index 71233d2ec..000000000 --- a/usr/lib/libc/stdio/setbuffer.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -void setbuffer(FILE *f, char *buf, size_t size) -{ - setvbuf(f, buf, buf ? _IOFBF : _IONBF, size); -} diff --git a/usr/lib/libc/stdio/setlinebuf.c b/usr/lib/libc/stdio/setlinebuf.c deleted file mode 100644 index b93c4d6a1..000000000 --- a/usr/lib/libc/stdio/setlinebuf.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -void setlinebuf(FILE *f) -{ - setvbuf(f, 0, _IOLBF, 0); -} diff --git a/usr/lib/libc/stdio/setvbuf.c b/usr/lib/libc/stdio/setvbuf.c deleted file mode 100644 index 541a125ff..000000000 --- a/usr/lib/libc/stdio/setvbuf.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "stdio_impl.h" - -/* This function makes no attempt to protect the user from his/her own - * stupidity. If called any time but when then ISO C standard specifically - * allows it, all hell can and will break loose, especially with threads! - * - * This implementation ignores all arguments except the buffering type, - * and uses the existing buffer allocated alongside the FILE object. - * In the case of stderr where the preexisting buffer is length 1, it - * is not possible to set line buffering or full buffering. */ - -int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size) -{ - f->lbf = EOF; - - if (type == _IONBF) - f->buf_size = 0; - else if (type == _IOLBF) - f->lbf = '\n'; - - f->flags |= F_SVB; - - return 0; -} diff --git a/usr/lib/libc/stdio/snprintf.c b/usr/lib/libc/stdio/snprintf.c deleted file mode 100644 index 771503b28..000000000 --- a/usr/lib/libc/stdio/snprintf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int snprintf(char *restrict s, size_t n, const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vsnprintf(s, n, fmt, ap); - va_end(ap); - return ret; -} - diff --git a/usr/lib/libc/stdio/sprintf.c b/usr/lib/libc/stdio/sprintf.c deleted file mode 100644 index 9dff524c0..000000000 --- a/usr/lib/libc/stdio/sprintf.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int sprintf(char *restrict s, const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vsprintf(s, fmt, ap); - va_end(ap); - return ret; -} diff --git a/usr/lib/libc/stdio/sscanf.c b/usr/lib/libc/stdio/sscanf.c deleted file mode 100644 index 073d3efbc..000000000 --- a/usr/lib/libc/stdio/sscanf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -int sscanf(const char *restrict s, const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vsscanf(s, fmt, ap); - va_end(ap); - return ret; -} - -weak_alias(sscanf,__isoc99_sscanf); diff --git a/usr/lib/libc/stdio/stderr.c b/usr/lib/libc/stdio/stderr.c deleted file mode 100644 index ab5fa4a18..000000000 --- a/usr/lib/libc/stdio/stderr.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "stdio_impl.h" - -static unsigned char buf[UNGET]; -static FILE f = { - .buf = buf+UNGET, - .buf_size = 0, - .fd = 2, -#if 0 - .flags = F_PERM | F_NORD, -#endif - .flags = F_PERM, - .lbf = -1, - .write = __stdio_write, - - .read = __stdio_read, /* (SO3) Special case for ls|more */ - - .seek = __stdio_seek, - .close = __stdio_close, - .lock = -1, -}; -FILE *const stderr = &f; -FILE *volatile __stderr_used = &f; diff --git a/usr/lib/libc/stdio/stdin.c b/usr/lib/libc/stdio/stdin.c deleted file mode 100644 index 171ff22a9..000000000 --- a/usr/lib/libc/stdio/stdin.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "stdio_impl.h" - -static unsigned char buf[BUFSIZ+UNGET]; -static FILE f = { - .buf = buf+UNGET, - .buf_size = sizeof buf-UNGET, - .fd = 0, - .flags = F_PERM | F_NOWR, - .read = __stdio_read, - .seek = __stdio_seek, - .close = __stdio_close, - .lock = -1, -}; -FILE *const stdin = &f; -FILE *volatile __stdin_used = &f; diff --git a/usr/lib/libc/stdio/stdout.c b/usr/lib/libc/stdio/stdout.c deleted file mode 100644 index 6b188942d..000000000 --- a/usr/lib/libc/stdio/stdout.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "stdio_impl.h" - -static unsigned char buf[BUFSIZ+UNGET]; -static FILE f = { - .buf = buf+UNGET, - .buf_size = sizeof buf-UNGET, - .fd = 1, - .flags = F_PERM | F_NORD, - .lbf = '\n', - .write = __stdout_write, - .seek = __stdio_seek, - .close = __stdio_close, - .lock = -1, -}; -FILE *const stdout = &f; -FILE *volatile __stdout_used = &f; diff --git a/usr/lib/libc/stdio/swprintf.c b/usr/lib/libc/stdio/swprintf.c deleted file mode 100644 index f75eb112e..000000000 --- a/usr/lib/libc/stdio/swprintf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int swprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vswprintf(s, n, fmt, ap); - va_end(ap); - return ret; -} - diff --git a/usr/lib/libc/stdio/swscanf.c b/usr/lib/libc/stdio/swscanf.c deleted file mode 100644 index d893fbacf..000000000 --- a/usr/lib/libc/stdio/swscanf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include "libc.h" - -int swscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vswscanf(s, fmt, ap); - va_end(ap); - return ret; -} - -weak_alias(swscanf,__isoc99_swscanf); diff --git a/usr/lib/libc/stdio/tempnam.c b/usr/lib/libc/stdio/tempnam.c deleted file mode 100644 index 5a5597527..000000000 --- a/usr/lib/libc/stdio/tempnam.c +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "syscall.h" - -#define MAXTRIES 100 - -char *__randname(char *); - -char *tempnam(const char *dir, const char *pfx) -{ - char s[PATH_MAX]; - size_t l, dl, pl; - int try; - int r; - - if (!dir) dir = P_tmpdir; - if (!pfx) pfx = "temp"; - - dl = strlen(dir); - pl = strlen(pfx); - l = dl + 1 + pl + 1 + 6; - - if (l >= PATH_MAX) { - errno = ENAMETOOLONG; - return 0; - } - - memcpy(s, dir, dl); - s[dl] = '/'; - memcpy(s+dl+1, pfx, pl); - s[dl+1+pl] = '_'; - s[l] = 0; - - for (try=0; try -#include -#include "stdio_impl.h" - -#define MAXTRIES 100 - -char *__randname(char *); - -FILE *tmpfile(void) -{ - char s[] = "/tmp/tmpfile_XXXXXX"; - int fd; - FILE *f; - int try; - for (try=0; try= 0) { -#ifdef SYS_unlink - __syscall(SYS_unlink, s); -#else - __syscall(SYS_unlinkat, AT_FDCWD, s, 0); -#endif - f = __fdopen(fd, "w+"); - if (!f) __syscall(SYS_close, fd); - return f; - } - } - return 0; -} - -LFS64(tmpfile); diff --git a/usr/lib/libc/stdio/tmpnam.c b/usr/lib/libc/stdio/tmpnam.c deleted file mode 100644 index 449eb9b07..000000000 --- a/usr/lib/libc/stdio/tmpnam.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include -#include -#include "syscall.h" - -#define MAXTRIES 100 - -char *__randname(char *); - -char *tmpnam(char *buf) -{ - static char internal[L_tmpnam]; - char s[] = "/tmp/tmpnam_XXXXXX"; - int try; - int r; - for (try=0; tryrpos) __toread(f); - if (!f->rpos || f->rpos <= f->buf - UNGET) { - FUNLOCK(f); - return EOF; - } - - *--f->rpos = c; - f->flags &= ~F_EOF; - - FUNLOCK(f); - return c; -} diff --git a/usr/lib/libc/stdio/ungetwc.c b/usr/lib/libc/stdio/ungetwc.c deleted file mode 100644 index 9edf366f9..000000000 --- a/usr/lib/libc/stdio/ungetwc.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "stdio_impl.h" -#include "locale_impl.h" -#include -#include -#include -#include - -wint_t ungetwc(wint_t c, FILE *f) -{ - unsigned char mbc[MB_LEN_MAX]; - int l; - locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; - - FLOCK(f); - - if (f->mode <= 0) fwide(f, 1); - *ploc = f->locale; - - if (!f->rpos) __toread(f); - if (!f->rpos || c == WEOF || (l = wcrtomb((void *)mbc, c, 0)) < 0 || - f->rpos < f->buf - UNGET + l) { - FUNLOCK(f); - *ploc = loc; - return WEOF; - } - - if (isascii(c)) *--f->rpos = c; - else memcpy(f->rpos -= l, mbc, l); - - f->flags &= ~F_EOF; - - FUNLOCK(f); - *ploc = loc; - return c; -} diff --git a/usr/lib/libc/stdio/vasprintf.c b/usr/lib/libc/stdio/vasprintf.c deleted file mode 100644 index 08251bc20..000000000 --- a/usr/lib/libc/stdio/vasprintf.c +++ /dev/null @@ -1,15 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include - -int vasprintf(char **s, const char *fmt, va_list ap) -{ - va_list ap2; - va_copy(ap2, ap); - int l = vsnprintf(0, 0, fmt, ap2); - va_end(ap2); - - if (l<0 || !(*s=malloc(l+1U))) return -1; - return vsnprintf(*s, l+1U, fmt, ap); -} diff --git a/usr/lib/libc/stdio/vdprintf.c b/usr/lib/libc/stdio/vdprintf.c deleted file mode 100644 index c35d9b4fb..000000000 --- a/usr/lib/libc/stdio/vdprintf.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "stdio_impl.h" - -static size_t wrap_write(FILE *f, const unsigned char *buf, size_t len) -{ - return __stdio_write(f, buf, len); -} - -int vdprintf(int fd, const char *restrict fmt, va_list ap) -{ - FILE f = { - .fd = fd, .lbf = EOF, .write = wrap_write, - .buf = (void *)fmt, .buf_size = 0, - .lock = -1 - }; - return vfprintf(&f, fmt, ap); -} diff --git a/usr/lib/libc/stdio/vfprintf.c b/usr/lib/libc/stdio/vfprintf.c deleted file mode 100644 index 067a405e0..000000000 --- a/usr/lib/libc/stdio/vfprintf.c +++ /dev/null @@ -1,696 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Some useful macros */ - -#define MAX(a,b) ((a)>(b) ? (a) : (b)) -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -/* Convenient bit representation for modifier flags, which all fall - * within 31 codepoints of the space character. */ - -#define ALT_FORM (1U<<('#'-' ')) -#define ZERO_PAD (1U<<('0'-' ')) -#define LEFT_ADJ (1U<<('-'-' ')) -#define PAD_POS (1U<<(' '-' ')) -#define MARK_POS (1U<<('+'-' ')) -#define GROUPED (1U<<('\''-' ')) - -#define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS|GROUPED) - -/* State machine to accept length modifiers + conversion specifiers. - * Result is 0 on failure, or an argument type to pop on success. */ - -enum { - BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, - ZTPRE, JPRE, - STOP, - PTR, INT, UINT, ULLONG, - LONG, ULONG, - SHORT, USHORT, CHAR, UCHAR, - LLONG, SIZET, IMAX, UMAX, PDIFF, UIPTR, - DBL, LDBL, - NOARG, - MAXSTATE -}; - -#define S(x) [(x)-'A'] - -static const unsigned char states[]['z'-'A'+1] = { - { /* 0: bare types */ - S('d') = INT, S('i') = INT, - S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = CHAR, S('C') = INT, - S('s') = PTR, S('S') = PTR, S('p') = UIPTR, S('n') = PTR, - S('m') = NOARG, - S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, - S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE, - }, { /* 1: l-prefixed */ - S('d') = LONG, S('i') = LONG, - S('o') = ULONG, S('u') = ULONG, S('x') = ULONG, S('X') = ULONG, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = INT, S('s') = PTR, S('n') = PTR, - S('l') = LLPRE, - }, { /* 2: ll-prefixed */ - S('d') = LLONG, S('i') = LLONG, - S('o') = ULLONG, S('u') = ULLONG, - S('x') = ULLONG, S('X') = ULLONG, - S('n') = PTR, - }, { /* 3: h-prefixed */ - S('d') = SHORT, S('i') = SHORT, - S('o') = USHORT, S('u') = USHORT, - S('x') = USHORT, S('X') = USHORT, - S('n') = PTR, - S('h') = HHPRE, - }, { /* 4: hh-prefixed */ - S('d') = CHAR, S('i') = CHAR, - S('o') = UCHAR, S('u') = UCHAR, - S('x') = UCHAR, S('X') = UCHAR, - S('n') = PTR, - }, { /* 5: L-prefixed */ - S('e') = LDBL, S('f') = LDBL, S('g') = LDBL, S('a') = LDBL, - S('E') = LDBL, S('F') = LDBL, S('G') = LDBL, S('A') = LDBL, - S('n') = PTR, - }, { /* 6: z- or t-prefixed (assumed to be same size) */ - S('d') = PDIFF, S('i') = PDIFF, - S('o') = SIZET, S('u') = SIZET, - S('x') = SIZET, S('X') = SIZET, - S('n') = PTR, - }, { /* 7: j-prefixed */ - S('d') = IMAX, S('i') = IMAX, - S('o') = UMAX, S('u') = UMAX, - S('x') = UMAX, S('X') = UMAX, - S('n') = PTR, - } -}; - -#define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') - -union arg -{ - uintmax_t i; - long double f; - void *p; -}; - -static void pop_arg(union arg *arg, int type, va_list *ap) -{ - switch (type) { - case PTR: arg->p = va_arg(*ap, void *); - break; case INT: arg->i = va_arg(*ap, int); - break; case UINT: arg->i = va_arg(*ap, unsigned int); - break; case LONG: arg->i = va_arg(*ap, long); - break; case ULONG: arg->i = va_arg(*ap, unsigned long); - break; case ULLONG: arg->i = va_arg(*ap, unsigned long long); - break; case SHORT: arg->i = (short)va_arg(*ap, int); - break; case USHORT: arg->i = (unsigned short)va_arg(*ap, int); - break; case CHAR: arg->i = (signed char)va_arg(*ap, int); - break; case UCHAR: arg->i = (unsigned char)va_arg(*ap, int); - break; case LLONG: arg->i = va_arg(*ap, long long); - break; case SIZET: arg->i = va_arg(*ap, size_t); - break; case IMAX: arg->i = va_arg(*ap, intmax_t); - break; case UMAX: arg->i = va_arg(*ap, uintmax_t); - break; case PDIFF: arg->i = va_arg(*ap, ptrdiff_t); - break; case UIPTR: arg->i = (uintptr_t)va_arg(*ap, void *); - break; case DBL: arg->f = va_arg(*ap, double); - break; case LDBL: arg->f = va_arg(*ap, long double); - } -} - -static void out(FILE *f, const char *s, size_t l) -{ - if (!(f->flags & F_ERR)) __fwritex((void *)s, l, f); -} - -static void pad(FILE *f, char c, int w, int l, int fl) -{ - char pad[256]; - if (fl & (LEFT_ADJ | ZERO_PAD) || l >= w) return; - l = w - l; - memset(pad, c, l>sizeof pad ? sizeof pad : l); - for (; l >= sizeof pad; l -= sizeof pad) - out(f, pad, sizeof pad); - out(f, pad, l); -} - -static const char xdigits[16] = { - "0123456789ABCDEF" -}; - -static char *fmt_x(uintmax_t x, char *s, int lower) -{ - for (; x; x>>=4) *--s = xdigits[(x&15)]|lower; - return s; -} - -static char *fmt_o(uintmax_t x, char *s) -{ - for (; x; x>>=3) *--s = '0' + (x&7); - return s; -} - -static char *fmt_u(uintmax_t x, char *s) -{ - unsigned long y; - for ( ; x>ULONG_MAX; x/=10) *--s = '0' + x%10; - for (y=x; y; y/=10) *--s = '0' + y%10; - return s; -} - -/* Do not override this check. The floating point printing code below - * depends on the float.h constants being right. If they are wrong, it - * may overflow the stack. */ -#if LDBL_MANT_DIG == 53 -typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)]; -#endif - -static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) -{ - uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion - + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion - uint32_t *a, *d, *r, *z; - int e2=0, e, i, j, l; - char buf[9+LDBL_MANT_DIG/4], *s; - const char *prefix="-0X+0X 0X-0x+0x 0x"; - int pl; - char ebuf0[3*sizeof(int)], *ebuf=&ebuf0[3*sizeof(int)], *estr; - - pl=1; - if (signbit(y)) { - y=-y; - } else if (fl & MARK_POS) { - prefix+=3; - } else if (fl & PAD_POS) { - prefix+=6; - } else prefix++, pl=0; - - if (!isfinite(y)) { - char *s = (t&32)?"inf":"INF"; - if (y!=y) s=(t&32)?"nan":"NAN"; - pad(f, ' ', w, 3+pl, fl&~ZERO_PAD); - out(f, prefix, pl); - out(f, s, 3); - pad(f, ' ', w, 3+pl, fl^LEFT_ADJ); - return MAX(w, 3+pl); - } - - y = frexpl(y, &e2) * 2; - if (y) e2--; - - if ((t|32)=='a') { - long double round = 8.0; - int re; - - if (t&32) prefix += 9; - pl += 2; - - if (p<0 || p>=LDBL_MANT_DIG/4-1) re=0; - else re=LDBL_MANT_DIG/4-1-p; - - if (re) { - round *= 1<<(LDBL_MANT_DIG%4); - while (re--) round*=16; - if (*prefix=='-') { - y=-y; - y-=round; - y+=round; - y=-y; - } else { - y+=round; - y-=round; - } - } - - estr=fmt_u(e2<0 ? -e2 : e2, ebuf); - if (estr==ebuf) *--estr='0'; - *--estr = (e2<0 ? '-' : '+'); - *--estr = t+('p'-'a'); - - s=buf; - do { - int x=y; - *s++=xdigits[x]|(t&32); - y=16*(y-x); - if (s-buf==1 && (y||p>0||(fl&ALT_FORM))) *s++='.'; - } while (y); - - if (p > INT_MAX-2-(ebuf-estr)-pl) - return -1; - if (p && s-buf-2 < p) - l = (p+2) + (ebuf-estr); - else - l = (s-buf) + (ebuf-estr); - - pad(f, ' ', w, pl+l, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+l, fl^ZERO_PAD); - out(f, buf, s-buf); - pad(f, '0', l-(ebuf-estr)-(s-buf), 0, 0); - out(f, estr, ebuf-estr); - pad(f, ' ', w, pl+l, fl^LEFT_ADJ); - return MAX(w, pl+l); - } - if (p<0) p=6; - - if (y) y *= 0x1p28, e2-=28; - - if (e2<0) a=r=z=big; - else a=r=z=big+sizeof(big)/sizeof(*big) - LDBL_MANT_DIG - 1; - - do { - *z = y; - y = 1000000000*(y-*z++); - } while (y); - - while (e2>0) { - uint32_t carry=0; - int sh=MIN(29,e2); - for (d=z-1; d>=a; d--) { - uint64_t x = ((uint64_t)*d<a && !z[-1]) z--; - e2-=sh; - } - while (e2<0) { - uint32_t carry=0, *b; - int sh=MIN(9,-e2), need=1+(p+LDBL_MANT_DIG/3U+8)/9; - for (d=a; d>sh) + carry; - carry = (1000000000>>sh) * rm; - } - if (!*a) a++; - if (carry) *z++ = carry; - /* Avoid (slow!) computation past requested precision */ - b = (t|32)=='f' ? r : a; - if (z-b > need) z = b+need; - e2+=sh; - } - - if (a=i; i*=10, e++); - else e=0; - - /* Perform rounding: j is precision after the radix (possibly neg) */ - j = p - ((t|32)!='f')*e - ((t|32)=='g' && p); - if (j < 9*(z-r-1)) { - uint32_t x; - /* We avoid C's broken division of negative numbers */ - d = r + 1 + ((j+9*LDBL_MAX_EXP)/9 - LDBL_MAX_EXP); - j += 9*LDBL_MAX_EXP; - j %= 9; - for (i=10, j++; j<9; i*=10, j++); - x = *d % i; - /* Are there any significant digits past j? */ - if (x || d+1!=z) { - long double round = 2/LDBL_EPSILON; - long double small; - if ((*d/i & 1) || (i==1000000000 && d>a && (d[-1]&1))) - round += 2; - if (x 999999999) { - *d--=0; - if (d=i; i*=10, e++); - } - } - if (z>d+1) z=d+1; - } - for (; z>a && !z[-1]; z--); - - if ((t|32)=='g') { - if (!p) p++; - if (p>e && e>=-4) { - t--; - p-=e+1; - } else { - t-=2; - p--; - } - if (!(fl&ALT_FORM)) { - /* Count trailing zeros in last place */ - if (z>a && z[-1]) for (i=10, j=0; z[-1]%i==0; i*=10, j++); - else j=9; - if ((t|32)=='f') - p = MIN(p,MAX(0,9*(z-r-1)-j)); - else - p = MIN(p,MAX(0,9*(z-r-1)+e-j)); - } - } - if (p > INT_MAX-1-(p || (fl&ALT_FORM))) - return -1; - l = 1 + p + (p || (fl&ALT_FORM)); - if ((t|32)=='f') { - if (e > INT_MAX-l) return -1; - if (e>0) l+=e; - } else { - estr=fmt_u(e<0 ? -e : e, ebuf); - while(ebuf-estr<2) *--estr='0'; - *--estr = (e<0 ? '-' : '+'); - *--estr = t; - if (ebuf-estr > INT_MAX-l) return -1; - l += ebuf-estr; - } - - if (l > INT_MAX-pl) return -1; - pad(f, ' ', w, pl+l, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+l, fl^ZERO_PAD); - - if ((t|32)=='f') { - if (a>r) a=r; - for (d=a; d<=r; d++) { - char *s = fmt_u(*d, buf+9); - if (d!=a) while (s>buf) *--s='0'; - else if (s==buf+9) *--s='0'; - out(f, s, buf+9-s); - } - if (p || (fl&ALT_FORM)) out(f, ".", 1); - for (; d0; d++, p-=9) { - char *s = fmt_u(*d, buf+9); - while (s>buf) *--s='0'; - out(f, s, MIN(9,p)); - } - pad(f, '0', p+9, 9, 0); - } else { - if (z<=a) z=a+1; - for (d=a; d=0; d++) { - char *s = fmt_u(*d, buf+9); - if (s==buf+9) *--s='0'; - if (d!=a) while (s>buf) *--s='0'; - else { - out(f, s++, 1); - if (p>0||(fl&ALT_FORM)) out(f, ".", 1); - } - out(f, s, MIN(buf+9-s, p)); - p -= buf+9-s; - } - pad(f, '0', p+18, 18, 0); - out(f, estr, ebuf-estr); - } - - pad(f, ' ', w, pl+l, fl^LEFT_ADJ); - - return MAX(w, pl+l); -} - -static int getint(char **s) { - int i; - for (i=0; isdigit(**s); (*s)++) { - if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; - else i = 10*i + (**s-'0'); - } - return i; -} - -static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, int *nl_type) -{ - char *a, *z, *s=(char *)fmt; - unsigned l10n=0, fl; - int w, p, xp; - union arg arg; - int argpos; - unsigned st, ps; - int cnt=0, l=0; - size_t i; - char buf[sizeof(uintmax_t)*3+3+LDBL_MANT_DIG/4]; - const char *prefix; - int t, pl; - wchar_t wc[2], *ws; - char mb[4]; - - for (;;) { - /* This error is only specified for snprintf, but since it's - * unspecified for other forms, do the same. Stop immediately - * on overflow; otherwise %n could produce wrong results. */ - if (l > INT_MAX - cnt) goto overflow; - - /* Update output count, end loop when fmt is exhausted */ - cnt += l; - if (!*s) break; - - /* Handle literal text and %% format specifiers */ - for (a=s; *s && *s!='%'; s++); - for (z=s; s[0]=='%' && s[1]=='%'; z++, s+=2); - if (z-a > INT_MAX-cnt) goto overflow; - l = z-a; - if (f) out(f, a, l); - if (l) continue; - - if (isdigit(s[1]) && s[2]=='$') { - l10n=1; - argpos = s[1]-'0'; - s+=3; - } else { - argpos = -1; - s++; - } - - /* Read modifier flags */ - for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&((1U << *s) - ' ')); s++) - fl |= (1U<<*s)-' '; - - /* Read field width */ - if (*s=='*') { - if (isdigit(s[1]) && s[2]=='$') { - l10n=1; - nl_type[s[1]-'0'] = INT; - w = nl_arg[s[1]-'0'].i; - s+=3; - } else if (!l10n) { - w = f ? va_arg(*ap, int) : 0; - s++; - } else goto inval; - if (w<0) fl|=LEFT_ADJ, w=-w; - } else if ((w=getint(&s))<0) goto overflow; - - /* Read precision */ - if (*s=='.' && s[1]=='*') { - if (isdigit(s[2]) && s[3]=='$') { - nl_type[s[2]-'0'] = INT; - p = nl_arg[s[2]-'0'].i; - s+=4; - } else if (!l10n) { - p = f ? va_arg(*ap, int) : 0; - s+=2; - } else goto inval; - xp = (p>=0); - } else if (*s=='.') { - s++; - p = getint(&s); - xp = 1; - } else { - p = -1; - xp = 0; - } - - /* Format specifier state machine */ - st=0; - do { - if (OOB(*s)) goto inval; - ps=st; - st=states[st]S(*s++); - } while (st-1=0) goto inval; - } else { - if (argpos>=0) nl_type[argpos]=st, arg=nl_arg[argpos]; - else if (f) pop_arg(&arg, st, ap); - else return 0; - } - - if (!f) continue; - - z = buf + sizeof(buf); - prefix = "-+ 0X0x"; - pl = 0; - t = s[-1]; - - /* Transform ls,lc -> S,C */ - if (ps && (t&15)==3) t&=~32; - - /* - and 0 flags are mutually exclusive */ - if (fl & LEFT_ADJ) fl &= ~ZERO_PAD; - - switch(t) { - case 'n': - switch(ps) { - case BARE: *(int *)arg.p = cnt; break; - case LPRE: *(long *)arg.p = cnt; break; - case LLPRE: *(long long *)arg.p = cnt; break; - case HPRE: *(unsigned short *)arg.p = cnt; break; - case HHPRE: *(unsigned char *)arg.p = cnt; break; - case ZTPRE: *(size_t *)arg.p = cnt; break; - case JPRE: *(uintmax_t *)arg.p = cnt; break; - } - continue; - case 'p': - p = MAX(p, 2*sizeof(void*)); - t = 'x'; - fl |= ALT_FORM; - case 'x': case 'X': - a = fmt_x(arg.i, z, t&32); - if (arg.i && (fl & ALT_FORM)) prefix+=(t>>4), pl=2; - if (0) { - case 'o': - a = fmt_o(arg.i, z); - if ((fl&ALT_FORM) && pINTMAX_MAX) { - arg.i=-arg.i; - } else if (fl & MARK_POS) { - prefix++; - } else if (fl & PAD_POS) { - prefix+=2; - } else pl=0; - case 'u': - a = fmt_u(arg.i, z); - } - if (xp && p<0) goto overflow; - if (xp) fl &= ~ZERO_PAD; - if (!arg.i && !p) { - a=z; - break; - } - p = MAX(p, z-a + !arg.i); - break; - case 'c': - *(a=z-(p=1))=arg.i; - fl &= ~ZERO_PAD; - break; - case 'm': - if (1) a = strerror(errno); else - case 's': - a = arg.p ? arg.p : "(null)"; - z = a + strnlen(a, p<0 ? INT_MAX : p); - if (p<0 && *z) goto overflow; - p = z-a; - fl &= ~ZERO_PAD; - break; - case 'C': - wc[0] = arg.i; - wc[1] = 0; - arg.p = wc; - p = -1; - case 'S': - ws = arg.p; - for (i=l=0; i

=0 && l<=p-i; i+=l); - if (l<0) return -1; - if (i > INT_MAX) goto overflow; - p = i; - pad(f, ' ', w, p, fl); - ws = arg.p; - for (i=0; i<0U+p && *ws && i+(l=wctomb(mb, *ws++))<=p; i+=l) - out(f, mb, l); - pad(f, ' ', w, p, fl^LEFT_ADJ); - l = w>p ? w : p; - continue; - case 'e': case 'f': case 'g': case 'a': - case 'E': case 'F': case 'G': case 'A': - if (xp && p<0) goto overflow; - l = fmt_fp(f, arg.f, w, p, fl, t); - if (l<0) goto overflow; - continue; - } - - if (p < z-a) p = z-a; - if (p > INT_MAX-pl) goto overflow; - if (w < pl+p) w = pl+p; - if (w > INT_MAX-cnt) goto overflow; - - pad(f, ' ', w, pl+p, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+p, fl^ZERO_PAD); - pad(f, '0', p, z-a, 0); - out(f, a, z-a); - pad(f, ' ', w, pl+p, fl^LEFT_ADJ); - - l = w; - } - - if (f) return cnt; - if (!l10n) return 0; - - for (i=1; i<=NL_ARGMAX && nl_type[i]; i++) - pop_arg(nl_arg+i, nl_type[i], ap); - for (; i<=NL_ARGMAX && !nl_type[i]; i++); - if (i<=NL_ARGMAX) goto inval; - return 1; - -inval: - errno = EINVAL; - return -1; -overflow: - errno = EOVERFLOW; - return -1; -} - -int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) -{ - va_list ap2; - int nl_type[NL_ARGMAX+1] = {0}; - union arg nl_arg[NL_ARGMAX+1]; - unsigned char internal_buf[80], *saved_buf = 0; - int olderr; - int ret; - - /* the copy allows passing va_list* even if va_list is an array */ - va_copy(ap2, ap); - if (printf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) { - va_end(ap2); - return -1; - } - - FLOCK(f); - olderr = f->flags & F_ERR; - if (f->mode < 1) f->flags &= ~F_ERR; - if (!f->buf_size) { - saved_buf = f->buf; - f->buf = internal_buf; - f->buf_size = sizeof internal_buf; - f->wpos = f->wbase = f->wend = 0; - } - if (!f->wend && __towrite(f)) ret = -1; - else ret = printf_core(f, fmt, &ap2, nl_arg, nl_type); - if (saved_buf) { - f->write(f, 0, 0); - if (!f->wpos) ret = -1; - f->buf = saved_buf; - f->buf_size = 0; - f->wpos = f->wbase = f->wend = 0; - } - if (f->flags & F_ERR) ret = -1; - f->flags |= olderr; - FUNLOCK(f); - va_end(ap2); - return ret; -} diff --git a/usr/lib/libc/stdio/vfscanf.c b/usr/lib/libc/stdio/vfscanf.c deleted file mode 100644 index af8016e0c..000000000 --- a/usr/lib/libc/stdio/vfscanf.c +++ /dev/null @@ -1,332 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define SIZE_hh -2 -#define SIZE_h -1 -#define SIZE_def 0 -#define SIZE_l 1 -#define SIZE_L 2 -#define SIZE_ll 3 - -static void store_int(void *dest, int size, unsigned long long i) -{ - if (!dest) return; - switch (size) { - case SIZE_hh: - *(char *)dest = i; - break; - case SIZE_h: - *(short *)dest = i; - break; - case SIZE_def: - *(int *)dest = i; - break; - case SIZE_l: - *(long *)dest = i; - break; - case SIZE_ll: - *(long long *)dest = i; - break; - } -} - -static void *arg_n(va_list ap, unsigned int n) -{ - void *p; - unsigned int i; - va_list ap2; - va_copy(ap2, ap); - for (i=n; i>1; i--) va_arg(ap2, void *); - p = va_arg(ap2, void *); - va_end(ap2); - return p; -} - -int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) -{ - int width; - int size; - int alloc; - int base; - const unsigned char *p; - int c, t; - char *s; - wchar_t *wcs; - mbstate_t st; - void *dest=NULL; - int invert; - int matches=0; - unsigned long long x; - long double y; - off_t pos = 0; - unsigned char scanset[257]; - size_t i, k; - wchar_t wc; - - FLOCK(f); - - for (p=(const unsigned char *)fmt; *p; p++) { - - alloc = 0; - - if (isspace(*p)) { - while (isspace(p[1])) p++; - shlim(f, 0); - while (isspace(shgetc(f))); - shunget(f); - pos += shcnt(f); - continue; - } - if (*p != '%' || p[1] == '%') { - p += *p=='%'; - shlim(f, 0); - c = shgetc(f); - if (c!=*p) { - shunget(f); - if (c<0) goto input_fail; - goto match_fail; - } - pos++; - continue; - } - - p++; - if (*p=='*') { - dest = 0; p++; - } else if (isdigit(*p) && p[1]=='$') { - dest = arg_n(ap, *p-'0'); p+=2; - } else { - dest = va_arg(ap, void *); - } - - for (width=0; isdigit(*p); p++) { - width = 10*width + *p - '0'; - } - - if (*p=='m') { - wcs = 0; - s = 0; - alloc = !!dest; - p++; - } else { - alloc = 0; - } - - size = SIZE_def; - switch (*p++) { - case 'h': - if (*p == 'h') p++, size = SIZE_hh; - else size = SIZE_h; - break; - case 'l': - if (*p == 'l') p++, size = SIZE_ll; - else size = SIZE_l; - break; - case 'j': - size = SIZE_ll; - break; - case 'z': - case 't': - size = SIZE_l; - break; - case 'L': - size = SIZE_L; - break; - case 'd': case 'i': case 'o': case 'u': case 'x': - case 'a': case 'e': case 'f': case 'g': - case 'A': case 'E': case 'F': case 'G': case 'X': - case 's': case 'c': case '[': - case 'S': case 'C': - case 'p': case 'n': - p--; - break; - default: - goto fmt_fail; - } - - t = *p; - - /* C or S */ - if ((t&0x2f) == 3) { - t |= 32; - size = SIZE_l; - } - - switch (t) { - case 'c': - if (width < 1) width = 1; - case '[': - break; - case 'n': - store_int(dest, size, pos); - /* do not increment match count, etc! */ - continue; - default: - shlim(f, 0); - while (isspace(shgetc(f))); - shunget(f); - pos += shcnt(f); - } - - shlim(f, width); - if (shgetc(f) < 0) goto input_fail; - shunget(f); - - switch (t) { - case 's': - case 'c': - case '[': - if (t == 'c' || t == 's') { - memset(scanset, -1, sizeof scanset); - scanset[0] = 0; - if (t == 's') { - scanset[1+'\t'] = 0; - scanset[1+'\n'] = 0; - scanset[1+'\v'] = 0; - scanset[1+'\f'] = 0; - scanset[1+'\r'] = 0; - scanset[1+' '] = 0; - } - } else { - if (*++p == '^') p++, invert = 1; - else invert = 0; - memset(scanset, invert, sizeof scanset); - scanset[0] = 0; - if (*p == '-') p++, scanset[1+'-'] = 1-invert; - else if (*p == ']') p++, scanset[1+']'] = 1-invert; - for (; *p != ']'; p++) { - if (!*p) goto fmt_fail; - if (*p=='-' && p[1] && p[1] != ']') - for (c=p++[-1]; c<*p; c++) - scanset[1+c] = 1-invert; - scanset[1+*p] = 1-invert; - } - } - wcs = 0; - s = 0; - i = 0; - k = t=='c' ? width+1U : 31; - if (size == SIZE_l) { - if (alloc) { - wcs = malloc(k*sizeof(wchar_t)); - if (!wcs) goto alloc_fail; - } else { - wcs = dest; - } - st = (mbstate_t){0}; - while (scanset[(c=shgetc(f))+1]) { - switch (mbrtowc(&wc, &(char){c}, 1, &st)) { - case -1: - goto input_fail; - case -2: - continue; - } - if (wcs) wcs[i++] = wc; - if (alloc && i==k) { - k+=k+1; - wchar_t *tmp = realloc(wcs, k*sizeof(wchar_t)); - if (!tmp) goto alloc_fail; - wcs = tmp; - } - } - if (!mbsinit(&st)) goto input_fail; - } else if (alloc) { - s = malloc(k); - if (!s) goto alloc_fail; - while (scanset[(c=shgetc(f))+1]) { - s[i++] = c; - if (i==k) { - k+=k+1; - char *tmp = realloc(s, k); - if (!tmp) goto alloc_fail; - s = tmp; - } - } - } else if ((s = dest)) { - while (scanset[(c=shgetc(f))+1]) - s[i++] = c; - } else { - while (scanset[(c=shgetc(f))+1]); - } - shunget(f); - if (!shcnt(f)) goto match_fail; - if (t == 'c' && shcnt(f) != width) goto match_fail; - if (alloc) { - if (size == SIZE_l) *(wchar_t **)dest = wcs; - else *(char **)dest = s; - } - if (t != 'c') { - if (wcs) wcs[i] = 0; - if (s) s[i] = 0; - } - break; - case 'p': - case 'X': - case 'x': - base = 16; - goto int_common; - case 'o': - base = 8; - goto int_common; - case 'd': - case 'u': - base = 10; - goto int_common; - case 'i': - base = 0; - int_common: - x = __intscan(f, base, 0, ULLONG_MAX); - if (!shcnt(f)) goto match_fail; - if (t=='p' && dest) *(void **)dest = (void *)(uintptr_t)x; - else store_int(dest, size, x); - break; - case 'a': case 'A': - case 'e': case 'E': - case 'f': case 'F': - case 'g': case 'G': - y = __floatscan(f, size, 0); - if (!shcnt(f)) goto match_fail; - if (dest) switch (size) { - case SIZE_def: - *(float *)dest = y; - break; - case SIZE_l: - *(double *)dest = y; - break; - case SIZE_L: - *(long double *)dest = y; - break; - } - break; - } - - pos += shcnt(f); - if (dest) matches++; - } - if (0) { -fmt_fail: -alloc_fail: -input_fail: - if (!matches) matches--; -match_fail: - if (alloc) { - free(s); - free(wcs); - } - } - FUNLOCK(f); - return matches; -} - -weak_alias(vfscanf,__isoc99_vfscanf); diff --git a/usr/lib/libc/stdio/vfwprintf.c b/usr/lib/libc/stdio/vfwprintf.c deleted file mode 100644 index b8fff2081..000000000 --- a/usr/lib/libc/stdio/vfwprintf.c +++ /dev/null @@ -1,386 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include -#include -#include - -/* Convenient bit representation for modifier flags, which all fall - * within 31 codepoints of the space character. */ - -#define ALT_FORM (1U<<'#'-' ') -#define ZERO_PAD (1U<<'0'-' ') -#define LEFT_ADJ (1U<<'-'-' ') -#define PAD_POS (1U<<' '-' ') -#define MARK_POS (1U<<'+'-' ') -#define GROUPED (1U<<'\''-' ') - -#define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS|GROUPED) - -#if UINT_MAX == ULONG_MAX -#define LONG_IS_INT -#endif - -#if SIZE_MAX != ULONG_MAX || UINTMAX_MAX != ULLONG_MAX -#define ODD_TYPES -#endif - -/* State machine to accept length modifiers + conversion specifiers. - * Result is 0 on failure, or an argument type to pop on success. */ - -enum { - BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, - ZTPRE, JPRE, - STOP, - PTR, INT, UINT, ULLONG, -#ifndef LONG_IS_INT - LONG, ULONG, -#else -#define LONG INT -#define ULONG UINT -#endif - SHORT, USHORT, CHAR, UCHAR, -#ifdef ODD_TYPES - LLONG, SIZET, IMAX, UMAX, PDIFF, UIPTR, -#else -#define LLONG ULLONG -#define SIZET ULONG -#define IMAX LLONG -#define UMAX ULLONG -#define PDIFF LONG -#define UIPTR ULONG -#endif - DBL, LDBL, - NOARG, - MAXSTATE -}; - -#define S(x) [(x)-'A'] - -static const unsigned char states[]['z'-'A'+1] = { - { /* 0: bare types */ - S('d') = INT, S('i') = INT, - S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = CHAR, S('C') = INT, - S('s') = PTR, S('S') = PTR, S('p') = UIPTR, S('n') = PTR, - S('m') = NOARG, - S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, - S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE, - }, { /* 1: l-prefixed */ - S('d') = LONG, S('i') = LONG, - S('o') = ULONG, S('u') = ULONG, S('x') = ULONG, S('X') = ULONG, - S('c') = INT, S('s') = PTR, S('n') = PTR, - S('l') = LLPRE, - }, { /* 2: ll-prefixed */ - S('d') = LLONG, S('i') = LLONG, - S('o') = ULLONG, S('u') = ULLONG, - S('x') = ULLONG, S('X') = ULLONG, - S('n') = PTR, - }, { /* 3: h-prefixed */ - S('d') = SHORT, S('i') = SHORT, - S('o') = USHORT, S('u') = USHORT, - S('x') = USHORT, S('X') = USHORT, - S('n') = PTR, - S('h') = HHPRE, - }, { /* 4: hh-prefixed */ - S('d') = CHAR, S('i') = CHAR, - S('o') = UCHAR, S('u') = UCHAR, - S('x') = UCHAR, S('X') = UCHAR, - S('n') = PTR, - }, { /* 5: L-prefixed */ - S('e') = LDBL, S('f') = LDBL, S('g') = LDBL, S('a') = LDBL, - S('E') = LDBL, S('F') = LDBL, S('G') = LDBL, S('A') = LDBL, - S('n') = PTR, - }, { /* 6: z- or t-prefixed (assumed to be same size) */ - S('d') = PDIFF, S('i') = PDIFF, - S('o') = SIZET, S('u') = SIZET, - S('x') = SIZET, S('X') = SIZET, - S('n') = PTR, - }, { /* 7: j-prefixed */ - S('d') = IMAX, S('i') = IMAX, - S('o') = UMAX, S('u') = UMAX, - S('x') = UMAX, S('X') = UMAX, - S('n') = PTR, - } -}; - -#define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') - -union arg -{ - uintmax_t i; - long double f; - void *p; -}; - -static void pop_arg(union arg *arg, int type, va_list *ap) -{ - /* Give the compiler a hint for optimizing the switch. */ - if ((unsigned)type > MAXSTATE) return; - switch (type) { - case PTR: arg->p = va_arg(*ap, void *); - break; case INT: arg->i = va_arg(*ap, int); - break; case UINT: arg->i = va_arg(*ap, unsigned int); -#ifndef LONG_IS_INT - break; case LONG: arg->i = va_arg(*ap, long); - break; case ULONG: arg->i = va_arg(*ap, unsigned long); -#endif - break; case ULLONG: arg->i = va_arg(*ap, unsigned long long); - break; case SHORT: arg->i = (short)va_arg(*ap, int); - break; case USHORT: arg->i = (unsigned short)va_arg(*ap, int); - break; case CHAR: arg->i = (signed char)va_arg(*ap, int); - break; case UCHAR: arg->i = (unsigned char)va_arg(*ap, int); -#ifdef ODD_TYPES - break; case LLONG: arg->i = va_arg(*ap, long long); - break; case SIZET: arg->i = va_arg(*ap, size_t); - break; case IMAX: arg->i = va_arg(*ap, intmax_t); - break; case UMAX: arg->i = va_arg(*ap, uintmax_t); - break; case PDIFF: arg->i = va_arg(*ap, ptrdiff_t); - break; case UIPTR: arg->i = (uintptr_t)va_arg(*ap, void *); -#endif - break; case DBL: arg->f = va_arg(*ap, double); - break; case LDBL: arg->f = va_arg(*ap, long double); - } -} - -static void out(FILE *f, const wchar_t *s, size_t l) -{ - while (l-- && !(f->flags & F_ERR)) fputwc(*s++, f); -} - -static int getint(wchar_t **s) { - int i; - for (i=0; iswdigit(**s); (*s)++) { - if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; - else i = 10*i + (**s-'0'); - } - return i; -} - -static const char sizeprefix['y'-'a'] = { -['a'-'a']='L', ['e'-'a']='L', ['f'-'a']='L', ['g'-'a']='L', -['d'-'a']='j', ['i'-'a']='j', ['o'-'a']='j', ['u'-'a']='j', ['x'-'a']='j', -['p'-'a']='j' -}; - -static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_arg, int *nl_type) -{ - wchar_t *a, *z, *s=(wchar_t *)fmt; - unsigned l10n=0, fl; - int w, p, xp; - union arg arg; - int argpos; - unsigned st, ps; - int cnt=0, l=0; - int i; - int t; - char *bs; - char charfmt[16]; - wchar_t wc; - - for (;;) { - /* This error is only specified for snprintf, but since it's - * unspecified for other forms, do the same. Stop immediately - * on overflow; otherwise %n could produce wrong results. */ - if (l > INT_MAX - cnt) goto overflow; - - /* Update output count, end loop when fmt is exhausted */ - cnt += l; - if (!*s) break; - - /* Handle literal text and %% format specifiers */ - for (a=s; *s && *s!='%'; s++); - for (z=s; s[0]=='%' && s[1]=='%'; z++, s+=2); - if (z-a > INT_MAX-cnt) goto overflow; - l = z-a; - if (f) out(f, a, l); - if (l) continue; - - if (iswdigit(s[1]) && s[2]=='$') { - l10n=1; - argpos = s[1]-'0'; - s+=3; - } else { - argpos = -1; - s++; - } - - /* Read modifier flags */ - for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&(1U<<*s-' ')); s++) - fl |= 1U<<*s-' '; - - /* Read field width */ - if (*s=='*') { - if (iswdigit(s[1]) && s[2]=='$') { - l10n=1; - nl_type[s[1]-'0'] = INT; - w = nl_arg[s[1]-'0'].i; - s+=3; - } else if (!l10n) { - w = f ? va_arg(*ap, int) : 0; - s++; - } else goto inval; - if (w<0) fl|=LEFT_ADJ, w=-w; - } else if ((w=getint(&s))<0) goto overflow; - - /* Read precision */ - if (*s=='.' && s[1]=='*') { - if (isdigit(s[2]) && s[3]=='$') { - nl_type[s[2]-'0'] = INT; - p = nl_arg[s[2]-'0'].i; - s+=4; - } else if (!l10n) { - p = f ? va_arg(*ap, int) : 0; - s+=2; - } else goto inval; - xp = (p>=0); - } else if (*s=='.') { - s++; - p = getint(&s); - xp = 1; - } else { - p = -1; - xp = 0; - } - - /* Format specifier state machine */ - st=0; - do { - if (OOB(*s)) goto inval; - ps=st; - st=states[st]S(*s++); - } while (st-1=0) goto inval; - } else { - if (argpos>=0) nl_type[argpos]=st, arg=nl_arg[argpos]; - else if (f) pop_arg(&arg, st, ap); - else return 0; - } - - if (!f) continue; - t = s[-1]; - if (ps && (t&15)==3) t&=~32; - - switch (t) { - case 'n': - switch(ps) { - case BARE: *(int *)arg.p = cnt; break; - case LPRE: *(long *)arg.p = cnt; break; - case LLPRE: *(long long *)arg.p = cnt; break; - case HPRE: *(unsigned short *)arg.p = cnt; break; - case HHPRE: *(unsigned char *)arg.p = cnt; break; - case ZTPRE: *(size_t *)arg.p = cnt; break; - case JPRE: *(uintmax_t *)arg.p = cnt; break; - } - continue; - case 'c': - fputwc(btowc(arg.i), f); - l = 1; - continue; - case 'C': - fputwc(arg.i, f); - l = 1; - continue; - case 'S': - a = arg.p; - z = a + wcsnlen(a, p<0 ? INT_MAX : p); - if (p<0 && *z) goto overflow; - p = z-a; - if (w0; bs+=i, l++); - if (i<0) return -1; - if (p<0 && *bs) goto overflow; - p=l; - if (wflags & F_ERR; - f->flags &= ~F_ERR; - ret = wprintf_core(f, fmt, &ap2, nl_arg, nl_type); - if (f->flags & F_ERR) ret = -1; - f->flags |= olderr; - FUNLOCK(f); - va_end(ap2); - return ret; -} diff --git a/usr/lib/libc/stdio/vfwscanf.c b/usr/lib/libc/stdio/vfwscanf.c deleted file mode 100644 index 1ebc5cef5..000000000 --- a/usr/lib/libc/stdio/vfwscanf.c +++ /dev/null @@ -1,329 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "stdio_impl.h" -#include "shgetc.h" -#include "intscan.h" -#include "floatscan.h" -#include "libc.h" - -#define SIZE_hh -2 -#define SIZE_h -1 -#define SIZE_def 0 -#define SIZE_l 1 -#define SIZE_L 2 -#define SIZE_ll 3 - -static void store_int(void *dest, int size, unsigned long long i) -{ - if (!dest) return; - switch (size) { - case SIZE_hh: - *(char *)dest = i; - break; - case SIZE_h: - *(short *)dest = i; - break; - case SIZE_def: - *(int *)dest = i; - break; - case SIZE_l: - *(long *)dest = i; - break; - case SIZE_ll: - *(long long *)dest = i; - break; - } -} - -static void *arg_n(va_list ap, unsigned int n) -{ - void *p; - unsigned int i; - va_list ap2; - va_copy(ap2, ap); - for (i=n; i>1; i--) va_arg(ap2, void *); - p = va_arg(ap2, void *); - va_end(ap2); - return p; -} - -static int in_set(const wchar_t *set, int c) -{ - int j; - const wchar_t *p = set; - if (*p == '-') { - if (c=='-') return 1; - p++; - } else if (*p == ']') { - if (c==']') return 1; - p++; - } - for (; *p && *p != ']'; p++) { - if (*p=='-' && p[1] && p[1] != ']') - for (j=p++[-1]; j<*p; j++) - if (c==j) return 1; - if (c==*p) return 1; - } - return 0; -} - -#if 1 -#undef getwc -#define getwc(f) \ - ((f)->rpos < (f)->rend && *(f)->rpos < 128 ? *(f)->rpos++ : (getwc)(f)) - -#undef ungetwc -#define ungetwc(c,f) \ - ((f)->rend && (c)<128U ? *--(f)->rpos : ungetwc((c),(f))) -#endif - -int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) -{ - int width; - int size; - int alloc; - const wchar_t *p; - int c, t; - char *s; - wchar_t *wcs; - void *dest=NULL; - int invert; - int matches=0; - off_t pos = 0, cnt; - static const char size_pfx[][3] = { "hh", "h", "", "l", "L", "ll" }; - char tmp[3*sizeof(int)+10]; - const wchar_t *set; - size_t i, k; - - FLOCK(f); - - fwide(f, 1); - - for (p=fmt; *p; p++) { - - alloc = 0; - - if (iswspace(*p)) { - while (iswspace(p[1])) p++; - while (iswspace((c=getwc(f)))) pos++; - ungetwc(c, f); - continue; - } - if (*p != '%' || p[1] == '%') { - p += *p=='%'; - c = getwc(f); - if (c!=*p) { - ungetwc(c, f); - if (c<0) goto input_fail; - goto match_fail; - } - pos++; - continue; - } - - p++; - if (*p=='*') { - dest = 0; p++; - } else if (iswdigit(*p) && p[1]=='$') { - dest = arg_n(ap, *p-'0'); p+=2; - } else { - dest = va_arg(ap, void *); - } - - for (width=0; iswdigit(*p); p++) { - width = 10*width + *p - '0'; - } - - if (*p=='m') { - wcs = 0; - s = 0; - alloc = !!dest; - p++; - } else { - alloc = 0; - } - - size = SIZE_def; - switch (*p++) { - case 'h': - if (*p == 'h') p++, size = SIZE_hh; - else size = SIZE_h; - break; - case 'l': - if (*p == 'l') p++, size = SIZE_ll; - else size = SIZE_l; - break; - case 'j': - size = SIZE_ll; - break; - case 'z': - case 't': - size = SIZE_l; - break; - case 'L': - size = SIZE_L; - break; - case 'd': case 'i': case 'o': case 'u': case 'x': - case 'a': case 'e': case 'f': case 'g': - case 'A': case 'E': case 'F': case 'G': case 'X': - case 's': case 'c': case '[': - case 'S': case 'C': - case 'p': case 'n': - p--; - break; - default: - goto fmt_fail; - } - - t = *p; - - /* Transform S,C -> ls,lc */ - if ((t&0x2f)==3) { - size = SIZE_l; - t |= 32; - } - - if (t != 'n') { - if (t != '[' && (t|32) != 'c') - while (iswspace((c=getwc(f)))) pos++; - else - c=getwc(f); - if (c < 0) goto input_fail; - ungetwc(c, f); - } - - switch (t) { - case 'n': - store_int(dest, size, pos); - /* do not increment match count, etc! */ - continue; - - case 's': - case 'c': - case '[': - if (t == 'c') { - if (width<1) width = 1; - invert = 1; - set = L""; - } else if (t == 's') { - invert = 1; - static const wchar_t spaces[] = { - ' ', '\t', '\n', '\r', 11, 12, 0x0085, - 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, - 0x2006, 0x2008, 0x2009, 0x200a, - 0x2028, 0x2029, 0x205f, 0x3000, 0 }; - set = spaces; - } else { - if (*++p == '^') p++, invert = 1; - else invert = 0; - set = p; - if (*p==']') p++; - while (*p!=']') { - if (!*p) goto fmt_fail; - p++; - } - } - - s = (size == SIZE_def) ? dest : 0; - wcs = (size == SIZE_l) ? dest : 0; - - int gotmatch = 0; - - if (width < 1) width = -1; - - i = 0; - if (alloc) { - k = t=='c' ? width+1U : 31; - if (size == SIZE_l) { - wcs = malloc(k*sizeof(wchar_t)); - if (!wcs) goto alloc_fail; - } else { - s = malloc(k); - if (!s) goto alloc_fail; - } - } - while (width) { - if ((c=getwc(f))<0) break; - if (in_set(set, c) == invert) - break; - if (wcs) { - wcs[i++] = c; - if (alloc && i==k) { - k += k+1; - wchar_t *tmp = realloc(wcs, k*sizeof(wchar_t)); - if (!tmp) goto alloc_fail; - wcs = tmp; - } - } else if (size != SIZE_l) { - int l = wctomb(s?s+i:tmp, c); - if (l<0) goto input_fail; - i += l; - if (alloc && i > k-4) { - k += k+1; - char *tmp = realloc(s, k); - if (!tmp) goto alloc_fail; - s = tmp; - } - } - pos++; - width-=(width>0); - gotmatch=1; - } - if (width) { - ungetwc(c, f); - if (t == 'c' || !gotmatch) goto match_fail; - } - - if (alloc) { - if (size == SIZE_l) *(wchar_t **)dest = wcs; - else *(char **)dest = s; - } - if (t != 'c') { - if (wcs) wcs[i] = 0; - if (s) s[i] = 0; - } - break; - - case 'd': case 'i': case 'o': case 'u': case 'x': - case 'a': case 'e': case 'f': case 'g': - case 'A': case 'E': case 'F': case 'G': case 'X': - case 'p': - if (width < 1) width = 0; - snprintf(tmp, sizeof tmp, "%.*s%.0d%s%c%%lln", - 1+!dest, "%*", width, size_pfx[size+2], t); - cnt = 0; - if (fscanf(f, tmp, dest?dest:&cnt, &cnt) == -1) - goto input_fail; - else if (!cnt) - goto match_fail; - pos += cnt; - break; - default: - goto fmt_fail; - } - - if (dest) matches++; - } - if (0) { -fmt_fail: -alloc_fail: -input_fail: - if (!matches) matches--; -match_fail: - if (alloc) { - free(s); - free(wcs); - } - } - FUNLOCK(f); - return matches; -} - -weak_alias(vfwscanf,__isoc99_vfwscanf); diff --git a/usr/lib/libc/stdio/vprintf.c b/usr/lib/libc/stdio/vprintf.c deleted file mode 100644 index 30d2bffa8..000000000 --- a/usr/lib/libc/stdio/vprintf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int vprintf(const char *restrict fmt, va_list ap) -{ - return vfprintf(stdout, fmt, ap); -} diff --git a/usr/lib/libc/stdio/vscanf.c b/usr/lib/libc/stdio/vscanf.c deleted file mode 100644 index d8fc05d23..000000000 --- a/usr/lib/libc/stdio/vscanf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -int vscanf(const char *restrict fmt, va_list ap) -{ - return vfscanf(stdin, fmt, ap); -} - -weak_alias(vscanf,__isoc99_vscanf); diff --git a/usr/lib/libc/stdio/vsnprintf.c b/usr/lib/libc/stdio/vsnprintf.c deleted file mode 100644 index 5f126a8e5..000000000 --- a/usr/lib/libc/stdio/vsnprintf.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include -#include -#include -#include - -struct cookie { - char *s; - size_t n; -}; - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -static size_t sn_write(FILE *f, const unsigned char *s, size_t l) -{ - struct cookie *c = f->cookie; - size_t k = MIN(c->n, f->wpos - f->wbase); - if (k) { - memcpy(c->s, f->wbase, k); - c->s += k; - c->n -= k; - } - k = MIN(c->n, l); - if (k) { - memcpy(c->s, s, k); - c->s += k; - c->n -= k; - } - *c->s = 0; - f->wpos = f->wbase = f->buf; - /* pretend to succeed, even if we discarded extra data */ - return l; -} - -int vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap) -{ - unsigned char buf[1]; - char dummy[1]; - struct cookie c = { .s = n ? s : dummy, .n = n ? n-1 : 0 }; - FILE f = { - .lbf = EOF, - .write = sn_write, - .lock = -1, - .buf = buf, - .cookie = &c, - }; - - if (n > INT_MAX) { - errno = EOVERFLOW; - return -1; - } - - *c.s = 0; - return vfprintf(&f, fmt, ap); -} diff --git a/usr/lib/libc/stdio/vsprintf.c b/usr/lib/libc/stdio/vsprintf.c deleted file mode 100644 index c57349d4d..000000000 --- a/usr/lib/libc/stdio/vsprintf.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int vsprintf(char *restrict s, const char *restrict fmt, va_list ap) -{ - return vsnprintf(s, INT_MAX, fmt, ap); -} diff --git a/usr/lib/libc/stdio/vsscanf.c b/usr/lib/libc/stdio/vsscanf.c deleted file mode 100644 index 419481cf5..000000000 --- a/usr/lib/libc/stdio/vsscanf.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -static size_t do_read(FILE *f, unsigned char *buf, size_t len) -{ - return __string_read(f, buf, len); -} - -int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap) -{ - FILE f = { - .buf = (void *)s, .cookie = (void *)s, - .read = do_read, .lock = -1 - }; - return vfscanf(&f, fmt, ap); -} - -weak_alias(vsscanf,__isoc99_vsscanf); diff --git a/usr/lib/libc/stdio/vswprintf.c b/usr/lib/libc/stdio/vswprintf.c deleted file mode 100644 index 823ff0348..000000000 --- a/usr/lib/libc/stdio/vswprintf.c +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -#include -#include -#include -#include - -struct cookie { - wchar_t *ws; - size_t l; -}; - -static size_t sw_write(FILE *f, const unsigned char *s, size_t l) -{ - size_t l0 = l; - int i = 0; - struct cookie *c = f->cookie; - if (s!=f->wbase && sw_write(f, f->wbase, f->wpos-f->wbase)==-1) - return -1; - while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) { - s+=i; - l-=i; - c->l--; - c->ws++; - } - *c->ws = 0; - if (i < 0) { - f->wpos = f->wbase = f->wend = 0; - f->flags |= F_ERR; - return i; - } - f->wend = f->buf + f->buf_size; - f->wpos = f->wbase = f->buf; - return l0; -} - -int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap) -{ - int r; - FILE f; - unsigned char buf[256]; - struct cookie c = { s, n-1 }; - - memset(&f, 0, sizeof(FILE)); - f.lbf = EOF; - f.write = sw_write; - f.buf_size = sizeof buf; - f.buf = buf; - f.lock = -1; - f.cookie = &c; - if (!n) { - return -1; - } else if (n > INT_MAX) { - errno = EOVERFLOW; - return -1; - } - r = vfwprintf(&f, fmt, ap); - sw_write(&f, 0, 0); - return r>=n ? -1 : r; -} diff --git a/usr/lib/libc/stdio/vswscanf.c b/usr/lib/libc/stdio/vswscanf.c deleted file mode 100644 index 411dd39c9..000000000 --- a/usr/lib/libc/stdio/vswscanf.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "stdio_impl.h" -#include "libc.h" -#include - -static size_t wstring_read(FILE *f, unsigned char *buf, size_t len) -{ - const wchar_t *src = f->cookie; - size_t k; - - if (!src) return 0; - - k = wcsrtombs((void *)f->buf, &src, f->buf_size, 0); - if (k==(size_t)-1) { - f->rpos = f->rend = 0; - return 0; - } - - f->rpos = f->buf; - f->rend = f->buf + k; - f->cookie = (void *)src; - - if (!len || !k) return 0; - - *buf = *f->rpos++; - return 1; -} - -int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap) -{ - unsigned char buf[256]; - FILE f = { - .buf = buf, .buf_size = sizeof buf, - .cookie = (void *)s, - .read = wstring_read, .lock = -1 - }; - return vfwscanf(&f, fmt, ap); -} - -weak_alias(vswscanf,__isoc99_vswscanf); diff --git a/usr/lib/libc/stdio/vwprintf.c b/usr/lib/libc/stdio/vwprintf.c deleted file mode 100644 index eeeecdc7c..000000000 --- a/usr/lib/libc/stdio/vwprintf.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int vwprintf(const wchar_t *restrict fmt, va_list ap) -{ - return vfwprintf(stdout, fmt, ap); -} diff --git a/usr/lib/libc/stdio/vwscanf.c b/usr/lib/libc/stdio/vwscanf.c deleted file mode 100644 index 63c9cce10..000000000 --- a/usr/lib/libc/stdio/vwscanf.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include -#include "libc.h" - -int vwscanf(const wchar_t *restrict fmt, va_list ap) -{ - return vfwscanf(stdin, fmt, ap); -} - -weak_alias(vwscanf,__isoc99_vwscanf); diff --git a/usr/lib/libc/stdio/wprintf.c b/usr/lib/libc/stdio/wprintf.c deleted file mode 100644 index 342cd9791..000000000 --- a/usr/lib/libc/stdio/wprintf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include - -int wprintf(const wchar_t *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vwprintf(fmt, ap); - va_end(ap); - return ret; -} diff --git a/usr/lib/libc/stdio/wscanf.c b/usr/lib/libc/stdio/wscanf.c deleted file mode 100644 index 804122523..000000000 --- a/usr/lib/libc/stdio/wscanf.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -#include "libc.h" - -int wscanf(const wchar_t *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vwscanf(fmt, ap); - va_end(ap); - return ret; -} - -weak_alias(wscanf,__isoc99_wscanf); diff --git a/usr/lib/libc/stdlib.c b/usr/lib/libc/stdlib.c deleted file mode 100644 index 822e84237..000000000 --- a/usr/lib/libc/stdlib.c +++ /dev/null @@ -1,29 +0,0 @@ -#include - -int atoi(const char *s) { - int result=0, sign=1; - - if (*s == -1) { - sign = -1; - s++; - } - - while (*s >= '0' && *s <= '9') - result = result*10 + (*(s++)-'0'); - - return result*sign; -} - -int abs(int i) { - return i < 0 ? -i : i; -} - -int log2i(int n) -{ - int c = 0; - if (n <= 0) - return -1; - while (n >>= 1) - c++; - return c; -} diff --git a/usr/lib/libc/stdlib/CMakeLists.txt b/usr/lib/libc/stdlib/CMakeLists.txt deleted file mode 100644 index 8e6b23531..000000000 --- a/usr/lib/libc/stdlib/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -target_sources(c - PRIVATE - abs.c - atof.c - atoi.c - strtod.c - strtol.c -) diff --git a/usr/lib/libc/stdlib/abs.c b/usr/lib/libc/stdlib/abs.c deleted file mode 100644 index 4806d629d..000000000 --- a/usr/lib/libc/stdlib/abs.c +++ /dev/null @@ -1,4 +0,0 @@ -int abs(int a) -{ - return a>0 ? a : -a; -} diff --git a/usr/lib/libc/stdlib/atof.c b/usr/lib/libc/stdlib/atof.c deleted file mode 100644 index f7fcd8266..000000000 --- a/usr/lib/libc/stdlib/atof.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double atof(const char *s) -{ - return strtod(s, 0); -} diff --git a/usr/lib/libc/stdlib/atoi.c b/usr/lib/libc/stdlib/atoi.c deleted file mode 100644 index 9baca7b89..000000000 --- a/usr/lib/libc/stdlib/atoi.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -int atoi(const char *s) -{ - int n=0, neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - /* Compute n as a negative number to avoid overflow on INT_MIN */ - while (isdigit(*s)) - n = 10*n - (*s++ - '0'); - return neg ? n : -n; -} diff --git a/usr/lib/libc/stdlib/atol.c b/usr/lib/libc/stdlib/atol.c deleted file mode 100644 index 140ea3ea3..000000000 --- a/usr/lib/libc/stdlib/atol.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -long atol(const char *s) -{ - long n=0; - int neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - /* Compute n as a negative number to avoid overflow on LONG_MIN */ - while (isdigit(*s)) - n = 10*n - (*s++ - '0'); - return neg ? n : -n; -} diff --git a/usr/lib/libc/stdlib/atoll.c b/usr/lib/libc/stdlib/atoll.c deleted file mode 100644 index b69304895..000000000 --- a/usr/lib/libc/stdlib/atoll.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -long long atoll(const char *s) -{ - long long n=0; - int neg=0; - while (isspace(*s)) s++; - switch (*s) { - case '-': neg=1; - case '+': s++; - } - /* Compute n as a negative number to avoid overflow on LLONG_MIN */ - while (isdigit(*s)) - n = 10*n - (*s++ - '0'); - return neg ? n : -n; -} diff --git a/usr/lib/libc/stdlib/bsearch.c b/usr/lib/libc/stdlib/bsearch.c deleted file mode 100644 index 61d89367e..000000000 --- a/usr/lib/libc/stdlib/bsearch.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -void *bsearch(const void *key, const void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *)) -{ - void *try; - int sign; - while (nel > 0) { - try = (char *)base + width*(nel/2); - sign = cmp(key, try); - if (!sign) return try; - else if (nel == 1) break; - else if (sign < 0) - nel /= 2; - else { - base = try; - nel -= nel/2; - } - } - return NULL; -} diff --git a/usr/lib/libc/stdlib/div.c b/usr/lib/libc/stdlib/div.c deleted file mode 100644 index e42c1f14f..000000000 --- a/usr/lib/libc/stdlib/div.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -div_t div(int num, int den) -{ - return (div_t){ num/den, num%den }; -} diff --git a/usr/lib/libc/stdlib/ecvt.c b/usr/lib/libc/stdlib/ecvt.c deleted file mode 100644 index 797b664ec..000000000 --- a/usr/lib/libc/stdlib/ecvt.c +++ /dev/null @@ -1,20 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -char *ecvt(double x, int n, int *dp, int *sign) -{ - static char buf[16]; - char tmp[32]; - int i, j; - - if (n-1U > 15) n = 15; - sprintf(tmp, "%.*e", n-1, x); - i = *sign = (tmp[0]=='-'); - for (j=0; tmp[i]!='e'; j+=(tmp[i++]!='.')) - buf[j] = tmp[i]; - buf[j] = 0; - *dp = atoi(tmp+i+1)+1; - - return buf; -} diff --git a/usr/lib/libc/stdlib/fcvt.c b/usr/lib/libc/stdlib/fcvt.c deleted file mode 100644 index f90928fe1..000000000 --- a/usr/lib/libc/stdlib/fcvt.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include - -char *fcvt(double x, int n, int *dp, int *sign) -{ - char tmp[1500]; - int i, lz; - - if (n > 1400U) n = 1400; - sprintf(tmp, "%.*f", n, x); - i = (tmp[0] == '-'); - if (tmp[i] == '0') lz = strspn(tmp+i+2, "0"); - else lz = -(int)strcspn(tmp+i, "."); - - if (n<=lz) { - *sign = i; - *dp = 1; - if (n>14U) n = 14; - return "000000000000000"+14-n; - } - - return ecvt(x, n-lz, dp, sign); -} diff --git a/usr/lib/libc/stdlib/gcvt.c b/usr/lib/libc/stdlib/gcvt.c deleted file mode 100644 index f29bc304e..000000000 --- a/usr/lib/libc/stdlib/gcvt.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -char *gcvt(double x, int n, char *b) -{ - sprintf(b, "%.*g", n, x); - return b; -} diff --git a/usr/lib/libc/stdlib/imaxabs.c b/usr/lib/libc/stdlib/imaxabs.c deleted file mode 100644 index 810018193..000000000 --- a/usr/lib/libc/stdlib/imaxabs.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -intmax_t imaxabs(intmax_t a) -{ - return a>0 ? a : -a; -} diff --git a/usr/lib/libc/stdlib/imaxdiv.c b/usr/lib/libc/stdlib/imaxdiv.c deleted file mode 100644 index b2ce821f5..000000000 --- a/usr/lib/libc/stdlib/imaxdiv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -imaxdiv_t imaxdiv(intmax_t num, intmax_t den) -{ - return (imaxdiv_t){ num/den, num%den }; -} diff --git a/usr/lib/libc/stdlib/labs.c b/usr/lib/libc/stdlib/labs.c deleted file mode 100644 index 675b95b8e..000000000 --- a/usr/lib/libc/stdlib/labs.c +++ /dev/null @@ -1,4 +0,0 @@ -long labs(long a) -{ - return a>0 ? a : -a; -} diff --git a/usr/lib/libc/stdlib/ldiv.c b/usr/lib/libc/stdlib/ldiv.c deleted file mode 100644 index 36eb960b0..000000000 --- a/usr/lib/libc/stdlib/ldiv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -ldiv_t ldiv(long num, long den) -{ - return (ldiv_t){ num/den, num%den }; -} diff --git a/usr/lib/libc/stdlib/llabs.c b/usr/lib/libc/stdlib/llabs.c deleted file mode 100644 index bec4a03d6..000000000 --- a/usr/lib/libc/stdlib/llabs.c +++ /dev/null @@ -1,4 +0,0 @@ -long long llabs(long long a) -{ - return a>0 ? a : -a; -} diff --git a/usr/lib/libc/stdlib/lldiv.c b/usr/lib/libc/stdlib/lldiv.c deleted file mode 100644 index 7aaf7a0e6..000000000 --- a/usr/lib/libc/stdlib/lldiv.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -lldiv_t lldiv(long long num, long long den) -{ - return (lldiv_t){ num/den, num%den }; -} diff --git a/usr/lib/libc/stdlib/qsort.c b/usr/lib/libc/stdlib/qsort.c deleted file mode 100644 index 434d93507..000000000 --- a/usr/lib/libc/stdlib/qsort.c +++ /dev/null @@ -1,215 +0,0 @@ -/* Copyright (C) 2011 by Valentin Ochs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -/* Minor changes by Rich Felker for integration in musl, 2011-04-27. */ - -#include -#include -#include - -#include "atomic.h" -#define ntz(x) a_ctz_l((x)) - -typedef int (*cmpfun)(const void *, const void *); - -static inline int pntz(size_t p[2]) { - int r = ntz(p[0] - 1); - if(r != 0 || (r = 8*sizeof(size_t) + ntz(p[1])) != 8*sizeof(size_t)) { - return r; - } - return 0; -} - -static void cycle(size_t width, unsigned char* ar[], int n) -{ - unsigned char tmp[256]; - size_t l; - int i; - - if(n < 2) { - return; - } - - ar[n] = tmp; - while(width) { - l = sizeof(tmp) < width ? sizeof(tmp) : width; - memcpy(ar[n], ar[0], l); - for(i = 0; i < n; i++) { - memcpy(ar[i], ar[i + 1], l); - ar[i] += l; - } - width -= l; - } -} - -/* shl() and shr() need n > 0 */ -static inline void shl(size_t p[2], int n) -{ - if(n >= 8 * sizeof(size_t)) { - n -= 8 * sizeof(size_t); - p[1] = p[0]; - p[0] = 0; - } - p[1] <<= n; - p[1] |= p[0] >> (sizeof(size_t) * 8 - n); - p[0] <<= n; -} - -static inline void shr(size_t p[2], int n) -{ - if(n >= 8 * sizeof(size_t)) { - n -= 8 * sizeof(size_t); - p[0] = p[1]; - p[1] = 0; - } - p[0] >>= n; - p[0] |= p[1] << (sizeof(size_t) * 8 - n); - p[1] >>= n; -} - -static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[]) -{ - unsigned char *rt, *lf; - unsigned char *ar[14 * sizeof(size_t) + 1]; - int i = 1; - - ar[0] = head; - while(pshift > 1) { - rt = head - width; - lf = head - width - lp[pshift - 2]; - - if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) { - break; - } - if((*cmp)(lf, rt) >= 0) { - ar[i++] = lf; - head = lf; - pshift -= 1; - } else { - ar[i++] = rt; - head = rt; - pshift -= 2; - } - } - cycle(width, ar, i); -} - -static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[]) -{ - unsigned char *stepson, - *rt, *lf; - size_t p[2]; - unsigned char *ar[14 * sizeof(size_t) + 1]; - int i = 1; - int trail; - - p[0] = pp[0]; - p[1] = pp[1]; - - ar[0] = head; - while(p[0] != 1 || p[1] != 0) { - stepson = head - lp[pshift]; - if((*cmp)(stepson, ar[0]) <= 0) { - break; - } - if(!trusty && pshift > 1) { - rt = head - width; - lf = head - width - lp[pshift - 2]; - if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) { - break; - } - } - - ar[i++] = stepson; - head = stepson; - trail = pntz(p); - shr(p, trail); - pshift += trail; - trusty = 0; - } - if(!trusty) { - cycle(width, ar, i); - sift(head, width, cmp, pshift, lp); - } -} - -void qsort(void *base, size_t nel, size_t width, cmpfun cmp) -{ - size_t lp[12*sizeof(size_t)]; - size_t i, size = width * nel; - unsigned char *head, *high; - size_t p[2] = {1, 0}; - int pshift = 1; - int trail; - - if (!size) return; - - head = base; - high = head + size - width; - - /* Precompute Leonardo numbers, scaled by element width */ - for(lp[0]=lp[1]=width, i=2; (lp[i]=lp[i-2]+lp[i-1]+width) < size; i++); - - while(head < high) { - if((p[0] & 3) == 3) { - sift(head, width, cmp, pshift, lp); - shr(p, 2); - pshift += 2; - } else { - if(lp[pshift - 1] >= high - head) { - trinkle(head, width, cmp, p, pshift, 0, lp); - } else { - sift(head, width, cmp, pshift, lp); - } - - if(pshift == 1) { - shl(p, 1); - pshift = 0; - } else { - shl(p, pshift - 1); - pshift = 1; - } - } - - p[0] |= 1; - head += width; - } - - trinkle(head, width, cmp, p, pshift, 0, lp); - - while(pshift != 1 || p[0] != 1 || p[1] != 0) { - if(pshift <= 1) { - trail = pntz(p); - shr(p, trail); - pshift += trail; - } else { - shl(p, 2); - pshift -= 2; - p[0] ^= 7; - shr(p, 1); - trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp); - shl(p, 1); - p[0] |= 1; - trinkle(head - width, width, cmp, p, pshift, 1, lp); - } - head -= width; - } -} diff --git a/usr/lib/libc/stdlib/strtod.c b/usr/lib/libc/stdlib/strtod.c deleted file mode 100644 index 7fdb0abfb..000000000 --- a/usr/lib/libc/stdlib/strtod.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include -#include - -static long double strtox(const char *s, char **p, int prec) -{ - FILE f = { - .buf = (void *)s, .rpos = (void *)s, - .rend = (void *)-1, .lock = -1 - }; - shlim(&f, 0); - long double y = __floatscan(&f, prec, 1); - off_t cnt = shcnt(&f); - if (p) *p = cnt ? (char *)s + cnt : (char *)s; - return y; -} - -float strtof(const char *restrict s, char **restrict p) -{ - return strtox(s, p, 0); -} - -double strtod(const char *restrict s, char **restrict p) -{ - return strtox(s, p, 1); -} - -long double strtold(const char *restrict s, char **restrict p) -{ - return strtox(s, p, 2); -} - -#if 0 -weak_alias(strtof, strtof_l); -weak_alias(strtod, strtod_l); -weak_alias(strtold, strtold_l); -weak_alias(strtof, __strtof_l); -weak_alias(strtod, __strtod_l); -weak_alias(strtold, __strtold_l); -#endif - diff --git a/usr/lib/libc/stdlib/strtol.c b/usr/lib/libc/stdlib/strtol.c deleted file mode 100644 index 730bf2d7b..000000000 --- a/usr/lib/libc/stdlib/strtol.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "stdio_impl.h" -#include "intscan.h" -#include "shgetc.h" -#include -#include -#include -#include "libc.h" - -static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim) -{ - /* FIXME: use a helper function or macro to setup the FILE */ - FILE f; - f.flags = 0; - f.buf = f.rpos = (void *)s; - if ((size_t)s > (size_t)-1/2) - f.rend = (void *)-1; - else - f.rend = (unsigned char *)s+(size_t)-1/2; - f.lock = -1; - shlim(&f, 0); - unsigned long long y = __intscan(&f, base, 1, lim); - if (p) { - size_t cnt = shcnt(&f); - *p = (char *)s + cnt; - } - return y; -} - -unsigned long long strtoull(const char *restrict s, char **restrict p, int base) -{ - return strtox(s, p, base, ULLONG_MAX); -} - -long long strtoll(const char *restrict s, char **restrict p, int base) -{ - return strtox(s, p, base, LLONG_MIN); -} - -unsigned long strtoul(const char *restrict s, char **restrict p, int base) -{ - return strtox(s, p, base, ULONG_MAX); -} - -long strtol(const char *restrict s, char **restrict p, int base) -{ - return strtox(s, p, base, 0UL+LONG_MIN); -} - -intmax_t strtoimax(const char *restrict s, char **restrict p, int base) -{ - return strtoll(s, p, base); -} - -uintmax_t strtoumax(const char *restrict s, char **restrict p, int base) -{ - return strtoull(s, p, base); -} - -weak_alias(strtol, __strtol_internal); -weak_alias(strtoul, __strtoul_internal); -weak_alias(strtoll, __strtoll_internal); -weak_alias(strtoull, __strtoull_internal); -weak_alias(strtoimax, __strtoimax_internal); -weak_alias(strtoumax, __strtoumax_internal); diff --git a/usr/lib/libc/stdlib/wcstod.c b/usr/lib/libc/stdlib/wcstod.c deleted file mode 100644 index 26fe9af8b..000000000 --- a/usr/lib/libc/stdlib/wcstod.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "shgetc.h" -#include "floatscan.h" -#include "stdio_impl.h" -#include -#include - -/* This read function heavily cheats. It knows: - * (1) len will always be 1 - * (2) non-ascii characters don't matter */ - -static size_t do_read(FILE *f, unsigned char *buf, size_t len) -{ - size_t i; - const wchar_t *wcs = f->cookie; - - if (!wcs[0]) wcs=L"@"; - for (i=0; ibuf_size && wcs[i]; i++) - f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; - f->rpos = f->buf; - f->rend = f->buf + i; - f->cookie = (void *)(wcs+i); - - if (i && len) { - *buf = *f->rpos++; - return 1; - } - return 0; -} - -static long double wcstox(const wchar_t *s, wchar_t **p, int prec) -{ - wchar_t *t = (wchar_t *)s; - unsigned char buf[64]; - FILE f = {0}; - f.flags = 0; - f.rpos = f.rend = 0; - f.buf = buf + 4; - f.buf_size = sizeof buf - 4; - f.lock = -1; - f.read = do_read; - while (iswspace(*t)) t++; - f.cookie = (void *)t; - shlim(&f, 0); - long double y = __floatscan(&f, prec, 1); - if (p) { - size_t cnt = shcnt(&f); - *p = cnt ? t + cnt : (wchar_t *)s; - } - return y; -} - -float wcstof(const wchar_t *restrict s, wchar_t **restrict p) -{ - return wcstox(s, p, 0); -} - -double wcstod(const wchar_t *restrict s, wchar_t **restrict p) -{ - return wcstox(s, p, 1); -} - -long double wcstold(const wchar_t *restrict s, wchar_t **restrict p) -{ - return wcstox(s, p, 2); -} diff --git a/usr/lib/libc/stdlib/wcstol.c b/usr/lib/libc/stdlib/wcstol.c deleted file mode 100644 index 4443f5772..000000000 --- a/usr/lib/libc/stdlib/wcstol.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "stdio_impl.h" -#include "intscan.h" -#include "shgetc.h" -#include -#include -#include -#include - -/* This read function heavily cheats. It knows: - * (1) len will always be 1 - * (2) non-ascii characters don't matter */ - -static size_t do_read(FILE *f, unsigned char *buf, size_t len) -{ - size_t i; - const wchar_t *wcs = f->cookie; - - if (!wcs[0]) wcs=L"@"; - for (i=0; ibuf_size && wcs[i]; i++) - f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; - f->rpos = f->buf; - f->rend = f->buf + i; - f->cookie = (void *)(wcs+i); - - if (i && len) { - *buf = *f->rpos++; - return 1; - } - return 0; -} - -static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsigned long long lim) -{ - wchar_t *t = (wchar_t *)s; - unsigned char buf[64]; - FILE f = {0}; - f.flags = 0; - f.rpos = f.rend = 0; - f.buf = buf + 4; - f.buf_size = sizeof buf - 4; - f.lock = -1; - f.read = do_read; - while (iswspace(*t)) t++; - f.cookie = (void *)t; - shlim(&f, 0); - unsigned long long y = __intscan(&f, base, 1, lim); - if (p) { - size_t cnt = shcnt(&f); - *p = cnt ? t + cnt : (wchar_t *)s; - } - return y; -} - -unsigned long long wcstoull(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, ULLONG_MAX); -} - -long long wcstoll(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, LLONG_MIN); -} - -unsigned long wcstoul(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, ULONG_MAX); -} - -long wcstol(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, 0UL+LONG_MIN); -} - -intmax_t wcstoimax(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstoll(s, p, base); -} - -uintmax_t wcstoumax(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstoull(s, p, base); -} diff --git a/usr/lib/libc/string/CMakeLists.txt b/usr/lib/libc/string/CMakeLists.txt deleted file mode 100644 index cbbb9d719..000000000 --- a/usr/lib/libc/string/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ - -target_sources(c - PRIVATE - strcpy.c - strcmp.c - strncmp.c - strlen.c - memcpy.c - strncpy.c - memset.c - memcmp.c - strcat.c - strchrnul.c - strnlen.c - memchr.c - memmove.c - stpncpy.c - stpcpy.c - strchr.c - strrchr.c - memrchr.c - strtok.c - strspn.c - strcspn.c -) diff --git a/usr/lib/libc/string/arm/__aeabi_memclr.c b/usr/lib/libc/string/arm/__aeabi_memclr.c deleted file mode 100644 index a25306d7a..000000000 --- a/usr/lib/libc/string/arm/__aeabi_memclr.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "libc.h" - -void __aeabi_memclr(void *dest, size_t n) -{ - memset(dest, 0, n); -} -weak_alias(__aeabi_memclr, __aeabi_memclr4); -weak_alias(__aeabi_memclr, __aeabi_memclr8); diff --git a/usr/lib/libc/string/arm/__aeabi_memcpy.c b/usr/lib/libc/string/arm/__aeabi_memcpy.c deleted file mode 100644 index 4ae5c7776..000000000 --- a/usr/lib/libc/string/arm/__aeabi_memcpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "libc.h" - -void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n) -{ - memcpy(dest, src, n); -} -weak_alias(__aeabi_memcpy, __aeabi_memcpy4); -weak_alias(__aeabi_memcpy, __aeabi_memcpy8); diff --git a/usr/lib/libc/string/arm/__aeabi_memmove.c b/usr/lib/libc/string/arm/__aeabi_memmove.c deleted file mode 100644 index 951e7d395..000000000 --- a/usr/lib/libc/string/arm/__aeabi_memmove.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "libc.h" - -void __aeabi_memmove(void *dest, const void *src, size_t n) -{ - memmove(dest, src, n); -} -weak_alias(__aeabi_memmove, __aeabi_memmove4); -weak_alias(__aeabi_memmove, __aeabi_memmove8); diff --git a/usr/lib/libc/string/arm/__aeabi_memset.c b/usr/lib/libc/string/arm/__aeabi_memset.c deleted file mode 100644 index 89299757f..000000000 --- a/usr/lib/libc/string/arm/__aeabi_memset.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "libc.h" - -void __aeabi_memset(void *dest, size_t n, int c) -{ - memset(dest, c, n); -} -weak_alias(__aeabi_memset, __aeabi_memset4); -weak_alias(__aeabi_memset, __aeabi_memset8); diff --git a/usr/lib/libc/string/arm/memcpy.c b/usr/lib/libc/string/arm/memcpy.c deleted file mode 100644 index f703c9bdf..000000000 --- a/usr/lib/libc/string/arm/memcpy.c +++ /dev/null @@ -1,3 +0,0 @@ -#if __ARMEB__ || __thumb__ -#include "../memcpy.c" -#endif diff --git a/usr/lib/libc/string/arm/memcpy_le.S b/usr/lib/libc/string/arm/memcpy_le.S deleted file mode 100644 index 9cfbcb2ab..000000000 --- a/usr/lib/libc/string/arm/memcpy_le.S +++ /dev/null @@ -1,383 +0,0 @@ -#if !__ARMEB__ && !__thumb__ - -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -/* - * Optimized memcpy() for ARM. - * - * note that memcpy() always returns the destination pointer, - * so we have to preserve R0. - */ - -/* - * This file has been modified from the original for use in musl libc. - * The main changes are: addition of .type memcpy,%function to make the - * code safely callable from thumb mode, adjusting the return - * instructions to be compatible with pre-thumb ARM cpus, and removal - * of prefetch code that is not compatible with older cpus. - */ - -.syntax unified - -.global memcpy -.type memcpy,%function -memcpy: - /* The stack must always be 64-bits aligned to be compliant with the - * ARM ABI. Since we have to save R0, we might as well save R4 - * which we can use for better pipelining of the reads below - */ - .fnstart - .save {r0, r4, lr} - stmfd sp!, {r0, r4, lr} - /* Making room for r5-r11 which will be spilled later */ - .pad #28 - sub sp, sp, #28 - - /* it simplifies things to take care of len<4 early */ - cmp r2, #4 - blo copy_last_3_and_return - - /* compute the offset to align the source - * offset = (4-(src&3))&3 = -src & 3 - */ - rsb r3, r1, #0 - ands r3, r3, #3 - beq src_aligned - - /* align source to 32 bits. We need to insert 2 instructions between - * a ldr[b|h] and str[b|h] because byte and half-word instructions - * stall 2 cycles. - */ - movs r12, r3, lsl #31 - sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */ - ldrbmi r3, [r1], #1 - ldrbcs r4, [r1], #1 - ldrbcs r12,[r1], #1 - strbmi r3, [r0], #1 - strbcs r4, [r0], #1 - strbcs r12,[r0], #1 - -src_aligned: - - /* see if src and dst are aligned together (congruent) */ - eor r12, r0, r1 - tst r12, #3 - bne non_congruent - - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack - * frame. Don't update sp. - */ - stmea sp, {r5-r11} - - /* align the destination to a cache-line */ - rsb r3, r0, #0 - ands r3, r3, #0x1C - beq congruent_aligned32 - cmp r3, r2 - andhi r3, r2, #0x1C - - /* conditionnaly copies 0 to 7 words (length in r3) */ - movs r12, r3, lsl #28 - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */ - ldmmi r1!, {r8, r9} /* 8 bytes */ - stmcs r0!, {r4, r5, r6, r7} - stmmi r0!, {r8, r9} - tst r3, #0x4 - ldrne r10,[r1], #4 /* 4 bytes */ - strne r10,[r0], #4 - sub r2, r2, r3 - -congruent_aligned32: - /* - * here source is aligned to 32 bytes. - */ - -cached_aligned32: - subs r2, r2, #32 - blo less_than_32_left - - /* - * We preload a cache-line up to 64 bytes ahead. On the 926, this will - * stall only until the requested world is fetched, but the linefill - * continues in the the background. - * While the linefill is going, we write our previous cache-line - * into the write-buffer (which should have some free space). - * When the linefill is done, the writebuffer will - * start dumping its content into memory - * - * While all this is going, we then load a full cache line into - * 8 registers, this cache line should be in the cache by now - * (or partly in the cache). - * - * This code should work well regardless of the source/dest alignment. - * - */ - - /* Align the preload register to a cache-line because the cpu does - * "critical word first" (the first word requested is loaded first). - */ - @ bic r12, r1, #0x1F - @ add r12, r12, #64 - -1: ldmia r1!, { r4-r11 } - subs r2, r2, #32 - - /* - * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi - * for ARM9 preload will not be safely guarded by the preceding subs. - * When it is safely guarded the only possibility to have SIGSEGV here - * is because the caller overstates the length. - */ - @ ldrhi r3, [r12], #32 /* cheap ARM9 preload */ - stmia r0!, { r4-r11 } - bhs 1b - - add r2, r2, #32 - -less_than_32_left: - /* - * less than 32 bytes left at this point (length in r2) - */ - - /* skip all this if there is nothing to do, which should - * be a common case (if not executed the code below takes - * about 16 cycles) - */ - tst r2, #0x1F - beq 1f - - /* conditionnaly copies 0 to 31 bytes */ - movs r12, r2, lsl #28 - ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */ - ldmmi r1!, {r8, r9} /* 8 bytes */ - stmcs r0!, {r4, r5, r6, r7} - stmmi r0!, {r8, r9} - movs r12, r2, lsl #30 - ldrcs r3, [r1], #4 /* 4 bytes */ - ldrhmi r4, [r1], #2 /* 2 bytes */ - strcs r3, [r0], #4 - strhmi r4, [r0], #2 - tst r2, #0x1 - ldrbne r3, [r1] /* last byte */ - strbne r3, [r0] - - /* we're done! restore everything and return */ -1: ldmfd sp!, {r5-r11} - ldmfd sp!, {r0, r4, lr} - bx lr - - /********************************************************************/ - -non_congruent: - /* - * here source is aligned to 4 bytes - * but destination is not. - * - * in the code below r2 is the number of bytes read - * (the number of bytes written is always smaller, because we have - * partial words in the shift queue) - */ - cmp r2, #4 - blo copy_last_3_and_return - - /* Use post-incriment mode for stm to spill r5-r11 to reserved stack - * frame. Don't update sp. - */ - stmea sp, {r5-r11} - - /* compute shifts needed to align src to dest */ - rsb r5, r0, #0 - and r5, r5, #3 /* r5 = # bytes in partial words */ - mov r12, r5, lsl #3 /* r12 = right */ - rsb lr, r12, #32 /* lr = left */ - - /* read the first word */ - ldr r3, [r1], #4 - sub r2, r2, #4 - - /* write a partial word (0 to 3 bytes), such that destination - * becomes aligned to 32 bits (r5 = nb of words to copy for alignment) - */ - movs r5, r5, lsl #31 - strbmi r3, [r0], #1 - movmi r3, r3, lsr #8 - strbcs r3, [r0], #1 - movcs r3, r3, lsr #8 - strbcs r3, [r0], #1 - movcs r3, r3, lsr #8 - - cmp r2, #4 - blo partial_word_tail - - /* Align destination to 32 bytes (cache line boundary) */ -1: tst r0, #0x1c - beq 2f - ldr r5, [r1], #4 - sub r2, r2, #4 - orr r4, r3, r5, lsl lr - mov r3, r5, lsr r12 - str r4, [r0], #4 - cmp r2, #4 - bhs 1b - blo partial_word_tail - - /* copy 32 bytes at a time */ -2: subs r2, r2, #32 - blo less_than_thirtytwo - - /* Use immediate mode for the shifts, because there is an extra cycle - * for register shifts, which could account for up to 50% of - * performance hit. - */ - - cmp r12, #24 - beq loop24 - cmp r12, #8 - beq loop8 - -loop16: - ldr r12, [r1], #4 -1: mov r4, r12 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} - subs r2, r2, #32 - ldrhs r12, [r1], #4 - orr r3, r3, r4, lsl #16 - mov r4, r4, lsr #16 - orr r4, r4, r5, lsl #16 - mov r5, r5, lsr #16 - orr r5, r5, r6, lsl #16 - mov r6, r6, lsr #16 - orr r6, r6, r7, lsl #16 - mov r7, r7, lsr #16 - orr r7, r7, r8, lsl #16 - mov r8, r8, lsr #16 - orr r8, r8, r9, lsl #16 - mov r9, r9, lsr #16 - orr r9, r9, r10, lsl #16 - mov r10, r10, lsr #16 - orr r10, r10, r11, lsl #16 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsr #16 - bhs 1b - b less_than_thirtytwo - -loop8: - ldr r12, [r1], #4 -1: mov r4, r12 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} - subs r2, r2, #32 - ldrhs r12, [r1], #4 - orr r3, r3, r4, lsl #24 - mov r4, r4, lsr #8 - orr r4, r4, r5, lsl #24 - mov r5, r5, lsr #8 - orr r5, r5, r6, lsl #24 - mov r6, r6, lsr #8 - orr r6, r6, r7, lsl #24 - mov r7, r7, lsr #8 - orr r7, r7, r8, lsl #24 - mov r8, r8, lsr #8 - orr r8, r8, r9, lsl #24 - mov r9, r9, lsr #8 - orr r9, r9, r10, lsl #24 - mov r10, r10, lsr #8 - orr r10, r10, r11, lsl #24 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsr #8 - bhs 1b - b less_than_thirtytwo - -loop24: - ldr r12, [r1], #4 -1: mov r4, r12 - ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} - subs r2, r2, #32 - ldrhs r12, [r1], #4 - orr r3, r3, r4, lsl #8 - mov r4, r4, lsr #24 - orr r4, r4, r5, lsl #8 - mov r5, r5, lsr #24 - orr r5, r5, r6, lsl #8 - mov r6, r6, lsr #24 - orr r6, r6, r7, lsl #8 - mov r7, r7, lsr #24 - orr r7, r7, r8, lsl #8 - mov r8, r8, lsr #24 - orr r8, r8, r9, lsl #8 - mov r9, r9, lsr #24 - orr r9, r9, r10, lsl #8 - mov r10, r10, lsr #24 - orr r10, r10, r11, lsl #8 - stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} - mov r3, r11, lsr #24 - bhs 1b - -less_than_thirtytwo: - /* copy the last 0 to 31 bytes of the source */ - rsb r12, lr, #32 /* we corrupted r12, recompute it */ - add r2, r2, #32 - cmp r2, #4 - blo partial_word_tail - -1: ldr r5, [r1], #4 - sub r2, r2, #4 - orr r4, r3, r5, lsl lr - mov r3, r5, lsr r12 - str r4, [r0], #4 - cmp r2, #4 - bhs 1b - -partial_word_tail: - /* we have a partial word in the input buffer */ - movs r5, lr, lsl #(31-3) - strbmi r3, [r0], #1 - movmi r3, r3, lsr #8 - strbcs r3, [r0], #1 - movcs r3, r3, lsr #8 - strbcs r3, [r0], #1 - - /* Refill spilled registers from the stack. Don't update sp. */ - ldmfd sp, {r5-r11} - -copy_last_3_and_return: - movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */ - ldrbmi r2, [r1], #1 - ldrbcs r3, [r1], #1 - ldrbcs r12,[r1] - strbmi r2, [r0], #1 - strbcs r3, [r0], #1 - strbcs r12,[r0] - - /* we're done! restore sp and spilled registers and return */ - add sp, sp, #28 - ldmfd sp!, {r0, r4, lr} - bx lr - -#endif diff --git a/usr/lib/libc/string/bcmp.c b/usr/lib/libc/string/bcmp.c deleted file mode 100644 index 87c6007ee..000000000 --- a/usr/lib/libc/string/bcmp.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _BSD_SOURCE -#include -#include - -int bcmp(const void *s1, const void *s2, size_t n) -{ - return memcmp(s1, s2, n); -} diff --git a/usr/lib/libc/string/bcopy.c b/usr/lib/libc/string/bcopy.c deleted file mode 100644 index a07129f50..000000000 --- a/usr/lib/libc/string/bcopy.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _BSD_SOURCE -#include -#include - -void bcopy(const void *s1, void *s2, size_t n) -{ - memmove(s2, s1, n); -} diff --git a/usr/lib/libc/string/bzero.c b/usr/lib/libc/string/bzero.c deleted file mode 100644 index ba536b07e..000000000 --- a/usr/lib/libc/string/bzero.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _BSD_SOURCE -#include -#include - -void bzero(void *s, size_t n) -{ - memset(s, 0, n); -} diff --git a/usr/lib/libc/string/index.c b/usr/lib/libc/string/index.c deleted file mode 100644 index 252948f9f..000000000 --- a/usr/lib/libc/string/index.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _BSD_SOURCE -#include -#include - -char *index(const char *s, int c) -{ - return strchr(s, c); -} diff --git a/usr/lib/libc/string/memccpy.c b/usr/lib/libc/string/memccpy.c deleted file mode 100644 index 7c233d5e9..000000000 --- a/usr/lib/libc/string/memccpy.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n) -{ - unsigned char *d = dest; - const unsigned char *s = src; - size_t *wd, k; - const size_t *ws; - - c = (unsigned char)c; - if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s)!=c; n--, s++, d++); - if ((uintptr_t)s & ALIGN) goto tail; - k = ONES * c; - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws^k); - n-=sizeof(size_t), ws++, wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } - for (; n && (*d=*s)!=c; n--, s++, d++); -tail: - if (*s==c) return d+1; - return 0; -} diff --git a/usr/lib/libc/string/memchr.c b/usr/lib/libc/string/memchr.c deleted file mode 100644 index b8f91298c..000000000 --- a/usr/lib/libc/string/memchr.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -#define SS (sizeof(size_t)) -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-(ONES & ~(x) & HIGHS)) - -void *memchr(const void *src, int c, size_t n) -{ - const unsigned char *s = src; - c = (unsigned char)c; - for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--); - if (n && *s != c) { - const size_t *w; - size_t k = ONES * c; - for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS); - for (s = (const void *)w; n && *s != c; s++, n--); - } - return n ? (void *)s : 0; -} diff --git a/usr/lib/libc/string/memcmp.c b/usr/lib/libc/string/memcmp.c deleted file mode 100644 index bdbce9f0f..000000000 --- a/usr/lib/libc/string/memcmp.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int memcmp(const void *vl, const void *vr, size_t n) -{ - const unsigned char *l=vl, *r=vr; - for (; n && *l == *r; n--, l++, r++); - return n ? *l-*r : 0; -} diff --git a/usr/lib/libc/string/memcpy.c b/usr/lib/libc/string/memcpy.c deleted file mode 100644 index 06e88742b..000000000 --- a/usr/lib/libc/string/memcpy.c +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include -#include - -void *memcpy(void *restrict dest, const void *restrict src, size_t n) -{ - unsigned char *d = dest; - const unsigned char *s = src; - -#ifdef __GNUC__ - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define LS >> -#define RS << -#else -#define LS << -#define RS >> -#endif - - typedef uint32_t __attribute__((__may_alias__)) u32; - uint32_t w, x; - - for (; (uintptr_t)s % 4 && n; n--) *d++ = *s++; - - if ((uintptr_t)d % 4 == 0) { - for (; n>=16; s+=16, d+=16, n-=16) { - *(u32 *)(d+0) = *(u32 *)(s+0); - *(u32 *)(d+4) = *(u32 *)(s+4); - *(u32 *)(d+8) = *(u32 *)(s+8); - *(u32 *)(d+12) = *(u32 *)(s+12); - } - if (n&8) { - *(u32 *)(d+0) = *(u32 *)(s+0); - *(u32 *)(d+4) = *(u32 *)(s+4); - d += 8; s += 8; - } - if (n&4) { - *(u32 *)(d+0) = *(u32 *)(s+0); - d += 4; s += 4; - } - if (n&2) { - *d++ = *s++; *d++ = *s++; - } - if (n&1) { - *d = *s; - } - return dest; - } - - if (n >= 32) switch ((uintptr_t)d % 4) { - case 1: - w = *(u32 *)s; - *d++ = *s++; - *d++ = *s++; - *d++ = *s++; - n -= 3; - for (; n>=17; s+=16, d+=16, n-=16) { - x = *(u32 *)(s+1); - *(u32 *)(d+0) = (w LS 24) | (x RS 8); - w = *(u32 *)(s+5); - *(u32 *)(d+4) = (x LS 24) | (w RS 8); - x = *(u32 *)(s+9); - *(u32 *)(d+8) = (w LS 24) | (x RS 8); - w = *(u32 *)(s+13); - *(u32 *)(d+12) = (x LS 24) | (w RS 8); - } - break; - case 2: - w = *(u32 *)s; - *d++ = *s++; - *d++ = *s++; - n -= 2; - for (; n>=18; s+=16, d+=16, n-=16) { - x = *(u32 *)(s+2); - *(u32 *)(d+0) = (w LS 16) | (x RS 16); - w = *(u32 *)(s+6); - *(u32 *)(d+4) = (x LS 16) | (w RS 16); - x = *(u32 *)(s+10); - *(u32 *)(d+8) = (w LS 16) | (x RS 16); - w = *(u32 *)(s+14); - *(u32 *)(d+12) = (x LS 16) | (w RS 16); - } - break; - case 3: - w = *(u32 *)s; - *d++ = *s++; - n -= 1; - for (; n>=19; s+=16, d+=16, n-=16) { - x = *(u32 *)(s+3); - *(u32 *)(d+0) = (w LS 8) | (x RS 24); - w = *(u32 *)(s+7); - *(u32 *)(d+4) = (x LS 8) | (w RS 24); - x = *(u32 *)(s+11); - *(u32 *)(d+8) = (w LS 8) | (x RS 24); - w = *(u32 *)(s+15); - *(u32 *)(d+12) = (x LS 8) | (w RS 24); - } - break; - } - if (n&16) { - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - } - if (n&8) { - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - } - if (n&4) { - *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; - } - if (n&2) { - *d++ = *s++; *d++ = *s++; - } - if (n&1) { - *d = *s; - } - return dest; -#endif - - for (; n; n--) *d++ = *s++; - return dest; -} diff --git a/usr/lib/libc/string/memmem.c b/usr/lib/libc/string/memmem.c deleted file mode 100644 index 4be6a310a..000000000 --- a/usr/lib/libc/string/memmem.c +++ /dev/null @@ -1,149 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) -{ - uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; - for (h++, k--; k; k--, hw = hw<<8 | *++h) - if (hw == nw) return (char *)h-1; - return 0; -} - -static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) -{ - uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8; - uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8; - for (h+=2, k-=2; k; k--, hw = (hw|*++h)<<8) - if (hw == nw) return (char *)h-2; - return 0; -} - -static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) -{ - uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; - uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; - for (h+=3, k-=3; k; k--, hw = hw<<8 | *++h) - if (hw == nw) return (char *)h-3; - return 0; -} - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const unsigned char *n, size_t l) -{ - size_t i, ip, jp, k, p, ms, p0, mem, mem0; - size_t byteset[32 / sizeof(size_t)] = { 0 }; - size_t shift[256]; - - /* Computing length of needle and fill shift table */ - for (i=0; i n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (memcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Search loop */ - for (;;) { - /* If remainder of haystack is shorter than needle, done */ - if (z-h < l) return 0; - - /* Check last byte first; advance by shift on mismatch */ - if (BITOP(byteset, h[l-1], &)) { - k = l-shift[h[l-1]]; - if (k) { - if (mem0 && mem && k < p) k = l-p; - h += k; - mem = 0; - continue; - } - } else { - h += l; - mem = 0; - continue; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); kmem && n[k-1] == h[k-1]; k--); - if (k <= mem) return (char *)h; - h += p; - mem = mem0; - } -} - -void *memmem(const void *h0, size_t k, const void *n0, size_t l) -{ - const unsigned char *h = h0, *n = n0; - - /* Return immediately on empty needle */ - if (!l) return (void *)h; - - /* Return immediately when needle is longer than haystack */ - if (k -#include - -#define WT size_t -#define WS (sizeof(WT)) - -void *memmove(void *dest, const void *src, size_t n) -{ - char *d = dest; - const char *s = src; - - if (d==s) return d; - if (s+n <= d || d+n <= s) return memcpy(d, s, n); - - if (d=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s; - } - for (; n; n--) *d++ = *s++; - } else { - if ((uintptr_t)s % WS == (uintptr_t)d % WS) { - while ((uintptr_t)(d+n) % WS) { - if (!n--) return dest; - d[n] = s[n]; - } - while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n); - } - while (n) n--, d[n] = s[n]; - } - - return dest; -} diff --git a/usr/lib/libc/string/mempcpy.c b/usr/lib/libc/string/mempcpy.c deleted file mode 100644 index a297985e6..000000000 --- a/usr/lib/libc/string/mempcpy.c +++ /dev/null @@ -1,7 +0,0 @@ -#define _GNU_SOURCE -#include - -void *mempcpy(void *dest, const void *src, size_t n) -{ - return (char *)memcpy(dest, src, n) + n; -} diff --git a/usr/lib/libc/string/memrchr.c b/usr/lib/libc/string/memrchr.c deleted file mode 100644 index a78e9d6ca..000000000 --- a/usr/lib/libc/string/memrchr.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "libc.h" - -void *__memrchr(const void *m, int c, size_t n) -{ - const unsigned char *s = m; - c = (unsigned char)c; - while (n--) if (s[n]==c) return (void *)(s+n); - return 0; -} - -weak_alias(__memrchr, memrchr); diff --git a/usr/lib/libc/string/memset.c b/usr/lib/libc/string/memset.c deleted file mode 100644 index f438b073a..000000000 --- a/usr/lib/libc/string/memset.c +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include - -void *memset(void *dest, int c, size_t n) -{ - unsigned char *s = dest; - size_t k; - - /* Fill head and tail with minimal branching. Each - * conditional ensures that all the subsequently used - * offsets are well-defined and in the dest region. */ - - if (!n) return dest; - s[0] = s[n-1] = c; - if (n <= 2) return dest; - s[1] = s[n-2] = c; - s[2] = s[n-3] = c; - if (n <= 6) return dest; - s[3] = s[n-4] = c; - if (n <= 8) return dest; - - /* Advance pointer to align it at a 4-byte boundary, - * and truncate n to a multiple of 4. The previous code - * already took care of any head/tail that get cut off - * by the alignment. */ - - k = -(uintptr_t)s & 3; - s += k; - n -= k; - n &= -4; - -#ifdef __GNUC__ - typedef uint32_t __attribute__((__may_alias__)) u32; - typedef uint64_t __attribute__((__may_alias__)) u64; - - u32 c32 = ((u32)-1)/255 * (unsigned char)c; - - /* In preparation to copy 32 bytes at a time, aligned on - * an 8-byte bounary, fill head/tail up to 28 bytes each. - * As in the initial byte-based head/tail fill, each - * conditional below ensures that the subsequent offsets - * are valid (e.g. !(n<=24) implies n>=28). */ - - *(u32 *)(s+0) = c32; - *(u32 *)(s+n-4) = c32; - if (n <= 8) return dest; - *(u32 *)(s+4) = c32; - *(u32 *)(s+8) = c32; - *(u32 *)(s+n-12) = c32; - *(u32 *)(s+n-8) = c32; - if (n <= 24) return dest; - *(u32 *)(s+12) = c32; - *(u32 *)(s+16) = c32; - *(u32 *)(s+20) = c32; - *(u32 *)(s+24) = c32; - *(u32 *)(s+n-28) = c32; - *(u32 *)(s+n-24) = c32; - *(u32 *)(s+n-20) = c32; - *(u32 *)(s+n-16) = c32; - - /* Align to a multiple of 8 so we can fill 64 bits at a time, - * and avoid writing the same bytes twice as much as is - * practical without introducing additional branching. */ - - k = 24 + ((uintptr_t)s & 4); - s += k; - n -= k; - - /* If this loop is reached, 28 tail bytes have already been - * filled, so any remainder when n drops below 32 can be - * safely ignored. */ - - u64 c64 = c32 | ((u64)c32 << 32); - for (; n >= 32; n-=32, s+=32) { - *(u64 *)(s+0) = c64; - *(u64 *)(s+8) = c64; - *(u64 *)(s+16) = c64; - *(u64 *)(s+24) = c64; - } -#else - /* Pure C fallback with no aliasing violations. */ - for (; n; n--, s++) *s = c; -#endif - - return dest; -} diff --git a/usr/lib/libc/string/rindex.c b/usr/lib/libc/string/rindex.c deleted file mode 100644 index 693c750b6..000000000 --- a/usr/lib/libc/string/rindex.c +++ /dev/null @@ -1,8 +0,0 @@ -#define _BSD_SOURCE -#include -#include - -char *rindex(const char *s, int c) -{ - return strrchr(s, c); -} diff --git a/usr/lib/libc/string/stpcpy.c b/usr/lib/libc/string/stpcpy.c deleted file mode 100644 index d416bc4b7..000000000 --- a/usr/lib/libc/string/stpcpy.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include - -#define ALIGN (sizeof(size_t)) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-(ONES & ~(x) & HIGHS)) - -char *__stpcpy(char *restrict d, const char *restrict s) -{ - size_t *wd; - const size_t *ws; - - if ((uintptr_t)s % ALIGN == (uintptr_t)d % ALIGN) { - for (; (uintptr_t)s % ALIGN; s++, d++) - if (!(*d=*s)) return d; - wd=(void *)d; ws=(const void *)s; - for (; !HASZERO(*ws); *wd++ = *ws++); - d=(void *)wd; s=(const void *)ws; - } - for (; (*d=*s); s++, d++); - - return d; -} - -weak_alias(__stpcpy, stpcpy); diff --git a/usr/lib/libc/string/stpncpy.c b/usr/lib/libc/string/stpncpy.c deleted file mode 100644 index 9c243bec9..000000000 --- a/usr/lib/libc/string/stpncpy.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-(ONES & ~(x) & HIGHS)) - -char *__stpncpy(char *restrict d, const char *restrict s, size_t n) -{ - size_t *wd; - const size_t *ws; - - if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); - if (!n || !*s) goto tail; - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws); - n-=sizeof(size_t), ws++, wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } - for (; n && (*d=*s); n--, s++, d++); -tail: - memset(d, 0, n); - return d; -} - -weak_alias(__stpncpy, stpncpy); - diff --git a/usr/lib/libc/string/strcasecmp.c b/usr/lib/libc/string/strcasecmp.c deleted file mode 100644 index 3cd5f2d02..000000000 --- a/usr/lib/libc/string/strcasecmp.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include "libc.h" - -int strcasecmp(const char *_l, const char *_r) -{ - const unsigned char *l=(void *)_l, *r=(void *)_r; - for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++); - return tolower(*l) - tolower(*r); -} - -int __strcasecmp_l(const char *l, const char *r, locale_t loc) -{ - return strcasecmp(l, r); -} - -weak_alias(__strcasecmp_l, strcasecmp_l); diff --git a/usr/lib/libc/string/strcasestr.c b/usr/lib/libc/string/strcasestr.c deleted file mode 100644 index af109f361..000000000 --- a/usr/lib/libc/string/strcasestr.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _GNU_SOURCE -#include - -char *strcasestr(const char *h, const char *n) -{ - size_t l = strlen(n); - for (; *h; h++) if (!strncasecmp(h, n, l)) return (char *)h; - return 0; -} diff --git a/usr/lib/libc/string/strcat.c b/usr/lib/libc/string/strcat.c deleted file mode 100644 index 33f749b1d..000000000 --- a/usr/lib/libc/string/strcat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -char *strcat(char *restrict dest, const char *restrict src) -{ - strcpy(dest + strlen(dest), src); - return dest; -} diff --git a/usr/lib/libc/string/strchr.c b/usr/lib/libc/string/strchr.c deleted file mode 100644 index bfae8f9f8..000000000 --- a/usr/lib/libc/string/strchr.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char *__strchrnul(const char *, int); - -char *strchr(const char *s, int c) -{ - char *r = __strchrnul(s, c); - return *(unsigned char *)r == (unsigned char)c ? r : 0; -} diff --git a/usr/lib/libc/string/strchrnul.c b/usr/lib/libc/string/strchrnul.c deleted file mode 100644 index f0df335fa..000000000 --- a/usr/lib/libc/string/strchrnul.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include -#include - -#define ALIGN (sizeof(size_t)) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-(ONES & ~(x) & HIGHS)) - -char *__strchrnul(const char *s, int c) -{ - size_t *w, k; - - c = (unsigned char)c; - if (!c) return (char *)s + strlen(s); - - for (; (uintptr_t)s % ALIGN; s++) - if (!*s || *(unsigned char *)s == c) return (char *)s; - k = ONES * c; - for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++); - for (s = (void *)w; *s && *(unsigned char *)s != c; s++); - return (char *)s; -} - -weak_alias(__strchrnul, strchrnul); diff --git a/usr/lib/libc/string/strcmp.c b/usr/lib/libc/string/strcmp.c deleted file mode 100644 index 808bd8370..000000000 --- a/usr/lib/libc/string/strcmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int strcmp(const char *l, const char *r) -{ - for (; *l==*r && *l; l++, r++); - return *(unsigned char *)l - *(unsigned char *)r; -} diff --git a/usr/lib/libc/string/strcpy.c b/usr/lib/libc/string/strcpy.c deleted file mode 100644 index 7675e9cea..000000000 --- a/usr/lib/libc/string/strcpy.c +++ /dev/null @@ -1,16 +0,0 @@ -#include - -char *__stpcpy(char *, const char *); - -char *strcpy(char *dest, const char *src) -{ -#if 1 - __stpcpy(dest, src); - return dest; -#else - const unsigned char *s = src; - unsigned char *d = dest; - while ((*d++ = *s++)); - return dest; -#endif -} diff --git a/usr/lib/libc/string/strcspn.c b/usr/lib/libc/string/strcspn.c deleted file mode 100644 index cfdba114c..000000000 --- a/usr/lib/libc/string/strcspn.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -char *__strchrnul(const char *, int); - -size_t strcspn(const char *s, const char *c) -{ - const char *a = s; - size_t byteset[32/sizeof(size_t)]; - - if (!c[0] || !c[1]) return __strchrnul(s, *c)-a; - - memset(byteset, 0, sizeof byteset); - for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); - for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++); - return s-a; -} diff --git a/usr/lib/libc/string/strdup.c b/usr/lib/libc/string/strdup.c deleted file mode 100644 index dd5f80c1c..000000000 --- a/usr/lib/libc/string/strdup.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "libc.h" - -char *__strdup(const char *s) -{ - size_t l = strlen(s); - char *d = malloc(l+1); - if (!d) return NULL; - return memcpy(d, s, l+1); -} - -weak_alias(__strdup, strdup); diff --git a/usr/lib/libc/string/strerror_r.c b/usr/lib/libc/string/strerror_r.c deleted file mode 100644 index da26b4fe9..000000000 --- a/usr/lib/libc/string/strerror_r.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include "libc.h" - -int strerror_r(int err, char *buf, size_t buflen) -{ - char *msg = strerror(err); - size_t l = strlen(msg); - if (l >= buflen) { - if (buflen) { - memcpy(buf, msg, buflen-1); - buf[buflen-1] = 0; - } - return ERANGE; - } - memcpy(buf, msg, l+1); - return 0; -} - -weak_alias(strerror_r, __xpg_strerror_r); diff --git a/usr/lib/libc/string/strlcat.c b/usr/lib/libc/string/strlcat.c deleted file mode 100644 index ef81209e3..000000000 --- a/usr/lib/libc/string/strlcat.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _BSD_SOURCE -#include - -size_t strlcat(char *d, const char *s, size_t n) -{ - size_t l = strnlen(d, n); - if (l == n) return l + strlen(s); - return l + strlcpy(d+l, s, n-l); -} diff --git a/usr/lib/libc/string/strlcpy.c b/usr/lib/libc/string/strlcpy.c deleted file mode 100644 index 193d72413..000000000 --- a/usr/lib/libc/string/strlcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include -#include "libc.h" - -#define ALIGN (sizeof(size_t)-1) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) - -size_t strlcpy(char *d, const char *s, size_t n) -{ - char *d0 = d; - size_t *wd; - const size_t *ws; - - if (!n--) goto finish; - if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { - for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); - if (n && *s) { - wd=(void *)d; ws=(const void *)s; - for (; n>=sizeof(size_t) && !HASZERO(*ws); - n-=sizeof(size_t), ws++, wd++) *wd = *ws; - d=(void *)wd; s=(const void *)ws; - } - } - for (; n && (*d=*s); n--, s++, d++); - *d = 0; -finish: - return d-d0 + strlen(s); -} diff --git a/usr/lib/libc/string/strlen.c b/usr/lib/libc/string/strlen.c deleted file mode 100644 index e114c14da..000000000 --- a/usr/lib/libc/string/strlen.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -#define ALIGN (sizeof(size_t)) -#define ONES ((size_t)-1/UCHAR_MAX) -#define HIGHS (ONES * (UCHAR_MAX/2+1)) -#define HASZERO(x) ((x)-(ONES & ~(x) & HIGHS)) - -size_t strlen(const char *s) -{ - int i = 0; - - while (*s != 0) { - i++; - s++; - } - - return i; - -#if 0 /* Does not work */ - const char *a = s; - const size_t *w; - if (!*s) - return 0; - for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a; - for (w = (const void *)s; !HASZERO(*w); w++); - for (s = (const void *)w; *s; s++); - return s-a; -#endif -} diff --git a/usr/lib/libc/string/strncasecmp.c b/usr/lib/libc/string/strncasecmp.c deleted file mode 100644 index 3af530087..000000000 --- a/usr/lib/libc/string/strncasecmp.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include "libc.h" - -int strncasecmp(const char *_l, const char *_r, size_t n) -{ - const unsigned char *l=(void *)_l, *r=(void *)_r; - if (!n--) return 0; - for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--); - return tolower(*l) - tolower(*r); -} - -int __strncasecmp_l(const char *l, const char *r, size_t n, locale_t loc) -{ - return strncasecmp(l, r, n); -} - -weak_alias(__strncasecmp_l, strncasecmp_l); diff --git a/usr/lib/libc/string/strncat.c b/usr/lib/libc/string/strncat.c deleted file mode 100644 index 01ca2a231..000000000 --- a/usr/lib/libc/string/strncat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -char *strncat(char *restrict d, const char *restrict s, size_t n) -{ - char *a = d; - d += strlen(d); - while (n && *s) n--, *d++ = *s++; - *d++ = 0; - return a; -} diff --git a/usr/lib/libc/string/strncmp.c b/usr/lib/libc/string/strncmp.c deleted file mode 100644 index e228843f0..000000000 --- a/usr/lib/libc/string/strncmp.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int strncmp(const char *_l, const char *_r, size_t n) -{ - const unsigned char *l=(void *)_l, *r=(void *)_r; - if (!n--) return 0; - for (; *l && *r && n && *l == *r ; l++, r++, n--); - return *l - *r; -} diff --git a/usr/lib/libc/string/strncpy.c b/usr/lib/libc/string/strncpy.c deleted file mode 100644 index 441ba0335..000000000 --- a/usr/lib/libc/string/strncpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char *__stpncpy(char *, const char *, size_t); - -char *strncpy(char *restrict d, const char *restrict s, size_t n) -{ - __stpncpy(d, s, n); - return d; -} diff --git a/usr/lib/libc/string/strndup.c b/usr/lib/libc/string/strndup.c deleted file mode 100644 index 617d27ba9..000000000 --- a/usr/lib/libc/string/strndup.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -char *strndup(const char *s, size_t n) -{ - size_t l = strnlen(s, n); - char *d = malloc(l+1); - if (!d) return NULL; - memcpy(d, s, l); - d[l] = 0; - return d; -} diff --git a/usr/lib/libc/string/strnlen.c b/usr/lib/libc/string/strnlen.c deleted file mode 100644 index 6442eb793..000000000 --- a/usr/lib/libc/string/strnlen.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -size_t strnlen(const char *s, size_t n) -{ - const char *p = memchr(s, 0, n); - return p ? p-s : n; -} diff --git a/usr/lib/libc/string/strpbrk.c b/usr/lib/libc/string/strpbrk.c deleted file mode 100644 index 55947c641..000000000 --- a/usr/lib/libc/string/strpbrk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -char *strpbrk(const char *s, const char *b) -{ - s += strcspn(s, b); - return *s ? (char *)s : 0; -} diff --git a/usr/lib/libc/string/strrchr.c b/usr/lib/libc/string/strrchr.c deleted file mode 100644 index 635fb3c1d..000000000 --- a/usr/lib/libc/string/strrchr.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -void *__memrchr(const void *, int, size_t); - -char *strrchr(const char *s, int c) -{ - return __memrchr(s, c, strlen(s) + 1); -} diff --git a/usr/lib/libc/string/strsep.c b/usr/lib/libc/string/strsep.c deleted file mode 100644 index cb37c32eb..000000000 --- a/usr/lib/libc/string/strsep.c +++ /dev/null @@ -1,13 +0,0 @@ -#define _GNU_SOURCE -#include - -char *strsep(char **str, const char *sep) -{ - char *s = *str, *end; - if (!s) return NULL; - end = s + strcspn(s, sep); - if (*end) *end++ = 0; - else end = 0; - *str = end; - return s; -} diff --git a/usr/lib/libc/string/strsignal.c b/usr/lib/libc/string/strsignal.c deleted file mode 100644 index 96bfe841f..000000000 --- a/usr/lib/libc/string/strsignal.c +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include "locale_impl.h" - -#if (SIGHUP == 1) && (SIGINT == 2) && (SIGQUIT == 3) && (SIGILL == 4) \ - && (SIGTRAP == 5) && (SIGABRT == 6) && (SIGBUS == 7) && (SIGFPE == 8) \ - && (SIGKILL == 9) && (SIGUSR1 == 10) && (SIGSEGV == 11) && (SIGUSR2 == 12) \ - && (SIGPIPE == 13) && (SIGALRM == 14) && (SIGTERM == 15) && (SIGSTKFLT == 16) \ - && (SIGCHLD == 17) && (SIGCONT == 18) && (SIGSTOP == 19) && (SIGTSTP == 20) \ - && (SIGTTIN == 21) && (SIGTTOU == 22) && (SIGURG == 23) && (SIGXCPU == 24) \ - && (SIGXFSZ == 25) && (SIGVTALRM == 26) && (SIGPROF == 27) && (SIGWINCH == 28) \ - && (SIGPOLL == 29) && (SIGPWR == 30) && (SIGSYS == 31) - -#define sigmap(x) x - -#else - -static const char map[] = { - [SIGHUP] = 1, - [SIGINT] = 2, - [SIGQUIT] = 3, - [SIGILL] = 4, - [SIGTRAP] = 5, - [SIGABRT] = 6, - [SIGBUS] = 7, - [SIGFPE] = 8, - [SIGKILL] = 9, - [SIGUSR1] = 10, - [SIGSEGV] = 11, - [SIGUSR2] = 12, - [SIGPIPE] = 13, - [SIGALRM] = 14, - [SIGTERM] = 15, - [SIGSTKFLT] = 16, - [SIGCHLD] = 17, - [SIGCONT] = 18, - [SIGSTOP] = 19, - [SIGTSTP] = 20, - [SIGTTIN] = 21, - [SIGTTOU] = 22, - [SIGURG] = 23, - [SIGXCPU] = 24, - [SIGXFSZ] = 25, - [SIGVTALRM] = 26, - [SIGPROF] = 27, - [SIGWINCH] = 28, - [SIGPOLL] = 29, - [SIGPWR] = 30, - [SIGSYS] = 31 -}; - -#define sigmap(x) ((x) >= sizeof map ? (x) : map[(x)]) - -#endif - -static const char strings[] = - "Unknown signal\0" - "Hangup\0" - "Interrupt\0" - "Quit\0" - "Illegal instruction\0" - "Trace/breakpoint trap\0" - "Aborted\0" - "Bus error\0" - "Arithmetic exception\0" - "Killed\0" - "User defined signal 1\0" - "Segmentation fault\0" - "User defined signal 2\0" - "Broken pipe\0" - "Alarm clock\0" - "Terminated\0" - "Stack fault\0" - "Child process status\0" - "Continued\0" - "Stopped (signal)\0" - "Stopped\0" - "Stopped (tty input)\0" - "Stopped (tty output)\0" - "Urgent I/O condition\0" - "CPU time limit exceeded\0" - "File size limit exceeded\0" - "Virtual timer expired\0" - "Profiling timer expired\0" - "Window changed\0" - "I/O possible\0" - "Power failure\0" - "Bad system call\0" - "RT32" - "\0RT33\0RT34\0RT35\0RT36\0RT37\0RT38\0RT39\0RT40" - "\0RT41\0RT42\0RT43\0RT44\0RT45\0RT46\0RT47\0RT48" - "\0RT49\0RT50\0RT51\0RT52\0RT53\0RT54\0RT55\0RT56" - "\0RT57\0RT58\0RT59\0RT60\0RT61\0RT62\0RT63\0RT64" -#if _NSIG > 65 - "\0RT65\0RT66\0RT67\0RT68\0RT69\0RT70\0RT71\0RT72" - "\0RT73\0RT74\0RT75\0RT76\0RT77\0RT78\0RT79\0RT80" - "\0RT81\0RT82\0RT83\0RT84\0RT85\0RT86\0RT87\0RT88" - "\0RT89\0RT90\0RT91\0RT92\0RT93\0RT94\0RT95\0RT96" - "\0RT97\0RT98\0RT99\0RT100\0RT101\0RT102\0RT103\0RT104" - "\0RT105\0RT106\0RT107\0RT108\0RT109\0RT110\0RT111\0RT112" - "\0RT113\0RT114\0RT115\0RT116\0RT117\0RT118\0RT119\0RT120" - "\0RT121\0RT122\0RT123\0RT124\0RT125\0RT126\0RT127\0RT128" -#endif - ""; - -char *strsignal(int signum) -{ - const char *s = strings; - - signum = sigmap(signum); - if (signum - 1U >= _NSIG-1) signum = 0; - - for (; signum--; s++) for (; *s; s++); - - return (char *)LCTRANS_CUR(s); -} diff --git a/usr/lib/libc/string/strspn.c b/usr/lib/libc/string/strspn.c deleted file mode 100644 index 9543dad09..000000000 --- a/usr/lib/libc/string/strspn.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -size_t strspn(const char *s, const char *c) -{ - const char *a = s; - size_t byteset[32/sizeof(size_t)] = { 0 }; - - if (!c[0]) return 0; - if (!c[1]) { - for (; *s == *c; s++); - return s-a; - } - - for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); - for (; *s && BITOP(byteset, *(unsigned char *)s, &); s++); - return s-a; -} diff --git a/usr/lib/libc/string/strstr.c b/usr/lib/libc/string/strstr.c deleted file mode 100644 index cd0691275..000000000 --- a/usr/lib/libc/string/strstr.c +++ /dev/null @@ -1,155 +0,0 @@ -#include -#include - -static char *twobyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; - for (h++; *h && hw != nw; hw = hw<<8 | *++h); - return *h ? (char *)h-1 : 0; -} - -static char *threebyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8; - uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8; - for (h+=2; *h && hw != nw; hw = (hw|*++h)<<8); - return *h ? (char *)h-2 : 0; -} - -static char *fourbyte_strstr(const unsigned char *h, const unsigned char *n) -{ - uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; - uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; - for (h+=3; *h && hw != nw; hw = hw<<8 | *++h); - return *h ? (char *)h-3 : 0; -} - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -#define BITOP(a,b,op) \ - ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) - -static char *twoway_strstr(const unsigned char *h, const unsigned char *n) -{ - const unsigned char *z; - size_t l, ip, jp, k, p, ms, p0, mem, mem0; - size_t byteset[32 / sizeof(size_t)] = { 0 }; - size_t shift[256]; - - /* Computing length of needle and fill shift table */ - for (l=0; n[l] && h[l]; l++) - BITOP(byteset, n[l], |=), shift[n[l]] = l+1; - if (n[l]) return 0; /* hit the end of h */ - - /* Compute maximal suffix */ - ip = -1; jp = 0; k = p = 1; - while (jp+k n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (memcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Initialize incremental end-of-haystack pointer */ - z = h; - - /* Search loop */ - for (;;) { - /* Update incremental end-of-haystack pointer */ - if (z-h < l) { - /* Fast estimate for MIN(l,63) */ - size_t grow = l | 63; - const unsigned char *z2 = memchr(z, 0, grow); - if (z2) { - z = z2; - if (z-h < l) return 0; - } else z += grow; - } - - /* Check last byte first; advance by shift on mismatch */ - if (BITOP(byteset, h[l-1], &)) { - k = l-shift[h[l-1]]; - //printf("adv by %zu (on %c) at [%s] (%zu;l=%zu)\n", k, h[l-1], h, shift[h[l-1]], l); - if (k) { - if (mem0 && mem && k < p) k = l-p; - h += k; - mem = 0; - continue; - } - } else { - h += l; - mem = 0; - continue; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); - if (n[k]) { - h += k-ms; - mem = 0; - continue; - } - /* Compare left half */ - for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); - if (k <= mem) return (char *)h; - h += p; - mem = mem0; - } -} - -char *strstr(const char *h, const char *n) -{ - /* Return immediately on empty needle */ - if (!n[0]) return (char *)h; - - /* Use faster algorithms for short needles */ - h = strchr(h, *n); - if (!h || !n[1]) return (char *)h; - if (!h[1]) return 0; - if (!n[2]) return twobyte_strstr((void *)h, (void *)n); - if (!h[2]) return 0; - if (!n[3]) return threebyte_strstr((void *)h, (void *)n); - if (!h[3]) return 0; - if (!n[4]) return fourbyte_strstr((void *)h, (void *)n); - - return twoway_strstr((void *)h, (void *)n); -} diff --git a/usr/lib/libc/string/strtok.c b/usr/lib/libc/string/strtok.c deleted file mode 100644 index 35087902d..000000000 --- a/usr/lib/libc/string/strtok.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -char *strtok(char *restrict s, const char *restrict sep) -{ - static char *p; - if (!s && !(s = p)) return NULL; - s += strspn(s, sep); - if (!*s) return p = 0; - p = s + strcspn(s, sep); - if (*p) *p++ = 0; - else p = 0; - return s; -} diff --git a/usr/lib/libc/string/strtok_r.c b/usr/lib/libc/string/strtok_r.c deleted file mode 100644 index 862d4fe48..000000000 --- a/usr/lib/libc/string/strtok_r.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p) -{ - if (!s && !(s = *p)) return NULL; - s += strspn(s, sep); - if (!*s) return *p = 0; - *p = s + strcspn(s, sep); - if (**p) *(*p)++ = 0; - else *p = 0; - return s; -} diff --git a/usr/lib/libc/string/strverscmp.c b/usr/lib/libc/string/strverscmp.c deleted file mode 100644 index 4daf276d0..000000000 --- a/usr/lib/libc/string/strverscmp.c +++ /dev/null @@ -1,34 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -int strverscmp(const char *l0, const char *r0) -{ - const unsigned char *l = (const void *)l0; - const unsigned char *r = (const void *)r0; - size_t i, dp, j; - int z = 1; - - /* Find maximal matching prefix and track its maximal digit - * suffix and whether those digits are all zeros. */ - for (dp=i=0; l[i]==r[i]; i++) { - int c = l[i]; - if (!c) return 0; - if (!isdigit(c)) dp=i+1, z=1; - else if (c!='0') z=0; - } - - if (l[dp]!='0' && r[dp]!='0') { - /* If we're not looking at a digit sequence that began - * with a zero, longest digit string is greater. */ - for (j=i; isdigit(l[j]); j++) - if (!isdigit(r[j])) return 1; - if (isdigit(r[j])) return -1; - } else if (z && dp - -void swab(const void *restrict _src, void *restrict _dest, ssize_t n) -{ - const char *src = _src; - char *dest = _dest; - for (; n>1; n-=2) { - dest[0] = src[1]; - dest[1] = src[0]; - dest += 2; - src += 2; - } -} diff --git a/usr/lib/libc/string/wcpcpy.c b/usr/lib/libc/string/wcpcpy.c deleted file mode 100644 index ef4013433..000000000 --- a/usr/lib/libc/string/wcpcpy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -wchar_t *wcpcpy(wchar_t *restrict d, const wchar_t *restrict s) -{ - return wcscpy(d, s) + wcslen(s); -} diff --git a/usr/lib/libc/string/wcpncpy.c b/usr/lib/libc/string/wcpncpy.c deleted file mode 100644 index b667f6d6a..000000000 --- a/usr/lib/libc/string/wcpncpy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -wchar_t *wcpncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) -{ - return wcsncpy(d, s, n) + wcsnlen(s, n); -} diff --git a/usr/lib/libc/string/wcscasecmp.c b/usr/lib/libc/string/wcscasecmp.c deleted file mode 100644 index 3edeec7d3..000000000 --- a/usr/lib/libc/string/wcscasecmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int wcscasecmp(const wchar_t *l, const wchar_t *r) -{ - return wcsncasecmp(l, r, -1); -} diff --git a/usr/lib/libc/string/wcscasecmp_l.c b/usr/lib/libc/string/wcscasecmp_l.c deleted file mode 100644 index 065dd0aad..000000000 --- a/usr/lib/libc/string/wcscasecmp_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int wcscasecmp_l(const wchar_t *l, const wchar_t *r, locale_t locale) -{ - return wcscasecmp(l, r); -} diff --git a/usr/lib/libc/string/wcscat.c b/usr/lib/libc/string/wcscat.c deleted file mode 100644 index d4f00ebdf..000000000 --- a/usr/lib/libc/string/wcscat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -wchar_t *wcscat(wchar_t *restrict dest, const wchar_t *restrict src) -{ - wcscpy(dest + wcslen(dest), src); - return dest; -} diff --git a/usr/lib/libc/string/wcschr.c b/usr/lib/libc/string/wcschr.c deleted file mode 100644 index 8dfc2f318..000000000 --- a/usr/lib/libc/string/wcschr.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wcschr(const wchar_t *s, wchar_t c) -{ - if (!c) return (wchar_t *)s + wcslen(s); - for (; *s && *s != c; s++); - return *s ? (wchar_t *)s : 0; -} diff --git a/usr/lib/libc/string/wcscmp.c b/usr/lib/libc/string/wcscmp.c deleted file mode 100644 index 26eeee704..000000000 --- a/usr/lib/libc/string/wcscmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int wcscmp(const wchar_t *l, const wchar_t *r) -{ - for (; *l==*r && *l && *r; l++, r++); - return *l - *r; -} diff --git a/usr/lib/libc/string/wcscpy.c b/usr/lib/libc/string/wcscpy.c deleted file mode 100644 index 625bf53d0..000000000 --- a/usr/lib/libc/string/wcscpy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wcscpy(wchar_t *restrict d, const wchar_t *restrict s) -{ - wchar_t *a = d; - while ((*d++ = *s++)); - return a; -} diff --git a/usr/lib/libc/string/wcscspn.c b/usr/lib/libc/string/wcscspn.c deleted file mode 100644 index c4e52722e..000000000 --- a/usr/lib/libc/string/wcscspn.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -size_t wcscspn(const wchar_t *s, const wchar_t *c) -{ - const wchar_t *a; - if (!c[0]) return wcslen(s); - if (!c[1]) return (s=wcschr(a=s, *c)) ? s-a : wcslen(a); - for (a=s; *s && !wcschr(c, *s); s++); - return s-a; -} diff --git a/usr/lib/libc/string/wcsdup.c b/usr/lib/libc/string/wcsdup.c deleted file mode 100644 index dd49c1b62..000000000 --- a/usr/lib/libc/string/wcsdup.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "libc.h" - -wchar_t *wcsdup(const wchar_t *s) -{ - size_t l = wcslen(s); - wchar_t *d = malloc((l+1)*sizeof(wchar_t)); - if (!d) return NULL; - return wmemcpy(d, s, l+1); -} diff --git a/usr/lib/libc/string/wcslen.c b/usr/lib/libc/string/wcslen.c deleted file mode 100644 index 1b7b66550..000000000 --- a/usr/lib/libc/string/wcslen.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -size_t wcslen(const wchar_t *s) -{ - const wchar_t *a; - for (a=s; *s; s++); - return s-a; -} diff --git a/usr/lib/libc/string/wcsncasecmp.c b/usr/lib/libc/string/wcsncasecmp.c deleted file mode 100644 index 8fefe799c..000000000 --- a/usr/lib/libc/string/wcsncasecmp.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int wcsncasecmp(const wchar_t *l, const wchar_t *r, size_t n) -{ - if (!n--) return 0; - for (; *l && *r && n && (*l == *r || towlower(*l) == towlower(*r)); l++, r++, n--); - return towlower(*l) - towlower(*r); -} diff --git a/usr/lib/libc/string/wcsncasecmp_l.c b/usr/lib/libc/string/wcsncasecmp_l.c deleted file mode 100644 index 638724819..000000000 --- a/usr/lib/libc/string/wcsncasecmp_l.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int wcsncasecmp_l(const wchar_t *l, const wchar_t *r, size_t n, locale_t locale) -{ - return wcsncasecmp(l, r, n); -} diff --git a/usr/lib/libc/string/wcsncat.c b/usr/lib/libc/string/wcsncat.c deleted file mode 100644 index 8563f1a2a..000000000 --- a/usr/lib/libc/string/wcsncat.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -wchar_t *wcsncat(wchar_t *restrict d, const wchar_t *restrict s, size_t n) -{ - wchar_t *a = d; - d += wcslen(d); - while (n && *s) n--, *d++ = *s++; - *d++ = 0; - return a; -} diff --git a/usr/lib/libc/string/wcsncmp.c b/usr/lib/libc/string/wcsncmp.c deleted file mode 100644 index 4ab32a924..000000000 --- a/usr/lib/libc/string/wcsncmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int wcsncmp(const wchar_t *l, const wchar_t *r, size_t n) -{ - for (; n && *l==*r && *l && *r; n--, l++, r++); - return n ? *l - *r : 0; -} diff --git a/usr/lib/libc/string/wcsncpy.c b/usr/lib/libc/string/wcsncpy.c deleted file mode 100644 index 4bede04d2..000000000 --- a/usr/lib/libc/string/wcsncpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -wchar_t *wcsncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) -{ - wchar_t *a = d; - while (n && *s) n--, *d++ = *s++; - wmemset(d, 0, n); - return a; -} diff --git a/usr/lib/libc/string/wcsnlen.c b/usr/lib/libc/string/wcsnlen.c deleted file mode 100644 index a77633731..000000000 --- a/usr/lib/libc/string/wcsnlen.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -size_t wcsnlen(const wchar_t *s, size_t n) -{ - const wchar_t *z = wmemchr(s, 0, n); - if (z) n = z-s; - return n; -} diff --git a/usr/lib/libc/string/wcspbrk.c b/usr/lib/libc/string/wcspbrk.c deleted file mode 100644 index 0c72c197b..000000000 --- a/usr/lib/libc/string/wcspbrk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -wchar_t *wcspbrk(const wchar_t *s, const wchar_t *b) -{ - s += wcscspn(s, b); - return *s ? (wchar_t *)s : NULL; -} diff --git a/usr/lib/libc/string/wcsrchr.c b/usr/lib/libc/string/wcsrchr.c deleted file mode 100644 index 8961b9e2f..000000000 --- a/usr/lib/libc/string/wcsrchr.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wcsrchr(const wchar_t *s, wchar_t c) -{ - const wchar_t *p; - for (p=s+wcslen(s); p>=s && *p!=c; p--); - return p>=s ? (wchar_t *)p : 0; -} diff --git a/usr/lib/libc/string/wcsspn.c b/usr/lib/libc/string/wcsspn.c deleted file mode 100644 index 4320d8f6b..000000000 --- a/usr/lib/libc/string/wcsspn.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -size_t wcsspn(const wchar_t *s, const wchar_t *c) -{ - const wchar_t *a; - for (a=s; *s && wcschr(c, *s); s++); - return s-a; -} diff --git a/usr/lib/libc/string/wcsstr.c b/usr/lib/libc/string/wcsstr.c deleted file mode 100644 index 4caaef3c9..000000000 --- a/usr/lib/libc/string/wcsstr.c +++ /dev/null @@ -1,105 +0,0 @@ -#include - -#define MAX(a,b) ((a)>(b)?(a):(b)) -#define MIN(a,b) ((a)<(b)?(a):(b)) - -static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n) -{ - const wchar_t *z; - size_t l, ip, jp, k, p, ms, p0, mem, mem0; - - /* Computing length of needle */ - for (l=0; n[l] && h[l]; l++); - if (n[l]) return 0; /* hit the end of h */ - - /* Compute maximal suffix */ - ip = -1; jp = 0; k = p = 1; - while (jp+k n[jp+k]) { - jp += k; - k = 1; - p = jp - ip; - } else { - ip = jp++; - k = p = 1; - } - } - ms = ip; - p0 = p; - - /* And with the opposite comparison */ - ip = -1; jp = 0; k = p = 1; - while (jp+k ms+1) ms = ip; - else p = p0; - - /* Periodic needle? */ - if (wmemcmp(n, n+p, ms+1)) { - mem0 = 0; - p = MAX(ms, l-ms-1) + 1; - } else mem0 = l-p; - mem = 0; - - /* Initialize incremental end-of-haystack pointer */ - z = h; - - /* Search loop */ - for (;;) { - /* Update incremental end-of-haystack pointer */ - if (z-h < l) { - /* Fast estimate for MIN(l,63) */ - size_t grow = l | 63; - const wchar_t *z2 = wmemchr(z, 0, grow); - if (z2) { - z = z2; - if (z-h < l) return 0; - } else z += grow; - } - - /* Compare right half */ - for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); - if (n[k]) { - h += k-ms; - mem = 0; - continue; - } - /* Compare left half */ - for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); - if (k <= mem) return (wchar_t *)h; - h += p; - mem = mem0; - } -} - -wchar_t *wcsstr(const wchar_t *restrict h, const wchar_t *restrict n) -{ - /* Return immediately on empty needle or haystack */ - if (!n[0]) return (wchar_t *)h; - if (!h[0]) return 0; - - /* Use faster algorithms for short needles */ - h = wcschr(h, *n); - if (!h || !n[1]) return (wchar_t *)h; - if (!h[1]) return 0; - - return twoway_wcsstr(h, n); -} diff --git a/usr/lib/libc/string/wcstok.c b/usr/lib/libc/string/wcstok.c deleted file mode 100644 index ecc803319..000000000 --- a/usr/lib/libc/string/wcstok.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -wchar_t *wcstok(wchar_t *restrict s, const wchar_t *restrict sep, wchar_t **restrict p) -{ - if (!s && !(s = *p)) return NULL; - s += wcsspn(s, sep); - if (!*s) return *p = 0; - *p = s + wcscspn(s, sep); - if (**p) *(*p)++ = 0; - else *p = 0; - return s; -} diff --git a/usr/lib/libc/string/wcswcs.c b/usr/lib/libc/string/wcswcs.c deleted file mode 100644 index 9cfe4ac40..000000000 --- a/usr/lib/libc/string/wcswcs.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -wchar_t *wcswcs(const wchar_t *haystack, const wchar_t *needle) -{ - return wcsstr(haystack, needle); -} diff --git a/usr/lib/libc/string/wmemchr.c b/usr/lib/libc/string/wmemchr.c deleted file mode 100644 index 2bc2c2702..000000000 --- a/usr/lib/libc/string/wmemchr.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) -{ - for (; n && *s != c; n--, s++); - return n ? (wchar_t *)s : 0; -} diff --git a/usr/lib/libc/string/wmemcmp.c b/usr/lib/libc/string/wmemcmp.c deleted file mode 100644 index 2a193263c..000000000 --- a/usr/lib/libc/string/wmemcmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int wmemcmp(const wchar_t *l, const wchar_t *r, size_t n) -{ - for (; n && *l==*r; n--, l++, r++); - return n ? *l-*r : 0; -} diff --git a/usr/lib/libc/string/wmemcpy.c b/usr/lib/libc/string/wmemcpy.c deleted file mode 100644 index 52e6e6e07..000000000 --- a/usr/lib/libc/string/wmemcpy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) -{ - wchar_t *a = d; - while (n--) *d++ = *s++; - return a; -} diff --git a/usr/lib/libc/string/wmemmove.c b/usr/lib/libc/string/wmemmove.c deleted file mode 100644 index e406f3d5c..000000000 --- a/usr/lib/libc/string/wmemmove.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) -{ - wchar_t *d0 = d; - if ((size_t)(d-s) < n) - while (n--) d[n] = s[n]; - else - while (n--) *d++ = *s++; - return d0; -} diff --git a/usr/lib/libc/string/wmemset.c b/usr/lib/libc/string/wmemset.c deleted file mode 100644 index 07a037a0f..000000000 --- a/usr/lib/libc/string/wmemset.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -wchar_t *wmemset(wchar_t *d, wchar_t c, size_t n) -{ - wchar_t *ret = d; - while (n--) *d++ = c; - return ret; -} diff --git a/usr/lib/libc/syscall_ret.c b/usr/lib/libc/syscall_ret.c deleted file mode 100644 index a3f471368..000000000 --- a/usr/lib/libc/syscall_ret.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include "syscall.h" - -long __syscall_ret(unsigned long r) -{ - if (r > -4096UL) { - errno = -r; - return -1; - } - return r; -} diff --git a/usr/lib/libc/thread/CMakeLists.txt b/usr/lib/libc/thread/CMakeLists.txt deleted file mode 100644 index 62fbcd8e5..000000000 --- a/usr/lib/libc/thread/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ - -if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l") - -target_sources(c - PRIVATE - __lock.c - atomics.S - thrd_sleep.c -) - -else() - -target_sources(c - PRIVATE - __lock.c - thrd_sleep.c -) - -endif() diff --git a/usr/lib/libc/thread/__futex.c b/usr/lib/libc/thread/__futex.c deleted file mode 100644 index 96307c088..000000000 --- a/usr/lib/libc/thread/__futex.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "futex.h" -#include "syscall.h" - -int __futex(volatile int *addr, int op, int val, void *ts) -{ - return syscall(SYS_futex, addr, op, val, ts); -} diff --git a/usr/lib/libc/thread/__lock.c b/usr/lib/libc/thread/__lock.c deleted file mode 100644 index d69e2df6d..000000000 --- a/usr/lib/libc/thread/__lock.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "pthread_impl.h" - -void __lock(volatile int *l) -{ -#if 0 - if (libc.threads_minus_1) - while (a_swap(l, 1)) __wait(l, l+1, 1, 1); -#endif -} - -void __unlock(volatile int *l) -{ -#if 0 - if (l[0]) { - a_store(l, 0); - if (l[1]) __wake(l, 1, 1); - } -#endif -} diff --git a/usr/lib/libc/thread/__set_thread_area.c b/usr/lib/libc/thread/__set_thread_area.c deleted file mode 100644 index 152a6a216..000000000 --- a/usr/lib/libc/thread/__set_thread_area.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int __set_thread_area(void *p) -{ -#ifdef SYS_set_thread_area - return __syscall(SYS_set_thread_area, p); -#else - return -ENOSYS; -#endif -} diff --git a/usr/lib/libc/thread/__syscall_cp.c b/usr/lib/libc/thread/__syscall_cp.c deleted file mode 100644 index 09a2be84f..000000000 --- a/usr/lib/libc/thread/__syscall_cp.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "pthread_impl.h" -#include "syscall.h" - -__attribute__((__visibility__("hidden"))) -long __syscall_cp_c(); - -static long sccp(syscall_arg_t nr, - syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, - syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) -{ - return (__syscall)(nr, u, v, w, x, y, z); -} - -weak_alias(sccp, __syscall_cp_c); - -long (__syscall_cp)(syscall_arg_t nr, - syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, - syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) -{ - return __syscall_cp_c(nr, u, v, w, x, y, z); -} diff --git a/usr/lib/libc/thread/__timedwait.c b/usr/lib/libc/thread/__timedwait.c deleted file mode 100644 index 13d8465a4..000000000 --- a/usr/lib/libc/thread/__timedwait.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include "futex.h" -#include "syscall.h" -#include "pthread_impl.h" - -int __pthread_setcancelstate(int, int *); -int __clock_gettime(clockid_t, struct timespec *); - -int __timedwait_cp(volatile int *addr, int val, - clockid_t clk, const struct timespec *at, int priv) -{ - int r; - struct timespec to, *top=0; - - if (priv) priv = 128; - - if (at) { - if (at->tv_nsec >= 1000000000UL) return EINVAL; - if (__clock_gettime(clk, &to)) return EINVAL; - to.tv_sec = at->tv_sec - to.tv_sec; - if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) { - to.tv_sec--; - to.tv_nsec += 1000000000; - } - if (to.tv_sec < 0) return ETIMEDOUT; - top = &to; - } - - r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT|priv, val, top); - if (r == ENOSYS) r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT, val, top); - if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0; - - return r; -} - -int __timedwait(volatile int *addr, int val, - clockid_t clk, const struct timespec *at, int priv) -{ - int cs, r; - __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - r = __timedwait_cp(addr, val, clk, at, priv); - __pthread_setcancelstate(cs, 0); - return r; -} diff --git a/usr/lib/libc/thread/__tls_get_addr.c b/usr/lib/libc/thread/__tls_get_addr.c deleted file mode 100644 index 3b6c9b1b2..000000000 --- a/usr/lib/libc/thread/__tls_get_addr.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include "pthread_impl.h" -#include "libc.h" - -__attribute__((__visibility__("hidden"))) -void *__tls_get_new(tls_mod_off_t *); - -void *__tls_get_addr(tls_mod_off_t *v) -{ - pthread_t self = __pthread_self(); - if (v[0]<=(size_t)self->dtv[0]) - return (char *)self->dtv[v[0]]+v[1]+DTP_OFFSET; - return __tls_get_new(v); -} - -weak_alias(__tls_get_addr, __tls_get_new); diff --git a/usr/lib/libc/thread/__unmapself.c b/usr/lib/libc/thread/__unmapself.c deleted file mode 100644 index 1d3bee1d9..000000000 --- a/usr/lib/libc/thread/__unmapself.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "pthread_impl.h" -#include "atomic.h" -#include "syscall.h" -/* cheat and reuse CRTJMP macro from dynlink code */ -#include "dynlink.h" - -static volatile int lock; -static void *unmap_base; -static size_t unmap_size; -static char shared_stack[256]; - -static void do_unmap() -{ - __syscall(SYS_munmap, unmap_base, unmap_size); - __syscall(SYS_exit); -} - -void __unmapself(void *base, size_t size) -{ - int tid=__pthread_self()->tid; - char *stack = shared_stack + sizeof shared_stack; - stack -= (uintptr_t)stack % 16; - while (lock || a_cas(&lock, 0, tid)) - a_spin(); - __syscall(SYS_set_tid_address, &lock); - unmap_base = base; - unmap_size = size; - CRTJMP(do_unmap, stack); -} diff --git a/usr/lib/libc/thread/__wait.c b/usr/lib/libc/thread/__wait.c deleted file mode 100644 index dc33c1a30..000000000 --- a/usr/lib/libc/thread/__wait.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "pthread_impl.h" - -void __wait(volatile int *addr, volatile int *waiters, int val, int priv) -{ - int spins=100; - if (priv) priv = FUTEX_PRIVATE; - while (spins-- && (!waiters || !*waiters)) { - if (*addr==val) a_spin(); - else return; - } - if (waiters) a_inc(waiters); - while (*addr==val) { - __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS - || __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); - } - if (waiters) a_dec(waiters); -} diff --git a/usr/lib/libc/thread/atomics.S b/usr/lib/libc/thread/atomics.S deleted file mode 100644 index 101ad391e..000000000 --- a/usr/lib/libc/thread/atomics.S +++ /dev/null @@ -1,106 +0,0 @@ -.syntax unified -.text - -.global __a_barrier_dummy -.hidden __a_barrier_dummy -.type __a_barrier_dummy,%function -__a_barrier_dummy: - bx lr - -.global __a_barrier_oldkuser -.hidden __a_barrier_oldkuser -.type __a_barrier_oldkuser,%function -__a_barrier_oldkuser: - push {r0,r1,r2,r3,ip,lr} - mov r1,r0 - mov r2,sp - ldr ip,=0xffff0fc0 - mov lr,pc - mov pc,ip - pop {r0,r1,r2,r3,ip,lr} - bx lr - -.global __a_barrier_v6 -.hidden __a_barrier_v6 -.type __a_barrier_v6,%function -__a_barrier_v6: - .arch armv6t2 - mcr p15,0,r0,c7,c10,5 - bx lr - -.global __a_barrier_v7 -.hidden __a_barrier_v7 -.type __a_barrier_v7,%function -__a_barrier_v7: - .arch armv7-a - dmb ish - bx lr - -.global __a_cas_dummy -.hidden __a_cas_dummy -.type __a_cas_dummy,%function -__a_cas_dummy: - mov r3,r0 - ldr r0,[r2] - subs r0,r3,r0 - streq r1,[r2] - bx lr - -.global __a_cas_v6 -.hidden __a_cas_v6 -.type __a_cas_v6,%function -__a_cas_v6: - .arch armv6t2 - mov r3,r0 - mcr p15,0,r0,c7,c10,5 -1: ldrex r0,[r2] - subs r0,r3,r0 - strexeq r0,r1,[r2] - teqeq r0,#1 - beq 1b - mcr p15,0,r0,c7,c10,5 - bx lr - -.global __a_cas_v7 -.hidden __a_cas_v7 -.type __a_cas_v7,%function -__a_cas_v7: - .arch armv7-a - mov r3,r0 - dmb ish -1: ldrex r0,[r2] - subs r0,r3,r0 - strexeq r0,r1,[r2] - teqeq r0,#1 - beq 1b - dmb ish - bx lr - -.global __a_gettp_cp15 -.hidden __a_gettp_cp15 -.type __a_gettp_cp15,%function -__a_gettp_cp15: - mrc p15,0,r0,c13,c0,3 - bx lr - -/* Tag this file with minimum ISA level so as not to affect linking. */ -.object_arch armv4t -.eabi_attribute 6,2 - -.data -.align 2 - -.global __a_barrier_ptr -.hidden __a_barrier_ptr -__a_barrier_ptr: - .word __a_barrier_dummy - -.global __a_cas_ptr -.hidden __a_cas_ptr -__a_cas_ptr: - .word __a_cas_dummy - -.global __a_gettp_ptr -.hidden __a_gettp_ptr -__a_gettp_ptr: - .word __a_gettp_cp15 diff --git a/usr/lib/libc/thread/call_once.c b/usr/lib/libc/thread/call_once.c deleted file mode 100644 index a7bc93532..000000000 --- a/usr/lib/libc/thread/call_once.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int __pthread_once(once_flag *, void (*)(void)); - -void call_once(once_flag *flag, void (*func)(void)) -{ - __pthread_once(flag, func); -} diff --git a/usr/lib/libc/thread/clone.c b/usr/lib/libc/thread/clone.c deleted file mode 100644 index be80c8ea4..000000000 --- a/usr/lib/libc/thread/clone.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "pthread_impl.h" - -int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...) -{ - return -ENOSYS; -} diff --git a/usr/lib/libc/thread/cnd_broadcast.c b/usr/lib/libc/thread/cnd_broadcast.c deleted file mode 100644 index 85d4d3ead..000000000 --- a/usr/lib/libc/thread/cnd_broadcast.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int __private_cond_signal(cnd_t *, int); - -int cnd_broadcast(cnd_t *c) -{ - /* This internal function never fails, and always returns zero, - * which matches the value thrd_success is defined with. */ - return __private_cond_signal(c, -1); -} diff --git a/usr/lib/libc/thread/cnd_destroy.c b/usr/lib/libc/thread/cnd_destroy.c deleted file mode 100644 index 453c90be5..000000000 --- a/usr/lib/libc/thread/cnd_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void cnd_destroy(cnd_t *c) -{ - /* For private cv this is a no-op */ -} diff --git a/usr/lib/libc/thread/cnd_init.c b/usr/lib/libc/thread/cnd_init.c deleted file mode 100644 index 18c508557..000000000 --- a/usr/lib/libc/thread/cnd_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int cnd_init(cnd_t *c) -{ - *c = (cnd_t){ 0 }; - return thrd_success; -} diff --git a/usr/lib/libc/thread/cnd_signal.c b/usr/lib/libc/thread/cnd_signal.c deleted file mode 100644 index 1211260b4..000000000 --- a/usr/lib/libc/thread/cnd_signal.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int __private_cond_signal(cnd_t *, int); - -int cnd_signal(cnd_t *c) -{ - /* This internal function never fails, and always returns zero, - * which matches the value thrd_success is defined with. */ - return __private_cond_signal(c, 1); -} diff --git a/usr/lib/libc/thread/cnd_timedwait.c b/usr/lib/libc/thread/cnd_timedwait.c deleted file mode 100644 index 599767937..000000000 --- a/usr/lib/libc/thread/cnd_timedwait.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -int __pthread_cond_timedwait(cnd_t *restrict, mtx_t *restrict, const struct timespec *restrict); - -int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct timespec *restrict ts) -{ - int ret = __pthread_cond_timedwait(c, m, ts); - switch (ret) { - /* May also return EINVAL or EPERM. */ - default: return thrd_error; - case 0: return thrd_success; - case ETIMEDOUT: return thrd_timedout; - } -} diff --git a/usr/lib/libc/thread/cnd_wait.c b/usr/lib/libc/thread/cnd_wait.c deleted file mode 100644 index 602796f85..000000000 --- a/usr/lib/libc/thread/cnd_wait.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int cnd_wait(cnd_t *c, mtx_t *m) -{ - /* Calling cnd_timedwait with a null pointer is an extension. - * It is convenient here to avoid duplication of the logic - * for return values. */ - return cnd_timedwait(c, m, 0); -} diff --git a/usr/lib/libc/thread/lock_ptc.c b/usr/lib/libc/thread/lock_ptc.c deleted file mode 100644 index 7adedab75..000000000 --- a/usr/lib/libc/thread/lock_ptc.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -static pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER; - -void __inhibit_ptc() -{ - pthread_rwlock_wrlock(&lock); -} - -void __acquire_ptc() -{ - pthread_rwlock_rdlock(&lock); -} - -void __release_ptc() -{ - pthread_rwlock_unlock(&lock); -} diff --git a/usr/lib/libc/thread/mtx_destroy.c b/usr/lib/libc/thread/mtx_destroy.c deleted file mode 100644 index 40a089998..000000000 --- a/usr/lib/libc/thread/mtx_destroy.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -void mtx_destroy(mtx_t *mtx) -{ -} diff --git a/usr/lib/libc/thread/mtx_init.c b/usr/lib/libc/thread/mtx_init.c deleted file mode 100644 index 4826f76b1..000000000 --- a/usr/lib/libc/thread/mtx_init.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" -#include - -int mtx_init(mtx_t *m, int type) -{ - *m = (mtx_t){ - ._m_type = ((type&mtx_recursive) ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL), - }; - return thrd_success; -} diff --git a/usr/lib/libc/thread/mtx_lock.c b/usr/lib/libc/thread/mtx_lock.c deleted file mode 100644 index 5c2415c1a..000000000 --- a/usr/lib/libc/thread/mtx_lock.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" -#include - -int mtx_lock(mtx_t *m) -{ - if (m->_m_type == PTHREAD_MUTEX_NORMAL && !a_cas(&m->_m_lock, 0, EBUSY)) - return thrd_success; - /* Calling mtx_timedlock with a null pointer is an extension. - * It is convenient, here to avoid duplication of the logic - * for return values. */ - return mtx_timedlock(m, 0); -} diff --git a/usr/lib/libc/thread/mtx_timedlock.c b/usr/lib/libc/thread/mtx_timedlock.c deleted file mode 100644 index bcc152c56..000000000 --- a/usr/lib/libc/thread/mtx_timedlock.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int __pthread_mutex_timedlock(mtx_t *restrict, const struct timespec *restrict); - -int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts) -{ - int ret = __pthread_mutex_timedlock(m, ts); - switch (ret) { - default: return thrd_error; - case 0: return thrd_success; - case ETIMEDOUT: return thrd_timedout; - } -} diff --git a/usr/lib/libc/thread/mtx_trylock.c b/usr/lib/libc/thread/mtx_trylock.c deleted file mode 100644 index 61e7694ed..000000000 --- a/usr/lib/libc/thread/mtx_trylock.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "pthread_impl.h" -#include - -int __pthread_mutex_trylock(mtx_t *); - -int mtx_trylock(mtx_t *m) -{ - if (m->_m_type == PTHREAD_MUTEX_NORMAL) - return (a_cas(&m->_m_lock, 0, EBUSY) & EBUSY) ? thrd_busy : thrd_success; - - int ret = __pthread_mutex_trylock(m); - switch (ret) { - default: return thrd_error; - case 0: return thrd_success; - case EBUSY: return thrd_busy; - } -} diff --git a/usr/lib/libc/thread/mtx_unlock.c b/usr/lib/libc/thread/mtx_unlock.c deleted file mode 100644 index 5033ace7f..000000000 --- a/usr/lib/libc/thread/mtx_unlock.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int __pthread_mutex_unlock(mtx_t *); - -int mtx_unlock(mtx_t *mtx) -{ - /* The only cases where pthread_mutex_unlock can return an - * error are undefined behavior for C11 mtx_unlock, so we can - * assume it does not return an error and simply tail call. */ - return __pthread_mutex_unlock(mtx); -} diff --git a/usr/lib/libc/thread/pthread_atfork.c b/usr/lib/libc/thread/pthread_atfork.c deleted file mode 100644 index a40d7f632..000000000 --- a/usr/lib/libc/thread/pthread_atfork.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include "libc.h" - -static struct atfork_funcs { - void (*prepare)(void); - void (*parent)(void); - void (*child)(void); - struct atfork_funcs *prev, *next; -} *funcs; - -static volatile int lock[2]; - -void __fork_handler(int who) -{ - struct atfork_funcs *p; - if (!funcs) return; - if (who < 0) { - LOCK(lock); - for (p=funcs; p; p = p->next) { - if (p->prepare) p->prepare(); - funcs = p; - } - } else { - for (p=funcs; p; p = p->prev) { - if (!who && p->parent) p->parent(); - else if (who && p->child) p->child(); - funcs = p; - } - UNLOCK(lock); - } -} - -int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) -{ - struct atfork_funcs *new = malloc(sizeof *new); - if (!new) return -1; - - LOCK(lock); - new->next = funcs; - new->prev = 0; - new->prepare = prepare; - new->parent = parent; - new->child = child; - if (funcs) funcs->prev = new; - funcs = new; - UNLOCK(lock); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_destroy.c b/usr/lib/libc/thread/pthread_attr_destroy.c deleted file mode 100644 index b5845dd0f..000000000 --- a/usr/lib/libc/thread/pthread_attr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_destroy(pthread_attr_t *a) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_get.c b/usr/lib/libc/thread/pthread_attr_get.c deleted file mode 100644 index 4aa5afdb2..000000000 --- a/usr/lib/libc/thread/pthread_attr_get.c +++ /dev/null @@ -1,98 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state) -{ - *state = a->_a_detach; - return 0; -} -int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size) -{ - *size = a->_a_guardsize; - return 0; -} - -int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit) -{ - *inherit = a->_a_sched; - return 0; -} - -int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) -{ - param->sched_priority = a->_a_prio; - return 0; -} - -int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy) -{ - *policy = a->_a_policy; - return 0; -} - -int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope) -{ - *scope = PTHREAD_SCOPE_SYSTEM; - return 0; -} - -int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size) -{ - if (!a->_a_stackaddr) - return EINVAL; - *size = a->_a_stacksize; - *addr = (void *)(a->_a_stackaddr - *size); - return 0; -} - -int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size) -{ - *size = a->_a_stacksize; - return 0; -} - -int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared) -{ - *pshared = !!a->__attr; - return 0; -} - -int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) -{ - *clk = a->__attr & 0x7fffffff; - return 0; -} - -int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared) -{ - *pshared = a->__attr>>31; - return 0; -} - -int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol) -{ - *protocol = PTHREAD_PRIO_NONE; - return 0; -} -int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared) -{ - *pshared = a->__attr / 128U % 2; - return 0; -} - -int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust) -{ - *robust = a->__attr / 4U % 2; - return 0; -} - -int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type) -{ - *type = a->__attr & 3; - return 0; -} - -int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared) -{ - *pshared = a->__attr[0]; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_init.c b/usr/lib/libc/thread/pthread_attr_init.c deleted file mode 100644 index 8f6e33745..000000000 --- a/usr/lib/libc/thread/pthread_attr_init.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_init(pthread_attr_t *a) -{ - *a = (pthread_attr_t){0}; - a->_a_stacksize = DEFAULT_STACK_SIZE; - a->_a_guardsize = DEFAULT_GUARD_SIZE; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_setdetachstate.c b/usr/lib/libc/thread/pthread_attr_setdetachstate.c deleted file mode 100644 index 1b7127839..000000000 --- a/usr/lib/libc/thread/pthread_attr_setdetachstate.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setdetachstate(pthread_attr_t *a, int state) -{ - if (state > 1U) return EINVAL; - a->_a_detach = state; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_setguardsize.c b/usr/lib/libc/thread/pthread_attr_setguardsize.c deleted file mode 100644 index 1c5c60acb..000000000 --- a/usr/lib/libc/thread/pthread_attr_setguardsize.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) -{ - if (size > SIZE_MAX/8) return EINVAL; - a->_a_guardsize = size; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_setinheritsched.c b/usr/lib/libc/thread/pthread_attr_setinheritsched.c deleted file mode 100644 index c91d8f83c..000000000 --- a/usr/lib/libc/thread/pthread_attr_setinheritsched.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit) -{ - if (inherit > 1U) return EINVAL; - a->_a_sched = inherit; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_setschedparam.c b/usr/lib/libc/thread/pthread_attr_setschedparam.c deleted file mode 100644 index d4c1204fd..000000000 --- a/usr/lib/libc/thread/pthread_attr_setschedparam.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param) -{ - a->_a_prio = param->sched_priority; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_setschedpolicy.c b/usr/lib/libc/thread/pthread_attr_setschedpolicy.c deleted file mode 100644 index bb71f393e..000000000 --- a/usr/lib/libc/thread/pthread_attr_setschedpolicy.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setschedpolicy(pthread_attr_t *a, int policy) -{ - a->_a_policy = policy; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_setscope.c b/usr/lib/libc/thread/pthread_attr_setscope.c deleted file mode 100644 index 46b520c04..000000000 --- a/usr/lib/libc/thread/pthread_attr_setscope.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setscope(pthread_attr_t *a, int scope) -{ - switch (scope) { - case PTHREAD_SCOPE_SYSTEM: - return 0; - case PTHREAD_SCOPE_PROCESS: - return ENOTSUP; - default: - return EINVAL; - } -} diff --git a/usr/lib/libc/thread/pthread_attr_setstack.c b/usr/lib/libc/thread/pthread_attr_setstack.c deleted file mode 100644 index 1eddcbd6e..000000000 --- a/usr/lib/libc/thread/pthread_attr_setstack.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setstack(pthread_attr_t *a, void *addr, size_t size) -{ - if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL; - a->_a_stackaddr = (size_t)addr + size; - a->_a_stacksize = size; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_attr_setstacksize.c b/usr/lib/libc/thread/pthread_attr_setstacksize.c deleted file mode 100644 index 9c6a8806e..000000000 --- a/usr/lib/libc/thread/pthread_attr_setstacksize.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setstacksize(pthread_attr_t *a, size_t size) -{ - if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL; - a->_a_stackaddr = 0; - a->_a_stacksize = size; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_barrier_destroy.c b/usr/lib/libc/thread/pthread_barrier_destroy.c deleted file mode 100644 index 4ce0b2e12..000000000 --- a/usr/lib/libc/thread/pthread_barrier_destroy.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_destroy(pthread_barrier_t *b) -{ - if (b->_b_limit < 0) { - if (b->_b_lock) { - int v; - a_or(&b->_b_lock, INT_MIN); - while ((v = b->_b_lock) & INT_MAX) - __wait(&b->_b_lock, 0, v, 0); - } - __vm_wait(); - } - return 0; -} diff --git a/usr/lib/libc/thread/pthread_barrier_init.c b/usr/lib/libc/thread/pthread_barrier_init.c deleted file mode 100644 index 4c3cb28d4..000000000 --- a/usr/lib/libc/thread/pthread_barrier_init.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_init(pthread_barrier_t *restrict b, const pthread_barrierattr_t *restrict a, unsigned count) -{ - if (count-1 > INT_MAX-1) return EINVAL; - *b = (pthread_barrier_t){ ._b_limit = count-1 | (a?a->__attr:0) }; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_barrier_wait.c b/usr/lib/libc/thread/pthread_barrier_wait.c deleted file mode 100644 index 06b83db92..000000000 --- a/usr/lib/libc/thread/pthread_barrier_wait.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "pthread_impl.h" - -static int pshared_barrier_wait(pthread_barrier_t *b) -{ - int limit = (b->_b_limit & INT_MAX) + 1; - int ret = 0; - int v, w; - - if (limit==1) return PTHREAD_BARRIER_SERIAL_THREAD; - - while ((v=a_cas(&b->_b_lock, 0, limit))) - __wait(&b->_b_lock, &b->_b_waiters, v, 0); - - /* Wait for threads to get to the barrier */ - if (++b->_b_count == limit) { - a_store(&b->_b_count, 0); - ret = PTHREAD_BARRIER_SERIAL_THREAD; - if (b->_b_waiters2) __wake(&b->_b_count, -1, 0); - } else { - a_store(&b->_b_lock, 0); - if (b->_b_waiters) __wake(&b->_b_lock, 1, 0); - while ((v=b->_b_count)>0) - __wait(&b->_b_count, &b->_b_waiters2, v, 0); - } - - __vm_lock(); - - /* Ensure all threads have a vm lock before proceeding */ - if (a_fetch_add(&b->_b_count, -1)==1-limit) { - a_store(&b->_b_count, 0); - if (b->_b_waiters2) __wake(&b->_b_count, -1, 0); - } else { - while ((v=b->_b_count)) - __wait(&b->_b_count, &b->_b_waiters2, v, 0); - } - - /* Perform a recursive unlock suitable for self-sync'd destruction */ - do { - v = b->_b_lock; - w = b->_b_waiters; - } while (a_cas(&b->_b_lock, v, v==INT_MIN+1 ? 0 : v-1) != v); - - /* Wake a thread waiting to reuse or destroy the barrier */ - if (v==INT_MIN+1 || (v==1 && w)) - __wake(&b->_b_lock, 1, 0); - - __vm_unlock(); - - return ret; -} - -struct instance -{ - volatile int count; - volatile int last; - volatile int waiters; - volatile int finished; -}; - -int pthread_barrier_wait(pthread_barrier_t *b) -{ - int limit = b->_b_limit; - struct instance *inst; - - /* Trivial case: count was set at 1 */ - if (!limit) return PTHREAD_BARRIER_SERIAL_THREAD; - - /* Process-shared barriers require a separate, inefficient wait */ - if (limit < 0) return pshared_barrier_wait(b); - - /* Otherwise we need a lock on the barrier object */ - while (a_swap(&b->_b_lock, 1)) - __wait(&b->_b_lock, &b->_b_waiters, 1, 1); - inst = b->_b_inst; - - /* First thread to enter the barrier becomes the "instance owner" */ - if (!inst) { - struct instance new_inst = { 0 }; - int spins = 200; - b->_b_inst = inst = &new_inst; - a_store(&b->_b_lock, 0); - if (b->_b_waiters) __wake(&b->_b_lock, 1, 1); - while (spins-- && !inst->finished) - a_spin(); - a_inc(&inst->finished); - while (inst->finished == 1) - __syscall(SYS_futex,&inst->finished,FUTEX_WAIT|128,1,0) != -ENOSYS - || __syscall(SYS_futex,&inst->finished,FUTEX_WAIT,1,0); - return PTHREAD_BARRIER_SERIAL_THREAD; - } - - /* Last thread to enter the barrier wakes all non-instance-owners */ - if (++inst->count == limit) { - b->_b_inst = 0; - a_store(&b->_b_lock, 0); - if (b->_b_waiters) __wake(&b->_b_lock, 1, 1); - a_store(&inst->last, 1); - if (inst->waiters) - __wake(&inst->last, -1, 1); - } else { - a_store(&b->_b_lock, 0); - if (b->_b_waiters) __wake(&b->_b_lock, 1, 1); - __wait(&inst->last, &inst->waiters, 0, 1); - } - - /* Last thread to exit the barrier wakes the instance owner */ - if (a_fetch_add(&inst->count,-1)==1 && a_fetch_add(&inst->finished,1)) - __wake(&inst->finished, 1, 1); - - return 0; -} diff --git a/usr/lib/libc/thread/pthread_barrierattr_destroy.c b/usr/lib/libc/thread/pthread_barrierattr_destroy.c deleted file mode 100644 index adec738fd..000000000 --- a/usr/lib/libc/thread/pthread_barrierattr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrierattr_destroy(pthread_barrierattr_t *a) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_barrierattr_init.c b/usr/lib/libc/thread/pthread_barrierattr_init.c deleted file mode 100644 index fa742bb73..000000000 --- a/usr/lib/libc/thread/pthread_barrierattr_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrierattr_init(pthread_barrierattr_t *a) -{ - *a = (pthread_barrierattr_t){0}; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_barrierattr_setpshared.c b/usr/lib/libc/thread/pthread_barrierattr_setpshared.c deleted file mode 100644 index b391461e1..000000000 --- a/usr/lib/libc/thread/pthread_barrierattr_setpshared.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrierattr_setpshared(pthread_barrierattr_t *a, int pshared) -{ - a->__attr = pshared ? INT_MIN : 0; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_cancel.c b/usr/lib/libc/thread/pthread_cancel.c deleted file mode 100644 index 3d229223e..000000000 --- a/usr/lib/libc/thread/pthread_cancel.c +++ /dev/null @@ -1,97 +0,0 @@ -#define _GNU_SOURCE -#include -#include "pthread_impl.h" -#include "syscall.h" -#include "libc.h" - -__attribute__((__visibility__("hidden"))) -long __cancel(), __syscall_cp_asm(), __syscall_cp_c(); - -long __cancel() -{ - pthread_t self = __pthread_self(); - if (self->canceldisable == PTHREAD_CANCEL_ENABLE || self->cancelasync) - pthread_exit(PTHREAD_CANCELED); - self->canceldisable = PTHREAD_CANCEL_DISABLE; - return -ECANCELED; -} - -long __syscall_cp_asm(volatile void *, syscall_arg_t, - syscall_arg_t, syscall_arg_t, syscall_arg_t, - syscall_arg_t, syscall_arg_t, syscall_arg_t); - -long __syscall_cp_c(syscall_arg_t nr, - syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, - syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) -{ - pthread_t self; - long r; - int st; - - if ((st=(self=__pthread_self())->canceldisable) - && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close)) - return __syscall(nr, u, v, w, x, y, z); - - r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z); - if (r==-EINTR && nr!=SYS_close && self->cancel && - self->canceldisable != PTHREAD_CANCEL_DISABLE) - r = __cancel(); - return r; -} - -static void _sigaddset(sigset_t *set, int sig) -{ - unsigned s = sig-1; - set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); -} - -__attribute__((__visibility__("hidden"))) -extern const char __cp_begin[1], __cp_end[1], __cp_cancel[1]; - -static void cancel_handler(int sig, siginfo_t *si, void *ctx) -{ - pthread_t self = __pthread_self(); - ucontext_t *uc = ctx; - uintptr_t pc = uc->uc_mcontext.MC_PC; - - a_barrier(); - if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return; - - _sigaddset(&uc->uc_sigmask, SIGCANCEL); - - if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) { - uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel; - return; - } - - __syscall(SYS_tkill, self->tid, SIGCANCEL); -} - -void __testcancel() -{ - pthread_t self = __pthread_self(); - if (self->cancel && !self->canceldisable) - __cancel(); -} - -static void init_cancellation() -{ - struct sigaction sa = { - .sa_flags = SA_SIGINFO | SA_RESTART, - .sa_sigaction = cancel_handler - }; - memset(&sa.sa_mask, -1, _NSIG/8); - __libc_sigaction(SIGCANCEL, &sa, 0); -} - -int pthread_cancel(pthread_t t) -{ - static int init; - if (!init) { - init_cancellation(); - init = 1; - } - a_store(&t->cancel, 1); - if (t == pthread_self() && !t->cancelasync) return 0; - return pthread_kill(t, SIGCANCEL); -} diff --git a/usr/lib/libc/thread/pthread_cleanup_push.c b/usr/lib/libc/thread/pthread_cleanup_push.c deleted file mode 100644 index 9b21764b5..000000000 --- a/usr/lib/libc/thread/pthread_cleanup_push.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "pthread_impl.h" - -static void dummy(struct __ptcb *cb) -{ -} -weak_alias(dummy, __do_cleanup_push); -weak_alias(dummy, __do_cleanup_pop); - -void _pthread_cleanup_push(struct __ptcb *cb, void (*f)(void *), void *x) -{ - cb->__f = f; - cb->__x = x; - __do_cleanup_push(cb); -} - -void _pthread_cleanup_pop(struct __ptcb *cb, int run) -{ - __do_cleanup_pop(cb); - if (run) cb->__f(cb->__x); -} diff --git a/usr/lib/libc/thread/pthread_cond_broadcast.c b/usr/lib/libc/thread/pthread_cond_broadcast.c deleted file mode 100644 index 69f840fb4..000000000 --- a/usr/lib/libc/thread/pthread_cond_broadcast.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" - -int __private_cond_signal(pthread_cond_t *, int); - -int pthread_cond_broadcast(pthread_cond_t *c) -{ - if (!c->_c_shared) return __private_cond_signal(c, -1); - if (!c->_c_waiters) return 0; - a_inc(&c->_c_seq); - __wake(&c->_c_seq, -1, 0); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_cond_destroy.c b/usr/lib/libc/thread/pthread_cond_destroy.c deleted file mode 100644 index 8c5551600..000000000 --- a/usr/lib/libc/thread/pthread_cond_destroy.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_destroy(pthread_cond_t *c) -{ - if (c->_c_shared && c->_c_waiters) { - int cnt; - a_or(&c->_c_waiters, 0x80000000); - a_inc(&c->_c_seq); - __wake(&c->_c_seq, -1, 0); - while ((cnt = c->_c_waiters) & 0x7fffffff) - __wait(&c->_c_waiters, 0, cnt, 0); - } - return 0; -} diff --git a/usr/lib/libc/thread/pthread_cond_init.c b/usr/lib/libc/thread/pthread_cond_init.c deleted file mode 100644 index 8c484ddcd..000000000 --- a/usr/lib/libc/thread/pthread_cond_init.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a) -{ - *c = (pthread_cond_t){0}; - if (a) { - c->_c_clock = a->__attr & 0x7fffffff; - if (a->__attr>>31) c->_c_shared = (void *)-1; - } - return 0; -} diff --git a/usr/lib/libc/thread/pthread_cond_signal.c b/usr/lib/libc/thread/pthread_cond_signal.c deleted file mode 100644 index 119c00abc..000000000 --- a/usr/lib/libc/thread/pthread_cond_signal.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" - -int __private_cond_signal(pthread_cond_t *, int); - -int pthread_cond_signal(pthread_cond_t *c) -{ - if (!c->_c_shared) return __private_cond_signal(c, 1); - if (!c->_c_waiters) return 0; - a_inc(&c->_c_seq); - __wake(&c->_c_seq, 1, 0); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_cond_timedwait.c b/usr/lib/libc/thread/pthread_cond_timedwait.c deleted file mode 100644 index 3526ecfb6..000000000 --- a/usr/lib/libc/thread/pthread_cond_timedwait.c +++ /dev/null @@ -1,214 +0,0 @@ -#include "pthread_impl.h" - -void __pthread_testcancel(void); -int __pthread_mutex_lock(pthread_mutex_t *); -int __pthread_mutex_unlock(pthread_mutex_t *); -int __pthread_setcancelstate(int, int *); - -/* - * struct waiter - * - * Waiter objects have automatic storage on the waiting thread, and - * are used in building a linked list representing waiters currently - * waiting on the condition variable or a group of waiters woken - * together by a broadcast or signal; in the case of signal, this is a - * degenerate list of one member. - * - * Waiter lists attached to the condition variable itself are - * protected by the lock on the cv. Detached waiter lists are never - * modified again, but can only be traversed in reverse order, and are - * protected by the "barrier" locks in each node, which are unlocked - * in turn to control wake order. - * - * Since process-shared cond var semantics do not necessarily allow - * one thread to see another's automatic storage (they may be in - * different processes), the waiter list is not used for the - * process-shared case, but the structure is still used to store data - * needed by the cancellation cleanup handler. - */ - -struct waiter { - struct waiter *prev, *next; - volatile int state, barrier; - volatile int *notify; -}; - -/* Self-synchronized-destruction-safe lock functions */ - -static inline void lock(volatile int *l) -{ - if (a_cas(l, 0, 1)) { - a_cas(l, 1, 2); - do __wait(l, 0, 2, 1); - while (a_cas(l, 0, 2)); - } -} - -static inline void unlock(volatile int *l) -{ - if (a_swap(l, 0)==2) - __wake(l, 1, 1); -} - -static inline void unlock_requeue(volatile int *l, volatile int *r, int w) -{ - a_store(l, 0); - if (w) __wake(l, 1, 1); - else __syscall(SYS_futex, l, FUTEX_REQUEUE|128, 0, 1, r) != -ENOSYS - || __syscall(SYS_futex, l, FUTEX_REQUEUE, 0, 1, r); -} - -enum { - WAITING, - SIGNALED, - LEAVING, -}; - -int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts) -{ - struct waiter node = { 0 }; - int e, seq, clock = c->_c_clock, cs, shared=0, oldstate, tmp; - volatile int *fut; - - if ((m->_m_type&15) && (m->_m_lock&INT_MAX) != __pthread_self()->tid) - return EPERM; - - if (ts && ts->tv_nsec >= 1000000000UL) - return EINVAL; - - __pthread_testcancel(); - - if (c->_c_shared) { - shared = 1; - fut = &c->_c_seq; - seq = c->_c_seq; - a_inc(&c->_c_waiters); - } else { - lock(&c->_c_lock); - - seq = node.barrier = 2; - fut = &node.barrier; - node.state = WAITING; - node.next = c->_c_head; - c->_c_head = &node; - if (!c->_c_tail) c->_c_tail = &node; - else node.next->prev = &node; - - unlock(&c->_c_lock); - } - - __pthread_mutex_unlock(m); - - __pthread_setcancelstate(PTHREAD_CANCEL_MASKED, &cs); - if (cs == PTHREAD_CANCEL_DISABLE) __pthread_setcancelstate(cs, 0); - - do e = __timedwait_cp(fut, seq, clock, ts, !shared); - while (*fut==seq && (!e || e==EINTR)); - if (e == EINTR) e = 0; - - if (shared) { - /* Suppress cancellation if a signal was potentially - * consumed; this is a legitimate form of spurious - * wake even if not. */ - if (e == ECANCELED && c->_c_seq != seq) e = 0; - if (a_fetch_add(&c->_c_waiters, -1) == -0x7fffffff) - __wake(&c->_c_waiters, 1, 0); - oldstate = WAITING; - goto relock; - } - - oldstate = a_cas(&node.state, WAITING, LEAVING); - - if (oldstate == WAITING) { - /* Access to cv object is valid because this waiter was not - * yet signaled and a new signal/broadcast cannot return - * after seeing a LEAVING waiter without getting notified - * via the futex notify below. */ - - lock(&c->_c_lock); - - if (c->_c_head == &node) c->_c_head = node.next; - else if (node.prev) node.prev->next = node.next; - if (c->_c_tail == &node) c->_c_tail = node.prev; - else if (node.next) node.next->prev = node.prev; - - unlock(&c->_c_lock); - - if (node.notify) { - if (a_fetch_add(node.notify, -1)==1) - __wake(node.notify, 1, 1); - } - } else { - /* Lock barrier first to control wake order. */ - lock(&node.barrier); - } - -relock: - /* Errors locking the mutex override any existing error or - * cancellation, since the caller must see them to know the - * state of the mutex. */ - if ((tmp = pthread_mutex_lock(m))) e = tmp; - - if (oldstate == WAITING) goto done; - - if (!node.next) a_inc(&m->_m_waiters); - - /* Unlock the barrier that's holding back the next waiter, and - * either wake it or requeue it to the mutex. */ - if (node.prev) - unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & 128); - else - a_dec(&m->_m_waiters); - - /* Since a signal was consumed, cancellation is not permitted. */ - if (e == ECANCELED) e = 0; - -done: - __pthread_setcancelstate(cs, 0); - - if (e == ECANCELED) { - __pthread_testcancel(); - __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); - } - - return e; -} - -int __private_cond_signal(pthread_cond_t *c, int n) -{ - struct waiter *p, *first=0; - volatile int ref = 0; - int cur; - - lock(&c->_c_lock); - for (p=c->_c_tail; n && p; p=p->prev) { - if (a_cas(&p->state, WAITING, SIGNALED) != WAITING) { - ref++; - p->notify = &ref; - } else { - n--; - if (!first) first=p; - } - } - /* Split the list, leaving any remainder on the cv. */ - if (p) { - if (p->next) p->next->prev = 0; - p->next = 0; - } else { - c->_c_head = 0; - } - c->_c_tail = p; - unlock(&c->_c_lock); - - /* Wait for any waiters in the LEAVING state to remove - * themselves from the list before returning or allowing - * signaled threads to proceed. */ - while ((cur = ref)) __wait(&ref, 0, cur, 1); - - /* Allow first signaled waiter, if any, to proceed. */ - if (first) unlock(&first->barrier); - - return 0; -} - -weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait); diff --git a/usr/lib/libc/thread/pthread_cond_wait.c b/usr/lib/libc/thread/pthread_cond_wait.c deleted file mode 100644 index 8735bf147..000000000 --- a/usr/lib/libc/thread/pthread_cond_wait.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m) -{ - return pthread_cond_timedwait(c, m, 0); -} diff --git a/usr/lib/libc/thread/pthread_condattr_destroy.c b/usr/lib/libc/thread/pthread_condattr_destroy.c deleted file mode 100644 index c54ec4122..000000000 --- a/usr/lib/libc/thread/pthread_condattr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_condattr_destroy(pthread_condattr_t *a) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_condattr_init.c b/usr/lib/libc/thread/pthread_condattr_init.c deleted file mode 100644 index a41741b4e..000000000 --- a/usr/lib/libc/thread/pthread_condattr_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_condattr_init(pthread_condattr_t *a) -{ - *a = (pthread_condattr_t){0}; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_condattr_setclock.c b/usr/lib/libc/thread/pthread_condattr_setclock.c deleted file mode 100644 index 711259413..000000000 --- a/usr/lib/libc/thread/pthread_condattr_setclock.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk) -{ - if (clk < 0 || clk-2U < 2) return EINVAL; - a->__attr &= 0x80000000; - a->__attr |= clk; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_condattr_setpshared.c b/usr/lib/libc/thread/pthread_condattr_setpshared.c deleted file mode 100644 index 51453e048..000000000 --- a/usr/lib/libc/thread/pthread_condattr_setpshared.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_condattr_setpshared(pthread_condattr_t *a, int pshared) -{ - if (pshared > 1U) return EINVAL; - a->__attr &= 0x7fffffff; - a->__attr |= (unsigned)pshared<<31; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_create.c b/usr/lib/libc/thread/pthread_create.c deleted file mode 100644 index 49f2f7296..000000000 --- a/usr/lib/libc/thread/pthread_create.c +++ /dev/null @@ -1,311 +0,0 @@ -#define _GNU_SOURCE -#include "pthread_impl.h" -#include "stdio_impl.h" -#include "libc.h" -#include -#include -#include - -void *__mmap(void *, size_t, int, int, int, off_t); -int __munmap(void *, size_t); -int __mprotect(void *, size_t, int); - -static void dummy_0() -{ -} -weak_alias(dummy_0, __acquire_ptc); -weak_alias(dummy_0, __release_ptc); -weak_alias(dummy_0, __pthread_tsd_run_dtors); -weak_alias(dummy_0, __do_orphaned_stdio_locks); -weak_alias(dummy_0, __dl_thread_cleanup); - -_Noreturn void __pthread_exit(void *result) -{ - pthread_t self = __pthread_self(); - sigset_t set; - - self->canceldisable = 1; - self->cancelasync = 0; - self->result = result; - - while (self->cancelbuf) { - void (*f)(void *) = self->cancelbuf->__f; - void *x = self->cancelbuf->__x; - self->cancelbuf = self->cancelbuf->__next; - f(x); - } - - __pthread_tsd_run_dtors(); - - __lock(self->exitlock); - - /* Mark this thread dead before decrementing count */ - __lock(self->killlock); - self->dead = 1; - - /* Block all signals before decrementing the live thread count. - * This is important to ensure that dynamically allocated TLS - * is not under-allocated/over-committed, and possibly for other - * reasons as well. */ - __block_all_sigs(&set); - - /* Wait to unlock the kill lock, which governs functions like - * pthread_kill which target a thread id, until signals have - * been blocked. This precludes observation of the thread id - * as a live thread (with application code running in it) after - * the thread was reported dead by ESRCH being returned. */ - __unlock(self->killlock); - - /* It's impossible to determine whether this is "the last thread" - * until performing the atomic decrement, since multiple threads - * could exit at the same time. For the last thread, revert the - * decrement and unblock signals to give the atexit handlers and - * stdio cleanup code a consistent state. */ - if (a_fetch_add(&libc.threads_minus_1, -1)==0) { - libc.threads_minus_1 = 0; - __restore_sigs(&set); - exit(0); - } - - /* Process robust list in userspace to handle non-pshared mutexes - * and the detached thread case where the robust list head will - * be invalid when the kernel would process it. */ - __vm_lock(); - volatile void *volatile *rp; - while ((rp=self->robust_list.head) && rp != &self->robust_list.head) { - pthread_mutex_t *m = (void *)((char *)rp - - offsetof(pthread_mutex_t, _m_next)); - int waiters = m->_m_waiters; - int priv = (m->_m_type & 128) ^ 128; - self->robust_list.pending = rp; - self->robust_list.head = *rp; - int cont = a_swap(&m->_m_lock, 0x40000000); - self->robust_list.pending = 0; - if (cont < 0 || waiters) - __wake(&m->_m_lock, 1, priv); - } - __vm_unlock(); - - __do_orphaned_stdio_locks(); - __dl_thread_cleanup(); - - if (self->detached && self->map_base) { - /* Detached threads must avoid the kernel clear_child_tid - * feature, since the virtual address will have been - * unmapped and possibly already reused by a new mapping - * at the time the kernel would perform the write. In - * the case of threads that started out detached, the - * initial clone flags are correct, but if the thread was - * detached later (== 2), we need to clear it here. */ - if (self->detached == 2) __syscall(SYS_set_tid_address, 0); - - /* Robust list will no longer be valid, and was already - * processed above, so unregister it with the kernel. */ - if (self->robust_list.off) - __syscall(SYS_set_robust_list, 0, 3*sizeof(long)); - - /* Since __unmapself bypasses the normal munmap code path, - * explicitly wait for vmlock holders first. */ - __vm_wait(); - - /* The following call unmaps the thread's stack mapping - * and then exits without touching the stack. */ - __unmapself(self->map_base, self->map_size); - } - - for (;;) __syscall(SYS_exit, 0); -} - -void __do_cleanup_push(struct __ptcb *cb) -{ - struct pthread *self = __pthread_self(); - cb->__next = self->cancelbuf; - self->cancelbuf = cb; -} - -void __do_cleanup_pop(struct __ptcb *cb) -{ - __pthread_self()->cancelbuf = cb->__next; -} - -static int start(void *p) -{ - pthread_t self = p; - if (self->startlock[0]) { - __wait(self->startlock, 0, 1, 1); - if (self->startlock[0]) { - self->detached = 2; - pthread_exit(0); - } - __restore_sigs(self->sigmask); - } - if (self->unblock_cancel) - __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, - SIGPT_SET, 0, _NSIG/8); - __pthread_exit(self->start(self->start_arg)); - return 0; -} - -static int start_c11(void *p) -{ - pthread_t self = p; - int (*start)(void*) = (int(*)(void*)) self->start; - __pthread_exit((void *)(uintptr_t)start(self->start_arg)); - return 0; -} - -#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE) - -/* pthread_key_create.c overrides this */ -static volatile size_t dummy = 0; -weak_alias(dummy, __pthread_tsd_size); -static void *dummy_tsd[1] = { 0 }; -weak_alias(dummy_tsd, __pthread_tsd_main); - -volatile int __block_new_threads = 0; -size_t __default_stacksize = DEFAULT_STACK_SIZE; -size_t __default_guardsize = DEFAULT_GUARD_SIZE; - -static FILE *volatile dummy_file = 0; -weak_alias(dummy_file, __stdin_used); -weak_alias(dummy_file, __stdout_used); -weak_alias(dummy_file, __stderr_used); - -static void init_file_lock(FILE *f) -{ - if (f && f->lock<0) f->lock = 0; -} - -void *__copy_tls(unsigned char *); - -int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg) -{ - int ret, c11 = (attrp == __ATTRP_C11_THREAD); - size_t size, guard; - struct pthread *self, *new; - unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit; - unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND - | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS - | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED; - int do_sched = 0; - pthread_attr_t attr = { 0 }; - - if (!libc.can_do_threads) return ENOSYS; - self = __pthread_self(); - if (!libc.threaded) { - for (FILE *f=*__ofl_lock(); f; f=f->next) - init_file_lock(f); - __ofl_unlock(); - init_file_lock(__stdin_used); - init_file_lock(__stdout_used); - init_file_lock(__stderr_used); - __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG/8); - self->tsd = (void **)__pthread_tsd_main; - libc.threaded = 1; - } - if (attrp && !c11) attr = *attrp; - - __acquire_ptc(); - if (!attrp || c11) { - attr._a_stacksize = __default_stacksize; - attr._a_guardsize = __default_guardsize; - } - - if (__block_new_threads) __wait(&__block_new_threads, 0, 1, 1); - - if (attr._a_stackaddr) { - size_t need = libc.tls_size + __pthread_tsd_size; - size = attr._a_stacksize; - stack = (void *)(attr._a_stackaddr & -16); - stack_limit = (void *)(attr._a_stackaddr - size); - /* Use application-provided stack for TLS only when - * it does not take more than ~12% or 2k of the - * application's stack space. */ - if (need < size/8 && need < 2048) { - tsd = stack - __pthread_tsd_size; - stack = tsd - libc.tls_size; - memset(stack, 0, need); - } else { - size = ROUND(need); - guard = 0; - } - } else { - guard = ROUND(attr._a_guardsize); - size = guard + ROUND(attr._a_stacksize - + libc.tls_size + __pthread_tsd_size); - } - - if (!tsd) { - if (guard) { - map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0); - if (map == MAP_FAILED) goto fail; - if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE) - && errno != ENOSYS) { - __munmap(map, size); - goto fail; - } - } else { - map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); - if (map == MAP_FAILED) goto fail; - } - tsd = map + size - __pthread_tsd_size; - if (!stack) { - stack = tsd - libc.tls_size; - stack_limit = map + guard; - } - } - - new = __copy_tls(tsd - libc.tls_size); - new->map_base = map; - new->map_size = size; - new->stack = stack; - new->stack_size = stack - stack_limit; - new->start = entry; - new->start_arg = arg; - new->self = new; - new->tsd = (void *)tsd; - new->locale = &libc.global_locale; - if (attr._a_detach) { - new->detached = 1; - flags -= CLONE_CHILD_CLEARTID; - } - if (attr._a_sched) { - do_sched = new->startlock[0] = 1; - __block_app_sigs(new->sigmask); - } - new->robust_list.head = &new->robust_list.head; - new->unblock_cancel = self->cancel; - new->CANARY = self->CANARY; - - a_inc(&libc.threads_minus_1); - ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->tid); - - __release_ptc(); - - if (do_sched) { - __restore_sigs(new->sigmask); - } - - if (ret < 0) { - a_dec(&libc.threads_minus_1); - if (map) __munmap(map, size); - return EAGAIN; - } - - if (do_sched) { - ret = __syscall(SYS_sched_setscheduler, new->tid, - attr._a_policy, &attr._a_prio); - a_store(new->startlock, ret<0 ? 2 : 0); - __wake(new->startlock, 1, 1); - if (ret < 0) return -ret; - } - - *res = new; - return 0; -fail: - __release_ptc(); - return EAGAIN; -} - -weak_alias(__pthread_exit, pthread_exit); -weak_alias(__pthread_create, pthread_create); diff --git a/usr/lib/libc/thread/pthread_detach.c b/usr/lib/libc/thread/pthread_detach.c deleted file mode 100644 index ed77f74d5..000000000 --- a/usr/lib/libc/thread/pthread_detach.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "pthread_impl.h" -#include - -int __pthread_join(pthread_t, void **); - -static int __pthread_detach(pthread_t t) -{ - /* Cannot detach a thread that's already exiting */ - if (a_swap(t->exitlock, 1)) - return __pthread_join(t, 0); - t->detached = 2; - __unlock(t->exitlock); - return 0; -} - -weak_alias(__pthread_detach, pthread_detach); -weak_alias(__pthread_detach, thrd_detach); diff --git a/usr/lib/libc/thread/pthread_equal.c b/usr/lib/libc/thread/pthread_equal.c deleted file mode 100644 index 7c31482af..000000000 --- a/usr/lib/libc/thread/pthread_equal.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include "libc.h" - -static int __pthread_equal(pthread_t a, pthread_t b) -{ - return a==b; -} - -weak_alias(__pthread_equal, pthread_equal); -weak_alias(__pthread_equal, thrd_equal); diff --git a/usr/lib/libc/thread/pthread_getattr_np.c b/usr/lib/libc/thread/pthread_getattr_np.c deleted file mode 100644 index ae26a5aba..000000000 --- a/usr/lib/libc/thread/pthread_getattr_np.c +++ /dev/null @@ -1,23 +0,0 @@ -#define _GNU_SOURCE -#include "pthread_impl.h" -#include "libc.h" -#include - -int pthread_getattr_np(pthread_t t, pthread_attr_t *a) -{ - *a = (pthread_attr_t){0}; - a->_a_detach = !!t->detached; - if (t->stack) { - a->_a_stackaddr = (uintptr_t)t->stack; - a->_a_stacksize = t->stack_size; - } else { - char *p = (void *)libc.auxv; - size_t l = PAGE_SIZE; - p += -(uintptr_t)p & PAGE_SIZE-1; - a->_a_stackaddr = (uintptr_t)p; - while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM) - l += PAGE_SIZE; - a->_a_stacksize = l; - } - return 0; -} diff --git a/usr/lib/libc/thread/pthread_getconcurrency.c b/usr/lib/libc/thread/pthread_getconcurrency.c deleted file mode 100644 index 269429a8a..000000000 --- a/usr/lib/libc/thread/pthread_getconcurrency.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int pthread_getconcurrency() -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_getcpuclockid.c b/usr/lib/libc/thread/pthread_getcpuclockid.c deleted file mode 100644 index 9df14fb68..000000000 --- a/usr/lib/libc/thread/pthread_getcpuclockid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_getcpuclockid(pthread_t t, clockid_t *clockid) -{ - *clockid = (-t->tid-1)*8U + 6; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_getschedparam.c b/usr/lib/libc/thread/pthread_getschedparam.c deleted file mode 100644 index 3053c1865..000000000 --- a/usr/lib/libc/thread/pthread_getschedparam.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "pthread_impl.h" - -int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *restrict param) -{ - int r; - __lock(t->killlock); - if (t->dead) { - r = ESRCH; - } else { - r = -__syscall(SYS_sched_getparam, t->tid, param); - if (!r) { - *policy = __syscall(SYS_sched_getscheduler, t->tid); - } - } - __unlock(t->killlock); - return r; -} diff --git a/usr/lib/libc/thread/pthread_getspecific.c b/usr/lib/libc/thread/pthread_getspecific.c deleted file mode 100644 index d9342a560..000000000 --- a/usr/lib/libc/thread/pthread_getspecific.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" -#include - -static void *__pthread_getspecific(pthread_key_t k) -{ - struct pthread *self = __pthread_self(); - return self->tsd[k]; -} - -weak_alias(__pthread_getspecific, pthread_getspecific); -weak_alias(__pthread_getspecific, tss_get); diff --git a/usr/lib/libc/thread/pthread_join.c b/usr/lib/libc/thread/pthread_join.c deleted file mode 100644 index 521114895..000000000 --- a/usr/lib/libc/thread/pthread_join.c +++ /dev/null @@ -1,36 +0,0 @@ -#include "pthread_impl.h" -#include - -int __munmap(void *, size_t); -void __pthread_testcancel(void); -int __pthread_setcancelstate(int, int *); - -int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) -{ - int tmp, cs, r = 0; - __pthread_testcancel(); - __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0); - while ((tmp = t->tid) && r != ETIMEDOUT && r != EINVAL) - r = __timedwait_cp(&t->tid, tmp, CLOCK_REALTIME, at, 0); - __pthread_setcancelstate(cs, 0); - if (r == ETIMEDOUT || r == EINVAL) return r; - a_barrier(); - if (res) *res = t->result; - if (t->map_base) __munmap(t->map_base, t->map_size); - return 0; -} - -int __pthread_join(pthread_t t, void **res) -{ - return __pthread_timedjoin_np(t, res, 0); -} - -int __pthread_tryjoin_np(pthread_t t, void **res) -{ - return t->tid ? EBUSY : __pthread_join(t, res); -} - -weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np); -weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np); -weak_alias(__pthread_join, pthread_join); diff --git a/usr/lib/libc/thread/pthread_key_create.c b/usr/lib/libc/thread/pthread_key_create.c deleted file mode 100644 index a78e507a6..000000000 --- a/usr/lib/libc/thread/pthread_key_create.c +++ /dev/null @@ -1,56 +0,0 @@ -#include "pthread_impl.h" - -volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; -void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 }; - -static void (*volatile keys[PTHREAD_KEYS_MAX])(void *); - -static void nodtor(void *dummy) -{ -} - -int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) -{ - unsigned i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX; - unsigned j = i; - pthread_t self = __pthread_self(); - - /* This can only happen in the main thread before - * pthread_create has been called. */ - if (!self->tsd) self->tsd = __pthread_tsd_main; - - if (!dtor) dtor = nodtor; - do { - if (!a_cas_p(keys+j, 0, (void *)dtor)) { - *k = j; - return 0; - } - } while ((j=(j+1)%PTHREAD_KEYS_MAX) != i); - return EAGAIN; -} - -int __pthread_key_delete(pthread_key_t k) -{ - keys[k] = 0; - return 0; -} - -void __pthread_tsd_run_dtors() -{ - pthread_t self = __pthread_self(); - int i, j, not_finished = self->tsd_used; - for (j=0; not_finished && jtsd[i] && keys[i]) { - void *tmp = self->tsd[i]; - self->tsd[i] = 0; - keys[i](tmp); - not_finished = 1; - } - } - } -} - -weak_alias(__pthread_key_delete, pthread_key_delete); -weak_alias(__pthread_key_create, pthread_key_create); diff --git a/usr/lib/libc/thread/pthread_kill.c b/usr/lib/libc/thread/pthread_kill.c deleted file mode 100644 index acdb1ea61..000000000 --- a/usr/lib/libc/thread/pthread_kill.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int pthread_kill(pthread_t t, int sig) -{ - int r; - __lock(t->killlock); - r = t->dead ? ESRCH : -__syscall(SYS_tkill, t->tid, sig); - __unlock(t->killlock); - return r; -} diff --git a/usr/lib/libc/thread/pthread_mutex_consistent.c b/usr/lib/libc/thread/pthread_mutex_consistent.c deleted file mode 100644 index 96b83b528..000000000 --- a/usr/lib/libc/thread/pthread_mutex_consistent.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_consistent(pthread_mutex_t *m) -{ - if (!(m->_m_type & 8)) return EINVAL; - if ((m->_m_lock & 0x7fffffff) != __pthread_self()->tid) - return EPERM; - m->_m_type &= ~8U; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutex_destroy.c b/usr/lib/libc/thread/pthread_mutex_destroy.c deleted file mode 100644 index 6d49e6898..000000000 --- a/usr/lib/libc/thread/pthread_mutex_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int pthread_mutex_destroy(pthread_mutex_t *mutex) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutex_getprioceiling.c b/usr/lib/libc/thread/pthread_mutex_getprioceiling.c deleted file mode 100644 index 8c75a6612..000000000 --- a/usr/lib/libc/thread/pthread_mutex_getprioceiling.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict m, int *restrict ceiling) -{ - return EINVAL; -} diff --git a/usr/lib/libc/thread/pthread_mutex_init.c b/usr/lib/libc/thread/pthread_mutex_init.c deleted file mode 100644 index acf45a746..000000000 --- a/usr/lib/libc/thread/pthread_mutex_init.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_init(pthread_mutex_t *restrict m, const pthread_mutexattr_t *restrict a) -{ - *m = (pthread_mutex_t){0}; - if (a) m->_m_type = a->__attr; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutex_lock.c b/usr/lib/libc/thread/pthread_mutex_lock.c deleted file mode 100644 index d0c93cab5..000000000 --- a/usr/lib/libc/thread/pthread_mutex_lock.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict); - -int __pthread_mutex_lock(pthread_mutex_t *m) -{ - if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL - && !a_cas(&m->_m_lock, 0, EBUSY)) - return 0; - - return __pthread_mutex_timedlock(m, 0); -} - -weak_alias(__pthread_mutex_lock, pthread_mutex_lock); diff --git a/usr/lib/libc/thread/pthread_mutex_setprioceiling.c b/usr/lib/libc/thread/pthread_mutex_setprioceiling.c deleted file mode 100644 index 681f07c88..000000000 --- a/usr/lib/libc/thread/pthread_mutex_setprioceiling.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_setprioceiling(pthread_mutex_t *restrict m, int ceiling, int *restrict old) -{ - return EINVAL; -} diff --git a/usr/lib/libc/thread/pthread_mutex_timedlock.c b/usr/lib/libc/thread/pthread_mutex_timedlock.c deleted file mode 100644 index 0a240e791..000000000 --- a/usr/lib/libc/thread/pthread_mutex_timedlock.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at) -{ - if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL - && !a_cas(&m->_m_lock, 0, EBUSY)) - return 0; - - int r, t, priv = (m->_m_type & 128) ^ 128; - - r = pthread_mutex_trylock(m); - if (r != EBUSY) return r; - - int spins = 100; - while (spins-- && m->_m_lock && !m->_m_waiters) a_spin(); - - while ((r=pthread_mutex_trylock(m)) == EBUSY) { - if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4))) - continue; - if ((m->_m_type&3) == PTHREAD_MUTEX_ERRORCHECK - && (r&0x7fffffff) == __pthread_self()->tid) - return EDEADLK; - - a_inc(&m->_m_waiters); - t = r | 0x80000000; - a_cas(&m->_m_lock, r, t); - r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv); - a_dec(&m->_m_waiters); - if (r && r != EINTR) break; - } - return r; -} - -weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock); diff --git a/usr/lib/libc/thread/pthread_mutex_trylock.c b/usr/lib/libc/thread/pthread_mutex_trylock.c deleted file mode 100644 index 54876a619..000000000 --- a/usr/lib/libc/thread/pthread_mutex_trylock.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_trylock_owner(pthread_mutex_t *m) -{ - int old, own; - int type = m->_m_type & 15; - pthread_t self = __pthread_self(); - int tid = self->tid; - - old = m->_m_lock; - own = old & 0x7fffffff; - if (own == tid && (type&3) == PTHREAD_MUTEX_RECURSIVE) { - if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN; - m->_m_count++; - return 0; - } - if (own == 0x7fffffff) return ENOTRECOVERABLE; - - if (m->_m_type & 128) { - if (!self->robust_list.off) { - self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next; - __syscall(SYS_set_robust_list, &self->robust_list, 3*sizeof(long)); - } - if (m->_m_waiters) tid |= 0x80000000; - self->robust_list.pending = &m->_m_next; - } - - if ((own && (!(own & 0x40000000) || !(type & 4))) - || a_cas(&m->_m_lock, old, tid) != old) { - self->robust_list.pending = 0; - return EBUSY; - } - - volatile void *next = self->robust_list.head; - m->_m_next = next; - m->_m_prev = &self->robust_list.head; - if (next != &self->robust_list.head) *(volatile void *volatile *) - ((char *)next - sizeof(void *)) = &m->_m_next; - self->robust_list.head = &m->_m_next; - self->robust_list.pending = 0; - - if (own) { - m->_m_count = 0; - m->_m_type |= 8; - return EOWNERDEAD; - } - - return 0; -} - -int __pthread_mutex_trylock(pthread_mutex_t *m) -{ - if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL) - return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY; - return __pthread_mutex_trylock_owner(m); -} - -weak_alias(__pthread_mutex_trylock, pthread_mutex_trylock); diff --git a/usr/lib/libc/thread/pthread_mutex_unlock.c b/usr/lib/libc/thread/pthread_mutex_unlock.c deleted file mode 100644 index 7dd00d275..000000000 --- a/usr/lib/libc/thread/pthread_mutex_unlock.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_unlock(pthread_mutex_t *m) -{ - pthread_t self; - int waiters = m->_m_waiters; - int cont; - int type = m->_m_type & 15; - int priv = (m->_m_type & 128) ^ 128; - - if (type != PTHREAD_MUTEX_NORMAL) { - self = __pthread_self(); - if ((m->_m_lock&0x7fffffff) != self->tid) - return EPERM; - if ((type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count) - return m->_m_count--, 0; - if (!priv) { - self->robust_list.pending = &m->_m_next; - __vm_lock(); - } - volatile void *prev = m->_m_prev; - volatile void *next = m->_m_next; - *(volatile void *volatile *)prev = next; - if (next != &self->robust_list.head) *(volatile void *volatile *) - ((char *)next - sizeof(void *)) = prev; - } - cont = a_swap(&m->_m_lock, (type & 8) ? 0x7fffffff : 0); - if (type != PTHREAD_MUTEX_NORMAL && !priv) { - self->robust_list.pending = 0; - __vm_unlock(); - } - if (waiters || cont<0) - __wake(&m->_m_lock, 1, priv); - return 0; -} - -weak_alias(__pthread_mutex_unlock, pthread_mutex_unlock); diff --git a/usr/lib/libc/thread/pthread_mutexattr_destroy.c b/usr/lib/libc/thread/pthread_mutexattr_destroy.c deleted file mode 100644 index 9fd697472..000000000 --- a/usr/lib/libc/thread/pthread_mutexattr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_destroy(pthread_mutexattr_t *a) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutexattr_init.c b/usr/lib/libc/thread/pthread_mutexattr_init.c deleted file mode 100644 index 0b72c1ba5..000000000 --- a/usr/lib/libc/thread/pthread_mutexattr_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_init(pthread_mutexattr_t *a) -{ - *a = (pthread_mutexattr_t){0}; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutexattr_setprotocol.c b/usr/lib/libc/thread/pthread_mutexattr_setprotocol.c deleted file mode 100644 index c92a31c8a..000000000 --- a/usr/lib/libc/thread/pthread_mutexattr_setprotocol.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol) -{ - if (protocol) return ENOTSUP; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutexattr_setpshared.c b/usr/lib/libc/thread/pthread_mutexattr_setpshared.c deleted file mode 100644 index 100f6ff20..000000000 --- a/usr/lib/libc/thread/pthread_mutexattr_setpshared.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_setpshared(pthread_mutexattr_t *a, int pshared) -{ - if (pshared > 1U) return EINVAL; - a->__attr &= ~128U; - a->__attr |= pshared<<7; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutexattr_setrobust.c b/usr/lib/libc/thread/pthread_mutexattr_setrobust.c deleted file mode 100644 index dcfa4cf1c..000000000 --- a/usr/lib/libc/thread/pthread_mutexattr_setrobust.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust) -{ - if (robust > 1U) return EINVAL; - a->__attr &= ~4; - a->__attr |= robust*4; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_mutexattr_settype.c b/usr/lib/libc/thread/pthread_mutexattr_settype.c deleted file mode 100644 index cd7a80e34..000000000 --- a/usr/lib/libc/thread/pthread_mutexattr_settype.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type) -{ - if ((unsigned)type > 2) return EINVAL; - a->__attr = (a->__attr & ~3) | type; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_once.c b/usr/lib/libc/thread/pthread_once.c deleted file mode 100644 index a8f8aeb17..000000000 --- a/usr/lib/libc/thread/pthread_once.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "pthread_impl.h" - -static void undo(void *control) -{ - /* Wake all waiters, since the waiter status is lost when - * resetting control to the initial state. */ - if (a_swap(control, 0) == 3) - __wake(control, -1, 1); -} - -int __pthread_once_full(pthread_once_t *control, void (*init)(void)) -{ - /* Try to enter initializing state. Four possibilities: - * 0 - we're the first or the other cancelled; run init - * 1 - another thread is running init; wait - * 2 - another thread finished running init; just return - * 3 - another thread is running init, waiters present; wait */ - - for (;;) switch (a_cas(control, 0, 1)) { - case 0: - pthread_cleanup_push(undo, control); - init(); - pthread_cleanup_pop(0); - - if (a_swap(control, 2) == 3) - __wake(control, -1, 1); - return 0; - case 1: - /* If this fails, so will __wait. */ - a_cas(control, 1, 3); - case 3: - __wait(control, 0, 3, 1); - continue; - case 2: - return 0; - } -} - -int __pthread_once(pthread_once_t *control, void (*init)(void)) -{ - /* Return immediately if init finished before, but ensure that - * effects of the init routine are visible to the caller. */ - if (*(volatile int *)control == 2) { - a_barrier(); - return 0; - } - return __pthread_once_full(control, init); -} - -weak_alias(__pthread_once, pthread_once); diff --git a/usr/lib/libc/thread/pthread_rwlock_destroy.c b/usr/lib/libc/thread/pthread_rwlock_destroy.c deleted file mode 100644 index 49ecfbd02..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_destroy(pthread_rwlock_t *rw) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_rwlock_init.c b/usr/lib/libc/thread/pthread_rwlock_init.c deleted file mode 100644 index a2c0b478c..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_init.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_init(pthread_rwlock_t *restrict rw, const pthread_rwlockattr_t *restrict a) -{ - *rw = (pthread_rwlock_t){0}; - if (a) rw->_rw_shared = a->__attr[0]*128; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_rwlock_rdlock.c b/usr/lib/libc/thread/pthread_rwlock_rdlock.c deleted file mode 100644 index 0800d21ff..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_rdlock.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_rdlock(pthread_rwlock_t *rw) -{ - return pthread_rwlock_timedrdlock(rw, 0); -} diff --git a/usr/lib/libc/thread/pthread_rwlock_timedrdlock.c b/usr/lib/libc/thread/pthread_rwlock_timedrdlock.c deleted file mode 100644 index 0d5d0d6c0..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_timedrdlock.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) -{ - int r, t; - - r = pthread_rwlock_tryrdlock(rw); - if (r != EBUSY) return r; - - int spins = 100; - while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin(); - - while ((r=pthread_rwlock_tryrdlock(rw))==EBUSY) { - if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue; - t = r | 0x80000000; - a_inc(&rw->_rw_waiters); - a_cas(&rw->_rw_lock, r, t); - r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128); - a_dec(&rw->_rw_waiters); - if (r && r != EINTR) return r; - } - return r; -} diff --git a/usr/lib/libc/thread/pthread_rwlock_timedwrlock.c b/usr/lib/libc/thread/pthread_rwlock_timedwrlock.c deleted file mode 100644 index 7f26dad1f..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_timedwrlock.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) -{ - int r, t; - - r = pthread_rwlock_trywrlock(rw); - if (r != EBUSY) return r; - - int spins = 100; - while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin(); - - while ((r=pthread_rwlock_trywrlock(rw))==EBUSY) { - if (!(r=rw->_rw_lock)) continue; - t = r | 0x80000000; - a_inc(&rw->_rw_waiters); - a_cas(&rw->_rw_lock, r, t); - r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128); - a_dec(&rw->_rw_waiters); - if (r && r != EINTR) return r; - } - return r; -} diff --git a/usr/lib/libc/thread/pthread_rwlock_tryrdlock.c b/usr/lib/libc/thread/pthread_rwlock_tryrdlock.c deleted file mode 100644 index fa271fcc6..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_tryrdlock.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_tryrdlock(pthread_rwlock_t *rw) -{ - int val, cnt; - do { - val = rw->_rw_lock; - cnt = val & 0x7fffffff; - if (cnt == 0x7fffffff) return EBUSY; - if (cnt == 0x7ffffffe) return EAGAIN; - } while (a_cas(&rw->_rw_lock, val, val+1) != val); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_rwlock_trywrlock.c b/usr/lib/libc/thread/pthread_rwlock_trywrlock.c deleted file mode 100644 index bb3d3a992..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_trywrlock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_trywrlock(pthread_rwlock_t *rw) -{ - if (a_cas(&rw->_rw_lock, 0, 0x7fffffff)) return EBUSY; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_rwlock_unlock.c b/usr/lib/libc/thread/pthread_rwlock_unlock.c deleted file mode 100644 index 7b5eec84d..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_unlock.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_unlock(pthread_rwlock_t *rw) -{ - int val, cnt, waiters, new, priv = rw->_rw_shared^128; - - do { - val = rw->_rw_lock; - cnt = val & 0x7fffffff; - waiters = rw->_rw_waiters; - new = (cnt == 0x7fffffff || cnt == 1) ? 0 : val-1; - } while (a_cas(&rw->_rw_lock, val, new) != val); - - if (!new && (waiters || val<0)) - __wake(&rw->_rw_lock, cnt, priv); - - return 0; -} diff --git a/usr/lib/libc/thread/pthread_rwlock_wrlock.c b/usr/lib/libc/thread/pthread_rwlock_wrlock.c deleted file mode 100644 index 7f33535c7..000000000 --- a/usr/lib/libc/thread/pthread_rwlock_wrlock.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlock_wrlock(pthread_rwlock_t *rw) -{ - return pthread_rwlock_timedwrlock(rw, 0); -} diff --git a/usr/lib/libc/thread/pthread_rwlockattr_destroy.c b/usr/lib/libc/thread/pthread_rwlockattr_destroy.c deleted file mode 100644 index fc8d611ae..000000000 --- a/usr/lib/libc/thread/pthread_rwlockattr_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_rwlockattr_init.c b/usr/lib/libc/thread/pthread_rwlockattr_init.c deleted file mode 100644 index e74206944..000000000 --- a/usr/lib/libc/thread/pthread_rwlockattr_init.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlockattr_init(pthread_rwlockattr_t *a) -{ - *a = (pthread_rwlockattr_t){0}; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_rwlockattr_setpshared.c b/usr/lib/libc/thread/pthread_rwlockattr_setpshared.c deleted file mode 100644 index e7061973d..000000000 --- a/usr/lib/libc/thread/pthread_rwlockattr_setpshared.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *a, int pshared) -{ - if (pshared > 1U) return EINVAL; - a->__attr[0] = pshared; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_self.c b/usr/lib/libc/thread/pthread_self.c deleted file mode 100644 index 241a6202d..000000000 --- a/usr/lib/libc/thread/pthread_self.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" -#include -#include "libc.h" - -static pthread_t __pthread_self_internal() -{ - return __pthread_self(); -} - -weak_alias(__pthread_self_internal, pthread_self); -weak_alias(__pthread_self_internal, thrd_current); diff --git a/usr/lib/libc/thread/pthread_setattr_default_np.c b/usr/lib/libc/thread/pthread_setattr_default_np.c deleted file mode 100644 index ffd2712b0..000000000 --- a/usr/lib/libc/thread/pthread_setattr_default_np.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "pthread_impl.h" -#include - -extern size_t __default_stacksize; -extern size_t __default_guardsize; - -int pthread_setattr_default_np(const pthread_attr_t *attrp) -{ - /* Reject anything in the attr object other than stack/guard size. */ - pthread_attr_t tmp = *attrp, zero = { 0 }; - tmp._a_stacksize = 0; - tmp._a_guardsize = 0; - if (memcmp(&tmp, &zero, sizeof tmp)) - return EINVAL; - - __inhibit_ptc(); - if (attrp->_a_stacksize >= __default_stacksize) - __default_stacksize = attrp->_a_stacksize; - if (attrp->_a_guardsize >= __default_guardsize) - __default_guardsize = attrp->_a_guardsize; - __release_ptc(); - - return 0; -} - -int pthread_getattr_default_np(pthread_attr_t *attrp) -{ - __acquire_ptc(); - *attrp = (pthread_attr_t) { - ._a_stacksize = __default_stacksize, - ._a_guardsize = __default_guardsize, - }; - __release_ptc(); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_setcancelstate.c b/usr/lib/libc/thread/pthread_setcancelstate.c deleted file mode 100644 index 5ab8c338f..000000000 --- a/usr/lib/libc/thread/pthread_setcancelstate.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_setcancelstate(int new, int *old) -{ - if (new > 2U) return EINVAL; - struct pthread *self = __pthread_self(); - if (old) *old = self->canceldisable; - self->canceldisable = new; - return 0; -} - -weak_alias(__pthread_setcancelstate, pthread_setcancelstate); diff --git a/usr/lib/libc/thread/pthread_setcanceltype.c b/usr/lib/libc/thread/pthread_setcanceltype.c deleted file mode 100644 index bf0a3f383..000000000 --- a/usr/lib/libc/thread/pthread_setcanceltype.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" - -int pthread_setcanceltype(int new, int *old) -{ - struct pthread *self = __pthread_self(); - if (new > 1U) return EINVAL; - if (old) *old = self->cancelasync; - self->cancelasync = new; - if (new) pthread_testcancel(); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_setconcurrency.c b/usr/lib/libc/thread/pthread_setconcurrency.c deleted file mode 100644 index 091abf98c..000000000 --- a/usr/lib/libc/thread/pthread_setconcurrency.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int pthread_setconcurrency(int val) -{ - if (val < 0) return EINVAL; - if (val > 0) return EAGAIN; - return 0; -} diff --git a/usr/lib/libc/thread/pthread_setname_np.c b/usr/lib/libc/thread/pthread_setname_np.c deleted file mode 100644 index 82d35e17e..000000000 --- a/usr/lib/libc/thread/pthread_setname_np.c +++ /dev/null @@ -1,26 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include - -#include "pthread_impl.h" - -int pthread_setname_np(pthread_t thread, const char *name) -{ - int fd, cs, status = 0; - char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)]; - size_t len; - - if ((len = strnlen(name, 16)) > 15) return ERANGE; - - if (thread == pthread_self()) - return prctl(PR_SET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0; - - snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid); - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - if ((fd = open(f, O_WRONLY)) < 0 || write(fd, name, len) < 0) status = errno; - if (fd >= 0) close(fd); - pthread_setcancelstate(cs, 0); - return status; -} diff --git a/usr/lib/libc/thread/pthread_setschedparam.c b/usr/lib/libc/thread/pthread_setschedparam.c deleted file mode 100644 index c4738d643..000000000 --- a/usr/lib/libc/thread/pthread_setschedparam.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param) -{ - int r; - __lock(t->killlock); - r = t->dead ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, param); - __unlock(t->killlock); - return r; -} diff --git a/usr/lib/libc/thread/pthread_setschedprio.c b/usr/lib/libc/thread/pthread_setschedprio.c deleted file mode 100644 index e0bdc03b8..000000000 --- a/usr/lib/libc/thread/pthread_setschedprio.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int pthread_setschedprio(pthread_t t, int prio) -{ - int r; - __lock(t->killlock); - r = t->dead ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio); - __unlock(t->killlock); - return r; -} diff --git a/usr/lib/libc/thread/pthread_setspecific.c b/usr/lib/libc/thread/pthread_setspecific.c deleted file mode 100644 index 55e46a899..000000000 --- a/usr/lib/libc/thread/pthread_setspecific.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" - -int pthread_setspecific(pthread_key_t k, const void *x) -{ - struct pthread *self = __pthread_self(); - /* Avoid unnecessary COW */ - if (self->tsd[k] != x) { - self->tsd[k] = (void *)x; - self->tsd_used = 1; - } - return 0; -} diff --git a/usr/lib/libc/thread/pthread_sigmask.c b/usr/lib/libc/thread/pthread_sigmask.c deleted file mode 100644 index 88c333f6b..000000000 --- a/usr/lib/libc/thread/pthread_sigmask.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include "syscall.h" - -int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old) -{ - int ret; - if ((unsigned)how - SIG_BLOCK > 2U) return EINVAL; - ret = -__syscall(SYS_rt_sigprocmask, how, set, old, _NSIG/8); - if (!ret && old) { - if (sizeof old->__bits[0] == 8) { - old->__bits[0] &= ~0x380000000ULL; - } else { - old->__bits[0] &= ~0x80000000UL; - old->__bits[1] &= ~0x3UL; - } - } - return ret; -} diff --git a/usr/lib/libc/thread/pthread_spin_destroy.c b/usr/lib/libc/thread/pthread_spin_destroy.c deleted file mode 100644 index e65a820c3..000000000 --- a/usr/lib/libc/thread/pthread_spin_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_destroy(pthread_spinlock_t *s) -{ - return 0; -} diff --git a/usr/lib/libc/thread/pthread_spin_init.c b/usr/lib/libc/thread/pthread_spin_init.c deleted file mode 100644 index 681881cf3..000000000 --- a/usr/lib/libc/thread/pthread_spin_init.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_init(pthread_spinlock_t *s, int shared) -{ - return *s = 0; -} diff --git a/usr/lib/libc/thread/pthread_spin_lock.c b/usr/lib/libc/thread/pthread_spin_lock.c deleted file mode 100644 index ded2b653c..000000000 --- a/usr/lib/libc/thread/pthread_spin_lock.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" -#include - -int pthread_spin_lock(pthread_spinlock_t *s) -{ - while (*(volatile int *)s || a_cas(s, 0, EBUSY)) a_spin(); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_spin_trylock.c b/usr/lib/libc/thread/pthread_spin_trylock.c deleted file mode 100644 index 5284fdac2..000000000 --- a/usr/lib/libc/thread/pthread_spin_trylock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" -#include - -int pthread_spin_trylock(pthread_spinlock_t *s) -{ - return a_cas(s, 0, EBUSY); -} diff --git a/usr/lib/libc/thread/pthread_spin_unlock.c b/usr/lib/libc/thread/pthread_spin_unlock.c deleted file mode 100644 index 724d9e0d6..000000000 --- a/usr/lib/libc/thread/pthread_spin_unlock.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_spin_unlock(pthread_spinlock_t *s) -{ - a_store(s, 0); - return 0; -} diff --git a/usr/lib/libc/thread/pthread_testcancel.c b/usr/lib/libc/thread/pthread_testcancel.c deleted file mode 100644 index ee48e6d8a..000000000 --- a/usr/lib/libc/thread/pthread_testcancel.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "pthread_impl.h" -#include "libc.h" - -static void dummy() -{ -} - -weak_alias(dummy, __testcancel); - -void __pthread_testcancel() -{ - __testcancel(); -} - -weak_alias(__pthread_testcancel, pthread_testcancel); diff --git a/usr/lib/libc/thread/sem_destroy.c b/usr/lib/libc/thread/sem_destroy.c deleted file mode 100644 index f4aced5da..000000000 --- a/usr/lib/libc/thread/sem_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int sem_destroy(sem_t *sem) -{ - return 0; -} diff --git a/usr/lib/libc/thread/sem_getvalue.c b/usr/lib/libc/thread/sem_getvalue.c deleted file mode 100644 index d9d830717..000000000 --- a/usr/lib/libc/thread/sem_getvalue.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int sem_getvalue(sem_t *restrict sem, int *restrict valp) -{ - int val = sem->__val[0]; - *valp = val < 0 ? 0 : val; - return 0; -} diff --git a/usr/lib/libc/thread/sem_init.c b/usr/lib/libc/thread/sem_init.c deleted file mode 100644 index 550924343..000000000 --- a/usr/lib/libc/thread/sem_init.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include - -int sem_init(sem_t *sem, int pshared, unsigned value) -{ - if (value > SEM_VALUE_MAX) { - errno = EINVAL; - return -1; - } - sem->__val[0] = value; - sem->__val[1] = 0; - sem->__val[2] = pshared ? 0 : 128; - return 0; -} diff --git a/usr/lib/libc/thread/sem_open.c b/usr/lib/libc/thread/sem_open.c deleted file mode 100644 index fda0acd35..000000000 --- a/usr/lib/libc/thread/sem_open.c +++ /dev/null @@ -1,175 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libc.h" - -char *__shm_mapname(const char *, char *); - -static struct { - ino_t ino; - sem_t *sem; - int refcnt; -} *semtab; -static volatile int lock[2]; - -#define FLAGS (O_RDWR|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK) - -sem_t *sem_open(const char *name, int flags, ...) -{ - va_list ap; - mode_t mode; - unsigned value; - int fd, i, e, slot, first=1, cnt, cs; - sem_t newsem; - void *map; - char tmp[64]; - struct timespec ts; - struct stat st; - char buf[NAME_MAX+10]; - - if (!(name = __shm_mapname(name, buf))) - return SEM_FAILED; - - LOCK(lock); - /* Allocate table if we don't have one yet */ - if (!semtab && !(semtab = calloc(sizeof *semtab, SEM_NSEMS_MAX))) { - UNLOCK(lock); - return SEM_FAILED; - } - - /* Reserve a slot in case this semaphore is not mapped yet; - * this is necessary because there is no way to handle - * failures after creation of the file. */ - slot = -1; - for (cnt=i=0; i= 0) { - if (fstat(fd, &st) < 0 || - (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { - close(fd); - goto fail; - } - close(fd); - break; - } - if (errno != ENOENT) - goto fail; - } - if (!(flags & O_CREAT)) - goto fail; - if (first) { - first = 0; - va_start(ap, flags); - mode = va_arg(ap, mode_t) & 0666; - value = va_arg(ap, unsigned); - va_end(ap); - if (value > SEM_VALUE_MAX) { - errno = EINVAL; - goto fail; - } - sem_init(&newsem, 1, value); - } - /* Create a temp file with the new semaphore contents - * and attempt to atomically link it as the new name */ - clock_gettime(CLOCK_REALTIME, &ts); - snprintf(tmp, sizeof(tmp), "/dev/shm/tmp-%d", (int)ts.tv_nsec); - fd = open(tmp, O_CREAT|O_EXCL|FLAGS, mode); - if (fd < 0) { - if (errno == EEXIST) continue; - goto fail; - } - if (write(fd, &newsem, sizeof newsem) != sizeof newsem || fstat(fd, &st) < 0 || - (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { - close(fd); - unlink(tmp); - goto fail; - } - close(fd); - e = link(tmp, name) ? errno : 0; - unlink(tmp); - if (!e) break; - munmap(map, sizeof(sem_t)); - /* Failure is only fatal when doing an exclusive open; - * otherwise, next iteration will try to open the - * existing file. */ - if (e != EEXIST || flags == (O_CREAT|O_EXCL)) - goto fail; - } - - /* See if the newly mapped semaphore is already mapped. If - * so, unmap the new mapping and use the existing one. Otherwise, - * add it to the table of mapped semaphores. */ - LOCK(lock); - for (i=0; i -#include "pthread_impl.h" - -int sem_post(sem_t *sem) -{ - int val, waiters, priv = sem->__val[2]; - do { - val = sem->__val[0]; - waiters = sem->__val[1]; - if (val == SEM_VALUE_MAX) { - errno = EOVERFLOW; - return -1; - } - } while (a_cas(sem->__val, val, val+1+(val<0)) != val); - if (val<0 || waiters) __wake(sem->__val, 1, priv); - return 0; -} diff --git a/usr/lib/libc/thread/sem_timedwait.c b/usr/lib/libc/thread/sem_timedwait.c deleted file mode 100644 index 8132eb1bf..000000000 --- a/usr/lib/libc/thread/sem_timedwait.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "pthread_impl.h" - -static void cleanup(void *p) -{ - a_dec(p); -} - -int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) -{ - pthread_testcancel(); - - if (!sem_trywait(sem)) return 0; - - int spins = 100; - while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin(); - - while (sem_trywait(sem)) { - int r; - a_inc(sem->__val+1); - a_cas(sem->__val, 0, -1); - pthread_cleanup_push(cleanup, (void *)(sem->__val+1)); - r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]); - pthread_cleanup_pop(1); - if (r && r != EINTR) { - errno = r; - return -1; - } - } - return 0; -} diff --git a/usr/lib/libc/thread/sem_trywait.c b/usr/lib/libc/thread/sem_trywait.c deleted file mode 100644 index 04edf46b5..000000000 --- a/usr/lib/libc/thread/sem_trywait.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include "pthread_impl.h" - -int sem_trywait(sem_t *sem) -{ - int val; - while ((val=sem->__val[0]) > 0) { - int new = val-1-(val==1 && sem->__val[1]); - if (a_cas(sem->__val, val, new)==val) return 0; - } - errno = EAGAIN; - return -1; -} diff --git a/usr/lib/libc/thread/sem_unlink.c b/usr/lib/libc/thread/sem_unlink.c deleted file mode 100644 index c06134bd4..000000000 --- a/usr/lib/libc/thread/sem_unlink.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int sem_unlink(const char *name) -{ - return shm_unlink(name); -} diff --git a/usr/lib/libc/thread/sem_wait.c b/usr/lib/libc/thread/sem_wait.c deleted file mode 100644 index 264194f97..000000000 --- a/usr/lib/libc/thread/sem_wait.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int sem_wait(sem_t *sem) -{ - return sem_timedwait(sem, 0); -} diff --git a/usr/lib/libc/thread/synccall.c b/usr/lib/libc/thread/synccall.c deleted file mode 100644 index f68135763..000000000 --- a/usr/lib/libc/thread/synccall.c +++ /dev/null @@ -1,178 +0,0 @@ -#include "pthread_impl.h" -#include -#include -#include -#include -#include -#include "futex.h" -#include "atomic.h" -#include "../dirent/__dirent.h" - -static struct chain { - struct chain *next; - int tid; - sem_t target_sem, caller_sem; -} *volatile head; - -static volatile int synccall_lock[2]; -static volatile int target_tid; -static void (*callback)(void *), *context; -static volatile int dummy = 0; -weak_alias(dummy, __block_new_threads); - -static void handler(int sig) -{ - struct chain ch; - int old_errno = errno; - - sem_init(&ch.target_sem, 0, 0); - sem_init(&ch.caller_sem, 0, 0); - - ch.tid = __syscall(SYS_gettid); - - do ch.next = head; - while (a_cas_p(&head, ch.next, &ch) != ch.next); - - if (a_cas(&target_tid, ch.tid, 0) == (ch.tid | 0x80000000)) - __syscall(SYS_futex, &target_tid, FUTEX_UNLOCK_PI|FUTEX_PRIVATE); - - sem_wait(&ch.target_sem); - callback(context); - sem_post(&ch.caller_sem); - sem_wait(&ch.target_sem); - - errno = old_errno; -} - -void __synccall(void (*func)(void *), void *ctx) -{ - sigset_t oldmask; - int cs, i, r, pid, self;; - DIR dir = {0}; - struct dirent *de; - struct sigaction sa = { .sa_flags = SA_RESTART, .sa_handler = handler }; - struct chain *cp, *next; - struct timespec ts; - - /* Blocking signals in two steps, first only app-level signals - * before taking the lock, then all signals after taking the lock, - * is necessary to achieve AS-safety. Blocking them all first would - * deadlock if multiple threads called __synccall. Waiting to block - * any until after the lock would allow re-entry in the same thread - * with the lock already held. */ - __block_app_sigs(&oldmask); - LOCK(synccall_lock); - __block_all_sigs(0); - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); - - head = 0; - - if (!libc.threaded) goto single_threaded; - - callback = func; - context = ctx; - - /* This atomic store ensures that any signaled threads will see the - * above stores, and prevents more than a bounded number of threads, - * those already in pthread_create, from creating new threads until - * the value is cleared to zero again. */ - a_store(&__block_new_threads, 1); - - /* Block even implementation-internal signals, so that nothing - * interrupts the SIGSYNCCALL handlers. The main possible source - * of trouble is asynchronous cancellation. */ - memset(&sa.sa_mask, -1, sizeof sa.sa_mask); - __libc_sigaction(SIGSYNCCALL, &sa, 0); - - pid = __syscall(SYS_getpid); - self = __syscall(SYS_gettid); - - /* Since opendir is not AS-safe, the DIR needs to be setup manually - * in automatic storage. Thankfully this is easy. */ - dir.fd = open("/proc/self/task", O_RDONLY|O_DIRECTORY|O_CLOEXEC); - if (dir.fd < 0) goto out; - - /* Initially send one signal per counted thread. But since we can't - * synchronize with thread creation/exit here, there could be too - * few signals. This initial signaling is just an optimization, not - * part of the logic. */ - for (i=libc.threads_minus_1; i; i--) - __syscall(SYS_kill, pid, SIGSYNCCALL); - - /* Loop scanning the kernel-provided thread list until it shows no - * threads that have not already replied to the signal. */ - for (;;) { - int miss_cnt = 0; - while ((de = readdir(&dir))) { - if (!isdigit(de->d_name[0])) continue; - int tid = atoi(de->d_name); - if (tid == self || !tid) continue; - - /* Set the target thread as the PI futex owner before - * checking if it's in the list of caught threads. If it - * adds itself to the list after we check for it, then - * it will see its own tid in the PI futex and perform - * the unlock operation. */ - a_store(&target_tid, tid); - - /* Thread-already-caught is a success condition. */ - for (cp = head; cp && cp->tid != tid; cp=cp->next); - if (cp) continue; - - r = -__syscall(SYS_tgkill, pid, tid, SIGSYNCCALL); - - /* Target thread exit is a success condition. */ - if (r == ESRCH) continue; - - /* The FUTEX_LOCK_PI operation is used to loan priority - * to the target thread, which otherwise may be unable - * to run. Timeout is necessary because there is a race - * condition where the tid may be reused by a different - * process. */ - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_nsec += 10000000; - if (ts.tv_nsec >= 1000000000) { - ts.tv_sec++; - ts.tv_nsec -= 1000000000; - } - r = -__syscall(SYS_futex, &target_tid, - FUTEX_LOCK_PI|FUTEX_PRIVATE, 0, &ts); - - /* Obtaining the lock means the thread responded. ESRCH - * means the target thread exited, which is okay too. */ - if (!r || r == ESRCH) continue; - - miss_cnt++; - } - if (!miss_cnt) break; - rewinddir(&dir); - } - close(dir.fd); - - /* Serialize execution of callback in caught threads. */ - for (cp=head; cp; cp=cp->next) { - sem_post(&cp->target_sem); - sem_wait(&cp->caller_sem); - } - - sa.sa_handler = SIG_IGN; - __libc_sigaction(SIGSYNCCALL, &sa, 0); - -single_threaded: - func(ctx); - - /* Only release the caught threads once all threads, including the - * caller, have returned from the callback function. */ - for (cp=head; cp; cp=next) { - next = cp->next; - sem_post(&cp->target_sem); - } - -out: - a_store(&__block_new_threads, 0); - __wake(&__block_new_threads, -1, 1); - - pthread_setcancelstate(cs, 0); - UNLOCK(synccall_lock); - __restore_sigs(&oldmask); -} diff --git a/usr/lib/libc/thread/syscall_cp.c b/usr/lib/libc/thread/syscall_cp.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/usr/lib/libc/thread/thrd_create.c b/usr/lib/libc/thread/thrd_create.c deleted file mode 100644 index e03366952..000000000 --- a/usr/lib/libc/thread/thrd_create.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "pthread_impl.h" -#include - -int __pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict); - -int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) -{ - int ret = __pthread_create(thr, __ATTRP_C11_THREAD, (void *(*)(void *))func, arg); - switch (ret) { - case 0: return thrd_success; - case EAGAIN: return thrd_nomem; - default: return thrd_error; - } -} diff --git a/usr/lib/libc/thread/thrd_exit.c b/usr/lib/libc/thread/thrd_exit.c deleted file mode 100644 index b66bd9969..000000000 --- a/usr/lib/libc/thread/thrd_exit.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" -#include - -_Noreturn void __pthread_exit(void *); - -_Noreturn void thrd_exit(int result) -{ - __pthread_exit((void*)(intptr_t)result); -} diff --git a/usr/lib/libc/thread/thrd_join.c b/usr/lib/libc/thread/thrd_join.c deleted file mode 100644 index ac6678939..000000000 --- a/usr/lib/libc/thread/thrd_join.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int __pthread_join(thrd_t, void**); - -int thrd_join(thrd_t t, int *res) -{ - void *pthread_res; - __pthread_join(t, &pthread_res); - if (res) *res = (int)(intptr_t)pthread_res; - return thrd_success; -} diff --git a/usr/lib/libc/thread/thrd_sleep.c b/usr/lib/libc/thread/thrd_sleep.c deleted file mode 100644 index 2a3749d35..000000000 --- a/usr/lib/libc/thread/thrd_sleep.c +++ /dev/null @@ -1,16 +0,0 @@ -//#include -#include -#include - -int thrd_sleep(const struct timespec *req, struct timespec *rem) -{ -// int ret = __syscall(SYS_nanosleep, req, rem); - - int ret = sys_nanosleep(req, rem); - - switch (ret) { - case 0: return 0; - case -EINTR: return -1; /* value specified by C11 */ - default: return -2; - } -} diff --git a/usr/lib/libc/thread/thrd_yield.c b/usr/lib/libc/thread/thrd_yield.c deleted file mode 100644 index f7ad13219..000000000 --- a/usr/lib/libc/thread/thrd_yield.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -void thrd_yield() -{ - __syscall(SYS_sched_yield); -} diff --git a/usr/lib/libc/thread/tls.c b/usr/lib/libc/thread/tls.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/usr/lib/libc/thread/tss_create.c b/usr/lib/libc/thread/tss_create.c deleted file mode 100644 index 251d22b9a..000000000 --- a/usr/lib/libc/thread/tss_create.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -int __pthread_key_create(tss_t *, void (*)(void *)); - -int tss_create(tss_t *tss, tss_dtor_t dtor) -{ - /* Different error returns are possible. C glues them together into - * just failure notification. Can't be optimized to a tail call, - * unless thrd_error equals EAGAIN. */ - return __pthread_key_create(tss, dtor) ? thrd_error : thrd_success; -} diff --git a/usr/lib/libc/thread/tss_delete.c b/usr/lib/libc/thread/tss_delete.c deleted file mode 100644 index 35db1032d..000000000 --- a/usr/lib/libc/thread/tss_delete.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int __pthread_key_delete(tss_t k); - -void tss_delete(tss_t key) -{ - __pthread_key_delete(key); -} diff --git a/usr/lib/libc/thread/tss_set.c b/usr/lib/libc/thread/tss_set.c deleted file mode 100644 index 70c4fb723..000000000 --- a/usr/lib/libc/thread/tss_set.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" -#include - -int tss_set(tss_t k, void *x) -{ - struct pthread *self = __pthread_self(); - /* Avoid unnecessary COW */ - if (self->tsd[k] != x) { - self->tsd[k] = x; - self->tsd_used = 1; - } - return thrd_success; -} diff --git a/usr/lib/libc/thread/vmlock.c b/usr/lib/libc/thread/vmlock.c deleted file mode 100644 index 75f3cb761..000000000 --- a/usr/lib/libc/thread/vmlock.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "pthread_impl.h" - -static volatile int vmlock[2]; - -void __vm_wait() -{ - int tmp; - while ((tmp=vmlock[0])) - __wait(vmlock, vmlock+1, tmp, 1); -} - -void __vm_lock() -{ - a_inc(vmlock); -} - -void __vm_unlock() -{ - if (a_fetch_add(vmlock, -1)==1 && vmlock[1]) - __wake(vmlock, -1, 1); -} diff --git a/usr/lib/libc/time/CMakeLists.txt b/usr/lib/libc/time/CMakeLists.txt deleted file mode 100644 index 6854ed331..000000000 --- a/usr/lib/libc/time/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ - -target_sources(c - PRIVATE - nanosleep.c - gettimeofday.c - time.c - clock.c - clock_gettime.c - ctime.c - localtime.c - asctime.c - localtime_r.c - strftime.c - __asctime.c - __year_to_secs.c - __secs_to_tm.c - __month_to_secs.c - __tm_to_secs.c -) diff --git a/usr/lib/libc/time/__asctime.c b/usr/lib/libc/time/__asctime.c deleted file mode 100644 index fc6b248ee..000000000 --- a/usr/lib/libc/time/__asctime.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include - -#include "locale_impl.h" -#include "atomic.h" - -const char *__nl_langinfo_l(nl_item, locale_t); - -char *__asctime(const struct tm *restrict tm, char *restrict buf) -{ - if (snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", - - __nl_langinfo_l(ABDAY_1+tm->tm_wday, C_LOCALE), - __nl_langinfo_l(ABMON_1+tm->tm_mon, C_LOCALE), - - tm->tm_mday, tm->tm_hour, - tm->tm_min, tm->tm_sec, - 1900 + tm->tm_year) >= 26) - { - /* ISO C requires us to use the above format string, - * even if it will not fit in the buffer. Thus asctime_r - * is _supposed_ to crash if the fields in tm are too large. - * We follow this behavior and crash "gracefully" to warn - * application developers that they may not be so lucky - * on other implementations (e.g. stack smashing..). - */ - a_crash(); - } - return buf; -} diff --git a/usr/lib/libc/time/__map_file.c b/usr/lib/libc/time/__map_file.c deleted file mode 100644 index b91eb8edb..000000000 --- a/usr/lib/libc/time/__map_file.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -void *__mmap(void *, size_t, int, int, int, off_t); - -const char unsigned *__map_file(const char *pathname, size_t *size) -{ - struct stat st; - const unsigned char *map = MAP_FAILED; - int fd = __sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK); - if (fd < 0) return 0; - if (!__syscall(SYS_fstat, fd, &st)) { - map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - *size = st.st_size; - } - __syscall(SYS_close, fd); - return map == MAP_FAILED ? 0 : map; -} diff --git a/usr/lib/libc/time/__month_to_secs.c b/usr/lib/libc/time/__month_to_secs.c deleted file mode 100644 index 43248fb3c..000000000 --- a/usr/lib/libc/time/__month_to_secs.c +++ /dev/null @@ -1,10 +0,0 @@ -int __month_to_secs(int month, int is_leap) -{ - static const int secs_through_month[] = { - 0, 31*86400, 59*86400, 90*86400, - 120*86400, 151*86400, 181*86400, 212*86400, - 243*86400, 273*86400, 304*86400, 334*86400 }; - int t = secs_through_month[month]; - if (is_leap && month >= 2) t+=86400; - return t; -} diff --git a/usr/lib/libc/time/__secs_to_tm.c b/usr/lib/libc/time/__secs_to_tm.c deleted file mode 100644 index 093d9021a..000000000 --- a/usr/lib/libc/time/__secs_to_tm.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "time_impl.h" -#include - -/* 2000-03-01 (mod 400 year, immediately after feb29 */ -#define LEAPOCH (946684800LL + 86400*(31+29)) - -#define DAYS_PER_400Y (365*400 + 97) -#define DAYS_PER_100Y (365*100 + 24) -#define DAYS_PER_4Y (365*4 + 1) - -int __secs_to_tm(long long t, struct tm *tm) -{ - long long days, secs, years; - int remdays, remsecs, remyears; - int qc_cycles, c_cycles, q_cycles; - int months; - int wday, yday, leap; - static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29}; - - /* Reject time_t values whose year would overflow int */ - if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL) - return -1; - - secs = t - LEAPOCH; - days = secs / 86400; - remsecs = secs % 86400; - if (remsecs < 0) { - remsecs += 86400; - days--; - } - - wday = (3+days)%7; - if (wday < 0) wday += 7; - - qc_cycles = days / DAYS_PER_400Y; - remdays = days % DAYS_PER_400Y; - if (remdays < 0) { - remdays += DAYS_PER_400Y; - qc_cycles--; - } - - c_cycles = remdays / DAYS_PER_100Y; - if (c_cycles == 4) c_cycles--; - remdays -= c_cycles * DAYS_PER_100Y; - - q_cycles = remdays / DAYS_PER_4Y; - if (q_cycles == 25) q_cycles--; - remdays -= q_cycles * DAYS_PER_4Y; - - remyears = remdays / 365; - if (remyears == 4) remyears--; - remdays -= remyears * 365; - - leap = !remyears && (q_cycles || !c_cycles); - yday = remdays + 31 + 28 + leap; - if (yday >= 365+leap) yday -= 365+leap; - - years = remyears + 4*q_cycles + 100*c_cycles + 400LL*qc_cycles; - - for (months=0; days_in_month[months] <= remdays; months++) - remdays -= days_in_month[months]; - - if (months >= 10) { - months -= 12; - years++; - } - - if (years+100 > INT_MAX || years+100 < INT_MIN) - return -1; - - tm->tm_year = years + 100; - tm->tm_mon = months + 2; - tm->tm_mday = remdays + 1; - tm->tm_wday = wday; - tm->tm_yday = yday; - - tm->tm_hour = remsecs / 3600; - tm->tm_min = remsecs / 60 % 60; - tm->tm_sec = remsecs % 60; - - return 0; -} diff --git a/usr/lib/libc/time/__tm_to_secs.c b/usr/lib/libc/time/__tm_to_secs.c deleted file mode 100644 index c29fa985a..000000000 --- a/usr/lib/libc/time/__tm_to_secs.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "time_impl.h" - -long long __tm_to_secs(const struct tm *tm) -{ - int is_leap; - long long year = tm->tm_year; - int month = tm->tm_mon; - if (month >= 12 || month < 0) { - int adj = month / 12; - month %= 12; - if (month < 0) { - adj--; - month += 12; - } - year += adj; - } - long long t = __year_to_secs(year, &is_leap); - t += __month_to_secs(month, is_leap); - t += 86400LL * (tm->tm_mday-1); - t += 3600LL * tm->tm_hour; - t += 60LL * tm->tm_min; - t += tm->tm_sec; - return t; -} diff --git a/usr/lib/libc/time/__tz.c b/usr/lib/libc/time/__tz.c deleted file mode 100644 index 2851e4389..000000000 --- a/usr/lib/libc/time/__tz.c +++ /dev/null @@ -1,421 +0,0 @@ -#include "time_impl.h" -#include -#include -#include -#include -#include "libc.h" - -long __timezone = 0; -int __daylight = 0; -char *__tzname[2] = { 0, 0 }; - -weak_alias(__timezone, timezone); -weak_alias(__daylight, daylight); -weak_alias(__tzname, tzname); - -static char std_name[TZNAME_MAX+1]; -static char dst_name[TZNAME_MAX+1]; -const char __gmt[] = "GMT"; - -static int dst_off; -static int r0[5], r1[5]; - -static const unsigned char *zi, *trans, *__index, *types, *abbrevs, *abbrevs_end; -static size_t map_size; - -static char old_tz_buf[32]; -static char *old_tz = old_tz_buf; -static size_t old_tz_size = sizeof old_tz_buf; - -static volatile int lock[2]; - -static int getint(const char **p) -{ - unsigned x; - for (x=0; **p-'0'<10U; (*p)++) x = **p-'0' + 10*x; - return x; -} - -static int getoff(const char **p) -{ - int neg = 0; - if (**p == '-') { - ++*p; - neg = 1; - } else if (**p == '+') { - ++*p; - } - int off = 3600*getint(p); - if (**p == ':') { - ++*p; - off += 60*getint(p); - if (**p == ':') { - ++*p; - off += getint(p); - } - } - return neg ? -off : off; -} - -static void getrule(const char **p, int rule[5]) -{ - int r = rule[0] = **p; - - if (r!='M') { - if (r=='J') ++*p; - else rule[0] = 0; - rule[1] = getint(p); - } else { - ++*p; rule[1] = getint(p); - ++*p; rule[2] = getint(p); - ++*p; rule[3] = getint(p); - } - - if (**p=='/') { - ++*p; - rule[4] = getoff(p); - } else { - rule[4] = 7200; - } -} - -static void getname(char *d, const char **p) -{ - int i; - if (**p == '<') { - ++*p; - for (i=0; (*p)[i]!='>' && i PATH_MAX+1) s = __gmt, i = 3; - if (i >= old_tz_size) { - old_tz_size *= 2; - if (i >= old_tz_size) old_tz_size = i+1; - if (old_tz_size > PATH_MAX+2) old_tz_size = PATH_MAX+2; - old_tz = malloc(old_tz_size); - } - if (old_tz) memcpy(old_tz, s, i+1); - - /* Non-suid can use an absolute tzfile pathname or a relative - * pathame beginning with "."; in secure mode, only the - * standard path will be searched. */ - if (*s == ':' || ((p=strchr(s, '/')) && !memchr(s, ',', p-s))) { - if (*s == ':') s++; - if (*s == '/' || *s == '.') { - if (!libc.secure || !strcmp(s, "/etc/localtime")) - map = __map_file(s, &map_size); - } else { - size_t l = strlen(s); - if (l <= NAME_MAX && !strchr(s, '.')) { - memcpy(pathname, s, l+1); - pathname[l] = 0; - for (try=search; !map && *try; try+=l+1) { - l = strlen(try); - memcpy(pathname-l, try, l); - map = __map_file(pathname-l, &map_size); - } - } - } - if (!map) s = __gmt; - } - if (map && (map_size < 44 || memcmp(map, "TZif", 4))) { - __munmap((void *)map, map_size); - map = 0; - s = __gmt; - } - - zi = map; - if (map) { - int scale = 2; - if (sizeof(time_t) > 4 && map[4]=='2') { - size_t skip = zi_dotprod(zi+20, VEC(1,1,8,5,6,1), 6); - trans = zi+skip+44+44; - scale++; - } else { - trans = zi+44; - } - __index = trans + (zi_read32(trans-12) << scale); - types = __index + zi_read32(trans-12); - abbrevs = types + 6*zi_read32(trans-8); - abbrevs_end = abbrevs + zi_read32(trans-4); - if (zi[map_size-1] == '\n') { - for (s = (const char *)zi+map_size-2; *s!='\n'; s--); - s++; - } else { - const unsigned char *p; - __tzname[0] = __tzname[1] = 0; - __daylight = __timezone = dst_off = 0; - for (i=0; i<5; i++) r0[i] = r1[i] = 0; - for (p=types; p>scale, m; - - if (!n) { - if (alt) *alt = 0; - return 0; - } - - /* Binary search for 'most-recent rule before t'. */ - while (n > 1) { - m = a + n/2; - x = zi_read32(trans + (m<>scale; - if (a == n-1) return -1; - if (a == 0) { - x = zi_read32(trans + (a<>(m-1))&1); -} - -/* Convert a POSIX DST rule plus year to seconds since epoch. */ - -static long long rule_to_secs(const int *rule, int year) -{ - int is_leap; - long long t = __year_to_secs(year, &is_leap); - int x, m, n, d; - if (rule[0]!='M') { - x = rule[1]; - if (rule[0]=='J' && (x < 60 || !is_leap)) x--; - t += 86400 * x; - } else { - m = rule[1]; - n = rule[2]; - d = rule[3]; - t += __month_to_secs(m-1, is_leap); - int wday = (int)((t + 4*86400) % (7*86400)) / 86400; - int days = d - wday; - if (days < 0) days += 7; - if (n == 5 && days+28 >= days_in_month(m, is_leap)) n = 4; - t += 86400 * (days + 7*(n-1)); - } - t += rule[4]; - return t; -} - -/* Determine the time zone in effect for a given time in seconds since the - * epoch. It can be given in local or universal time. The results will - * indicate whether DST is in effect at the queried time, and will give both - * the GMT offset for the active zone/DST rule and the opposite DST. This - * enables a caller to efficiently adjust for the case where an explicit - * DST specification mismatches what would be in effect at the time. */ - -void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppoff, const char **zonename) -{ - LOCK(lock); - - do_tzset(); - - if (zi) { - size_t alt, i = scan_trans(t, local, &alt); - if (i != -1) { - *isdst = types[6*i+4]; - *offset = (int32_t)zi_read32(types+6*i); - *zonename = (const char *)abbrevs + types[6*i+5]; - if (oppoff) *oppoff = (int32_t)zi_read32(types+6*alt); - UNLOCK(lock); - return; - } - } - - if (!__daylight) goto std; - - /* FIXME: may be broken if DST changes right at year boundary? - * Also, this could be more efficient.*/ - long long y = t / 31556952 + 70; - while (__year_to_secs(y, 0) > t) y--; - while (__year_to_secs(y+1, 0) < t) y++; - - long long t0 = rule_to_secs(r0, y); - long long t1 = rule_to_secs(r1, y); - - if (!local) { - t0 += __timezone; - t1 += dst_off; - } - if (t0 < t1) { - if (t >= t0 && t < t1) goto dst; - goto std; - } else { - if (t >= t1 && t < t0) goto std; - goto dst; - } -std: - *isdst = 0; - *offset = -__timezone; - if (oppoff) *oppoff = -dst_off; - *zonename = __tzname[0]; - UNLOCK(lock); - return; -dst: - *isdst = 1; - *offset = -dst_off; - if (oppoff) *oppoff = -__timezone; - *zonename = __tzname[1]; - UNLOCK(lock); -} - -void __tzset() -{ - LOCK(lock); - do_tzset(); - UNLOCK(lock); -} - -weak_alias(__tzset, tzset); - -const char *__tm_to_tzname(const struct tm *tm) -{ - const void *p = tm->__tm_zone; - LOCK(lock); - do_tzset(); - if (p != __gmt && p != __tzname[0] && p != __tzname[1] && - (!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs)) - p = ""; - UNLOCK(lock); - return p; -} diff --git a/usr/lib/libc/time/__year_to_secs.c b/usr/lib/libc/time/__year_to_secs.c deleted file mode 100644 index 983507972..000000000 --- a/usr/lib/libc/time/__year_to_secs.c +++ /dev/null @@ -1,49 +0,0 @@ -long long __year_to_secs(long long year, int *is_leap) -{ - int cycles, centuries, leaps, rem; - int __is_leap_null = 0; - - if (year - 2ULL <= 136) { - int y = year; - int leaps = (y-68)>>2; - if (!((y-68)&3)) { - leaps--; - if (is_leap) *is_leap = 1; - } else if (is_leap) *is_leap = 0; - return 31536000*(y-70) + 86400*leaps; - } - - if (!is_leap) is_leap = &__is_leap_null; - - cycles = (year-100) / 400; - rem = (year-100) % 400; - if (rem < 0) { - cycles--; - rem += 400; - } - if (!rem) { - *is_leap = 1; - centuries = 0; - leaps = 0; - } else { - if (rem >= 200) { - if (rem >= 300) centuries = 3, rem -= 300; - else centuries = 2, rem -= 200; - } else { - if (rem >= 100) centuries = 1, rem -= 100; - else centuries = 0; - } - if (!rem) { - *is_leap = 0; - leaps = 0; - } else { - leaps = rem / 4U; - rem %= 4U; - *is_leap = !rem; - } - } - - leaps += 97*cycles + 24*centuries - *is_leap; - - return (year-100) * 31536000LL + leaps * 86400LL + 946684800 + 86400; -} diff --git a/usr/lib/libc/time/asctime.c b/usr/lib/libc/time/asctime.c deleted file mode 100644 index 3102eb873..000000000 --- a/usr/lib/libc/time/asctime.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -char *__asctime(const struct tm *, char *); - -char *asctime(const struct tm *tm) -{ - static char buf[26]; - return __asctime(tm, buf); -} diff --git a/usr/lib/libc/time/asctime_r.c b/usr/lib/libc/time/asctime_r.c deleted file mode 100644 index 7dfbb1210..000000000 --- a/usr/lib/libc/time/asctime_r.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -char *__asctime(const struct tm *restrict, char *restrict); - -char *asctime_r(const struct tm *restrict tm, char *restrict buf) -{ - return __asctime(tm, buf); -} diff --git a/usr/lib/libc/time/clock.c b/usr/lib/libc/time/clock.c deleted file mode 100644 index c348e3983..000000000 --- a/usr/lib/libc/time/clock.c +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -int __clock_gettime(clockid_t, struct timespec *); - -clock_t clock() -{ - struct timespec ts; - - if (__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts)) - return -1; - - if (ts.tv_sec > LONG_MAX/1000000 - || ts.tv_nsec/1000 > LONG_MAX-1000000*ts.tv_sec) - return -1; - - return ts.tv_sec*1000000 + ts.tv_nsec/1000; -} diff --git a/usr/lib/libc/time/clock_getcpuclockid.c b/usr/lib/libc/time/clock_getcpuclockid.c deleted file mode 100644 index 8a0e2d4c3..000000000 --- a/usr/lib/libc/time/clock_getcpuclockid.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -int clock_getcpuclockid(pid_t pid, clockid_t *clk) -{ - struct timespec ts; - clockid_t id = (-pid-1)*8U + 2; - int ret = __syscall(SYS_clock_getres, id, &ts); - if (ret) return -ret; - *clk = id; - return 0; -} diff --git a/usr/lib/libc/time/clock_getres.c b/usr/lib/libc/time/clock_getres.c deleted file mode 100644 index 36a0d695b..000000000 --- a/usr/lib/libc/time/clock_getres.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int clock_getres(clockid_t clk, struct timespec *ts) -{ - return syscall(SYS_clock_getres, clk, ts); -} diff --git a/usr/lib/libc/time/clock_gettime.c b/usr/lib/libc/time/clock_gettime.c deleted file mode 100644 index fc9486991..000000000 --- a/usr/lib/libc/time/clock_gettime.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#ifdef VDSO_CGT_SYM - -void *__vdsosym(const char *, const char *); - -static void *volatile vdso_func; - -static int cgt_init(clockid_t clk, struct timespec *ts) -{ - void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM); - int (*f)(clockid_t, struct timespec *) = - (int (*)(clockid_t, struct timespec *))p; - a_cas_p(&vdso_func, (void *)cgt_init, p); - return f ? f(clk, ts) : -ENOSYS; -} - -static void *volatile vdso_func = (void *)cgt_init; - -#endif - -int __clock_gettime(clockid_t clk, struct timespec *ts) -{ - int r; - -#ifdef VDSO_CGT_SYM - int (*f)(clockid_t, struct timespec *) = - (int (*)(clockid_t, struct timespec *))vdso_func; - if (f) { - r = f(clk, ts); - if (!r) return r; - if (r == -EINVAL) return __syscall_ret(r); - /* Fall through on errors other than EINVAL. Some buggy - * vdso implementations return ENOSYS for clocks they - * can't handle, rather than making the syscall. This - * also handles the case where cgt_init fails to find - * a vdso function to use. */ - } -#endif -#if 0 - r = __syscall(SYS_clock_gettime, clk, ts); -#endif - r = sys_clock_gettime(clk, ts); - - if (r == -ENOSYS) { - if (clk == CLOCK_REALTIME) { -#if 0 - __syscall(SYS_gettimeofday, ts, 0); -#endif - sys_gettimeofday(ts, NULL); - /* ts->tv_nsec = (int)ts->tv_nsec * 1000; */ - return 0; - } - r = -EINVAL; - } - - return __syscall_ret(r); -} - -weak_alias(__clock_gettime, clock_gettime); diff --git a/usr/lib/libc/time/clock_nanosleep.c b/usr/lib/libc/time/clock_nanosleep.c deleted file mode 100644 index 9e4d9f1f4..000000000 --- a/usr/lib/libc/time/clock_nanosleep.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -int clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem) -{ - int r = -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem); - return clk == CLOCK_THREAD_CPUTIME_ID ? EINVAL : r; -} diff --git a/usr/lib/libc/time/clock_settime.c b/usr/lib/libc/time/clock_settime.c deleted file mode 100644 index 66b8162d7..000000000 --- a/usr/lib/libc/time/clock_settime.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int clock_settime(clockid_t clk, const struct timespec *ts) -{ - return syscall(SYS_clock_settime, clk, ts); -} diff --git a/usr/lib/libc/time/ctime.c b/usr/lib/libc/time/ctime.c deleted file mode 100644 index 360293151..000000000 --- a/usr/lib/libc/time/ctime.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -char *ctime(const time_t *t) -{ - struct tm *tm = localtime(t); - if (!tm) return 0; - return asctime(tm); -} diff --git a/usr/lib/libc/time/ctime_r.c b/usr/lib/libc/time/ctime_r.c deleted file mode 100644 index d2260a165..000000000 --- a/usr/lib/libc/time/ctime_r.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -char *ctime_r(const time_t *t, char *buf) -{ - struct tm tm; - localtime_r(t, &tm); - return asctime_r(&tm, buf); -} diff --git a/usr/lib/libc/time/difftime.c b/usr/lib/libc/time/difftime.c deleted file mode 100644 index 80a18cc0b..000000000 --- a/usr/lib/libc/time/difftime.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -double difftime(time_t t1, time_t t0) -{ - return t1-t0; -} diff --git a/usr/lib/libc/time/ftime.c b/usr/lib/libc/time/ftime.c deleted file mode 100644 index a1734d0f9..000000000 --- a/usr/lib/libc/time/ftime.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int ftime(struct timeb *tp) -{ - struct timespec ts; - clock_gettime(CLOCK_REALTIME, &ts); - tp->time = ts.tv_sec; - tp->millitm = ts.tv_nsec / 1000000; - tp->timezone = tp->dstflag = 0; - return 0; -} diff --git a/usr/lib/libc/time/getdate.c b/usr/lib/libc/time/getdate.c deleted file mode 100644 index 420cd8e41..000000000 --- a/usr/lib/libc/time/getdate.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include -#include - -int getdate_err; - -struct tm *getdate(const char *s) -{ - static struct tm tmbuf; - struct tm *ret = 0; - char *datemsk = getenv("DATEMSK"); - FILE *f = 0; - char fmt[100], *p; - int cs; - - pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED, &cs); - - if (!datemsk) { - getdate_err = 1; - goto out; - } - - f = fopen(datemsk, "rbe"); - if (!f) { - if (errno == ENOMEM) getdate_err = 6; - else getdate_err = 2; - goto out; - } - - while (fgets(fmt, sizeof fmt, f)) { - p = strptime(s, fmt, &tmbuf); - if (p && !*p) { - ret = &tmbuf; - goto out; - } - } - - if (ferror(f)) getdate_err = 5; - else getdate_err = 7; -out: - if (f) fclose(f); - pthread_setcancelstate(cs, 0); - return ret; -} diff --git a/usr/lib/libc/time/gettimeofday.c b/usr/lib/libc/time/gettimeofday.c deleted file mode 100644 index 92f532b18..000000000 --- a/usr/lib/libc/time/gettimeofday.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include -#include - -int gettimeofday(struct timeval *restrict tv, void *restrict tz) -{ - struct timespec ts; - if (!tv) return 0; - - clock_gettime(CLOCK_REALTIME, &ts); - - tv->tv_sec = ts.tv_sec; - tv->tv_usec = ts.tv_nsec / (time_t) 1000; - return 0; -} diff --git a/usr/lib/libc/time/gmtime.c b/usr/lib/libc/time/gmtime.c deleted file mode 100644 index 3791b24c6..000000000 --- a/usr/lib/libc/time/gmtime.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "time_impl.h" -#include - -struct tm *__gmtime_r(const time_t *restrict, struct tm *restrict); - -struct tm *gmtime(const time_t *t) -{ - static struct tm tm; - return __gmtime_r(t, &tm); -} diff --git a/usr/lib/libc/time/gmtime_r.c b/usr/lib/libc/time/gmtime_r.c deleted file mode 100644 index 8cbdadcb5..000000000 --- a/usr/lib/libc/time/gmtime_r.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "time_impl.h" -#include -#include "libc.h" - -extern const char __gmt[]; - -struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm) -{ - if (__secs_to_tm(*t, tm) < 0) { - errno = EOVERFLOW; - return 0; - } - tm->tm_isdst = 0; - tm->__tm_gmtoff = 0; - tm->__tm_zone = __gmt; - return tm; -} - -weak_alias(__gmtime_r, gmtime_r); diff --git a/usr/lib/libc/time/localtime.c b/usr/lib/libc/time/localtime.c deleted file mode 100644 index bb6718c33..000000000 --- a/usr/lib/libc/time/localtime.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "time_impl.h" - -struct tm *__localtime_r(const time_t *restrict, struct tm *restrict); - -struct tm *localtime(const time_t *t) -{ - static struct tm tm; - return __localtime_r(t, &tm); -} diff --git a/usr/lib/libc/time/localtime_r.c b/usr/lib/libc/time/localtime_r.c deleted file mode 100644 index 201471a58..000000000 --- a/usr/lib/libc/time/localtime_r.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "time_impl.h" -#include -#include "libc.h" - -struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm) -{ - /* Reject time_t values whose year would overflow int because - * __secs_to_zone cannot safely handle them. */ - if ((long long)*t < INT_MIN * 31622400LL || (long long)*t > INT_MAX * 31622400LL) { - errno = EOVERFLOW; - return 0; - } -#if 1 - /* Disable zone conversion because it's not currently implemented */ - // __secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone); - if (__secs_to_tm((long long)*t + 0, tm) < 0) { - errno = EOVERFLOW; - return 0; - } - return tm; -#endif - return NULL; -} - -weak_alias(__localtime_r, localtime_r); diff --git a/usr/lib/libc/time/mktime.c b/usr/lib/libc/time/mktime.c deleted file mode 100644 index bad3f0765..000000000 --- a/usr/lib/libc/time/mktime.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "time_impl.h" -#include - -time_t mktime(struct tm *tm) -{ - struct tm new; - long opp; - long long t = __tm_to_secs(tm); - - __secs_to_zone(t, 1, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone); - - if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst) - t -= opp - new.__tm_gmtoff; - - t -= new.__tm_gmtoff; - if ((time_t)t != t) goto error; - - __secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone); - - if (__secs_to_tm(t + new.__tm_gmtoff, &new) < 0) goto error; - - *tm = new; - return t; - -error: - errno = EOVERFLOW; - return -1; -} diff --git a/usr/lib/libc/time/nanosleep.c b/usr/lib/libc/time/nanosleep.c deleted file mode 100644 index 8f2aa3339..000000000 --- a/usr/lib/libc/time/nanosleep.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -int nanosleep(const struct timespec *req, struct timespec *rem) -{ - return __syscall_ret(sys_nanosleep(req, rem)); -} diff --git a/usr/lib/libc/time/strftime.c b/usr/lib/libc/time/strftime.c deleted file mode 100644 index 6e9e8895a..000000000 --- a/usr/lib/libc/time/strftime.c +++ /dev/null @@ -1,327 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "locale_impl.h" -#include "time_impl.h" - -const char *__nl_langinfo_l(nl_item n, locale_t l) { - - switch (n) { - - case ABDAY_1: - return "Sun"; - case ABDAY_2: - return "Mon"; - case ABDAY_3: - return "Tue"; - case ABDAY_4: - return "Wed"; - case ABDAY_5: - return "Thu"; - case ABDAY_6: - return "Fri"; - case ABDAY_7: - return "Sat"; - - case ABMON_1: - return "Jan"; - case ABMON_2: - return "Feb"; - case ABMON_3: - return "Mar"; - case ABMON_4: - return "Apr"; - case ABMON_5: - return "May"; - case ABMON_6: - return "Jun"; - case ABMON_7: - return "Jul"; - case ABMON_8: - return "Aug"; - case ABMON_9: - return "Sep"; - case ABMON_10: - return "Oct"; - case ABMON_11: - return "Nov"; - case ABMON_12: - return "Dec"; - - default: - return "(n/a)"; - } - -} - -static int is_leap(int y) -{ - /* Avoid overflow */ - if (y>INT_MAX-1900) y -= 2000; - y += 1900; - return !(y%4) && ((y%100) || !(y%400)); -} - -static int week_num(const struct tm *tm) -{ - int val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; - /* If 1 Jan is just 1-3 days past Monday, - * the previous week is also in this year. */ - if ((tm->tm_wday + 371U - tm->tm_yday - 2) % 7 <= 2) - val++; - if (!val) { - val = 52; - /* If 31 December of prev year a Thursday, - * or Friday of a leap year, then the - * prev year has 53 weeks. */ - int dec31 = (tm->tm_wday + 7U - tm->tm_yday - 1) % 7; - if (dec31 == 4 || (dec31 == 5 && is_leap(tm->tm_year%400-1))) - val++; - } else if (val == 53) { - /* If 1 January is not a Thursday, and not - * a Wednesday of a leap year, then this - * year has only 52 weeks. */ - int jan1 = (tm->tm_wday + 371U - tm->tm_yday) % 7; - if (jan1 != 4 && (jan1 != 3 || !is_leap(tm->tm_year))) - val = 1; - } - return val; -} - -const char *__tm_to_tzname(const struct tm *); -size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t); - -const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc) -{ - nl_item item; - long long val; - const char *fmt = "-"; - int width = 2; - - switch (f) { - case 'a': - if (tm->tm_wday > 6U) goto string; - item = ABDAY_1 + tm->tm_wday; - goto nl_strcat; - case 'A': - if (tm->tm_wday > 6U) goto string; - item = DAY_1 + tm->tm_wday; - goto nl_strcat; - case 'h': - case 'b': - if (tm->tm_mon > 11U) goto string; - item = ABMON_1 + tm->tm_mon; - goto nl_strcat; - case 'B': - if (tm->tm_mon > 11U) goto string; - item = MON_1 + tm->tm_mon; - goto nl_strcat; - case 'c': - item = D_T_FMT; - goto nl_strftime; - case 'C': - val = (1900LL+tm->tm_year) / 100; - goto number; - case 'd': - val = tm->tm_mday; - goto number; - case 'D': - fmt = "%m/%d/%y"; - goto recu_strftime; - case 'e': - *l = snprintf(*s, sizeof *s, "%2d", tm->tm_mday); - return *s; - case 'F': - fmt = "%Y-%m-%d"; - goto recu_strftime; - case 'g': - case 'G': - val = tm->tm_year + 1900LL; - if (tm->tm_yday < 3 && week_num(tm) != 1) val--; - else if (tm->tm_yday > 360 && week_num(tm) == 1) val++; - if (f=='g') val %= 100; - else width = 4; - goto number; - case 'H': - val = tm->tm_hour; - goto number; - case 'I': - val = tm->tm_hour; - if (!val) val = 12; - else if (val > 12) val -= 12; - goto number; - case 'j': - val = tm->tm_yday+1; - width = 3; - goto number; - case 'm': - val = tm->tm_mon+1; - goto number; - case 'M': - val = tm->tm_min; - goto number; - case 'n': - *l = 1; - return "\n"; - case 'p': - item = tm->tm_hour >= 12 ? PM_STR : AM_STR; - goto nl_strcat; - case 'r': - item = T_FMT_AMPM; - goto nl_strftime; - case 'R': - fmt = "%H:%M"; - goto recu_strftime; - case 's': - val = __tm_to_secs(tm) - tm->__tm_gmtoff; - width = 1; - goto number; - case 'S': - val = tm->tm_sec; - goto number; - case 't': - *l = 1; - return "\t"; - case 'T': - fmt = "%H:%M:%S"; - goto recu_strftime; - case 'u': - val = tm->tm_wday ? tm->tm_wday : 7; - width = 1; - goto number; - case 'U': - val = (tm->tm_yday + 7U - tm->tm_wday) / 7; - goto number; - case 'W': - val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; - goto number; - case 'V': - val = week_num(tm); - goto number; - case 'w': - val = tm->tm_wday; - width = 1; - goto number; - case 'x': - item = D_FMT; - goto nl_strftime; - case 'X': - item = T_FMT; - goto nl_strftime; - case 'y': - val = (tm->tm_year + 1900LL) % 100; - if (val < 0) val = -val; - goto number; - case 'Y': - val = tm->tm_year + 1900LL; - if (val >= 10000) { - *l = snprintf(*s, sizeof *s, "+%lld", val); - return *s; - } - width = 4; - goto number; - case 'z': - if (tm->tm_isdst < 0) { - *l = 0; - return ""; - } - *l = snprintf(*s, sizeof *s, "%+.2d%.2d", - (tm->__tm_gmtoff)/3600, - abs(tm->__tm_gmtoff%3600)/60); - return *s; - case 'Z': - if (tm->tm_isdst < 0) { - *l = 0; - return ""; - } -#if 0 /* so3 - Not implemented */ - fmt = __tm_to_tzname(tm); -#endif - fmt = ""; - goto string; - case '%': - *l = 1; - return "%"; - default: - return 0; - } -number: - *l = snprintf(*s, sizeof *s, "%0*lld", width, val); - return *s; -nl_strcat: - fmt = __nl_langinfo_l(item, loc); -string: - *l = strlen(fmt); - return fmt; -nl_strftime: - fmt = __nl_langinfo_l(item, loc); -recu_strftime: - *l = __strftime_l(*s, sizeof *s, fmt, tm, loc); - if (!*l) return 0; - return *s; -} - -size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t loc) -{ - size_t l, k; - char buf[100]; - char *p; - const char *t; - int plus; - unsigned long width; - for (l=0; ltm_year >= 10000-1900) - s[l++] = '+'; - else if (tm->tm_year < -1900) - s[l++] = '-'; - else - width++; - for (; width > k && l < n; width--) - s[l++] = '0'; - } - if (k > n-l) k = n-l; - memcpy(s+l, t, k); - l += k; - } - if (n) { - if (l==n) l=n-1; - s[l] = 0; - } - return 0; -} - -size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) -{ - return __strftime_l(s, n, f, tm, C_LOCALE); -} - -weak_alias(__strftime_l, strftime_l); diff --git a/usr/lib/libc/time/strptime.c b/usr/lib/libc/time/strptime.c deleted file mode 100644 index c54a0d8c4..000000000 --- a/usr/lib/libc/time/strptime.c +++ /dev/null @@ -1,206 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm) -{ - int i, w, neg, adj, min, range, *dest, dummy; - const char *ex; - size_t len; - int want_century = 0, century = 0, relyear = 0; - while (*f) { - if (*f != '%') { - if (isspace(*f)) for (; *s && isspace(*s); s++); - else if (*s != *f) return 0; - else s++; - f++; - continue; - } - f++; - if (*f == '+') f++; - if (isdigit(*f)) { - char *new_f; - w=strtoul(f, &new_f, 10); - f = new_f; - } else { - w=-1; - } - adj=0; - switch (*f++) { - case 'a': case 'A': - dest = &tm->tm_wday; - min = ABDAY_1; - range = 7; - goto symbolic_range; - case 'b': case 'B': case 'h': - dest = &tm->tm_mon; - min = ABMON_1; - range = 12; - goto symbolic_range; - case 'c': - s = strptime(s, nl_langinfo(D_T_FMT), tm); - if (!s) return 0; - break; - case 'C': - dest = ¢ury; - if (w<0) w=2; - want_century |= 2; - goto numeric_digits; - case 'd': case 'e': - dest = &tm->tm_mday; - min = 1; - range = 31; - goto numeric_range; - case 'D': - s = strptime(s, "%m/%d/%y", tm); - if (!s) return 0; - break; - case 'H': - dest = &tm->tm_hour; - min = 0; - range = 24; - goto numeric_range; - case 'I': - dest = &tm->tm_hour; - min = 1; - range = 12; - goto numeric_range; - case 'j': - dest = &tm->tm_yday; - min = 1; - range = 366; - adj = 1; - goto numeric_range; - case 'm': - dest = &tm->tm_mon; - min = 1; - range = 12; - adj = 1; - goto numeric_range; - case 'M': - dest = &tm->tm_min; - min = 0; - range = 60; - goto numeric_range; - case 'n': case 't': - for (; *s && isspace(*s); s++); - break; - case 'p': - ex = nl_langinfo(AM_STR); - len = strlen(ex); - if (!strncasecmp(s, ex, len)) { - tm->tm_hour %= 12; - s += len; - break; - } - ex = nl_langinfo(PM_STR); - len = strlen(ex); - if (!strncasecmp(s, ex, len)) { - tm->tm_hour %= 12; - tm->tm_hour += 12; - s += len; - break; - } - return 0; - case 'r': - s = strptime(s, nl_langinfo(T_FMT_AMPM), tm); - if (!s) return 0; - break; - case 'R': - s = strptime(s, "%H:%M", tm); - if (!s) return 0; - break; - case 'S': - dest = &tm->tm_sec; - min = 0; - range = 61; - goto numeric_range; - case 'T': - s = strptime(s, "%H:%M:%S", tm); - if (!s) return 0; - break; - case 'U': - case 'W': - /* Throw away result, for now. (FIXME?) */ - dest = &dummy; - min = 0; - range = 54; - goto numeric_range; - case 'w': - dest = &tm->tm_wday; - min = 0; - range = 7; - goto numeric_range; - case 'x': - s = strptime(s, nl_langinfo(D_FMT), tm); - if (!s) return 0; - break; - case 'X': - s = strptime(s, nl_langinfo(T_FMT), tm); - if (!s) return 0; - break; - case 'y': - dest = &relyear; - w = 2; - want_century |= 1; - goto numeric_digits; - case 'Y': - dest = &tm->tm_year; - if (w<0) w=4; - adj = 1900; - want_century = 0; - goto numeric_digits; - case '%': - if (*s++ != '%') return 0; - break; - default: - return 0; - numeric_range: - if (!isdigit(*s)) return 0; - *dest = 0; - for (i=1; i<=min+range && isdigit(*s); i*=10) - *dest = *dest * 10 + *s++ - '0'; - if (*dest - min >= (unsigned)range) return 0; - *dest -= adj; - switch((char *)dest - (char *)tm) { - case offsetof(struct tm, tm_yday): - ; - } - goto update; - numeric_digits: - neg = 0; - if (*s == '+') s++; - else if (*s == '-') neg=1, s++; - if (!isdigit(*s)) return 0; - for (*dest=i=0; i=0; i--) { - ex = nl_langinfo(min+i); - len = strlen(ex); - if (strncasecmp(s, ex, len)) continue; - s += len; - *dest = i % range; - break; - } - if (i<0) return 0; - goto update; - update: - //FIXME - ; - } - } - if (want_century) { - tm->tm_year = relyear; - if (want_century & 2) tm->tm_year += century * 100 - 1900; - else if (tm->tm_year <= 68) tm->tm_year += 100; - } - return (char *)s; -} diff --git a/usr/lib/libc/time/time.c b/usr/lib/libc/time/time.c deleted file mode 100644 index 836e38d6c..000000000 --- a/usr/lib/libc/time/time.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int __clock_gettime(clockid_t, struct timespec *); - -time_t time(time_t *t) -{ - struct timespec ts; - __clock_gettime(CLOCK_REALTIME, &ts); - if (t) *t = ts.tv_sec; - return ts.tv_sec; -} diff --git a/usr/lib/libc/time/time_impl.h b/usr/lib/libc/time/time_impl.h deleted file mode 100644 index 2e9a2c096..000000000 --- a/usr/lib/libc/time/time_impl.h +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int __days_in_month(int, int); -int __month_to_secs(int, int); -long long __year_to_secs(long long, int *); -long long __tm_to_secs(const struct tm *); -int __secs_to_tm(long long, struct tm *); -void __secs_to_zone(long long, int, int *, long *, long *, const char **); -const unsigned char *__map_file(const char *, size_t *); diff --git a/usr/lib/libc/time/timegm.c b/usr/lib/libc/time/timegm.c deleted file mode 100644 index b5dae8b64..000000000 --- a/usr/lib/libc/time/timegm.c +++ /dev/null @@ -1,20 +0,0 @@ -#define _GNU_SOURCE -#include "time_impl.h" -#include - -extern const char __gmt[]; - -time_t timegm(struct tm *tm) -{ - struct tm new; - long long t = __tm_to_secs(tm); - if (__secs_to_tm(t, &new) < 0) { - errno = EOVERFLOW; - return -1; - } - *tm = new; - tm->tm_isdst = 0; - tm->__tm_gmtoff = 0; - tm->__tm_zone = __gmt; - return t; -} diff --git a/usr/lib/libc/time/timer_create.c b/usr/lib/libc/time/timer_create.c deleted file mode 100644 index b54a524ce..000000000 --- a/usr/lib/libc/time/timer_create.c +++ /dev/null @@ -1,141 +0,0 @@ -#include -#include -#include "pthread_impl.h" - -struct ksigevent { - union sigval sigev_value; - int sigev_signo; - int sigev_notify; - int sigev_tid; -}; - -struct start_args { - pthread_barrier_t b; - struct sigevent *sev; -}; - -static void dummy_1(pthread_t self) -{ -} -weak_alias(dummy_1, __pthread_tsd_run_dtors); - -void __reset_tls(); - -static void cleanup_fromsig(void *p) -{ - pthread_t self = __pthread_self(); - __pthread_tsd_run_dtors(self); - self->cancel = 0; - self->cancelbuf = 0; - self->canceldisable = 0; - self->cancelasync = 0; - self->unblock_cancel = 0; - __reset_tls(); - longjmp(p, 1); -} - -static void timer_handler(int sig, siginfo_t *si, void *ctx) -{ - pthread_t self = __pthread_self(); - jmp_buf jb; - void (*notify)(union sigval) = (void (*)(union sigval))self->start; - union sigval val = { .sival_ptr = self->start_arg }; - - if (!setjmp(jb) && si->si_code == SI_TIMER) { - pthread_cleanup_push(cleanup_fromsig, jb); - notify(val); - pthread_cleanup_pop(1); - } -} - -static void install_handler() -{ - struct sigaction sa = { - .sa_sigaction = timer_handler, - .sa_flags = SA_SIGINFO | SA_RESTART - }; - __libc_sigaction(SIGTIMER, &sa, 0); -} - -static void *start(void *arg) -{ - pthread_t self = __pthread_self(); - struct start_args *args = arg; - int id; - - /* Reuse no-longer-needed thread structure fields to avoid - * needing the timer address in the signal handler. */ - self->start = (void *(*)(void *))args->sev->sigev_notify_function; - self->start_arg = args->sev->sigev_value.sival_ptr; - - pthread_barrier_wait(&args->b); - if ((id = self->timer_id) >= 0) { - __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, - SIGTIMER_SET, 0, _NSIG/8); - __wait(&self->timer_id, 0, id, 1); - __syscall(SYS_timer_delete, id); - } - return 0; -} - -int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict res) -{ - static pthread_once_t once = PTHREAD_ONCE_INIT; - pthread_t td; - pthread_attr_t attr; - int r; - struct start_args args; - struct ksigevent ksev, *ksevp=0; - int timerid; - sigset_t set; - - switch (evp ? evp->sigev_notify : SIGEV_SIGNAL) { - case SIGEV_NONE: - case SIGEV_SIGNAL: - if (evp) { - ksev.sigev_value = evp->sigev_value; - ksev.sigev_signo = evp->sigev_signo; - ksev.sigev_notify = evp->sigev_notify; - ksev.sigev_tid = 0; - ksevp = &ksev; - } - if (syscall(SYS_timer_create, clk, ksevp, &timerid) < 0) - return -1; - *res = (void *)(intptr_t)timerid; - break; - case SIGEV_THREAD: - pthread_once(&once, install_handler); - if (evp->sigev_notify_attributes) - attr = *evp->sigev_notify_attributes; - else - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - pthread_barrier_init(&args.b, 0, 2); - args.sev = evp; - - __block_app_sigs(&set); - r = pthread_create(&td, &attr, start, &args); - __restore_sigs(&set); - if (r) { - errno = r; - return -1; - } - - ksev.sigev_value.sival_ptr = 0; - ksev.sigev_signo = SIGTIMER; - ksev.sigev_notify = 4; /* SIGEV_THREAD_ID */ - ksev.sigev_tid = td->tid; - if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0) - timerid = -1; - td->timer_id = timerid; - pthread_barrier_wait(&args.b); - if (timerid < 0) return -1; - *res = (void *)(INTPTR_MIN | (uintptr_t)td>>1); - break; - default: - errno = EINVAL; - return -1; - } - - return 0; -} diff --git a/usr/lib/libc/time/timer_delete.c b/usr/lib/libc/time/timer_delete.c deleted file mode 100644 index 7c97eeb1a..000000000 --- a/usr/lib/libc/time/timer_delete.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include "pthread_impl.h" - -int timer_delete(timer_t t) -{ - if ((intptr_t)t < 0) { - pthread_t td = (void *)((uintptr_t)t << 1); - a_store(&td->timer_id, td->timer_id | INT_MIN); - __wake(&td->timer_id, 1, 1); - return 0; - } - return __syscall(SYS_timer_delete, t); -} diff --git a/usr/lib/libc/time/timer_getoverrun.c b/usr/lib/libc/time/timer_getoverrun.c deleted file mode 100644 index e7f891e40..000000000 --- a/usr/lib/libc/time/timer_getoverrun.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "pthread_impl.h" - -int timer_getoverrun(timer_t t) -{ - if ((intptr_t)t < 0) { - pthread_t td = (void *)((uintptr_t)t << 1); - t = (void *)(uintptr_t)(td->timer_id & INT_MAX); - } - return syscall(SYS_timer_getoverrun, t); -} diff --git a/usr/lib/libc/time/timer_gettime.c b/usr/lib/libc/time/timer_gettime.c deleted file mode 100644 index ed6d8d65c..000000000 --- a/usr/lib/libc/time/timer_gettime.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "pthread_impl.h" - -int timer_gettime(timer_t t, struct itimerspec *val) -{ - if ((intptr_t)t < 0) { - pthread_t td = (void *)((uintptr_t)t << 1); - t = (void *)(uintptr_t)(td->timer_id & INT_MAX); - } - return syscall(SYS_timer_gettime, t, val); -} diff --git a/usr/lib/libc/time/timer_settime.c b/usr/lib/libc/time/timer_settime.c deleted file mode 100644 index 62631aa49..000000000 --- a/usr/lib/libc/time/timer_settime.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "pthread_impl.h" - -int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, struct itimerspec *restrict old) -{ - if ((intptr_t)t < 0) { - pthread_t td = (void *)((uintptr_t)t << 1); - t = (void *)(uintptr_t)(td->timer_id & INT_MAX); - } - return syscall(SYS_timer_settime, t, flags, val, old); -} diff --git a/usr/lib/libc/time/times.c b/usr/lib/libc/time/times.c deleted file mode 100644 index c4a100f79..000000000 --- a/usr/lib/libc/time/times.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -clock_t times(struct tms *tms) -{ - return __syscall(SYS_times, tms); -} diff --git a/usr/lib/libc/time/timespec_get.c b/usr/lib/libc/time/timespec_get.c deleted file mode 100644 index 03c5a77b7..000000000 --- a/usr/lib/libc/time/timespec_get.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int __clock_gettime(clockid_t, struct timespec *); - -/* There is no other implemented value than TIME_UTC; all other values - * are considered erroneous. */ -int timespec_get(struct timespec * ts, int base) -{ - if (base != TIME_UTC) return 0; - int ret = __clock_gettime(CLOCK_REALTIME, ts); - return ret < 0 ? 0 : base; -} diff --git a/usr/lib/libc/time/utime.c b/usr/lib/libc/time/utime.c deleted file mode 100644 index e7592b297..000000000 --- a/usr/lib/libc/time/utime.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include -#include - -int utime(const char *path, const struct utimbuf *times) -{ - return utimensat(AT_FDCWD, path, times ? ((struct timespec [2]){ - { .tv_sec = times->actime }, { .tv_sec = times->modtime }}) - : 0, 0); -} diff --git a/usr/lib/libc/time/wcsftime.c b/usr/lib/libc/time/wcsftime.c deleted file mode 100644 index 638e64f6b..000000000 --- a/usr/lib/libc/time/wcsftime.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include "locale_impl.h" -#include "libc.h" - -const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc); - -size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, const struct tm *restrict tm, locale_t loc) -{ - size_t l, k; - char buf[100]; - wchar_t wbuf[100]; - wchar_t *p; - const char *t_mb; - const wchar_t *t; - int plus; - unsigned long width; - for (l=0; ltm_year >= 10000-1900) - s[l++] = '+'; - else if (tm->tm_year < -1900) - s[l++] = '-'; - else - width++; - for (; width > k && l < n; width--) - s[l++] = '0'; - } - if (k >= n-l) k = n-l; - wmemcpy(s+l, t, k); - l += k; - } - if (n) { - if (l==n) l=n-1; - s[l] = 0; - } - return 0; -} - -size_t wcsftime(wchar_t *restrict wcs, size_t n, const wchar_t *restrict f, const struct tm *restrict tm) -{ - return __wcsftime_l(wcs, n, f, tm, CURRENT_LOCALE); -} - -weak_alias(__wcsftime_l, wcsftime_l); diff --git a/usr/lib/libc/unistd/CMakeLists.txt b/usr/lib/libc/unistd/CMakeLists.txt deleted file mode 100644 index fffa25f87..000000000 --- a/usr/lib/libc/unistd/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ - -target_sources(c - PRIVATE - write.c - read.c - getpid.c - close.c - pipe.c - dup2.c - dup.c - sleep.c - usleep.c - lseek.c -) diff --git a/usr/lib/libc/unistd/_exit.c b/usr/lib/libc/unistd/_exit.c deleted file mode 100644 index 769948232..000000000 --- a/usr/lib/libc/unistd/_exit.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -_Noreturn void _exit(int status) -{ - _Exit(status); -} diff --git a/usr/lib/libc/unistd/access.c b/usr/lib/libc/unistd/access.c deleted file mode 100644 index d6eed6839..000000000 --- a/usr/lib/libc/unistd/access.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int access(const char *filename, int amode) -{ -#ifdef SYS_access - return syscall(SYS_access, filename, amode); -#else - return syscall(SYS_faccessat, AT_FDCWD, filename, amode, 0); -#endif -} diff --git a/usr/lib/libc/unistd/acct.c b/usr/lib/libc/unistd/acct.c deleted file mode 100644 index f6f25a8a6..000000000 --- a/usr/lib/libc/unistd/acct.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" -#include "libc.h" - -int acct(const char *filename) -{ - return syscall(SYS_acct, filename); -} diff --git a/usr/lib/libc/unistd/alarm.c b/usr/lib/libc/unistd/alarm.c deleted file mode 100644 index 2e3263ac5..000000000 --- a/usr/lib/libc/unistd/alarm.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include "syscall.h" - -unsigned alarm(unsigned seconds) -{ - struct itimerval it = { .it_value.tv_sec = seconds }; - __syscall(SYS_setitimer, ITIMER_REAL, &it, &it); - return it.it_value.tv_sec + !!it.it_value.tv_usec; -} diff --git a/usr/lib/libc/unistd/chdir.c b/usr/lib/libc/unistd/chdir.c deleted file mode 100644 index 5ba78b631..000000000 --- a/usr/lib/libc/unistd/chdir.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int chdir(const char *path) -{ - return syscall(SYS_chdir, path); -} diff --git a/usr/lib/libc/unistd/chown.c b/usr/lib/libc/unistd/chown.c deleted file mode 100644 index 14b032550..000000000 --- a/usr/lib/libc/unistd/chown.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int chown(const char *path, uid_t uid, gid_t gid) -{ -#ifdef SYS_chown - return syscall(SYS_chown, path, uid, gid); -#else - return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, 0); -#endif -} diff --git a/usr/lib/libc/unistd/close.c b/usr/lib/libc/unistd/close.c deleted file mode 100644 index de18c13c5..000000000 --- a/usr/lib/libc/unistd/close.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include - -static int dummy(int fd) -{ - return fd; -} - -weak_alias(dummy, __aio_close); - -int close(int fd) -{ - fd = __aio_close(fd); - - return __syscall_ret(sys_close(fd)); - -#if 0 /* so3 */ - int r = __syscall_cp(SYS_close, fd); - if (r == -EINTR) r = 0; - return __syscall_ret(r); -#endif - -} diff --git a/usr/lib/libc/unistd/ctermid.c b/usr/lib/libc/unistd/ctermid.c deleted file mode 100644 index 1612770af..000000000 --- a/usr/lib/libc/unistd/ctermid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -char *ctermid(char *s) -{ - return s ? strcpy(s, "/dev/tty") : "/dev/tty"; -} diff --git a/usr/lib/libc/unistd/dup.c b/usr/lib/libc/unistd/dup.c deleted file mode 100644 index 03a3a5af7..000000000 --- a/usr/lib/libc/unistd/dup.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int dup(int fd) -{ - return __syscall_ret(sys_dup(fd)); -} diff --git a/usr/lib/libc/unistd/dup2.c b/usr/lib/libc/unistd/dup2.c deleted file mode 100644 index 4c9c7872f..000000000 --- a/usr/lib/libc/unistd/dup2.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include - -int dup2(int old, int new) -{ -#if 0 - int r; -#endif - - return __syscall_ret(sys_dup2(old, new)); - -#if 0 /* SO3 */ -#ifdef SYS_dup2 - while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); -#else - if (old==new) { - r = __syscall(SYS_fcntl, old, F_GETFD); - if (r >= 0) return old; - } else { - while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY); - } -#endif - return __syscall_ret(r); -#endif -} diff --git a/usr/lib/libc/unistd/dup3.c b/usr/lib/libc/unistd/dup3.c deleted file mode 100644 index 0eb6caf59..000000000 --- a/usr/lib/libc/unistd/dup3.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include "syscall.h" -#include "libc.h" - -int __dup3(int old, int new, int flags) -{ - int r; -#ifdef SYS_dup2 - if (old==new) return __syscall_ret(-EINVAL); - if (flags & O_CLOEXEC) { - while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); - if (r!=-ENOSYS) return __syscall_ret(r); - } - while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); - if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC); -#else - while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); -#endif - return __syscall_ret(r); -} - -weak_alias(__dup3, dup3); diff --git a/usr/lib/libc/unistd/faccessat.c b/usr/lib/libc/unistd/faccessat.c deleted file mode 100644 index 33478959c..000000000 --- a/usr/lib/libc/unistd/faccessat.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include "syscall.h" -#include "pthread_impl.h" - -struct ctx { - int fd; - const char *filename; - int amode; -}; - -static const int errors[] = { - 0, -EACCES, -ELOOP, -ENAMETOOLONG, -ENOENT, -ENOTDIR, - -EROFS, -EBADF, -EINVAL, -ETXTBSY, - -EFAULT, -EIO, -ENOMEM, - -EBUSY -}; - -static int checker(void *p) -{ - struct ctx *c = p; - int ret; - int i; - if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1) - || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1)) - __syscall(SYS_exit, 1); - ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0); - for (i=0; i < sizeof errors/sizeof *errors - 1 && ret!=errors[i]; i++); - return i; -} - -int faccessat(int fd, const char *filename, int amode, int flag) -{ - if (!flag || (flag==AT_EACCESS && getuid()==geteuid() && getgid()==getegid())) - return syscall(SYS_faccessat, fd, filename, amode, flag); - - if (flag != AT_EACCESS) - return __syscall_ret(-EINVAL); - - char stack[1024]; - sigset_t set; - pid_t pid; - int ret = -EBUSY; - struct ctx c = { .fd = fd, .filename = filename, .amode = amode }; - - __block_all_sigs(&set); - - pid = __clone(checker, stack+sizeof stack, 0, &c); - if (pid > 0) { - int status; - do { - __syscall(SYS_wait4, pid, &status, __WCLONE, 0); - } while (!WIFEXITED(status) && !WIFSIGNALED(status)); - if (WIFEXITED(status)) - ret = errors[WEXITSTATUS(status)]; - } - - __restore_sigs(&set); - - return __syscall_ret(ret); -} diff --git a/usr/lib/libc/unistd/fchdir.c b/usr/lib/libc/unistd/fchdir.c deleted file mode 100644 index 72c3915ee..000000000 --- a/usr/lib/libc/unistd/fchdir.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -void __procfdname(char *, unsigned); - -int fchdir(int fd) -{ - int ret = __syscall(SYS_fchdir, fd); - if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) - return __syscall_ret(ret); - - char buf[15+3*sizeof(int)]; - __procfdname(buf, fd); - return syscall(SYS_chdir, buf); -} diff --git a/usr/lib/libc/unistd/fchown.c b/usr/lib/libc/unistd/fchown.c deleted file mode 100644 index 75075eece..000000000 --- a/usr/lib/libc/unistd/fchown.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -void __procfdname(char *, unsigned); - -int fchown(int fd, uid_t uid, gid_t gid) -{ - int ret = __syscall(SYS_fchown, fd, uid, gid); - if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) - return __syscall_ret(ret); - - char buf[15+3*sizeof(int)]; - __procfdname(buf, fd); -#ifdef SYS_chown - return syscall(SYS_chown, buf, uid, gid); -#else - return syscall(SYS_fchownat, AT_FDCWD, buf, uid, gid, 0); -#endif - -} diff --git a/usr/lib/libc/unistd/fchownat.c b/usr/lib/libc/unistd/fchownat.c deleted file mode 100644 index 62457a3ec..000000000 --- a/usr/lib/libc/unistd/fchownat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag) -{ - return syscall(SYS_fchownat, fd, path, uid, gid, flag); -} diff --git a/usr/lib/libc/unistd/fdatasync.c b/usr/lib/libc/unistd/fdatasync.c deleted file mode 100644 index 3895ae530..000000000 --- a/usr/lib/libc/unistd/fdatasync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fdatasync(int fd) -{ - return syscall_cp(SYS_fdatasync, fd); -} diff --git a/usr/lib/libc/unistd/fsync.c b/usr/lib/libc/unistd/fsync.c deleted file mode 100644 index 7a1c80b5d..000000000 --- a/usr/lib/libc/unistd/fsync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int fsync(int fd) -{ - return syscall_cp(SYS_fsync, fd); -} diff --git a/usr/lib/libc/unistd/ftruncate.c b/usr/lib/libc/unistd/ftruncate.c deleted file mode 100644 index 467135f00..000000000 --- a/usr/lib/libc/unistd/ftruncate.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int ftruncate(int fd, off_t length) -{ - return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length)); -} - -LFS64(ftruncate); diff --git a/usr/lib/libc/unistd/getcwd.c b/usr/lib/libc/unistd/getcwd.c deleted file mode 100644 index a7b925d2d..000000000 --- a/usr/lib/libc/unistd/getcwd.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include -#include "syscall.h" - -char *getcwd(char *buf, size_t size) -{ - char tmp[PATH_MAX]; - if (!buf) { - buf = tmp; - size = PATH_MAX; - } else if (!size) { - errno = EINVAL; - return 0; - } - if (syscall(SYS_getcwd, buf, size) < 0) return 0; - return buf == tmp ? strdup(buf) : buf; -} diff --git a/usr/lib/libc/unistd/getegid.c b/usr/lib/libc/unistd/getegid.c deleted file mode 100644 index 6287490da..000000000 --- a/usr/lib/libc/unistd/getegid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -gid_t getegid(void) -{ - return __syscall(SYS_getegid); -} diff --git a/usr/lib/libc/unistd/geteuid.c b/usr/lib/libc/unistd/geteuid.c deleted file mode 100644 index 88f2cd538..000000000 --- a/usr/lib/libc/unistd/geteuid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -uid_t geteuid(void) -{ - return __syscall(SYS_geteuid); -} diff --git a/usr/lib/libc/unistd/getgid.c b/usr/lib/libc/unistd/getgid.c deleted file mode 100644 index 1c9fe7157..000000000 --- a/usr/lib/libc/unistd/getgid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -gid_t getgid(void) -{ - return __syscall(SYS_getgid); -} diff --git a/usr/lib/libc/unistd/getgroups.c b/usr/lib/libc/unistd/getgroups.c deleted file mode 100644 index 0e6e63af0..000000000 --- a/usr/lib/libc/unistd/getgroups.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int getgroups(int count, gid_t list[]) -{ - return syscall(SYS_getgroups, count, list); -} diff --git a/usr/lib/libc/unistd/gethostname.c b/usr/lib/libc/unistd/gethostname.c deleted file mode 100644 index f984b7dd2..000000000 --- a/usr/lib/libc/unistd/gethostname.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -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 - -char *getlogin(void) -{ - return getenv("LOGNAME"); -} diff --git a/usr/lib/libc/unistd/getlogin_r.c b/usr/lib/libc/unistd/getlogin_r.c deleted file mode 100644 index 53866c6dc..000000000 --- a/usr/lib/libc/unistd/getlogin_r.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include - -int getlogin_r(char *name, size_t size) -{ - char *logname = getlogin(); - if (!logname) return ENXIO; /* or...? */ - if (strlen(logname) >= size) return ERANGE; - strcpy(name, logname); - return 0; -} diff --git a/usr/lib/libc/unistd/getpgid.c b/usr/lib/libc/unistd/getpgid.c deleted file mode 100644 index d295bfd59..000000000 --- a/usr/lib/libc/unistd/getpgid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getpgid(pid_t pid) -{ - return syscall(SYS_getpgid, pid); -} diff --git a/usr/lib/libc/unistd/getpgrp.c b/usr/lib/libc/unistd/getpgrp.c deleted file mode 100644 index 90e9bb07f..000000000 --- a/usr/lib/libc/unistd/getpgrp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getpgrp(void) -{ - return __syscall(SYS_getpgid, 0); -} diff --git a/usr/lib/libc/unistd/getpid.c b/usr/lib/libc/unistd/getpid.c deleted file mode 100644 index 0b5f7cd6b..000000000 --- a/usr/lib/libc/unistd/getpid.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -pid_t getpid(void) -{ - return __syscall_ret(sys_getpid()); -#if 0 - return __syscall(SYS_getpid); -#endif -} diff --git a/usr/lib/libc/unistd/getppid.c b/usr/lib/libc/unistd/getppid.c deleted file mode 100644 index 05cade53b..000000000 --- a/usr/lib/libc/unistd/getppid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getppid(void) -{ - return __syscall(SYS_getppid); -} diff --git a/usr/lib/libc/unistd/getsid.c b/usr/lib/libc/unistd/getsid.c deleted file mode 100644 index 93ba690e7..000000000 --- a/usr/lib/libc/unistd/getsid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t getsid(pid_t pid) -{ - return syscall(SYS_getsid, pid); -} diff --git a/usr/lib/libc/unistd/getuid.c b/usr/lib/libc/unistd/getuid.c deleted file mode 100644 index 61309d1b7..000000000 --- a/usr/lib/libc/unistd/getuid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -uid_t getuid(void) -{ - return __syscall(SYS_getuid); -} diff --git a/usr/lib/libc/unistd/isatty.c b/usr/lib/libc/unistd/isatty.c deleted file mode 100644 index c8badaf55..000000000 --- a/usr/lib/libc/unistd/isatty.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include "syscall.h" - -int isatty(int fd) -{ - struct winsize wsz; - return !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz); -} diff --git a/usr/lib/libc/unistd/lchown.c b/usr/lib/libc/unistd/lchown.c deleted file mode 100644 index ccd5ee025..000000000 --- a/usr/lib/libc/unistd/lchown.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int lchown(const char *path, uid_t uid, gid_t gid) -{ -#ifdef SYS_lchown - return syscall(SYS_lchown, path, uid, gid); -#else - return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW); -#endif -} diff --git a/usr/lib/libc/unistd/link.c b/usr/lib/libc/unistd/link.c deleted file mode 100644 index feec18e53..000000000 --- a/usr/lib/libc/unistd/link.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int link(const char *existing, const char *new) -{ -#ifdef SYS_link - return syscall(SYS_link, existing, new); -#else - return syscall(SYS_linkat, AT_FDCWD, existing, AT_FDCWD, new, 0); -#endif -} diff --git a/usr/lib/libc/unistd/linkat.c b/usr/lib/libc/unistd/linkat.c deleted file mode 100644 index 6a9a0b775..000000000 --- a/usr/lib/libc/unistd/linkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int linkat(int fd1, const char *existing, int fd2, const char *new, int flag) -{ - return syscall(SYS_linkat, fd1, existing, fd2, new, flag); -} diff --git a/usr/lib/libc/unistd/lseek.c b/usr/lib/libc/unistd/lseek.c deleted file mode 100644 index 4d56625a3..000000000 --- a/usr/lib/libc/unistd/lseek.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include - -off_t lseek(int fd, off_t offset, int whence) -{ -#ifdef SYS__llseek - off_t result; - return syscall(SYS__llseek, fd, offset>>32, offset, &result, whence) ? -1 : result; -#else - return __syscall_ret(sys_lseek(fd, offset, whence)); -#if 0 - return syscall(SYS_lseek, fd, offset, whence); -#endif - -#endif -} - -LFS64(lseek); diff --git a/usr/lib/libc/unistd/nice.c b/usr/lib/libc/unistd/nice.c deleted file mode 100644 index da5699677..000000000 --- a/usr/lib/libc/unistd/nice.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int nice(int inc) -{ -#ifdef SYS_nice - return syscall(SYS_nice, inc); -#else - return setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0)+inc); -#endif -} diff --git a/usr/lib/libc/unistd/pause.c b/usr/lib/libc/unistd/pause.c deleted file mode 100644 index 56eb171e0..000000000 --- a/usr/lib/libc/unistd/pause.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" - -int pause(void) -{ -#ifdef SYS_pause - return syscall_cp(SYS_pause); -#else - return syscall_cp(SYS_ppoll, 0, 0, 0, 0); -#endif -} diff --git a/usr/lib/libc/unistd/pipe.c b/usr/lib/libc/unistd/pipe.c deleted file mode 100644 index 623750dd6..000000000 --- a/usr/lib/libc/unistd/pipe.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int pipe(int fd[2]) -{ - return __syscall_ret(sys_pipe(fd)); -#if 0 -#ifdef SYS_pipe - return syscall(SYS_pipe, fd); -#else - return syscall(SYS_pipe2, fd, 0); -#endif -#endif -} diff --git a/usr/lib/libc/unistd/pipe2.c b/usr/lib/libc/unistd/pipe2.c deleted file mode 100644 index f24f74fb0..000000000 --- a/usr/lib/libc/unistd/pipe2.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include "syscall.h" - -int pipe2(int fd[2], int flag) -{ - if (!flag) return pipe(fd); - int ret = __syscall(SYS_pipe2, fd, flag); - if (ret != -ENOSYS) return __syscall_ret(ret); - ret = pipe(fd); - if (ret) return ret; - if (flag & O_CLOEXEC) { - __syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); - __syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); - } - if (flag & O_NONBLOCK) { - __syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); - __syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); - } - return 0; -} diff --git a/usr/lib/libc/unistd/posix_close.c b/usr/lib/libc/unistd/posix_close.c deleted file mode 100644 index 90f51a82e..000000000 --- a/usr/lib/libc/unistd/posix_close.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int posix_close(int fd, int flags) -{ - return close(fd); -} diff --git a/usr/lib/libc/unistd/pread.c b/usr/lib/libc/unistd/pread.c deleted file mode 100644 index 5483eb9d7..000000000 --- a/usr/lib/libc/unistd/pread.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t pread(int fd, void *buf, size_t size, off_t ofs) -{ - return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL_PRW(ofs)); -} - -LFS64(pread); diff --git a/usr/lib/libc/unistd/preadv.c b/usr/lib/libc/unistd/preadv.c deleted file mode 100644 index 46d9ece7b..000000000 --- a/usr/lib/libc/unistd/preadv.c +++ /dev/null @@ -1,13 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include "syscall.h" -#include "libc.h" - -ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs) -{ - return syscall_cp(SYS_preadv, fd, iov, count, - (long)(ofs), (long)(ofs>>32)); -} - -LFS64(preadv); diff --git a/usr/lib/libc/unistd/pwrite.c b/usr/lib/libc/unistd/pwrite.c deleted file mode 100644 index 4bf3d7dfc..000000000 --- a/usr/lib/libc/unistd/pwrite.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) -{ - return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs)); -} - -LFS64(pwrite); diff --git a/usr/lib/libc/unistd/pwritev.c b/usr/lib/libc/unistd/pwritev.c deleted file mode 100644 index aec5d3235..000000000 --- a/usr/lib/libc/unistd/pwritev.c +++ /dev/null @@ -1,13 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include "syscall.h" -#include "libc.h" - -ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs) -{ - return syscall_cp(SYS_pwritev, fd, iov, count, - (long)(ofs), (long)(ofs>>32)); -} - -LFS64(pwritev); diff --git a/usr/lib/libc/unistd/read.c b/usr/lib/libc/unistd/read.c deleted file mode 100644 index 8cb3d36e2..000000000 --- a/usr/lib/libc/unistd/read.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -ssize_t read(int fd, void *buf, size_t count) -{ - return __syscall_ret(sys_read(fd, buf, count)); -#if 0 - return syscall_cp(SYS_read, fd, buf, count); -#endif -} diff --git a/usr/lib/libc/unistd/readlink.c b/usr/lib/libc/unistd/readlink.c deleted file mode 100644 index a152d5249..000000000 --- a/usr/lib/libc/unistd/readlink.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize) -{ -#ifdef SYS_readlink - return syscall(SYS_readlink, path, buf, bufsize); -#else - return syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize); -#endif -} diff --git a/usr/lib/libc/unistd/readlinkat.c b/usr/lib/libc/unistd/readlinkat.c deleted file mode 100644 index 9af45cd5a..000000000 --- a/usr/lib/libc/unistd/readlinkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize) -{ - return syscall(SYS_readlinkat, fd, path, buf, bufsize); -} diff --git a/usr/lib/libc/unistd/readv.c b/usr/lib/libc/unistd/readv.c deleted file mode 100644 index e45cb484f..000000000 --- a/usr/lib/libc/unistd/readv.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t readv(int fd, const struct iovec *iov, int count) -{ - return syscall_cp(SYS_readv, fd, iov, count); -} diff --git a/usr/lib/libc/unistd/renameat.c b/usr/lib/libc/unistd/renameat.c deleted file mode 100644 index 125748221..000000000 --- a/usr/lib/libc/unistd/renameat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int renameat(int oldfd, const char *old, int newfd, const char *new) -{ - return syscall(SYS_renameat, oldfd, old, newfd, new); -} diff --git a/usr/lib/libc/unistd/rmdir.c b/usr/lib/libc/unistd/rmdir.c deleted file mode 100644 index 6825ffc83..000000000 --- a/usr/lib/libc/unistd/rmdir.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int rmdir(const char *path) -{ -#ifdef SYS_rmdir - return syscall(SYS_rmdir, path); -#else - return syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); -#endif -} diff --git a/usr/lib/libc/unistd/setegid.c b/usr/lib/libc/unistd/setegid.c deleted file mode 100644 index e6da2573c..000000000 --- a/usr/lib/libc/unistd/setegid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "libc.h" -#include "syscall.h" - -int setegid(gid_t egid) -{ - return __setxid(SYS_setresgid, -1, egid, -1); -} diff --git a/usr/lib/libc/unistd/seteuid.c b/usr/lib/libc/unistd/seteuid.c deleted file mode 100644 index ef8b9df43..000000000 --- a/usr/lib/libc/unistd/seteuid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int seteuid(uid_t euid) -{ - return __setxid(SYS_setresuid, -1, euid, -1); -} diff --git a/usr/lib/libc/unistd/setgid.c b/usr/lib/libc/unistd/setgid.c deleted file mode 100644 index bae4616ad..000000000 --- a/usr/lib/libc/unistd/setgid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setgid(gid_t gid) -{ - return __setxid(SYS_setgid, gid, 0, 0); -} diff --git a/usr/lib/libc/unistd/setpgid.c b/usr/lib/libc/unistd/setpgid.c deleted file mode 100644 index 061606951..000000000 --- a/usr/lib/libc/unistd/setpgid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int setpgid(pid_t pid, pid_t pgid) -{ - return syscall(SYS_setpgid, pid, pgid); -} diff --git a/usr/lib/libc/unistd/setpgrp.c b/usr/lib/libc/unistd/setpgrp.c deleted file mode 100644 index a2a37f65f..000000000 --- a/usr/lib/libc/unistd/setpgrp.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -pid_t setpgrp(void) -{ - return setpgid(0, 0); -} diff --git a/usr/lib/libc/unistd/setregid.c b/usr/lib/libc/unistd/setregid.c deleted file mode 100644 index f5a8972ae..000000000 --- a/usr/lib/libc/unistd/setregid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setregid(gid_t rgid, gid_t egid) -{ - return __setxid(SYS_setregid, rgid, egid, 0); -} diff --git a/usr/lib/libc/unistd/setresgid.c b/usr/lib/libc/unistd/setresgid.c deleted file mode 100644 index b9af540af..000000000 --- a/usr/lib/libc/unistd/setresgid.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" -#include "libc.h" - -int setresgid(gid_t rgid, gid_t egid, gid_t sgid) -{ - return __setxid(SYS_setresgid, rgid, egid, sgid); -} diff --git a/usr/lib/libc/unistd/setresuid.c b/usr/lib/libc/unistd/setresuid.c deleted file mode 100644 index 83692b4c9..000000000 --- a/usr/lib/libc/unistd/setresuid.c +++ /dev/null @@ -1,9 +0,0 @@ -#define _GNU_SOURCE -#include -#include "syscall.h" -#include "libc.h" - -int setresuid(uid_t ruid, uid_t euid, uid_t suid) -{ - return __setxid(SYS_setresuid, ruid, euid, suid); -} diff --git a/usr/lib/libc/unistd/setreuid.c b/usr/lib/libc/unistd/setreuid.c deleted file mode 100644 index 3fcc59e29..000000000 --- a/usr/lib/libc/unistd/setreuid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setreuid(uid_t ruid, uid_t euid) -{ - return __setxid(SYS_setreuid, ruid, euid, 0); -} diff --git a/usr/lib/libc/unistd/setsid.c b/usr/lib/libc/unistd/setsid.c deleted file mode 100644 index 609bbe4ac..000000000 --- a/usr/lib/libc/unistd/setsid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -pid_t setsid(void) -{ - return syscall(SYS_setsid); -} diff --git a/usr/lib/libc/unistd/setuid.c b/usr/lib/libc/unistd/setuid.c deleted file mode 100644 index 602ecbbf4..000000000 --- a/usr/lib/libc/unistd/setuid.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int setuid(uid_t uid) -{ - return __setxid(SYS_setuid, uid, 0, 0); -} diff --git a/usr/lib/libc/unistd/setxid.c b/usr/lib/libc/unistd/setxid.c deleted file mode 100644 index 0239f8afa..000000000 --- a/usr/lib/libc/unistd/setxid.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include "syscall.h" -#include "libc.h" -#include "pthread_impl.h" - -struct ctx { - int id, eid, sid; - int nr, err; -}; - -static void do_setxid(void *p) -{ - struct ctx *c = p; - if (c->err>0) return; - int ret = -__syscall(c->nr, c->id, c->eid, c->sid); - if (ret && !c->err) { - /* If one thread fails to set ids after another has already - * succeeded, forcibly killing the process is the only safe - * thing to do. State is inconsistent and dangerous. Use - * SIGKILL because it is uncatchable. */ - __block_all_sigs(0); - __syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL); - } - c->err = ret; -} - -int __setxid(int nr, int id, int eid, int sid) -{ - /* err is initially nonzero so that failure of the first thread does not - * trigger the safety kill above. */ - struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .err = -1 }; - __synccall(do_setxid, &c); - if (c.err) { - if (c.err>0) errno = c.err; - return -1; - } - return 0; -} diff --git a/usr/lib/libc/unistd/sleep.c b/usr/lib/libc/unistd/sleep.c deleted file mode 100644 index d64509413..000000000 --- a/usr/lib/libc/unistd/sleep.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -unsigned sleep(unsigned seconds) -{ - struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 }; - if (nanosleep(&tv, &tv)) - return tv.tv_sec; - return 0; -} diff --git a/usr/lib/libc/unistd/symlink.c b/usr/lib/libc/unistd/symlink.c deleted file mode 100644 index 0973d78a8..000000000 --- a/usr/lib/libc/unistd/symlink.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int symlink(const char *existing, const char *new) -{ -#ifdef SYS_symlink - return syscall(SYS_symlink, existing, new); -#else - return syscall(SYS_symlinkat, existing, AT_FDCWD, new); -#endif -} diff --git a/usr/lib/libc/unistd/symlinkat.c b/usr/lib/libc/unistd/symlinkat.c deleted file mode 100644 index d1c59b4db..000000000 --- a/usr/lib/libc/unistd/symlinkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int symlinkat(const char *existing, int fd, const char *new) -{ - return syscall(SYS_symlinkat, existing, fd, new); -} diff --git a/usr/lib/libc/unistd/sync.c b/usr/lib/libc/unistd/sync.c deleted file mode 100644 index f18765aa8..000000000 --- a/usr/lib/libc/unistd/sync.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -void sync(void) -{ - __syscall(SYS_sync); -} diff --git a/usr/lib/libc/unistd/tcgetpgrp.c b/usr/lib/libc/unistd/tcgetpgrp.c deleted file mode 100644 index 50080c7e8..000000000 --- a/usr/lib/libc/unistd/tcgetpgrp.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include -#include - -pid_t tcgetpgrp(int fd) -{ - int pgrp; - if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) - return -1; - return pgrp; -} diff --git a/usr/lib/libc/unistd/tcsetpgrp.c b/usr/lib/libc/unistd/tcsetpgrp.c deleted file mode 100644 index 67c38cb45..000000000 --- a/usr/lib/libc/unistd/tcsetpgrp.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include -#include - -int tcsetpgrp(int fd, pid_t pgrp) -{ - int pgrp_int = pgrp; - return ioctl(fd, TIOCSPGRP, &pgrp_int); -} diff --git a/usr/lib/libc/unistd/truncate.c b/usr/lib/libc/unistd/truncate.c deleted file mode 100644 index 8e65655cd..000000000 --- a/usr/lib/libc/unistd/truncate.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -int truncate(const char *path, off_t length) -{ - return syscall(SYS_truncate, path, __SYSCALL_LL_O(length)); -} - -LFS64(truncate); diff --git a/usr/lib/libc/unistd/ttyname.c b/usr/lib/libc/unistd/ttyname.c deleted file mode 100644 index 0f3e11411..000000000 --- a/usr/lib/libc/unistd/ttyname.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include - -char *ttyname(int fd) -{ - static char buf[TTY_NAME_MAX]; - int result; - if ((result = ttyname_r(fd, buf, sizeof buf))) { - errno = result; - return NULL; - } - return buf; -} diff --git a/usr/lib/libc/unistd/ttyname_r.c b/usr/lib/libc/unistd/ttyname_r.c deleted file mode 100644 index 33aa4ae1a..000000000 --- a/usr/lib/libc/unistd/ttyname_r.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -void __procfdname(char *, unsigned); - -int ttyname_r(int fd, char *name, size_t size) -{ - struct stat st1, st2; - char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; - ssize_t l; - - if (!isatty(fd)) return ENOTTY; - - __procfdname(procname, fd); - l = readlink(procname, name, size); - - if (l < 0) return errno; - else if (l == size) return ERANGE; - - name[l] = 0; - - if (stat(name, &st1) || fstat(fd, &st2)) - return errno; - if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) - return ENODEV; - - return 0; -} diff --git a/usr/lib/libc/unistd/ualarm.c b/usr/lib/libc/unistd/ualarm.c deleted file mode 100644 index 855504bca..000000000 --- a/usr/lib/libc/unistd/ualarm.c +++ /dev/null @@ -1,13 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -unsigned ualarm(unsigned value, unsigned interval) -{ - struct itimerval it = { - .it_interval.tv_usec = interval, - .it_value.tv_usec = value - }; - setitimer(ITIMER_REAL, &it, &it); - return it.it_value.tv_sec*1000000 + it.it_value.tv_usec; -} diff --git a/usr/lib/libc/unistd/unlink.c b/usr/lib/libc/unistd/unlink.c deleted file mode 100644 index c40c28d50..000000000 --- a/usr/lib/libc/unistd/unlink.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "syscall.h" - -int unlink(const char *path) -{ -#ifdef SYS_unlink - return syscall(SYS_unlink, path); -#else - return syscall(SYS_unlinkat, AT_FDCWD, path, 0); -#endif -} diff --git a/usr/lib/libc/unistd/unlinkat.c b/usr/lib/libc/unistd/unlinkat.c deleted file mode 100644 index e0e25d22a..000000000 --- a/usr/lib/libc/unistd/unlinkat.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -int unlinkat(int fd, const char *path, int flag) -{ - return syscall(SYS_unlinkat, fd, path, flag); -} diff --git a/usr/lib/libc/unistd/usleep.c b/usr/lib/libc/unistd/usleep.c deleted file mode 100644 index 62712eda6..000000000 --- a/usr/lib/libc/unistd/usleep.c +++ /dev/null @@ -1,12 +0,0 @@ - -#include -#include - -int usleep(unsigned useconds) -{ - struct timespec tv = { - .tv_sec = useconds/1000000, - .tv_nsec = (useconds%1000000)*1000 - }; - return nanosleep(&tv, &tv); -} diff --git a/usr/lib/libc/unistd/write.c b/usr/lib/libc/unistd/write.c deleted file mode 100644 index 545eb1a54..000000000 --- a/usr/lib/libc/unistd/write.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t write(int fd, const void *buf, size_t count) -{ - return __syscall_ret(sys_write(fd, buf, count)); - -#if 0 - return syscall_cp(SYS_write, fd, buf, count); -#endif -} diff --git a/usr/lib/libc/unistd/writev.c b/usr/lib/libc/unistd/writev.c deleted file mode 100644 index ef300ddf8..000000000 --- a/usr/lib/libc/unistd/writev.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include "syscall.h" -#include "libc.h" - -ssize_t writev(int fd, const struct iovec *iov, int count) -{ - return syscall_cp(SYS_writev, fd, iov, count); -} From 0553699e30e4910e62422c80a4dbfcf6699297b7 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 10 Dec 2025 10:42:59 +0100 Subject: [PATCH 68/69] [musl] remove old cmake toolchain files Signed-off-by: Jean-Pierre Miceli --- usr/aarch64_none_toolchain.cmake | 30 ---------------------------- usr/aarch64_toolchain.cmake | 29 --------------------------- usr/arm_toolchain.cmake | 34 -------------------------------- 3 files changed, 93 deletions(-) delete mode 100644 usr/aarch64_none_toolchain.cmake delete mode 100644 usr/aarch64_toolchain.cmake delete mode 100644 usr/arm_toolchain.cmake diff --git a/usr/aarch64_none_toolchain.cmake b/usr/aarch64_none_toolchain.cmake deleted file mode 100644 index c0549bb29..000000000 --- a/usr/aarch64_none_toolchain.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# -# CMake toolchain information for SO3 build -# Inspired from buildroot generated toolchain.cmake -# - -set(CMAKE_SYSTEM_NAME SO3_usr) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR aarch64) - -set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS") -set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release CFLAGS") - -set(CMAKE_BUILD_TYPE Release CACHE STRING "SO3 user applications build system") - -set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "SO3 usr LDFLAGS for executables") - -set(CMAKE_INSTALL_SO_NO_EXE 0) - -# This toolchain file can be used both inside and outside Buildroot. -set(CMAKE_C_COMPILER "aarch64-none-elf-gcc") -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) -set(CMAKE_CXX_COMPILER "aarch64-none-elf-g++") -set(CMAKE_C_LINK_EXECUTABLE "aarch64-none-elf-ld -o ") -set(CMAKE_ASM_COMPILER "aarch64-none-elf-gcc") - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D_GNU_SOURCE -nostdlib -D__ARM64__ -ffreestanding -fno-common") - -set(CMAKE_ASM_FLAGS "-D__ARM64__ -D__ASSEMBLY__") - -set(CMAKE_LINKER "aarch64-none-elf-ld") diff --git a/usr/aarch64_toolchain.cmake b/usr/aarch64_toolchain.cmake deleted file mode 100644 index 3e65fc675..000000000 --- a/usr/aarch64_toolchain.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# -# CMake toolchain information for SO3 build -# Inspired from buildroot generated toolchain.cmake -# - -set(CMAKE_SYSTEM_NAME SO3_usr) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR aarch64) - -set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS") -set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release CFLAGS") - -set(CMAKE_BUILD_TYPE Release CACHE STRING "SO3 user applications build system") - -set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "SO3 usr LDFLAGS for executables") - -set(CMAKE_INSTALL_SO_NO_EXE 0) - -# This toolchain file can be used both inside and outside Buildroot. -set(CMAKE_C_COMPILER "aarch64-none-linux-gnu-gcc") -set(CMAKE_CXX_COMPILER "aarch64-none-linux-gnu-g++") -set(CMAKE_C_LINK_EXECUTABLE "aarch64-none-linux-gnu-ld -o ") -set(CMAKE_ASM_COMPILER "aarch64-none-linux-gnu-gcc") - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D_GNU_SOURCE -nostdlib -D__ARM64__ -ffreestanding -fno-common") - -set(CMAKE_ASM_FLAGS "-D__ARM64__ -D__ASSEMBLY__") - -set(CMAKE_LINKER "aarch64-none-linux-gnu-ld") diff --git a/usr/arm_toolchain.cmake b/usr/arm_toolchain.cmake deleted file mode 100644 index 497691e59..000000000 --- a/usr/arm_toolchain.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# -# CMake toolchain information for SO3 build -# Inspired from buildroot generated toolchain.cmake -# - -set(CMAKE_SYSTEM_NAME SO3_usr) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR armv7l) - -set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "Debug CFLAGS") -set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG" CACHE STRING "Release CFLAGS") - -set(CMAKE_BUILD_TYPE Release CACHE STRING "SO3 user applications build system") - -set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "SO3 usr LDFLAGS for executables") - -set(CMAKE_INSTALL_SO_NO_EXE 0) - -# This toolchain file can be used both inside and outside Buildroot. -set(CMAKE_C_COMPILER "arm-none-eabi-gcc") -set(CMAKE_CXX_COMPILER "arm-none-eabi-g++") -set(CMAKE_C_LINK_EXECUTABLE "arm-none-eabi-ld -o ") -set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc") - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D_GNU_SOURCE -nostdlib -D__ARM__ -marm -mno-thumb-interwork -ffreestanding -fno-common") - -set(CMAKE_ASM_FLAGS "-D__ARM__ -D__ASSEMBLY__") - -set(CMAKE_LINKER "arm-none-eabi-ld") - -set(CMAKE_EXE_LINKER_FLAGS "-nostdlib") - - - From 3c915d8a11fc34d658e99a0d5caf1dca5b45f786 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Miceli Date: Wed, 10 Dec 2025 10:55:02 +0100 Subject: [PATCH 69/69] [musl] small fixes based on review Signed-off-by: Jean-Pierre Miceli --- docker/Dockerfile.lvperf_64b | 6 +----- usr/aarch64-linux-musl.cmake | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile.lvperf_64b b/docker/Dockerfile.lvperf_64b index c8038f429..c8f0a74a9 100644 --- a/docker/Dockerfile.lvperf_64b +++ b/docker/Dockerfile.lvperf_64b @@ -79,11 +79,7 @@ RUN echo "#!/bin/sh" > install_dependencies.sh && chmod +x install_dependencies. RUN rm -rf /var/cache/apk/* RUN rm -rf /usr/share/man /usr/share/doc /usr/share/info /var/cache/apk/* -# This env varialbe is read from the usr/build.sh script in order to set a custom aarch64 toolchain -# This may be removed if so3 is fully migrated to the aarch64-none-elf toolchain -# Right now aarch64-none-linux-gnu is still used by default -#ENV USR_BUILD_TOOLCHAIN_FILE=aarch64_none_toolchain.cmake ENV QEMU_ARCH=aarch64 ENV PLATFORM=virt64 -#CMD ./install_dependencies.sh && ./docker/scripts/setup_ramfs.sh && ./docker/scripts/setup_filesystem.sh && ./docker/scripts/run.sh +CMD ./install_dependencies.sh && ./docker/scripts/setup_ramfs.sh && ./docker/scripts/setup_filesystem.sh && ./docker/scripts/run.sh diff --git a/usr/aarch64-linux-musl.cmake b/usr/aarch64-linux-musl.cmake index 9589fe32d..a36f89037 100644 --- a/usr/aarch64-linux-musl.cmake +++ b/usr/aarch64-linux-musl.cmake @@ -24,6 +24,6 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c99 -D_GNU_SOURCE -D__ARM64__ -fn set(CMAKE_ASM_FLAGS "-D__ARM64__ -D__ASSEMBLY__") -#set(CMAKE_LINKER "aarch64-none-elf-ld") +set(CMAKE_LINKER "aarch64-linux-musl-ld") set(CMAKE_EXE_LINKER_FLAGS "-Os -static" CACHE STRING "SO3 usr LDFLAGS for executables")