1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /**   ThreadX Component                                                   */
16 /**                                                                       */
17 /**   POSIX Compliancy Wrapper (POSIX)                                    */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 /**************************************************************************/
23 /*                                                                        */
24 /*  EKP DEFINITIONS                                        RELEASE        */
25 /*                                                                        */
26 /*    signal.h                                            PORTABLE C      */
27 /*                                                           6.2.0        */
28 /*  AUTHOR                                                                */
29 /*                                                                        */
30 /*    William E. Lamie, Microsoft Corporation                             */
31 /*                                                                        */
32 /*  DESCRIPTION                                                           */
33 /*                                                                        */
34 /*    This file defines the constants, structures, etc.needed to          */
35 /*    implement signals functionality for POSIX Users (POSIX)             */
36 /*                                                                        */
37 /*                                                                        */
38 /*  RELEASE HISTORY                                                       */
39 /*                                                                        */
40 /*    DATE              NAME                      DESCRIPTION             */
41 /*                                                                        */
42 /*  06-02-2021      William E. Lamie        Initial Version 6.1.7         */
43 /*  10-31-2022      Scott Larson            Update pthread_kill argument  */
44 /*                                            type,                       */
45 /*                                            resulting in version 6.2.0  */
46 /*                                                                        */
47 /**************************************************************************/
48 
49 #ifndef _SIGNAL_H
50 #define _SIGNAL_H
51 
52 
53 /* The POSIX wrapper for ThreadX supports a maximum of 32 signals, from 0
54    through 31, inclusive. In this implemenation, signals are NOT queued.  */
55 
56 
57 /* Define constants for the signal implementation.  */
58 
59 #define MAX_SIGNALS 32
60 #define SIGRTMIN    0
61 #define SIGRTMAX    31
62 #define SIG_DFL     (void *) 0
63 #define SIG_IGN     (void *) 0
64 #define SIG_BLOCK   1
65 #define SIG_SETMASK 2
66 #define SIG_UNBLOCK 3
67 
68 
69 /* Define the typdefs for this signal handling implementation.  */
70 
71 
72 /* Define the type that holds the desired signals.  */
73 
74 typedef struct sigset_t_struct
75 {
76     unsigned long   signal_set;
77 } sigset_t;
78 
79 
80 /* Define the type that keeps track of information in the POSIX thread control block. POSIX threads are used to simulate the behavior
81    of POSIX signals in this implemenation.  */
82 
83 struct pthread_control_block;
84 struct pthread_t_variable;
85 
86 typedef struct signal_info_struct
87 {
88 
89     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. */
90     UINT                            signal_nesting_depth;                   /* A positive value indicates the level of nested signal handling the POSIX thread is currently processing.  */
91     sigset_t                        signal_pending;                         /* Bit map of signals pending.                                                                               */
92     sigset_t                        signal_mask;                            /* Signal mask, bit blocks the signal until cleared.                                                         */
93     UINT                            saved_thread_state;                     /* Saved ThreadX state of the POSIX thread, at the time of the first signal.                                 */
94     struct  pthread_control_block  *base_thread_ptr;                        /* Pointer to the thread associated with the signal.                                                         */
95     struct  pthread_control_block  *top_signal_thread;                      /* Pointer to the top (most recent) signal thread.                                                           */
96     struct  pthread_control_block  *next_signal_thread;                     /* Pointer to the next most recent signal thread.                                                            */
97     void                            (*signal_func[MAX_SIGNALS])(int);       /* Array of signal handlers for this thread.                                                                 */
98     TX_EVENT_FLAGS_GROUP            signal_event_flags;                     /* ThreadX event flag group used for sigwait                                                                 */
99 
100 } signal_info;
101 
102 
103 /* Define public POSIX routines.  */
104 
105 int   signal(int signo, void (*func)(int));
106 int   pthread_kill(ALIGN_TYPE thread, int sig);
107 int   sigwait(const sigset_t *set, int *sig);
108 int   sigemptyset(sigset_t *set);
109 int   sigaddset(sigset_t *set, int signo);
110 int   sigfillset(sigset_t *set);
111 int   sigdelset(sigset_t *set, int signo);
112 int   pthread_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask);
113 
114 
115 /* Define internal POSIX routines.  */
116 
117 void  internal_signal_dispatch(ULONG id);
118 
119 
120 #endif
121