aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/cloudabi
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2015-07-29 17:18:27 +0000
committerEd Schouten <ed@FreeBSD.org>2015-07-29 17:18:27 +0000
commit8328babdd0716967a63a23af9dee2e122bb291dc (patch)
treeb3859e39cb480af3103e9c6bf3bf05ce156893d7 /sys/compat/cloudabi
parente555b4309c337304587b7fda6ebda106d6854758 (diff)
downloadsrc-8328babdd0716967a63a23af9dee2e122bb291dc.tar.gz
src-8328babdd0716967a63a23af9dee2e122bb291dc.zip
Make pipes in CloudABI work.
Summary: Pipes in CloudABI are unidirectional. The reason for this is that CloudABI attempts to provide a uniform runtime environment across different flavours of UNIX. Instead of implementing a custom pipe that is unidirectional, we can simply reuse Capsicum permission bits to support this. This is nice, because CloudABI already attempts to restrict permission bits to correspond with the operations that apply to a certain file descriptor. Replace kern_pipe() and kern_pipe2() by a single kern_pipe() that takes a pair of filecaps. These filecaps are passed to the newly introduced falloc_caps() function that creates the descriptors with rights in place. Test Plan: CloudABI pipes seem to be created with proper rights in place: https://github.com/NuxiNL/cloudlibc/blob/master/src/libc/unistd/pipe_test.c#L44 Reviewers: jilles, mjg Reviewed By: mjg Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3236
Notes
Notes: svn path=/head/; revision=286021
Diffstat (limited to 'sys/compat/cloudabi')
-rw-r--r--sys/compat/cloudabi/cloudabi_fd.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/compat/cloudabi/cloudabi_fd.c b/sys/compat/cloudabi/cloudabi_fd.c
index 1b3aa0f0ce09..5a58cb312d98 100644
--- a/sys/compat/cloudabi/cloudabi_fd.c
+++ b/sys/compat/cloudabi/cloudabi_fd.c
@@ -120,10 +120,24 @@ int
cloudabi_sys_fd_create2(struct thread *td,
struct cloudabi_sys_fd_create2_args *uap)
{
+ struct filecaps fcaps1 = {}, fcaps2 = {};
int fds[2];
int error;
switch (uap->type) {
+ case CLOUDABI_FILETYPE_FIFO:
+ /*
+ * CloudABI pipes are unidirectional. Restrict rights on
+ * the pipe to simulate this.
+ */
+ cap_rights_init(&fcaps1.fc_rights, CAP_EVENT, CAP_FCNTL,
+ CAP_FSTAT, CAP_READ);
+ fcaps1.fc_fcntls = CAP_FCNTL_SETFL;
+ cap_rights_init(&fcaps2.fc_rights, CAP_EVENT, CAP_FCNTL,
+ CAP_FSTAT, CAP_WRITE);
+ fcaps2.fc_fcntls = CAP_FCNTL_SETFL;
+ error = kern_pipe(td, fds, 0, &fcaps1, &fcaps2);
+ break;
case CLOUDABI_FILETYPE_SOCKET_DGRAM:
error = kern_socketpair(td, AF_UNIX, SOCK_DGRAM, 0, fds);
break;