path: root/sys/compat/cloudabi64/cloudabi64_module.c
diff options
authorEd Schouten <ed@FreeBSD.org>2017-11-08 14:21:52 +0000
committerEd Schouten <ed@FreeBSD.org>2017-11-08 14:21:52 +0000
commit7e6155744d78c5f233af37fefc8f1e576a0fe63f (patch)
tree37276fa420d32a1380a86d37eb54675781f3334c /sys/compat/cloudabi64/cloudabi64_module.c
parent8c9e09194412512173244881d29da6c8f2d32e56 (diff)
Upgrade to CloudABI v0.17.
Compared to the previous version, v0.16, there are a couple of minor changes: - CLOUDABI_AT_PID: Process identifiers for CloudABI processes. Initially, BSD process identifiers weren't exposed inside the runtime, due to them being pretty much useless inside of a cluster computing environment. When jobs are scheduled across systems, the BSD process number doesn't act as an identifier. Even on individual systems they may recycle relatively quickly. With this change, the kernel will now generate a UUIDv4 when executing a process. These UUIDs can be obtained within the process using program_getpid(). Right now, FreeBSD will not attempt to store this value. This should of course happen at some point in time, so that it may be printed by administration tools. - Removal of some unused structure members for polling. With the polling framework being simplified/redesigned, it turns out some of the structure fields were not used by the C library. We can remove these to keep things nice and tidy. Obtained from: https://github.com/NuxiNL/cloudabi
Notes: svn path=/head/; revision=325555
Diffstat (limited to 'sys/compat/cloudabi64/cloudabi64_module.c')
1 files changed, 20 insertions, 4 deletions
diff --git a/sys/compat/cloudabi64/cloudabi64_module.c b/sys/compat/cloudabi64/cloudabi64_module.c
index da1ea1149a4b..9c71b87b08f4 100644
--- a/sys/compat/cloudabi64/cloudabi64_module.c
+++ b/sys/compat/cloudabi64/cloudabi64_module.c
@@ -63,10 +63,10 @@ cloudabi64_copyout_strings(struct image_params *imgp)
cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
- char canarybuf[64];
+ char canarybuf[64], pidbuf[16];
Elf64_Auxargs *args;
struct thread *td;
- void *argdata, *canary;
+ void *argdata, *canary, *pid;
size_t argdatalen;
int error;
@@ -79,8 +79,9 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
td = curthread;
td->td_proc->p_osrel = __FreeBSD_version;
- /* Store canary for stack smashing protection. */
argdata = *stack_base;
+ /* Store canary for stack smashing protection. */
arc4rand(canarybuf, sizeof(canarybuf), 0);
*stack_base -= howmany(sizeof(canarybuf), sizeof(register_t));
canary = *stack_base;
@@ -89,6 +90,20 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
return (error);
+ * Generate a random UUID that identifies the process. Right now
+ * we don't store this UUID in the kernel. Ideally, it should be
+ * exposed through ps(1).
+ */
+ arc4rand(pidbuf, sizeof(pidbuf), 0);
+ pidbuf[6] = (pidbuf[6] & 0x0f) | 0x40;
+ pidbuf[8] = (pidbuf[8] & 0x3f) | 0x80;
+ *stack_base -= howmany(sizeof(pidbuf), sizeof(register_t));
+ pid = *stack_base;
+ error = copyout(pidbuf, pid, sizeof(pidbuf));
+ if (error != 0)
+ return (error);
+ /*
* Compute length of program arguments. As the argument data is
* binary safe, we had to add a trailing null byte in
* exec_copyin_data_fds(). Undo this by reducing the length.
@@ -111,9 +126,10 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp)
VAL(CLOUDABI_AT_PAGESZ, args->pagesz),
PTR(CLOUDABI_AT_PHDR, args->phdr),
VAL(CLOUDABI_AT_PHNUM, args->phnum),
- VAL(CLOUDABI_AT_TID, td->td_tid),
+ VAL(CLOUDABI_AT_TID, td->td_tid),
#undef VAL
#undef PTR
{ .a_type = CLOUDABI_AT_NULL },