[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v3 11/12] lib/uksched: Add re-entrancy support for newlib


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Fri, 22 Mar 2019 17:16:00 +0200
  • Cc: Florian.Schmidt@xxxxxxxxx
  • Delivery-date: Fri, 22 Mar 2019 15:16:57 +0000
  • Ironport-phdr: 9a23:SndUYxyJ87TUyQjXCy+O+j09IxM/srCxBDY+r6Qd2+sfIJqq85mqBkHD//Il1AaPAdyDra0dwLWN+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhUiDanY75+MRq6oAffu8ILnYZsN6E9xwfTrHBVYepW32RoJVySnxb4+Mi9+YNo/jpTtfw86cNOSL32cKskQ7NWCjQmKH0169bwtRbfVwuP52ATXXsQnxFVHgXK9hD6XpP2sivnqupw3TSRMMPqQbwoXzmp8qFmQwLqhigaLT406GHZhNJtgqxVoxyvoB5ww4DPbY2JKPZzZL/RcMkGSWZdWMtaSixPApm7b4sKF+cMI+FYr5Lhp1sPqxu1GA+iBP73yj9Vm3T72rE10+M6EQHa3QwgGcgCsHDJrNXtKacfSvy6zLLSwTXbcvNZwi3x6JLPch04p/yHQLF+cdLJxEUyGA7Jk0+cpI/lMj+PyOgBrWqW4/BuWO63lmIqpBx9riKsy8oskIXFmIwYx17e+Slkz4s5O9u1Q1Nhb9G+CptfrSSaOpNzQsMlXm5npj43yqYDuZ6nZCgKz4knxwLHZ/yHbYeI5hXjWf6PITd9nn1leba/iwyu/ki70OH8TtS0301QoipfldnArnEN1xrN5cibUvZx40is1SuV2w3Q6uxIO144mbTZJpI7zLM8jp8Tvl7CHi/ylkX2lqiWdkA89+e07OTneanmpp6aN4NujgH+L7wumtGkDOskKQgCRXCb+fmn27H55035R61GjucqnanBrJDaOcMbq7a8Aw9U1IYj6hG/Dyy/3NsFg3YHMkxKeBacgojtOlHOO+z4Deylj1WjjjhrwerKPrr7ApXCNnLDiqvufa5h605Azwo+1dBR55ZTCrEbIfL8QEnxuMbFABAlMwy0xufnB8hh1o4FX2KAHLOWMKfIvlCT/O4gPfSMN8cpv2P4Kv4k4OWrgXInlFs1eaiywYBReH2+WPN8LBa3e33p1/wGCnsLuEIaUfT3wAmJViVPZnD0W78k+xkwE8S+EI2FXIf70+/J5zuyApADPjMOMVuLC3q9L4g=
  • Ironport-sdr: b1GtwefUROEsWURqbdG4unM/PF4ktIpktmxoPS3oO0F3ZJ7LyBdyjzDN1hXdrdZhT0tk0U33nF AB2TDmZZqc9A==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Re-entrancy in newlib is provided by mapping a _reent attribute to
each thread. The attribute encapsulates the global state specific
to each thread (e.g. errno, standard IO streams, signal state, etc).

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
 lib/uksched/exportsyms.uk       |  3 +++
 lib/uksched/include/uk/thread.h |  4 ++--
 lib/uksched/thread.c            | 29 +++++++++++++++++++++++++++--
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/lib/uksched/exportsyms.uk b/lib/uksched/exportsyms.uk
index c67892c4..5297affd 100644
--- a/lib/uksched/exportsyms.uk
+++ b/lib/uksched/exportsyms.uk
@@ -30,3 +30,6 @@ uk_thread_attr_set_prio
 uk_thread_attr_get_prio
 uk_thread_attr_set_timeslice
 uk_thread_attr_get_timeslice
+
+# Newlib related
+__getreent
\ No newline at end of file
diff --git a/lib/uksched/include/uk/thread.h b/lib/uksched/include/uk/thread.h
index f3891c29..f8bdbb5e 100644
--- a/lib/uksched/include/uk/thread.h
+++ b/lib/uksched/include/uk/thread.h
@@ -30,7 +30,7 @@
 
 #include <stdint.h>
 #include <stdbool.h>
-#ifdef CONFIG_HAVE_LIBC
+#ifdef CONFIG_LIBNEWLIBC
 #include <sys/reent.h>
 #endif
 #include <uk/arch/lcpu.h>
@@ -57,7 +57,7 @@ struct uk_thread {
        bool detached;
        struct uk_waitq waiting_threads;
        struct uk_sched *sched;
-#ifdef CONFIG_HAVE_LIBC
+#ifdef CONFIG_LIBNEWLIBC
        struct _reent reent;
 #endif
 };
diff --git a/lib/uksched/thread.c b/lib/uksched/thread.c
index 4d931a74..72adfc68 100644
--- a/lib/uksched/thread.c
+++ b/lib/uksched/thread.c
@@ -29,6 +29,7 @@
  * Thread definitions
  * Ported from Mini-OS
  */
+#include <string.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <uk/plat/config.h>
@@ -61,6 +62,30 @@ static void init_sp(unsigned long *sp, char *stack,
        stack_push(sp, (unsigned long) data);
 }
 
+#ifdef CONFIG_LIBNEWLIBC
+static void reent_init(struct _reent *reent)
+{
+       _REENT_INIT_PTR(reent);
+#if 0
+       /* TODO initialize basic signal handling */
+       _init_signal_r(myreent);
+#endif
+}
+
+struct _reent *__getreent(void)
+{
+       struct _reent *_reent;
+       struct uk_sched *s = uk_sched_get_default();
+
+       if (!s || !uk_sched_started(s))
+               _reent = _impure_ptr;
+       else
+               _reent = &uk_thread_current()->reent;
+
+       return _reent;
+}
+#endif /* CONFIG_LIBNEWLIBC */
+
 int uk_thread_init(struct uk_thread *thread,
                struct ukplat_ctx_callbacks *cbs, struct uk_alloc *allocator,
                const char *name, void *stack,
@@ -91,8 +116,8 @@ int uk_thread_init(struct uk_thread *thread,
        uk_waitq_init(&thread->waiting_threads);
        thread->sched = NULL;
 
-#ifdef CONFIG_HAVE_LIBC
-       //TODO _REENT_INIT_PTR(&thread->reent);
+#ifdef CONFIG_LIBNEWLIBC
+       reent_init(&thread->reent);
 #endif
 
        uk_pr_info("Thread \"%s\": pointer: %p, stack: %p\n",
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.