Page MenuHomeFreeBSD

Add implementations for some of the CloudABI file descriptor system calls.
ClosedPublic

Authored by ed on Jul 9 2015, 12:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 26, 6:02 AM
Unknown Object (File)
Fri, Apr 26, 6:02 AM
Unknown Object (File)
Feb 11 2024, 1:00 AM
Unknown Object (File)
Dec 20 2023, 4:41 AM
Unknown Object (File)
Dec 9 2023, 10:33 PM
Unknown Object (File)
Dec 1 2023, 5:24 AM
Unknown Object (File)
Aug 24 2023, 4:28 AM
Unknown Object (File)
Aug 11 2023, 10:34 AM
Subscribers

Details

Summary

All of the CloudABI system calls that operate on file descriptors of an arbitrary type are prefixed with fd_. This change adds wrappers for these system calls around their FreeBSD equivalents.

The dup2() system call present on CloudABI deviates from POSIX, in the sense that it can only be used to replace existing file descriptor. It cannot be used to create new ones. The reason for this is that this is inherently thread-unsafe. Furthermore, there is no need on CloudABI to use fixed file descriptor numbers. File descriptors 0, 1 and 2 have no special meaning.

This change exposes the kern_dup() through <sys/syscallsubr.h> and puts the FDDUP_* flags in <sys/filedesc.h>. It then adds a new flag, FDDUP_MUSTREPLACE to force that file descriptors are replaced -- not allocated.

Test Plan

This change passes the CloudABI test suite.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ed retitled this revision from to Add implementations for some of the CloudABI file descriptor system calls..
ed updated this object.
ed edited the test plan for this revision. (Show Details)
ed added reviewers: mjg, brooks.
ed set the repository for this revision to rS FreeBSD src repository - subversion.

I made a commit with part of the work concerning do_dup here: https://svnweb.freebsd.org/base/head/sys/kern/kern_descrip.c?r1=285321&r2=285320&pathrev=285321

To quote the commit message:

  • rename it [do_dup] to kern_dup.
  • prefix flags with FD
  • assert that correct flags were passed
sys/kern/kern_descrip.c
838 ↗(On Diff #6814)

The only caller passes DUP_FIXED | DUP_REPLACE. I don't object, but in this case the code should assert that DUP_FIXED was also provided.

I would prefer if DUP_REPLACE was made a conflicting flag with _FIXED instead. Maybe renaming it to _MUSTREPLACE (or compatible) would express the intent better. Then assert that at most one is provided (e.g. MPASS((flags & (FDDUP_FIXED | FDDUP_MUSTREPLACE)) != (FDDUP_FIXED | FDDUP_MUSTREPLACE))).

sys/sys/syscallsubr.h
263 ↗(On Diff #6814)

This file pretty much lacks other macros. I don't mind them landing here, but I'm quite sure someone will object and I won't defend it :)

I suggest moving these macros to sys/filedesc.h instead, at least for the time being.

ed updated this object.
ed edited edge metadata.

Thanks for the review!

sys/kern/kern_descrip.c
830 ↗(On Diff #6823)

Sounds perfectly reasonable! I've renamed the flag to FDDUP_MUSTREPLACE and it is now independent of FDDUP_FIXED.

sys/sys/syscallsubr.h
91 ↗(On Diff #6823)

Done!

mjg edited edge metadata.

ACK in general

You missed the assertion. MPASS((flags & ~(FDDUP_FIXED | FDDUP_FCNTL | FDDUP_CLOEXEC)) == 0); now needs to be extended with FDDUP_MUSTREPLACE, but there is no need to upload an updated patch here.

This revision is now accepted and ready to land.Jul 9 2015, 4:04 PM
In D3035#59963, @mjg wrote:

ACK in general

You missed the assertion. MPASS((flags & ~(FDDUP_FIXED | FDDUP_FCNTL | FDDUP_CLOEXEC)) == 0); now needs to be extended with FDDUP_MUSTREPLACE, but there is no need to upload an updated patch here.

Whoops. Fixed!

This revision was automatically updated to reflect the committed changes.