summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-10-03 11:32:07 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-14 17:01:58 +0000
commit45ab4673cb6e7aa589d72f3f3700f7ed74a59e8d (patch)
tree0a70b80c64778887cf063a6bcfa662392c34c0c8 /libc
parent6003975a719df8440fb8da8ff7270eb6a3edc412 (diff)
downloadchrome-ec-45ab4673cb6e7aa589d72f3f3700f7ed74a59e8d.tar.gz
libc: Implement _exit(), which is needed by libc
_exit() is called by libc functions such as abort() or exit(). This implementation replaces the one from newlib's libnosys. BRANCH=none BUG=b:234181908 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I1d8f65fa206b3544a2772f38be854ee905532ad3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3933256 Reviewed-by: Andrea Grandi <agrandi@google.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/build.mk5
-rw-r--r--libc/syscalls.c29
2 files changed, 34 insertions, 0 deletions
diff --git a/libc/build.mk b/libc/build.mk
new file mode 100644
index 0000000000..594f3061d6
--- /dev/null
+++ b/libc/build.mk
@@ -0,0 +1,5 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+libc-y=syscalls.o
diff --git a/libc/syscalls.c b/libc/syscalls.c
new file mode 100644
index 0000000000..9c683a2732
--- /dev/null
+++ b/libc/syscalls.c
@@ -0,0 +1,29 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ *@brief Provides implementations of syscalls needed by libc. The newlib
+ * documentation provides a list of the required syscalls:
+ * https://sourceware.org/newlib/libc.html#Syscalls and minimal implementations
+ * can be found in newlib's "nosys" library:
+ * https://sourceware.org/git/?p=newlib-cygwin.git;a=tree;f=libgloss/libnosys.
+ */
+
+#include "panic.h"
+#include "software_panic.h"
+#include "task.h"
+
+/**
+ * Reboot the system.
+ *
+ * This function is called from libc functions such as abort() or exit().
+ *
+ * @param rc exit code
+ */
+void _exit(int rc)
+{
+ panic_printf("%s called with rc: %d\n", __func__, rc);
+ software_panic(PANIC_SW_EXIT, task_get_current());
+}