diff --git a/include/bits/sys/socket.h b/include/bits/sys/socket.h deleted file mode 100644 index 99f0d9fe38..0000000000 --- a/include/bits/sys/socket.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _BITS_SYS_SOCKET_H -#define _BITS_SYS_SOCKET_H - -struct sockaddr_storage { - sa_family_t ss_family; - char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; - unsigned long __ss_align; -}; - -// These definitions were taken from musl, license MIT { -#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) -#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) -#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) - -#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) -#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ - __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ - ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) - -#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) -#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) -// } from musl, license MIT - -#endif // _BITS_SYS_SOCKET_H diff --git a/src/header/sys_socket/cbindgen.toml b/src/header/sys_socket/cbindgen.toml index 53adbc0fe3..03207837a5 100644 --- a/src/header/sys_socket/cbindgen.toml +++ b/src/header/sys_socket/cbindgen.toml @@ -1,10 +1,32 @@ sys_includes = ["stddef.h", "stdint.h", "sys/types.h"] -include_guard = "_SYS_SOCKET_H" +include_guard = "_RELIBC_SYS_SOCKET_H" after_includes = """ -#include // for iovec +#include // for iovec from sys/uio.h #include // for socklen_t """ -trailer = "#include " +trailer = """ +struct sockaddr_storage { + sa_family_t ss_family; + char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; + unsigned long __ss_align; +}; + +// These definitions were taken from musl, license MIT { +#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) +#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) +#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) + +#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) +#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ + __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ + ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) +#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) + +#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) +#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) +#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) +// } from musl, license MIT +""" language = "C" style = "Tag" no_includes = true diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 89c6b29986..6863c867e4 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -76,8 +76,10 @@ pub struct sockaddr { } // Max size of [`sockaddr_storage`] +/// cbindgen:ignore const _SS_MAXSIZE: usize = 128; // Align to pointer width +/// cbindgen:ignore const _SS_PADDING: usize = _SS_MAXSIZE - mem::size_of::() - mem::size_of::(); /// See . @@ -91,22 +93,26 @@ const _SS_PADDING: usize = _SS_MAXSIZE - mem::size_of::() - mem::si /// from protocol structs in C #[repr(C)] //#[derive(CheckVsLibcCrate)] FIXME: can't ignore private fields yet +/// cbindgen:ignore pub struct sockaddr_storage { pub ss_family: sa_family_t, __ss_pad2: [u8; _SS_PADDING], __ss_align: usize, } -// These must match C macros in include/bits/sys/socket.h { +// These must match C macros in sys_socket/cbindgen.toml { +/// cbindgen:ignore pub unsafe extern "C" fn __CMSG_LEN(cmsg: *const cmsghdr) -> ssize_t { ((unsafe { (*cmsg).cmsg_len as size_t } + mem::size_of::() - 1) & !(mem::size_of::() - 1)) as ssize_t } +/// cbindgen:ignore pub unsafe extern "C" fn __CMSG_NEXT(cmsg: *const cmsghdr) -> *mut c_uchar { unsafe { (cmsg as *mut c_uchar).offset(__CMSG_LEN(cmsg)) } } +/// cbindgen:ignore pub unsafe extern "C" fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar { unsafe { ((*mhdr).msg_control.cast::()).add((*mhdr).msg_controllen) } } @@ -165,7 +171,7 @@ pub unsafe extern "C" fn CMSG_SPACE(len: c_uint) -> c_uint { pub unsafe extern "C" fn CMSG_LEN(length: c_uint) -> c_uint { (unsafe { CMSG_ALIGN(mem::size_of::()) } + length as usize) as c_uint } -// } These must match C macros in include/bits/sys/socket.h +// } These must match C macros in sys_socket/cbindgen.toml /// See . #[unsafe(no_mangle)]