]> xenbits.xensource.com Git - unikraft/libs/musl.git/commitdiff
Make musl initialization work with unikraft RELEASE-0.10.0 RELEASE-0.6 RELEASE-0.7.0 RELEASE-0.8.0 RELEASE-0.9.0
authorCyril Soldani <cyril.soldani@uliege.be>
Thu, 10 Dec 2020 08:31:16 +0000 (09:31 +0100)
committerUnikraft <monkey@unikraft.io>
Wed, 13 Oct 2021 11:31:40 +0000 (11:31 +0000)
Work around some syscalls not being implemented in unikraft.

Signed-off-by: Cyril Soldani <cyril.soldani@uliege.be>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #3

patches/0013-init-no-mprotect.patch [new file with mode: 0644]
patches/0014-mmap-alloc.patch [new file with mode: 0644]
patches/0015-avoid-mmap-in-init_tls.patch [new file with mode: 0644]
patches/0016-avoid-arch_prctl.patch [new file with mode: 0644]

diff --git a/patches/0013-init-no-mprotect.patch b/patches/0013-init-no-mprotect.patch
new file mode 100644 (file)
index 0000000..8111f5d
--- /dev/null
@@ -0,0 +1,14 @@
+--- a/src/thread/pthread_create.c      2020-11-06 14:30:42.098195850 +0100
++++ b/src/thread/pthread_create.c      2020-11-06 14:41:51.039515090 +0100
+@@ -244,11 +244,6 @@
+               if (guard) {
+                       map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0);
+                       if (map == MAP_FAILED) goto fail;
+-                      if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE)
+-                          && errno != ENOSYS) {
+-                              __munmap(map, size);
+-                              goto fail;
+-                      }
+               } else {
+                       map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+                       if (map == MAP_FAILED) goto fail;
diff --git a/patches/0014-mmap-alloc.patch b/patches/0014-mmap-alloc.patch
new file mode 100644 (file)
index 0000000..d860994
--- /dev/null
@@ -0,0 +1,37 @@
+--- a/src/mman/mmap.c  2020-11-06 14:33:14.588895081 +0100
++++ b/src/mman/mmap.c  2020-11-06 14:54:26.393274709 +0100
+@@ -6,6 +6,9 @@
+ #include "syscall.h"
+ #include "libc.h"
++#include <uk/alloc.h>
++#include <uk/assert.h>
++
+ static void dummy(void) { }
+ weak_alias(dummy, __vm_wait);
+@@ -26,11 +29,22 @@
+       if (flags & MAP_FIXED) {
+               __vm_wait();
+       }
++        if (start == NULL && fd == -1 && (flags & MAP_ANON)) {
++            start = NULL;
++            uk_posix_memalign(
++                    uk_alloc_get_default(),
++                    &start,
++                    4096, // TODO read actual page size
++                    len);
++            UK_ASSERT(start != NULL);
++            ret = (long) start;
++        } else {
+ #ifdef SYS_mmap2
+-      ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
++            ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
+ #else
+-      ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off);
++            ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off);
+ #endif
++        }
+       /* Fixup incorrect EPERM from kernel. */
+       if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED))
+               ret = -ENOMEM;
diff --git a/patches/0015-avoid-mmap-in-init_tls.patch b/patches/0015-avoid-mmap-in-init_tls.patch
new file mode 100644 (file)
index 0000000..26ca81c
--- /dev/null
@@ -0,0 +1,36 @@
+--- a/src/env/__init_tls.c     2020-11-06 14:11:05.226052792 +0100
++++ b/src/env/__init_tls.c     2020-11-06 14:37:32.885073260 +0100
+@@ -8,6 +8,9 @@
+ #include "atomic.h"
+ #include "syscall.h"
++#include <uk/alloc.h>
++#include <uk/assert.h>
++
+ int __init_tp(void *p)
+ {
+       pthread_t td = p;
+@@ -114,16 +117,13 @@
+               + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN;
+       if (libc.tls_size > sizeof builtin_tls) {
+-#ifndef SYS_mmap2
+-#define SYS_mmap2 SYS_mmap
+-#endif
+-              mem = (void *)__syscall(
+-                      SYS_mmap2,
+-                      0, libc.tls_size, PROT_READ|PROT_WRITE,
+-                      MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+-              /* -4095...-1 cast to void * will crash on dereference anyway,
+-               * so don't bloat the init code checking for error codes and
+-               * explicitly calling a_crash(). */
++                mem = NULL;
++                uk_posix_memalign(
++                        uk_alloc_get_default(),
++                        &mem,
++                        4096, // TODO read actual page size
++                        libc.tls_size);
++                UK_ASSERT(mem != NULL);
+       } else {
+               mem = builtin_tls;
+       }
diff --git a/patches/0016-avoid-arch_prctl.patch b/patches/0016-avoid-arch_prctl.patch
new file mode 100644 (file)
index 0000000..3090ea6
--- /dev/null
@@ -0,0 +1,13 @@
+--- a/src/thread/x86_64/__set_thread_area.s    2018-02-22 19:39:19.000000000 +0100
++++ b/src/thread/x86_64/__set_thread_area.s    2020-11-13 12:26:36.600544392 +0100
+@@ -3,8 +3,6 @@
+ .global __set_thread_area
+ .type __set_thread_area,@function
+ __set_thread_area:
+-      mov %rdi,%rsi           /* shift for syscall */
+-      movl $0x1002,%edi       /* SET_FS register */
+-      movl $158,%eax          /* set fs segment to */
+-      syscall                 /* arch_prctl(SET_FS, arg)*/
++      wrfsbase %rdi
++       movq $0,%rax
+       ret