open_coroutine_hooks/unix/
read.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 RECV: Lazy<extern "C" fn(c_int, *mut c_void, size_t, c_int) -> ssize_t> = init_hook!("recv");
6
7#[no_mangle]
8pub extern "C" fn recv(socket: c_int, buf: *mut c_void, len: size_t, flags: c_int) -> ssize_t {
9 open_coroutine_core::syscall::recv(Some(Lazy::force(&RECV)), socket, buf, len, flags)
10}
11
12static RECVFROM: Lazy<
13 extern "C" fn(c_int, *mut c_void, size_t, c_int, *mut sockaddr, *mut socklen_t) -> ssize_t,
14> = init_hook!("recvfrom");
15
16#[no_mangle]
17pub extern "C" fn recvfrom(
18 socket: c_int,
19 buf: *mut c_void,
20 len: size_t,
21 flags: c_int,
22 addr: *mut sockaddr,
23 addrlen: *mut socklen_t,
24) -> ssize_t {
25 open_coroutine_core::syscall::recvfrom(
26 Some(Lazy::force(&RECVFROM)),
27 socket,
28 buf,
29 len,
30 flags,
31 addr,
32 addrlen,
33 )
34}
35
36static PREAD: Lazy<extern "C" fn(c_int, *mut c_void, size_t, off_t) -> ssize_t> =
37 init_hook!("pread");
38
39#[no_mangle]
40pub extern "C" fn pread(fd: c_int, buf: *mut c_void, count: size_t, offset: off_t) -> ssize_t {
41 open_coroutine_core::syscall::pread(Some(Lazy::force(&PREAD)), fd, buf, count, offset)
42}
43
44static READV: Lazy<extern "C" fn(c_int, *const iovec, c_int) -> ssize_t> = init_hook!("readv");
45
46#[no_mangle]
47pub extern "C" fn readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
48 open_coroutine_core::syscall::readv(Some(Lazy::force(&READV)), fd, iov, iovcnt)
49}
50
51static PREADV: Lazy<extern "C" fn(c_int, *const iovec, c_int, off_t) -> ssize_t> =
52 init_hook!("preadv");
53
54#[no_mangle]
55pub extern "C" fn preadv(fd: c_int, iov: *const iovec, iovcnt: c_int, offset: off_t) -> ssize_t {
56 open_coroutine_core::syscall::preadv(Some(Lazy::force(&PREADV)), fd, iov, iovcnt, offset)
57}
58
59static RECVMSG: Lazy<extern "C" fn(c_int, *mut msghdr, c_int) -> ssize_t> = init_hook!("recvmsg");
60
61#[no_mangle]
62pub extern "C" fn recvmsg(fd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t {
63 open_coroutine_core::syscall::recvmsg(Some(Lazy::force(&RECVMSG)), fd, msg, flags)
64}