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

[Minios-devel] [UNIKRAFT/RUBY PATCH 06/16] core: Add thread related definitions



With pthread-embedded, special care has to be taken when dealing with
conversions from pthread_t to scalar values. Therefore we have to define our
own conversion functions. We also copy ruby_fill_thread_id_string() function
from origin to glue in order to avoid patching the origin code.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 Makefile.uk           |  2 ++
 include/ruby/config.h |  9 ++++++++
 thread.c              | 52 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 thread.c

diff --git a/Makefile.uk b/Makefile.uk
index 98e738f..d65a9c3 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -88,6 +88,8 @@ LIBRUBY_CFLAGS-y += -std=gnu99 -D_FORTIFY_SOURCE=2 \
         -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard \
        -DRUBY_EXPORT -DCANONICALIZATION_FOR_MATHN
 
+LIBRUBY_SRCS-y += $(LIBRUBY_BASE)/thread.c|unikraft
+
 ifeq ($(CONFIG_LIBRUBY_MINI),y)
 LIBRUBY_SRCS-y += $(LIBRUBY_SRC)/dmydln.c
 LIBRUBY_SRCS-y += $(LIBRUBY_SRC)/miniinit.c
diff --git a/include/ruby/config.h b/include/ruby/config.h
index 81992de..e9ff4d1 100644
--- a/include/ruby/config.h
+++ b/include/ruby/config.h
@@ -429,4 +429,13 @@
 #define USE_MJIT 1
 #define HAVE_PTHREAD_H 1
 #define RUBY_PLATFORM "x86_64-unikraft"
+
+/* Threads */
+#define NON_SCALAR_THREAD_ID 1
+#ifndef fill_thread_id_str
+# define fill_thread_id_string(thid, buf) ((void 
*)(uintptr_t)pthread_to_unsigned_long(&thid))
+# define fill_thread_id_str(th) (void)0
+# define thread_id_str(th) ((void 
*)(uintptr_t)pthread_to_unsigned_long(&(th)->thread_id))
+# define PRI_THREAD_ID "p"
+#endif
 #endif /* INCLUDE_RUBY_CONFIG_H */
diff --git a/thread.c b/thread.c
new file mode 100644
index 0000000..646649c
--- /dev/null
+++ b/thread.c
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright (C) 2004-2007 Koichi Sasada
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/* ruby_fill_thread_id_string() is copied from Ruby's thread.c */
+
+#include "ruby/config.h"
+#include "ruby/thread_native.h"
+#include "vm_core.h"
+
+
+# ifdef NON_SCALAR_THREAD_ID
+const char *
+ruby_fill_thread_id_string(rb_nativethread_id_t thid, rb_thread_id_string_t 
buf)
+{
+    extern const char ruby_digitmap[];
+    size_t i;
+
+    buf[0] = '0';
+    buf[1] = 'x';
+    for (i = 0; i < sizeof(thid); i++) {
+# ifdef LITTLE_ENDIAN
+       size_t j = sizeof(thid) - i - 1;
+# else
+       size_t j = i;
+# endif
+       unsigned char c = (unsigned char)((char *)&thid)[j];
+       buf[2 + i * 2] = ruby_digitmap[(c >> 4) & 0xf];
+       buf[3 + i * 2] = ruby_digitmap[c & 0xf];
+    }
+    buf[sizeof(rb_thread_id_string_t)-1] = '\0';
+    return buf;
+}
+#endif
-- 
2.20.1


_______________________________________________
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®.