aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/cloudabi64
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/cloudabi64')
-rw-r--r--sys/compat/cloudabi64/cloudabi64_module.c24
-rw-r--r--sys/compat/cloudabi64/cloudabi64_poll.c21
-rw-r--r--sys/compat/cloudabi64/cloudabi64_proto.h2
-rw-r--r--sys/compat/cloudabi64/cloudabi64_systrace_args.c4
4 files changed, 27 insertions, 24 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)
int
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),
+ PTR(CLOUDABI_AT_PID, pid),
PTR(CLOUDABI_AT_SYSINFO_EHDR,
imgp->proc->p_sysent->sv_shared_page_base),
+ VAL(CLOUDABI_AT_TID, td->td_tid),
#undef VAL
#undef PTR
{ .a_type = CLOUDABI_AT_NULL },
diff --git a/sys/compat/cloudabi64/cloudabi64_poll.c b/sys/compat/cloudabi64/cloudabi64_poll.c
index 2b80d7af6b62..52950928b27c 100644
--- a/sys/compat/cloudabi64/cloudabi64_poll.c
+++ b/sys/compat/cloudabi64/cloudabi64_poll.c
@@ -78,7 +78,7 @@ convert_signal(int sig)
struct cloudabi64_kevent_args {
const cloudabi64_subscription_t *in;
- cloudabi64_event_t *out;
+ cloudabi_event_t *out;
};
/* Converts CloudABI's subscription objects to FreeBSD's struct kevent. */
@@ -145,7 +145,7 @@ cloudabi64_kevent_copyin(void *arg, struct kevent *kevp, int count)
static int
cloudabi64_kevent_copyout(void *arg, struct kevent *kevp, int count)
{
- cloudabi64_event_t ev;
+ cloudabi_event_t ev;
struct cloudabi64_kevent_args *args;
int error;
@@ -157,19 +157,15 @@ cloudabi64_kevent_copyout(void *arg, struct kevent *kevp, int count)
switch (kevp->filter) {
case EVFILT_TIMER:
ev.type = CLOUDABI_EVENTTYPE_CLOCK;
- ev.clock.identifier = kevp->ident;
break;
case EVFILT_READ:
ev.type = CLOUDABI_EVENTTYPE_FD_READ;
- ev.fd_readwrite.fd = kevp->ident;
break;
case EVFILT_WRITE:
ev.type = CLOUDABI_EVENTTYPE_FD_WRITE;
- ev.fd_readwrite.fd = kevp->ident;
break;
case EVFILT_PROCDESC:
ev.type = CLOUDABI_EVENTTYPE_PROC_TERMINATE;
- ev.proc_terminate.fd = kevp->ident;
break;
}
@@ -231,7 +227,7 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
*/
if (uap->nsubscriptions == 1) {
cloudabi64_subscription_t sub;
- cloudabi64_event_t ev = {};
+ cloudabi_event_t ev = {};
int error;
error = copyin(uap->in, &sub, sizeof(sub));
@@ -241,7 +237,6 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
ev.type = sub.type;
if (sub.type == CLOUDABI_EVENTTYPE_CONDVAR) {
/* Wait on a condition variable. */
- ev.condvar.condvar = sub.condvar.condvar;
ev.error = cloudabi_convert_errno(
cloudabi_futex_condvar_wait(
td, TO_PTR(sub.condvar.condvar),
@@ -253,7 +248,6 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
return (copyout(&ev, uap->out, sizeof(ev)));
} else if (sub.type == CLOUDABI_EVENTTYPE_LOCK_RDLOCK) {
/* Acquire a read lock. */
- ev.lock.lock = sub.lock.lock;
ev.error = cloudabi_convert_errno(
cloudabi_futex_lock_rdlock(
td, TO_PTR(sub.lock.lock),
@@ -263,7 +257,6 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
return (copyout(&ev, uap->out, sizeof(ev)));
} else if (sub.type == CLOUDABI_EVENTTYPE_LOCK_WRLOCK) {
/* Acquire a write lock. */
- ev.lock.lock = sub.lock.lock;
ev.error = cloudabi_convert_errno(
cloudabi_futex_lock_wrlock(
td, TO_PTR(sub.lock.lock),
@@ -274,7 +267,7 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
}
} else if (uap->nsubscriptions == 2) {
cloudabi64_subscription_t sub[2];
- cloudabi64_event_t ev[2] = {};
+ cloudabi_event_t ev[2] = {};
int error;
error = copyin(uap->in, &sub, sizeof(sub));
@@ -288,8 +281,6 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
sub[1].type == CLOUDABI_EVENTTYPE_CLOCK &&
sub[1].clock.flags == CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) {
/* Wait for a condition variable with timeout. */
- ev[0].condvar.condvar = sub[0].condvar.condvar;
- ev[1].clock.identifier = sub[1].clock.identifier;
error = cloudabi_futex_condvar_wait(
td, TO_PTR(sub[0].condvar.condvar),
sub[0].condvar.condvar_scope,
@@ -309,8 +300,6 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
sub[1].type == CLOUDABI_EVENTTYPE_CLOCK &&
sub[1].clock.flags == CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) {
/* Acquire a read lock with a timeout. */
- ev[0].lock.lock = sub[0].lock.lock;
- ev[1].clock.identifier = sub[1].clock.identifier;
error = cloudabi_futex_lock_rdlock(
td, TO_PTR(sub[0].lock.lock),
sub[0].lock.lock_scope, sub[1].clock.clock_id,
@@ -328,8 +317,6 @@ cloudabi64_sys_poll(struct thread *td, struct cloudabi64_sys_poll_args *uap)
sub[1].type == CLOUDABI_EVENTTYPE_CLOCK &&
sub[1].clock.flags == CLOUDABI_SUBSCRIPTION_CLOCK_ABSTIME) {
/* Acquire a write lock with a timeout. */
- ev[0].lock.lock = sub[0].lock.lock;
- ev[1].clock.identifier = sub[1].clock.identifier;
error = cloudabi_futex_lock_wrlock(
td, TO_PTR(sub[0].lock.lock),
sub[0].lock.lock_scope, sub[1].clock.clock_id,
diff --git a/sys/compat/cloudabi64/cloudabi64_proto.h b/sys/compat/cloudabi64/cloudabi64_proto.h
index 2f0302f9aa11..acaf078d7b09 100644
--- a/sys/compat/cloudabi64/cloudabi64_proto.h
+++ b/sys/compat/cloudabi64/cloudabi64_proto.h
@@ -224,7 +224,7 @@ struct cloudabi_sys_mem_unmap_args {
};
struct cloudabi64_sys_poll_args {
char in_l_[PADL_(const cloudabi64_subscription_t *)]; const cloudabi64_subscription_t * in; char in_r_[PADR_(const cloudabi64_subscription_t *)];
- char out_l_[PADL_(cloudabi64_event_t *)]; cloudabi64_event_t * out; char out_r_[PADR_(cloudabi64_event_t *)];
+ char out_l_[PADL_(cloudabi_event_t *)]; cloudabi_event_t * out; char out_r_[PADR_(cloudabi_event_t *)];
char nsubscriptions_l_[PADL_(size_t)]; size_t nsubscriptions; char nsubscriptions_r_[PADR_(size_t)];
};
struct cloudabi_sys_proc_exec_args {
diff --git a/sys/compat/cloudabi64/cloudabi64_systrace_args.c b/sys/compat/cloudabi64/cloudabi64_systrace_args.c
index 6dc8fc77163a..b2bbbfa06f08 100644
--- a/sys/compat/cloudabi64/cloudabi64_systrace_args.c
+++ b/sys/compat/cloudabi64/cloudabi64_systrace_args.c
@@ -352,7 +352,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 37: {
struct cloudabi64_sys_poll_args *p = params;
uarg[0] = (intptr_t) p->in; /* const cloudabi64_subscription_t * */
- uarg[1] = (intptr_t) p->out; /* cloudabi64_event_t * */
+ uarg[1] = (intptr_t) p->out; /* cloudabi_event_t * */
uarg[2] = p->nsubscriptions; /* size_t */
*n_args = 3;
break;
@@ -1062,7 +1062,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const cloudabi64_subscription_t *";
break;
case 1:
- p = "userland cloudabi64_event_t *";
+ p = "userland cloudabi_event_t *";
break;
case 2:
p = "size_t";