Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion sgx_urts/src/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// specific language governing permissions and limitations
// under the License..

use libc::{self, c_int, c_ulong, c_void, iovec, off64_t, size_t, ssize_t};
use libc::{self, c_int, c_void, iovec, off64_t, size_t, ssize_t};
#[cfg(not(target_env="musl"))]
use libc::{c_ulong};
use std::io::Error;

#[no_mangle]
Expand Down Expand Up @@ -217,6 +219,23 @@ pub extern "C" fn u_fcntl_arg1_ocall(
ret
}

#[cfg(all(target_env="musl", not(target_env="")))]
#[no_mangle]
pub extern "C" fn u_ioctl_arg0_ocall(error: * mut c_int,
fd: c_int,
request: c_int) -> c_int {
let mut errno = 0;
let ret = unsafe { libc::ioctl(fd, request) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding conditional compilation option in this line (let ret = unsafe { libc::ioctl(fd, request) }). Because the function prototype has not changed, I think there is no need to define a function for the musl target separately.

if ret < 0 {
errno = Error::last_os_error().raw_os_error().unwrap_or(0);
}
if !error.is_null() {
unsafe { *error = errno; }
}
ret
}

#[cfg(not(target_env="musl"))]
#[no_mangle]
pub extern "C" fn u_ioctl_arg0_ocall(error: *mut c_int, fd: c_int, request: c_int) -> c_int {
let mut errno = 0;
Expand All @@ -232,6 +251,24 @@ pub extern "C" fn u_ioctl_arg0_ocall(error: *mut c_int, fd: c_int, request: c_in
ret
}

#[cfg(all(target_env="musl", not(target_env="")))]
#[no_mangle]
pub extern "C" fn u_ioctl_arg1_ocall(error: * mut c_int,
fd: c_int,
request: c_int,
arg: * const c_int) -> c_int {
let mut errno = 0;
let ret = unsafe { libc::ioctl(fd, request, arg) };
if ret < 0 {
errno = Error::last_os_error().raw_os_error().unwrap_or(0);
}
if !error.is_null() {
unsafe { *error = errno; }
}
ret
}

#[cfg(not(target_env="musl"))]
#[no_mangle]
pub extern "C" fn u_ioctl_arg1_ocall(
error: *mut c_int,
Expand Down