-
Notifications
You must be signed in to change notification settings - Fork 2
/
signal.c
90 lines (65 loc) · 2.18 KB
/
signal.c
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
/*++
toro C Library
https://github.com/KilianKegel/toro-C-Library#toro-c-library-formerly-known-as-torito-c-library
Copyright (c) 2017-2024, Kilian Kegel. All rights reserved.
SPDX-License-Identifier: GNU General Public License v3.0
Module Name:
signal.c
Abstract:
Implementation of the Standard C function.
Sets interrupt signal handling.
Author:
Kilian Kegel
--*/
#include <CdeServices.h>
#include <signal.h>
extern char _cdeSig2idx(int sig);
extern void _cdeSigDflt(int sig);
extern void _cdeSigIgn(int sig);
/**
Synopsis
#include <signal.h>
void (*signal(int sig, void (*func)(int)))(int);
Description
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=msvc-160&viewFallbackFrom=vs-2019
Parameters
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=msvc-160#parameters
Returns
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=msvc-160#return-value
@param[in] sig signal number
@param[in] func address of handler
@retval eighter ISLOWER or ISUPPER or
@retval 0 if not
**/
void (*signal(int sig, void (*func)(int)))(int)
{
void (*pRet)(int) = (void (*)(int)) - 1;
char idx = _cdeSig2idx(sig);
CDE_APP_IF* pCdeAppIf = __cdeGetAppIf();
do {
if (idx < 0)
break; //return -1
//NOTE: raise() does not reinstall the default handler, as expected, but some garbage address
// that is returned by signal(), once the signal was raised...
//MSFT BUGBUG pCdeAppIf->rgfnSignal[idx] = &_cdeSigDflt;
if (pCdeAppIf->rgfnSignal[idx] == &_cdeSigDflt) {
pRet = SIG_DFL;
}
else if (pCdeAppIf->rgfnSignal[idx] == &_cdeSigIgn) {
pRet = SIG_IGN;
}
else {
pRet = pCdeAppIf->rgfnSignal[idx];
}
if (func == SIG_DFL) {
pCdeAppIf->rgfnSignal[idx] = &_cdeSigDflt;
}
else if (func == SIG_IGN) {
pCdeAppIf->rgfnSignal[idx] = &_cdeSigIgn;
}
else {
pCdeAppIf->rgfnSignal[idx] = func;
}
} while (0);
return (pRet);
}