1 | /** @file
|
---|
2 | Implementation of the signal and raise functions as declared in <signal.h>.
|
---|
3 |
|
---|
4 | Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
|
---|
5 | This program and the accompanying materials are licensed and made available under
|
---|
6 | the terms and conditions of the BSD License that accompanies this distribution.
|
---|
7 | The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php.
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 |
|
---|
13 | **/
|
---|
14 | #include <Uefi.h>
|
---|
15 | #include <Library/UefiLib.h>
|
---|
16 |
|
---|
17 | #include <LibConfig.h>
|
---|
18 | #include <errno.h>
|
---|
19 | #include <signal.h>
|
---|
20 | #include <MainData.h>
|
---|
21 |
|
---|
22 | /** The signal function associates a "signal handler" with a signal number.
|
---|
23 |
|
---|
24 | The signal function chooses one of three ways in which receipt of the
|
---|
25 | signal number, sig, is to be subsequently handled. If the value of func
|
---|
26 | is SIG_DFL, default handling for that signal will occur. If the value of
|
---|
27 | func is SIG_IGN, the signal will be ignored. Otherwise, func shall point
|
---|
28 | to a function to be called when that signal occurs. An invocation of such a
|
---|
29 | function because of a signal, or (recursively) of any further functions
|
---|
30 | called by that invocation (other than functions in the standard library),
|
---|
31 | is called a signal handler.
|
---|
32 |
|
---|
33 | At program startup, the equivalent of signal(sig, SIG_IGN); may be executed
|
---|
34 | for some signals selected in an implementation-defined manner; the
|
---|
35 | equivalent of signal(sig, SIG_DFL); is executed for all other signals
|
---|
36 | defined by the implementation.
|
---|
37 |
|
---|
38 | @return If the request can be honored, the signal function returns the
|
---|
39 | value of func for the most recent successful call to signal for
|
---|
40 | the specified signal sig. Otherwise, a value of SIG_ERR is
|
---|
41 | returned and a positive value is stored in errno.
|
---|
42 | */
|
---|
43 | __sighandler_t *
|
---|
44 | signal(int sig, __sighandler_t *func)
|
---|
45 | {
|
---|
46 | __sighandler_t *OldHandler;
|
---|
47 |
|
---|
48 | if (sig < 0 || sig >= SIG_LAST) {
|
---|
49 | errno = EINVAL;
|
---|
50 | return SIG_ERR;
|
---|
51 | }
|
---|
52 | OldHandler = gMD->sigarray[sig];
|
---|
53 | gMD->sigarray[sig] = func;
|
---|
54 |
|
---|
55 | return OldHandler;
|
---|
56 | }
|
---|
57 |
|
---|
58 | static
|
---|
59 | void
|
---|
60 | _defaultSignalHandler( int sig )
|
---|
61 | {
|
---|
62 | Print(L"\nCaught signal %d.\n", sig);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /** Send a signal.
|
---|
66 |
|
---|
67 | The raise function carries out the actions described for signal, above,
|
---|
68 | for the signal sig.
|
---|
69 |
|
---|
70 | If a signal handler is called, the raise function shall not return until
|
---|
71 | after the signal handler does.
|
---|
72 |
|
---|
73 | @return The raise function returns zero if successful,
|
---|
74 | nonzero if unsuccessful.
|
---|
75 | **/
|
---|
76 | int
|
---|
77 | raise( int sig)
|
---|
78 | {
|
---|
79 | __sighandler_t *Handler;
|
---|
80 |
|
---|
81 | if (sig < 0 || sig >= SIG_LAST) {
|
---|
82 | return EINVAL;
|
---|
83 | }
|
---|
84 | Handler = gMD->sigarray[sig];
|
---|
85 |
|
---|
86 | if(Handler == SIG_DFL) {
|
---|
87 | _defaultSignalHandler( sig );
|
---|
88 | }
|
---|
89 | else if( Handler != SIG_IGN) {
|
---|
90 | Handler( sig );
|
---|
91 | }
|
---|
92 | return 0;
|
---|
93 | }
|
---|