From 863654d1883daf825caf6f312203a04f369e81b6 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 26 Apr 2019 12:47:33 +0200 Subject: [PATCH] Libc: update port to Freebsd 12 Fix #3289 --- repos/libports/include/libc-plugin/plugin.h | 6 + repos/libports/lib/import/import-libc.mk | 20 +- repos/libports/lib/import/import-stdcxx.mk | 3 + repos/libports/lib/mk/libc-common.inc | 5 + repos/libports/lib/mk/libc-compat.mk | 2 + repos/libports/lib/mk/libc-gen.inc | 48 +++- repos/libports/lib/mk/libc-libkern.mk | 9 + repos/libports/lib/mk/libc-locale.mk | 15 +- repos/libports/lib/mk/libc-net.mk | 3 + repos/libports/lib/mk/libc-resolv.mk | 9 +- repos/libports/lib/mk/libc-stdlib.mk | 3 +- repos/libports/lib/mk/libc-stdtime.mk | 4 +- repos/libports/lib/mk/libc-tzcode.mk | 9 + repos/libports/lib/mk/libc.mk | 20 +- repos/libports/lib/mk/libiconv.mk | 1 + repos/libports/lib/mk/libm.inc | 2 +- repos/libports/lib/mk/libutil.mk | 12 - repos/libports/lib/mk/mesa-common.inc | 2 +- repos/libports/lib/mk/spec/arm/libc-gen.mk | 3 + repos/libports/lib/mk/spec/arm/libc.mk | 1 + repos/libports/lib/mk/spec/arm_64/libc-gen.mk | 21 ++ .../lib/mk/spec/arm_64/libc-setjmp.mk | 8 + repos/libports/lib/mk/spec/arm_64/libc.mk | 6 + repos/libports/lib/mk/spec/x86_32/libc.mk | 4 + repos/libports/lib/mk/spec/x86_64/libc.mk | 3 + repos/libports/lib/symbols/libc | 27 ++- repos/libports/ports/e2fsprogs-lib.hash | 2 +- repos/libports/ports/libc.hash | 2 +- repos/libports/ports/libc.port | 212 ++++++++++-------- repos/libports/ports/openlibm.hash | 1 - repos/libports/ports/openlibm.port | 14 -- .../recipes/api/libc_setjmp/content.mk | 2 +- repos/libports/recipes/src/libc/content.mk | 13 +- .../libports/recipes/src/libiconv/content.mk | 6 +- repos/libports/run/ieee754.run | 4 + repos/libports/run/libc.run | 42 ++++ repos/libports/run/libc_getaddrinfo.run | 68 +++--- repos/libports/src/lib/curl/curl_config.h | 2 +- .../lib/e2fsprogs/patches/DIOCGDINFO.patch | 14 ++ repos/libports/src/lib/libc/Version.def | 9 - repos/libports/src/lib/libc/dummies.cc | 110 +++++++-- .../libports/src/lib/libc/file_operations.cc | 175 ++++++++------- repos/libports/src/lib/libc/getrandom.cc | 99 ++++++++ .../include/spec/arm_64/internal/call_func.h | 35 +++ repos/libports/src/lib/libc/nanosleep.cc | 42 ---- repos/libports/src/lib/libc/nolocale.cc | 67 ++++++ .../src/lib/libc/patches/MB_CUR_MAX.patch | 23 ++ .../lib/libc/patches/_CurrentRuneLocale.patch | 23 ++ .../libports/src/lib/libc/patches/gdtoa.patch | 43 ++++ .../src/lib/libc/patches/malloc_c.patch | 10 - .../src/lib/libc/patches/math_private.patch | 17 -- .../src/lib/libc/patches/max_align_t.patch | 59 ----- .../libports/src/lib/libc/patches/nis_x.patch | 26 --- .../src/lib/libc/patches/printfcommon.patch | 12 + .../patches/pthread_not_implemented.patch | 76 ------- .../src/lib/libc/patches/res_init_c.patch | 70 +++++- .../src/lib/libc/patches/res_send_c.patch | 32 --- .../src/lib/libc/patches/runetype.patch | 15 ++ .../src/lib/libc/patches/semaphore.patch | 11 + .../src/lib/libc/patches/setlocale.patch | 11 + .../src/lib/libc/patches/thread_local.patch | 23 ++ .../libports/src/lib/libc/patches/types.patch | 54 +++-- .../src/lib/libc/patches/xlocale.patch | 35 +++ .../lib/libc/patches/xlocale_private.patch | 59 +++++ .../src/lib/libc/patches/xprintf_float.patch | 12 + repos/libports/src/lib/libc/plugin.cc | 16 ++ repos/libports/src/lib/libc/poll.cc | 168 +++++++------- repos/libports/src/lib/libc/pread_pwrite.cc | 6 + repos/libports/src/lib/libc/readv_writev.cc | 24 +- repos/libports/src/lib/libc/select.cc | 40 ++-- repos/libports/src/lib/libc/signal.cc | 86 ++++++- repos/libports/src/lib/libc/sleep.cc | 105 +++++++++ .../libports/src/lib/libc/socket_fs_plugin.cc | 57 ++++- .../src/lib/libc/socket_operations.cc | 146 +++++------- repos/libports/src/lib/libc/sysctl.cc | 132 +---------- repos/libports/src/lib/libc/thread.cc | 6 + repos/libports/src/lib/libc/thread_create.h | 5 + repos/libports/src/lib/libc/time.cc | 8 + repos/libports/src/lib/libc/vfs_plugin.cc | 42 ++++ repos/libports/src/lib/libc/vfs_plugin.h | 2 + repos/libports/src/lib/libc_pipe/plugin.cc | 41 ++++ repos/libports/src/test/libc/main.cc | 16 +- repos/ports/ports/e2fsprogs.hash | 2 +- repos/ports/recipes/src/seoul/content.mk | 4 +- repos/ports/run/noux.run | 24 +- repos/ports/run/noux_bash.run | 9 +- repos/ports/src/lib/libc_noux/plugin.cc | 36 ++- .../e2fsprogs/patches/DIOCGDINFO.patch | 14 ++ .../e2fsprogs/patches/unix_io.c.patch | 13 ++ repos/ports/src/noux-pkg/gcc/target.inc | 3 + tool/ports/mk/install.mk | 3 +- 91 files changed, 1819 insertions(+), 965 deletions(-) create mode 100644 repos/libports/lib/mk/libc-libkern.mk create mode 100644 repos/libports/lib/mk/libc-tzcode.mk delete mode 100644 repos/libports/lib/mk/libutil.mk create mode 100644 repos/libports/lib/mk/spec/arm_64/libc-gen.mk create mode 100644 repos/libports/lib/mk/spec/arm_64/libc-setjmp.mk create mode 100644 repos/libports/lib/mk/spec/arm_64/libc.mk delete mode 100644 repos/libports/ports/openlibm.hash delete mode 100644 repos/libports/ports/openlibm.port create mode 100644 repos/libports/run/libc.run create mode 100644 repos/libports/src/lib/e2fsprogs/patches/DIOCGDINFO.patch delete mode 100644 repos/libports/src/lib/libc/Version.def create mode 100644 repos/libports/src/lib/libc/getrandom.cc create mode 100644 repos/libports/src/lib/libc/include/spec/arm_64/internal/call_func.h delete mode 100644 repos/libports/src/lib/libc/nanosleep.cc create mode 100644 repos/libports/src/lib/libc/nolocale.cc create mode 100644 repos/libports/src/lib/libc/patches/MB_CUR_MAX.patch create mode 100644 repos/libports/src/lib/libc/patches/_CurrentRuneLocale.patch create mode 100644 repos/libports/src/lib/libc/patches/gdtoa.patch delete mode 100644 repos/libports/src/lib/libc/patches/malloc_c.patch delete mode 100644 repos/libports/src/lib/libc/patches/math_private.patch delete mode 100644 repos/libports/src/lib/libc/patches/max_align_t.patch delete mode 100644 repos/libports/src/lib/libc/patches/nis_x.patch create mode 100644 repos/libports/src/lib/libc/patches/printfcommon.patch delete mode 100644 repos/libports/src/lib/libc/patches/pthread_not_implemented.patch delete mode 100644 repos/libports/src/lib/libc/patches/res_send_c.patch create mode 100644 repos/libports/src/lib/libc/patches/runetype.patch create mode 100644 repos/libports/src/lib/libc/patches/semaphore.patch create mode 100644 repos/libports/src/lib/libc/patches/setlocale.patch create mode 100644 repos/libports/src/lib/libc/patches/thread_local.patch create mode 100644 repos/libports/src/lib/libc/patches/xlocale.patch create mode 100644 repos/libports/src/lib/libc/patches/xlocale_private.patch create mode 100644 repos/libports/src/lib/libc/patches/xprintf_float.patch create mode 100644 repos/libports/src/lib/libc/sleep.cc create mode 100644 repos/ports/src/noux-pkg/e2fsprogs/patches/DIOCGDINFO.patch create mode 100644 repos/ports/src/noux-pkg/e2fsprogs/patches/unix_io.c.patch diff --git a/repos/libports/include/libc-plugin/plugin.h b/repos/libports/include/libc-plugin/plugin.h index da218293b..12b0cf6ef 100644 --- a/repos/libports/include/libc-plugin/plugin.h +++ b/repos/libports/include/libc-plugin/plugin.h @@ -22,6 +22,7 @@ #include #include #include /* for 'struct statfs' */ +#include /* for 'struct pollfd' */ namespace Genode { class Env; } @@ -42,6 +43,9 @@ namespace Libc { typedef Genode::size_t size_t; + /* Resume all libc threads blocked for I/O */ + void resume_all(); + public: Plugin(int priority = 0); @@ -55,6 +59,7 @@ namespace Libc { virtual bool supports_mkdir(const char *path, mode_t mode); virtual bool supports_open(const char *pathname, int flags); virtual bool supports_pipe(); + virtual bool supports_poll(); virtual bool supports_readlink(const char *path, char *buf, ::size_t bufsiz); virtual bool supports_rename(const char *oldpath, const char *newpath); virtual bool supports_rmdir(const char *path); @@ -115,6 +120,7 @@ namespace Libc { virtual int msync(void *addr, ::size_t len, int flags); virtual File_descriptor *open(const char *pathname, int flags); virtual int pipe(File_descriptor *pipefd[2]); + virtual bool poll(File_descriptor&, struct pollfd &pfd); virtual ssize_t read(File_descriptor *, void *buf, ::size_t count); virtual ssize_t readlink(const char *path, char *buf, ::size_t bufsiz); virtual ssize_t recv(File_descriptor *, void *buf, ::size_t len, int flags); diff --git a/repos/libports/lib/import/import-libc.mk b/repos/libports/lib/import/import-libc.mk index d6032470f..c53a4d078 100644 --- a/repos/libports/lib/import/import-libc.mk +++ b/repos/libports/lib/import/import-libc.mk @@ -10,9 +10,14 @@ ifeq ($(filter-out $(SPECS),x86_64),) endif # x86_64 ifeq ($(filter-out $(SPECS),arm),) + CC_OPT += -D__ARM_PCS_VFP LIBC_ARCH_INC_DIR := include/spec/arm/libc endif # ARM +ifeq ($(filter-out $(SPECS),arm_64),) + LIBC_ARCH_INC_DIR := include/spec/arm_64/libc +endif # ARM64 + # # If we found no valid include path for the configured target platform, # we have to prevent the build system from building the target. This is @@ -25,10 +30,16 @@ endif ifeq ($(CONTRIB_DIR),) REP_INC_DIR += include/libc REP_INC_DIR += $(LIBC_ARCH_INC_DIR) +ifeq ($(filter-out $(SPECS),x86),) + REP_INC_DIR += include/spec/x86/libc +endif else LIBC_PORT_DIR := $(call select_from_ports,libc) INC_DIR += $(LIBC_PORT_DIR)/include/libc INC_DIR += $(LIBC_PORT_DIR)/$(LIBC_ARCH_INC_DIR) +ifeq ($(filter-out $(SPECS),x86),) + INC_DIR += $(LIBC_PORT_DIR)/include/spec/x86/libc +endif endif # @@ -40,12 +51,7 @@ REP_INC_DIR += include/libc-genode # Prevent gcc headers from defining __size_t. This definition is done in # machine/_types.h. # -CC_OPT += -D__FreeBSD__=8 - -# -# Provide C99 API functions (needed for C++11 in stdcxx at least) -# -CC_OPT += -D__ISO_C_VISIBLE=1999 +CC_OPT += -D__FreeBSD__=12 # # Prevent gcc-4.4.5 from generating code for the family of 'sin' and 'cos' @@ -53,3 +59,5 @@ CC_OPT += -D__ISO_C_VISIBLE=1999 # or 'sincosf', which is a GNU extension, not provided by our libc. # CC_OPT += -fno-builtin-sin -fno-builtin-cos -fno-builtin-sinf -fno-builtin-cosf + +CC_OPT += -D__GENODE__ diff --git a/repos/libports/lib/import/import-stdcxx.mk b/repos/libports/lib/import/import-stdcxx.mk index 9880b5bce..84a2c0eda 100644 --- a/repos/libports/lib/import/import-stdcxx.mk +++ b/repos/libports/lib/import/import-stdcxx.mk @@ -17,3 +17,6 @@ CC_OPT += -D_GLIBCXX_HAVE_MBSTATE_T # use compiler-builtin atomic operations CC_OPT += -D_GLIBCXX_ATOMIC_BUILTINS_4 + +# No isinf isnan +CC_OPT += -D_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC diff --git a/repos/libports/lib/mk/libc-common.inc b/repos/libports/lib/mk/libc-common.inc index 04788c9fe..51728194e 100644 --- a/repos/libports/lib/mk/libc-common.inc +++ b/repos/libports/lib/mk/libc-common.inc @@ -30,6 +30,11 @@ CC_CXX_OPT += -Wall # CC_OPT += -DPIC +# +# Disable thread local locales +# +CC_OPT += -D__NO_TLS + # # Use libc import rules also for building the libc itself # diff --git a/repos/libports/lib/mk/libc-compat.mk b/repos/libports/lib/mk/libc-compat.mk index 3864d3b43..bfad9aff1 100644 --- a/repos/libports/lib/mk/libc-compat.mk +++ b/repos/libports/lib/mk/libc-compat.mk @@ -1,5 +1,7 @@ LIBC_COMPAT_DIR = $(LIBC_DIR)/lib/libc/compat-43 +FILTER_OUT += creat.c + SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(LIBC_COMPAT_DIR)/*.c))) include $(REP_DIR)/lib/mk/libc-common.inc diff --git a/repos/libports/lib/mk/libc-gen.inc b/repos/libports/lib/mk/libc-gen.inc index 449653f30..ab0ce929a 100644 --- a/repos/libports/lib/mk/libc-gen.inc +++ b/repos/libports/lib/mk/libc-gen.inc @@ -6,19 +6,65 @@ FILTER_OUT_C += getosreldate.c sem.c valloc.c getpwent.c # the following are superceded by our minimalist sysctl and sysconf FILTER_OUT_C += \ devname.c feature_present.c getpagesizes.c getvfsbyname.c \ - setproctitle.c sysconf.c sysctlbyname.c + setproctitle.c sysconf.c # the following is a wrapper over rusage, which we cannot provide FILTER_OUT_C += clock.c +# we implement this ourselves +FILTER_OUT_C += isatty.c + +# compatibility with older FreeBSD is not a concern +FILTER_OUT_C += $(notdir $(wildcard $(LIBC_GEN_DIR)/*-compat11.c)) + +# file-locking not supported +FILTER_OUT_C += lockf.c + +# interposing stubs +FILTER_OUT_C += \ + elf_utils.c \ + sleep.c \ + _spinlock_stub.c \ + usleep.c \ + wait3.c \ + wait.c \ + waitid.c \ + waitpid.c \ + +# not appropriate in this context +FILTER_OUT_C += \ + cap_sandboxed.c \ + daemon.c \ + disklabel.c \ + exect.c \ + getentropy.c \ + getutxent.c \ + pututxline.c \ + readpassphrase.c \ + scandir_b.c \ + sem_new.c \ + signal.c \ + siginterrupt.c \ + trivial-getcontextx.c \ + utxdb.c \ + +# Uses non-standard "thr_kill" +FILTER_OUT_C += raise.c + SRC_C = $(filter-out $(FILTER_OUT_C),$(notdir $(wildcard $(LIBC_GEN_DIR)/*.c))) +SRC_C += interposing_table.c + # 'sysconf.c' includes the local 'stdtime/tzfile.h' INC_DIR += $(REP_DIR)/src/lib/libc/stdtime # '_pthread_stubs.c' includes the local 'libc_pdbg.h' INC_DIR += $(REP_DIR)/src/lib/libc +INC_DIR += $(LIBC_DIR)/sys/crypto/chacha20 +INC_DIR += $(LIBC_DIR)/sys + include $(REP_DIR)/lib/mk/libc-common.inc vpath %.c $(LIBC_GEN_DIR) +vpath interposing_table.c $(LIBC_DIR)/lib/libc/sys diff --git a/repos/libports/lib/mk/libc-libkern.mk b/repos/libports/lib/mk/libc-libkern.mk new file mode 100644 index 000000000..cc554871c --- /dev/null +++ b/repos/libports/lib/mk/libc-libkern.mk @@ -0,0 +1,9 @@ +LIBC_LIBKERN_DIR = $(LIBC_DIR)/sys/libkern + +SRC_C = explicit_bzero.c + +include $(REP_DIR)/lib/mk/libc-common.inc + +vpath %.c $(LIBC_LIBKERN_DIR) + +CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/libc-locale.mk b/repos/libports/lib/mk/libc-locale.mk index 222bf2fd2..8e75e5958 100644 --- a/repos/libports/lib/mk/libc-locale.mk +++ b/repos/libports/lib/mk/libc-locale.mk @@ -1,9 +1,22 @@ LIBC_LOCALE_DIR = $(LIBC_DIR)/lib/libc/locale -SRC_C = $(notdir $(wildcard $(LIBC_LOCALE_DIR)/*.c)) +CC_OPT += -D_Thread_local="" + +# strip locale support down to "C" +FILTER_OUT = \ + c16rtomb.c c32rtomb_iconv.c mbrtoc16_iconv.c mbrtoc32_iconv.c \ + setlocale.c xlocale.c setrunelocale.c \ + ascii.c big5.c euc.co gb18030.c gb2312.c gbk.c mbsinit.c mskanji.c utf8.c \ + +SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(LIBC_LOCALE_DIR)/*.c))) + +# locale dummies +SRC_CC += nolocale.cc +CXX_OPT += -fpermissive include $(REP_DIR)/lib/mk/libc-common.inc vpath %.c $(LIBC_LOCALE_DIR) +vpath nolocale.cc $(REP_DIR)/src/lib/libc CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/libc-net.mk b/repos/libports/lib/mk/libc-net.mk index c4b29f07e..551f3be4f 100644 --- a/repos/libports/lib/mk/libc-net.mk +++ b/repos/libports/lib/mk/libc-net.mk @@ -30,6 +30,9 @@ INC_DIR += $(LIBC_PORT_DIR)/include/libc/sys # needed for name6.c, contains res_private.h INC_DIR += $(LIBC_DIR)/lib/libc/resolv +# needed for net/firewire.h +INC_DIR += $(LIBC_DIR)/sys + vpath %.c $(LIBC_NET_DIR) nslexer.o: nsparser.c nsparser.c diff --git a/repos/libports/lib/mk/libc-resolv.mk b/repos/libports/lib/mk/libc-resolv.mk index c4eaf0940..d84b47ab6 100644 --- a/repos/libports/lib/mk/libc-resolv.mk +++ b/repos/libports/lib/mk/libc-resolv.mk @@ -1,9 +1,16 @@ LIBC_RESOLV_DIR = $(LIBC_DIR)/lib/libc/resolv -SRC_C = $(notdir $(wildcard $(LIBC_RESOLV_DIR)/*.c)) +FILTER_OUT = res_debug.c + +SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(LIBC_RESOLV_DIR)/*.c))) include $(REP_DIR)/lib/mk/libc-common.inc +INC_DIR += sys/sys +INC_DIR += $(LIBC_DIR)/sys/sys + +CC_DEF += -DSTDERR_FILENO=2 + vpath %.c $(LIBC_RESOLV_DIR) CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/libc-stdlib.mk b/repos/libports/lib/mk/libc-stdlib.mk index 8a3b81a7a..38795c83e 100644 --- a/repos/libports/lib/mk/libc-stdlib.mk +++ b/repos/libports/lib/mk/libc-stdlib.mk @@ -1,7 +1,6 @@ LIBC_STDLIB_DIR = $(LIBC_DIR)/lib/libc/stdlib -FILTER_OUT = exit.c atexit.c malloc.c +FILTER_OUT = exit.c atexit.c malloc.c system.c -#SRC_C = $(notdir $(wildcard $(LIBC_STDLIB_DIR)/*.c)) SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(LIBC_STDLIB_DIR)/*.c))) include $(REP_DIR)/lib/mk/libc-common.inc diff --git a/repos/libports/lib/mk/libc-stdtime.mk b/repos/libports/lib/mk/libc-stdtime.mk index a7be2baba..7ad73b1a4 100644 --- a/repos/libports/lib/mk/libc-stdtime.mk +++ b/repos/libports/lib/mk/libc-stdtime.mk @@ -1,6 +1,8 @@ LIBC_STDTIME_DIR = $(LIBC_DIR)/lib/libc/stdtime -SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(LIBC_STDTIME_DIR)/*.c))) +INC_DIR += $(LIBC_DIR)/contrib/tzcode/stdtime + +SRC_C = $(notdir $(wildcard $(LIBC_STDTIME_DIR)/*.c)) CC_OPT_localtime = -DTZ_MAX_TIMES=1 diff --git a/repos/libports/lib/mk/libc-tzcode.mk b/repos/libports/lib/mk/libc-tzcode.mk new file mode 100644 index 000000000..a9247f611 --- /dev/null +++ b/repos/libports/lib/mk/libc-tzcode.mk @@ -0,0 +1,9 @@ +TZCODE_DIR = $(LIBC_DIR)/contrib/tzcode/stdtime + +SRC_C = $(filter-out $(FILTER_OUT),$(notdir $(wildcard $(TZCODE_DIR)/*.c))) + +include $(REP_DIR)/lib/mk/libc-common.inc + +vpath %.c $(TZCODE_DIR) + +CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/libc.mk b/repos/libports/lib/mk/libc.mk index e4257e560..a4f13993e 100644 --- a/repos/libports/lib/mk/libc.mk +++ b/repos/libports/lib/mk/libc.mk @@ -3,7 +3,8 @@ # LIBS = libc-string libc-locale libc-stdlib libc-stdio libc-gen libc-gdtoa \ libc-inet libc-stdtime libc-regex libc-compat libc-setjmp libc-mem \ - libc-resolv libc-isc libc-nameser libc-net libc-rpc \ + libc-resolv libc-isc libc-nameser libc-net libc-rpc libc-tzcode \ + libc-libkern LIBS += base vfs @@ -13,11 +14,11 @@ LIBS += base vfs SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc \ issetugid.cc errno.cc gai_strerror.cc time.cc \ malloc.cc progname.cc fd_alloc.cc file_operations.cc \ - plugin.cc plugin_registry.cc select.cc exit.cc environ.cc nanosleep.cc \ + plugin.cc plugin_registry.cc select.cc exit.cc environ.cc sleep.cc \ pread_pwrite.cc readv_writev.cc poll.cc \ vfs_plugin.cc rtc.cc dynamic_linker.cc signal.cc \ socket_operations.cc task.cc socket_fs_plugin.cc syscall.cc \ - getpwent.cc + getpwent.cc getrandom.cc # # Pthreads @@ -25,13 +26,22 @@ SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc \ SRC_CC += semaphore.cc rwlock.cc \ thread.cc thread_create.cc -CC_OPT_sysctl += -Wno-write-strings +# +# FreeBSD headers use the C99 restrict keyword +# +CXX_DEF += -Drestrict=__restrict + +# +# Extra include path for internal dummies +# +CC_OPT_dummies += -I$(LIBC_DIR)/sys INC_DIR += $(REP_DIR)/src/lib/libc INC_DIR += $(REP_DIR)/src/lib/libc/include # needed for base/internal/unmanaged_singleton.h INC_DIR += $(BASE_DIR)/src/include +INC_DIR += $(BASE_DIR)/sys # # Files from string library that are not included in libc-raw_string because @@ -48,4 +58,4 @@ vpath % $(LIBC_DIR)/lib/libc/string # Shared library, for libc we need symbol versioning # SHARED_LIB = yes -LD_OPT += --version-script=$(REP_DIR)/src/lib/libc/Version.def +LD_OPT += --version-script=$(LIBC_DIR)/lib/libc/Versions.def diff --git a/repos/libports/lib/mk/libiconv.mk b/repos/libports/lib/mk/libiconv.mk index e8ee49ce7..a4154ba6d 100644 --- a/repos/libports/lib/mk/libiconv.mk +++ b/repos/libports/lib/mk/libiconv.mk @@ -2,6 +2,7 @@ LIBICONV_PORT_DIR := $(call select_from_ports,libiconv) LIBS += libc +INC_DIR += $(REP_DIR)/include/iconv INC_DIR += $(LIBICONV_PORT_DIR)/include/iconv # find 'config.h' diff --git a/repos/libports/lib/mk/libm.inc b/repos/libports/lib/mk/libm.inc index 4ba2b1257..29052f1a7 100644 --- a/repos/libports/lib/mk/libm.inc +++ b/repos/libports/lib/mk/libm.inc @@ -1,4 +1,4 @@ -PORT_DIR := $(call select_from_ports,openlibm) +PORT_DIR := $(call select_from_ports,libc) # Depot hack ifneq ($(PORT_DIR),) diff --git a/repos/libports/lib/mk/libutil.mk b/repos/libports/lib/mk/libutil.mk deleted file mode 100644 index b4cf289ea..000000000 --- a/repos/libports/lib/mk/libutil.mk +++ /dev/null @@ -1,12 +0,0 @@ -LIBC_UTIL_DIR = $(LIBC_DIR)/lib/libutil - -# needed by libinetutils -SRC_C = logout.c logwtmp.c trimdomain.c - -INC_DIR += $(LIBC_UTIL_DIR) - -include $(REP_DIR)/lib/mk/libc-common.inc - -vpath %.c $(LIBC_UTIL_DIR) - -CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/mesa-common.inc b/repos/libports/lib/mk/mesa-common.inc index 94151ea58..820c38c4f 100644 --- a/repos/libports/lib/mk/mesa-common.inc +++ b/repos/libports/lib/mk/mesa-common.inc @@ -13,7 +13,7 @@ INC_DIR += $(MESA_SRC_DIR) \ $(MESA_PORT_DIR)/src/gallium/include \ $(LIB_DIR)/include -CC_OPT += -DHAVE_PTHREAD -D_XOPEN_SOURCE=600 -DDEFAULT_DRIVER_DIR=\"\ \" +CC_OPT += -DHAVE_PTHREAD -D_XOPEN_SOURCE=700 -DDEFAULT_DRIVER_DIR=\"\ \" CC_WARN += -Wno-return-type CC_C_OPT +=-Wno-implicit-function-declaration diff --git a/repos/libports/lib/mk/spec/arm/libc-gen.mk b/repos/libports/lib/mk/spec/arm/libc-gen.mk index 5cfc2d5e9..17719629c 100644 --- a/repos/libports/lib/mk/spec/arm/libc-gen.mk +++ b/repos/libports/lib/mk/spec/arm/libc-gen.mk @@ -6,6 +6,9 @@ LIBC_GEN_ARM_DIR = $(LIBC_DIR)/lib/libc/arm/gen FILTER_OUT_S += rfork_thread.S divsi3.S setjmp.S _setjmp.S FILTER_OUT_C += _set_tp.c fabs.c frexp.c modf.c +INC_DIR += $(LIBC_DIR)/lib/libc/arm/softfloat +INC_DIR += $(LIBC_DIR)/lib/libc/softfloat + SRC_S += $(filter-out $(FILTER_OUT_S),$(notdir $(wildcard $(LIBC_GEN_ARM_DIR)/*.S))) SRC_C += $(filter-out $(FILTER_OUT_C),$(notdir $(wildcard $(LIBC_GEN_ARM_DIR)/*.c))) diff --git a/repos/libports/lib/mk/spec/arm/libc.mk b/repos/libports/lib/mk/spec/arm/libc.mk index 042d4b706..9dc4d9ca8 100644 --- a/repos/libports/lib/mk/spec/arm/libc.mk +++ b/repos/libports/lib/mk/spec/arm/libc.mk @@ -1,5 +1,6 @@ include $(REP_DIR)/lib/mk/libc.mk INC_DIR += $(REP_DIR)/src/lib/libc/include/spec/arm +INC_DIR += $(LIBC_DIR)/include/spec/arm CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/spec/arm_64/libc-gen.mk b/repos/libports/lib/mk/spec/arm_64/libc-gen.mk new file mode 100644 index 000000000..5bd025dcf --- /dev/null +++ b/repos/libports/lib/mk/spec/arm_64/libc-gen.mk @@ -0,0 +1,21 @@ +include $(REP_DIR)/lib/mk/libc-gen.inc + +LIBC_GEN_ARM64_DIR = $(LIBC_DIR)/lib/libc/aarch64/gen + +#INC_DIR += $(LIBC_DIR)/lib/msun/aarch64 + +SRC_S += _ctx_start.S sigsetjmp.S +SRC_C += flt_rounds.c fpgetmask.c fpsetmask.c infinity.c makecontext.c + +# +# Fix missing include prefix for 'ucontext.h', should be 'sys/ucontext.h' +# +# The first path is in effect when using the regular build system. The second +# path is in effect when building the libc from a source archive (where the +# ucontext.h header is taken from the libc API archive). +# +CC_OPT_makecontext = -I$(call select_from_ports,libc)/include/libc/sys \ + $(addprefix -I,$(call select_from_repositories,/include/libc/sys)) + +vpath %.c $(LIBC_GEN_ARM64_DIR) +vpath %.S $(LIBC_GEN_ARM64_DIR) diff --git a/repos/libports/lib/mk/spec/arm_64/libc-setjmp.mk b/repos/libports/lib/mk/spec/arm_64/libc-setjmp.mk new file mode 100644 index 000000000..48819af0f --- /dev/null +++ b/repos/libports/lib/mk/spec/arm_64/libc-setjmp.mk @@ -0,0 +1,8 @@ +LIBC_GEN_ARM64_DIR = $(LIBC_DIR)/lib/libc/aarch64/gen + +SRC_S = _setjmp.S setjmp.S + +include $(REP_DIR)/lib/mk/libc-common.inc + +vpath %.S $(LIBC_GEN_ARM64_DIR) + diff --git a/repos/libports/lib/mk/spec/arm_64/libc.mk b/repos/libports/lib/mk/spec/arm_64/libc.mk new file mode 100644 index 000000000..7fd7c2137 --- /dev/null +++ b/repos/libports/lib/mk/spec/arm_64/libc.mk @@ -0,0 +1,6 @@ +include $(REP_DIR)/lib/mk/libc.mk + +INC_DIR += $(REP_DIR)/src/lib/libc/include/spec/arm_64 +INC_DIR += $(LIBC_DIR)/include/spec/arm_64 + +CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/spec/x86_32/libc.mk b/repos/libports/lib/mk/spec/x86_32/libc.mk index 9a5472746..9db361f55 100644 --- a/repos/libports/lib/mk/spec/x86_32/libc.mk +++ b/repos/libports/lib/mk/spec/x86_32/libc.mk @@ -1,5 +1,9 @@ include $(REP_DIR)/lib/mk/libc.mk INC_DIR += $(REP_DIR)/src/lib/libc/include/spec/x86_32 +INC_DIR += $(LIBC_DIR)/include/spec/x86_32 + +SRC_C += msun/i387/fenv.c +vpath msun/i387/fenv.c $(LIBC_DIR)/lib CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/mk/spec/x86_64/libc.mk b/repos/libports/lib/mk/spec/x86_64/libc.mk index e3ac6bbf6..52889ad93 100644 --- a/repos/libports/lib/mk/spec/x86_64/libc.mk +++ b/repos/libports/lib/mk/spec/x86_64/libc.mk @@ -1,5 +1,8 @@ include $(REP_DIR)/lib/mk/libc.mk + + INC_DIR += $(REP_DIR)/src/lib/libc/include/spec/x86_64 +INC_DIR += $(LIBC_DIR)/include/spec/x86_64 CC_CXX_WARN_STRICT = diff --git a/repos/libports/lib/symbols/libc b/repos/libports/lib/symbols/libc index 2df5d8ac2..4b8fd9ba5 100644 --- a/repos/libports/lib/symbols/libc +++ b/repos/libports/lib/symbols/libc @@ -7,6 +7,7 @@ __error T __flt_rounds T __fpclassifyd T __fpclassifyf T +__has_sse D 4 __h_errno T __h_errno_set T __inet_addr T @@ -17,6 +18,7 @@ __inet_ntop T __inet_pton T __isthreaded B 4 __mb_cur_max D 8 +___mb_cur_max D 50 __res_init T __res_query T __res_state T @@ -25,6 +27,7 @@ __stderrp D 8 __stdinp D 8 __stdoutp D 8 __swbuf T +__test_sse T __xuname T _exit T _getlong T @@ -33,6 +36,7 @@ a64l T abort T abs T accept T +accept4 T access T alarm T alphasort T @@ -145,6 +149,7 @@ fchown W fclose T fcloseall W fcntl T +fdatasync W fdevname T fdevname_r T fdopen T @@ -189,6 +194,7 @@ free T freeaddrinfo T freebsd7___semctl W freebsd7_semctl T +freelocale T freopen T fscanf T fseek T @@ -230,10 +236,12 @@ getchar_unlocked T getcontext W getcwd T getdelim T +getdirentries T getdiskbyname T getdomainname T getdtablesize W getegid W +getentropy W getenv T geteuid W getfsent T @@ -283,6 +291,7 @@ getpwnam W getpwnam_r W getpwuid W getpwuid_r W +getrandom W getrlimit W getrusage W gets T @@ -445,6 +454,8 @@ mrand48 T msync T munmap T nanosleep W +clock_nanosleep W +newlocale T nextwctype T nftw T nice T @@ -453,6 +464,7 @@ nlist T nrand48 T offtime T open T +openat T opendir T openlog T optarg B 8 @@ -466,8 +478,10 @@ pclose T perror T pipe T poll W +ppoll W popen T posix2time T +posix_fadvise T posix_madvise T posix_spawn T posix_spawn_file_actions_addclose T @@ -627,6 +641,7 @@ sem_trywait T sem_unlink T sem_wait T send T +sendmsg W sendto T setbuf T setbuffer T @@ -769,7 +784,7 @@ swprintf T swscanf T symlink T sync W -sys_errlist D 752 +sys_errlist D 776 sys_nerr R 4 sys_nsig R 4 sys_siglist D 256 @@ -829,10 +844,11 @@ unlink T unlockpt T unsetenv T unvis T +uselocale T user_from_uid T usleep W -utime T utimes W +utime W vasprintf T vdprintf T verr T @@ -927,8 +943,8 @@ xsi_sigpause T __mb_sb_limit D 4 _DefaultRuneLocale D 4224 _CurrentRuneLocale D 8 -__isinff T -__isinfl T +__isinf T + # # Public interface between Genode-component code and the libc runtime @@ -967,6 +983,7 @@ _ZN4Libc6Plugin13getdirentriesEPNS_15File_descriptorEPcmPl T _ZN4Libc6Plugin13supports_mmapEv T _ZN4Libc6Plugin13supports_openEPKci T _ZN4Libc6Plugin13supports_pipeEv T +_ZN4Libc6Plugin13supports_pollEv T _ZN4Libc6Plugin13supports_statEPKc T _ZN4Libc6Plugin14supports_mkdirEPKct T _ZN4Libc6Plugin14supports_rmdirEPKc T @@ -986,6 +1003,7 @@ _ZN4Libc6Plugin4mmapEPvmiiPNS_15File_descriptorEx T _ZN4Libc6Plugin4mmapEPvmiiPNS_15File_descriptorEl T _ZN4Libc6Plugin4openEPKci T _ZN4Libc6Plugin4pipeEPPNS_15File_descriptorE T +_ZN4Libc6Plugin4pollERNS_15File_descriptorER6pollfd T _ZN4Libc6Plugin4readEPNS_15File_descriptorEPvj T _ZN4Libc6Plugin4readEPNS_15File_descriptorEPvm T _ZN4Libc6Plugin4recvEPNS_15File_descriptorEPvji T @@ -1029,6 +1047,7 @@ _ZN4Libc6Plugin8recvfromEPNS_15File_descriptorEPvmiP8sockaddrPj T _ZN4Libc6Plugin8shutdownEPNS_15File_descriptorEi T _ZN4Libc6Plugin9ftruncateEPNS_15File_descriptorEl T _ZN4Libc6Plugin9ftruncateEPNS_15File_descriptorEx T +_ZN4Libc6Plugin10resume_allEv T _ZN4Libc6PluginC1Ei T _ZN4Libc6PluginC2Ei T _ZN4Libc6PluginD0Ev T diff --git a/repos/libports/ports/e2fsprogs-lib.hash b/repos/libports/ports/e2fsprogs-lib.hash index fb81b9046..135533a1f 100644 --- a/repos/libports/ports/e2fsprogs-lib.hash +++ b/repos/libports/ports/e2fsprogs-lib.hash @@ -1 +1 @@ -7302da4fea6929fd6c2e4b4c70f81b20b9dd7d38 +caa34f01d1f0afe9d9bd5d6ea2f997e7b86cc4ee diff --git a/repos/libports/ports/libc.hash b/repos/libports/ports/libc.hash index 7314c69c7..49ea13a61 100644 --- a/repos/libports/ports/libc.hash +++ b/repos/libports/ports/libc.hash @@ -1 +1 @@ -be4908ff7037258395bb0dfbc5d4c5ffef22f859 +15bedbc9f3adea283d1c036ef57448ebbdaa4cbc diff --git a/repos/libports/ports/libc.port b/repos/libports/ports/libc.port index b94105254..d144f4223 100644 --- a/repos/libports/ports/libc.port +++ b/repos/libports/ports/libc.port @@ -1,5 +1,44 @@ -LICENSE := BSD -VERSION := 8.2.0 +LICENSE = BSD +VERSION = 12.0.0 +DOWNLOADS = libc.archive openlibm.archive + +D = src/lib/libc + +URL(libc) = http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/12.0-RELEASE/src.txz +SHA(libc) = 0da393ac2174168a71c1c527d1453e07372295187d05c288250800cb152a889b +DIR(libc) = $(D) + +OWNER := JuliaMath +REPO := openlibm +REV := a96f0740e32c3d8aaa0a34c3988201018dfa90ce + +URL(openlibm) := https://github.com/$(OWNER)/$(REPO)/archive/$(REV).tar.gz +SHA(openlibm) := a9c7d4450c3e9a8b92ec1e20c7a9fd2682e900743dff37f163c9a9ac68b4f471 +DIR(openlibm) := src/lib/openlibm + +TAR_OPT(libc) = --strip-components=2 + +TAR_OPT(libc) += usr/src/contrib/gdtoa +TAR_OPT(libc) += usr/src/contrib/libc-vis +TAR_OPT(libc) += usr/src/contrib/tzcode/stdtime +TAR_OPT(libc) += usr/src/include +TAR_OPT(libc) += usr/src/lib/libc +TAR_OPT(libc) += usr/src/lib/msun +TAR_OPT(libc) += usr/src/sys/amd64 +TAR_OPT(libc) += usr/src/sys/arm +TAR_OPT(libc) += usr/src/sys/arm64 +TAR_OPT(libc) += usr/src/sys/bsm +TAR_OPT(libc) += usr/src/sys/crypto/chacha20 +TAR_OPT(libc) += usr/src/sys/i386 +TAR_OPT(libc) += usr/src/sys/libkern +TAR_OPT(libc) += usr/src/sys/net +TAR_OPT(libc) += usr/src/sys/netinet +TAR_OPT(libc) += usr/src/sys/netinet6 +TAR_OPT(libc) += usr/src/sys/riscv +TAR_OPT(libc) += usr/src/sys/rpc +TAR_OPT(libc) += usr/src/sys/sys +TAR_OPT(libc) += usr/src/sys/vm +TAR_OPT(libc) += usr/src/sys/x86 # # Check for tools @@ -9,116 +48,86 @@ $(call check_tool,flex) $(call check_tool,bison) $(call check_tool,rpcgen) -svn_exports := libc libutil include sys_sys sys_netinet \ - sys_netinet6 sys_net sys_bsm sys_rpc sys_vm \ - sys_arm sys_i386 sys_amd64 msun gdtoa gen - -DOWNLOADS := $(addsuffix .svn,$(svn_exports)) - -svn_base_url := http://svn.freebsd.org/base/release/8.2.0 - -sub_dir(libc) := lib/libc -sub_dir(gen) := lib/libc/gen -sub_dir(libutil) := lib/libutil -sub_dir(include) := include -sub_dir(sys_sys) := sys/sys -sub_dir(sys_netinet) := sys/rpc -sub_dir(sys_netinet6) := sys/net -sub_dir(sys_net) := sys/netinet -sub_dir(sys_bsm) := sys/netinet6 -sub_dir(sys_rpc) := sys/bsm -sub_dir(sys_vm) := sys/vm -sub_dir(sys_arm) := sys/arm/include -sub_dir(sys_i386) := sys/i386/include -sub_dir(sys_amd64) := sys/amd64/include -sub_dir(msun) := lib/msun -sub_dir(gdtoa) := contrib/gdtoa - -$(foreach svn_export,$(svn_exports),\ - $(eval URL($(svn_export)) := $(svn_base_url)/$(sub_dir($(svn_export))))) - -$(foreach svn_export,$(svn_exports),\ - $(eval DIR($(svn_export)) := src/lib/libc/$(sub_dir($(svn_export))))) - -$(foreach svn_export,$(svn_exports),\ - $(eval REV($(svn_export)) := HEAD)) - -PATCHES := $(sort $(wildcard $(REP_DIR)/src/lib/libc/patches/*.patch)) +PATCHES := $(sort $(wildcard $(REP_DIR)/$(D)/patches/*.patch)) # # Generic headers # -DIRS := include/libc +DIRS := include/libc include/openlibm + +DIR_CONTENT(include/openlibm) = src/lib/openlibm/include/* + DIR_CONTENT(include/libc) := \ - $(addprefix src/lib/libc/include/,\ - strings.h limits.h string.h ctype.h _ctype.h runetype.h \ + $(addprefix $(D)/include/,\ + strings.h limits.h string.h ctype.h _ctype.h \ stdlib.h stdio.h signal.h unistd.h wchar.h time.h sysexits.h \ resolv.h wctype.h locale.h langinfo.h regex.h paths.h ieeefp.h \ inttypes.h fstab.h netdb.h ar.h memory.h res_update.h \ netconfig.h ifaddrs.h pthread.h err.h getopt.h search.h \ - varargs.h stddef.h stdbool.h assert.h monetary.h printf.h vis.h \ + varargs.h stddef.h stdbool.h assert.h monetary.h printf.h \ libgen.h dirent.h dlfcn.h link.h fmtmsg.h fnmatch.h fts.h ftw.h \ - db.h grp.h nsswitch.h pthread_np.h pwd.h utmp.h ttyent.h \ + db.h grp.h nsswitch.h pthread_np.h pwd.h ttyent.h \ stringlist.h glob.h a.out.h elf-hints.h nlist.h spawn.h \ readpassphrase.h setjmp.h elf.h ulimit.h utime.h wordexp.h \ - complex.h) \ - $(addprefix src/lib/libc/sys/sys/,\ - syslog.h fcntl.h stdint.h sched.h ktrace.h termios.h \ - semaphore.h _semaphore.h) \ - src/lib/libc/sys/sys/errno.h \ - src/lib/libc/lib/msun/src/math.h + complex.h semaphore.h uchar.h iconv.h termios.h \ + xlocale.h runetype.h) \ + $(addprefix $(D)/sys/sys/,\ + syslog.h fcntl.h stdint.h sched.h ktrace.h \ + _semaphore.h ucontext.h) \ + $(D)/sys/sys/errno.h \ + $(D)/lib/msun/src/math.h \ + $(D)/contrib/libc-vis/vis.h DIRS += include/libc/rpc DIR_CONTENT(include/libc/rpc) := \ - $(addprefix src/lib/libc/include/rpc/,\ + $(addprefix $(D)/include/rpc/,\ rpc.h xdr.h auth.h clnt_stat.h clnt.h clnt_soc.h rpc_msg.h \ auth_unix.h auth_des.h svc.h svc_soc.h svc_auth.h pmap_clnt.h \ pmap_prot.h rpcb_clnt.h rpcent.h des_crypt.h des.h nettype.h \ rpcsec_gss.h raw.h rpc_com.h) \ - src/lib/libc/include/rpc/rpcb_prot.h + $(D)/include/rpc/rpcb_prot.h DIRS += include/libc/rpcsvc DIR_CONTENT(include/libc/rpcsvc) := \ - $(addprefix src/lib/libc/include/rpcsvc/,\ - yp_prot.h nis.h ypclnt.h nis_tags.h nislib.h crypt.h) + $(addprefix $(D)/include/rpcsvc/,\ + yp_prot.h nis.h ypclnt.h nis_tags.h nislib.h) DIRS += include/libc/gssapi -DIR_CONTENT(include/libc/gssapi) := src/lib/libc/include/gssapi/gssapi.h +DIR_CONTENT(include/libc/gssapi) := $(D)/include/gssapi/gssapi.h DIRS += include/libc/arpa DIR_CONTENT(include/libc/arpa) := \ - $(addprefix src/lib/libc/include/arpa/,\ + $(addprefix $(D)/include/arpa/,\ inet.h ftp.h nameser.h nameser_compat.h telnet.h tftp.h) DIRS += include/libc/vm DIR_CONTENT(include/libc/vm) := \ - $(addprefix src/lib/libc/sys/vm/, vm_param.h vm.h pmap.h) + $(addprefix $(D)/sys/vm/, vm_param.h vm.h pmap.h) DIRS += include/libc/net DIR_CONTENT(include/libc/net) := \ - $(addprefix src/lib/libc/sys/net/, if.h if_dl.h if_tun.h if_types.h \ - radix.h route.h \ - ethernet.h if_arp.h) + $(addprefix $(D)/sys/net/, if.h if_dl.h if_tun.h if_types.h \ + radix.h route.h ethernet.h if_arp.h vnet.h) DIRS += include/libc/netinet DIR_CONTENT(include/libc/netinet) := \ - $(addprefix src/lib/libc/sys/netinet/, in.h in_systm.h ip.h tcp.h \ + $(addprefix $(D)/sys/netinet/, in.h in_systm.h ip.h tcp.h \ udp.h ip_icmp.h if_ether.h tcp_fsm.h) DIRS += include/libc/netinet6 -DIR_CONTENT(include/libc/netinet6) := src/lib/libc/sys/netinet6/in6.h +DIR_CONTENT(include/libc/netinet6) := $(D)/sys/netinet6/in6.h DIRS += include/libc/bsm -DIR_CONTENT(include/libc/bsm) := src/lib/libc/sys/bsm/audit.h +DIR_CONTENT(include/libc/bsm) := $(D)/sys/bsm/audit.h DIRS += include/libc/sys/rpc -DIR_CONTENT(include/libc/sys/rpc) := src/lib/libc/sys/rpc/types.h +DIR_CONTENT(include/libc/sys/rpc) := $(D)/sys/rpc/types.h DIRS += include/libc/sys DIR_CONTENT(include/libc/sys) := \ - $(addprefix src/lib/libc/sys/sys/,\ + $(addprefix $(D)/sys/sys/,\ _types.h limits.h cdefs.h _null.h types.h _pthreadtypes.h \ syslimits.h select.h _sigset.h _timeval.h timespec.h \ _timespec.h stat.h signal.h unistd.h time.h param.h stdint.h \ @@ -129,8 +138,16 @@ DIR_CONTENT(include/libc/sys) := \ cpuset.h socket.h un.h ttydefaults.h imgact_aout.h elf32.h \ elf64.h elf_generic.h elf_common.h nlist_aout.h ipc.h sem.h \ exec.h _lock.h _mutex.h statvfs.h ucontext.h syslog.h times.h \ - utsname.h elf.h mtio.h) + utsname.h elf.h mtio.h _stdint.h atomic_common.h _ucontext.h \ + _cpuset.h _bitset.h bitset.h _stdarg.h _uio.h auxv.h random.h \ + _sockaddr_storage.h termios.h _termios.h _umtx.h kerneldump.h \ + conf.h disk_zone.h counter.h time.h) +DIRS += include/libc/sys/disk +DIR_CONTENT(include/libc/sys/disk) := $(D)/sys/sys/disk/*h + +DIRS += include/libc/xlocale +DIR_CONTENT(include/libc/xlocale) := $(D)/include/xlocale/*.h # # CPU-architecture-specific headers @@ -140,29 +157,39 @@ DIR_CONTENT(include/libc/sys) := \ # common_include_libc_arch_content = \ - $(addprefix src/lib/libc/sys/$1/include/, stdarg.h float.h) \ - $(addprefix src/lib/libc/lib/libc/$1/, arith.h _fpmath.h SYS.h gd_qnan.h) + $(addprefix $(D)/sys/$1/include/, stdarg.h float.h) \ + $(addprefix $(D)/lib/libc/$2/, arith.h _fpmath.h SYS.h gd_qnan.h) common_include_libc_arch_machine_content = \ - $(addprefix src/lib/libc/sys/$1/include/,\ + $(addprefix $(D)/sys/$1/include/,\ _types.h endian.h _limits.h signal.h trap.h _stdint.h \ - sysarch.h ieeefp.h frame.h sigframe.h vm.h \ + sysarch.h ieeefp.h frame.h vm.h \ cpufunc.h vmparam.h atomic.h elf.h exec.h reloc.h pmap.h \ - ucontext.h setjmp.h asm.h param.h _inttypes.h) + ucontext.h setjmp.h asm.h param.h _inttypes.h _align.h \ + float.h) +# +# x86-specific headers +# +DIRS += include/spec/x86/libc +DIR_CONTENT(include/spec/x86/libc) := \ + $(D)/lib/msun/x86/fenv.h + +DIRS += include/libc/x86 +DIR_CONTENT(include/libc/x86) := \ + $(D)/sys/x86/include/*.h # # i386-specific headers # DIRS += include/spec/x86_32/libc DIR_CONTENT(include/spec/x86_32/libc) := \ - $(call common_include_libc_arch_content,i386) \ - src/lib/libc/lib/msun/i387/fenv.h + $(call common_include_libc_arch_content,i386,i386) DIRS += include/spec/x86_32/libc/machine DIR_CONTENT(include/spec/x86_32/libc/machine) := \ $(call common_include_libc_arch_machine_content,i386) \ - $(addprefix src/lib/libc/sys/i386/include/, specialreg.h npx.h) + $(addprefix $(D)/sys/i386/include/, specialreg.h npx.h sigframe.h) # @@ -170,13 +197,12 @@ DIR_CONTENT(include/spec/x86_32/libc/machine) := \ # DIRS += include/spec/x86_64/libc DIR_CONTENT(include/spec/x86_64/libc) := \ - $(call common_include_libc_arch_content,amd64) \ - src/lib/libc/lib/msun/amd64/fenv.h + $(call common_include_libc_arch_content,amd64,amd64) DIRS += include/spec/x86_64/libc/machine DIR_CONTENT(include/spec/x86_64/libc/machine) := \ $(call common_include_libc_arch_machine_content,amd64) \ - $(addprefix src/lib/libc/sys/amd64/include/, specialreg.h fpu.h) + $(addprefix $(D)/sys/amd64/include/, specialreg.h fpu.h sigframe.h) # @@ -184,37 +210,43 @@ DIR_CONTENT(include/spec/x86_64/libc/machine) := \ # DIRS += include/spec/arm/libc DIR_CONTENT(include/spec/arm/libc) := \ - $(call common_include_libc_arch_content,arm) \ - src/lib/libc/lib/msun/arm/fenv.h + $(call common_include_libc_arch_content,arm,arm) \ + $(D)/lib/msun/arm/fenv.h DIRS += include/spec/arm/libc/machine DIR_CONTENT(include/spec/arm/libc/machine) := \ $(call common_include_libc_arch_machine_content,arm) \ - $(addprefix src/lib/libc/sys/arm/include/, pte.h cpuconf.h armreg.h ieee.h) + $(addprefix $(D)/sys/arm/include/, armreg.h atomic-v6.h ieee.h sysreg.h sigframe.h) + + +# +# ARM64-specific headers +# +DIRS += include/spec/arm_64/libc +DIR_CONTENT(include/spec/arm_64/libc) := \ + $(call common_include_libc_arch_content,arm64,aarch64) \ + $(D)/lib/msun/aarch64/fenv.h + +DIRS += include/spec/arm_64/libc/machine +DIR_CONTENT(include/spec/arm_64/libc/machine) := \ + $(call common_include_libc_arch_machine_content,arm64) \ + $(addprefix $(D)/sys/arm64/include/, armreg.h) # # Rules for generating files # -src/lib/libc/include/rpcsvc/nis.h: src/lib/libc/include/rpcsvc/nis_object.x - @$(MSG_GENERATE)$(notdir $@) - $(VERBOSE)rpcgen -C -h -DWANT_NFS3 $< -o $@ - -src/lib/libc/include/rpcsvc/nis_object.x : $(DOWNLOADS) +$(D)/include/rpcsvc/nis_object.x : $(DOWNLOADS) %.h: %.x @$(MSG_GENERATE)$(notdir $@) $(VERBOSE)rpcgen -C -h -DWANT_NFS3 $< -o $@ generated_rpcsvc_files := \ - $(addprefix src/lib/libc/include/rpcsvc/,\ - bootparam_prot.h nfs_prot.h nlm_prot.h rstat.h ypupdate_prot.h \ - crypt.h nis_cache.h pmap_prot.h rwall.h yp.h \ - key_prot.h nis_callback.h rex.h sm_inter.h ypxfrd.h \ - klm_prot.h nis_object.h rnusers.h spray.h \ - mount.h nis.h rquota.h yppasswd.h) \ - src/lib/libc/include/rpc/rpcb_prot.h + $(D)/include/rpc/rpcb_prot.h \ + $(addprefix $(D)/include/rpcsvc/,\ + nis.h) $(generated_rpcsvc_files:.h=.x): $(DOWNLOADS) diff --git a/repos/libports/ports/openlibm.hash b/repos/libports/ports/openlibm.hash deleted file mode 100644 index ceda38df4..000000000 --- a/repos/libports/ports/openlibm.hash +++ /dev/null @@ -1 +0,0 @@ -c1868f791e2a4dd9c2c31af84a425924179f1580 diff --git a/repos/libports/ports/openlibm.port b/repos/libports/ports/openlibm.port deleted file mode 100644 index 0600f6880..000000000 --- a/repos/libports/ports/openlibm.port +++ /dev/null @@ -1,14 +0,0 @@ -LICENSE = MIT+ISC+BSD -DOWNLOADS = openlibm.archive -VERSION = 0.6.0 - -OWNER := JuliaMath -REPO := openlibm -REV := a96f0740e32c3d8aaa0a34c3988201018dfa90ce - -URL(openlibm) := https://github.com/$(OWNER)/$(REPO)/archive/$(REV).tar.gz -SHA(openlibm) := a9c7d4450c3e9a8b92ec1e20c7a9fd2682e900743dff37f163c9a9ac68b4f471 -DIR(openlibm) := src/lib/openlibm - -DIRS := include/openlibm -DIR_CONTENT(include/openlibm) = src/lib/openlibm/include/* diff --git a/repos/libports/recipes/api/libc_setjmp/content.mk b/repos/libports/recipes/api/libc_setjmp/content.mk index dbc85fca7..0bcd21e24 100644 --- a/repos/libports/recipes/api/libc_setjmp/content.mk +++ b/repos/libports/recipes/api/libc_setjmp/content.mk @@ -22,7 +22,7 @@ content: $(MIRROR_FROM_PORT_DIR) $(MIRROR_FROM_PORT_DIR): mkdir -p $(dir $@) - cp $(PORT_DIR)/$@ $@ + cp -r $(PORT_DIR)/$@ $@ content: LICENSE diff --git a/repos/libports/recipes/src/libc/content.mk b/repos/libports/recipes/src/libc/content.mk index 15c7e0766..dec7c005f 100644 --- a/repos/libports/recipes/src/libc/content.mk +++ b/repos/libports/recipes/src/libc/content.mk @@ -1,12 +1,17 @@ -content: include/libc-plugin src/lib/libc/target.mk lib/mk LICENSE +content: include/libc-plugin src/lib/libc/target.mk lib/mk LICENSE src/lib/openlibm -PORT_DIR := $(call port_dir,$(REP_DIR)/ports/libc) +LIBC_PORT_DIR := $(call port_dir,$(REP_DIR)/ports/libc) +LIBM_PORT_DIR := $(LIBC_PORT_DIR) src/lib/libc: mkdir -p $@ - cp -r $(PORT_DIR)/src/lib/libc/* $@ + cp -r $(LIBC_PORT_DIR)/src/lib/libc/* $@ cp -r $(REP_DIR)/src/lib/libc/* $@ +src/lib/openlibm: + mkdir -p $@ + cp -r $(LIBM_PORT_DIR)/$@/* $@ + # target.mk for triggering the build of both libraries libc and libm src/lib/libc/target.mk: src/lib/libc echo "LIBS += libc libm" > $@ @@ -16,7 +21,7 @@ include/libc-plugin include/libc/sys/ucontext.h: lib/mk: mkdir -p $@ - cp $(addprefix $(REP_DIR)/$@/,libc_* libc.mk libc-* libm.mk) $@ + cp $(addprefix $(REP_DIR)/$@/,libc_* libc.mk libc-* libm.inc) $@ for spec in x86_32 x86_64 arm; do \ mkdir -p $@/spec/$$spec; \ cp $(addprefix $(REP_DIR)/$@/spec/$$spec/,libc-* libc.mk libm.mk) $@/spec/$$spec/; done diff --git a/repos/libports/recipes/src/libiconv/content.mk b/repos/libports/recipes/src/libiconv/content.mk index 263577f8a..a8e156d43 100644 --- a/repos/libports/recipes/src/libiconv/content.mk +++ b/repos/libports/recipes/src/libiconv/content.mk @@ -5,10 +5,14 @@ content: $(MIRROR_FROM_REP_DIR) $(MIRROR_FROM_REP_DIR): $(mirror_from_rep_dir) -content: src/lib/libiconv +content: src/lib/libiconv include/iconv PORT_DIR := $(call port_dir,$(REP_DIR)/ports/libiconv) +include/iconv: + mkdir -p $@ + cp -r $(PORT_DIR)/$@/* $@/ + src/lib/libiconv: mkdir -p $@ cp -r $(PORT_DIR)/src/lib/libiconv/* $@ diff --git a/repos/libports/run/ieee754.run b/repos/libports/run/ieee754.run index 165f68c3a..2fc46d141 100644 --- a/repos/libports/run/ieee754.run +++ b/repos/libports/run/ieee754.run @@ -79,6 +79,8 @@ while {true} { } set reference_output_arm { +Warning: missing sysctl for [6][10] +Warning: isatty: isatty not implemented FLT_RADIX = 2 FLT_MANT_DIG = 24 DBL_MANT_DIG = 53 @@ -300,6 +302,7 @@ Error } set reference_output_x86_64 { +Warning: isatty: isatty not implemented FLT_RADIX = 2 FLT_MANT_DIG = 24 DBL_MANT_DIG = 53 @@ -991,6 +994,7 @@ pow(-2, -2) = 0.25 } set reference_output_x86_32 { +Warning: isatty: isatty not implemented FLT_RADIX = 2 FLT_MANT_DIG = 24 DBL_MANT_DIG = 53 diff --git a/repos/libports/run/libc.run b/repos/libports/run/libc.run new file mode 100644 index 000000000..3a73d49ea --- /dev/null +++ b/repos/libports/run/libc.run @@ -0,0 +1,42 @@ +build "core init timer test/libc" + +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +build_boot_image { + core init timer test-libc + ld.lib.so libc.lib.so vfs.lib.so libm.lib.so posix.lib.so +} + +append qemu_args " -nographic " + +run_genode_until "child .* exited with exit value 0.*\n" 13 diff --git a/repos/libports/run/libc_getaddrinfo.run b/repos/libports/run/libc_getaddrinfo.run index b50d79675..5e8af6db0 100644 --- a/repos/libports/run/libc_getaddrinfo.run +++ b/repos/libports/run/libc_getaddrinfo.run @@ -1,22 +1,24 @@ +source ${genode_dir}/repos/base/run/platform_drv.inc + if {[have_spec linux]} { puts "The [run_name] scenario requires QEMU networking." exit 1 } +set build_components { + core init timer + drivers/nic + lib/vfs/lwip + test/libc_getaddrinfo +} + +append_platform_drv_build_components + +build $build_components + create_boot_directory -import_from_depot [depot_user]/src/[base_src] \ - [depot_user]/pkg/[drivers_nic_pkg] \ - [depot_user]/src/init \ - [depot_user]/src/libc \ - [depot_user]/src/posix \ - [depot_user]/src/vfs \ - [depot_user]/src/vfs_lwip \ - [depot_user]/src/zlib - -build { test/libc_getaddrinfo } - -install_config { +append config { @@ -31,22 +33,20 @@ install_config { - + } +append_platform_drv_config + +append config { - - - - - - - - - - + + + + + } [nic_drv_config] { @@ -66,15 +66,23 @@ install_config { } -build_boot_image { test-libc_getaddrinfo } +install_config $config -proc qemu_nic_model {} { - if [have_spec x86] { return e1000 } - if [have_spec lan9118] { return lan9118 } - if [have_spec zynq] { return cadence_gem } - return nic_model_missing +set boot_modules { + core init ld.lib.so + libc.lib.so libm.lib.so posix.lib.so + vfs_lwip.lib.so + test-libc_getaddrinfo + vfs.lib.so + timer } -append qemu_args " -nographic -net nic,model=[qemu_nic_model] -net user" +# platform-specific modules +append_platform_drv_boot_modules +lappend boot_modules [nic_drv_binary] + +build_boot_image $boot_modules + +append qemu_args " -nographic -net nic,model=e1000 -net user" run_genode_until "child .* exited with exit value 0.*\n" 20 diff --git a/repos/libports/src/lib/curl/curl_config.h b/repos/libports/src/lib/curl/curl_config.h index 230dac80a..d351f48cd 100644 --- a/repos/libports/src/lib/curl/curl_config.h +++ b/repos/libports/src/lib/curl/curl_config.h @@ -511,7 +511,7 @@ /* #undef HAVE_PK11_CREATEGENERICOBJECT */ /* Define to 1 if you have a working poll function. */ -/* #undef HAVE_POLL */ +#define HAVE_POLL 1 /* If you have a fine poll */ /* #undef HAVE_POLL_FINE */ diff --git a/repos/libports/src/lib/e2fsprogs/patches/DIOCGDINFO.patch b/repos/libports/src/lib/e2fsprogs/patches/DIOCGDINFO.patch new file mode 100644 index 000000000..6d41482cb --- /dev/null +++ b/repos/libports/src/lib/e2fsprogs/patches/DIOCGDINFO.patch @@ -0,0 +1,14 @@ +--- src/lib/e2fsprogs/lib/blkid/getsize.c.old 2019-05-16 13:06:14.874236710 +0200 ++++ src/lib/e2fsprogs/lib/blkid/getsize.c 2019-05-16 13:00:38.790499736 +0200 +@@ -152,11 +152,6 @@ + (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))) + part = st.st_rdev & 7; + +- if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) { +- pp = &lab.d_partitions[part]; +- if (pp->p_size) +- return pp->p_size << 9; +- } + } + #endif /* HAVE_SYS_DISKLABEL_H */ + { diff --git a/repos/libports/src/lib/libc/Version.def b/repos/libports/src/lib/libc/Version.def deleted file mode 100644 index 7e5b82a96..000000000 --- a/repos/libports/src/lib/libc/Version.def +++ /dev/null @@ -1,9 +0,0 @@ -# -# \brief Version node description for libc -# \author Sebastian Sumpf -# \date 2010-06-17 -# - -#depends on nothing -FBSD_1.0 { -}; diff --git a/repos/libports/src/lib/libc/dummies.cc b/repos/libports/src/lib/libc/dummies.cc index 9b30fc976..9e77663f5 100644 --- a/repos/libports/src/lib/libc/dummies.cc +++ b/repos/libports/src/lib/libc/dummies.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2008-2017 Genode Labs GmbH + * Copyright (C) 2008-2019 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -33,6 +33,11 @@ extern "C" { #include #include #include +#include +#include +#include +#include + #define DUMMY(ret_type, ret_val, name, args) __attribute__((weak)) \ ret_type name args \ @@ -50,28 +55,41 @@ ret_type name args \ return ret_val; \ } +#define __SYS_DUMMY(ret_type, ret_val, name, args)\ + extern "C" __attribute__((weak)) \ + ret_type __sys_##name args \ + { \ + Genode::warning(__func__, ": " #name " not implemented"); \ + errno = ENOSYS; \ + return ret_val; \ + } \ + extern "C" __attribute__((weak)) \ + ret_type __libc_##name args \ + { \ + Genode::warning(__func__, ": " #name " not implemented"); \ + errno = ENOSYS; \ + return ret_val; \ + } \ + ret_type _##name args __attribute__((weak, alias("__sys_" #name))); \ + ret_type name args __attribute__((weak, alias("__sys_" #name))); \ + -DUMMY(int , -1, chmod, (const char *, mode_t)) -DUMMY(int , -1, chown, (const char *, uid_t, gid_t)) DUMMY(int , -1, chroot, (const char *)) DUMMY(char *, 0, crypt, (const char *, const char *)) DUMMY(DB * , 0, dbopen, (const char *, int, int, DBTYPE, const void *)) DUMMY(u_int32_t, 0, __default_hash, (const void *, size_t)); -DUMMY(int , 0, fchmod, (int, mode_t)) -DUMMY(int , -1, fchown, (int, uid_t, gid_t)) -DUMMY(int , -1, flock, (int, int)) -DUMMY(pid_t , -1, fork, (void)) DUMMY_SILENT(long , -1, _fpathconf, (int, int)) +DUMMY(pid_t , -1, vfork, (void)) DUMMY(long , -1, fpathconf, (int, int)) DUMMY(int , -1, freebsd7___semctl, (void)) -DUMMY(int , -1, fstatat, (int, const char *, struct stat *, int)) DUMMY(int , -1, getcontext, (ucontext_t *)) DUMMY(gid_t , 0, getegid, (void)) DUMMY(uid_t , 0, geteuid, (void)) -DUMMY(int , -1, getfsstat, (struct statfs *, long, int)) DUMMY(gid_t , 0, getgid, (void)) DUMMY(int , -1, getgroups, (int, gid_t *)) DUMMY(struct hostent *, 0, gethostbyname, (const char *)) +DUMMY(int, -1, getifaddrs, (struct ifaddrs **)) +DUMMY(void, , freeifaddrs, (struct ifaddrs *ifp)) DUMMY(char *, 0, _getlogin, (void)) DUMMY(int , -1, getnameinfo, (const sockaddr *, socklen_t, char *, size_t, char *, size_t, int)) DUMMY_SILENT(pid_t , -1, getpid, (void)) @@ -82,22 +100,24 @@ DUMMY(pid_t , -1, getpgrp, (void)) DUMMY(int , -1, getpriority, (int, int)) DUMMY(int , -1, getrusage, (int, rusage *)) DUMMY(uid_t , 0, getuid, (void)) +DUMMY(int , 1, isatty, (int)) DUMMY(int , -1, kill, (pid_t, int)) DUMMY(int , -1, link, (const char *, const char *)) -DUMMY(int , -1, mkfifo, (const char *, mode_t)) +DUMMY(int , 0, minherit, (void *, size_t, int)) DUMMY(int , -1, mknod, (const char *, mode_t, dev_t)) -DUMMY(int , -1, mprotect, (const void *, size_t, int)) +DUMMY(int , -1, mprotect, (void *, size_t, int)) DUMMY(void *, 0, ___mtctxres, (void)) DUMMY(void *, 0, __nsdefaultsrc, (void)) DUMMY(int , -1, _nsdispatch, (void)) DUMMY(long , -1, pathconf, (const char *, int)) +DUMMY(int , -1, raise, (int)) DUMMY(int , -1, rmdir, (const char *)) DUMMY(void *, 0, sbrk, (intptr_t)) DUMMY(int , -1, sched_setparam, (pid_t, const sched_param *)) DUMMY(int , -1, sched_setscheduler, (pid_t, int, const sched_param *)) DUMMY(int , -1, sched_yield, (void)) DUMMY(int , -1, __semctl, (void)) -DUMMY(int , -1, setcontext, (const ucontext_t *)) +DUMMY(sig_t, SIG_ERR, signal, (int, sig_t)); DUMMY(int , -1, setegid, (uid_t)) DUMMY(int , -1, seteuid, (uid_t)) DUMMY(int , -1, setgid, (gid_t)) @@ -110,23 +130,63 @@ DUMMY(int , -1, setregid, (gid_t, gid_t)) DUMMY(int , -1, setreuid, (uid_t, uid_t)) DUMMY(int , -1, setrlimit, (int, const rlimit *)) DUMMY(pid_t , -1, setsid, (void)) -DUMMY_SILENT(int , -1, _sigaction, (int, const struct sigaction *, struct sigaction *)) -DUMMY(int , -1, sigaction, (int, const struct sigaction *, struct sigaction *)) -DUMMY(int , -1, sigblock, (int)) -DUMMY(int , -1, sigpause, (int)) -DUMMY(int , -1, _sigsuspend, (const sigset_t *)) -DUMMY(int , -1, sigsuspend, (const sigset_t *)) DUMMY(int , -1, socketpair, (int, int, int, int *)) -DUMMY(int , -1, stat, (const char *, struct stat *)) -DUMMY(int , -1, statfs, (const char *, struct statfs *)) -DUMMY(void , , sync, (void)) -DUMMY(int , -1, truncate, (const char *, off_t)) DUMMY_SILENT(mode_t, 0, umask, (mode_t)) DUMMY(int , 0, utimes, (const char *, const timeval *)) -DUMMY(pid_t , -1, vfork, (void)) -DUMMY(pid_t , -1, _wait4, (pid_t, int *, int, struct rusage *)) DUMMY(int, -1, semget, (key_t, int, int)) DUMMY(int, -1, semop, (key_t, int, int)) +__SYS_DUMMY(int, -1, aio_suspend, (const struct aiocb * const[], int, const struct timespec *)); +__SYS_DUMMY(pid_t , -1, fork, (void)) +__SYS_DUMMY(int , -1, getfsstat, (struct statfs *, long, int)) +__SYS_DUMMY(int, -1, kevent, (int, const struct kevent*, int, struct kevent *, int, const struct timespec*)); +__SYS_DUMMY(void , , map_stacks_exec, (void)); +__SYS_DUMMY(int , -1, ptrace, (int, pid_t, caddr_t, int)); +__SYS_DUMMY(ssize_t, -1, sendmsg, (int s, const struct msghdr*, int)); +__SYS_DUMMY(int , -1, setcontext, (const ucontext_t *ucp)); +__SYS_DUMMY(void , , spinlock_stub, (spinlock_t *)); +__SYS_DUMMY(void , , spinlock, (spinlock_t *)); +__SYS_DUMMY(void , , spinunlock, (spinlock_t *)); +__SYS_DUMMY(void , , spinunlock_stub, (spinlock_t *)); +__SYS_DUMMY(int, -1, swapcontext, (ucontext_t *, const ucontext_t *)); +__SYS_DUMMY(int, -1, system, (const char *string)); + + +/***************** + ** File-system ** + *****************/ + +DUMMY(int, 0, fchmod, (int, mode_t)) +DUMMY(int, -1, lockf, (int, int, off_t)) +DUMMY_SILENT(int, 0, posix_fadvise, (int, off_t, off_t, int)) +DUMMY(int, -1, chmod, (const char *, mode_t)) +DUMMY(int, -1, chown, (const char *, uid_t, gid_t)) +DUMMY(int, -1, fchown, (int, uid_t, gid_t)) +DUMMY(int, -1, flock, (int, int)) +DUMMY(int, -1, fstatat, (int, const char *, struct stat *, int)) +DUMMY(int, -1, mkfifo, (const char *, mode_t)) +DUMMY(int, -1, stat, (const char *, struct stat *)) +DUMMY(void, , sync, (void)) +__SYS_DUMMY(int, -11, utimensat, (int, const char *, const struct timespec[2], int)); +__SYS_DUMMY(int, -1, futimens, (int, const struct timespec[2])); +__SYS_DUMMY(int, -1, statfs, (const char *, struct statfs *)) +__SYS_DUMMY(int, -1, truncate, (const char *, off_t)) + + +/*********** + * Signals * + ***********/ + +#include +#include +DUMMY(int, -1, sigblock, (int)) +DUMMY(int, -1, thr_kill2, (pid_t pid, long id, int sig)); + +__SYS_DUMMY(int, -1, sigaction, (int, const struct sigaction *, struct sigaction *)); +__SYS_DUMMY(int, -1, sigsuspend, (const sigset_t *)) +__SYS_DUMMY(int, -1, sigtimedwait, (const sigset_t *, siginfo_t *, const struct timespec *)); +__SYS_DUMMY(int, -1, sigwaitinfo, (const sigset_t *, siginfo_t *)); +__SYS_DUMMY(int, -1, sigwait, (const sigset_t *, int *)); +__SYS_DUMMY(int, -1, thr_kill, (long id, int sig)); void ksem_init(void) @@ -148,5 +208,7 @@ int __attribute__((weak)) madvise(void *addr, size_t length, int advice) return -1; } +const struct res_sym __p_type_syms[] = { }; + } /* extern "C" */ diff --git a/repos/libports/src/lib/libc/file_operations.cc b/repos/libports/src/lib/libc/file_operations.cc index 7ae1ea14a..2ebb6eaba 100644 --- a/repos/libports/src/lib/libc/file_operations.cc +++ b/repos/libports/src/lib/libc/file_operations.cc @@ -8,7 +8,7 @@ */ /* - * Copyright (C) 2010-2017 Genode Labs GmbH + * Copyright (C) 2010-2019 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -23,6 +23,7 @@ #include #include +extern "C" { /* libc includes */ #include #include @@ -31,7 +32,11 @@ #include #include #include +#include #include +#include +#include +} /* libc-internal includes */ #include "libc_file.h" @@ -41,6 +46,13 @@ using namespace Libc; +#define __SYS_(ret_type, name, args, body) \ + extern "C" {\ + ret_type __sys_##name args body \ + ret_type __libc_##name args __attribute__((alias("__sys_" #name))); \ + ret_type _##name args __attribute__((alias("__sys_" #name))); \ + ret_type name args __attribute__((alias("__sys_" #name))); \ + } \ Libc::Mmap_registry *Libc::mmap_registry() { @@ -223,20 +235,17 @@ extern "C" int chdir(const char *path) /** * Close is called incorrectly enough to justify a silent failure */ -extern "C" int _close(int libc_fd) +__SYS_(int, close, (int libc_fd), { Libc::File_descriptor *fd = Libc::file_descriptor_allocator()->find_by_libc_fd(libc_fd); return (!fd || !fd->plugin) ? Libc::Errno(EBADF) : fd->plugin->close(fd); -} +}) -extern "C" int close(int libc_fd) { return _close(libc_fd); } - - -extern "C" int _dup(int libc_fd) +extern "C" int dup(int libc_fd) { File_descriptor *ret_fd; FD_FUNC_WRAPPER_GENERIC(ret_fd =, 0, dup, libc_fd); @@ -244,13 +253,7 @@ extern "C" int _dup(int libc_fd) } -extern "C" int dup(int libc_fd) -{ - return _dup(libc_fd); -} - - -extern "C" int _dup2(int libc_fd, int new_libc_fd) +extern "C" int dup2(int libc_fd, int new_libc_fd) { File_descriptor *fd = libc_fd_to_fd(libc_fd, "dup2"); if (!fd || !fd->plugin) { @@ -276,13 +279,11 @@ extern "C" int _dup2(int libc_fd, int new_libc_fd) } -extern "C" int dup2(int libc_fd, int new_libc_fd) -{ - return _dup2(libc_fd, new_libc_fd); -} +extern "C" __attribute__((alias("dup2"))) +int _dup2(int libc_fd, int new_libc_fd); -extern "C" int _execve(char const *filename, char *const argv[], +extern "C" int execve(char const *filename, char *const argv[], char *const envp[]) { try { @@ -295,11 +296,8 @@ extern "C" int _execve(char const *filename, char *const argv[], } -extern "C" int execve(char const *filename, char *const argv[], - char *const envp[]) -{ - return _execve(filename, argv, envp); -} +extern "C" __attribute__((alias("execve"))) +int _execve(char const *, char *const [], char *const []); extern "C" int fchdir(int libc_fd) @@ -315,7 +313,7 @@ extern "C" int fchdir(int libc_fd) } -extern "C" int fcntl(int libc_fd, int cmd, ...) +__SYS_(int, fcntl, (int libc_fd, int cmd, ...), { va_list ap; int res; @@ -323,24 +321,16 @@ extern "C" int fcntl(int libc_fd, int cmd, ...) FD_FUNC_WRAPPER_GENERIC(res =, INVALID_FD, fcntl, libc_fd, cmd, va_arg(ap, long)); va_end(ap); return res; -} +}) -extern "C" int _fcntl(int libc_fd, int cmd, long arg) { - return fcntl(libc_fd, cmd, arg); } - - -extern "C" int _fstat(int libc_fd, struct stat *buf) { - FD_FUNC_WRAPPER(fstat, libc_fd, buf); } - - -extern "C" int fstat(int libc_fd, struct stat *buf) +__SYS_(int, fstat, (int libc_fd, struct stat *buf), { - return _fstat(libc_fd, buf); -} + FD_FUNC_WRAPPER(fstat, libc_fd, buf); +}) -extern "C" int fstatat(int libc_fd, char const *path, struct stat *buf, int flags) +__SYS_(int, fstatat, (int libc_fd, char const *path, struct stat *buf, int flags), { if (*path == '/') { if (flags & AT_SYMLINK_NOFOLLOW) @@ -366,36 +356,35 @@ extern "C" int fstatat(int libc_fd, char const *path, struct stat *buf, int flag return (flags & AT_SYMLINK_NOFOLLOW) ? lstat(abs_path.base(), buf) : stat(abs_path.base(), buf); -} +}) -extern "C" int _fstatfs(int libc_fd, struct statfs *buf) { - FD_FUNC_WRAPPER(fstatfs, libc_fd, buf); } +__SYS_(int, fstatfs, (int libc_fd, struct statfs *buf), { + FD_FUNC_WRAPPER(fstatfs, libc_fd, buf); }) -extern "C" int fsync(int libc_fd) { - FD_FUNC_WRAPPER(fsync, libc_fd); } +__SYS_(int, fsync, (int libc_fd), { + FD_FUNC_WRAPPER(fsync, libc_fd); }) -extern "C" int ftruncate(int libc_fd, ::off_t length) { - FD_FUNC_WRAPPER(ftruncate, libc_fd, length); } +__SYS_(int, fdatasync, (int libc_fd), { + FD_FUNC_WRAPPER(fsync, libc_fd); }) -extern "C" ssize_t _getdirentries(int libc_fd, char *buf, ::size_t nbytes, ::off_t *basep) { - FD_FUNC_WRAPPER(getdirentries, libc_fd, buf, nbytes, basep); } +__SYS_(int, ftruncate, (int libc_fd, ::off_t length), { + FD_FUNC_WRAPPER(ftruncate, libc_fd, length); }) - -extern "C" int ioctl(int libc_fd, int request, char *argp) { - FD_FUNC_WRAPPER(ioctl, libc_fd, request, argp); } +__SYS_(ssize_t, getdirentries, (int libc_fd, char *buf, ::size_t nbytes, ::off_t *basep), { + FD_FUNC_WRAPPER(getdirentries, libc_fd, buf, nbytes, basep); }) -extern "C" int _ioctl(int libc_fd, int request, char *argp) { - FD_FUNC_WRAPPER(ioctl, libc_fd, request, argp); } +__SYS_(int, ioctl, (int libc_fd, int request, char *argp), { + FD_FUNC_WRAPPER(ioctl, libc_fd, request, argp); }) -extern "C" ::off_t lseek(int libc_fd, ::off_t offset, int whence) { - FD_FUNC_WRAPPER(lseek, libc_fd, offset, whence); } +__SYS_(::off_t, lseek, (int libc_fd, ::off_t offset, int whence), { + FD_FUNC_WRAPPER(lseek, libc_fd, offset, whence); }) extern "C" int lstat(const char *path, struct stat *buf) @@ -422,8 +411,9 @@ extern "C" int mkdir(const char *path, mode_t mode) } -extern "C" void *mmap(void *addr, ::size_t length, int prot, int flags, - int libc_fd, ::off_t offset) +__SYS_(void *, mmap, (void *addr, ::size_t length, + int prot, int flags, + int libc_fd, ::off_t offset), { /* handle requests for anonymous memory */ @@ -449,7 +439,7 @@ extern "C" void *mmap(void *addr, ::size_t length, int prot, int flags, void *start = fd->plugin->mmap(addr, length, prot, flags, fd, offset); mmap_registry()->insert(start, length, fd->plugin); return start; -} +}) extern "C" int munmap(void *start, ::size_t length) @@ -482,7 +472,7 @@ extern "C" int munmap(void *start, ::size_t length) } -extern "C" int msync(void *start, ::size_t len, int flags) +__SYS_(int, msync, (void *start, ::size_t len, int flags), { if (!mmap_registry()->registered(start)) { Genode::warning("munmap: could not lookup plugin for address ", start); @@ -502,11 +492,10 @@ extern "C" int msync(void *start, ::size_t len, int flags) ret = plugin->msync(start, len, flags); return ret; -} +}) - -extern "C" int _open(const char *pathname, int flags, ::mode_t mode) +__SYS_(int, open, (const char *pathname, int flags, ...), { Absolute_path resolved_path; @@ -547,20 +536,45 @@ extern "C" int _open(const char *pathname, int flags, ::mode_t mode) new_fdo->path(resolved_path.base()); return new_fdo->libc_fd; -} +}) -extern "C" int open(const char *pathname, int flags, ...) +__SYS_(int, openat, (int libc_fd, const char *path, int flags, ...), { va_list ap; va_start(ap, flags); - int res = _open(pathname, flags, va_arg(ap, unsigned)); + mode_t mode = va_arg(ap, unsigned); va_end(ap); - return res; -} -extern "C" int pipe(int pipefd[2]) + if (*path == '/') { + return open(path, flags, mode); + } + + Libc::Absolute_path abs_path; + + if (libc_fd == AT_FDCWD) { + abs_path = cwd(); + abs_path.append_element(path); + } else { + Libc::File_descriptor *fd = + Libc::file_descriptor_allocator()->find_by_libc_fd(libc_fd); + if (!fd) { + errno = EBADF; + return -1; + } + abs_path.import(path, fd->fd_path); + } + + return open(abs_path.base(), flags, mode); +}) + + +extern "C" int pipe(int pipefd[2]) { + return pipe2(pipefd, 0); } + + +extern "C" int pipe2(int pipefd[2], int flags) { Plugin *plugin; File_descriptor *pipefdo[2]; @@ -577,6 +591,13 @@ extern "C" int pipe(int pipefd[2]) return -1; } + if (flags & O_NONBLOCK) { + int err = plugin->fcntl(pipefdo[0], F_SETFL, O_NONBLOCK) + | plugin->fcntl(pipefdo[1], F_SETFL, O_NONBLOCK); + if (err != 0) + Genode::warning("pipe plugin does not support O_NONBLOCK"); + } + pipefd[0] = pipefdo[0]->libc_fd; pipefd[1] = pipefdo[1]->libc_fd; @@ -584,16 +605,8 @@ extern "C" int pipe(int pipefd[2]) } -extern "C" ssize_t _read(int libc_fd, void *buf, ::size_t count) -{ - FD_FUNC_WRAPPER(read, libc_fd, buf, count); -} - - -extern "C" ssize_t read(int libc_fd, void *buf, ::size_t count) -{ - return _read(libc_fd, buf, count); -} +__SYS_(ssize_t, read, (int libc_fd, void *buf, ::size_t count), { + FD_FUNC_WRAPPER(read, libc_fd, buf, count); }) extern "C" ssize_t readlink(const char *path, char *buf, ::size_t bufsiz) @@ -679,7 +692,7 @@ extern "C" int unlink(const char *path) } -extern "C" ssize_t _write(int libc_fd, const void *buf, ::size_t count) +__SYS_(ssize_t, write, (int libc_fd, const void *buf, ::size_t count), { int flags = fcntl(libc_fd, F_GETFL); @@ -687,11 +700,7 @@ extern "C" ssize_t _write(int libc_fd, const void *buf, ::size_t count) lseek(libc_fd, 0, SEEK_END); FD_FUNC_WRAPPER(write, libc_fd, buf, count); -} - - -extern "C" ssize_t write(int libc_fd, const void *buf, ::size_t count) { - return _write(libc_fd, buf, count); } +}) extern "C" int __getcwd(char *dst, ::size_t dst_size) diff --git a/repos/libports/src/lib/libc/getrandom.cc b/repos/libports/src/lib/libc/getrandom.cc new file mode 100644 index 000000000..88fa63ffe --- /dev/null +++ b/repos/libports/src/lib/libc/getrandom.cc @@ -0,0 +1,99 @@ +/* + * \brief C-library back end for getrandom/getentropy + * \author Emery Hemingway + * \date 2019-05-07 + */ + +/* + * Copyright (C) 2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +/* Libc includes */ +extern "C" { +#include +#include +#include +#include +#include +} + +/* local includes */ +#include "libc_errno.h" + +/* Genode includes */ +#include +#include +#include + +namespace Libc { extern char const *config_rng(); } + +static +ssize_t read_rng(char *buf, size_t buflen) +{ + static int rng_fd { -1 }; + static bool fallback { false }; + + if (fallback) { + size_t off = 0; + while (off < buflen) { + /* collect 31 bits of random */ + unsigned const nonce = random(); + size_t n = Genode::min(4U, buflen-off); + memcpy(buf+off, &nonce, n); + off += n; + } + return buflen; + } + + if (rng_fd == -1) { + if (!Genode::strcmp(Libc::config_rng(), "")) { + Genode::warning("Libc RNG not configured"); + + /* initialize the FreeBSD random facility */ + srandom(Genode::Trace::timestamp()|1); + fallback = true; + + return read_rng(buf, buflen); + } + + rng_fd = open(Libc::config_rng(), O_RDONLY); + if (rng_fd == -1) { + Genode::error("RNG device ", Genode::Cstring(Libc::config_rng()), " not readable!"); + exit(~0); + } + } + + return read(rng_fd, buf, buflen); +} + + +extern "C" ssize_t __attribute__((weak)) +getrandom(void *buf, size_t buflen, unsigned int flags) +{ + size_t off = 0; + while (off < buflen && off < 256) { + ssize_t n = read_rng((char*)buf+off, buflen-off); + if (n < 1) return Libc::Errno(EIO); + off += n; + } + return off; +} + + +extern "C" int __attribute__((weak)) +getentropy(void *buf, size_t buflen) +{ + /* maximum permitted value for the length argument is 256 */ + if (256 < buflen) return Libc::Errno(EIO); + + size_t off = 0; + while (off < buflen) { + ssize_t n = read_rng((char*)buf+off, buflen-off); + if (n < 1) return Libc::Errno(EIO); + off += n; + } + return 0; +} diff --git a/repos/libports/src/lib/libc/include/spec/arm_64/internal/call_func.h b/repos/libports/src/lib/libc/include/spec/arm_64/internal/call_func.h new file mode 100644 index 000000000..c402a3d26 --- /dev/null +++ b/repos/libports/src/lib/libc/include/spec/arm_64/internal/call_func.h @@ -0,0 +1,35 @@ +/* + * \brief User-level task helpers (arm_64) + * \author Sebastian Sumpf + * \date 2019-05-06 + */ + +/* + * Copyright (C) 2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _INCLUDE__SPEC__ARM_64__INTERNAL__CALL_FUNC_H_ +#define _INCLUDE__SPEC__ARM_64__INTERNAL__CALL_FUNC_H_ + +/* Libc includes */ +#include /* _setjmp() as we don't care about signal state */ + + +/** + * Call function with a new stack + */ +[[noreturn]] inline void call_func(void *sp, void *func, void *arg) +{ + asm volatile ("mov x0, %2;" /* set arg */ + "mov sp, %0;" /* set stack */ + "mov x29, xzr;" /* clear frame pointer */ + "br %1;" /* call func */ + "" + : : "r"(sp), "r"(func), "r"(arg) : "x0"); + __builtin_unreachable(); +} + +#endif /* _INCLUDE__SPEC__ARM_64__INTERNAL__CALL_FUNC_H_ */ diff --git a/repos/libports/src/lib/libc/nanosleep.cc b/repos/libports/src/lib/libc/nanosleep.cc deleted file mode 100644 index d32e30449..000000000 --- a/repos/libports/src/lib/libc/nanosleep.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * \brief C-library back end - * \author Christian Prochaska - * \date 2012-03-20 - */ - -/* - * Copyright (C) 2008-2017 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -/* Libc includes */ -#include - -#include "task.h" - -extern "C" __attribute__((weak)) -int _nanosleep(const struct timespec *req, struct timespec *rem) -{ - Genode::uint64_t sleep_ms = (uint64_t)req->tv_sec*1000 + req->tv_nsec/1000000; - - if (!sleep_ms) return 0; - - struct Check : Libc::Suspend_functor { bool suspend() override { return true; } } check; - do { sleep_ms = Libc::suspend(check, sleep_ms); } while (sleep_ms); - - if (rem) { - rem->tv_sec = 0; - rem->tv_nsec = 0; - } - - return 0; -} - - -extern "C" __attribute__((weak)) -int nanosleep(const struct timespec *req, struct timespec *rem) -{ - return _nanosleep(req, rem); -} diff --git a/repos/libports/src/lib/libc/nolocale.cc b/repos/libports/src/lib/libc/nolocale.cc new file mode 100644 index 000000000..9d43c35ac --- /dev/null +++ b/repos/libports/src/lib/libc/nolocale.cc @@ -0,0 +1,67 @@ +/* + * \brief POSIX locale stubs + * \author Emery Hemingway + * \date 2019-04-18 + */ + +/* + * Copyright (C) 2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +/* Genode includes */ +#include + +extern "C" { + +/* Libc includes */ +#include +#include +#include + + +extern struct xlocale_component __xlocale_global_collate; +extern struct xlocale_component __xlocale_global_ctype; +extern struct xlocale_component __xlocale_global_monetary; +extern struct xlocale_component __xlocale_global_numeric; +extern struct xlocale_component __xlocale_global_time; +extern struct xlocale_component __xlocale_global_messages; +extern struct xlocale_component __xlocale_C_collate; +extern struct xlocale_component __xlocale_C_ctype; + +struct _xlocale __xlocale_global_locale = { + {0}, + { + &__xlocale_global_collate, + &__xlocale_global_ctype, + &__xlocale_global_monetary, + &__xlocale_global_numeric, + &__xlocale_global_time, + &__xlocale_global_messages + }, + 0, + 0, + 1, + 0 +}; + + +locale_t +__get_locale(void) +{ + return &__xlocale_global_locale; +} + + +extern int _none_init(struct xlocale_ctype *l, _RuneLocale *rl); + +char *setlocale(int, const char *) +{ + _none_init((xlocale_ctype*)&__xlocale_global_ctype, + (_RuneLocale*)&_DefaultRuneLocale); + return (char*)"C"; +} + +} diff --git a/repos/libports/src/lib/libc/patches/MB_CUR_MAX.patch b/repos/libports/src/lib/libc/patches/MB_CUR_MAX.patch new file mode 100644 index 000000000..c51d6e52d --- /dev/null +++ b/repos/libports/src/lib/libc/patches/MB_CUR_MAX.patch @@ -0,0 +1,23 @@ +--- src/lib/libc/include/stdlib.h.orig 2019-04-18 13:26:58.781188866 +0200 ++++ src/lib/libc/include/stdlib.h 2019-04-18 13:27:46.100594001 +0200 +@@ -81,7 +81,8 @@ + #endif + extern int __mb_cur_max; + extern int ___mb_cur_max(void); +-#define MB_CUR_MAX ((size_t)___mb_cur_max()) ++/* ASCII only */ ++#define MB_CUR_MAX 1 + + _Noreturn void abort(void); + int abs(int) __pure2; + +--- src/lib/libc/include/xlocale/_stdlib.h.orig 2019-04-18 13:28:52.691756865 +0200 ++++ src/lib/libc/include/xlocale/_stdlib.h 2019-04-18 13:29:13.079500565 +0200 +@@ -57,5 +57,6 @@ + int wctomb_l(char *, wchar_t, locale_t); + + int ___mb_cur_max_l(locale_t); +-#define MB_CUR_MAX_L(x) ((size_t)___mb_cur_max_l(x)) ++/* ASCII only */ ++#define MB_CUR_MAX_L(x) 1 + \ No newline at end of file diff --git a/repos/libports/src/lib/libc/patches/_CurrentRuneLocale.patch b/repos/libports/src/lib/libc/patches/_CurrentRuneLocale.patch new file mode 100644 index 000000000..1420e8464 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/_CurrentRuneLocale.patch @@ -0,0 +1,23 @@ +--- src/lib/libc/include/runetype.h.orig 2019-04-16 11:51:27.954530199 +0200 ++++ src/lib/libc/include/runetype.h 2019-04-16 11:51:53.346901123 +0200 +@@ -88,19 +88,7 @@ + __BEGIN_DECLS + extern const _RuneLocale _DefaultRuneLocale; + extern const _RuneLocale *_CurrentRuneLocale; +-#if defined(__NO_TLS) || defined(__RUNETYPE_INTERNAL) +-extern const _RuneLocale *__getCurrentRuneLocale(void); +-#else +-extern _Thread_local const _RuneLocale *_ThreadRuneLocale; +-static __inline const _RuneLocale *__getCurrentRuneLocale(void) +-{ +- +- if (_ThreadRuneLocale) +- return _ThreadRuneLocale; +- return _CurrentRuneLocale; +-} +-#endif /* __NO_TLS || __RUNETYPE_INTERNAL */ +-#define _CurrentRuneLocale (__getCurrentRuneLocale()) ++#define _CurrentRuneLocale (&_DefaultRuneLocale) + __END_DECLS + + #endif /* !_RUNETYPE_H_ */ diff --git a/repos/libports/src/lib/libc/patches/gdtoa.patch b/repos/libports/src/lib/libc/patches/gdtoa.patch new file mode 100644 index 000000000..d9d6ae358 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/gdtoa.patch @@ -0,0 +1,43 @@ +--- src/lib/libc/contrib/gdtoa/gdtoaimp.h.orig 2019-04-16 11:11:02.420833030 +0200 ++++ src/lib/libc/contrib/gdtoa/gdtoaimp.h 2019-04-16 11:11:17.704278981 +0200 +@@ -506,40 +506,6 @@ + #define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int)) + #endif /* NO_STRING_H */ + +-/* +- * Paranoia: Protect exported symbols, including ones in files we don't +- * compile right now. The standard strtof and strtod survive. +- */ +-#define dtoa __dtoa +-#define gdtoa __gdtoa +-#define freedtoa __freedtoa +-#define strtodg __strtodg +-#define g_ddfmt __g_ddfmt +-#define g_dfmt __g_dfmt +-#define g_ffmt __g_ffmt +-#define g_Qfmt __g_Qfmt +-#define g_xfmt __g_xfmt +-#define g_xLfmt __g_xLfmt +-#define strtoId __strtoId +-#define strtoIdd __strtoIdd +-#define strtoIf __strtoIf +-#define strtoIQ __strtoIQ +-#define strtoIx __strtoIx +-#define strtoIxL __strtoIxL +-#define strtord_l __strtord_l +-#define strtordd __strtordd +-#define strtorf __strtorf +-#define strtorQ_l __strtorQ_l +-#define strtorx_l __strtorx_l +-#define strtorxL __strtorxL +-#define strtodI __strtodI +-#define strtopd __strtopd +-#define strtopdd __strtopdd +-#define strtopf __strtopf +-#define strtopQ __strtopQ +-#define strtopx __strtopx +-#define strtopxL __strtopxL +- + /* Protect gdtoa-internal symbols */ + #define Balloc __Balloc_D2A + #define Bfree __Bfree_D2A diff --git a/repos/libports/src/lib/libc/patches/malloc_c.patch b/repos/libports/src/lib/libc/patches/malloc_c.patch deleted file mode 100644 index c612f7064..000000000 --- a/repos/libports/src/lib/libc/patches/malloc_c.patch +++ /dev/null @@ -1,10 +0,0 @@ -+++ src/lib/libc/lib/libc/stdlib/malloc.c -@@ -153,7 +153,7 @@ - * unnecessary, but we are burdened by history and the lack of resource limits - * for anonymous mapped memory. - */ --#define MALLOC_DSS -+//#define MALLOC_DSS - - #include - __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.179 2008/09/10 14:27:34 jasone Exp $"); diff --git a/repos/libports/src/lib/libc/patches/math_private.patch b/repos/libports/src/lib/libc/patches/math_private.patch deleted file mode 100644 index b7bb4455c..000000000 --- a/repos/libports/src/lib/libc/patches/math_private.patch +++ /dev/null @@ -1,17 +0,0 @@ -+++ src/lib/libc/lib/msun/src/math_private.h -@@ -225,6 +225,7 @@ - - /* Asm versions of some functions. */ - -+#if 0 /* "Y" constraint not supported by gcc 4.3 */ - #ifdef __amd64__ - static __inline int - irint(double x) -@@ -236,6 +237,7 @@ - } - #define HAVE_EFFICIENT_IRINT - #endif -+#endif - - #ifdef __i386__ - static __inline int diff --git a/repos/libports/src/lib/libc/patches/max_align_t.patch b/repos/libports/src/lib/libc/patches/max_align_t.patch deleted file mode 100644 index 029b95ba5..000000000 --- a/repos/libports/src/lib/libc/patches/max_align_t.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 689bb2db9dbb8fa247c030735dbd6e4f861d0e60 Mon Sep 17 00:00:00 2001 -From: jhb -Date: Fri, 21 Oct 2016 23:50:02 +0000 -Subject: [PATCH] Define max_align_t for C11. - -libc++'s stddef.h includes an existing definition of max_align_t for -C++11, but it is only defined for C++, not for C. In addition, GCC and -clang both define an alternate version of max_align_t that uses a -union of multiple types rather than a plain long double as in libc++. -This adds a __max_align_t to that matches the GCC and -clang definition that is mapped to max_align_t in . - -PR: 210890 -Reviewed by: dim -MFC after: 1 month -Differential Revision: https://reviews.freebsd.org/D8194 - -cproc: slightly modified for Genode (_Alignof -> __alignof__) - ---- - include/stddef.h | 8 ++++++++ - sys/sys/_types.h | 5 +++++ - 2 files changed, 13 insertions(+) - -diff --git a/include/stddef.h b/include/stddef.h -index 7898da2..7f2d2f0c 100644 ---- src/lib/libc/include/stddef.h -+++ src/lib/libc/include/stddef.h -@@ -62,6 +62,14 @@ typedef ___wchar_t wchar_t; - #endif - #endif - -+#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L -+#ifndef __CLANG_MAX_ALIGN_T_DEFINED -+typedef __max_align_t max_align_t; -+#define __CLANG_MAX_ALIGN_T_DEFINED -+#define __GCC_MAX_ALIGN_T -+#endif -+#endif -+ - #define offsetof(type, member) __offsetof(type, member) - - #endif /* _STDDEF_H_ */ -diff --git a/sys/sys/_types.h b/sys/sys/_types.h -index ecc1c7e..8736651 100644 ---- src/lib/libc/sys/sys/_types.h -+++ src/lib/libc/sys/sys/_types.h -@@ -100,6 +100,11 @@ typedef __uint_least32_t __char32_t; - #define _CHAR32_T_DECLARED - #endif - -+typedef struct { -+ long long __max_align1 __aligned(__alignof__(long long)); -+ long double __max_align2 __aligned(__alignof__(long double)); -+} __max_align_t; -+ - typedef __uint32_t __dev_t; /* device number */ - - typedef __uint32_t __fixpt_t; /* fixed point number */ diff --git a/repos/libports/src/lib/libc/patches/nis_x.patch b/repos/libports/src/lib/libc/patches/nis_x.patch deleted file mode 100644 index 93d4ca2c7..000000000 --- a/repos/libports/src/lib/libc/patches/nis_x.patch +++ /dev/null @@ -1,26 +0,0 @@ -+++ src/lib/libc/include/rpcsvc/nis.x -@@ -399,10 +399,7 @@ - %#define OARIGHTS(d, n) (((d)->do_armask.do_armask_val+n)->oa_rights) - %#define WORLD_DEFAULT (NIS_READ_ACC) - %#define GROUP_DEFAULT (NIS_READ_ACC << 8) --%#define OWNER_DEFAULT ((NIS_READ_ACC +\ -- NIS_MODIFY_ACC +\ -- NIS_CREATE_ACC +\ -- NIS_DESTROY_ACC) << 16) -+%#define OWNER_DEFAULT ((NIS_READ_ACC + NIS_MODIFY_ACC + NIS_CREATE_ACC + NIS_DESTROY_ACC) << 16) - %#define DEFAULT_RIGHTS (WORLD_DEFAULT | GROUP_DEFAULT | OWNER_DEFAULT) - % - %/* Result manipulation defines ... */ -@@ -431,10 +428,8 @@ - % * these definitions they take an nis_object *, and an int and return - % * a u_char * for Value, and an int for length. - % */ --%#define ENTRY_VAL(obj, col) \ -- (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val --%#define ENTRY_LEN(obj, col) \ -- (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len -+%#define ENTRY_VAL(obj, col) (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val -+%#define ENTRY_LEN(obj, col) (obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len - % - %#ifdef __cplusplus - %} diff --git a/repos/libports/src/lib/libc/patches/printfcommon.patch b/repos/libports/src/lib/libc/patches/printfcommon.patch new file mode 100644 index 000000000..301d5afd9 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/printfcommon.patch @@ -0,0 +1,12 @@ +--- src/lib/libc/lib/libc/stdio/printfcommon.h.orig 2019-04-16 12:35:21.549592905 +0200 ++++ src/lib/libc/lib/libc/stdio/printfcommon.h 2019-04-16 12:35:34.163738398 +0200 +@@ -47,9 +47,6 @@ + + #ifndef NO_FLOATING_POINT + +-#define dtoa __dtoa +-#define freedtoa __freedtoa +- + #include + #include + #include "floatio.h" diff --git a/repos/libports/src/lib/libc/patches/pthread_not_implemented.patch b/repos/libports/src/lib/libc/patches/pthread_not_implemented.patch deleted file mode 100644 index 6aef198b3..000000000 --- a/repos/libports/src/lib/libc/patches/pthread_not_implemented.patch +++ /dev/null @@ -1,76 +0,0 @@ -Print 'not implemented' message in pthread stubs - -From: Christian Prochaska - - ---- -+++ src/lib/libc/lib/libc/gen/_pthread_stubs.c -@@ -33,6 +33,8 @@ __FBSDID("$FreeBSD$"); - - #include "libc_private.h" - -+ -+ - /* - * Weak symbols: All libc internal usage of these functions should - * use the weak symbol versions (_pthread_XXX). If libpthread is -@@ -138,12 +140,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { - typedef ret (*FUNC_TYPE(name))(void); \ - static ret FUNC_EXP(name)(void) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ - return (func()); \ - } \ - static ret FUNC_INT(name)(void) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ - return (func()); \ -@@ -157,12 +161,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { - typedef ret (*FUNC_TYPE(name))(p0_type); \ - static ret FUNC_EXP(name)(p0_type p0) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ - return (func(p0)); \ - } \ - static ret FUNC_INT(name)(p0_type p0) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ - return (func(p0)); \ -@@ -176,12 +182,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { - typedef ret (*FUNC_TYPE(name))(p0_type, p1_type); \ - static ret FUNC_EXP(name)(p0_type p0, p1_type p1) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ - return (func(p0, p1)); \ - } \ - static ret FUNC_INT(name)(p0_type p0, p1_type p1) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ - return (func(p0, p1)); \ -@@ -195,12 +203,14 @@ pthread_func_entry_t __thr_jtable[PJT_MAX] = { - typedef ret (*FUNC_TYPE(name))(p0_type, p1_type, p2_type); \ - static ret FUNC_EXP(name)(p0_type p0, p1_type p1, p2_type p2) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ - return (func(p0, p1, p2)); \ - } \ - static ret FUNC_INT(name)(p0_type p0, p1_type p1, p2_type p2) \ - { \ -+ puts(#name " called, not implemented"); \ - FUNC_TYPE(name) func; \ - func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ - return (func(p0, p1, p2)); \ diff --git a/repos/libports/src/lib/libc/patches/res_init_c.patch b/repos/libports/src/lib/libc/patches/res_init_c.patch index 03622278f..4eb8d7b4c 100644 --- a/repos/libports/src/lib/libc/patches/res_init_c.patch +++ b/repos/libports/src/lib/libc/patches/res_init_c.patch @@ -1,5 +1,26 @@ -+++ src/lib/libc/lib/libc/resolv/res_init.c -@@ -152,6 +152,10 @@ +--- src/lib/libc/lib/libc/resolv/res_init.c.old 2019-05-07 11:26:07.854155106 +0200 ++++ src/lib/libc/lib/libc/resolv/res_init.c 2019-05-07 11:26:18.499341340 +0200 +@@ -93,18 +93,7 @@ + #include + #include + +-#ifndef HAVE_MD5 +-# include "../dst/md5.h" +-#else +-# ifdef SOLARIS2 +-# include +-# elif _LIBC +-# include +-# endif +-#endif +-#ifndef _MD5_H_ +-# define _MD5_H_ 1 /*%< make sure we do not include rsaref md5.h file */ +-#endif ++#include + + #include "un-namespace.h" + +@@ -169,6 +158,10 @@ return (__res_vinit(statp, 0)); } @@ -7,15 +28,21 @@ +extern char const *libc_resolv_path; + + - /*% This function has to be reachable by res_data.c but not publically. */ + /*% This function has to be reachable by res_data.c but not publicly. */ int __res_vinit(res_state statp, int preinit) { -@@ -304,8 +308,47 @@ +@@ -325,7 +318,7 @@ line[sizeof(name) - 1] == '\t')) nserv = 0; -- if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { -+ if ((fp = fopen(libc_resolv_path, "r")) != NULL) { +- if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) { ++ if ((fp = fopen(libc_resolv_path, "re")) != NULL) { + struct stat sb; + struct timespec now; + +@@ -339,6 +332,45 @@ + } + /* read the config file */ +#if 1 + if (fgets(buf, sizeof(buf), fp) != NULL) { @@ -59,7 +86,7 @@ while (fgets(buf, sizeof(buf), fp) != NULL) { /* skip comments */ if (*buf == ';' || *buf == '#') -@@ -502,6 +545,7 @@ +@@ -536,6 +568,7 @@ continue; } } @@ -67,3 +94,32 @@ if (nserv > 0) statp->nscount = nserv; #ifdef RESOLVSORT +@@ -777,25 +810,9 @@ + + u_int + res_nrandomid(res_state statp) { +- struct timeval now; +- u_int16_t u16; +- MD5_CTX ctx; +- u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd; +- +- gettimeofday(&now, NULL); +- u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec); +- memcpy(rnd + 14, &u16, 2); +-#ifndef HAVE_MD5 +- MD5_Init(&ctx); +- MD5_Update(&ctx, rnd, 16); +- MD5_Final(rnd, &ctx); +-#else +- MD5Init(&ctx); +- MD5Update(&ctx, rnd, 16); +- MD5Final(rnd, &ctx); +-#endif +- memcpy(&u16, rnd + 14, 2); +- return ((u_int) u16); ++ u_int val; ++ getrandom(&val, sizeof(val), 0); ++ return val; + } + + /*% diff --git a/repos/libports/src/lib/libc/patches/res_send_c.patch b/repos/libports/src/lib/libc/patches/res_send_c.patch deleted file mode 100644 index 38f65e765..000000000 --- a/repos/libports/src/lib/libc/patches/res_send_c.patch +++ /dev/null @@ -1,32 +0,0 @@ -+++ src/lib/libc/lib/libc/include/port_after.h -@@ -4,7 +4,7 @@ - #define _PORT_AFTER_H_ - - #define HAVE_SA_LEN 1 --#define HAS_INET6_STRUCTS 1 -+//#define HAS_INET6_STRUCTS 1 - #define HAVE_SIN6_SCOPE_ID 1 - #define HAVE_TIME_R 1 - -+++ src/lib/libc/lib/libc/include/port_before.h -@@ -4,8 +4,8 @@ - #define _PORT_BEFORE_H_ - - #define _LIBC 1 --#define DO_PTHREADS 1 --#define USE_KQUEUE 1 -+//#define DO_PTHREADS 1 -+//#define USE_KQUEUE 1 - - #define ISC_SOCKLEN_T socklen_t - #define ISC_FORMAT_PRINTF(fmt, args) \ -+++ src/lib/libc/lib/libc/resolv/res_send.c -@@ -78,7 +78,7 @@ - - #include "port_before.h" - #ifndef USE_KQUEUE --#include "fd_setsize.h" -+//#include "fd_setsize.h" - #endif - - #include "namespace.h" diff --git a/repos/libports/src/lib/libc/patches/runetype.patch b/repos/libports/src/lib/libc/patches/runetype.patch new file mode 100644 index 000000000..1e8dbec99 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/runetype.patch @@ -0,0 +1,15 @@ +--- src/lib/libc/lib/libc/locale/runetype.c.orig 2019-04-18 15:12:08.961502991 +0200 ++++ src/lib/libc/lib/libc/locale/runetype.c 2019-04-18 15:13:44.287945177 +0200 +@@ -82,10 +82,9 @@ + + int ___mb_cur_max(void) + { +- return XLOCALE_CTYPE(__get_locale())->__mb_cur_max; ++ return MB_CUR_MAX; + } + int ___mb_cur_max_l(locale_t locale) + { +- FIX_LOCALE(locale); +- return XLOCALE_CTYPE(locale)->__mb_cur_max; ++ return MB_CUR_MAX; + } diff --git a/repos/libports/src/lib/libc/patches/semaphore.patch b/repos/libports/src/lib/libc/patches/semaphore.patch new file mode 100644 index 000000000..495f0801e --- /dev/null +++ b/repos/libports/src/lib/libc/patches/semaphore.patch @@ -0,0 +1,11 @@ +--- src/lib/libc/include/semaphore.h 2019-04-09 14:12:29.619185765 +0200 ++++ src/lib/libc/include/semaphore.h.new 2019-04-09 14:31:35.913650094 +0200 +@@ -46,7 +46,7 @@ + __uint32_t _padding; /* Preserve structure size */ + }; + +-typedef struct _sem sem_t; ++typedef struct sem* sem_t; + + #define SEM_FAILED ((sem_t *)0) + #define SEM_VALUE_MAX __INT_MAX diff --git a/repos/libports/src/lib/libc/patches/setlocale.patch b/repos/libports/src/lib/libc/patches/setlocale.patch new file mode 100644 index 000000000..7f8e36531 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/setlocale.patch @@ -0,0 +1,11 @@ +--- src/lib/libc/lib/libc/locale/setlocale.h.orig 2019-04-18 13:46:58.382346791 +0200 ++++ src/lib/libc/lib/libc/locale/setlocale.h 2019-04-18 13:47:18.967789876 +0200 +@@ -34,7 +34,7 @@ + #define ENCODING_LEN 31 + #define CATEGORY_LEN 11 + +-extern char *_PathLocale; ++#define _PathLocale "/dev/null" + + int __detect_path_locale(void); + int __wrap_setrunelocale(const char *); diff --git a/repos/libports/src/lib/libc/patches/thread_local.patch b/repos/libports/src/lib/libc/patches/thread_local.patch new file mode 100644 index 000000000..89fa01b06 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/thread_local.patch @@ -0,0 +1,23 @@ +--- src/lib/libc/sys/sys/cdefs.h.orig 2019-04-16 10:50:14.382883576 +0200 ++++ src/lib/libc/sys/sys/cdefs.h 2019-04-16 10:50:34.008444965 +0200 +@@ -298,20 +298,6 @@ + #endif + #endif + +-#if !__has_extension(c_thread_local) +-/* +- * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode +- * without actually supporting the thread_local keyword. Don't check for +- * the presence of C++11 when defining _Thread_local. +- */ +-#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ +- __has_extension(cxx_thread_local) +-#define _Thread_local thread_local +-#else +-#define _Thread_local __thread +-#endif +-#endif +- + #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ + + /* diff --git a/repos/libports/src/lib/libc/patches/types.patch b/repos/libports/src/lib/libc/patches/types.patch index 4df54ec1a..e401f6e64 100644 --- a/repos/libports/src/lib/libc/patches/types.patch +++ b/repos/libports/src/lib/libc/patches/types.patch @@ -1,21 +1,10 @@ -+++ src/lib/libc/sys/i386/include/_types.h -@@ -89,11 +89,11 @@ 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 __int32_t __ptrdiff_t; /* ptr1 - ptr2 */ -+typedef __PTRDIFF_TYPE__ __ptrdiff_t; /* ptr1 - ptr2 */ - typedef __int32_t __register_t; - typedef __int32_t __segsz_t; /* segment size (in pages) */ --typedef __uint32_t __size_t; /* sizeof() */ --typedef __int32_t __ssize_t; /* byte count or error */ -+typedef __SIZE_TYPE__ __size_t; /* sizeof() */ -+typedef __PTRDIFF_TYPE__ __ssize_t; /* byte count or error */ - typedef __int32_t __time_t; /* time()... */ - typedef __uint32_t __uintfptr_t; - typedef __uint64_t __uintmax_t; +Use the unified size types provided by the Genode tool chain. + +diff --git src/lib/libc/sys/arm/include/_types.h src/lib/libc/sys/arm/include/_types.h +index 3012f97..3ec5a24 100644 +--- src/lib/libc/sys/arm/include/_types.h +++ src/lib/libc/sys/arm/include/_types.h -@@ -82,11 +82,11 @@ +@@ -85,11 +85,11 @@ typedef __int8_t __int_least8_t; typedef __int16_t __int_least16_t; typedef __int32_t __int_least32_t; typedef __int64_t __int_least64_t; @@ -30,3 +19,34 @@ typedef __int64_t __time_t; /* time()... */ typedef __uint32_t __uintfptr_t; typedef __uint64_t __uintmax_t; +diff --git src/lib/libc/sys/x86/include/_types.h src/lib/libc/sys/x86/include/_types.h +index 07893c6..abd2ea4 100644 +--- src/lib/libc/sys/x86/include/_types.h ++++ src/lib/libc/sys/x86/include/_types.h +@@ -100,20 +100,20 @@ typedef __int16_t __int_least16_t; + typedef __int32_t __int_least32_t; + typedef __int64_t __int_least64_t; + #ifdef __LP64__ +-typedef __int64_t __ptrdiff_t; /* ptr1 - ptr2 */ ++typedef __PTRDIFF_TYPE__ __ptrdiff_t; /* ptr1 - ptr2 */ + typedef __int64_t __register_t; + typedef __int64_t __segsz_t; /* segment size (in pages) */ +-typedef __uint64_t __size_t; /* sizeof() */ +-typedef __int64_t __ssize_t; /* byte count or error */ ++typedef __SIZE_TYPE__ __size_t; /* sizeof() */ ++typedef __PTRDIFF_TYPE__ __ssize_t; /* byte count or error */ + typedef __int64_t __time_t; /* time()... */ + typedef __uint64_t __uintfptr_t; + typedef __uint64_t __uintptr_t; + #else +-typedef __int32_t __ptrdiff_t; ++typedef __PTRDIFF_TYPE__ __ptrdiff_t; + typedef __int32_t __register_t; + typedef __int32_t __segsz_t; +-typedef __uint32_t __size_t; +-typedef __int32_t __ssize_t; ++typedef __SIZE_TYPE__ __size_t; ++typedef __PTRDIFF_TYPE__ __ssize_t; + typedef __int32_t __time_t; + typedef __uint32_t __uintfptr_t; + typedef __uint32_t __uintptr_t; diff --git a/repos/libports/src/lib/libc/patches/xlocale.patch b/repos/libports/src/lib/libc/patches/xlocale.patch new file mode 100644 index 000000000..97538757f --- /dev/null +++ b/repos/libports/src/lib/libc/patches/xlocale.patch @@ -0,0 +1,35 @@ +--- src/lib/libc/lib/libc/locale/setrunelocale.c ++++ src/lib/libc/lib/libc/locale/setrunelocale.c +@@ -60,7 +60,7 @@ extern _RuneLocale const *_CurrentRuneLocale; + /* + * A cached version of the runes for this thread. Used by ctype.h + */ +-_Thread_local const _RuneLocale *_ThreadRuneLocale; ++const _RuneLocale *_ThreadRuneLocale; + #endif + + extern int __mb_sb_limit; + +--- src/lib/libc/lib/libc/locale/xlocale.c ++++ src/lib/libc/lib/libc/locale/xlocale.c +@@ -59,7 +59,7 @@ extern struct xlocale_component __xlocale_C_ctype; + /* + * The locale for this thread. + */ +-_Thread_local locale_t __thread_locale; ++locale_t __thread_locale; + #endif + /* + * Flag indicating that one or more per-thread locales exist. + +--- src/lib/libc/lib/libc/locale/xlocale_private.h ++++ src/lib/libc/lib/libc/locale/xlocale_private.h +@@ -213,7 +213,7 @@ extern int __has_thread_locale; + * The per-thread locale. Avoids the need to use pthread lookup functions when + * getting the per-thread locale. + */ +-extern _Thread_local locale_t __thread_locale; ++extern locale_t __thread_locale; + + /** + * Returns the current locale for this thread, or the global locale if none is diff --git a/repos/libports/src/lib/libc/patches/xlocale_private.patch b/repos/libports/src/lib/libc/patches/xlocale_private.patch new file mode 100644 index 000000000..b35570469 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/xlocale_private.patch @@ -0,0 +1,59 @@ +--- src/lib/libc/lib/libc/locale/xlocale_private.h.orig 2019-04-18 14:31:34.331373088 +0200 ++++ src/lib/libc/lib/libc/locale/xlocale_private.h 2019-04-18 14:31:57.418620988 +0200 +@@ -166,24 +166,16 @@ + __attribute__((unused)) static void* + xlocale_retain(void *val) + { +- struct xlocale_refcounted *obj = val; +- atomic_add_long(&(obj->retain_count), 1); + return (val); + } ++ + /** + * Decrements the reference count of a reference-counted structure, freeing it + * if this is the last reference, calling its destructor if it has one. + */ + __attribute__((unused)) static void + xlocale_release(void *val) +-{ +- struct xlocale_refcounted *obj = val; +- long count; +- +- count = atomic_fetchadd_long(&(obj->retain_count), -1) - 1; +- if (count < 0 && obj->destructor != NULL) +- obj->destructor(obj); +-} ++{ } + + /** + * Load functions. Each takes the name of a locale and a pointer to the data +@@ -223,27 +215,15 @@ + */ + static inline locale_t __get_locale(void) + { +- +- if (!__has_thread_locale) { +- return (&__xlocale_global_locale); +- } +- return (__thread_locale ? __thread_locale : &__xlocale_global_locale); ++ return (&__xlocale_global_locale); + } + #else + locale_t __get_locale(void); + #endif + +-/** +- * Two magic values are allowed for locale_t objects. NULL and -1. This +- * function maps those to the real locales that they represent. +- */ + static inline locale_t get_real_locale(locale_t locale) + { +- switch ((intptr_t)locale) { +- case 0: return (&__xlocale_C_locale); +- case -1: return (&__xlocale_global_locale); +- default: return (locale); +- } ++ return &__xlocale_global_locale; + } + + /** diff --git a/repos/libports/src/lib/libc/patches/xprintf_float.patch b/repos/libports/src/lib/libc/patches/xprintf_float.patch new file mode 100644 index 000000000..f44cb7a96 --- /dev/null +++ b/repos/libports/src/lib/libc/patches/xprintf_float.patch @@ -0,0 +1,12 @@ +--- src/lib/libc/lib/libc/stdio/xprintf_float.c.orig 2019-04-16 12:34:20.167688219 +0200 ++++ src/lib/libc/lib/libc/stdio/xprintf_float.c 2019-04-16 12:34:01.986830677 +0200 +@@ -42,9 +42,6 @@ + #include + #include + +-#define dtoa __dtoa +-#define freedtoa __freedtoa +- + #include + #include + #include "gdtoa.h" diff --git a/repos/libports/src/lib/libc/plugin.cc b/repos/libports/src/lib/libc/plugin.cc index 5f89f91f9..4f3a84b5d 100644 --- a/repos/libports/src/lib/libc/plugin.cc +++ b/repos/libports/src/lib/libc/plugin.cc @@ -19,10 +19,19 @@ #include #include +/* local includes */ +#include "task.h" + using namespace Genode; using namespace Libc; +void Plugin::resume_all() +{ + Libc::resume_all(); +} + + Plugin::Plugin(int priority) : _priority(priority) { @@ -73,6 +82,12 @@ bool Plugin::supports_pipe() } +bool Plugin::supports_poll() +{ + return false; +} + + bool Plugin::supports_readlink(const char *path, char *buf, ::size_t bufsiz) { return false; @@ -189,6 +204,7 @@ DUMMY(void *, (void *)(-1), mmap, (void *addr, ::size_t length, int prot, int fl DUMMY(int, -1, munmap, (void *, ::size_t)); DUMMY(int, -1, msync, (void *addr, ::size_t len, int flags)); DUMMY(int, -1, pipe, (File_descriptor*[2])); +DUMMY(bool, 0, poll, (File_descriptor &, struct pollfd &)); DUMMY(ssize_t, -1, readlink, (const char *, char *, ::size_t)); DUMMY(int, -1, rename, (const char *, const char *)); DUMMY(int, -1, rmdir, (const char*)); diff --git a/repos/libports/src/lib/libc/poll.cc b/repos/libports/src/lib/libc/poll.cc index b23249d4b..58e5e6e4d 100644 --- a/repos/libports/src/lib/libc/poll.cc +++ b/repos/libports/src/lib/libc/poll.cc @@ -1,14 +1,12 @@ /* * \brief poll() implementation * \author Josef Soentgen + * \author Emery Hemingway * \date 2012-07-12 - * - * this 'poll()' implementation is based on OpenSSHp's and - * uses our 'select()' function internally. */ /* - * Copyright (C) 2010-2017 Genode Labs GmbH + * Copyright (C) 2010-2019 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -17,97 +15,99 @@ /* Libc includes */ #include #include -#include #include -#include -using namespace Libc; +/* internal includes */ +#include "libc_errno.h" +#include "libc_file.h" +#include "task.h" -/** - * The poll function was taken from OpenSSH portable (bsd-poll.c) and adepted - * to better fit within Genode's libc. - * - * Copyright (c) 2004, 2005, 2007 Darren Tucker (dtucker at zip com au). - * - * 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. - */ -extern "C" int -__attribute__((weak)) -poll(struct pollfd fds[], nfds_t nfds, int timeout) +extern "C" __attribute__((weak)) +int poll(struct pollfd fds[], nfds_t nfds, int timeout_ms) { - nfds_t i; - int ret, fd, maxfd = 0; - fd_set readfds, writefds, exceptfds; - struct timeval tv, *tvp = NULL; + using namespace Libc; - for (i = 0; i < nfds; i++) { - fd = fds[i].fd; - if (fd >= (int)FD_SETSIZE) { - /*errno = EINVAL;*/ - return -1; + if (!fds || nfds == 0) return Errno(EINVAL); + + struct Check : Libc::Suspend_functor + { + pollfd *_fds; + nfds_t const _nfds; + + int nready { 0 }; + + Check(struct pollfd fds[], nfds_t nfds) + : _fds(fds), _nfds(nfds) { } + + bool suspend() override + { + bool polling = false; + + for (unsigned i = 0; i < _nfds; ++i) + { + pollfd &pfd = _fds[i]; + File_descriptor *libc_fd = libc_fd_to_fd(pfd.fd, "poll"); + if (!libc_fd) { + pfd.revents |= POLLNVAL; + ++nready; + continue; + } + + if (!libc_fd->plugin || !libc_fd->plugin->supports_poll()) { + Genode::warning("poll not supported for file descriptor ", pfd.fd); + continue; + } + + nready += libc_fd->plugin->poll(*libc_fd, pfd); + polling = true; + } + + return (polling && nready == 0); } - maxfd = MAX(maxfd, fd); + + } check (fds, nfds); + + check.suspend(); + + if (timeout_ms == 0) { + return check.nready; } - /* populate event bit vectors for the events we're interested in */ - - FD_ZERO(&readfds); - FD_ZERO(&writefds); - FD_ZERO(&exceptfds); - - for (i = 0; i < nfds; i++) { - fd = fds[i].fd; - if (fd == -1) - continue; - if (fds[i].events & POLLIN) { - FD_SET(fd, &readfds); - FD_SET(fd, &exceptfds); + if (timeout_ms == -1) { + while (check.nready == 0) { + Libc::suspend(check, 0); } - if (fds[i].events & POLLOUT) { - FD_SET(fd, &writefds); - FD_SET(fd, &exceptfds); + } else { + Genode::uint64_t remaining_ms = timeout_ms; + while (check.nready == 0 && remaining_ms > 0) { + remaining_ms = Libc::suspend(check, remaining_ms); } } - /* poll timeout is msec, select is timeval (sec + usec) */ - if (timeout >= 0) { - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - tvp = &tv; - } - ret = select(maxfd + 1, &readfds, &writefds, &exceptfds, tvp); - /*saved_errno = errno;*/ - /* scan through select results and set poll() flags */ - for (i = 0; i < nfds; i++) { - fd = fds[i].fd; - fds[i].revents = 0; - if (fd == -1) - continue; - if ((fds[i].events & POLLIN) && FD_ISSET(fd, &readfds)) { - fds[i].revents |= POLLIN; - } - if ((fds[i].events & POLLOUT) && FD_ISSET(fd, &writefds)) { - fds[i].revents |= POLLOUT; - } - if (FD_ISSET(fd, &exceptfds)) { - fds[i].revents |= POLLERR; - } - } - - /* - if (ret == -1) - errno = saved_errno; - */ - return ret; + return check.nready; } + + +extern "C" __attribute__((weak, alias("poll"))) +int __sys_poll(struct pollfd fds[], nfds_t nfds, int timeout_ms); + + +extern "C" __attribute__((weak, alias("poll"))) +int _poll(struct pollfd fds[], nfds_t nfds, int timeout_ms); + + +extern "C" __attribute__((weak)) +int ppoll(struct pollfd fds[], nfds_t nfds, + const struct timespec *timeout, + const sigset_t*) +{ + int timeout_ms = timeout->tv_sec * 1000 + timeout->tv_nsec / 1000; + return poll(fds, nfds, timeout_ms); +} + + +extern "C" __attribute__((weak, alias("ppoll"))) +int __sys_ppoll(struct pollfd fds[], nfds_t nfds, + const struct timespec *timeout, + const sigset_t*); diff --git a/repos/libports/src/lib/libc/pread_pwrite.cc b/repos/libports/src/lib/libc/pread_pwrite.cc index 72502e7a9..4dac3d6f7 100644 --- a/repos/libports/src/lib/libc/pread_pwrite.cc +++ b/repos/libports/src/lib/libc/pread_pwrite.cc @@ -70,8 +70,14 @@ extern "C" ssize_t pread(int fd, void *buf, ::size_t count, ::off_t offset) return pread_pwrite_impl(Read(), fd, buf, count, offset); } +extern "C" __attribute__((alias("pread"))) +ssize_t __sys_pread(int fd, void *buf, ::size_t count, ::off_t offset); + extern "C" ssize_t pwrite(int fd, const void *buf, ::size_t count, ::off_t offset) { return pread_pwrite_impl(Write(), fd, buf, count, offset); } + +extern "C" __attribute__((alias("pwrite"))) +ssize_t __sys_pwrite(int fd, const void *buf, ::size_t count, ::off_t offset); diff --git a/repos/libports/src/lib/libc/readv_writev.cc b/repos/libports/src/lib/libc/readv_writev.cc index 7e2c5a2ae..7555062bd 100644 --- a/repos/libports/src/lib/libc/readv_writev.cc +++ b/repos/libports/src/lib/libc/readv_writev.cc @@ -93,25 +93,25 @@ static ssize_t readv_writev_impl(Rw_func rw_func, int fd, const struct iovec *io } -extern "C" ssize_t _readv(int fd, const struct iovec *iov, int iovcnt) +extern "C" ssize_t readv(int fd, const struct iovec *iov, int iovcnt) { return readv_writev_impl(Read(), fd, iov, iovcnt); } +extern "C" __attribute__((alias("readv"))) +ssize_t __sys_readv(int fd, const struct iovec *iov, int iovcnt); -extern "C" ssize_t readv(int fd, const struct iovec *iov, int iovcnt) -{ - return _readv(fd, iov, iovcnt); -} - - -extern "C" ssize_t _writev(int fd, const struct iovec *iov, int iovcnt) -{ - return readv_writev_impl(Write(), fd, iov, iovcnt); -} +extern "C" __attribute__((alias("readv"))) +ssize_t _readv(int fd, const struct iovec *iov, int iovcnt); extern "C" ssize_t writev(int fd, const struct iovec *iov, int iovcnt) { - return _writev(fd, iov, iovcnt); + return readv_writev_impl(Write(), fd, iov, iovcnt); } + +extern "C" __attribute__((alias("writev"))) +ssize_t __sys_writev(int fd, const struct iovec *iov, int iovcnt); + +extern "C" __attribute__((alias("writev"))) +ssize_t _writev(int fd, const struct iovec *iov, int iovcnt); diff --git a/repos/libports/src/lib/libc/select.cc b/repos/libports/src/lib/libc/select.cc index 058674923..924f64c9c 100644 --- a/repos/libports/src/lib/libc/select.cc +++ b/repos/libports/src/lib/libc/select.cc @@ -215,10 +215,9 @@ static void print(Genode::Output &output, timeval *tv) } -extern "C" int -__attribute__((weak)) -_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, - struct timeval *tv) +extern "C" __attribute__((weak)) +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *tv) { fd_set in_readfds, in_writefds, in_exceptfds; @@ -298,21 +297,18 @@ _select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, return select_cb->nready; } +extern "C" __attribute__((alias("select"))) +int __sys_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *tv); -extern "C" int -__attribute__((weak)) -select(int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, struct timeval *timeout) -{ - return _select(nfds, readfds, writefds, exceptfds, timeout); -} +extern "C" __attribute__((alias("select"))) +int _select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *tv); -extern "C" int -__attribute__((weak)) -_pselect(int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, const struct timespec *timeout, - const sigset_t *sigmask) +extern "C" __attribute__((weak)) +int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const sigset_t *sigmask) { struct timeval tv; sigset_t origmask; @@ -332,15 +328,9 @@ _pselect(int nfds, fd_set *readfds, fd_set *writefds, return nready; } - -extern "C" int -__attribute__((weak)) -pselect(int nfds, fd_set *readfds, fd_set *writefds, - fd_set *exceptfds, const struct timespec *timeout, - const sigset_t *sigmask) -{ - return _pselect(nfds, readfds, writefds, exceptfds, timeout, sigmask); -} +extern "C" __attribute__((alias("pselect"))) +int __sys_pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const sigset_t *sigmask); /**************************************** diff --git a/repos/libports/src/lib/libc/signal.cc b/repos/libports/src/lib/libc/signal.cc index 13ccfd3bc..1782bc619 100644 --- a/repos/libports/src/lib/libc/signal.cc +++ b/repos/libports/src/lib/libc/signal.cc @@ -2,10 +2,12 @@ * \brief POSIX signals * \author Emery Hemingway * \date 2015-10-30 + * + * Signal related procedures to be overidden by Noux */ /* - * Copyright (C) 2006-2017 Genode Labs GmbH + * Copyright (C) 2006-2019 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -16,10 +18,15 @@ extern "C" { #include #include #include +#include } +/* Genode includes */ +#include -extern "C" int __attribute__((weak)) sigprocmask(int how, const sigset_t *set, sigset_t *old_set) + +extern "C" __attribute__((weak)) +int sigprocmask(int how, const sigset_t *set, sigset_t *old_set) { /* no signals should be expected, so report all signals blocked */ if (old_set != NULL) @@ -37,7 +44,78 @@ extern "C" int __attribute__((weak)) sigprocmask(int how, const sigset_t *set, s return -1; } -extern "C" int __attribute__((weak)) _sigprocmask(int how, const sigset_t *set, sigset_t *old_set) + +extern "C" +int __sys_sigprocmask(int how, const sigset_t *set, sigset_t *old) { + return sigprocmask(how, set, old); } + + +extern "C" +int __libc_sigprocmask(int how, const sigset_t *set, sigset_t *old) { + return sigprocmask(how, set, old); } + + +extern "C" __attribute__((weak)) +pid_t wait4(pid_t, int *, int, struct rusage *) { - return sigprocmask(how, set, old_set); + Genode::warning(__func__, " not implemented"); + errno = ENOSYS; + return -1; +} + + +extern "C" +pid_t __sys_wait4(pid_t wpid, int *status, int options, struct rusage *rusage) { + return wait4(wpid, status, options, rusage); } + + +extern "C" +pid_t _wait4(pid_t wpid, int *status, int options, struct rusage *rusage) { + return wait4(wpid, status, options, rusage); } + + +extern "C" pid_t wait(int *istat) { + return wait4(WAIT_ANY, istat, 0, NULL); } + + +extern "C" pid_t waitpid(pid_t pid, int *istat, int options) { + return wait4(pid, istat, options, NULL); } + + +extern "C" pid_t _waitpid(pid_t pid, int *istat, int options) { + return wait4(pid, istat, options, NULL); } + + +extern "C" __attribute__((weak)) +pid_t wait6(idtype_t, id_t, int*, int, struct __wrusage*, siginfo_t*) +{ + Genode::warning(__func__, " not implemented"); + errno = ENOSYS; + return -1; +} + +extern "C" +pid_t __sys_wait6(idtype_t idtype, id_t id, int *status, int options, + struct __wrusage *wrusage, siginfo_t *infop) { + return wait6(idtype, id, status, options, wrusage, infop); } + + +extern "C" int waitid(idtype_t idtype, id_t id, siginfo_t *info, int flags) +{ + int status; + pid_t ret = wait6(idtype, id, &status, flags, NULL, info); + + /* + * According to SUSv4, waitid() shall not return a PID when a + * process is found, but only 0. If a process was actually + * found, siginfo_t fields si_signo and si_pid will be + * non-zero. In case WNOHANG was set in the flags and no + * process was found those fields are set to zero using + * memset() below. + */ + if (ret == 0 && info != NULL) + *info = siginfo_t { 0 }; + else if (ret > 0) + ret = 0; + return (ret); } diff --git a/repos/libports/src/lib/libc/sleep.cc b/repos/libports/src/lib/libc/sleep.cc new file mode 100644 index 000000000..fcd0b43dc --- /dev/null +++ b/repos/libports/src/lib/libc/sleep.cc @@ -0,0 +1,105 @@ +/* + * \brief C-library back end + * \author Christian Prochaska + * \author Emery Hemingway + * \date 2012-03-20 + */ + +/* + * Copyright (C) 2008-2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +/* Libc includes */ +#include + +#include "task.h" + + +/* Genode includes */ +#include + +static void millisleep(Genode::uint64_t timeout_ms) +{ + Genode::uint64_t remaining_ms = timeout_ms; + + struct Check : Libc::Suspend_functor + { + bool suspend() override { return true; } + + } check; + + while (remaining_ms > 0) + remaining_ms = Libc::suspend(check, remaining_ms); +} + + +extern "C" __attribute__((weak)) +int nanosleep(const struct timespec *req, struct timespec *rem) +{ + Genode::uint64_t sleep_ms = (uint64_t)req->tv_sec*1000; + if (req->tv_nsec) + sleep_ms += req->tv_nsec / 1000000; + millisleep(sleep_ms); + + if (rem) + *rem = { 0, 0 }; + + return 0; +} + +extern "C" __attribute__((alias("nanosleep"))) +int __sys_nanosleep(const struct timespec *req, struct timespec *rem); + + +extern "C" __attribute__((weak)) +int clock_nanosleep(clockid_t clock_id, int flags, + const struct timespec *rqt, + struct timespec *rmt) +{ + if (flags & TIMER_ABSTIME) { + struct timespec now_ts { 0 }; + if (clock_gettime(clock_id, &now_ts) != 0) { + Genode::error(__func__, ": RTC device not configured"); + return -1; + } + + if (now_ts.tv_sec <= rqt->tv_sec && now_ts.tv_nsec < rqt->tv_nsec) { + struct timespec new_ts = { + .tv_sec = rqt->tv_sec - now_ts.tv_sec, + .tv_nsec = rqt->tv_nsec - now_ts.tv_nsec, + }; + return nanosleep(&new_ts, rmt); + } + return 0; + } + return nanosleep(rqt, rmt); +} + +extern "C" __attribute__((alias("clock_nanosleep"))) +int __sys_clock_nanosleep(clockid_t clock_id, int flags, + const struct timespec *rqt, + struct timespec *rmt); + + +extern "C" __attribute__((weak)) +unsigned int sleep(unsigned int seconds) +{ + Genode::uint64_t sleep_ms = 1000 * (Genode::uint64_t)seconds; + millisleep(sleep_ms); + return 0; +} + + +extern "C" __attribute__((weak)) +int usleep(useconds_t useconds) +{ + if (useconds) + millisleep(useconds / 1000); + return 0; +} + +extern "C" __attribute__((alias("usleep"))) +int _usleep(useconds_t useconds); diff --git a/repos/libports/src/lib/libc/socket_fs_plugin.cc b/repos/libports/src/lib/libc/socket_fs_plugin.cc index 1f0a5784e..559762bee 100644 --- a/repos/libports/src/lib/libc/socket_fs_plugin.cc +++ b/repos/libports/src/lib/libc/socket_fs_plugin.cc @@ -1,3 +1,5 @@ +#include + /* * \brief Libc pseudo plugin for socket fs * \author Christian Helmuth @@ -8,7 +10,7 @@ */ /* - * Copyright (C) 2015-2017 Genode Labs GmbH + * Copyright (C) 2015-2019 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -295,12 +297,14 @@ struct Socket_fs::Local_functor : Socket_fs::Sockaddr_functor struct Socket_fs::Plugin : Libc::Plugin { + bool supports_poll() override { return true; } bool supports_select(int, fd_set *, fd_set *, fd_set *, timeval *) override; ssize_t read(Libc::File_descriptor *, void *, ::size_t) override; ssize_t write(Libc::File_descriptor *, const void *, ::size_t) override; int fcntl(Libc::File_descriptor *, int, long) override; int close(Libc::File_descriptor *) override; + bool poll(Libc::File_descriptor &fd, struct pollfd &pfd) override; int select(int, fd_set *, fd_set *, fd_set *, timeval *) override; int ioctl(Libc::File_descriptor *, int, char *) override; }; @@ -604,8 +608,11 @@ extern "C" int socket_fs_connect(int libc_fd, sockaddr const *addr, socklen_t ad if (!addr) return Errno(EFAULT); - if (addr->sa_family != AF_INET) { - Genode::error(__func__, ": family not supported"); + switch (addr->sa_family) { + case AF_UNSPEC: + case AF_INET: + break; + default: return Errno(EAFNOSUPPORT); } @@ -931,11 +938,11 @@ extern "C" int socket_fs_socket(int domain, int type, int protocol) return Errno(EACCES); } - if ((type != SOCK_STREAM || (protocol != 0 && protocol != IPPROTO_TCP)) - && (type != SOCK_DGRAM || (protocol != 0 && protocol != IPPROTO_UDP))) { + if (((type&7) != SOCK_STREAM || (protocol != 0 && protocol != IPPROTO_TCP)) + && ((type&7) != SOCK_DGRAM || (protocol != 0 && protocol != IPPROTO_UDP))) { Genode::error(__func__, - ": socket with type=", type, - " protocol=", protocol, " not supported"); + ": socket with type=", (Genode::Hex)type, + " protocol=", (Genode::Hex)protocol, " not supported"); return Errno(EAFNOSUPPORT); } @@ -1012,6 +1019,42 @@ ssize_t Socket_fs::Plugin::write(Libc::File_descriptor *fd, const void *buf, ::s } +bool Socket_fs::Plugin::poll(Libc::File_descriptor &fdo, + struct pollfd &pfd) +{ + if (fdo.plugin != this) return false; + Socket_fs::Context *context { nullptr }; + + try { + context = dynamic_cast(fdo.context); + } catch (Socket_fs::Context::Inaccessible) { + pfd.revents |= POLLNVAL; + return true; + } + + enum { + POLLIN_MASK = POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI, + POLLOUT_MASK = POLLOUT | POLLWRNORM | POLLWRBAND, + }; + + bool res { false }; + + if ((pfd.events & POLLIN_MASK) && context->read_ready()) + { + pfd.revents |= pfd.events & POLLIN_MASK; + res = true; + } + + if ((pfd.events & POLLOUT_MASK) && context->write_ready()) + { + pfd.revents |= pfd.events & POLLOUT_MASK; + res = true; + } + + return res; +} + + bool Socket_fs::Plugin::supports_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) diff --git a/repos/libports/src/lib/libc/socket_operations.cc b/repos/libports/src/lib/libc/socket_operations.cc index fc518a338..d2647b7f0 100644 --- a/repos/libports/src/lib/libc/socket_operations.cc +++ b/repos/libports/src/lib/libc/socket_operations.cc @@ -19,14 +19,27 @@ #include /* libc includes */ +extern "C" { +#include +#include #include +} /* libc-internal includes */ #include "libc_file.h" #include "socket_fs_plugin.h" + using namespace Libc; + +#define __SYS_(ret_type, name, args, body) \ + extern "C" {\ + ret_type __sys_##name args body \ + ret_type _##name args __attribute__((alias("__sys_" #name))); \ + ret_type name args __attribute__((alias("__sys_" #name))); \ + } \ + namespace Libc { extern char const *config_socket(); } @@ -34,7 +47,7 @@ namespace Libc { extern char const *config_socket(); } ** Address functions ** ***********************/ -extern "C" int _getpeername(int libc_fd, sockaddr *addr, socklen_t *addrlen) +extern "C" int getpeername(int libc_fd, sockaddr *addr, socklen_t *addrlen) { if (*Libc::config_socket()) return socket_fs_getpeername(libc_fd, addr, addrlen); @@ -43,13 +56,11 @@ extern "C" int _getpeername(int libc_fd, sockaddr *addr, socklen_t *addrlen) } -extern "C" int getpeername(int libc_fd, sockaddr *addr, socklen_t *addrlen) -{ - return _getpeername(libc_fd, addr, addrlen); -} +extern "C" __attribute__((alias("getpeername"))) +int _getpeername(int libc_fd, sockaddr *addr, socklen_t *addrlen); -extern "C" int _getsockname(int libc_fd, sockaddr *addr, socklen_t *addrlen) +extern "C" int getsockname(int libc_fd, sockaddr *addr, socklen_t *addrlen) { if (*Libc::config_socket()) return socket_fs_getsockname(libc_fd, addr, addrlen); @@ -58,17 +69,15 @@ extern "C" int _getsockname(int libc_fd, sockaddr *addr, socklen_t *addrlen) } -extern "C" int getsockname(int libc_fd, sockaddr *addr, socklen_t *addrlen) -{ - return _getsockname(libc_fd, addr, addrlen); -} +extern "C" __attribute__((alias("getsockname"))) +int _getsockname(int libc_fd, sockaddr *addr, socklen_t *addrlen); /************************** ** Socket transport API ** **************************/ -extern "C" int _accept(int libc_fd, sockaddr *addr, socklen_t *addrlen) +__SYS_(int, accept, (int libc_fd, sockaddr *addr, socklen_t *addrlen), { if (*Libc::config_socket()) return socket_fs_accept(libc_fd, addr, addrlen); @@ -76,16 +85,16 @@ extern "C" int _accept(int libc_fd, sockaddr *addr, socklen_t *addrlen) File_descriptor *ret_fd; FD_FUNC_WRAPPER_GENERIC(ret_fd =, 0, accept, libc_fd, addr, addrlen); return ret_fd ? ret_fd->libc_fd : INVALID_FD; -} +}) -extern "C" int accept(int libc_fd, sockaddr *addr, socklen_t *addrlen) +__SYS_(int, accept4, (int libc_fd, struct sockaddr *addr, socklen_t *addrlen, int /*flags*/), { - return _accept(libc_fd, addr, addrlen); -} + return accept(libc_fd, addr, addrlen); +}) -extern "C" int _bind(int libc_fd, sockaddr const *addr, socklen_t addrlen) +extern "C" int bind(int libc_fd, sockaddr const *addr, socklen_t addrlen) { if (*Libc::config_socket()) return socket_fs_bind(libc_fd, addr, addrlen); @@ -94,28 +103,20 @@ extern "C" int _bind(int libc_fd, sockaddr const *addr, socklen_t addrlen) } -extern "C" int bind(int libc_fd, sockaddr const *addr, socklen_t addrlen) -{ - return _bind(libc_fd, addr, addrlen); -} +extern "C" __attribute__((alias("bind"))) +int _bind(int libc_fd, sockaddr const *addr, socklen_t addrlen); -extern "C" int _connect(int libc_fd, sockaddr const *addr, socklen_t addrlen) +__SYS_(int, connect, (int libc_fd, sockaddr const *addr, socklen_t addrlen), { if (*Libc::config_socket()) return socket_fs_connect(libc_fd, addr, addrlen); FD_FUNC_WRAPPER(connect, libc_fd, addr, addrlen); -} +}) -extern "C" int connect(int libc_fd, sockaddr const *addr, socklen_t addrlen) -{ - return _connect(libc_fd, addr, addrlen); -} - - -extern "C" int _listen(int libc_fd, int backlog) +extern "C" int listen(int libc_fd, int backlog) { if (*Libc::config_socket()) return socket_fs_listen(libc_fd, backlog); @@ -124,68 +125,42 @@ extern "C" int _listen(int libc_fd, int backlog) } -extern "C" int listen(int libc_fd, int backlog) -{ - return _listen(libc_fd, backlog); -} - - -extern "C" ssize_t _recvfrom(int libc_fd, void *buf, ::size_t len, int flags, - sockaddr *src_addr, socklen_t *src_addrlen) +__SYS_(ssize_t, recvfrom, (int libc_fd, void *buf, ::size_t len, int flags, + sockaddr *src_addr, socklen_t *src_addrlen), { if (*Libc::config_socket()) return socket_fs_recvfrom(libc_fd, buf, len, flags, src_addr, src_addrlen); FD_FUNC_WRAPPER(recvfrom, libc_fd, buf, len, flags, src_addr, src_addrlen); -} +}) -extern "C" ssize_t recvfrom(int libc_fd, void *buf, ::size_t len, int flags, - sockaddr *src_addr, socklen_t *src_addrlen) -{ - return _recvfrom(libc_fd, buf, len, flags, src_addr, src_addrlen); -} - - -extern "C" ssize_t recv(int libc_fd, void *buf, ::size_t len, int flags) +__SYS_(ssize_t, recv, (int libc_fd, void *buf, ::size_t len, int flags), { if (*Libc::config_socket()) return socket_fs_recv(libc_fd, buf, len, flags); FD_FUNC_WRAPPER(recv, libc_fd, buf, len, flags); -} +}) -extern "C" ssize_t _recvmsg(int libc_fd, msghdr *msg, int flags) +__SYS_(ssize_t, recvmsg, (int libc_fd, msghdr *msg, int flags), { if (*Libc::config_socket()) return socket_fs_recvmsg(libc_fd, msg, flags); FD_FUNC_WRAPPER(recvmsg, libc_fd, msg, flags); -} +}) -extern "C" ssize_t recvmsg(int libc_fd, msghdr *msg, int flags) -{ - return _recvmsg(libc_fd, msg, flags); -} - - -extern "C" ssize_t _sendto(int libc_fd, void const *buf, ::size_t len, int flags, - sockaddr const *dest_addr, socklen_t dest_addrlen) +__SYS_(ssize_t, sendto, (int libc_fd, void const *buf, ::size_t len, int flags, + sockaddr const *dest_addr, socklen_t dest_addrlen), { if (*Libc::config_socket()) return socket_fs_sendto(libc_fd, buf, len, flags, dest_addr, dest_addrlen); FD_FUNC_WRAPPER(sendto, libc_fd, buf, len, flags, dest_addr, dest_addrlen); -} - - -extern "C" ssize_t sendto(int libc_fd, void const *buf, ::size_t len, int flags, - sockaddr const *dest_addr, socklen_t dest_addrlen) -{ - return _sendto(libc_fd, buf, len, flags, dest_addr, dest_addrlen); -} +}) extern "C" ssize_t send(int libc_fd, void const *buf, ::size_t len, int flags) @@ -197,7 +172,7 @@ extern "C" ssize_t send(int libc_fd, void const *buf, ::size_t len, int flags) } -extern "C" int _getsockopt(int libc_fd, int level, int optname, +extern "C" int getsockopt(int libc_fd, int level, int optname, void *optval, socklen_t *optlen) { if (*Libc::config_socket()) @@ -207,15 +182,13 @@ extern "C" int _getsockopt(int libc_fd, int level, int optname, } -extern "C" int getsockopt(int libc_fd, int level, int optname, - void *optval, socklen_t *optlen) -{ - return _getsockopt(libc_fd, level, optname, optval, optlen); -} +extern "C" __attribute__((alias("getsockopt"))) +int _getsockopt(int libc_fd, int level, int optname, + void *optval, socklen_t *optlen); -extern "C" int _setsockopt(int libc_fd, int level, int optname, - void const *optval, socklen_t optlen) +extern "C" int setsockopt(int libc_fd, int level, int optname, + void const *optval, socklen_t optlen) { if (*Libc::config_socket()) return socket_fs_setsockopt(libc_fd, level, optname, optval, optlen); @@ -224,14 +197,12 @@ extern "C" int _setsockopt(int libc_fd, int level, int optname, } -extern "C" int setsockopt(int libc_fd, int level, int optname, - void const *optval, socklen_t optlen) -{ - return _setsockopt(libc_fd, level, optname, optval, optlen); -} +extern "C" __attribute__((alias("setsockopt"))) +int _setsockopt(int libc_fd, int level, int optname, + void const *optval, socklen_t optlen); -extern "C" int _shutdown(int libc_fd, int how) +extern "C" int shutdown(int libc_fd, int how) { if (*Libc::config_socket()) return socket_fs_shutdown(libc_fd, how); @@ -239,14 +210,7 @@ extern "C" int _shutdown(int libc_fd, int how) FD_FUNC_WRAPPER(shutdown, libc_fd, how); } - -extern "C" int shutdown(int libc_fd, int how) -{ - return _shutdown(libc_fd, how); -} - - -extern "C" int _socket(int domain, int type, int protocol) +__SYS_(int, socket, (int domain, int type, int protocol), { if (*Libc::config_socket()) return socket_fs_socket(domain, type, protocol); @@ -268,10 +232,4 @@ extern "C" int _socket(int domain, int type, int protocol) } return new_fdo->libc_fd; -} - - -extern "C" int socket(int domain, int type, int protocol) -{ - return _socket(domain, type, protocol); -} +}) diff --git a/repos/libports/src/lib/libc/sysctl.cc b/repos/libports/src/lib/libc/sysctl.cc index c03e6df9e..7576f9309 100644 --- a/repos/libports/src/lib/libc/sysctl.cc +++ b/repos/libports/src/lib/libc/sysctl.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2016-2017 Genode Labs GmbH + * Copyright (C) 2016-2019 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -60,68 +60,23 @@ extern "C" long sysconf(int name) } -/* non-standard FreeBSD function not supported */ -extern "C" int sysctlbyname(char const *name, void *oldp, size_t *oldlenp, - void *newp, size_t newlen) +extern "C" int __sysctl(const int *name, u_int namelen, + void *oldp, size_t *oldlenp, + const void *newp, size_t newlen) { - Genode::warning(__func__, "(", name, ",...) not implemented"); - return Libc::Errno(ENOENT); -} - - -extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, - void *newp, size_t newlen) -{ - static const ctlname ctl_names[] = CTL_NAMES; - static const ctlname ctl_kern_names[] = CTL_KERN_NAMES; - static const ctlname ctl_hw_names[] = CTL_HW_NAMES; - static const ctlname ctl_user_names[] = CTL_USER_NAMES; - static const ctlname ctl_p1003_1b_names[] = CTL_P1003_1B_NAMES; - /* read only */ if (!oldp) /* check for write attempt */ return Libc::Errno(newp ? EPERM : EINVAL); - ctlname const *ctl = nullptr; + if (namelen != 2) return Libc::Errno(ENOENT); + char *buf = (char*)oldp; int index_a = name[0]; int index_b = name[1]; - if (namelen != 2) return Libc::Errno(ENOENT); - if (index_a >= CTL_MAXID) return Libc::Errno(EINVAL); Genode::memset(buf, 0x00, *oldlenp); - switch(index_a) { - case CTL_KERN: - if (index_b >= KERN_MAXID) return Libc::Errno(EINVAL); - ctl = &ctl_kern_names[index_b]; break; - - case CTL_HW: - if (index_b >= HW_MAXID) return Libc::Errno(EINVAL); - ctl = &ctl_hw_names[index_b]; break; - - case CTL_USER: - if (index_b >= USER_MAXID) return Libc::Errno(EINVAL); - ctl = &ctl_user_names[index_b]; break; - - case CTL_P1003_1B: - if (index_b >= CTL_P1003_1B_MAXID) return Libc::Errno(EINVAL); - ctl = &ctl_p1003_1b_names[index_b]; break; - } - - if (!ctl) return Libc::Errno(EINVAL); - - if (((ctl->ctl_type == CTLTYPE_INT) && (*oldlenp < sizeof(int))) || - ((ctl->ctl_type == CTLTYPE_STRING) && (*oldlenp < 1)) || - ((ctl->ctl_type == CTLTYPE_QUAD) && (*oldlenp < sizeof(Genode::uint64_t))) || - ((ctl->ctl_type == CTLTYPE_UINT) && (*oldlenp < sizeof(unsigned int))) || - ((ctl->ctl_type == CTLTYPE_LONG) && (*oldlenp < sizeof(long))) || - ((ctl->ctl_type == CTLTYPE_ULONG) && (*oldlenp < sizeof(unsigned long)))) - { - return Libc::Errno(EINVAL); - } - /* builtins */ { switch(index_a) { @@ -159,77 +114,6 @@ extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, } } - - /* runtime overrides */ - { - Libc::Absolute_path sysctl_path(ctl_names[index_a].ctl_name, "/.sysctl/"); - sysctl_path.append("/"); - sysctl_path.append(ctl->ctl_name); - - /* - * read from /.sysctl/... - * - * The abstracted libc interface is used to read files here - * rather than to explicity resolve a file system plugin. - */ - int fd = open(sysctl_path.base(), 0); - if (fd != -1) { - auto n = read(fd, buf, *oldlenp); - close(fd); - - if (n > 0) switch (ctl->ctl_type) { - case CTLTYPE_INT: { - long value = 0; - Genode::ascii_to((char*)oldp, value); - *(int*)oldp = int(value); - *oldlenp = sizeof(int); - return 0; - } - - case CTLTYPE_STRING: - *oldlenp = n; - return 0; - - case CTLTYPE_QUAD: { - Genode::uint64_t value = 0; - Genode::ascii_to((char*)oldp, value); - *(Genode::uint64_t*)oldp = value; - *oldlenp = sizeof(Genode::uint64_t); - return 0; - } - - case CTLTYPE_UINT: { - unsigned value = 0; - Genode::ascii_to((char*)oldp, value); - *(unsigned*)oldp = value; - *oldlenp = sizeof(unsigned); - return 0; - } - - case CTLTYPE_LONG: { - long value = 0; - Genode::ascii_to((char*)oldp, value); - *(long*)oldp = value; - *oldlenp = sizeof(long); - return 0; - } - - case CTLTYPE_ULONG: { - unsigned long value = 0; - Genode::ascii_to((char*)oldp, value); - *(unsigned long*)oldp = value; - *oldlenp = sizeof(unsigned long); - return 0; - } - - default: - Genode::warning("unhandled sysctl data type for ", sysctl_path); - return Libc::Errno(EINVAL); - } - } - } - - /* fallback values */ { switch(index_a) { @@ -270,8 +154,6 @@ extern "C" int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, } } - Genode::warning("sysctl: no builtin or override value found for ", - Genode::Cstring(ctl_names[index_a].ctl_name), ".", - Genode::Cstring(ctl->ctl_name)); + Genode::warning("missing sysctl for [", index_a, "][", index_b, "]"); return Libc::Errno(ENOENT); } diff --git a/repos/libports/src/lib/libc/thread.cc b/repos/libports/src/lib/libc/thread.cc index 935963eba..1981345e6 100644 --- a/repos/libports/src/lib/libc/thread.cc +++ b/repos/libports/src/lib/libc/thread.cc @@ -256,6 +256,12 @@ extern "C" { } + pthread_t thr_self(void) { return pthread_self(); } + + __attribute__((alias("thr_self"))) + pthread_t __sys_thr_self(void); + + int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) { if (!attr || !*attr) diff --git a/repos/libports/src/lib/libc/thread_create.h b/repos/libports/src/lib/libc/thread_create.h index 3f7493d78..c760cbf31 100644 --- a/repos/libports/src/lib/libc/thread_create.h +++ b/repos/libports/src/lib/libc/thread_create.h @@ -13,6 +13,9 @@ * under the terms of the GNU Affero General Public License version 3. */ +#ifndef _LIBC__THREAD_CREATE_H_ +#define _LIBC__THREAD_CREATE_H_ + #include #include @@ -24,3 +27,5 @@ namespace Libc { int pthread_create(pthread_t *, Genode::Thread &); } + +#endif /* _LIBC__THREAD_CREATE_H_ */ diff --git a/repos/libports/src/lib/libc/time.cc b/repos/libports/src/lib/libc/time.cc index 944e5d085..eed2458e2 100644 --- a/repos/libports/src/lib/libc/time.cc +++ b/repos/libports/src/lib/libc/time.cc @@ -80,6 +80,10 @@ int clock_gettime(clockid_t clk_id, struct timespec *ts) } +extern "C" __attribute__((weak, alias("clock_gettime"))) +int __sys_clock_gettime(clockid_t clk_id, struct timespec *ts); + + extern "C" __attribute__((weak)) int gettimeofday(struct timeval *tv, struct timezone *) { @@ -96,6 +100,10 @@ int gettimeofday(struct timeval *tv, struct timezone *) } +extern "C" __attribute__((weak, alias("gettimeofday"))) +int __sys_gettimeofday(struct timeval *tv, struct timezone *); + + extern "C" clock_t clock() { diff --git a/repos/libports/src/lib/libc/vfs_plugin.cc b/repos/libports/src/lib/libc/vfs_plugin.cc index 99379e09d..b47b0708e 100644 --- a/repos/libports/src/lib/libc/vfs_plugin.cc +++ b/repos/libports/src/lib/libc/vfs_plugin.cc @@ -131,6 +131,13 @@ namespace Libc { return rtc.string(); } + char const *config_rng() __attribute__((weak)); + char const *config_rng() + { + static Config_attr rng("rng", ""); + return rng.string(); + } + char const *config_socket() __attribute__((weak)); char const *config_socket() { @@ -894,6 +901,7 @@ int Libc::Vfs_plugin::ftruncate(Libc::File_descriptor *fd, ::off_t length) int Libc::Vfs_plugin::fcntl(Libc::File_descriptor *fd, int cmd, long arg) { switch (cmd) { + case F_DUPFD_CLOEXEC: case F_DUPFD: { /* @@ -1235,6 +1243,40 @@ int Libc::Vfs_plugin::munmap(void *addr, ::size_t) } +bool Libc::Vfs_plugin::poll(File_descriptor &fd, struct pollfd &pfd) +{ + if (fd.plugin != this) return false; + + Vfs::Vfs_handle *handle = vfs_handle(&fd); + if (!handle) { + pfd.revents |= POLLNVAL; + return true; + } + + enum { + POLLIN_MASK = POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI, + POLLOUT_MASK = POLLOUT | POLLWRNORM | POLLWRBAND, + }; + + bool res { false }; + + if ((pfd.events & POLLIN_MASK) + && VFS_THREAD_SAFE(handle->fs().read_ready(handle))) + { + pfd.revents |= pfd.events & POLLIN_MASK; + res = true; + } + + if ((pfd.events & POLLOUT_MASK) /* XXX always writeable */) + { + pfd.revents |= pfd.events & POLLOUT_MASK; + res = true; + } + + return res; +} + + bool Libc::Vfs_plugin::supports_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) diff --git a/repos/libports/src/lib/libc/vfs_plugin.h b/repos/libports/src/lib/libc/vfs_plugin.h index 2573588d2..86fab8245 100644 --- a/repos/libports/src/lib/libc/vfs_plugin.h +++ b/repos/libports/src/lib/libc/vfs_plugin.h @@ -180,6 +180,7 @@ class Libc::Vfs_plugin : public Libc::Plugin bool supports_access(const char *, int) override { return true; } bool supports_mkdir(const char *, mode_t) override { return true; } bool supports_open(const char *, int) override { return true; } + bool supports_poll() override { return true; } bool supports_readlink(const char *, char *, ::size_t) override { return true; } bool supports_rename(const char *, const char *) override { return true; } bool supports_rmdir(const char *) override { return true; } @@ -211,6 +212,7 @@ class Libc::Vfs_plugin : public Libc::Plugin int ioctl(Libc::File_descriptor *, int , char *) override; ::off_t lseek(Libc::File_descriptor *fd, ::off_t offset, int whence) override; int mkdir(const char *, mode_t) override; + bool poll(File_descriptor &fdo, struct pollfd &pfd) override; ssize_t read(Libc::File_descriptor *, void *, ::size_t) override; ssize_t readlink(const char *, char *, ::size_t) override; int rename(const char *, const char *) override; diff --git a/repos/libports/src/lib/libc_pipe/plugin.cc b/repos/libports/src/lib/libc_pipe/plugin.cc index 63337cbae..abc29a6a2 100644 --- a/repos/libports/src/lib/libc_pipe/plugin.cc +++ b/repos/libports/src/lib/libc_pipe/plugin.cc @@ -101,6 +101,7 @@ namespace Libc_pipe { void init(Genode::Env &env) override; bool supports_pipe() override; + bool supports_poll() override; bool supports_select(int nfds, fd_set *readfds, fd_set *writefds, @@ -110,6 +111,7 @@ namespace Libc_pipe { int close(Libc::File_descriptor *pipefdo) override; int fcntl(Libc::File_descriptor *pipefdo, int cmd, long arg) override; int pipe(Libc::File_descriptor *pipefdo[2]) override; + bool poll(Libc::File_descriptor &, struct pollfd &) override; ssize_t read(Libc::File_descriptor *pipefdo, void *buf, ::size_t count) override; int select(int nfds, fd_set *readfds, fd_set *writefds, @@ -204,6 +206,12 @@ namespace Libc_pipe { } + bool Plugin::supports_poll() + { + return true; + } + + bool Plugin::supports_select(int nfds, fd_set *readfds, fd_set *writefds, @@ -308,6 +316,37 @@ namespace Libc_pipe { } + bool Plugin::poll(Libc::File_descriptor &fdo, struct pollfd &pfd) + { + if (fdo.plugin != this) return false; + + enum { + POLLIN_MASK = POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI, + POLLOUT_MASK = POLLOUT | POLLWRNORM | POLLWRBAND, + }; + + bool res { false }; + + if ((pfd.events & POLLIN_MASK) + && read_end(&fdo) + && !context(&fdo)->buffer()->empty()) + { + pfd.revents |= pfd.events & POLLIN_MASK; + res = true; + } + + if ((pfd.events & POLLOUT_MASK) + && write_end(&fdo) + && (context(&fdo)->buffer()->avail_capacity() > 0)) + { + pfd.revents |= pfd.events & POLLOUT_MASK; + res = true; + } + + return res; + } + + ssize_t Plugin::read(Libc::File_descriptor *fdo, void *buf, ::size_t count) { if (!read_end(fdo)) { @@ -413,6 +452,7 @@ namespace Libc_pipe { if (libc_select_notify) libc_select_notify(); + Plugin::resume_all(); } context(fdo)->write_avail_sem()->down(); @@ -423,6 +463,7 @@ namespace Libc_pipe { if (libc_select_notify) libc_select_notify(); + Plugin::resume_all(); return num_bytes_written; } diff --git a/repos/libports/src/test/libc/main.cc b/repos/libports/src/test/libc/main.cc index c0ef4604d..eecbe79a4 100644 --- a/repos/libports/src/test/libc/main.cc +++ b/repos/libports/src/test/libc/main.cc @@ -21,14 +21,16 @@ #include /* libC includes */ +extern "C" { #include #include #include #include #include #include +#include #include - +} int main(int argc, char **argv) { @@ -157,5 +159,17 @@ int main(int argc, char **argv) printf("sleep/gettime: %.09f\n", ts.tv_sec + ts.tv_nsec / 1000000000.0); } + { + unsigned long long buf = 0; + getrandom(&buf, sizeof(buf), 0); + printf("getrandom %llx\n", buf); + } + + { + unsigned long long buf = 0; + getentropy(&buf, sizeof(buf)); + printf("getentropy %llx\n", buf); + } + exit(error_count); } diff --git a/repos/ports/ports/e2fsprogs.hash b/repos/ports/ports/e2fsprogs.hash index 06252517e..2e9b0ccac 100644 --- a/repos/ports/ports/e2fsprogs.hash +++ b/repos/ports/ports/e2fsprogs.hash @@ -1 +1 @@ -456c6445bab2a174dd845f7aa2beb767250722db +2a09cdc29a00804cca8908d1459511a73dd5881b diff --git a/repos/ports/recipes/src/seoul/content.mk b/repos/ports/recipes/src/seoul/content.mk index e969df858..8dbd86465 100644 --- a/repos/ports/recipes/src/seoul/content.mk +++ b/repos/ports/recipes/src/seoul/content.mk @@ -54,7 +54,9 @@ include $(REP_DIR)/lib/mk/seoul_libc_support.mk MIRROR_FROM_LIBC := $(addprefix src/lib/libc/lib/libc/,$(SRC_C)) \ src/lib/libc/lib/libc/locale/mblocal.h \ - src/lib/libc/lib/libc/string/index.c + src/lib/libc/lib/libc/locale/xlocale_private.h \ + src/lib/libc/lib/libc/locale/setlocale.h \ + src/lib/libc/lib/libc/include/libc_private.h \ content: $(MIRROR_FROM_LIBC) diff --git a/repos/ports/run/noux.run b/repos/ports/run/noux.run index 83fd65714..74a4f28b7 100644 --- a/repos/ports/run/noux.run +++ b/repos/ports/run/noux.run @@ -1,8 +1,11 @@ -build { core init timer noux server/log_terminal - lib/libc_noux noux-pkg/coreutils } +build { noux lib/libc_noux } create_boot_directory +import_from_depot [depot_user]/src/[base_src] \ + [depot_user]/src/init \ + [depot_user]/src/coreutils \ + install_config { @@ -23,15 +26,10 @@ install_config { - - - - - - - + + @@ -39,14 +37,10 @@ install_config { } build_boot_image { - core init timer log_terminal ld.lib.so noux libc.lib.so vfs.lib.so libm.lib.so - libc_noux.lib.so coreutils.tar posix.lib.so + noux libc.lib.so vfs.lib.so libm.lib.so + libc_noux.lib.so posix.lib.so } append qemu_args " -nographic -serial mon:stdio " -if {[have_spec x86_64]} { - # coreutils.tar is really huge when built for x86_64 -} - run_genode_until {child "noux" exited with exit value 0.*\n} 30 diff --git a/repos/ports/run/noux_bash.run b/repos/ports/run/noux_bash.run index 315f39a8f..ce24dec88 100644 --- a/repos/ports/run/noux_bash.run +++ b/repos/ports/run/noux_bash.run @@ -4,8 +4,6 @@ import_from_depot [depot_user]/src/[base_src] \ [depot_user]/pkg/[drivers_interactive_pkg] \ [depot_user]/pkg/terminal \ [depot_user]/src/init \ - [depot_user]/src/libc \ - [depot_user]/src/noux \ [depot_user]/src/posix \ [depot_user]/src/ncurses \ [depot_user]/src/vim \ @@ -13,6 +11,8 @@ import_from_depot [depot_user]/src/[base_src] \ [depot_user]/src/coreutils \ [depot_user]/src/ram_fs +build { noux lib/libc_noux } + # write default vimrc file set vimrc_fd [open [run_dir]/genode/vimrc w] puts $vimrc_fd { @@ -131,6 +131,9 @@ Hello world !! } -build_boot_image { } +build_boot_image { + noux libc_noux.lib.so + libc.lib.so libm.lib.so vfs.lib.so +} run_genode_until forever diff --git a/repos/ports/src/lib/libc_noux/plugin.cc b/repos/ports/src/lib/libc_noux/plugin.cc index a1385f143..655aac990 100644 --- a/repos/ports/src/lib/libc_noux/plugin.cc +++ b/repos/ports/src/lib/libc_noux/plugin.cc @@ -674,8 +674,8 @@ extern "C" int chmod(char const *path, mode_t mode) } -extern "C" pid_t _wait4(pid_t pid, int *status, int options, - struct rusage *rusage) +extern "C" pid_t wait4(pid_t pid, int *status, int options, + struct rusage *rusage) { sysio()->wait4_in.pid = pid; sysio()->wait4_in.nohang = !!(options & WNOHANG); @@ -698,6 +698,20 @@ extern "C" pid_t _wait4(pid_t pid, int *status, int options, } +extern "C" __attribute__((alias("wait4"))) +pid_t _wait4(pid_t, int *, int, struct rusage *); + + +extern "C" __attribute__((alias("wait4"))) +pid_t __sys_wait4(pid_t, int *, int, struct rusage *); + + +extern "C" pid_t waitpid(pid_t pid, int *istat, int options) +{ + return wait4(pid, istat, options, NULL); +} + + int getrusage(int who, struct rusage *usage) { if (verbose) @@ -740,6 +754,12 @@ extern "C" int kill(__pid_t pid, int sig) } +extern "C" int raise(int sig) +{ + return kill(getpid(), sig); +} + + extern "C" int nanosleep(const struct timespec *timeout, struct timespec *remainder) { @@ -893,10 +913,7 @@ extern "C" int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) } -extern "C" int _sigprocmask(int how, const sigset_t *set, sigset_t *oldset) -{ - return sigprocmask(how, set, oldset); -} +extern "C" int _sigprocmask(int how, const sigset_t *set, sigset_t *oldset) __attribute__((alias("sigprocmask"))); extern "C" int _sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) @@ -919,11 +936,7 @@ extern "C" int _sigaction(int signum, const struct sigaction *act, struct sigact } -extern "C" int sigaction(int signum, const struct sigaction *act, - struct sigaction *oldact) -{ - return _sigaction(signum, act, oldact); -} +extern "C" int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) __attribute__((alias("_sigaction"))); /********************* @@ -1580,6 +1593,7 @@ namespace { sysio()->fcntl_in.fd = noux_fd(fd->context); switch (cmd) { + case F_DUPFD_CLOEXEC: case F_DUPFD: { /* diff --git a/repos/ports/src/noux-pkg/e2fsprogs/patches/DIOCGDINFO.patch b/repos/ports/src/noux-pkg/e2fsprogs/patches/DIOCGDINFO.patch new file mode 100644 index 000000000..c6751c9a2 --- /dev/null +++ b/repos/ports/src/noux-pkg/e2fsprogs/patches/DIOCGDINFO.patch @@ -0,0 +1,14 @@ +--- src/noux-pkg/e2fsprogs/lib/blkid/getsize.c.old 2019-05-16 13:06:14.874236710 +0200 ++++ src/noux-pkg/e2fsprogs/lib/blkid/getsize.c 2019-05-16 13:00:38.790499736 +0200 +@@ -152,11 +152,6 @@ + (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))) + part = st.st_rdev & 7; + +- if (part >= 0 && (ioctl(fd, DIOCGDINFO, (char *)&lab) >= 0)) { +- pp = &lab.d_partitions[part]; +- if (pp->p_size) +- return pp->p_size << 9; +- } + } + #endif /* HAVE_SYS_DISKLABEL_H */ + { diff --git a/repos/ports/src/noux-pkg/e2fsprogs/patches/unix_io.c.patch b/repos/ports/src/noux-pkg/e2fsprogs/patches/unix_io.c.patch new file mode 100644 index 000000000..9dff97c9c --- /dev/null +++ b/repos/ports/src/noux-pkg/e2fsprogs/patches/unix_io.c.patch @@ -0,0 +1,13 @@ +Remove io->align check because it is not needed in our case +and rather leads to an memory allocation error (we cannot satisfy +the alignment). ++++ src/noux-pkg/e2fsprogs/lib/ext2fs/unix_io.c +@@ -558,7 +558,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel) + } + #endif + +-#if defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ++#if 0 + /* + * Some operating systems require that the buffers be aligned, + * regardless of O_DIRECT diff --git a/repos/ports/src/noux-pkg/gcc/target.inc b/repos/ports/src/noux-pkg/gcc/target.inc index eced60b3c..e91b94d83 100644 --- a/repos/ports/src/noux-pkg/gcc/target.inc +++ b/repos/ports/src/noux-pkg/gcc/target.inc @@ -33,6 +33,9 @@ ENV += CXXFLAGS_FOR_TARGET='-fPIC' MAKE_ENV += GENODE="yes" +# prevent "converting to ‘bool’ from ‘std::nullptr_t’" error +CXXFLAGS += -fpermissive + # # We link libraries to the final binaries using the 'LIBS' variable. But # unfortunately, the gcc build system has hardcoded some libs such as '-lc'. diff --git a/tool/ports/mk/install.mk b/tool/ports/mk/install.mk index efb40cc3b..0c78b5882 100644 --- a/tool/ports/mk/install.mk +++ b/tool/ports/mk/install.mk @@ -225,9 +225,10 @@ _extract_function(tgz) = tar xfz $(ARCHIVE) -C $(DIR) $(call _tar_opt,$1) _extract_function(tar.gz) = tar xfz $(ARCHIVE) -C $(DIR) $(call _tar_opt,$1) _extract_function(tar.xz) = tar xfJ $(ARCHIVE) -C $(DIR) $(call _tar_opt,$1) _extract_function(tar.bz2) = tar xfj $(ARCHIVE) -C $(DIR) $(call _tar_opt,$1) +_extract_function(txz) = tar xfJ $(ARCHIVE) -C $(DIR) $(call _tar_opt,$1) _extract_function(zip) = unzip -o -q -d $(DIR) $(call _unzip_opt,$1) $(ARCHIVE) -_ARCHIVE_EXTS := tar tar.gz tar.xz tgz tar.bz2 zip +_ARCHIVE_EXTS := tar tar.gz tar.xz tgz tar.bz2 txz zip # # Function that returns the matching extraction function for a given archive