summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Demos/DynamicLink/LinkLib/DynamicLib.cpp8
-rw-r--r--Libraries/LibC/crt0.cpp7
-rw-r--r--Libraries/LibC/libcinit.cpp7
-rw-r--r--Libraries/LibC/malloc.cpp1
-rw-r--r--Libraries/LibC/stdio.cpp1
-rw-r--r--Libraries/LibC/sys/internals.h39
6 files changed, 49 insertions, 14 deletions
diff --git a/Demos/DynamicLink/LinkLib/DynamicLib.cpp b/Demos/DynamicLink/LinkLib/DynamicLib.cpp
index 547a206468..8e1a36dcb0 100644
--- a/Demos/DynamicLink/LinkLib/DynamicLib.cpp
+++ b/Demos/DynamicLink/LinkLib/DynamicLib.cpp
@@ -27,19 +27,17 @@
#include <AK/String.h>
#include <assert.h>
#include <stdio.h>
+#include <sys/internals.h>
char* __static_environ[] = { nullptr }; // We don't get the environment without some libc workarounds..
-// FIXME: Because we need to call printf, and we don't have access to the stout file descriptor
-// from the main executable. We need to call __libc_init....
-extern "C" void __libc_init();
-extern "C" bool __environ_is_malloced;
-
class Global {
public:
Global(int i)
: m_i(i)
{
+ // FIXME: Because we need to call printf, and we don't have access to the stdout
+ // file descriptor from the main executable, we need to initialize LibC ourself.
__environ_is_malloced = false;
environ = __static_environ;
__libc_init();
diff --git a/Libraries/LibC/crt0.cpp b/Libraries/LibC/crt0.cpp
index 60a96cb066..513df9c49f 100644
--- a/Libraries/LibC/crt0.cpp
+++ b/Libraries/LibC/crt0.cpp
@@ -28,16 +28,13 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/internals.h>
+#include <unistd.h>
extern "C" {
int main(int, char**, char**);
-extern void __libc_init();
-extern void _init();
-extern char** environ;
-extern bool __environ_is_malloced;
-
// Tell the compiler that this may be called from somewhere else.
int _start(int argc, char** argv, char** env);
diff --git a/Libraries/LibC/libcinit.cpp b/Libraries/LibC/libcinit.cpp
index 8aba7a62b5..8f97a51737 100644
--- a/Libraries/LibC/libcinit.cpp
+++ b/Libraries/LibC/libcinit.cpp
@@ -26,6 +26,8 @@
#include <AK/Types.h>
#include <assert.h>
+#include <sys/internals.h>
+#include <unistd.h>
extern "C" {
@@ -35,10 +37,7 @@ bool __environ_is_malloced;
void __libc_init()
{
- void __malloc_init();
__malloc_init();
-
- void __stdio_init();
__stdio_init();
}
@@ -52,9 +51,9 @@ void __libc_init()
extern u32 __stack_chk_guard;
u32 __stack_chk_guard = (u32)0xc6c7c8c9;
+[[noreturn]] void __stack_chk_fail();
[[noreturn]] void __stack_chk_fail()
{
ASSERT_NOT_REACHED();
}
-
}
diff --git a/Libraries/LibC/malloc.cpp b/Libraries/LibC/malloc.cpp
index 6971ead3ff..17ddbbb1b4 100644
--- a/Libraries/LibC/malloc.cpp
+++ b/Libraries/LibC/malloc.cpp
@@ -35,6 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/internals.h>
#include <sys/mman.h>
// FIXME: Thread safety.
diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp
index f0922acde4..53ee187fa6 100644
--- a/Libraries/LibC/stdio.cpp
+++ b/Libraries/LibC/stdio.cpp
@@ -38,6 +38,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/internals.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
diff --git a/Libraries/LibC/sys/internals.h b/Libraries/LibC/sys/internals.h
new file mode 100644
index 0000000000..d86f616b5c
--- /dev/null
+++ b/Libraries/LibC/sys/internals.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2020, the SerenityOS developers.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+extern void __libc_init();
+extern void __malloc_init();
+extern void __stdio_init();
+extern void _init();
+extern bool __environ_is_malloced;
+
+__END_DECLS