1 // NOTE: The ioctl definitions are sequestered into this module because the
2 // `ioctl_*!` macros provided by the nix crate generate public functions that we
3 // don't want to be part of this crate's public API.
4 //
5 // NOTE: We are manually re-declaring the types and constants here instead of using
6 // bindgen and a separate `-sys` crate because the defines used for the ioctl
7 // numbers (`TIPC_IOC_CONNECT` and `TIPC_IOC_SEND_MSG`) can't currently be
8 // translated by bindgen.
9 
10 use std::os::raw::c_char;
11 
12 const TIPC_IOC_MAGIC: u8 = b'r';
13 
14 // NOTE: We use `ioctl_write_ptr_bad!` here due to an error in how the ioctl
15 // code is defined in `trusty/ipc.h`.
16 //
17 // If we were to do `ioctl_write_ptr!(TIPC_IOC_MAGIC, 0x80, c_char)` it would
18 // generate a function that takes a `*const c_char` data arg and would use
19 // `size_of::<c_char>()` when generating the ioctl number. However, in
20 // `trusty/ipc.h` the definition for `TIPC_IOC_CONNECT` declares the ioctl with
21 // `char*`, meaning we need to use `size_of::<*const c_char>()` to generate an
22 // ioctl number that matches what Trusty expects.
23 //
24 // To maintain compatibility with the `trusty/ipc.h` and the kernel driver we
25 // use `ioctl_write_ptr_bad!` and manually use `request_code_write!` to generate
26 // the ioctl number using the correct size.
27 nix::ioctl_write_ptr_bad!(
28     tipc_connect,
29     nix::request_code_write!(TIPC_IOC_MAGIC, 0x80, std::mem::size_of::<*const c_char>()),
30     c_char
31 );
32