]> xenbits.xensource.com Git - unikraft/libs/newlib.git/commitdiff
Adapt to the latest changes in Unikraft core
authorEduard Vintilă <eduard.vintila47@gmail.com>
Wed, 23 Nov 2022 18:34:46 +0000 (20:34 +0200)
committerUnikraft <monkey@unikraft.io>
Mon, 8 May 2023 10:10:14 +0000 (10:10 +0000)
This commit updates various headers to match the latest posix-time
interface from Unikraft core, while also introducing new glue code
(`__uk_init_tls.c`) to adapt the library to the new TCB/TLS layout.

Checkpatch-Ignore: EMBEDDED_FUNCTION_NAME
Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Maria Sfiraiala <maria.sfiraiala@gmail.com>
Reviewed-by: Teodor Tiron <teotiron@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #28

12 files changed:
Config.uk
Makefile.uk
__uk_init_tls.c [new file with mode: 0644]
fork.c [new file with mode: 0644]
include/dirent.h
include/sys/time.h
include/time.h
include/time_types.h [new file with mode: 0644]
include/uk/_timespec.h
include/uk/_types.h
musl-imported/include/sys/ioctl.h
patches/0017-Remove-__nonnull-coliding-with-existent-macro.patch [new file with mode: 0644]

index 551f1c6d4ff956d016d5599e6cc28c1fb42a204c..53cc031cb1c58a394dc8b857f4033f36d059fea9 100644 (file)
--- a/Config.uk
+++ b/Config.uk
@@ -12,6 +12,7 @@ menuconfig LIBNEWLIBC
        select LIBUKTIME
        select LIBVFSCORE
        select LIBUKSIGNAL
+       select LIBUKSCHED_TCB_INIT
        select LIBPOSIX_PROCESS
        select LIBPOSIX_USER
        select FPSIMD if ARCH_ARM_64
index f5840fe41559ba6fd8ff1d14b4586cf1e268c431..a023165bc996f760dd64b3ff959998d407251680 100644 (file)
 #  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #  POSSIBILITY OF SUCH DAMAGE.
 #
+################################################################################
+# This will reserve space within `uk_tls` for a **pointer** to struct _reent
+# Please refer to ./arch/Makefile.rules for more details.
+# In our case, 16 bytes is sufficient to also cover for the minimum size required by ARM.
+################################################################################
+$(eval $(call ukarch_tls_tcb_reserve,16))
+
+
 
 ################################################################################
 # Library registration
@@ -82,7 +90,7 @@ LIBNEWLIBM_CXXINCLUDES += -I$(LIBNEWLIB_LIBM)/common
 # Global flags
 ################################################################################
 LIBNEWLIB_GLOBAL_FLAGS-y  += -DMISSING_SYSCALL_NAMES -DMALLOC_PROVIDED
-LIBNEWLIB_GLOBAL_FLAGS-y  += -D_POSIX_REALTIME_SIGNALS
+#LIBNEWLIB_GLOBAL_FLAGS-y  += -D_POSIX_REALTIME_SIGNALS
 LIBNEWLIB_GLOBAL_FLAGS-$(CONFIG_LIBNEWLIBC_WANT_IO_C99_FORMATS) += -D_WANT_IO_C99_FORMATS
 LIBNEWLIB_GLOBAL_FLAGS-$(CONFIG_LIBNEWLIBC_LINUX_ERRNO_EXTENSIONS) += -D__LINUX_ERRNO_EXTENSIONS__
 ifeq ($(CONFIG_ARCH_ARM_64),y)
@@ -143,6 +151,8 @@ LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/termios/tcsetattr.c
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/termios/tcgetattr.c
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/math/sincosl.c
 LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/musl-imported/src/exit/assert.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/__uk_init_tls.c
+LIBNEWLIBGLUE_SRCS-y += $(LIBNEWLIBC_BASE)/fork.c
 
 ifeq ($(CONFIG_LIBNEWLIBC_CRYPT),y)
 LIBNEWLIBGLUE_CFLAGS-y   += -Wno-missing-braces -Wno-sign-compare -Wno-char-subscripts
diff --git a/__uk_init_tls.c b/__uk_init_tls.c
new file mode 100644 (file)
index 0000000..1386239
--- /dev/null
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Authors: Eduard Vintilă <eduard.vintila47@gmail.com>
+ *
+ * Copyright (c) 2022, University of Bucharest. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <uk/tcb_impl.h>
+#include <uk/plat/tls.h>
+#include <uk/arch/tls.h>
+#include <uk/alloc.h>
+#include <uk/assert.h>
+#include <sys/reent.h>
+#include <string.h>
+
+/* Needed by newlib. Retrieves the reentrant structure of the current thread.*/
+struct _reent *__getreent(void)
+{
+       void *tcb = ukarch_tls_tcb_get(ukplat_tlsp_get());
+       struct _reent **reent = (struct _reent **) tcb;
+
+       if (reent && *reent)
+               return *reent;
+
+       return _impure_ptr;
+}
+
+int uk_thread_uktcb_init(struct uk_thread *thread, void *tcb)
+{
+       /* We already initialize the TCB in ukarch_tls_tcb_init() */
+       return 0;
+}
+
+void uk_thread_uktcb_fini(struct uk_thread *thread, void *tcb)
+{
+       struct _reent **reent = (struct _reent **)tcb;
+
+       uk_pr_debug("uk_thread_tcb_fini uk_thread %p, tcb %p\n", thread, tcb);
+       uk_free(uk_alloc_get_default(), *reent);
+}
+
+
+/*
+ * Called for every thread.
+ * Initializes newlib's reentrant structure for the given TCB.
+ */
+void ukarch_tls_tcb_init(void *tcb)
+{
+       struct _reent **reent = (struct _reent **)tcb;
+
+       uk_pr_info("ukarch_tls_tcb_init tcb %p\n", tcb);
+
+       UK_ASSERT(reent);
+
+       *reent = uk_memalign(
+           uk_alloc_get_default(),
+           __PAGE_SIZE,
+           sizeof(struct _reent));
+
+       UK_ASSERT(*reent);
+
+       _REENT_INIT_PTR(*reent);
+
+#if 0
+       /* TODO initialize basic signal handling */
+       _init_signal_r(myreent);
+#endif
+}
diff --git a/fork.c b/fork.c
new file mode 100644 (file)
index 0000000..6c5fb55
--- /dev/null
+++ b/fork.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * FIXME: Placeholder stub fork.
+ *
+ * Authors: Eduard Vintilă <eduard.vintila47@gmail.com>
+ *
+ * Copyright (c) 2022, University of Bucharest. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <errno.h>
+
+int fork(void)
+{
+       /* TODO: implement. */
+       errno = ENOSYS;
+       return -1;
+}
index e86be2a694770b7326391146f4a869d730f98de4..cc102c5a0c35db2b7c9c4d27319e2080f56ce28b 100644 (file)
@@ -109,7 +109,6 @@ int versionsort(const struct dirent **, const struct dirent **);
 #define versionsort64 versionsort
 #define off64_t off_t
 #define ino64_t ino_t
-#define getdents64 getdents
 #endif
 
 #ifdef __cplusplus
index 02fc1d611593692cfc6c194b086ad289c5d1b1fd..fe3a30ae50366166f7255174b0d0e07d0186b20c 100644 (file)
@@ -1,40 +1,70 @@
-/* SPDX-License-Identifier: BSD-3-Clause */
-/*
- * Authors: Costin Lupu <costin.lupu@cs.pub.ro>
- *
- * Copyright (c) 2019, University Politehnica of Bucharest. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the copyright holder nor the names of its
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __NEWLIB_GLUE_SYS_TIME_H__
-#define __NEWLIB_GLUE_SYS_TIME_H__
-
-#include "_ansi.h"
-
-#include <sys/reent.h>
-
-#endif /* __NEWLIB_GLUE_SYS_TIME_H__ */
+#ifndef _SYS_TIME_H_
+#define _SYS_TIME_H_
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <uk/config.h>
+
+#define __NEED_time_t
+#define __NEED_suseconds_t
+#define __NEED_struct_timeval
+#include <time_types.h>
+
+#ifndef CONFIG_LIBNOLIBC
+/* Allow custom definitions */
+#include_next <sys/time.h>
+#endif
+
+int gettimeofday (struct timeval *__restrict, void *__restrict);
+
+#define ITIMER_REAL    0
+#define ITIMER_VIRTUAL 1
+#define ITIMER_PROF    2
+
+struct itimerval {
+       struct timeval it_interval;
+       struct timeval it_value;
+};
+
+int getitimer (int, struct itimerval *);
+int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict);
+int utimes (const char *, const struct timeval *);
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+struct timezone {
+       int tz_minuteswest;
+       int tz_dsttime;
+};
+int futimes(int, const struct timeval *);
+int futimesat(int, const char *, const struct timeval *);
+int lutimes(const char *, const struct timeval *);
+int settimeofday(const struct timeval *, const struct timezone *);
+int adjtime (const struct timeval *, struct timeval *);
+#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
+#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
+#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
+       (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
+#define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
+       ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
+       ((a)->tv_usec -= 1000000, (a)->tv_sec++) )
+#define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
+       ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
+       ((a)->tv_usec += 1000000, (a)->tv_sec--) )
+#endif
+
+#if defined(_GNU_SOURCE)
+#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \
+       (ts)->tv_sec = (tv)->tv_sec, \
+       (ts)->tv_nsec = (tv)->tv_usec * 1000, \
+       (void)0 )
+#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \
+       (tv)->tv_sec = (ts)->tv_sec, \
+       (tv)->tv_usec = (ts)->tv_nsec / 1000, \
+       (void)0 )
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif
index 540e663b09f19d3dd844c5b150f56620387713b3..3869e3b5555284f3ef18e64cda93270054097738 100644 (file)
-/* SPDX-License-Identifier: BSD-3-Clause */
-/*
- * libnewlib glue code
- *
- * Authors: Florian Schmidt <florian.schmidt@neclab.eu>
- *
- * Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the copyright holder nor the names of its
- *    contributors may be used to endorse or promote products derived from
- *    this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef NEWLIBGLUE_TIME_H
-#define NEWLIBGLUE_TIME_H
-
-/* Make newlib provide declarations for the timer functions
- * such as nanosleep
- */
-#define _POSIX_TIMERS 1
-#define _POSIX_MONOTONIC_CLOCK 1
+#ifndef _TIME_H_
+#define _TIME_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <uk/config.h>
+#include <_ansi.h>
 #include <sys/reent.h>
+
+#define __NEED_size_t
+#define __NEED_time_t
+#define __NEED_clock_t
+#define __NEED_struct_timespec
+#define __NEED_clockid_t
+#define __NEED_timer_t
+#define __NEED_pid_t
+#define __NEED_locale_t
+
+#include <sys/types.h>
 #include <xlocale.h>
 
+#ifndef CONFIG_LIBNOLIBC
+/* Allow custom definitions */
+#include_next <time.h>
+#endif
+
+#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+#define __tm_gmtoff tm_gmtoff
+#define __tm_zone tm_zone
+#endif
+
+struct tm {
+       int tm_sec;
+       int tm_min;
+       int tm_hour;
+       int tm_mday;
+       int tm_mon;
+       int tm_year;
+       int tm_wday;
+       int tm_yday;
+       int tm_isdst;
+       long __tm_gmtoff;
+       const char *__tm_zone;
+};
+
+clock_t clock (void);
+time_t time (time_t *);
+double difftime (time_t, time_t);
+time_t mktime (struct tm *);
+size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict);
+struct tm *gmtime (const time_t *);
+struct tm *localtime (const time_t *);
+char *asctime (const struct tm *);
+char *ctime (const time_t *);
+int timespec_get(struct timespec *, int);
+
+#define CLOCKS_PER_SEC 1000000L
+
+#define TIME_UTC 1
+
+size_t strftime_l (char *  __restrict, size_t, const char *  __restrict, const struct tm *  __restrict, locale_t);
+
+struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
+struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
+char *asctime_r (const struct tm *__restrict, char *__restrict);
+char *ctime_r (const time_t *, char *);
+
+void tzset (void);
+
+struct itimerspec {
+       struct timespec it_interval;
+       struct timespec it_value;
+};
+
+#define CLOCK_REALTIME           0
+#define CLOCK_MONOTONIC          1
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_THREAD_CPUTIME_ID  3
+#define CLOCK_MONOTONIC_RAW      4
+#define CLOCK_REALTIME_COARSE    5
+#define CLOCK_MONOTONIC_COARSE   6
+#define CLOCK_BOOTTIME           7
+#define CLOCK_REALTIME_ALARM     8
+#define CLOCK_BOOTTIME_ALARM     9
+#define CLOCK_SGI_CYCLE         10
+#define CLOCK_TAI               11
+
+#define TIMER_ABSTIME 1
+
+int nanosleep (const struct timespec *, struct timespec *);
+int clock_getres (clockid_t, struct timespec *);
+int clock_gettime (clockid_t, struct timespec *);
+int clock_settime (clockid_t, const struct timespec *);
+int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *);
+int clock_getcpuclockid (pid_t, clockid_t *);
+
+struct sigevent;
+int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict);
+int timer_delete (timer_t);
+int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict);
+int timer_gettime (timer_t, struct itimerspec *);
+int timer_getoverrun (timer_t);
+
+extern char *tzname[2];
+
+#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
+extern int daylight;
+extern long timezone;
+extern int getdate_err;
+struct tm *getdate (const char *);
+#endif
+
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+int stime(const time_t *);
+time_t timegm(struct tm *);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#if __POSIX_VISIBLE
+_VOID      _EXFUN(tzset,       (_VOID));
+#endif
+_VOID      _EXFUN(_tzset_r,    (struct _reent *));
+
 typedef struct __tzrule_struct
 {
-       char ch;
-       int m;
-       int n;
-       int d;
-       int s;
-       time_t change;
-       long offset; /* Match type of _timezone. */
+  char ch;
+  int m;
+  int n;
+  int d;
+  int s;
+  time_t change;
+  long offset; /* Match type of _timezone. */
 } __tzrule_type;
 
 typedef struct __tzinfo_struct
 {
-       int __tznorth;
-       int __tzyear;
-       __tzrule_type  __tzrule [2];
+  int __tznorth;
+  int __tzyear;
+  __tzrule_type __tzrule[2];
 } __tzinfo_type;
 
-__tzinfo_type *__gettzinfo(void);
+__tzinfo_type *_EXFUN (__gettzinfo, (_VOID));
+
+#ifdef HAVE_GETDATE
+#if __XSI_VISIBLE >= 4
+#ifndef _REENT_ONLY
+#define getdate_err (*__getdate_err())
+int *_EXFUN(__getdate_err,(_VOID));
+
+struct tm *    _EXFUN(getdate, (const char *));
+/* getdate_err is set to one of the following values to indicate the error.
+     1  the DATEMSK environment variable is null or undefined,
+     2  the template file cannot be opened for reading,
+     3  failed to get file status information,
+     4  the template file is not a regular file,
+     5  an error is encountered while reading the template file,
+     6  memory allication failed (not enough memory available),
+     7  there is no line in the template that matches the input,
+     8  invalid input specification  */
+#endif /* !_REENT_ONLY */
+#endif /* __XSI_VISIBLE >= 4 */
 
-extern long _timezone;
-extern int _daylight;
-extern char *_tzname[2];
+#if __GNU_VISIBLE
+/* getdate_r returns the error code as above */
+int            _EXFUN(getdate_r, (const char *, struct tm *));
+#endif /* __GNU_VISIBLE */
+#endif /* HAVE_GETDATE */
 
+/* defines for the opengroup specifications Derived from Issue 1 of the SVID.  */
+#if __SVID_VISIBLE || __XSI_VISIBLE
+extern __IMPORT long _timezone;
+extern __IMPORT int _daylight;
+#endif
+#if __POSIX_VISIBLE
+extern __IMPORT char *_tzname[2];
+
+/* POSIX defines the external tzname being defined in time.h */
 #ifndef tzname
 #define tzname _tzname
 #endif
+#endif /* __POSIX_VISIBLE */
 
-#endif /* NEWLIBGLUE_TIME_H */
+
+#endif
diff --git a/include/time_types.h b/include/time_types.h
new file mode 100644 (file)
index 0000000..6d1bd61
--- /dev/null
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Florian Schmidt <florian.schmidt@neclab.eu>
+ *
+ * Copyright (c) 2018, NEC Labs Europe, NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* This header does by design not have include guards, so that it can be
+ * included from multiple files. The __NEED_x macros instead make sure that
+ * only those definitions are included that are required by that specific
+ * file, and only if they haven't been defined on a previous pass through
+ * this file.
+ */
+#ifndef __NEWLIB_TIME_TYPES__
+#define __NEWLIB_TIME_TYPES__
+
+#include <uk/arch/types.h>
+
+#if (defined __NEED_time_t && !defined __DEFINED_time_t)
+typedef long time_t;
+#define __DEFINED_time_t
+#endif
+
+#if (defined __NEED_suseconds_t && !defined __DEFINED_suseconds_t)
+typedef long suseconds_t;
+#define __DEFINED_suseconds_t
+#endif
+
+#if (defined __NEED_struct_timeval && !defined __DEFINED_struct_timeval)
+struct timeval {
+       time_t      tv_sec;
+       suseconds_t tv_usec;
+};
+#define __DEFINED_struct_timeval
+#endif
+
+#if (defined __NEED_struct_timespec && !defined __DEFINED_struct_timespec)
+struct timespec {
+       time_t tv_sec;
+       long   tv_nsec;
+};
+#define __DEFINED_struct_timespec
+#endif
+
+#if defined(__NEED_timer_t) && !defined(__DEFINED_timer_t)
+typedef void *timer_t;
+#define __DEFINED_timer_t
+#endif
+
+#if (defined __NEED_clockid_t && !defined __DEFINED_clockid_t)
+typedef int clockid_t;
+#define __DEFINED_clockid_t
+#endif
+
+#if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t)
+typedef long clock_t;
+#define __DEFINED_clock_t
+#endif
+
+#endif /* __NEWLIB_TIME_TYPES__ */
index 701ade6a72c0919f2b9a6e7ae9a625eebfc1e3a2..9d654cff19d1f29e912d1e318186c9dfe0e052c5 100644 (file)
@@ -3,7 +3,7 @@
 
 #define __NEED_time_t
 #define __NEED_struct_timespec
-#include <uk/time_types.h>
+#include <time_types.h>
 
 /* newlib guards */
 #define __time_t_defined
index bb840cf786cf16adbfad36d6991a1e22590c104d..78c462bd703c745c25aeaa9a878827180ba68689 100644 (file)
@@ -41,7 +41,7 @@
 #define __NEED_timer_t
 #define __NEED_clockid_t
 #define __NEED_clock_t
-#include <uk/time_types.h>
+#include <time_types.h>
 
 /* newlib guards */
 #define __time_t_defined
index b1cf5c1cb3315bc1aa7565ec00c055f1e6607693..967b90c9325c2bfbd0184accf6b33fa579b695aa 100644 (file)
@@ -140,7 +140,7 @@ struct winsize {
 #define SIOCDEVPRIVATE     0x89F0
 #define SIOCPROTOPRIVATE   0x89E0
 
-int ioctl (int, int, ...);
+int ioctl (int, unsigned long int, ...);
 
 #ifdef __cplusplus
 }
diff --git a/patches/0017-Remove-__nonnull-coliding-with-existent-macro.patch b/patches/0017-Remove-__nonnull-coliding-with-existent-macro.patch
new file mode 100644 (file)
index 0000000..aad503a
--- /dev/null
@@ -0,0 +1,266 @@
+From d5dccbc80d1d8b52178b3a6a232d51f1965d0b42 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Eduard=20Vintil=C4=83?= <eduard.vintila47@gmail.com>
+Date: Sat, 6 May 2023 02:26:51 +0300
+Subject: [PATCH] Remove `__nonnull()` coliding with existent macro
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The `__nonnull` macro is already defined in `uk/essentials.h`, so we
+remove newlib's definition and references to its parametrized macro,
+`__nonnull()`.
+
+Co-authored-by: Stefan Jumarea <stefanjumarea02@gmail.com>
+Signed-off-by: Eduard Vintilă <eduard.vintila47@gmail.com>
+---
+ newlib/libc/include/pthread.h   | 56 ++++++++++++++++-----------------
+ newlib/libc/include/stdlib.h    |  7 +++--
+ newlib/libc/include/string.h    |  3 +-
+ newlib/libc/include/sys/cdefs.h |  9 +-----
+ 4 files changed, 35 insertions(+), 40 deletions(-)
+
+diff --git a/newlib/libc/include/pthread.h b/newlib/libc/include/pthread.h
+index 516131d..d2b7d8f 100644
+--- a/newlib/libc/include/pthread.h
++++ b/newlib/libc/include/pthread.h
+@@ -41,7 +41,7 @@ struct _pthread_cleanup_context {
+ /* Register Fork Handlers */
+ int   _EXFUN(pthread_atfork,(void (*prepare)(void), void (*parent)(void),
+                    void (*child)(void)));
+-          
++
+ /* Mutex Initialization Attributes, P1003.1c/Draft 10, p. 81 */
+ int   _EXFUN(pthread_mutexattr_init, (pthread_mutexattr_t *__attr));
+@@ -69,7 +69,7 @@ int  _EXFUN(pthread_mutex_init,
+ int   _EXFUN(pthread_mutex_destroy, (pthread_mutex_t *__mutex));
+ /* This is used to statically initialize a pthread_mutex_t. Example:
+-  
++
+     pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+  */
+@@ -90,7 +90,7 @@ int  _EXFUN(pthread_mutex_timedlock,
+ #endif /* _POSIX_TIMEOUTS */
+ /* Condition Variable Initialization Attributes, P1003.1c/Draft 10, p. 96 */
+- 
++
+ int   _EXFUN(pthread_condattr_init, (pthread_condattr_t *__attr));
+ int   _EXFUN(pthread_condattr_destroy, (pthread_condattr_t *__attr));
+@@ -104,34 +104,34 @@ int      _EXFUN(pthread_condattr_getpshared,
+               (_CONST pthread_condattr_t *__attr, int *__pshared));
+ int   _EXFUN(pthread_condattr_setpshared,
+               (pthread_condattr_t *__attr, int __pshared));
+- 
++
+ /* Initializing and Destroying a Condition Variable, P1003.1c/Draft 10, p. 87 */
+- 
++
+ int   _EXFUN(pthread_cond_init,
+       (pthread_cond_t *__cond, _CONST pthread_condattr_t *__attr));
+ int   _EXFUN(pthread_cond_destroy, (pthread_cond_t *__mutex));
+- 
++
+ /* This is used to statically initialize a pthread_cond_t. Example:
+-  
++
+     pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+  */
+- 
++
+ #define PTHREAD_COND_INITIALIZER _PTHREAD_COND_INITIALIZER
+- 
++
+ /* Broadcasting and Signaling a Condition, P1003.1c/Draft 10, p. 101 */
+- 
++
+ int   _EXFUN(pthread_cond_signal, (pthread_cond_t *__cond));
+ int   _EXFUN(pthread_cond_broadcast, (pthread_cond_t *__cond));
+- 
++
+ /* Waiting on a Condition, P1003.1c/Draft 10, p. 105 */
+- 
++
+ int   _EXFUN(pthread_cond_wait,
+       (pthread_cond_t *__cond, pthread_mutex_t *__mutex));
+- 
++
+ int   _EXFUN(pthread_cond_timedwait,
+               (pthread_cond_t *__cond, pthread_mutex_t *__mutex,
+               _CONST struct timespec *__abstime));
+- 
++
+ #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
+ /* Thread Creation Scheduling Attributes, P1003.1c/Draft 10, p. 120 */
+@@ -171,15 +171,15 @@ int      _EXFUN(pthread_setschedprio, (pthread_t thread, int prio));
+ #endif /* defined(_POSIX_THREAD_PRIORITY_SCHEDULING) */
+ #if __GNU_VISIBLE
+-int   pthread_getname_np(pthread_t, char *, size_t) __nonnull(2);
++int   pthread_getname_np(pthread_t, char *, size_t);
+-int   pthread_setname_np(pthread_t, const char *) __nonnull(2);
++int   pthread_setname_np(pthread_t, const char *);
+ #endif
+ #if defined(_POSIX_THREAD_PRIO_INHERIT) || defined(_POSIX_THREAD_PRIO_PROTECT)
+ /* Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 */
+- 
++
+ int   _EXFUN(pthread_mutexattr_setprotocol,
+       (pthread_mutexattr_t *__attr, int __protocol));
+ int   _EXFUN(pthread_mutexattr_getprotocol,
+@@ -227,14 +227,14 @@ int      _EXFUN(pthread_attr_getguardsize,
+ int   _EXFUN(pthread_attr_setguardsize,
+       (pthread_attr_t *__attr, size_t __guardsize));
+-/* POSIX thread APIs beyond the POSIX standard but provided 
++/* POSIX thread APIs beyond the POSIX standard but provided
+  * in GNU/Linux. They may be provided by other OSes for
+  * compatibility.
+  */
+ #if __GNU_VISIBLE
+-#if defined(__rtems__) 
++#if defined(__rtems__)
+ int   _EXFUN(pthread_attr_setaffinity_np,
+-      (pthread_attr_t *__attr, size_t __cpusetsize, 
++      (pthread_attr_t *__attr, size_t __cpusetsize,
+       const cpu_set_t *__cpuset));
+ int   _EXFUN(pthread_attr_getaffinity_np,
+       (const pthread_attr_t *__attr, size_t __cpusetsize,
+@@ -291,13 +291,13 @@ void     _EXFUN(pthread_yield, (void));
+ /* Dynamic Package Initialization */
+ /* This is used to statically initialize a pthread_once_t. Example:
+-  
++
+     pthread_once_t once = PTHREAD_ONCE_INIT;
+-  
++
+     NOTE:  This is named inconsistently -- it should be INITIALIZER.  */
+- 
++
+ #define PTHREAD_ONCE_INIT _PTHREAD_ONCE_INIT
+- 
++
+ int   _EXFUN(pthread_once,
+       (pthread_once_t *__once_control, void (*__init_routine)(void)));
+@@ -375,12 +375,12 @@ void     _EXFUN(_pthread_cleanup_pop_restore,
+ #endif /* __GNU_VISIBLE */
+ #if defined(_POSIX_THREAD_CPUTIME)
+- 
++
+ /* Accessing a Thread CPU-time Clock, P1003.4b/D8, p. 58 */
+- 
++
+ int   _EXFUN(pthread_getcpuclockid,
+       (pthread_t __pthread_id, clockid_t *__clock_id));
+- 
++
+ #endif /* defined(_POSIX_THREAD_CPUTIME) */
+@@ -419,7 +419,7 @@ int        _EXFUN(pthread_spin_unlock, (pthread_spinlock_t *__spinlock));
+ #if defined(_POSIX_READER_WRITER_LOCKS)
+ /* This is used to statically initialize a pthread_rwlock_t. Example:
+-  
++
+     pthread_mutex_t mutex = PTHREAD_RWLOCK_INITIALIZER;
+  */
+diff --git a/newlib/libc/include/stdlib.h b/newlib/libc/include/stdlib.h
+index f81b112..204c268 100644
+--- a/newlib/libc/include/stdlib.h
++++ b/newlib/libc/include/stdlib.h
+@@ -18,6 +18,7 @@
+ #include <sys/reent.h>
+ #include <sys/cdefs.h>
+ #include <machine/stdlib.h>
++#include <uk/essentials.h>
+ #ifndef __STRICT_ANSI__
+ #include <alloca.h>
+ #endif
+@@ -39,13 +40,13 @@
+ _BEGIN_STD_C
+-typedef struct 
++typedef struct
+ {
+   int quot; /* quotient */
+   int rem; /* remainder */
+ } div_t;
+-typedef struct 
++typedef struct
+ {
+   long quot; /* quotient */
+   long rem; /* remainder */
+@@ -338,7 +339,7 @@ static inline int posix_memalign(void **memptr, size_t align, size_t size)
+ }
+ #endif /* __UK_HAVE_POSIX_MEMALIGN__ */
+ #else
+-int _EXFUN(__nonnull (1) posix_memalign,(void **, size_t, size_t));
++int _EXFUN(__nonnull posix_memalign,(void **, size_t, size_t));
+ #endif
+ #endif
+diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h
+index 9c536f3..21e9088 100644
+--- a/newlib/libc/include/string.h
++++ b/newlib/libc/include/string.h
+@@ -11,6 +11,7 @@
+ #include <sys/reent.h>
+ #include <sys/cdefs.h>
+ #include <sys/features.h>
++#include <uk/essentials.h>
+ #define __need_size_t
+ #define __need_NULL
+@@ -169,7 +170,7 @@ int         _EXFUN(strverscmp,(const char *, const char *));
+    sure here. */
+ #if __GNU_VISIBLE && !defined(basename)
+ # define basename basename
+-char  *_EXFUN(__nonnull (1) basename,(const char *)) __asm__(__ASMNAME("__gnu_basename"));
++char  *_EXFUN(__nonnull basename,(const char *)) __asm__(__ASMNAME("__gnu_basename"));
+ #endif
+ #include <sys/string.h>
+diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
+index aff864b..85e0129 100644
+--- a/newlib/libc/include/sys/cdefs.h
++++ b/newlib/libc/include/sys/cdefs.h
+@@ -397,13 +397,6 @@
+ #define       __noinline
+ #endif
+-#if __GNUC_PREREQ__(3, 3)
+-#define       __nonnull(x)    __attribute__((__nonnull__(x)))
+-#define       __nonnull_all   __attribute__((__nonnull__))
+-#else
+-#define       __nonnull(x)
+-#define       __nonnull_all
+-#endif
+ #if __GNUC_PREREQ__(3, 4)
+ #define       __fastcall      __attribute__((__fastcall__))
+@@ -649,7 +642,7 @@
+  * Type Safety Checking
+  *
+  * Clang provides additional attributes to enable checking type safety
+- * properties that cannot be enforced by the C type system. 
++ * properties that cannot be enforced by the C type system.
+  */
+ #if __has_attribute(__argument_with_type_tag__) && \
+-- 
+2.40.0
+