[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: Sun, 10 Mar 2019 22:10:04 +0200
  • Cc: Florian.Schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx, sharan.santhanam@xxxxxxxxx
  • Delivery-date: Sun, 10 Mar 2019 20:10:21 +0000
  • Ironport-phdr: 9a23:vCMBJBc8QXU4YDWbWSlRuwLmlGMj4u6mDksu8pMizoh2WeGdxc26ZBaN2/xhgRfzUJnB7Loc0qyK6vimATVIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfK9+IA+qoQnMq8IbnZZsJqEtxxXTv3BGYf5WxWRmJVKSmxbz+MK994N9/ipTpvws6ddOXb31cKokQ7NYCi8mM30u683wqRbDVwqP6WACXWgQjxFFHhLK7BD+Xpf2ryv6qu9w0zSUMMHqUbw5Xymp4qF2QxHqlSgHLSY0/mHJhMJtgqxVoxWvqB5xw4PPfI2ZKOBzcr/HcN8GWWZMWNtaWSxbAoO7aosCF/QMPeFDr4nhplsOqwa1Cw+xBOP31z9Dm3j70rE90+Q6DQHG3QogE8gKsHTJtNX1KbwfXvyuzKXS1TXDcuhZ1S3n6IjPax0sp+yHU7FoccfJ1EUiGB7Jgk+TpIHlJT+ZyPoBvmqB4+duTe6jlmEqpxxrrjWsxsogkJfFi4wbx1ze6Cl0z5g5KNulQ0Bhe9GkCoFftySCOotzRcMtXn9ntT4hyr0DpZ67ZC8KyIk7xxLHa/yIbYyI4hX7WeaPJDd3nnNleLalixmu6kis0PX8VtSv31pQtCpFlcHAtnEL1xPN9siKUuZx80i81TqV1A3e6vtILV4qmafZMZIszKY8lp8JvkTCGi/2ll/2jKiTdkg85ueo7P/nYqnnpp+aLYN0jhz+MrwzmsGkHes4KRICX3CG+eunzrHj50r5TK1QjvIqiqnZrIzaJcMDq668Ag9V1Icj6xGkDzu/zdsXg2cHI0xBeB+ci4jpOkrOIOzjDfuljFWjjjFry+rBPr37DZXHNmLDn6v5fbZh905czxI+w9Bb55JTELEBIej8WknruNLFEhA5Mwm0w+f6B9VhzY4eX3yADbOdMKzIqlCE/PwgI/SUbo8PpDn9M+Ql5+LpjXIhgl8dfbOm3YENZ3C+BPhmOF+WYXzwgtcBC2gKuBAxTOnxhV2ETzFce3KyULgn6T0hFo2mEJ/JRpqxj7yZwCe7AppWa3hdClCNFHfocIOEV+0PaCKPPMBhlD0FWqa7S4I60xGhqhP1y759IeXP4CEXq4/j3sBv5+LPjREy6SB0D8OF3mCNUmF0hGIISyUo3KB4pUxy1leD0at/g/xGDtFT4e1GXRs+NZHG1ON2Ec79Wh+SNuuOHVOnRNShGnQ9Q8w8x/cKYl1hAJOygxaF2DClUJEPkLneL5sv7qPal1zsP9s1n33Bz7UgiR8iX9NSHWa9wLZi/U7JANiawA2ii6+2ePFEj2b2/2CZwD/WsQ==
  • Ironport-sdr: uzRuVnzbEWcBFQSOAyoaBZvb5OCunhzXmWvUoL8ESgS9SEZHHAWPfN0K1bmmKnjJ7EjmGzk63/ Ezb1yW5od3cQ==
  • 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>
---
 lib/uksched/include/uk/thread.h |  4 ++--
 lib/uksched/thread.c            | 28 ++++++++++++++++++++++++++--
 2 files changed, 28 insertions(+), 4 deletions(-)

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 e52bb30f..64fe6a2b 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,29 @@ 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;
+
+       if (!uk_sched_started(uk_sched_get_default()))
+               _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 +115,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®.