diff --git a/iceoryx2-bb/posix/src/signal.rs b/iceoryx2-bb/posix/src/signal.rs index ecb18a902..c5116f819 100644 --- a/iceoryx2-bb/posix/src/signal.rs +++ b/iceoryx2-bb/posix/src/signal.rs @@ -499,13 +499,13 @@ impl SignalHandler { fn register_signal_from_state(&mut self, details: SignalDetail) -> posix::sigaction_t { let adjusted_state = posix::sigaction_t { - sa_handler: details.state.sa_handler, - sa_flags: if self.do_repeat_eintr_call { + iox2_sa_handler: details.state.iox2_sa_handler, + iox2_sa_flags: if self.do_repeat_eintr_call { posix::SA_RESTART } else { 0 }, - sa_mask: details.state.sa_mask, + iox2_sa_mask: details.state.iox2_sa_mask, }; let mut previous_action = posix::sigaction_t::new(); @@ -524,7 +524,7 @@ impl SignalHandler { callback: posix::sighandler_t, ) -> posix::sigaction_t { let mut action = posix::sigaction_t::new(); - action.sa_handler = callback; + action.iox2_sa_handler = callback; self.register_signal_from_state(SignalDetail::new(signal, action)) } diff --git a/iceoryx2-pal/posix/build.rs b/iceoryx2-pal/posix/build.rs index 89836873f..51ce60fff 100644 --- a/iceoryx2-pal/posix/build.rs +++ b/iceoryx2-pal/posix/build.rs @@ -20,13 +20,9 @@ fn main() { #[cfg(any(target_os = "linux", target_os = "freebsd"))] println!("cargo:rustc-link-lib=pthread"); - if std::env::var("DOCS_RS").is_ok() { - println!("cargo:rerun-if-changed=src/c/posix_docs_rs.h"); - } else { - #[cfg(all(target_os = "linux", feature = "acl"))] - println!("cargo:rustc-link-lib=acl"); - println!("cargo:rerun-if-changed=src/c/posix.h"); - } + #[cfg(all(target_os = "linux", feature = "acl"))] + println!("cargo:rustc-link-lib=acl"); + println!("cargo:rerun-if-changed=src/c/posix.h"); let bindings = if std::env::var("DOCS_RS").is_ok() { bindgen::Builder::default() @@ -61,10 +57,17 @@ fn main() { .write_to_file(out_path.join("posix_generated.rs")) .expect("Couldn't write bindings!"); + println!("cargo:rerun-if-changed=src/c/sigaction.c"); + cc::Build::new() + .file("src/c/sigaction.c") + .compile("libsigaction.a"); + + println!("cargo:rerun-if-changed=src/c/scandir.c"); cc::Build::new() .file("src/c/scandir.c") .compile("libscandir.a"); + println!("cargo:rerun-if-changed=src/c/socket_macros.c"); cc::Build::new() .file("src/c/socket_macros.c") .compile("libsocket_macros.a"); diff --git a/iceoryx2-pal/posix/src/c/posix.h b/iceoryx2-pal/posix/src/c/posix.h index de6286346..49c6919c4 100644 --- a/iceoryx2-pal/posix/src/c/posix.h +++ b/iceoryx2-pal/posix/src/c/posix.h @@ -1,3 +1,15 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + #ifdef __FreeBSD__ #include #if defined(IOX2_ACL_SUPPORT) && !defined(IOX2_DOCS_RS_SUPPORT) @@ -89,3 +101,9 @@ int acl_set_fd(int, acl_t) { return 0; } char *acl_to_text(acl_t, ssize_t *) { return NULL; } acl_t acl_from_text(const char *) { return 0; } #endif + +struct iox2_sigaction { + size_t iox2_sa_handler; + sigset_t iox2_sa_mask; + int iox2_sa_flags; +}; diff --git a/iceoryx2-pal/posix/src/c/posix_docs_rs.h b/iceoryx2-pal/posix/src/c/posix_docs_rs.h deleted file mode 100644 index ae332a66c..000000000 --- a/iceoryx2-pal/posix/src/c/posix_docs_rs.h +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef IOX2_DOCS_RS_SUPPORT -/////////////////////////////// -// stub libacl.h implementation -/////////////////////////////// - -typedef int acl_tag_t; -typedef unsigned int acl_perm_t; -typedef int acl_type_t; -typedef int acl_t; -typedef int acl_entry_t; -typedef int acl_permset_t; - -#define ACL_EXECUTE 0x01 -#define ACL_WRITE 0x02 -#define ACL_READ 0x04 - -#define ACL_UNDEFINED_TAG 0 -#define ACL_USER_OBJ 1 -#define ACL_USER 2 -#define ACL_GROUP_OBJ 3 -#define ACL_GROUP 4 -#define ACL_MASK 5 -#define ACL_OTHER 6 - -#define ACL_FIRST_ENTRY 7 -#define ACL_NEXT_ENTRY 8 - -int acl_get_perm(acl_permset_t, acl_perm_t) { return 0; } -acl_t acl_init(int) { return 0; } -int acl_free(void *) { return 0; } -int acl_valid(acl_t) { return 0; } -int acl_create_entry(acl_t *, acl_entry_t *) { return 0; } -int acl_get_entry(acl_t, int, acl_entry_t *) { return 0; } -int acl_add_perm(acl_permset_t, acl_perm_t) { return 0; } -int acl_clear_perms(acl_permset_t) { return 0; } -int acl_get_permset(acl_entry_t, acl_permset_t *) { return 0; } -int acl_set_permset(acl_entry_t, acl_permset_t) { return 0; } -void *acl_get_qualifier(acl_entry_t) { return NULL; } -int acl_set_qualifier(acl_entry_t, const void *) { return 0; } -int acl_get_tag_type(acl_entry_t, acl_tag_t *) { return 0; } -int acl_set_tag_type(acl_entry_t, acl_tag_t) { return 0; } -acl_t acl_get_fd(int) { return 0; } -int acl_set_fd(int, acl_t) { return 0; } -char *acl_to_text(acl_t, ssize_t *) { return NULL; } -acl_t acl_from_text(const char *) { return 0; } -#endif diff --git a/iceoryx2-pal/posix/src/c/scandir.c b/iceoryx2-pal/posix/src/c/scandir.c index 63d3bd647..655ca4afb 100644 --- a/iceoryx2-pal/posix/src/c/scandir.c +++ b/iceoryx2-pal/posix/src/c/scandir.c @@ -1,3 +1,15 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + #ifndef _WIN64 #include diff --git a/iceoryx2-pal/posix/src/c/sigaction.c b/iceoryx2-pal/posix/src/c/sigaction.c new file mode 100644 index 000000000..7a8e35c58 --- /dev/null +++ b/iceoryx2-pal/posix/src/c/sigaction.c @@ -0,0 +1,47 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +#ifndef _WIN64 +#include "posix.h" + +int iox2_sigaction_func(int sig, const struct iox2_sigaction *restrict act, + struct iox2_sigaction *restrict oact) { + struct sigaction tr_act; + memset(&tr_act, 0, sizeof(struct sigaction)); + struct sigaction *tr_act_ptr = NULL; + + struct sigaction tr_oact; + memset(&tr_act, 0, sizeof(struct sigaction)); + struct sigaction *tr_oact_ptr = NULL; + + if (act != NULL) { + tr_act.sa_flags = act->iox2_sa_flags; + tr_act.sa_mask = act->iox2_sa_mask; + tr_act.sa_handler = (void (*)(int))act->iox2_sa_handler; + tr_act_ptr = &tr_act; + } + + if (oact != NULL) { + tr_oact_ptr = &tr_oact; + } + + int ret_val = sigaction(sig, tr_act_ptr, tr_oact_ptr); + + if (ret_val == 0 && oact != NULL) { + oact->iox2_sa_flags = tr_act.sa_flags; + oact->iox2_sa_mask = tr_act.sa_mask; + oact->iox2_sa_handler = (size_t)tr_act.sa_handler; + } + + return ret_val; +} +#endif diff --git a/iceoryx2-pal/posix/src/c/socket_macros.c b/iceoryx2-pal/posix/src/c/socket_macros.c index ddf09f90b..025f44171 100644 --- a/iceoryx2-pal/posix/src/c/socket_macros.c +++ b/iceoryx2-pal/posix/src/c/socket_macros.c @@ -1,11 +1,20 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + #ifdef _WIN64 +#include #include #include -#include #include - - - #else #include #include diff --git a/iceoryx2-pal/posix/src/freebsd/dirent.rs b/iceoryx2-pal/posix/src/freebsd/dirent.rs index a6a57dbae..ee8ea5ff5 100644 --- a/iceoryx2-pal/posix/src/freebsd/dirent.rs +++ b/iceoryx2-pal/posix/src/freebsd/dirent.rs @@ -38,7 +38,6 @@ pub unsafe fn dirfd(dirp: *mut DIR) -> int { mod internal { use super::*; - #[cfg_attr(target_os = "freebsd", link(name = "c"))] extern "C" { pub(super) fn scandir_ext(path: *const c_char, namelist: *mut *mut *mut dirent) -> int; } diff --git a/iceoryx2-pal/posix/src/freebsd/signal.rs b/iceoryx2-pal/posix/src/freebsd/signal.rs index 1a20462d1..0afab1e6c 100644 --- a/iceoryx2-pal/posix/src/freebsd/signal.rs +++ b/iceoryx2-pal/posix/src/freebsd/signal.rs @@ -15,13 +15,21 @@ use crate::posix::types::*; pub unsafe fn sigaction(sig: int, act: *const sigaction_t, oact: *mut sigaction_t) -> int { - crate::internal::sigaction( - sig, - act as *const crate::internal::sigaction, - oact as *mut crate::internal::sigaction, - ) + internal::iox2_sigaction_func(sig, act, oact) } pub unsafe fn kill(pid: pid_t, sig: int) -> int { crate::internal::kill(pid, sig) } + +mod internal { + use super::*; + + extern "C" { + pub(super) fn iox2_sigaction_func( + sig: int, + act: *const sigaction_t, + oact: *mut sigaction_t, + ) -> int; + } +} diff --git a/iceoryx2-pal/posix/src/linux/dirent.rs b/iceoryx2-pal/posix/src/linux/dirent.rs index eb3f6628f..2e44410a5 100644 --- a/iceoryx2-pal/posix/src/linux/dirent.rs +++ b/iceoryx2-pal/posix/src/linux/dirent.rs @@ -42,7 +42,6 @@ pub unsafe fn readdir(dirp: *mut DIR) -> *const dirent { mod internal { use super::*; - #[cfg_attr(target_os = "linux", link(name = "c"))] extern "C" { pub(super) fn scandir_ext(path: *const c_char, namelist: *mut *mut *mut dirent) -> int; } diff --git a/iceoryx2-pal/posix/src/linux/signal.rs b/iceoryx2-pal/posix/src/linux/signal.rs index be9acb59f..0afab1e6c 100644 --- a/iceoryx2-pal/posix/src/linux/signal.rs +++ b/iceoryx2-pal/posix/src/linux/signal.rs @@ -12,70 +12,24 @@ #![allow(non_camel_case_types)] #![allow(clippy::missing_safety_doc)] -use crate::posix::{types::*, Struct}; +use crate::posix::types::*; -impl Struct for crate::internal::sigaction {} - -impl From<&sigaction_t> for crate::internal::sigaction { - fn from(value: &sigaction_t) -> Self { - let mut this = crate::internal::sigaction::new(); - this.sa_mask = value.sa_mask; - this.sa_flags = value.sa_flags; - this.__sigaction_handler.sa_handler = - Some(unsafe { core::mem::transmute(value.sa_handler) }); - - this - } +pub unsafe fn sigaction(sig: int, act: *const sigaction_t, oact: *mut sigaction_t) -> int { + internal::iox2_sigaction_func(sig, act, oact) } -impl From<&crate::internal::sigaction> for sigaction_t { - fn from(value: &crate::internal::sigaction) -> Self { - let mut this = sigaction_t::new(); - this.sa_mask = value.sa_mask; - this.sa_flags = value.sa_flags; - this.sa_handler = match unsafe { value.__sigaction_handler.sa_handler } { - Some(v) => unsafe { core::mem::transmute(v) }, - None => 0, - }; - - this - } +pub unsafe fn kill(pid: pid_t, sig: int) -> int { + crate::internal::kill(pid, sig) } -pub unsafe fn sigaction(sig: int, act: *const sigaction_t, oact: *mut sigaction_t) -> int { - let c_act: crate::internal::sigaction = if act.is_null() { - crate::internal::sigaction::new() - } else { - (&*act).into() - }; - - let mut c_oact: crate::internal::sigaction = if oact.is_null() { - crate::internal::sigaction::new() - } else { - (&*oact).into() - }; +mod internal { + use super::*; - let ret_val = crate::internal::sigaction( - sig, - if act.is_null() { - core::ptr::null() - } else { - &c_act - }, - if oact.is_null() { - core::ptr::null_mut() - } else { - &mut c_oact - }, - ); - - if ret_val == 0 && !oact.is_null() { - *oact = (&c_oact).into(); + extern "C" { + pub(super) fn iox2_sigaction_func( + sig: int, + act: *const sigaction_t, + oact: *mut sigaction_t, + ) -> int; } - - ret_val -} - -pub unsafe fn kill(pid: pid_t, sig: int) -> int { - crate::internal::kill(pid, sig) } diff --git a/iceoryx2-pal/posix/src/linux/types.rs b/iceoryx2-pal/posix/src/linux/types.rs index 50dc520dc..1246490ce 100644 --- a/iceoryx2-pal/posix/src/linux/types.rs +++ b/iceoryx2-pal/posix/src/linux/types.rs @@ -108,21 +108,8 @@ impl Struct for rlimit {} pub type sched_param = crate::internal::sched_param; impl Struct for sched_param {} -#[repr(C)] -pub struct sigaction_t { - pub sa_handler: sighandler_t, - pub sa_mask: sigset_t, - pub sa_flags: int, -} -impl Struct for sigaction_t { - fn new() -> Self { - Self { - sa_handler: 0, - sa_mask: sigset_t::new(), - sa_flags: 0, - } - } -} +pub type sigaction_t = crate::internal::iox2_sigaction; +impl Struct for sigaction_t {} #[repr(C)] pub struct stat_t { diff --git a/iceoryx2-pal/posix/src/macos/signal.rs b/iceoryx2-pal/posix/src/macos/signal.rs index 1a20462d1..54e2b5f83 100644 --- a/iceoryx2-pal/posix/src/macos/signal.rs +++ b/iceoryx2-pal/posix/src/macos/signal.rs @@ -25,3 +25,15 @@ pub unsafe fn sigaction(sig: int, act: *const sigaction_t, oact: *mut sigaction_ pub unsafe fn kill(pid: pid_t, sig: int) -> int { crate::internal::kill(pid, sig) } + +mod internal { + use super::*; + + extern "C" { + pub(super) fn iox2_sigaction_func( + sig: int, + act: *const sigaction_t, + oact: *mut sigaction_t, + ) -> int; + } +}