aboutsummaryrefslogtreecommitdiff
path: root/sys/compat
Commit message (Collapse)AuthorAgeFilesLines
* Fix build for the KTR-enabled kernels.Konstantin Belousov2015-10-231-2/+9
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=289822
* Refactoring: move out generic bits from cloudabi64_sysvec.c.Ed Schouten2015-10-222-0/+158
| | | | | | | | | | | | | In order to make it easier to support CloudABI on ARM64, move out all of the bits from the AMD64 cloudabi_sysvec.c into a new file cloudabi_module.c that would otherwise remain identical. This reduces the AMD64 specific code to just ~160 lines. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D3974 Notes: svn path=/head/; revision=289747
* Properly format pointer size independent CloudABI system calls.Ed Schouten2015-10-081-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | CloudABI has approximately 50 system calls that do not depend on the pointer size of the system. As the ABI is pretty compact, it takes little effort to each truss(8) the formatting rules for these system calls. Start off by formatting pointer size independent system calls. Changes: - Make it possible to include the CloudABI system call definitions in FreeBSD userspace builds. Add ${root}/sys to the truss(8) Makefile so we can pull in <compat/cloudabi/cloudabi_syscalldefs.h>. - Refactoring: patch up amd64-cloudabi64.c to use the CLOUDABI_* constants instead of rolling our own table. - Add table entries for all of the system calls. - Add new generic formatting types (UInt, IntArray) that we'll be using to format unsigned integers and arrays of integers. - Add CloudABI specific formatting types. Approved by: jhb Differential Revision: https://reviews.freebsd.org/D3836 Notes: svn path=/head/; revision=289004
* Remove redundant RFFPWAIT/vfork(2) handling in Linux fork(2) and clone(2) ↵Bryan Drewery2015-10-071-28/+5
| | | | | | | | | | | | | | | | | | | | wrappers. r161611 added some of the code from sys_vfork() directly into the Linux module wrappers since they use RFSTOPPED. In r232240, the RFFPWAIT handling was moved to syscallret(), thus this code in the Linux module is no longer needed as it will be called later. This also allows the Linux wrappers to benefit from the fix in r275616 for threads not getting suspended if their vforked child is stopped while they wait on them. Reviewed by: jhb, kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D3828 Notes: svn path=/head/; revision=288994
* save some bytes by using more concise SDT_PROBE<n> instead of SDT_PROBEAndriy Gapon2015-09-281-1/+1
| | | | | | | | | | | | SDT_PROBE requires 5 parameters whereas SDT_PROBE<n> requires n parameters where n is typically smaller than 5. Perhaps SDT_PROBE should be made a private implementation detail. MFC after: 20 days Notes: svn path=/head/; revision=288336
* Fixes a panic triggered by threaded Linux applications when runningEdward Tomasz Napierala2015-09-021-1/+21
| | | | | | | | | | | | | with RACCT/RCTL enabled. Reviewed by: ngie@, ed@ Tested by: Larry Rosenman <ler@lerctr.org> MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D3470 Notes: svn path=/head/; revision=287395
* Decompose linkat()/renameat() rights to source and target.Ed Schouten2015-08-271-4/+4
| | | | | | | | | | | | | | | To make it easier to understand how Capsicum interacts with linkat() and renameat(), rename the rights to CAP_{LINK,RENAME}AT_{SOURCE,TARGET}. This also addresses a shortcoming in Capsicum, where it isn't possible to disable linking to files stored in a directory. Creating hardlinks essentially makes it possible to access files with additional rights. Reviewed by: rwatson, wblock Differential Revision: https://reviews.freebsd.org/D3411 Notes: svn path=/head/; revision=287209
* Don't forget to invoke pre_execve() and post_execve().Ed Schouten2015-08-171-0/+5
| | | | | | | | CloudABI's proc_exec() was implemented before r282708 introduced pre_execve() and post_execve(). Sync up by adding these missing calls. Notes: svn path=/head/; revision=286844
* Add the last remaining system calls: send() and recv().Ed Schouten2015-08-121-4/+100
| | | | | | | | | | | There is still one TODO item for these calls: add file descriptor passing. The data structures are already prepared for this. It's just the translation that's missing. Obtained from: http://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=286680
* Use CAP_EVENT instead of CAP_PDWAIT.Ed Schouten2015-08-122-3/+4
| | | | | | | | | | | The cloudlibc pdwait() function ends up using FreeBSD's kqueue() in combination with EVFILT_PROCDESC. This depends on CAP_EVENT -- not CAP_PDWAIT. Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=286661
* Make blocking CloudABI futex operations work.Ed Schouten2015-08-121-0/+121
| | | | | | | | | | | | | | | | | | | Blocking on locks and condition variables can be accomplished by polling and using the special filters CONDVAR, LOCK_RDLOCK and LOCK_WRLOCK. For now it wouldn't make sense to implement this functionality into kqueue() itself, for the reason that they are CloudABI specific and would require us to resize 'struct kevent' to hold all of the parameters of interest. Add a bandaid to the CloudABI poll system call to call into the futex code directly if it detects specific combinations of events that are used by the C library. Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=286656
* Make poll() and kqueue() on CloudABI work.Ed Schouten2015-08-121-4/+242
| | | | | | | | | | | | | | | | | | | | | This change implements two functions, cloudabi64_kevent_copyin() and cloudabi64_kevent_copyout(), that convert CloudABI structures to FreeBSD's struct kevent. CloudABI uses two structures: subscription_t and event_t. The former is used for input, whereas the latter is used for output. Unlike struct kevent, fields aren't overloaded for multiple purposes or for separate event types. For poll() we call into the newly introduced kern_kevent_anonymous() function that allows us to poll without a file descriptor. This function is not only used by poll(), but also by functions such as sleep() and clock_nanosleep(). Reviewed by: jmg Obtained from: https://github.com/NuxiNL/freebsd Differential Revision: https://reviews.freebsd.org/D3308 Notes: svn path=/head/; revision=286654
* Fall back to O_RDONLY -- not O_WRONLY.Ed Schouten2015-08-111-1/+1
| | | | | | | | | If CloudABI processes open files with a set of requested rights that do not match any of the privileges granted by O_RDONLY, O_WRONLY or O_RDWR, we'd better fall back to O_RDONLY -- not O_WRONLY. Notes: svn path=/head/; revision=286633
* Properly convert the error number to CloudABI's indexing.Ed Schouten2015-08-111-1/+1
| | | | | | | | We currently return FreeBSD's errno value directly, which is of course not correct. Notes: svn path=/head/; revision=286632
* Make cap_rights_limit() work for CloudABI processes.Ed Schouten2015-08-111-0/+8
| | | | | | | | Call into the recently introduced kern_cap_rights_limit() function to restrict rights. Notes: svn path=/head/; revision=286619
* Add file_open(): the underlying system call of openat().Ed Schouten2015-08-063-3/+148
| | | | | | | | | | | | | | | | | | | | | | | | | | CloudABI purely operates on file descriptor rights (CAP_*). File descriptor access modes (O_ACCMODE) are emulated on top of rights. Instead of accepting the traditional flags argument, file_open() copies in an fdstat_t object that contains the initial rights the descriptor should have, but also file descriptor flags that should persist after opening (APPEND, NONBLOCK, *SYNC). Only flags that don't persist (EXCL, TRUNC, CREAT, DIRECTORY) are passed in as an argument. file_open() first converts the rights, the persistent flags and the non-persistent flags to fflags. It then calls into vn_open(). If successful, it installs the file descriptor with the requested rights, trimming off rights that don't apply to the type of the file that has been opened. Unlike kern_openat(), this function does not support /dev/fd/*. I can't think of a reason why we need to support this for CloudABI. Obtained from: https://github.com/NuxiNL/freebsd Differential Revision: https://reviews.freebsd.org/D3235 Notes: svn path=/head/; revision=286359
* Correct the previous commit: remove the DECLARE_MODULE().Ed Schouten2015-08-051-8/+0
| | | | | | | | | It looks like a MODULE_VERSION() can also appear on its own -- there is no need to use explicitly use DECLARE_MODULE(). Looking at other modules, this seems common practice. Notes: svn path=/head/; revision=286325
* Add DECLARE_MODULE() to the "cloudabi" kernel module.Ed Schouten2015-08-051-0/+11
| | | | | | | | | | | This kernel module does not require any explicit initialization, but a module declaration is needed to let the "cloudabi64" kernel module automatically pull this in. Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=286324
* Make fcntl(F_SETFL) work.Ed Schouten2015-08-051-2/+19
| | | | | | | | | | | | The stat_put() system call can be used to modify file descriptor attributes, such as flags, but also Capsicum permission bits. Support for changing Capsicum bits will be added as soon as its dependent changes have been pushed through code review. Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=286323
* Regenerate the system call table.Ed Schouten2015-08-055-22/+67
| | | | Notes: svn path=/head/; revision=286319
* Import the latest CloudABI system call definitions and table.Ed Schouten2015-08-052-3/+18
| | | | | | | | We're going to need these for next code I'm going to send out for review: support for poll() and kqueue() on CloudABI. Notes: svn path=/head/; revision=286318
* Add the remaining pointer size independent CloudABI socket system calls.Ed Schouten2015-08-052-4/+120
| | | | | | | | | | | | | | | | | CloudABI uses a structure called cloudabi_sockstat_t. Think of it as 'struct stat' for sockets. It is used by functions such as getsockname(), getpeername(), some of the getsockopt() values, etc. This change implements the sock_stat_get() system call that returns a copy of this structure. The accept() system call should also return a full copy of this structure eventually, but for now we're only interested in the peer address. Add a TODO() to make sure this is patched up later on. Differential Revision: https://reviews.freebsd.org/D3218 Notes: svn path=/head/; revision=286312
* Allow the creation of polling descriptors (kqueues) on CloudABI.Ed Schouten2015-08-051-0/+3
| | | | Notes: svn path=/head/; revision=286310
* Allow the creation of kqueues with a restricted set of Capsicum rights.Ed Schouten2015-08-051-1/+1
| | | | | | | | | | | | | | | | | | | On CloudABI we want to create file descriptors with just the minimal set of Capsicum rights in place. The reason for this is that it makes it easier to obtain uniform behaviour across different operating systems. By explicitly whitelisting the operations, we can return consistent error codes, but also prevent applications from depending OS-specific behaviour. Extend kern_kqueue() to take an additional struct filecaps that is passed on to falloc_caps(). Update the existing consumers to pass in NULL. Differential Revision: https://reviews.freebsd.org/D3259 Notes: svn path=/head/; revision=286309
* Let the CloudABI futex code use umtx_keys.Ed Schouten2015-08-041-72/+11
| | | | | | | | | | The CloudABI kernel still passes all of the cloudlibc unit tests. Reviewed by: vangyzen Differential Revision: https://reviews.freebsd.org/D3286 Notes: svn path=/head/; revision=286278
* Allow CloudABI processes to create shared memory objects.Ed Schouten2015-08-011-0/+6
| | | | | | | | | | | | | | | Summary: Use the newly created `kern_shm_open()` function to create objects with just the rights that are actually needed. Reviewers: jhb, kib Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3260 Notes: svn path=/head/; revision=286147
* Limit rights on process descriptors.Ed Schouten2015-07-312-5/+9
| | | | | | | | | | | | | | | | | | | | | On CloudABI, the rights bits returned by cap_rights_get() match up with the operations that you can actually perform on the file descriptor. Limiting the rights is good, because it makes it easier to get uniform behaviour across different operating systems. If process descriptors on FreeBSD would suddenly gain support for any new file operation, this wouldn't become exposed to CloudABI processes without first extending the rights. Extend fork1() to gain a 'struct filecaps' argument that allows you to construct process descriptors with custom rights. Use this in cloudabi_sys_proc_fork() to limit the rights to just fstat() and pdwait(). Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=286122
* Make pipes in CloudABI work.Ed Schouten2015-07-292-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: svn path=/head/; revision=286021
* Split up Capsicum to CloudABI rights conversion into two separate routines.Ed Schouten2015-07-291-30/+85
| | | | | | | | | | | CloudABI's openat() ensures that files are opened with the smallest set of relevant rights. For example, when opening a FIFO, unrelated rights like CAP_RECV are automatically removed. To remove unrelated rights, we can just reuse the code for this that was already present in the rights conversion function. Notes: svn path=/head/; revision=286006
* Implement CloudABI's readdir().Ed Schouten2015-07-291-2/+174
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: CloudABI's readdir() system call could be thought of as a mixture between FreeBSD's getdents(2) and pread(). Instead of using the file descriptor offset, userspace provides a 64-bit cloudabi_dircookie_t continue reading at a given point. CLOUDABI_DIRCOOKIE_START, having value 0, can be used to return entries at the start of the directory. The file descriptor offset is not used to store the cookie for the reason that in a file descriptor centric environment, it would make sense to allow concurrent use of a single file descriptor. The remaining space returned by the system call should be filled with a partially truncated copy of the next entry. The advantage of doing this is that it gracefully deals with long filenames. If the C library provides a buffer that is too small to hold a single entry, it can still extract the directory entry header, meaning that it can retry the read with a larger buffer or skip it using the cookie. Test Plan: This implementation passes the cloudlibc unit tests at: https://github.com/NuxiNL/cloudlibc/tree/master/src/libc/dirent Reviewers: marcel, kib Reviewed By: kib Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3226 Notes: svn path=/head/; revision=285998
* Implement file attribute modification system calls for CloudABI.Ed Schouten2015-07-281-4/+79
| | | | | | | | | | | | | | | | | CloudABI uses a system call interface to modify file attributes that is more similar to KPI's/FUSE, namely where a stat structure is passed back to the kernel, together with a bitmask of attributes that should be changed. This would allow us to update any set of attributes atomically. That said, I'd rather not go as far as to actually implement it that way, as it would require us to duplicate more code than strictly needed. Let's just stick to the combinations that are actually used by cloudlibc. Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=285954
* Implement directory and FIFO creation.Ed Schouten2015-07-281-2/+24
| | | | | | | | | | The file_create() system call can be used to create files of a given type. Right now it can only be used to create directories and FIFOs. As CloudABI does not expose filesystem permissions, this system call lacks a mode argument. Simply use 0777 or 0666 depending on the file type. Notes: svn path=/head/; revision=285931
* Make fstat() and friends work.Ed Schouten2015-07-283-6/+336
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: CloudABI provides access to two different stat structures: - fdstat, containing file descriptor level status: oflags, file descriptor type and Capsicum rights, used by cap_rights_get(), fcntl(F_GETFL), getsockopt(SO_TYPE). - filestat, containing your regular file status: timestamps, inode number, used by fstat(). Unlike FreeBSD's stat::st_mode, CloudABI file descriptor types don't have overloaded meanings (e.g., returning S_ISCHR() for kqueues). Add a utility function to extract the type of a file descriptor accurately. CloudABI does not work with O_ACCMODEs. File descriptors have two sets of Capsicum-style rights: rights that apply to the file descriptor itself ('base') and rights that apply to any new file descriptors yielded through openat() ('inheriting'). Though not perfect, we can pretty safely decompose Capsicum rights to such a pair. This is done in convert_capabilities(). Test Plan: Tests for these system calls are fairly extensive in cloudlibc. Reviewers: jonathan, mjg, #manpages Reviewed By: mjg Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3171 Notes: svn path=/head/; revision=285930
* Add a futex implementation for CloudABI.Ed Schouten2015-07-274-19/+1237
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: CloudABI provides two different types of futex objects: read-write locks and condition variables. There is no need to provide separate support for once objects and thread joining, as these are efficiently simulated by blocking on a read-write lock. Mutexes simply use read-write locks. Condition variables always have a lock object associated to them. They always know to which lock a thread needs to be migrated if woken up. This allows us to implement requeueing. A broadcast on a condition variable will never cause multiple threads to be woken up at once. They will be woken up iteratively. This implementation still has lots of room for improvement. Locking is coarse and right now we use linked lists to store all of the locks and condition variables, instead of using a hash table. The primary goal of this implementation was to behave correctly. Performance will be improved as we go. Test Plan: This futex implementation has been in use for the last couple of months and seems to work pretty well. All of the cloudlibc and libc++ unit tests seem to pass. Reviewers: dchagin, kib, vangyzen Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3148 Notes: svn path=/head/; revision=285908
* Regenerate system call table.Ed Schouten2015-07-275-13/+13
| | | | Notes: svn path=/head/; revision=285907
* Sync in latest upstream system call definitions.Ed Schouten2015-07-271-3/+3
| | | | | | | | | Futex object scopes have been renamed from using their own constants to simply reusing the existing CLOUDABI_MAP_{PRIVATE,SHARED} flags, as they are more accurate in this context. Notes: svn path=/head/; revision=285906
* Implement the basic system calls that operate on pathnames.Ed Schouten2015-07-243-15/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Unlike FreeBSD, CloudABI does not use null terminated strings for its pathnames. Introduce a function called copyin_path() that can be used by all of the filesystem system calls that use pathnames. This change already implements the system calls that don't depend on any additional functionality (e.g., conversion of struct stat). Also implement the socket system calls that operate on pathnames, namely the ones used by the C library functions bindat() and connectat(). These don't receive a 'struct sockaddr_un', but just the pathname, meaning they could be implemented in such a way that they don't depend on the size of sun_path. For now, just use the existing interfaces. Add a missing #include to cloudabi_syscalldefs.h to get this code to build, as one of its macros depends on UINT64_C(). Test Plan: These implementations have already been tested in the CloudABI branch on GitHub. They pass all of the tests. Reviewers: kib, pjd Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3097 Notes: svn path=/head/; revision=285834
* Allow us to create UNIX sockets and socketpairs in CloudABI processes.Ed Schouten2015-07-231-4/+37
| | | | Notes: svn path=/head/; revision=285812
* Regenerate system call table.Ed Schouten2015-07-225-8/+23
| | | | Notes: svn path=/head/; revision=285791
* Import upstream changes to the system call definitions.Ed Schouten2015-07-221-2/+5
| | | | | | | | Support has been added for providing the scope of a futex operation, whether the futex is local to the process or shared between processes. Notes: svn path=/head/; revision=285790
* Make clock_gettime() and clock_getres() work for CloudABI programs.Ed Schouten2015-07-212-4/+87
| | | | | | | | | | | | | | | | | | | | | | Though the standard C library uses a 'struct timespec' using a 64-bit 'time_t', there is no need to use such a type at the system call level. CloudABI uses a simple 64-bit unsigned timestamp in nanoseconds. This is sufficient to express any time value from 1970 to 2554. The CloudABI low-level interface also supports fetching timestamp values with a lower precision. Instead of overloading the clock ID argument for this purpose, the system call provides a precision argument that may be used to specify the maximum slack. The current system call implementation does not use this information, but it's good to already have this available. Expose cloudabi_convert_timespec(), as we're going to need this for fstat() as well. Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=285754
* Make thread creation work for CloudABI processes.Ed Schouten2015-07-212-2/+71
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Remove the stub system call that was put in place during the system call import and replace it by a target-dependent version stored in sys/amd64. Initialize the thread in a way similar to cpu_set_upcall_kse(). We provide the entry point with two arguments: the thread ID and the argument pointer. Test Plan: Thread creation still seems to work, both for FreeBSD and CloudABI binaries. Reviewers: dchagin, mjg, kib Reviewed By: kib Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3110 Notes: svn path=/head/; revision=285744
* Make forking of CloudABI processes work.Ed Schouten2015-07-201-2/+10
| | | | | | | | | | | | | | | Just like FreeBSD+Capsicum, CloudABI uses process descriptors. Return the file descriptor number to the parent process. To the child process we both return a special value for the file descriptor number (CLOUDABI_PROCESS_CHILD). We also return the thread ID of the new thread in the copied process, so the threading library can reinitialize itself. Obtained from: https://github.com/NuxiNL/freebsd Notes: svn path=/head/; revision=285716
* Add support to the jail framework to be able to mount linsysfs(5) andMarcelo Araujo2015-07-192-2/+2
| | | | | | | | | | | linprocfs(5). Differential Revision: D2846 Submitted by: Nikolai Lifanov <lifanov@mail.lifanov.com> Reviewed by: jamie Notes: svn path=/head/; revision=285685
* The si_status field of the siginfo_t, provided by the waitid(2) andKonstantin Belousov2015-07-184-5/+5
| | | | | | | | | | | | | | | | | | | SIGCHLD signal, should keep full 32 bits of the status passed to the _exit(2). Split the combined p_xstat of the struct proc into the separate exit status p_xexit for normal process exit, and signalled termination information p_xsig. Kernel-visible macro KW_EXITCODE() reconstructs old p_xstat from p_xexit and p_xsig. p_xexit contains complete status and copied out into si_status. Requested by: Joerg Schilling Reviewed by: jilles (previous version), pho Tested by: pho Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=285670
* Implement CloudABI memory management system calls.Ed Schouten2015-07-171-17/+107
| | | | | | | | | | | | | Add support for the <sys/mman.h> functions by wrapping around our own implementations. There are no kern_*() variants of these system calls, but we also don't need them in this case. It is sufficient to just call into the sys_*() functions. Differential Revision: https://reviews.freebsd.org/D3033 Reviewed by: brooks Notes: svn path=/head/; revision=285652
* Add a sysentvec for CloudABI on x86-64.Ed Schouten2015-07-162-0/+157
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: For CloudABI we need to put two things on the stack of new processes: the argument data (a binary blob; not strings) and a startup data structure. The startup data structure contains interesting things such as a pointer to the ELF program header, the thread ID of the initial thread, a stack smashing protection canary, and a pointer to the argument data. Fetching system call arguments and setting the return value is similar to FreeBSD. The only differences are that system call 0 does not exist and that we call into cloudabi_convert_errno() to convert the error code. We also need this function in a couple of other places, so we'd better reuse it here. Reviewers: dchagin, kib Reviewed By: kib Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3098 Notes: svn path=/head/; revision=285641
* Implement CloudABI's exec() call.Ed Schouten2015-07-161-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In a runtime that is purely based on capability-based security, there is a strong emphasis on how programs start their execution. We need to make sure that we execute an new program with an exact set of file descriptors, ensuring that credentials are not leaked into the process accidentally. Providing the right file descriptors is just half the problem. There also needs to be a framework in place that gives meaning to these file descriptors. How does a CloudABI mail server know which of the file descriptors corresponds to the socket that receives incoming emails? Furthermore, how will this mail server acquire its configuration parameters, as it cannot open a configuration file from a global path on disk? CloudABI solves this problem by replacing traditional string command line arguments by tree-like data structure consisting of scalars, sequences and mappings (similar to YAML/JSON). In this structure, file descriptors are treated as a first-class citizen. When calling exec(), file descriptors are passed on to the new executable if and only if they are referenced from this tree structure. See the cloudabi-run(1) man page for more details and examples (sysutils/cloudabi-utils). Fortunately, the kernel does not need to care about this tree structure at all. The C library is responsible for serializing and deserializing, but also for extracting the list of referenced file descriptors. The system call only receives a copy of the serialized data and a layout of what the new file descriptor table should look like: int proc_exec(int execfd, const void *data, size_t datalen, const int *fds, size_t fdslen); This change introduces a set of fd*_remapped() functions: - fdcopy_remapped() pulls a copy of a file descriptor table, remapping all of the file descriptors according to the provided mapping table. - fdinstall_remapped() replaces the file descriptor table of the process by the copy created by fdcopy_remapped(). - fdescfree_remapped() frees the table in case we aborted before fdinstall_remapped(). We then add a function exec_copyin_data_fds() that builds on top these functions. It copies in the data and constructs a new remapped file descriptor. This is used by cloudabi_sys_proc_exec(). Test Plan: cloudabi-run(1) is capable of spawning processes successfully, providing it data and file descriptors. procstat -f seems to confirm all is good. Regular FreeBSD processes also work properly. Reviewers: kib, mjg Reviewed By: mjg Subscribers: imp Differential Revision: https://reviews.freebsd.org/D3079 Notes: svn path=/head/; revision=285622
* Implement the trivial socket system calls: shutdown() and listen().Ed Schouten2015-07-151-4/+27
| | | | Notes: svn path=/head/; revision=285598
* Make posix_fallocate() and posix_fadvise() work.Ed Schouten2015-07-151-5/+32
| | | | | | | | | We can map these system calls directly to the FreeBSD counterparts. The other filesystem related system calls will be sent out for review separately, as they are a bit more complex to get right. Notes: svn path=/head/; revision=285596