From 30666f8692574f0a3f14f0ff6cc2b391664f2081 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 31 May 2024 16:56:44 +0200 Subject: [PATCH] getting a bit further now --- Cargo.lock | 7 + examples/src/main.rs | 253 +----- lib/bindings.rs | 1833 +++++++++++++++++++++++++++++++++++++++- lib/clone-csp.sh | 2 +- lib/gen-bindings.sh | 2 +- lib/wrapper.h | 1 + libcsp-rust/Cargo.toml | 1 + libcsp-rust/src/ffi.rs | 249 +++++- libcsp-rust/src/lib.rs | 137 +-- 9 files changed, 2184 insertions(+), 301 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9097735..0ebd55b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + [[package]] name = "libcsp-cargo-build" version = "0.1.0" @@ -48,6 +54,7 @@ name = "libcsp-rust" version = "0.1.0" dependencies = [ "bitflags", + "libc", "num_enum", ] diff --git a/examples/src/main.rs b/examples/src/main.rs index 7877d43..f6b864c 100644 --- a/examples/src/main.rs +++ b/examples/src/main.rs @@ -15,235 +15,12 @@ use libcsp_rust::{ }; const MY_SERVER_PORT: i32 = 10; +const TEST_MODE: bool = false; const RUN_DURATION_IN_SECS: u32 = 3; -const TEST_MODE: bool = false; - -/* -#include -#include -#include -#include - -#include -#include -#include -#include - - -/* These three functions must be provided in arch specific way */ -int router_start(void); -int server_start(void); -int client_start(void); - -/* Server port, the port the server listens on for incoming connections from the client. */ -#define MY_SERVER_PORT 10 - -/* Commandline options */ -static uint8_t server_address = 255; - -/* test mode, used for verifying that host & client can exchange packets over the loopback interface */ -static bool test_mode = false; -static unsigned int server_received = 0; -static unsigned int run_duration_in_sec = 3; - -/* Server task - handles requests from clients */ -void server(void) { - - csp_print("Server task started\n"); - - /* Create socket with no specific socket options, e.g. accepts CRC32, HMAC, etc. if enabled during compilation */ - csp_socket_t sock = {0}; - - /* Bind socket to all ports, e.g. all incoming connections will be handled here */ - csp_bind(&sock, CSP_ANY); - - /* Create a backlog of 10 connections, i.e. up to 10 new connections can be queued */ - csp_listen(&sock, 10); - - /* Wait for connections and then process packets on the connection */ - while (1) { - - /* Wait for a new connection, 10000 mS timeout */ - csp_conn_t *conn; - if ((conn = csp_accept(&sock, 10000)) == NULL) { - /* timeout */ - continue; - } - - /* Read packets on connection, timout is 100 mS */ - csp_packet_t *packet; - while ((packet = csp_read(conn, 50)) != NULL) { - switch (csp_conn_dport(conn)) { - case MY_SERVER_PORT: - /* Process packet here */ - csp_print("Packet received on MY_SERVER_PORT: %s\n", (char *) packet->data); - csp_buffer_free(packet); - ++server_received; - break; - - default: - /* Call the default CSP service handler, handle pings, buffer use, etc. */ - csp_service_handler(packet); - break; - } - } - - /* Close current connection */ - csp_close(conn); - - } - - return; - -} -/* End of server task */ - -/* Client task sending requests to server task */ -void client(void) { - - csp_print("Client task started\n"); - - unsigned int count = 'A'; - - while (1) { - - usleep(test_mode ? 200000 : 1000000); - - /* Send ping to server, timeout 1000 mS, ping size 100 bytes */ - int result = csp_ping(server_address, 1000, 100, CSP_O_NONE); - csp_print("Ping address: %u, result %d [mS]\n", server_address, result); - (void) result; - - /* Send reboot request to server, the server has no actual implementation of csp_sys_reboot() and fails to reboot */ - csp_reboot(server_address); - csp_print("reboot system request sent to address: %u\n", server_address); - - /* Send data packet (string) to server */ - - /* 1. Connect to host on 'server_address', port MY_SERVER_PORT with regular UDP-like protocol and 1000 ms timeout */ - csp_conn_t * conn = csp_connect(CSP_PRIO_NORM, server_address, MY_SERVER_PORT, 1000, CSP_O_NONE); - if (conn == NULL) { - /* Connect failed */ - csp_print("Connection failed\n"); - return; - } - - /* 2. Get packet buffer for message/data */ - csp_packet_t * packet = csp_buffer_get(100); - if (packet == NULL) { - /* Could not get buffer element */ - csp_print("Failed to get CSP buffer\n"); - return; - } - - /* 3. Copy data to packet */ - memcpy(packet->data, "Hello world ", 12); - memcpy(packet->data + 12, &count, 1); - memset(packet->data + 13, 0, 1); - count++; - - /* 4. Set packet length */ - packet->length = (strlen((char *) packet->data) + 1); /* include the 0 termination */ - - /* 5. Send packet */ - csp_send(conn, packet); - - /* 6. Close connection */ - csp_close(conn); - } - - return; -} -/* End of client task */ - -static void print_usage(void) -{ - csp_print("Usage:\n" - " -t enable test mode\n" - " -T enable test mode with running time in seconds\n" - " -h print help\n"); -} - -/* main - initialization of CSP and start of server/client tasks */ -int main(int argc, char * argv[]) { - - uint8_t address = 0; - int opt; - while ((opt = getopt(argc, argv, "tT:h")) != -1) { - switch (opt) { - case 'a': - address = atoi(optarg); - break; - case 'r': - server_address = atoi(optarg); - break; - case 't': - test_mode = true; - break; - case 'T': - test_mode = true; - run_duration_in_sec = atoi(optarg); - break; - case 'h': - print_usage(); - exit(0); - break; - default: - print_usage(); - exit(1); - break; - } - } - - csp_print("Initialising CSP"); - - /* Init CSP */ - csp_init(); - - /* Start router */ - router_start(); - - /* Add interface(s) */ - csp_iface_t * default_iface = NULL; - if (!default_iface) { - /* no interfaces configured - run server and client in process, using loopback interface */ - server_address = address; - } - - csp_print("Connection table\r\n"); - csp_conn_print_table(); - - csp_print("Interfaces\r\n"); - csp_iflist_print(); - - /* Start server thread */ - server_start(); - - /* Start client thread */ - client_start(); - - /* Wait for execution to end (ctrl+c) */ - while(1) { - sleep(run_duration_in_sec); - - if (test_mode) { - /* Test mode is intended for checking that host & client can exchange packets over loopback */ - if (server_received < 5) { - csp_print("Server received %u packets\n", server_received); - exit(1); - } - csp_print("Server received %u packets\n", server_received); - exit(0); - } - } - - return 0; -} -*/ - fn main() -> Result<(), u32> { - println!("CSP server example"); + println!("CSP client/server example"); + // SAFETY: We only call this once. unsafe { csp_init() }; @@ -288,9 +65,7 @@ fn main() -> Result<(), u32> { let received_count = server_recv_copy.load(std::sync::atomic::Ordering::Relaxed); println!("CSP: Server received {} packets", received_count); if received_count < 5 { - stop_signal.store(true, std::sync::atomic::Ordering::Relaxed); app_result = Err(1); - break; } stop_signal.store(true, std::sync::atomic::Ordering::Relaxed); break; @@ -327,21 +102,26 @@ fn server(server_received: Arc, stop_signal: Arc) { if conn.is_none() { continue; } - let conn = conn.unwrap(); + println!("server accepted conn"); + let mut conn = conn.unwrap(); // Read packets on connection, timout is 100 mS loop { if stop_signal.load(std::sync::atomic::Ordering::Relaxed) { break; } + + println!("server trying read"); // SAFETY: Connection is active while we read here. - let packet = unsafe { csp_read(conn.0, Duration::from_millis(100)) }; + let packet = unsafe { csp_read(&mut conn.0, Duration::from_millis(100)) }; if packet.is_none() { break; } + println!("server read a packet"); let mut packet = packet.unwrap(); - match csp_conn_dport(conn.0) { + match csp_conn_dport(&conn.0) { MY_SERVER_PORT => { + println!("server received packet on custom port"); server_received.fetch_add(1, std::sync::atomic::Ordering::Relaxed); // Process packet here. println!( @@ -350,6 +130,7 @@ fn server(server_received: Arc, stop_signal: Arc) { ); } _ => { + println!("calling CSP service handler"); csp_service_handler(&mut packet); } }; @@ -371,6 +152,8 @@ fn client(stop_signal: Arc) { } else { thread::sleep(Duration::from_millis(100)); } + println!("client trying to ping"); + // Send ping to server, timeout 1000 mS, ping size 100 bytes if let Err(e) = csp_ping( CSP_LOOPBACK, @@ -401,7 +184,7 @@ fn client(stop_signal: Arc) { println!("CSP client: connection failed"); return; } - let conn = conn.unwrap(); + let mut conn = conn.unwrap(); // 2. Get packet buffer for message/data. let packet_ref = csp_buffer_get(); @@ -409,7 +192,7 @@ fn client(stop_signal: Arc) { println!("CSP client: failed to get CSP buffer"); return; } - let mut packet_ref = packet_ref.unwrap(); + let mut packet_mut = packet_ref.unwrap(); // 3. Copy data to packet. let mut string_to_set = String::from("Hello world"); @@ -417,9 +200,9 @@ fn client(stop_signal: Arc) { string_to_set.push(current_letter); current_letter = (current_letter as u8 + 1) as char; string_to_set.push('\0'); - packet_ref.set_data(string_to_set.as_bytes()); + packet_mut.set_data(string_to_set.as_bytes()); // 4. Send data. - csp_send(conn.0, packet_ref); + csp_send(&mut conn.0, packet_mut); } } diff --git a/lib/bindings.rs b/lib/bindings.rs index 3e143b8..8cc8d9c 100644 --- a/lib/bindings.rs +++ b/lib/bindings.rs @@ -23,7 +23,7 @@ pub const CSP_HAVE_STDIO: u32 = 1; pub const CSP_ENABLE_CSP_PRINT: u32 = 1; pub const CSP_PRINT_STDIO: u32 = 1; pub const CSP_REPRODUCIBLE_BUILDS: u32 = 0; -pub const CSP_QFIFO_LEN: u32 = 15; +pub const CSP_QFIFO_LEN: u32 = 16; pub const CSP_PORT_MAX_BIND: u32 = 16; pub const CSP_CONN_RXQUEUE_LEN: u32 = 16; pub const CSP_CONN_MAX: u32 = 8; @@ -34,9 +34,9 @@ pub const CSP_RTABLE_SIZE: u32 = 10; pub const CSP_USE_RDP: u32 = 1; pub const CSP_USE_HMAC: u32 = 1; pub const CSP_USE_PROMISC: u32 = 1; -pub const CSP_USE_RTABLE: u32 = 1; +pub const CSP_USE_RTABLE: u32 = 0; pub const CSP_HAVE_LIBSOCKETCAN: u32 = 0; -pub const CSP_HAVE_LIBZMQ: u32 = 1; +pub const CSP_HAVE_LIBZMQ: u32 = 0; pub const _INTTYPES_H: u32 = 1; pub const _FEATURES_H: u32 = 1; pub const _DEFAULT_SOURCE: u32 = 1; @@ -313,9 +313,9 @@ pub const CSP_DBG_ETH_ERR_RX_OUT: u32 = 3; pub const CSP_DBG_ETH_ERR_SHORT_BEGIN: u32 = 4; pub const CSP_DBG_ETH_ERR_INCOMPLETE: u32 = 5; pub const CSP_DBG_ETH_ERR_UNKNOWN: u32 = 6; -pub const __bool_true_false_are_defined: u32 = 1; pub const true_: u32 = 1; pub const false_: u32 = 0; +pub const __bool_true_false_are_defined: u32 = 1; pub const CSP_QUEUE_OK: u32 = 0; pub const CSP_QUEUE_ERROR: i32 = -1; pub const CSP_ANY: u32 = 255; @@ -358,6 +358,54 @@ pub const _STRINGS_H: u32 = 1; pub const CSP_MAX_TIMEOUT: u32 = 4294967295; pub const CSP_MAX_DELAY: u32 = 4294967295; pub const CSP_INFINITY: u32 = 4294967295; +pub const CSP_SEMAPHORE_OK: u32 = 0; +pub const CSP_SEMAPHORE_ERROR: i32 = -1; +pub const _SEMAPHORE_H: u32 = 1; +pub const _SYS_TYPES_H: u32 = 1; +pub const __clock_t_defined: u32 = 1; +pub const __clockid_t_defined: u32 = 1; +pub const __time_t_defined: u32 = 1; +pub const __timer_t_defined: u32 = 1; +pub const __BIT_TYPES_DEFINED__: u32 = 1; +pub const _ENDIAN_H: u32 = 1; +pub const _BITS_ENDIAN_H: u32 = 1; +pub const __LITTLE_ENDIAN: u32 = 1234; +pub const __BIG_ENDIAN: u32 = 4321; +pub const __PDP_ENDIAN: u32 = 3412; +pub const _BITS_ENDIANNESS_H: u32 = 1; +pub const __BYTE_ORDER: u32 = 1234; +pub const __FLOAT_WORD_ORDER: u32 = 1234; +pub const LITTLE_ENDIAN: u32 = 1234; +pub const BIG_ENDIAN: u32 = 4321; +pub const PDP_ENDIAN: u32 = 3412; +pub const BYTE_ORDER: u32 = 1234; +pub const _BITS_BYTESWAP_H: u32 = 1; +pub const _BITS_UINTN_IDENTITY_H: u32 = 1; +pub const _SYS_SELECT_H: u32 = 1; +pub const __sigset_t_defined: u32 = 1; +pub const __timeval_defined: u32 = 1; +pub const _STRUCT_TIMESPEC: u32 = 1; +pub const FD_SETSIZE: u32 = 1024; +pub const _BITS_PTHREADTYPES_COMMON_H: u32 = 1; +pub const _THREAD_SHARED_TYPES_H: u32 = 1; +pub const _BITS_PTHREADTYPES_ARCH_H: u32 = 1; +pub const __SIZEOF_PTHREAD_MUTEX_T: u32 = 40; +pub const __SIZEOF_PTHREAD_ATTR_T: u32 = 56; +pub const __SIZEOF_PTHREAD_RWLOCK_T: u32 = 56; +pub const __SIZEOF_PTHREAD_BARRIER_T: u32 = 32; +pub const __SIZEOF_PTHREAD_MUTEXATTR_T: u32 = 4; +pub const __SIZEOF_PTHREAD_COND_T: u32 = 48; +pub const __SIZEOF_PTHREAD_CONDATTR_T: u32 = 4; +pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: u32 = 8; +pub const __SIZEOF_PTHREAD_BARRIERATTR_T: u32 = 4; +pub const _THREAD_MUTEX_INTERNAL_H: u32 = 1; +pub const __PTHREAD_MUTEX_HAVE_PREV: u32 = 1; +pub const __have_pthread_attr_t: u32 = 1; +pub const __SIZEOF_SEM_T: u32 = 32; +pub const CSP_RDP_CLOSED_BY_USERSPACE: u32 = 1; +pub const CSP_RDP_CLOSED_BY_PROTOCOL: u32 = 2; +pub const CSP_RDP_CLOSED_BY_TIMEOUT: u32 = 4; +pub const CSP_RDP_CLOSED_BY_ALL: u32 = 7; pub type __u_char = ::core::ffi::c_uchar; pub type __u_short = ::core::ffi::c_ushort; pub type __u_int = ::core::ffi::c_uint; @@ -1934,11 +1982,7 @@ extern "C" { ) -> ::core::ffi::c_int; } extern "C" { - pub fn bcopy( - __src: *const ::core::ffi::c_void, - __dest: *mut ::core::ffi::c_void, - __n: ::core::ffi::c_ulong, - ); + pub fn bcopy(__src: *const ::core::ffi::c_void, __dest: *mut ::core::ffi::c_void, __n: usize); } extern "C" { pub fn bzero(__s: *mut ::core::ffi::c_void, __n: ::core::ffi::c_ulong); @@ -2184,7 +2228,7 @@ extern "C" { } extern "C" { #[doc = " Copy csp id fields from source to target object"] - pub fn csp_id_copy(target: *mut csp_id_t, source: *mut csp_id_t); + pub fn csp_id_copy(target: *mut csp_id_t, source: *const csp_id_t); } extern "C" { #[doc = " Wait/accept a new connection.\n\n @param[in] socket socket to accept connections on, created by calling csp_socket().\n @param[in] timeout timeout in mS to wait for a connection, use CSP_MAX_TIMEOUT for infinite timeout.\n @return New connection on success, NULL on failure or timeout."] @@ -2266,23 +2310,23 @@ extern "C" { } extern "C" { #[doc = " Return destination port of connection.\n\n @param[in] conn connection\n @return destination port of an incoming connection"] - pub fn csp_conn_dport(conn: *mut csp_conn_t) -> ::core::ffi::c_int; + pub fn csp_conn_dport(conn: *const csp_conn_t) -> ::core::ffi::c_int; } extern "C" { #[doc = " Return source port of connection.\n\n @param[in] conn connection\n @return source port of an incoming connection"] - pub fn csp_conn_sport(conn: *mut csp_conn_t) -> ::core::ffi::c_int; + pub fn csp_conn_sport(conn: *const csp_conn_t) -> ::core::ffi::c_int; } extern "C" { #[doc = " Return destination address of connection.\n\n @param[in] conn connection\n @return destination address of an incoming connection"] - pub fn csp_conn_dst(conn: *mut csp_conn_t) -> ::core::ffi::c_int; + pub fn csp_conn_dst(conn: *const csp_conn_t) -> ::core::ffi::c_int; } extern "C" { #[doc = " Return source address of connection.\n\n @param[in] conn connection\n @return source address of an incoming connection"] - pub fn csp_conn_src(conn: *mut csp_conn_t) -> ::core::ffi::c_int; + pub fn csp_conn_src(conn: *const csp_conn_t) -> ::core::ffi::c_int; } extern "C" { #[doc = " Return flags of connection.\n\n @param[in] conn connection\n @return flags of an incoming connection, see @ref CSP_HEADER_FLAGS"] - pub fn csp_conn_flags(conn: *mut csp_conn_t) -> ::core::ffi::c_int; + pub fn csp_conn_flags(conn: *const csp_conn_t) -> ::core::ffi::c_int; } extern "C" { #[doc = " Set socket to listen for incoming connections.\n\n @param[in] socket socket\n @param[in] backlog max length of backlog queue. The backlog queue holds incoming connections, waiting to be returned by call to csp_accept().\n @return #CSP_ERR_NONE on success, otherwise an error code."] @@ -2406,10 +2450,1767 @@ extern "C" { str_size: ::core::ffi::c_int, ) -> ::core::ffi::c_int; } +pub const memory_order_memory_order_relaxed: memory_order = 0; +pub const memory_order_memory_order_consume: memory_order = 1; +pub const memory_order_memory_order_acquire: memory_order = 2; +pub const memory_order_memory_order_release: memory_order = 3; +pub const memory_order_memory_order_acq_rel: memory_order = 4; +pub const memory_order_memory_order_seq_cst: memory_order = 5; +pub type memory_order = ::core::ffi::c_uint; +extern "C" { + pub fn atomic_thread_fence(arg1: memory_order); +} +extern "C" { + pub fn atomic_signal_fence(arg1: memory_order); +} +pub type atomic_bool = u8; +pub type atomic_char = u8; +pub type atomic_schar = u8; +pub type atomic_uchar = u8; +pub type atomic_short = u16; +pub type atomic_ushort = u16; +pub type atomic_int = u32; +pub type atomic_uint = u32; +pub type atomic_long = u64; +pub type atomic_ulong = u64; +pub type atomic_llong = u64; +pub type atomic_ullong = u64; +pub type atomic_char16_t = u16; +pub type atomic_char32_t = u32; +pub type atomic_wchar_t = u32; +pub type atomic_int_least8_t = u8; +pub type atomic_uint_least8_t = u8; +pub type atomic_int_least16_t = u16; +pub type atomic_uint_least16_t = u16; +pub type atomic_int_least32_t = u32; +pub type atomic_uint_least32_t = u32; +pub type atomic_int_least64_t = u64; +pub type atomic_uint_least64_t = u64; +pub type atomic_int_fast8_t = u8; +pub type atomic_uint_fast8_t = u8; +pub type atomic_int_fast16_t = u64; +pub type atomic_uint_fast16_t = u64; +pub type atomic_int_fast32_t = u64; +pub type atomic_uint_fast32_t = u64; +pub type atomic_int_fast64_t = u64; +pub type atomic_uint_fast64_t = u64; +pub type atomic_intptr_t = u64; +pub type atomic_uintptr_t = u64; +pub type atomic_size_t = u64; +pub type atomic_ptrdiff_t = u64; +pub type atomic_intmax_t = u64; +pub type atomic_uintmax_t = u64; #[repr(C)] #[derive(Debug, Copy, Clone)] +pub struct atomic_flag { + pub _Value: atomic_bool, +} +#[test] +fn bindgen_test_layout_atomic_flag() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 1usize, + concat!("Size of: ", stringify!(atomic_flag)) + ); + assert_eq!( + ::core::mem::align_of::(), + 1usize, + concat!("Alignment of ", stringify!(atomic_flag)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr)._Value) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(atomic_flag), + "::", + stringify!(_Value) + ) + ); +} +extern "C" { + pub fn atomic_flag_test_and_set(arg1: *mut atomic_flag) -> bool; +} +extern "C" { + pub fn atomic_flag_test_and_set_explicit(arg1: *mut atomic_flag, arg2: memory_order) -> bool; +} +extern "C" { + pub fn atomic_flag_clear(arg1: *mut atomic_flag); +} +extern "C" { + pub fn atomic_flag_clear_explicit(arg1: *mut atomic_flag, arg2: memory_order); +} +pub type u_char = __u_char; +pub type u_short = __u_short; +pub type u_int = __u_int; +pub type u_long = __u_long; +pub type quad_t = __quad_t; +pub type u_quad_t = __u_quad_t; +pub type fsid_t = __fsid_t; +pub type loff_t = __loff_t; +pub type ino_t = __ino_t; +pub type dev_t = __dev_t; +pub type gid_t = __gid_t; +pub type mode_t = __mode_t; +pub type nlink_t = __nlink_t; +pub type uid_t = __uid_t; +pub type off_t = __off_t; +pub type pid_t = __pid_t; +pub type id_t = __id_t; +pub type daddr_t = __daddr_t; +pub type caddr_t = __caddr_t; +pub type key_t = __key_t; +pub type clock_t = __clock_t; +pub type clockid_t = __clockid_t; +pub type time_t = __time_t; +pub type timer_t = __timer_t; +pub type ulong = ::core::ffi::c_ulong; +pub type ushort = ::core::ffi::c_ushort; +pub type uint = ::core::ffi::c_uint; +pub type u_int8_t = __uint8_t; +pub type u_int16_t = __uint16_t; +pub type u_int32_t = __uint32_t; +pub type u_int64_t = __uint64_t; +pub type register_t = ::core::ffi::c_long; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __sigset_t { + pub __val: [::core::ffi::c_ulong; 16usize], +} +#[test] +fn bindgen_test_layout___sigset_t() { + const UNINIT: ::core::mem::MaybeUninit<__sigset_t> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__sigset_t>(), + 128usize, + concat!("Size of: ", stringify!(__sigset_t)) + ); + assert_eq!( + ::core::mem::align_of::<__sigset_t>(), + 8usize, + concat!("Alignment of ", stringify!(__sigset_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__val) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__sigset_t), + "::", + stringify!(__val) + ) + ); +} +pub type sigset_t = __sigset_t; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct timeval { + pub tv_sec: __time_t, + pub tv_usec: __suseconds_t, +} +#[test] +fn bindgen_test_layout_timeval() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(timeval)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timeval)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_usec) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timeval), + "::", + stringify!(tv_usec) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct timespec { + pub tv_sec: __time_t, + pub tv_nsec: __syscall_slong_t, +} +#[test] +fn bindgen_test_layout_timespec() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 16usize, + concat!("Size of: ", stringify!(timespec)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(timespec)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(timespec), + "::", + stringify!(tv_sec) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tv_nsec) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(timespec), + "::", + stringify!(tv_nsec) + ) + ); +} +pub type suseconds_t = __suseconds_t; +pub type __fd_mask = ::core::ffi::c_long; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct fd_set { + pub __fds_bits: [__fd_mask; 16usize], +} +#[test] +fn bindgen_test_layout_fd_set() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 128usize, + concat!("Size of: ", stringify!(fd_set)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(fd_set)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__fds_bits) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(fd_set), + "::", + stringify!(__fds_bits) + ) + ); +} +pub type fd_mask = __fd_mask; +extern "C" { + pub fn select( + __nfds: ::core::ffi::c_int, + __readfds: *mut fd_set, + __writefds: *mut fd_set, + __exceptfds: *mut fd_set, + __timeout: *mut timeval, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn pselect( + __nfds: ::core::ffi::c_int, + __readfds: *mut fd_set, + __writefds: *mut fd_set, + __exceptfds: *mut fd_set, + __timeout: *const timespec, + __sigmask: *const __sigset_t, + ) -> ::core::ffi::c_int; +} +pub type blksize_t = __blksize_t; +pub type blkcnt_t = __blkcnt_t; +pub type fsblkcnt_t = __fsblkcnt_t; +pub type fsfilcnt_t = __fsfilcnt_t; +#[repr(C)] +#[derive(Copy, Clone)] +pub union __atomic_wide_counter { + pub __value64: ::core::ffi::c_ulonglong, + pub __value32: __atomic_wide_counter__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __atomic_wide_counter__bindgen_ty_1 { + pub __low: ::core::ffi::c_uint, + pub __high: ::core::ffi::c_uint, +} +#[test] +fn bindgen_test_layout___atomic_wide_counter__bindgen_ty_1() { + const UNINIT: ::core::mem::MaybeUninit<__atomic_wide_counter__bindgen_ty_1> = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__atomic_wide_counter__bindgen_ty_1>(), + 8usize, + concat!("Size of: ", stringify!(__atomic_wide_counter__bindgen_ty_1)) + ); + assert_eq!( + ::core::mem::align_of::<__atomic_wide_counter__bindgen_ty_1>(), + 4usize, + concat!( + "Alignment of ", + stringify!(__atomic_wide_counter__bindgen_ty_1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__low) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__atomic_wide_counter__bindgen_ty_1), + "::", + stringify!(__low) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__high) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(__atomic_wide_counter__bindgen_ty_1), + "::", + stringify!(__high) + ) + ); +} +#[test] +fn bindgen_test_layout___atomic_wide_counter() { + const UNINIT: ::core::mem::MaybeUninit<__atomic_wide_counter> = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__atomic_wide_counter>(), + 8usize, + concat!("Size of: ", stringify!(__atomic_wide_counter)) + ); + assert_eq!( + ::core::mem::align_of::<__atomic_wide_counter>(), + 8usize, + concat!("Alignment of ", stringify!(__atomic_wide_counter)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__value64) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__atomic_wide_counter), + "::", + stringify!(__value64) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__value32) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__atomic_wide_counter), + "::", + stringify!(__value32) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __pthread_internal_list { + pub __prev: *mut __pthread_internal_list, + pub __next: *mut __pthread_internal_list, +} +#[test] +fn bindgen_test_layout___pthread_internal_list() { + const UNINIT: ::core::mem::MaybeUninit<__pthread_internal_list> = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__pthread_internal_list>(), + 16usize, + concat!("Size of: ", stringify!(__pthread_internal_list)) + ); + assert_eq!( + ::core::mem::align_of::<__pthread_internal_list>(), + 8usize, + concat!("Alignment of ", stringify!(__pthread_internal_list)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__prev) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__pthread_internal_list), + "::", + stringify!(__prev) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__next) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(__pthread_internal_list), + "::", + stringify!(__next) + ) + ); +} +pub type __pthread_list_t = __pthread_internal_list; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __pthread_internal_slist { + pub __next: *mut __pthread_internal_slist, +} +#[test] +fn bindgen_test_layout___pthread_internal_slist() { + const UNINIT: ::core::mem::MaybeUninit<__pthread_internal_slist> = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__pthread_internal_slist>(), + 8usize, + concat!("Size of: ", stringify!(__pthread_internal_slist)) + ); + assert_eq!( + ::core::mem::align_of::<__pthread_internal_slist>(), + 8usize, + concat!("Alignment of ", stringify!(__pthread_internal_slist)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__next) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__pthread_internal_slist), + "::", + stringify!(__next) + ) + ); +} +pub type __pthread_slist_t = __pthread_internal_slist; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __pthread_mutex_s { + pub __lock: ::core::ffi::c_int, + pub __count: ::core::ffi::c_uint, + pub __owner: ::core::ffi::c_int, + pub __nusers: ::core::ffi::c_uint, + pub __kind: ::core::ffi::c_int, + pub __spins: ::core::ffi::c_short, + pub __elision: ::core::ffi::c_short, + pub __list: __pthread_list_t, +} +#[test] +fn bindgen_test_layout___pthread_mutex_s() { + const UNINIT: ::core::mem::MaybeUninit<__pthread_mutex_s> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__pthread_mutex_s>(), + 40usize, + concat!("Size of: ", stringify!(__pthread_mutex_s)) + ); + assert_eq!( + ::core::mem::align_of::<__pthread_mutex_s>(), + 8usize, + concat!("Alignment of ", stringify!(__pthread_mutex_s)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__lock) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__lock) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__count) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__count) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__owner) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__owner) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__nusers) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__nusers) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__kind) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__kind) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__spins) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__spins) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__elision) as usize - ptr as usize }, + 22usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__elision) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__list) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(__pthread_mutex_s), + "::", + stringify!(__list) + ) + ); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __pthread_rwlock_arch_t { + pub __readers: ::core::ffi::c_uint, + pub __writers: ::core::ffi::c_uint, + pub __wrphase_futex: ::core::ffi::c_uint, + pub __writers_futex: ::core::ffi::c_uint, + pub __pad3: ::core::ffi::c_uint, + pub __pad4: ::core::ffi::c_uint, + pub __cur_writer: ::core::ffi::c_int, + pub __shared: ::core::ffi::c_int, + pub __rwelision: ::core::ffi::c_schar, + pub __pad1: [::core::ffi::c_uchar; 7usize], + pub __pad2: ::core::ffi::c_ulong, + pub __flags: ::core::ffi::c_uint, +} +#[test] +fn bindgen_test_layout___pthread_rwlock_arch_t() { + const UNINIT: ::core::mem::MaybeUninit<__pthread_rwlock_arch_t> = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__pthread_rwlock_arch_t>(), + 56usize, + concat!("Size of: ", stringify!(__pthread_rwlock_arch_t)) + ); + assert_eq!( + ::core::mem::align_of::<__pthread_rwlock_arch_t>(), + 8usize, + concat!("Alignment of ", stringify!(__pthread_rwlock_arch_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__readers) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__readers) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__writers) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__writers) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__wrphase_futex) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__wrphase_futex) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__writers_futex) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__writers_futex) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad3) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__pad3) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad4) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__pad4) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__cur_writer) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__cur_writer) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__shared) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__shared) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__rwelision) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__rwelision) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad1) as usize - ptr as usize }, + 33usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__pad1) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__pad2) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__pad2) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__flags) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(__pthread_rwlock_arch_t), + "::", + stringify!(__flags) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct __pthread_cond_s { + pub __wseq: __atomic_wide_counter, + pub __g1_start: __atomic_wide_counter, + pub __g_refs: [::core::ffi::c_uint; 2usize], + pub __g_size: [::core::ffi::c_uint; 2usize], + pub __g1_orig_size: ::core::ffi::c_uint, + pub __wrefs: ::core::ffi::c_uint, + pub __g_signals: [::core::ffi::c_uint; 2usize], +} +#[test] +fn bindgen_test_layout___pthread_cond_s() { + const UNINIT: ::core::mem::MaybeUninit<__pthread_cond_s> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__pthread_cond_s>(), + 48usize, + concat!("Size of: ", stringify!(__pthread_cond_s)) + ); + assert_eq!( + ::core::mem::align_of::<__pthread_cond_s>(), + 8usize, + concat!("Alignment of ", stringify!(__pthread_cond_s)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__wseq) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__pthread_cond_s), + "::", + stringify!(__wseq) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__g1_start) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(__pthread_cond_s), + "::", + stringify!(__g1_start) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__g_refs) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(__pthread_cond_s), + "::", + stringify!(__g_refs) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__g_size) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(__pthread_cond_s), + "::", + stringify!(__g_size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__g1_orig_size) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(__pthread_cond_s), + "::", + stringify!(__g1_orig_size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__wrefs) as usize - ptr as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(__pthread_cond_s), + "::", + stringify!(__wrefs) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__g_signals) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(__pthread_cond_s), + "::", + stringify!(__g_signals) + ) + ); +} +pub type __tss_t = ::core::ffi::c_uint; +pub type __thrd_t = ::core::ffi::c_ulong; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __once_flag { + pub __data: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout___once_flag() { + const UNINIT: ::core::mem::MaybeUninit<__once_flag> = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::<__once_flag>(), + 4usize, + concat!("Size of: ", stringify!(__once_flag)) + ); + assert_eq!( + ::core::mem::align_of::<__once_flag>(), + 4usize, + concat!("Alignment of ", stringify!(__once_flag)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__data) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(__once_flag), + "::", + stringify!(__data) + ) + ); +} +pub type pthread_t = ::core::ffi::c_ulong; +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_mutexattr_t { + pub __size: [::core::ffi::c_char; 4usize], + pub __align: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout_pthread_mutexattr_t() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pthread_mutexattr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pthread_mutexattr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_mutexattr_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_mutexattr_t), + "::", + stringify!(__align) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_condattr_t { + pub __size: [::core::ffi::c_char; 4usize], + pub __align: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout_pthread_condattr_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pthread_condattr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pthread_condattr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_condattr_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_condattr_t), + "::", + stringify!(__align) + ) + ); +} +pub type pthread_key_t = ::core::ffi::c_uint; +pub type pthread_once_t = ::core::ffi::c_int; +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_attr_t { + pub __size: [::core::ffi::c_char; 56usize], + pub __align: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_pthread_attr_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(pthread_attr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_attr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_attr_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_attr_t), + "::", + stringify!(__align) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_mutex_t { + pub __data: __pthread_mutex_s, + pub __size: [::core::ffi::c_char; 40usize], + pub __align: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_pthread_mutex_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 40usize, + concat!("Size of: ", stringify!(pthread_mutex_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_mutex_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__data) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_mutex_t), + "::", + stringify!(__data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_mutex_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_mutex_t), + "::", + stringify!(__align) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_cond_t { + pub __data: __pthread_cond_s, + pub __size: [::core::ffi::c_char; 48usize], + pub __align: ::core::ffi::c_longlong, +} +#[test] +fn bindgen_test_layout_pthread_cond_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(pthread_cond_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_cond_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__data) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_cond_t), + "::", + stringify!(__data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_cond_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_cond_t), + "::", + stringify!(__align) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_rwlock_t { + pub __data: __pthread_rwlock_arch_t, + pub __size: [::core::ffi::c_char; 56usize], + pub __align: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_pthread_rwlock_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 56usize, + concat!("Size of: ", stringify!(pthread_rwlock_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_rwlock_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__data) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_rwlock_t), + "::", + stringify!(__data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_rwlock_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_rwlock_t), + "::", + stringify!(__align) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_rwlockattr_t { + pub __size: [::core::ffi::c_char; 8usize], + pub __align: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_pthread_rwlockattr_t() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 8usize, + concat!("Size of: ", stringify!(pthread_rwlockattr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_rwlockattr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_rwlockattr_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_rwlockattr_t), + "::", + stringify!(__align) + ) + ); +} +pub type pthread_spinlock_t = ::core::ffi::c_int; +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_barrier_t { + pub __size: [::core::ffi::c_char; 32usize], + pub __align: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_pthread_barrier_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(pthread_barrier_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(pthread_barrier_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_barrier_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_barrier_t), + "::", + stringify!(__align) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union pthread_barrierattr_t { + pub __size: [::core::ffi::c_char; 4usize], + pub __align: ::core::ffi::c_int, +} +#[test] +fn bindgen_test_layout_pthread_barrierattr_t() { + const UNINIT: ::core::mem::MaybeUninit = + ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 4usize, + concat!("Size of: ", stringify!(pthread_barrierattr_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 4usize, + concat!("Alignment of ", stringify!(pthread_barrierattr_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_barrierattr_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(pthread_barrierattr_t), + "::", + stringify!(__align) + ) + ); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union sem_t { + pub __size: [::core::ffi::c_char; 32usize], + pub __align: ::core::ffi::c_long, +} +#[test] +fn bindgen_test_layout_sem_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(sem_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(sem_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sem_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sem_t), + "::", + stringify!(__align) + ) + ); +} +extern "C" { + pub fn sem_init( + __sem: *mut sem_t, + __pshared: ::core::ffi::c_int, + __value: ::core::ffi::c_uint, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_destroy(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_open( + __name: *const ::core::ffi::c_char, + __oflag: ::core::ffi::c_int, + ... + ) -> *mut sem_t; +} +extern "C" { + pub fn sem_close(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_unlink(__name: *const ::core::ffi::c_char) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_wait(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_timedwait(__sem: *mut sem_t, __abstime: *const timespec) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_trywait(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_post(__sem: *mut sem_t) -> ::core::ffi::c_int; +} +extern "C" { + pub fn sem_getvalue(__sem: *mut sem_t, __sval: *mut ::core::ffi::c_int) -> ::core::ffi::c_int; +} +pub type csp_bin_sem_t = sem_t; +extern "C" { + #[doc = " initialize a binary semaphore with static storage\n The semaphore is created in state \\a unlocked (value 1).\n On platforms supporting max values, the semaphore is created with a max value of 1, hence the naming \\a binary."] + pub fn csp_bin_sem_init(sem: *mut csp_bin_sem_t); +} +extern "C" { + #[doc = " Wait/lock semaphore\n @param[in] timeout timeout in mS. Use #CSP_MAX_TIMEOUT for no timeout, e.g. wait forever until locked.\n @return #CSP_SEMAPHORE_OK on success, otherwise #CSP_SEMAPHORE_ERROR"] + pub fn csp_bin_sem_wait( + sem: *mut csp_bin_sem_t, + timeout: ::core::ffi::c_uint, + ) -> ::core::ffi::c_int; +} +extern "C" { + #[doc = " Signal/unlock semaphore\n @return #CSP_SEMAPHORE_OK on success, otherwise #CSP_SEMAPHORE_ERROR"] + pub fn csp_bin_sem_post(sem: *mut csp_bin_sem_t) -> ::core::ffi::c_int; +} +pub const csp_conn_state_t_CONN_CLOSED: csp_conn_state_t = 0; +pub const csp_conn_state_t_CONN_OPEN: csp_conn_state_t = 1; +#[doc = " Connection states"] +pub type csp_conn_state_t = ::core::ffi::c_uint; +pub const csp_conn_type_t_CONN_CLIENT: csp_conn_type_t = 0; +pub const csp_conn_type_t_CONN_SERVER: csp_conn_type_t = 1; +#[doc = " Connection types"] +pub type csp_conn_type_t = ::core::ffi::c_uint; +pub const csp_rdp_state_t_RDP_CLOSED: csp_rdp_state_t = 0; +pub const csp_rdp_state_t_RDP_SYN_SENT: csp_rdp_state_t = 1; +pub const csp_rdp_state_t_RDP_SYN_RCVD: csp_rdp_state_t = 2; +pub const csp_rdp_state_t_RDP_OPEN: csp_rdp_state_t = 3; +pub const csp_rdp_state_t_RDP_CLOSE_WAIT: csp_rdp_state_t = 4; +#[doc = " RDP Connection states"] +pub type csp_rdp_state_t = ::core::ffi::c_uint; +#[doc = " RDP Connection"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct csp_rdp_t { + #[doc = "< Connection state"] + pub state: csp_rdp_state_t, + #[doc = "< Tracks 'who' have closed the RDP connection"] + pub closed_by: u8, + #[doc = "< The sequence number of the next segment that is to be sent"] + pub snd_nxt: u16, + #[doc = "< The sequence number of the oldest unacknowledged segment"] + pub snd_una: u16, + #[doc = "< The initial send sequence number"] + pub snd_iss: u16, + #[doc = "< The sequence number of the last segment received correctly and in sequence"] + pub rcv_cur: u16, + #[doc = "< The initial receive sequence number"] + pub rcv_irs: u16, + #[doc = "< The last sequence number acknowledged by the receiver"] + pub rcv_lsa: u16, + pub window_size: u32, + pub conn_timeout: u32, + pub packet_timeout: u32, + pub delayed_acks: u32, + pub ack_timeout: u32, + pub ack_delay_count: u32, + pub ack_timestamp: u32, + pub tx_wait: csp_bin_sem_t, +} +#[test] +fn bindgen_test_layout_csp_rdp_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 80usize, + concat!("Size of: ", stringify!(csp_rdp_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_rdp_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(state) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).closed_by) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(closed_by) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).snd_nxt) as usize - ptr as usize }, + 6usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(snd_nxt) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).snd_una) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(snd_una) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).snd_iss) as usize - ptr as usize }, + 10usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(snd_iss) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rcv_cur) as usize - ptr as usize }, + 12usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(rcv_cur) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rcv_irs) as usize - ptr as usize }, + 14usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(rcv_irs) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rcv_lsa) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(rcv_lsa) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).window_size) as usize - ptr as usize }, + 20usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(window_size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).conn_timeout) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(conn_timeout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).packet_timeout) as usize - ptr as usize }, + 28usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(packet_timeout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).delayed_acks) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(delayed_acks) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ack_timeout) as usize - ptr as usize }, + 36usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(ack_timeout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ack_delay_count) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(ack_delay_count) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).ack_timestamp) as usize - ptr as usize }, + 44usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(ack_timestamp) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).tx_wait) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(csp_rdp_t), + "::", + stringify!(tx_wait) + ) + ); +} +#[doc = " @brief Connection struct"] +#[repr(C)] +#[derive(Copy, Clone)] pub struct csp_conn_s { - pub _address: u8, + pub type_: atomic_int, + pub state: atomic_int, + pub idin: csp_id_t, + pub idout: csp_id_t, + pub sport_outgoing: u8, + pub rx_queue: csp_queue_handle_t, + pub rx_queue_static: csp_static_queue_t, + pub rx_queue_static_data: [::core::ffi::c_char; 128usize], + pub callback: ::core::option::Option, + pub dest_socket: *mut csp_socket_t, + pub timestamp: u32, + pub opts: u32, + pub rdp: csp_rdp_t, +} +#[test] +fn bindgen_test_layout_csp_conn_s() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 280usize, + concat!("Size of: ", stringify!(csp_conn_s)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_conn_s)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(state) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idin) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idin) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idout) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sport_outgoing) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(sport_outgoing) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static_data) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static_data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, + 176usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(callback) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).dest_socket) as usize - ptr as usize }, + 184usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(dest_socket) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).timestamp) as usize - ptr as usize }, + 192usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(timestamp) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).opts) as usize - ptr as usize }, + 196usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(opts) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rdp) as usize - ptr as usize }, + 200usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rdp) + ) + ); +} +extern "C" { + pub fn csp_conn_enqueue_packet( + conn: *mut csp_conn_t, + packet: *mut csp_packet_t, + ) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_conn_init(); +} +extern "C" { + pub fn csp_conn_allocate(type_: csp_conn_type_t) -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_find_existing(id: *mut csp_id_t) -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_find_dport(dport: ::core::ffi::c_uint) -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_new(idin: csp_id_t, idout: csp_id_t, type_: csp_conn_type_t) + -> *mut csp_conn_t; +} +extern "C" { + pub fn csp_conn_check_timeouts(); +} +extern "C" { + pub fn csp_conn_get_rxq(prio: ::core::ffi::c_int) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_conn_close(conn: *mut csp_conn_t, closed_by: u8) -> ::core::ffi::c_int; +} +extern "C" { + pub fn csp_conn_get_array(size: *mut usize) -> *const csp_conn_t; } #[repr(C)] #[derive(Debug, Copy, Clone)] diff --git a/lib/clone-csp.sh b/lib/clone-csp.sh index 48e0f1b..e0b42bb 100755 --- a/lib/clone-csp.sh +++ b/lib/clone-csp.sh @@ -1,3 +1,3 @@ #!/bin/bash git clone https://github.com/us-irs/libcsp.git -git checkout 447cc38f2106a15290358dc8c128ad553a415568 +git checkout const-correctness diff --git a/lib/gen-bindings.sh b/lib/gen-bindings.sh index da9ceee..e94116f 100755 --- a/lib/gen-bindings.sh +++ b/lib/gen-bindings.sh @@ -1,2 +1,2 @@ #!/bin/bash -bindgen --use-core wrapper.h -- "-I./libcsp/include" "-I./cfg" > bindings.rs +bindgen --use-core wrapper.h -- "-I./libcsp/include" "-I./cfg" "-I./libcsp/src" > bindings.rs diff --git a/lib/wrapper.h b/lib/wrapper.h index ebc2d10..9c33746 100644 --- a/lib/wrapper.h +++ b/lib/wrapper.h @@ -1 +1,2 @@ #include "csp/csp.h" +#include "csp_conn.h" diff --git a/libcsp-rust/Cargo.toml b/libcsp-rust/Cargo.toml index 3831407..3038ebe 100644 --- a/libcsp-rust/Cargo.toml +++ b/libcsp-rust/Cargo.toml @@ -7,3 +7,4 @@ links = "csp" [dependencies] bitflags = "2" num_enum = "0.7" +libc = "0.2" diff --git a/libcsp-rust/src/ffi.rs b/libcsp-rust/src/ffi.rs index 6700c43..aabb57b 100644 --- a/libcsp-rust/src/ffi.rs +++ b/libcsp-rust/src/ffi.rs @@ -26,11 +26,13 @@ pub struct csp_id_t { pub sport: u8, } +/* #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct csp_conn_s { pub address: u8, } +*/ #[doc = " CSP Packet.\n\n This structure is constructed to fit with all interface and protocols to prevent the\n need to copy data (zero copy).\n\n .. note:: In most cases a CSP packet cannot be reused in case of send failure, because the\n \t\t\t lower layers may add additional data causing increased length (e.g. CRC32), convert\n \t\t\t the CSP id to different endian (e.g. I2C), etc.\n"] #[repr(C)] @@ -156,6 +158,70 @@ pub type csp_socket_t = csp_socket_s; #[doc = " Forward declaration of connection structure"] pub type csp_conn_t = csp_conn_s; +pub type atomic_int = u32; + +#[doc = " Connection states"] +pub type csp_conn_state_t = ::core::ffi::c_uint; + +#[doc = " Connection types"] +pub type csp_conn_type_t = ::core::ffi::c_uint; + +#[doc = " RDP Connection states"] +pub type csp_rdp_state_t = ::core::ffi::c_uint; + +#[cfg(unix)] +pub type csp_bin_sem_t = libc::sem_t; + +#[doc = " RDP Connection"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct csp_rdp_t { + #[doc = "< Connection state"] + pub state: csp_rdp_state_t, + #[doc = "< Tracks 'who' have closed the RDP connection"] + pub closed_by: u8, + #[doc = "< The sequence number of the next segment that is to be sent"] + pub snd_nxt: u16, + #[doc = "< The sequence number of the oldest unacknowledged segment"] + pub snd_una: u16, + #[doc = "< The initial send sequence number"] + pub snd_iss: u16, + #[doc = "< The sequence number of the last segment received correctly and in sequence"] + pub rcv_cur: u16, + #[doc = "< The initial receive sequence number"] + pub rcv_irs: u16, + #[doc = "< The last sequence number acknowledged by the receiver"] + pub rcv_lsa: u16, + pub window_size: u32, + pub conn_timeout: u32, + pub packet_timeout: u32, + pub delayed_acks: u32, + pub ack_timeout: u32, + pub ack_delay_count: u32, + pub ack_timestamp: u32, + pub tx_wait: csp_bin_sem_t, +} + +#[doc = " @brief Connection struct"] +#[repr(C)] +#[derive(Copy, Clone)] +pub struct csp_conn_s { + pub type_: atomic_int, + pub state: atomic_int, + pub idin: csp_id_t, + pub idout: csp_id_t, + pub sport_outgoing: u8, + pub rx_queue: csp_queue_handle_t, + pub rx_queue_static: csp_static_queue_t, + pub rx_queue_static_data: + [core::ffi::c_char; CSP_CONN_RXQUEUE_LEN * core::mem::size_of::<*const csp_packet_s>()], + pub callback: ::core::option::Option, + pub dest_socket: *mut csp_socket_t, + pub timestamp: u32, + pub opts: u32, + pub rdp: csp_rdp_t, +} + extern "C" { #[doc = " Error counters"] pub static mut csp_dbg_buffer_out: u8; @@ -216,7 +282,7 @@ extern "C" { ) -> *mut csp_conn_t; #[doc = " Return destination port of connection.\n\n @param[in] conn connection\n @return destination port of an incoming connection"] - pub fn csp_conn_dport(conn: *mut csp_conn_t) -> ::core::ffi::c_int; + pub fn csp_conn_dport(conn: *const csp_conn_t) -> ::core::ffi::c_int; #[doc = " Get free buffer from task context.\n\n @param[in] unused OBSOLETE ignored field, csp packets have a fixed size now\n @return Buffer pointer to #csp_packet_t or NULL if no buffers available"] pub fn csp_buffer_get(unused: usize) -> *mut csp_packet_t; @@ -228,6 +294,152 @@ extern "C" { pub fn csp_conn_print_table(); pub fn csp_iflist_print(); + +} +#[test] +fn bindgen_test_layout_csp_conn_s() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 280usize, + concat!("Size of: ", stringify!(csp_conn_s)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(csp_conn_s)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).type_) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(type_) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).state) as usize - ptr as usize }, + 4usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(state) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idin) as usize - ptr as usize }, + 8usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idin) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).idout) as usize - ptr as usize }, + 16usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(idout) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).sport_outgoing) as usize - ptr as usize }, + 24usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(sport_outgoing) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue) as usize - ptr as usize }, + 32usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static) as usize - ptr as usize }, + 40usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rx_queue_static_data) as usize - ptr as usize }, + 48usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rx_queue_static_data) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).callback) as usize - ptr as usize }, + 176usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(callback) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).dest_socket) as usize - ptr as usize }, + 184usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(dest_socket) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).timestamp) as usize - ptr as usize }, + 192usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(timestamp) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).opts) as usize - ptr as usize }, + 196usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(opts) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).rdp) as usize - ptr as usize }, + 200usize, + concat!( + "Offset of field: ", + stringify!(csp_conn_s), + "::", + stringify!(rdp) + ) + ); } #[cfg(test)] @@ -661,4 +873,39 @@ mod tests { ) ); } + #[test] + fn bindgen_test_layout_sem_t() { + const UNINIT: ::core::mem::MaybeUninit = ::core::mem::MaybeUninit::uninit(); + let ptr = UNINIT.as_ptr(); + assert_eq!( + ::core::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(sem_t)) + ); + assert_eq!( + ::core::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(sem_t)) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__size) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sem_t), + "::", + stringify!(__size) + ) + ); + assert_eq!( + unsafe { ::core::ptr::addr_of!((*ptr).__align) as usize - ptr as usize }, + 0usize, + concat!( + "Offset of field: ", + stringify!(sem_t), + "::", + stringify!(__align) + ) + ); + } } diff --git a/libcsp-rust/src/lib.rs b/libcsp-rust/src/lib.rs index b18e49a..6afdffd 100644 --- a/libcsp-rust/src/lib.rs +++ b/libcsp-rust/src/lib.rs @@ -92,7 +92,32 @@ bitflags! { } } -#[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] +#[repr(u8)] +pub enum ConnState { + Closed = 0, + Open = 1, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] +#[repr(u8)] +pub enum ConnType { + Client = 0, + Server = 1, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, TryFromPrimitive, IntoPrimitive)] +#[repr(u32)] +pub enum RdpState { + Closed = 0, + SynSent = 1, + SynRcvd = 2, + Open = 3, + CloseWait = 4, +} + +#[derive(Debug, PartialEq, Eq, Copy, Clone, TryFromPrimitive, IntoPrimitive)] +#[repr(u8)] pub enum MsgPriority { Critical = 0, High = 1, @@ -102,19 +127,53 @@ pub enum MsgPriority { pub struct CspPacket(pub csp_packet_s); -pub struct CspPacketRef<'a>(&'a mut csp_packet_s); +pub struct CspPacketRef(*mut csp_packet_s); -impl<'a> CspPacketRef<'a> { +pub struct CspPacketMut(*mut csp_packet_s); + +impl From for CspPacketRef { + fn from(value: CspPacketMut) -> Self { + Self(value.0) + } +} + +impl CspPacketRef { pub fn packet_data(&self) -> &[u8] { - unsafe { &self.0.packet_data_union.data[..self.packet_length()] } + unsafe { &(*self.0).packet_data_union.data[..self.packet_length()] } } pub fn whole_data(&self) -> &[u8; ffi::CSP_BUFFER_SIZE] { - unsafe { &self.0.packet_data_union.data } + unsafe { &(*self.0).packet_data_union.data } + } + + pub fn packet_length(&self) -> usize { + unsafe { (*self.0).length.into() } + } + + pub fn inner(&self) -> *const csp_packet_s { + self.0 + } +} + +impl CspPacketMut { + pub fn packet_data(&self) -> &[u8] { + unsafe { &(*self.0).packet_data_union.data[..self.packet_length()] } + } + + pub fn whole_data(&self) -> &[u8; ffi::CSP_BUFFER_SIZE] { + unsafe { &(*self.0).packet_data_union.data } + } + + pub fn packet_length(&self) -> usize { + unsafe { (*self.0).length.into() } + } + + pub fn inner(&self) -> *const csp_packet_s { + self.0 } pub fn whole_data_mut(&mut self) -> &mut [u8; ffi::CSP_BUFFER_SIZE] { - unsafe { &mut self.0.packet_data_union.data } + unsafe { &mut (*self.0).packet_data_union.data } } pub fn set_data(&mut self, data: &[u8]) -> bool { @@ -122,19 +181,13 @@ impl<'a> CspPacketRef<'a> { return false; } self.whole_data_mut()[0..data.len()].copy_from_slice(data); - self.0.length = data.len() as u16; + unsafe { + (*self.0).length = data.len() as u16; + } true } - pub fn packet_length(&self) -> usize { - self.0.length.into() - } - - pub fn inner(&self) -> *const csp_packet_s { - self.0 - } - - pub fn inner_mut(&self) -> *const csp_packet_s { + pub fn inner_mut(&self) -> *mut csp_packet_s { self.0 } } @@ -215,19 +268,9 @@ pub fn csp_route_work() -> Result<(), CspError> { } #[derive(Debug, Copy, Clone)] -pub struct CspConn(csp_conn_s); +pub struct CspConnRef(*mut csp_conn_s); -impl CspConn { - fn new(address: u8) -> Self { - Self(csp_conn_s { address }) - } - - pub fn addr(&self) -> u8 { - self.0.address - } -} - -pub struct CspConnGuard(pub CspConn); +pub struct CspConnGuard(pub CspConnRef); impl Drop for CspConnGuard { fn drop(&mut self) { @@ -235,14 +278,14 @@ impl Drop for CspConnGuard { } } -impl AsRef for CspConnGuard { - fn as_ref(&self) -> &CspConn { +impl AsRef for CspConnGuard { + fn as_ref(&self) -> &CspConnRef { &self.0 } } -impl AsMut for CspConnGuard { - fn as_mut(&mut self) -> &mut CspConn { +impl AsMut for CspConnGuard { + fn as_mut(&mut self) -> &mut CspConnRef { &mut self.0 } } @@ -252,17 +295,17 @@ pub fn csp_accept_guarded(socket: &mut CspSocket, timeout: Duration) -> Option Option { +pub fn csp_accept(socket: &mut CspSocket, timeout: Duration) -> Option { let timeout_millis = timeout.as_millis(); if timeout_millis > u32::MAX as u128 { return None; } - Some(CspConn::new(unsafe { + Some(CspConnRef(unsafe { let addr = ffi::csp_accept(socket.inner_as_mut_ptr(), timeout_millis as u32); if addr.is_null() { return None; } - (*addr).address + addr })) } @@ -271,12 +314,12 @@ pub fn csp_accept(socket: &mut CspSocket, timeout: Duration) -> Option /// # Safety /// /// - You MUST ensure that a connection is active when calling this function. -pub unsafe fn csp_read<'a>(mut conn: CspConn, timeout: Duration) -> Option> { +pub unsafe fn csp_read(conn: &mut CspConnRef, timeout: Duration) -> Option { let timeout_millis = timeout.as_millis(); if timeout_millis > u32::MAX as u128 { return None; } - let opt_packet = unsafe { ffi::csp_read(&mut conn.0, timeout_millis as u32) }; + let opt_packet = unsafe { ffi::csp_read(conn.0, timeout_millis as u32) }; if opt_packet.is_null() { return None; } @@ -285,9 +328,9 @@ pub unsafe fn csp_read<'a>(mut conn: CspConn, timeout: Duration) -> Option i32 { +pub fn csp_conn_dport(conn: &CspConnRef) -> i32 { // SAFETY: FFI call. - unsafe { ffi::csp_conn_dport(&mut conn.0) } + unsafe { ffi::csp_conn_dport(conn.0) } } pub fn csp_service_handler(packet: &mut CspPacketRef) { @@ -296,9 +339,9 @@ pub fn csp_service_handler(packet: &mut CspPacketRef) { } /// Rust wrapper for [ffi::csp_close]. -pub fn csp_close(mut conn: CspConn) -> i32 { +pub fn csp_close(conn: CspConnRef) -> i32 { // SAFETY: FFI call. - unsafe { ffi::csp_close(&mut conn.0) } + unsafe { ffi::csp_close(conn.0) } } /// Rust wrapper for [ffi::csp_ping], returns the result code directly. @@ -342,7 +385,7 @@ pub fn csp_connect( dst_port: u8, timeout: Duration, opts: ConnectOpts, -) -> Option { +) -> Option { // SAFETY: FFI call. let conn = unsafe { ffi::csp_connect( @@ -357,7 +400,7 @@ pub fn csp_connect( return None; } // SAFETY: We checked that the pointer is valid. - Some(CspConn::new(unsafe { *conn }.address)) + Some(CspConnRef(conn)) } /// Rust wrapper for [ffi::csp_connect] which returns a guard structure. The connection will be @@ -375,7 +418,7 @@ pub fn csp_connect_guarded( } /// Rust wrapper for [ffi::csp_buffer_get]. -pub fn csp_buffer_get() -> Option> { +pub fn csp_buffer_get() -> Option { let packet_ref = unsafe { // The size argument is unused ffi::csp_buffer_get(0) @@ -384,13 +427,13 @@ pub fn csp_buffer_get() -> Option> { return None; } // SAFETY: We checked that the pointer is valid. - Some(CspPacketRef(unsafe { &mut *packet_ref })) + Some(CspPacketMut(unsafe { &mut *packet_ref })) } /// Rust wrapper for [ffi::csp_send]. -pub fn csp_send(mut conn: CspConn, packet: CspPacketRef) { +pub fn csp_send(conn: &mut CspConnRef, packet: impl Into) { // SAFETY: FFI call. - unsafe { ffi::csp_send(&mut conn.0, packet.0) } + unsafe { ffi::csp_send(conn.0, packet.into().0) } } /// Rust wrapper for [ffi::csp_conn_print_table].