+++ /dev/null
-From b97146b7c5633fc561692c21546f52b3c7164dbb Mon Sep 17 00:00:00 2001
-From: Dragos Iulian Argint <dragosargint21@gmail.com>
-Date: Sat, 7 May 2022 11:23:38 +0300
-Subject: [PATCH] lib-musl: Use `uk_syscall_r()` for `__syscall_cp_c()`
-
-If we have a system call number known only at runtime then
-we will use `uk_syscall_r()` from syscall shim. This
-makes a function call (not a binary system call), but knows
-how to demultiplex depending on the number given as a parameter.
-
-Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
----
- src/thread/pthread_cancel.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/thread/pthread_cancel.c b/src/thread/pthread_cancel.c
-index 3d22922..8321734 100644
---- a/src/thread/pthread_cancel.c
-+++ b/src/thread/pthread_cancel.c
-@@ -30,7 +30,7 @@ long __syscall_cp_c(syscall_arg_t nr,
-
- if ((st=(self=__pthread_self())->canceldisable)
- && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close))
-- return __syscall(nr, u, v, w, x, y, z);
-+ return uk_syscall6_r(nr, u, v, w, x, y, z);
-
- r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z);
- if (r==-EINTR && nr!=SYS_close && self->cancel &&
---
-2.17.1
-
+++ /dev/null
-From db5c67091a7a9817668aaa61a782eeb5ee83847b Mon Sep 17 00:00:00 2001
-From: Dragos Iulian Argint <dragosargint21@gmail.com>
-Date: Sat, 7 May 2022 11:10:07 +0300
-Subject: [PATCH] lib-musl: Use `uk_syscall_r()` for `do_setxid()`
-
-If we have a system call number known only at runtime then
-we will use `uk_syscall_r()` from syscall shim. This
-makes a function call (not a binary system call), but knows
-how to demultiplex depending on the number given as a parameter.
-
-Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
----
- src/unistd/setxid.c | 3 ++-
- 1 file changed, 2 insertions(+), 1 deletion(-)
-
-diff --git a/src/unistd/setxid.c b/src/unistd/setxid.c
-index 0239f8a..d994de9 100644
---- a/src/unistd/setxid.c
-+++ b/src/unistd/setxid.c
-@@ -3,6 +3,7 @@
- #include "syscall.h"
- #include "libc.h"
- #include "pthread_impl.h"
-+#include <uk/syscall.h>
-
- struct ctx {
- int id, eid, sid;
-@@ -13,7 +14,7 @@ static void do_setxid(void *p)
- {
- struct ctx *c = p;
- if (c->err>0) return;
-- int ret = -__syscall(c->nr, c->id, c->eid, c->sid);
-+ int ret = -uk_syscall_r(c->nr, c->id, c->eid, c->sid);
- if (ret && !c->err) {
- /* If one thread fails to set ids after another has already
- * succeeded, forcibly killing the process is the only safe
---
-2.17.1
-
+++ /dev/null
-From 0707c3af258a7859bd91e3efa468d39a5a151a3f Mon Sep 17 00:00:00 2001
-From: Gaulthier Gain <gaulthier.gain@uliege.be>
-Date: Sat, 25 Jan 2020 14:18:41 +0100
-Subject: [PATCH] Use uk/bits/syscall_nrs.h instead of musl internal
- bits/syscall.h
-
-Signed-off-by: Gaulthier Gain <gaulthier.gain@uliege.be>
----
- include/sys/syscall.h | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/include/sys/syscall.h b/include/sys/syscall.h
-index 24987dd..918de59 100644
---- a/include/sys/syscall.h
-+++ b/include/sys/syscall.h
-@@ -1,6 +1,6 @@
- #ifndef _SYS_SYSCALL_H
- #define _SYS_SYSCALL_H
-
--#include <bits/syscall.h>
-+#include <uk/bits/syscall_nrs.h>
-
- #endif
---
-2.20.1
-
--- /dev/null
+From db5c67091a7a9817668aaa61a782eeb5ee83847b Mon Sep 17 00:00:00 2001
+From: Dragos Iulian Argint <dragosargint21@gmail.com>
+Date: Sat, 7 May 2022 11:10:07 +0300
+Subject: [PATCH] lib-musl: Use `uk_syscall_r()` for `do_setxid()`
+
+If we have a system call number known only at runtime then
+we will use `uk_syscall_r()` from syscall shim. This
+makes a function call (not a binary system call), but knows
+how to demultiplex depending on the number given as a parameter.
+
+Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
+---
+ src/unistd/setxid.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/unistd/setxid.c b/src/unistd/setxid.c
+index 0239f8a..d994de9 100644
+--- a/src/unistd/setxid.c
++++ b/src/unistd/setxid.c
+@@ -3,6 +3,7 @@
+ #include "syscall.h"
+ #include "libc.h"
+ #include "pthread_impl.h"
++#include <uk/syscall.h>
+
+ struct ctx {
+ int id, eid, sid;
+@@ -13,7 +14,7 @@ static void do_setxid(void *p)
+ {
+ struct ctx *c = p;
+ if (c->err>0) return;
+- int ret = -__syscall(c->nr, c->id, c->eid, c->sid);
++ int ret = -uk_syscall_r(c->nr, c->id, c->eid, c->sid);
+ if (ret && !c->err) {
+ /* If one thread fails to set ids after another has already
+ * succeeded, forcibly killing the process is the only safe
+--
+2.17.1
+
+++ /dev/null
-From 0a1ffcddc9c4e3dfb251b8ccf153821448f97048 Mon Sep 17 00:00:00 2001
-From: Gaulthier Gain <gaulthier.gain@uliege.be>
-Date: Sat, 25 Jan 2020 15:45:06 +0100
-Subject: [PATCH] Update __syscall_cp to use syscalls from syscall shim layer
-
-Signed-off-by: Gaulthier Gain <gaulthier.gain@uliege.be>
----
- src/thread/__syscall_cp.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/thread/__syscall_cp.c b/src/thread/__syscall_cp.c
-index 09a2be8..e22e75b 100644
---- a/src/thread/__syscall_cp.c
-+++ b/src/thread/__syscall_cp.c
-@@ -8,7 +8,7 @@ static long sccp(syscall_arg_t nr,
- syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
- syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
- {
-- return (__syscall)(nr, u, v, w, x, y, z);
-+ return (uk_syscall)(nr, u, v, w, x, y, z);
- }
-
- weak_alias(sccp, __syscall_cp_c);
---
-2.20.1
-
--- /dev/null
+From b97146b7c5633fc561692c21546f52b3c7164dbb Mon Sep 17 00:00:00 2001
+From: Dragos Iulian Argint <dragosargint21@gmail.com>
+Date: Sat, 7 May 2022 11:23:38 +0300
+Subject: [PATCH] lib-musl: Use `uk_syscall_r()` for `__syscall_cp_c()`
+
+If we have a system call number known only at runtime then
+we will use `uk_syscall_r()` from syscall shim. This
+makes a function call (not a binary system call), but knows
+how to demultiplex depending on the number given as a parameter.
+
+Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
+---
+ src/thread/pthread_cancel.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/thread/pthread_cancel.c b/src/thread/pthread_cancel.c
+index 3d22922..8321734 100644
+--- a/src/thread/pthread_cancel.c
++++ b/src/thread/pthread_cancel.c
+@@ -30,7 +30,7 @@ long __syscall_cp_c(syscall_arg_t nr,
+
+ if ((st=(self=__pthread_self())->canceldisable)
+ && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close))
+- return __syscall(nr, u, v, w, x, y, z);
++ return uk_syscall6_r(nr, u, v, w, x, y, z);
+
+ r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z);
+ if (r==-EINTR && nr!=SYS_close && self->cancel &&
+--
+2.17.1
+
--- /dev/null
+From 0a1ffcddc9c4e3dfb251b8ccf153821448f97048 Mon Sep 17 00:00:00 2001
+From: Gaulthier Gain <gaulthier.gain@uliege.be>
+Date: Sat, 25 Jan 2020 15:45:06 +0100
+Subject: [PATCH] Update __syscall_cp to use syscalls from syscall shim layer
+
+Signed-off-by: Gaulthier Gain <gaulthier.gain@uliege.be>
+---
+ src/thread/__syscall_cp.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/thread/__syscall_cp.c b/src/thread/__syscall_cp.c
+index 09a2be8..e22e75b 100644
+--- a/src/thread/__syscall_cp.c
++++ b/src/thread/__syscall_cp.c
+@@ -8,7 +8,7 @@ static long sccp(syscall_arg_t nr,
+ syscall_arg_t u, syscall_arg_t v, syscall_arg_t w,
+ syscall_arg_t x, syscall_arg_t y, syscall_arg_t z)
+ {
+- return (__syscall)(nr, u, v, w, x, y, z);
++ return (uk_syscall)(nr, u, v, w, x, y, z);
+ }
+
+ weak_alias(sccp, __syscall_cp_c);
+--
+2.20.1
+
+++ /dev/null
-From ab6c1cf39135f9b11524267a0d3b517b88f4ff27 Mon Sep 17 00:00:00 2001
-From: gaulthier gain <gaulthier.gain@uliege.be>
-Date: Fri, 9 Oct 2020 15:18:24 +0000
-Subject: [PATCH] Stub istty by ignoring ioctl
-
-Signed-off-by: gaulthier gain <gaulthier.gain@uliege.be>
----
- src/unistd/isatty.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/unistd/isatty.c b/src/unistd/isatty.c
-index c8badaf..a0f34d5 100644
---- a/src/unistd/isatty.c
-+++ b/src/unistd/isatty.c
-@@ -5,5 +5,5 @@
- int isatty(int fd)
- {
- struct winsize wsz;
-- return !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
-+ return 1; //!__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
- }
---
-2.17.1
-
--- /dev/null
+From 0707c3af258a7859bd91e3efa468d39a5a151a3f Mon Sep 17 00:00:00 2001
+From: Gaulthier Gain <gaulthier.gain@uliege.be>
+Date: Sat, 25 Jan 2020 14:18:41 +0100
+Subject: [PATCH] Use uk/bits/syscall_nrs.h instead of musl internal
+ bits/syscall.h
+
+Signed-off-by: Gaulthier Gain <gaulthier.gain@uliege.be>
+---
+ include/sys/syscall.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/sys/syscall.h b/include/sys/syscall.h
+index 24987dd..918de59 100644
+--- a/include/sys/syscall.h
++++ b/include/sys/syscall.h
+@@ -1,6 +1,6 @@
+ #ifndef _SYS_SYSCALL_H
+ #define _SYS_SYSCALL_H
+
+-#include <bits/syscall.h>
++#include <uk/bits/syscall_nrs.h>
+
+ #endif
+--
+2.20.1
+
+++ /dev/null
-From 120d042546de02e005e668306ff4022bdaf784b4 Mon Sep 17 00:00:00 2001
-From: gaulthier gain <gaulthier.gain@uliege.be>
-Date: Fri, 9 Oct 2020 15:32:04 +0000
-Subject: [PATCH] Fix stdio_write output
-
-Signed-off-by: gaulthier gain <gaulthier.gain@uliege.be>
----
- src/stdio/__stdio_write.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c
-index d2d8947..cae0ea9 100644
---- a/src/stdio/__stdio_write.c
-+++ b/src/stdio/__stdio_write.c
-@@ -24,7 +24,7 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
- return iovcnt == 2 ? 0 : len-iov[0].iov_len;
- }
- rem -= cnt;
-- if (cnt > iov[0].iov_len) {
-+ if (cnt >= iov[0].iov_len) {
- cnt -= iov[0].iov_len;
- iov++; iovcnt--;
- }
---
-2.17.1
-
--- /dev/null
+From ab6c1cf39135f9b11524267a0d3b517b88f4ff27 Mon Sep 17 00:00:00 2001
+From: gaulthier gain <gaulthier.gain@uliege.be>
+Date: Fri, 9 Oct 2020 15:18:24 +0000
+Subject: [PATCH] Stub istty by ignoring ioctl
+
+Signed-off-by: gaulthier gain <gaulthier.gain@uliege.be>
+---
+ src/unistd/isatty.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/unistd/isatty.c b/src/unistd/isatty.c
+index c8badaf..a0f34d5 100644
+--- a/src/unistd/isatty.c
++++ b/src/unistd/isatty.c
+@@ -5,5 +5,5 @@
+ int isatty(int fd)
+ {
+ struct winsize wsz;
+- return !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
++ return 1; //!__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
+ }
+--
+2.17.1
+
--- /dev/null
+From 120d042546de02e005e668306ff4022bdaf784b4 Mon Sep 17 00:00:00 2001
+From: gaulthier gain <gaulthier.gain@uliege.be>
+Date: Fri, 9 Oct 2020 15:32:04 +0000
+Subject: [PATCH] Fix stdio_write output
+
+Signed-off-by: gaulthier gain <gaulthier.gain@uliege.be>
+---
+ src/stdio/__stdio_write.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c
+index d2d8947..cae0ea9 100644
+--- a/src/stdio/__stdio_write.c
++++ b/src/stdio/__stdio_write.c
+@@ -24,7 +24,7 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
+ return iovcnt == 2 ? 0 : len-iov[0].iov_len;
+ }
+ rem -= cnt;
+- if (cnt > iov[0].iov_len) {
++ if (cnt >= iov[0].iov_len) {
+ cnt -= iov[0].iov_len;
+ iov++; iovcnt--;
+ }
+--
+2.17.1
+
+++ /dev/null
-From 8ecbb57a730c20505e6117e8c5f012ed3348e1ec Mon Sep 17 00:00:00 2001
-From: gaulthier gain <gaulthier.gain@uliege.be>
-Date: Fri, 9 Oct 2020 15:57:11 +0000
-Subject: [PATCH] Update stdoutwrite by removing ioctl
-
-Signed-off-by: gaulthier gain <gaulthier.gain@uliege.be>
----
- src/stdio/__stdout_write.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/src/stdio/__stdout_write.c b/src/stdio/__stdout_write.c
-index dd1ec60..70dc450 100644
---- a/src/stdio/__stdout_write.c
-+++ b/src/stdio/__stdout_write.c
-@@ -5,7 +5,7 @@ size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len)
- {
- struct winsize wsz;
- f->write = __stdio_write;
-- if (!(f->flags & F_SVB) && __syscall(SYS_ioctl, f->fd, TIOCGWINSZ, &wsz))
-+ if (!(f->flags & F_SVB))
- f->lbf = -1;
- return __stdio_write(f, buf, len);
- }
---
-2.17.1
-
--- /dev/null
+From cab8414305bdbb07a9adfa72682d110fd7365da9 Mon Sep 17 00:00:00 2001
+From: Dragos Iulian Argint <dragosargint21@gmail.com>
+Date: Sun, 14 Aug 2022 20:14:33 +0300
+Subject: [PATCH] Change some things in pthread_create.c
+
+This patch replaces 2 function calls from musl with
+2 custom ones and introduces an additional size
+when allocating the map for a thread, `libc.tls_align`.
+It is needed because Unikraft demands that the tls be aligned.
+
+Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
+---
+ src/thread/pthread_create.c | 28 +++++++++++++++++++++-------
+ 1 file changed, 21 insertions(+), 7 deletions(-)
+
+diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
+index 439ee36..d7d5da9 100644
+--- a/src/thread/pthread_create.c
++++ b/src/thread/pthread_create.c
+@@ -10,6 +10,11 @@ void *__mmap(void *, size_t, int, int, int, off_t);
+ int __munmap(void *, size_t);
+ int __mprotect(void *, size_t, int);
+
++/*
++ * Unikraft version of `__unmapself()`. See `__uk_unmapself.c`
++ */
++void __uk_unmapself(void *base, size_t size);
++
+ static void dummy_0()
+ {
+ }
+@@ -108,9 +113,15 @@ _Noreturn void __pthread_exit(void *result)
+ * explicitly wait for vmlock holders first. */
+ __vm_wait();
+
+- /* The following call unmaps the thread's stack mapping
+- * and then exits without touching the stack. */
+- __unmapself(self->map_base, self->map_size);
++ /*
++ * In the original code `__unampself()` was called here.
++ * That call unmaps the thread's stack mapping and then
++ * exits without touching the stack. However, we cannot
++ * do this since we don't have a kernel stack. We use
++ * a different approach and let the `idle` thread do the
++ * cleaning. Please refer to the `__uk_unampself.c` file.
++ */
++ __uk_unmapself(self->map_base, self->map_size);
+ }
+
+ for (;;) __syscall(SYS_exit, 0);
+@@ -181,7 +192,10 @@ static void init_file_lock(FILE *f)
+ if (f && f->lock<0) f->lock = 0;
+ }
+
+-void *__copy_tls(unsigned char *);
++/*
++ * Unikraft version of `__copy_tls()`
++ */
++void *__uk_copy_tls(unsigned char *);
+
+ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
+ {
+@@ -237,7 +251,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
+ } else {
+ guard = ROUND(attr._a_guardsize);
+ size = guard + ROUND(attr._a_stacksize
+- + libc.tls_size + __pthread_tsd_size);
++ + libc.tls_size + libc.tls_align + __pthread_tsd_size);
+ }
+
+ if (!tsd) {
+@@ -255,12 +269,12 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
+ }
+ tsd = map + size - __pthread_tsd_size;
+ if (!stack) {
+- stack = tsd - libc.tls_size;
++ stack = tsd - libc.tls_size - libc.tls_align;
+ stack_limit = map + guard;
+ }
+ }
+
+- new = __copy_tls(tsd - libc.tls_size);
++ new = __uk_copy_tls(tsd - libc.tls_size);
+ new->map_base = map;
+ new->map_size = size;
+ new->stack = stack;
+--
+2.17.1
+
+++ /dev/null
---- 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;
+++ /dev/null
-From cab8414305bdbb07a9adfa72682d110fd7365da9 Mon Sep 17 00:00:00 2001
-From: Dragos Iulian Argint <dragosargint21@gmail.com>
-Date: Sun, 14 Aug 2022 20:14:33 +0300
-Subject: [PATCH] Change some things in pthread_create.c
-
-This patch replaces 2 function calls from musl with
-2 custom ones and introduces an additional size
-when allocating the map for a thread, `libc.tls_align`.
-It is needed because Unikraft demands that the tls be aligned.
-
-Signed-off-by: Dragos Iulian Argint <dragosargint21@gmail.com>
----
- src/thread/pthread_create.c | 28 +++++++++++++++++++++-------
- 1 file changed, 21 insertions(+), 7 deletions(-)
-
-diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
-index 439ee36..d7d5da9 100644
---- a/src/thread/pthread_create.c
-+++ b/src/thread/pthread_create.c
-@@ -10,6 +10,11 @@ void *__mmap(void *, size_t, int, int, int, off_t);
- int __munmap(void *, size_t);
- int __mprotect(void *, size_t, int);
-
-+/*
-+ * Unikraft version of `__unmapself()`. See `__uk_unmapself.c`
-+ */
-+void __uk_unmapself(void *base, size_t size);
-+
- static void dummy_0()
- {
- }
-@@ -108,9 +113,15 @@ _Noreturn void __pthread_exit(void *result)
- * explicitly wait for vmlock holders first. */
- __vm_wait();
-
-- /* The following call unmaps the thread's stack mapping
-- * and then exits without touching the stack. */
-- __unmapself(self->map_base, self->map_size);
-+ /*
-+ * In the original code `__unampself()` was called here.
-+ * That call unmaps the thread's stack mapping and then
-+ * exits without touching the stack. However, we cannot
-+ * do this since we don't have a kernel stack. We use
-+ * a different approach and let the `idle` thread do the
-+ * cleaning. Please refer to the `__uk_unampself.c` file.
-+ */
-+ __uk_unmapself(self->map_base, self->map_size);
- }
-
- for (;;) __syscall(SYS_exit, 0);
-@@ -181,7 +192,10 @@ static void init_file_lock(FILE *f)
- if (f && f->lock<0) f->lock = 0;
- }
-
--void *__copy_tls(unsigned char *);
-+/*
-+ * Unikraft version of `__copy_tls()`
-+ */
-+void *__uk_copy_tls(unsigned char *);
-
- int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
- {
-@@ -237,7 +251,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
- } else {
- guard = ROUND(attr._a_guardsize);
- size = guard + ROUND(attr._a_stacksize
-- + libc.tls_size + __pthread_tsd_size);
-+ + libc.tls_size + libc.tls_align + __pthread_tsd_size);
- }
-
- if (!tsd) {
-@@ -255,12 +269,12 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
- }
- tsd = map + size - __pthread_tsd_size;
- if (!stack) {
-- stack = tsd - libc.tls_size;
-+ stack = tsd - libc.tls_size - libc.tls_align;
- stack_limit = map + guard;
- }
- }
-
-- new = __copy_tls(tsd - libc.tls_size);
-+ new = __uk_copy_tls(tsd - libc.tls_size);
- new->map_base = map;
- new->map_size = size;
- new->stack = stack;
---
-2.17.1
-
+++ /dev/null
---- 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;
+++ /dev/null
---- 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;
- }
+++ /dev/null
---- 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