/*BEGIN_LEGAL 
Intel Open Source License 

Copyright (c) 2002-2014 Intel Corporation. All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.  Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.  Neither the name of
the Intel Corporation nor the names of its contributors may be used to
endorse or promote products derived from this software without
specific prior written permission.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
END_LEGAL */
// <ORIGINAL-AUTHOR>: Greg Lueck
// <COMPONENT>: barecrt
// <FILE-TYPE>: component public header

#ifndef BARECRT_MAC_IA32_SIGNAL_TYPES_HPP
#define BARECRT_MAC_IA32_SIGNAL_TYPES_HPP

#include <stddef.h>
#include "fund.hpp"
#include "barecrt/sigset32.hpp"


namespace BARECRT {


/*!
 * Values for the _flags field in SIGACTION.
 */
enum
{
    SIGACTION_ONSTACK   = 0x0001,
    SIGACTION_RESTART   = 0x0002,
    SIGACTION_RESETHAND = 0x0004,
    SIGACTION_NOCLDSTOP = 0x0008,
    SIGACTION_NODEFER   = 0x0010,
    SIGACTION_NOCLDWAIT = 0x0020,
    SIGACTION_SIGINFO   = 0x0040,
    SIGACTION_USERTRAMP = 0x0100,
    SIGACTION_64REGSET  = 0x0200
};


/*!
 * Represents the additional signal information passed to a signal handler (siginfo_t).
 */
struct /*<POD>*/ SIGXINFO
{
    FUND::INT32 _signo;
    FUND::INT32 _errno;
    FUND::INT32 _code;
    FUND::UINT32 _pid;
    FUND::UINT32 _uid;
    FUND::INT32 _status;
    FUND::PTRINT _addr;
    FUND::PTRINT _value;
    FUND::INT64 _band;
    FUND::UINT64 _pad[7];

    // The members after _code are laid out differently on other targets.  These accessors
    // maintain source compatibility across all targets.

    PID GetKillPid() const  {return _pid;}                  ///< @return The PID of the process that sent the signal.
    void SetKillPid(PID pid) {_pid = pid;}                  ///< @param Set the PID field.
    PID GetKillUid() const  {return _uid;}                  ///< @return The UID of the process that sent the signal.
    void SetKillUid(UID uid) {_uid = uid;}                  ///< @param Set the UID field.
    FUND::PTRINT GetFaultAddr() const {return _addr;}       ///< @return The address of the fault (either PC or EA).
    void SetFaultAddr(FUND::PTRINT addr) {_addr = addr;}    ///< @param Set the fault address field.
};


/*!
 * Describes how to handle a signal.
 * NOTE: This is the layout expected by the kernel, which is not necessarily the same as the
 * libc "struct sigaction".
 */
struct /*<POD>*/ SIGACTION
{
    union
    {
        void (*_sigaction)(int, SIGXINFO *, void *);
        void (*_handler)(int);
    };
    void (*_tramp)(void *, unsigned int, int, SIGXINFO *, void *);
    SIGSET _mask;
    FUND::UINT32 _flags;
};


/*!
 * Describes an stack to use when handling signals (stack_t).
 */
struct /*<POD>*/ SIGSTACK
{
    void *_sp;
    FUND::UINT64 _size;
    FUND::UINT32 _flags;
};

} // namespace
#endif // file guard
