Skip to content

Conversation

artob
Copy link

@artob artob commented Nov 29, 2015

This pull request adds initial basic support for the ioctl(2) facility long missing from OCaml. By specifying only the nullary command version (i.e., suitable only to ioctl_list(2) requests that don't take any argument), this initial implementation is of limited utility but also a no-brainer to provide as a bare minimum.

As you'll note in the evolution of the commit history for this branch, I've checked that the signature is compatible with at least Linux, Darwin, FreeBSD, OpenBSD, and NetBSD. The obsolescent POSIX definition of ioctl(2) has hence been superseded in actual practice by all major platforms of note.

In terms of future directions to extend this to a fully-functional unary-argument version, I believe that there are four distinct cases to handle:

  1. ioctl(fd, cmd, arg), where arg is an immediate integer input argument.
  2. ioctl(fd, cmd, &arg), where arg is an integer input/output argument.
  3. ioctl(fd, cmd, buf), where arg is effectively a const void* input argument.
  4. ioctl(fd, cmd, &buf), where arg is effectively a void* input/output argument.

The first case would be trivial, but I'd appreciate guidance on what an extended interface for all the above might best look like in terms of the conventions of and facilities provided by ExtUnix. Two options that come to mind would be to either provide a variant type to facilitate case analysis of the argument, or else to provide (at least) four distinct functions (e.g., ioctl_int, etc). Thoughts?

This function signature now matches at least Linux, Darwin,
FreeBSD, OpenBSD, and NetBSD--all of which type the request
parameter as 'unsigned long' instead of historical 'int'.

See: https://bugzilla.kernel.org/show_bug.cgi?id=42705
See: http://man7.org/linux/man-pages/man2/ioctl.2.html
@ygrek
Copy link
Owner

ygrek commented Dec 5, 2015

Note that there are already several specific bindings to some ioctl functions - namely siocgifconf and 4 tty ioctls - we will probably need to unify the code at some point.
As for the future interface - looks like we will be able to generically cover not many cases bc many ioctls take or return C struct and will require a specific binding.

@ygrek
Copy link
Owner

ygrek commented Dec 6, 2015

Can you give some examples of ioctl's that use this NULL-arg form?
I imagine that we will have a list of "popular" ioctls builtin in extunix, but will also let users call ioctl functions with different type signatures implemented in extunix with user-provided ioctl cmd number (which is inherently unsafe) - this is a valid use-case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants