summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2020-10-10 17:47:21 +0300
committerAndreas Kling <kling@serenityos.org>2020-12-14 23:05:53 +0100
commit65ee2f07b725e8e71c156de8a8741e8e545c8786 (patch)
tree82550ed31769e6e956b9587470936fa51ea55564
parentb1c1d7661f51e04b733a77eadc416a0479721e18 (diff)
downloadserenity-65ee2f07b725e8e71c156de8a8741e8e545c8786.zip
LibC: Make it possible to use ASSERTs without initializing stdio
-rw-r--r--Libraries/LibC/assert.cpp5
-rw-r--r--Libraries/LibC/libcinit.cpp1
-rw-r--r--Libraries/LibC/stdio.cpp1
-rw-r--r--Libraries/LibC/sys/internals.h1
4 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibC/assert.cpp b/Libraries/LibC/assert.cpp
index ae4ddfe7df..9e84b22cd6 100644
--- a/Libraries/LibC/assert.cpp
+++ b/Libraries/LibC/assert.cpp
@@ -27,15 +27,18 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/internals.h>
#include <unistd.h>
extern "C" {
+extern bool __stdio_is_initialized;
#ifdef DEBUG
void __assertion_failed(const char* msg)
{
dbgprintf("USERSPACE(%d) ASSERTION FAILED: %s\n", getpid(), msg);
- fprintf(stderr, "ASSERTION FAILED: %s\n", msg);
+ if (__stdio_is_initialized)
+ fprintf(stderr, "ASSERTION FAILED: %s\n", msg);
abort();
}
#endif
diff --git a/Libraries/LibC/libcinit.cpp b/Libraries/LibC/libcinit.cpp
index 22e7eb62e9..7e38ebc36f 100644
--- a/Libraries/LibC/libcinit.cpp
+++ b/Libraries/LibC/libcinit.cpp
@@ -34,6 +34,7 @@ extern "C" {
__thread int errno;
char** environ;
bool __environ_is_malloced;
+bool __stdio_is_initialized;
void __libc_init()
{
diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp
index f39a7f0639..02f8b76702 100644
--- a/Libraries/LibC/stdio.cpp
+++ b/Libraries/LibC/stdio.cpp
@@ -585,6 +585,7 @@ void __stdio_init()
new (stdout) FILE(1, O_WRONLY);
new (stderr) FILE(2, O_WRONLY);
stderr->setbuf(nullptr, _IONBF, 0);
+ __stdio_is_initialized = true;
}
int setvbuf(FILE* stream, char* buf, int mode, size_t size)
diff --git a/Libraries/LibC/sys/internals.h b/Libraries/LibC/sys/internals.h
index 0ddde4037b..70443404e1 100644
--- a/Libraries/LibC/sys/internals.h
+++ b/Libraries/LibC/sys/internals.h
@@ -37,6 +37,7 @@ extern void __malloc_init();
extern void __stdio_init();
extern void _init();
extern bool __environ_is_malloced;
+extern bool __stdio_is_initialized;
int __cxa_atexit(AtExitFunction exit_function, void* parameter, void* dso_handle);
void __cxa_finalize(void* dso_handle);