open_coroutine_hooks/unix/
write.rs1use libc::{iovec, msghdr, off_t, size_t, sockaddr, socklen_t, ssize_t};
2use once_cell::sync::Lazy;
3use std::ffi::{c_int, c_void};
4
5static SEND: Lazy<extern "C" fn(c_int, *const c_void, size_t, c_int) -> ssize_t> =
6 init_hook!("send");
7
8#[no_mangle]
9pub extern "C" fn send(socket: c_int, buf: *const c_void, len: size_t, flags: c_int) -> ssize_t {
10 open_coroutine_core::syscall::send(Some(Lazy::force(&SEND)), socket, buf, len, flags)
11}
12
13static SENDTO: Lazy<
14 extern "C" fn(c_int, *const c_void, size_t, c_int, *const sockaddr, socklen_t) -> ssize_t,
15> = init_hook!("sendto");
16
17#[no_mangle]
18pub extern "C" fn sendto(
19 socket: c_int,
20 buf: *const c_void,
21 len: size_t,
22 flags: c_int,
23 addr: *const sockaddr,
24 addrlen: socklen_t,
25) -> ssize_t {
26 open_coroutine_core::syscall::sendto(
27 Some(Lazy::force(&SENDTO)),
28 socket,
29 buf,
30 len,
31 flags,
32 addr,
33 addrlen,
34 )
35}
36
37static PWRITE: Lazy<extern "C" fn(c_int, *const c_void, size_t, off_t) -> ssize_t> =
38 init_hook!("pwrite");
39
40#[no_mangle]
41pub extern "C" fn pwrite(fd: c_int, buf: *const c_void, count: size_t, offset: off_t) -> ssize_t {
42 open_coroutine_core::syscall::pwrite(Some(Lazy::force(&PWRITE)), fd, buf, count, offset)
43}
44
45static WRITEV: Lazy<extern "C" fn(c_int, *const iovec, c_int) -> ssize_t> = init_hook!("writev");
46
47#[no_mangle]
48pub extern "C" fn writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
49 open_coroutine_core::syscall::writev(Some(Lazy::force(&WRITEV)), fd, iov, iovcnt)
50}
51
52static PWRITEV: Lazy<extern "C" fn(c_int, *const iovec, c_int, off_t) -> ssize_t> =
53 init_hook!("pwritev");
54
55#[no_mangle]
56pub extern "C" fn pwritev(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t {
57 open_coroutine_core::syscall::pwritev(Some(Lazy::force(&PWRITEV)), fd, iov, iovcnt, offset)
58}
59
60static SENDMSG: Lazy<extern "C" fn(c_int, *const msghdr, c_int) -> ssize_t> = init_hook!("sendmsg");
61
62#[no_mangle]
63pub extern "C" fn sendmsg(fd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t {
64 open_coroutine_core::syscall::sendmsg(Some(Lazy::force(&SENDMSG)), fd, msg, flags)
65}