summaryrefslogtreecommitdiffstats
path: root/StdLib/LibC/Signal
diff options
context:
space:
mode:
Diffstat (limited to 'StdLib/LibC/Signal')
-rw-r--r--StdLib/LibC/Signal/Signal.c93
-rw-r--r--StdLib/LibC/Signal/Signal.inf39
2 files changed, 132 insertions, 0 deletions
diff --git a/StdLib/LibC/Signal/Signal.c b/StdLib/LibC/Signal/Signal.c
new file mode 100644
index 0000000000..15b9ecabc2
--- /dev/null
+++ b/StdLib/LibC/Signal/Signal.c
@@ -0,0 +1,93 @@
+/** @file
+ Implementation of the signal and raise functions as declared in <signal.h>.
+
+ Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials are licensed and made available under
+ the terms and conditions of the BSD License that accompanies this distribution.
+ The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#include <Uefi.h>
+#include <Library/UefiLib.h>
+
+#include <LibConfig.h>
+#include <errno.h>
+#include <signal.h>
+#include <MainData.h>
+
+/** The signal function associates a "signal handler" with a signal number.
+
+ The signal function chooses one of three ways in which receipt of the
+ signal number, sig, is to be subsequently handled. If the value of func
+ is SIG_DFL, default handling for that signal will occur. If the value of
+ func is SIG_IGN, the signal will be ignored. Otherwise, func shall point
+ to a function to be called when that signal occurs. An invocation of such a
+ function because of a signal, or (recursively) of any further functions
+ called by that invocation (other than functions in the standard library),
+ is called a signal handler.
+
+ At program startup, the equivalent of signal(sig, SIG_IGN); may be executed
+ for some signals selected in an implementation-defined manner; the
+ equivalent of signal(sig, SIG_DFL); is executed for all other signals
+ defined by the implementation.
+
+ @return If the request can be honored, the signal function returns the
+ value of func for the most recent successful call to signal for
+ the specified signal sig. Otherwise, a value of SIG_ERR is
+ returned and a positive value is stored in errno.
+ */
+__sighandler_t *
+signal(int sig, __sighandler_t *func)
+{
+ __sighandler_t *OldHandler;
+
+ if (sig < 0 || sig >= SIG_LAST) {
+ errno = EINVAL;
+ return SIG_ERR;
+ }
+ OldHandler = gMD->sigarray[sig];
+ gMD->sigarray[sig] = func;
+
+ return OldHandler;
+}
+
+static
+void
+_defaultSignalHandler( int sig )
+{
+ Print(L"\nCaught signal %d.\n", sig);
+}
+
+/** Send a signal.
+
+ The raise function carries out the actions described for signal, above,
+ for the signal sig.
+
+ If a signal handler is called, the raise function shall not return until
+ after the signal handler does.
+
+ @return The raise function returns zero if successful,
+ nonzero if unsuccessful.
+**/
+int
+raise( int sig)
+{
+ __sighandler_t *Handler;
+
+ if (sig < 0 || sig >= SIG_LAST) {
+ return EINVAL;
+ }
+ Handler = gMD->sigarray[sig];
+
+ if(Handler == SIG_DFL) {
+ _defaultSignalHandler( sig );
+ }
+ else if( Handler != SIG_IGN) {
+ Handler( sig );
+ }
+ return 0;
+}
diff --git a/StdLib/LibC/Signal/Signal.inf b/StdLib/LibC/Signal/Signal.inf
new file mode 100644
index 0000000000..1d991887dd
--- /dev/null
+++ b/StdLib/LibC/Signal/Signal.inf
@@ -0,0 +1,39 @@
+## @file
+# Standard C library: StdLib implementations.
+#
+# Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php.
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = LibSignal
+ FILE_GUID = 00c86db8-013b-4ff4-b8e9-208f4fcf1c00
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = LibSignal
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF
+#
+
+[Sources]
+ Signal.c
+
+[Packages]
+ StdLib/StdLib.dec
+ StdLibPrivateInternalFiles/DoNotUse.dec
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiLib
+ LibC