Browse Source

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.
Andreas Kling 4 years ago
parent
commit
07c7e35372

+ 0 - 2
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)

+ 0 - 2
Demos/DynamicLink/CMakeLists.txt

@@ -1,2 +0,0 @@
-add_subdirectory(LinkDemo)
-add_subdirectory(LinkLib)

+ 0 - 6
Demos/DynamicLink/LinkDemo/CMakeLists.txt

@@ -1,6 +0,0 @@
-set(SOURCES
-    main.cpp
-)
-
-serenity_bin(LinkDemo)
-target_link_libraries(LinkDemo LibC)

+ 0 - 121
Demos/DynamicLink/LinkDemo/main.cpp

@@ -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;
-}

+ 0 - 7
Demos/DynamicLink/LinkLib/CMakeLists.txt

@@ -1,7 +0,0 @@
-set(SOURCES
-    DynamicLib.cpp
-)
-
-add_library(DynamicLib SHARED ${SOURCES})
-target_link_libraries(DynamicLib LibC)
-install(TARGETS DynamicLib DESTINATION usr/lib)

+ 0 - 83
Demos/DynamicLink/LinkLib/DynamicLib.cpp

@@ -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();
-}
-}

+ 0 - 10
Demos/DynamicObject/CMakeLists.txt

@@ -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)

+ 0 - 11
Demos/DynamicObject/SampleLib/CMakeLists.txt

@@ -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)

+ 0 - 45
Demos/DynamicObject/SampleLib/lib.cpp

@@ -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;
-}

+ 0 - 32
Demos/DynamicObject/lib.h

@@ -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;

+ 0 - 78
Demos/DynamicObject/main.cpp

@@ -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;
-}