Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sigaction struct on OS X #49

Closed
w1ldptr opened this issue Jan 17, 2015 · 6 comments
Closed

sigaction struct on OS X #49

w1ldptr opened this issue Jan 17, 2015 · 6 comments

Comments

@w1ldptr
Copy link
Contributor

w1ldptr commented Jan 17, 2015

I've been looking on signal-handling code in nix-rust to implement signal support in mio and it seems that sigaction struct definition for OS X is a bit off.

Relevant definition from 10.10:

/* union for signal handlers */
union __sigaction_u {
        void    (*__sa_handler)(int);
        void    (*__sa_sigaction)(int, struct __siginfo *,
                       void *);
};

/* Signal vector template for Kernel user boundary */
struct  __sigaction {
        union __sigaction_u __sigaction_u;  /* signal handler */
        void    (*sa_tramp)(void *, int, int, siginfo_t *, void *);
        sigset_t sa_mask;               /* signal mask to apply */
        int     sa_flags;               /* see signal options below */
};

/*                                                                                                                                                                              
 * Signal vector "template" used in sigaction call.                                                                                                                             
 */
struct  sigaction {
        union __sigaction_u __sigaction_u;  /* signal handler */
    sigset_t sa_mask;               /* signal mask to apply */
        int     sa_flags;               /* see signal options below */
};

struct definition from nix:

    #[cfg(any(target_os = "macos", target_os = "ios"))]
    #[repr(C)]
    #[allow(missing_copy_implementations)]
    pub struct sigaction {
        pub sa_handler: extern fn(libc::c_int),
        sa_tramp: *mut libc::c_void,
        pub sa_mask: sigset_t,
        pub sa_flags: SockFlag,
    }

So it seems that nix defines sigaction according to private kernel-user boundary OS X struct instead of public struct which actually used as param type to sigaction function.
Also I need the sa_sigaction(instead of sa_handler which is currently used in nix struct) handler to obtain siginfo_t structure and I'm struggling to define c-union in Rust. Any suggestions?

@vhbit
Copy link
Contributor

vhbit commented Jan 23, 2015

@vbuslov there is no way to define unions in Rust, in case of data with the same size (like pointer to a function) workaround is to use mem::transmute.

@fiveop
Copy link
Contributor

fiveop commented Jan 18, 2016

I have the same problem and was thinking of using one or two enums to encapsulate the differences between sa_handler, sa_sigaction as well as the difference between an actual function pointer and SIG_IGN and SIG_DFL. I'll work on a proposal.

@carllerche
Copy link
Contributor

Great! Looking forward to it.

@fiveop
Copy link
Contributor

fiveop commented Jan 20, 2016

#241 would solve the second part of the question. The first would be solved by using libc's raw structs instead of our own. See https://github.com/rust-lang-nursery/libc/blob/master/src/unix/bsd/apple/mod.rs .

@kamalmarhubi
Copy link
Member

Filed #264 to track the first part. I'll start on the signal module which should let us close this.

@fiveop
Copy link
Contributor

fiveop commented Mar 1, 2016

8f1d193 fixes the first part, which should resolve this issue.

@fiveop fiveop closed this as completed Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants