summaryrefslogtreecommitdiff
path: root/utility/rtos_compatibility_layers/posix/signal.h
blob: 0da4adea7e1ff792ee3abd6b7269a119f471d31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/

/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/**   ThreadX Component                                                   */
/**                                                                       */
/**   POSIX Compliancy Wrapper (POSIX)                                    */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

/**************************************************************************/
/*                                                                        */
/*  EKP DEFINITIONS                                        RELEASE        */
/*                                                                        */
/*    signal.h                                            PORTABLE C      */
/*                                                           6.2.0        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    William E. Lamie, Microsoft Corporation                             */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This file defines the constants, structures, etc.needed to          */
/*    implement signals functionality for POSIX Users (POSIX)             */
/*                                                                        */
/**************************************************************************/

#ifndef _SIGNAL_H
#define _SIGNAL_H


/* The POSIX wrapper for ThreadX supports a maximum of 32 signals, from 0
   through 31, inclusive. In this implemenation, signals are NOT queued.  */


/* Define constants for the signal implementation.  */

#define MAX_SIGNALS 32
#define SIGRTMIN    0
#define SIGRTMAX    31
#define SIG_DFL     (void *) 0
#define SIG_IGN     (void *) 0
#define SIG_BLOCK   1
#define SIG_SETMASK 2
#define SIG_UNBLOCK 3


/* Define the typdefs for this signal handling implementation.  */


/* Define the type that holds the desired signals.  */

typedef struct sigset_t_struct
{
    unsigned long   signal_set;
} sigset_t;


/* Define the type that keeps track of information in the POSIX thread control block. POSIX threads are used to simulate the behavior
   of POSIX signals in this implemenation.  */

struct pthread_control_block;
struct pthread_t_variable;

typedef struct signal_info_struct
{

    UINT                            signal_handler;                         /* This is a flag. If TRUE, this thread is being used as a signal handler. If FALSE, it is a regular thread. */
    UINT                            signal_nesting_depth;                   /* A positive value indicates the level of nested signal handling the POSIX thread is currently processing.  */
    sigset_t                        signal_pending;                         /* Bit map of signals pending.                                                                               */
    sigset_t                        signal_mask;                            /* Signal mask, bit blocks the signal until cleared.                                                         */
    UINT                            saved_thread_state;                     /* Saved ThreadX state of the POSIX thread, at the time of the first signal.                                 */
    struct  pthread_control_block  *base_thread_ptr;                        /* Pointer to the thread associated with the signal.                                                         */
    struct  pthread_control_block  *top_signal_thread;                      /* Pointer to the top (most recent) signal thread.                                                           */
    struct  pthread_control_block  *next_signal_thread;                     /* Pointer to the next most recent signal thread.                                                            */
    void                            (*signal_func[MAX_SIGNALS])(int);       /* Array of signal handlers for this thread.                                                                 */
    TX_EVENT_FLAGS_GROUP            signal_event_flags;                     /* ThreadX event flag group used for sigwait                                                                 */

} signal_info;


/* Define public POSIX routines.  */

int   signal(int signo, void (*func)(int));
int   pthread_kill(ALIGN_TYPE thread, int sig);
int   sigwait(const sigset_t *set, int *sig);
int   sigemptyset(sigset_t *set);
int   sigaddset(sigset_t *set, int signo);
int   sigfillset(sigset_t *set);
int   sigdelset(sigset_t *set, int signo);
int   pthread_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask);


/* Define internal POSIX routines.  */

void  internal_signal_dispatch(ULONG id);


#endif