diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-12 11:42:47 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-12 11:42:47 +0100 |
commit | 07c7e353722d880b565188dba9f81a0449baf80c (patch) | |
tree | 8feb9e4823fca5c908180be7ee17ed3f022f1d69 | |
parent | 76b5869bf4d30d719e1c888606dd9f0fa78ccc2b (diff) | |
download | serenity-07c7e353722d880b565188dba9f81a0449baf80c.zip |
Demos: Remove "DynamicLink" and "DynamicObject"
The whole system builds & runs with dynamic linking now, so we don't
really need these little test apps anymore.
-rw-r--r-- | Demos/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Demos/DynamicLink/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Demos/DynamicLink/LinkDemo/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Demos/DynamicLink/LinkDemo/main.cpp | 121 | ||||
-rw-r--r-- | Demos/DynamicLink/LinkLib/CMakeLists.txt | 7 | ||||
-rw-r--r-- | Demos/DynamicLink/LinkLib/DynamicLib.cpp | 83 | ||||
-rw-r--r-- | Demos/DynamicObject/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Demos/DynamicObject/SampleLib/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Demos/DynamicObject/SampleLib/lib.cpp | 45 | ||||
-rw-r--r-- | Demos/DynamicObject/lib.h | 32 | ||||
-rw-r--r-- | Demos/DynamicObject/main.cpp | 78 |
11 files changed, 0 insertions, 397 deletions
diff --git a/Demos/CMakeLists.txt b/Demos/CMakeLists.txt index 5c16229e77..dbb31e2e1a 100644 --- a/Demos/CMakeLists.txt +++ b/Demos/CMakeLists.txt @@ -1,7 +1,5 @@ add_subdirectory(CatDog) add_subdirectory(Cube) -add_subdirectory(DynamicObject) -#add_subdirectory(DynamicLink) add_subdirectory(Eyes) add_subdirectory(Fire) add_subdirectory(HelloWorld) diff --git a/Demos/DynamicLink/CMakeLists.txt b/Demos/DynamicLink/CMakeLists.txt deleted file mode 100644 index d162567bdd..0000000000 --- a/Demos/DynamicLink/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(LinkDemo) -add_subdirectory(LinkLib) diff --git a/Demos/DynamicLink/LinkDemo/CMakeLists.txt b/Demos/DynamicLink/LinkDemo/CMakeLists.txt deleted file mode 100644 index ec5506f6a2..0000000000 --- a/Demos/DynamicLink/LinkDemo/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -set(SOURCES - main.cpp -) - -serenity_bin(LinkDemo) -target_link_libraries(LinkDemo LibC) diff --git a/Demos/DynamicLink/LinkDemo/main.cpp b/Demos/DynamicLink/LinkDemo/main.cpp deleted file mode 100644 index f24e2a17bc..0000000000 --- a/Demos/DynamicLink/LinkDemo/main.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2019-2020, Andrew Kaster <andrewdkaster@gmail.com> - * 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. - */ - -#include <AK/String.h> -#include <LibELF/AuxiliaryVector.h> - -#include <dlfcn.h> -#include <stdio.h> - -int main(int argc, char** argv, char** envp) -{ - for (int i = 0; i < argc; ++i) - outln("argv[{}]: {}", i, argv[i]); - - char** env; - for (env = envp; *env; ++env) - outln("env: {}", *env); - - for (auxv_t* auxvp = (auxv_t*)++env; auxvp->a_type != AT_NULL; ++auxvp) { - outln("AuxVal: Type={}, Val/Ptr={}", auxvp->a_type, auxvp->a_un.a_ptr); - if (auxvp->a_type == AT_PLATFORM) { - outln(" Platform: {}", (char*)auxvp->a_un.a_ptr); - } else if (auxvp->a_type == AT_EXECFN) { - outln(" Filename: {}", (char*)auxvp->a_un.a_ptr); - } else if (auxvp->a_type == AT_RANDOM) { - auto byte_ptr = (uint8_t*)auxvp->a_un.a_ptr; - outln(" My Random bytes are: "); - for (size_t i = 0; i < 16; ++i) - out("{:#02x} ", byte_ptr[i]); - outln(); - } - } - - void* handle = dlopen("/usr/lib/libDynamicLib.so", RTLD_LAZY | RTLD_GLOBAL); - - if (!handle) { - warnln("Failed to dlopen! {}", dlerror()); - return 1; - } - - // Test getting an external variable from the library and read it out - int* ptr_global = (int*)dlsym(handle, "global_lib_variable"); - - if (!ptr_global) { - warnln("Failed to dlsym for \"global_lib_variable\"! {}", dlerror()); - return 2; - } - - outln("Found global lib variable address: {}", ptr_global); - - outln("Global lib variable is {}", *ptr_global); - - // Test getting a method from the library and calling it - void (*lib_func)() = (void (*)())dlsym(handle, "global_lib_function"); - - outln("Found global lib function address: {}", lib_func); - - if (!lib_func) { - warnln("Failed to dlsym for \"global_lib_function\"! {}", dlerror()); - return 2; - } - - lib_func(); - - outln("I think I called my lib function!"); - - // Test getting a method that takes and returns arguments now - const char* (*other_func)(int) = (const char* (*)(int))dlsym(handle, "other_lib_function"); - - outln("Found other lib function address {}", other_func); - - if (!other_func) { - warnln("Failed to dlsym for \"other_lib_function\"! {}", dlerror()); - return 2; - } - - // Call it twice with different arguments - String formatted_result = other_func(10); - - outln("({} + {} = {}) {}", *ptr_global, 10, *ptr_global + 10, formatted_result); - - *ptr_global = 17; - - formatted_result = other_func(5); - - outln("({} + {} = {}) {}", *ptr_global, 5, *ptr_global + 5, formatted_result); - - int ret = dlclose(handle); - - if (ret < 0) { - warnln("Failed to dlclose! {}", dlerror()); - return 3; - } - - outln("Bye for now!"); - - return 0; -} diff --git a/Demos/DynamicLink/LinkLib/CMakeLists.txt b/Demos/DynamicLink/LinkLib/CMakeLists.txt deleted file mode 100644 index 982cdda6a5..0000000000 --- a/Demos/DynamicLink/LinkLib/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(SOURCES - DynamicLib.cpp -) - -add_library(DynamicLib SHARED ${SOURCES}) -target_link_libraries(DynamicLib LibC) -install(TARGETS DynamicLib DESTINATION usr/lib) diff --git a/Demos/DynamicLink/LinkLib/DynamicLib.cpp b/Demos/DynamicLink/LinkLib/DynamicLib.cpp deleted file mode 100644 index 45461c7c48..0000000000 --- a/Demos/DynamicLink/LinkLib/DynamicLib.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2019-2020, Andrew Kaster <andrewdkaster@gmail.com> - * 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. - */ - -#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.. - -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(); - } - - int get_i() const { return m_i; } - -private: - int m_i = 0; -}; - -// This object exists to call __stdio_init and __malloc_init. Also to show that global vars work -Global g_glob { 5 }; - -extern "C" { - -// Tell the compiler that these symbols might be accessed from other places: -extern int global_lib_variable; -void global_lib_function(); -const char* other_lib_function(int my_argument); - -int global_lib_variable = 1234; - -void global_lib_function() -{ - outln("Hello from Dynamic Lib! g_glob::m_i == {}", g_glob.get_i()); -} - -const char* other_lib_function(int my_argument) -{ - dbgln("Hello from Dynamic Lib, now from the debug port! g_glob::m_i == {}", g_glob.get_i()); - - int sum = my_argument + global_lib_variable; - - // FIXME: We can't just return AK::String::format across the lib boundary here. - // It will use malloc from our DSO's copy of LibC, and then probably be free'd into - // the malloc of the main program which would be what they call 'very crash'. - // Feels very Windows :) - static String s_string; - s_string = String::formatted("Here's your string! Sum of argument and global_lib_variable: {}", sum); - return s_string.characters(); -} -} diff --git a/Demos/DynamicObject/CMakeLists.txt b/Demos/DynamicObject/CMakeLists.txt deleted file mode 100644 index 06781c7c9f..0000000000 --- a/Demos/DynamicObject/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -set(SOURCES - main.cpp -) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostartfiles -lgcc_s -pie -fpic ") - -serenity_bin(DynamicObjectDemo) -target_link_libraries(DynamicObjectDemo SampleLib LibC LibCore LibGUI) - -add_subdirectory(SampleLib) diff --git a/Demos/DynamicObject/SampleLib/CMakeLists.txt b/Demos/DynamicObject/SampleLib/CMakeLists.txt deleted file mode 100644 index 38a75141f0..0000000000 --- a/Demos/DynamicObject/SampleLib/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ - -set(SOURCES - lib.cpp -) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -fpic") - -add_library(SampleLib SHARED ${SOURCES}) -target_link_libraries(SampleLib LibC) -#target_link_libraries(SampleLib) -install(TARGETS SampleLib DESTINATION usr/lib) diff --git a/Demos/DynamicObject/SampleLib/lib.cpp b/Demos/DynamicObject/SampleLib/lib.cpp deleted file mode 100644 index a0e6e76aa7..0000000000 --- a/Demos/DynamicObject/SampleLib/lib.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ - -#include "../lib.h" - -int func(); - -__thread int g_tls1 = 0; -__thread int g_tls2 = 0; - -static void init_function() __attribute__((constructor)); - -void init_function() -{ - g_tls1 = 1; - g_tls2 = 2; -} - -int func() -{ - return 3; -} diff --git a/Demos/DynamicObject/lib.h b/Demos/DynamicObject/lib.h deleted file mode 100644 index 05b59afd9e..0000000000 --- a/Demos/DynamicObject/lib.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 - -int func(); - -extern __thread int g_tls1; -extern __thread int g_tls2; diff --git a/Demos/DynamicObject/main.cpp b/Demos/DynamicObject/main.cpp deleted file mode 100644 index 541aa6ea0d..0000000000 --- a/Demos/DynamicObject/main.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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. - */ - -#include "lib.h" -#include <LibCore/Command.h> -#include <LibGUI/Application.h> -#include <LibGUI/BoxLayout.h> -#include <LibGUI/Button.h> -#include <LibGUI/Label.h> -#include <LibGUI/Widget.h> -#include <LibGUI/Window.h> -#include <fcntl.h> -#include <stdio.h> -#include <sys/internals.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> - -int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv, [[maybe_unused]] char** env) -{ - printf("Well Hello Friends!\n"); - printf("trying to open /etc/fstab for writing..\n"); - int rc = open("/etc/fstab", O_RDWR); - if (rc == -1) { - int _errno = errno; - perror("open failed"); - printf("rc: %d, errno: %d\n", rc, _errno); - } - printf("ls: %s\n", Core::command("ls", {}).characters()); - auto app = GUI::Application::construct(argc, argv); - - auto window = GUI::Window::construct(); - window->resize(240, 160); - window->set_title("Hello World!"); - window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-hello-world.png")); - - auto& main_widget = window->set_main_widget<GUI::Widget>(); - main_widget.set_fill_with_background_color(true); - auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>(); - layout.set_margins({ 4, 4, 4, 4 }); - - auto& label = main_widget.add<GUI::Label>(); - label.set_text("Hello\nWorld!"); - - auto& button = main_widget.add<GUI::Button>(); - button.set_text("Good-bye"); - button.on_click = [&](auto) { - app->quit(); - }; - - window->show(); - - return app->exec(); - // return func() + g_tls1 + g_tls2; -} |