aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/cloudabi64/cloudabi64_module.c
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2016-04-06 11:11:31 +0000
committerEd Schouten <ed@FreeBSD.org>2016-04-06 11:11:31 +0000
commitab8357507077525f79ba675f5b4daf505ab3fa01 (patch)
treeb34a51eca356eac838df8dddb88435653105bae9 /sys/compat/cloudabi64/cloudabi64_module.c
parent1c7c13aa0e7ad180c67fb2dc24964febe4a44bab (diff)
downloadsrc-ab8357507077525f79ba675f5b4daf505ab3fa01.tar.gz
src-ab8357507077525f79ba675f5b4daf505ab3fa01.zip
Make CloudABI's way of doing TLS more friendly to userspace emulators.
We're currently seeing how hard it would be to run CloudABI binaries on operating systems cannot be modified easily (Windows, Mac OS X). The idea is that we want to just run them without any sandboxing. Now that CloudABI executables are PIE, this is already a bit easier, but TLS is still problematic: - CloudABI executables want to write to the %fs, which typically requires extra system calls by the emulator every time it needs to switch between CloudABI's and its own TLS. - If CloudABI executables overwrite the %fs base unconditionally, it also becomes harder for the emulator to store a backup of the old value of %fs. To solve this, let's no longer overwrite %fs, but just %fs:0. As CloudABI's C library does not use a TCB, this space can now be used by an emulator to keep track of its internal state. The executable can now safely overwrite %fs:0, as long as it makes sure that the TCB is copied over to the new TLS area. Ensure that there is an initial TLS area set up when the process starts, only containing a bogus TCB. We don't really care about its contents on FreeBSD. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D5836
Notes
Notes: svn path=/head/; revision=297613
Diffstat (limited to 'sys/compat/cloudabi64/cloudabi64_module.c')
-rw-r--r--sys/compat/cloudabi64/cloudabi64_module.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sys/compat/cloudabi64/cloudabi64_module.c b/sys/compat/cloudabi64/cloudabi64_module.c
index de890bc5c652..246a887105cb 100644
--- a/sys/compat/cloudabi64/cloudabi64_module.c
+++ b/sys/compat/cloudabi64/cloudabi64_module.c
@@ -112,7 +112,13 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
{ .a_type = CLOUDABI_AT_NULL },
};
*stack_base -= howmany(sizeof(auxv), sizeof(register_t));
- return (copyout(auxv, *stack_base, sizeof(auxv)));
+ error = copyout(auxv, *stack_base, sizeof(auxv));
+ if (error != 0)
+ return (error);
+
+ /* Reserve space for storing the TCB. */
+ *stack_base -= howmany(sizeof(cloudabi64_tcb_t), sizeof(register_t));
+ return (0);
}
static int