summaryrefslogtreecommitdiffhomepage
path: root/Private/Source/SharedObject.cxx
blob: a6ccc224fef6f3fb35a4f06f01489860a9afff5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * ========================================================
 *
 * hCore
 * Copyright 2024 Mahrouss Logic, all rights reserved.
 *
 *  ========================================================
 */

#include <KernelKit/DebugOutput.hpp>
#include <KernelKit/PEF.hpp>
#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/SharedObjectCore.hxx>
#include <KernelKit/ThreadLocalStorage.hxx>
#include <NewKit/Defines.hpp>

using namespace hCore;

/***********************************************************************************/

extern "C" SharedObject *__LibMain(VoidPtr image)
{
    /***********************************************************************************/
    /* Allocate new library to be added to the lookup table. 						   */
    /***********************************************************************************/

    SharedObject *library = hcore_tls_new_class<SharedObject>();

    if (!library)
    {
        kcout << "__LibMain: Out of Memory!\n";
        ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();

        return nullptr;
    }

    library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>());

    if (!library->Get())
    {
        kcout << "__LibMain: Out of Memory!\n";
        ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();

        return nullptr;
    }

    library->Get()->fImageObject = ProcessManager::Shared().Leak().GetCurrent().Leak().Image;
    library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart);

    kcout << "__LibMain: Done allocating Shared Library...\n";

    return library;
}

/***********************************************************************************/