summaryrefslogtreecommitdiffhomepage
path: root/Private/Source/SharedObjectEntry.cxx
blob: c4d69be9c32d754752ccaef4f4eee585b37d80f3 (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
56
57
58
/*
 * ========================================================
 *
 * 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;

/***********************************************************************************/
/// @file SharedObjectEntry.cxx
/// @brief Shared Object Init code.
/***********************************************************************************/

/***********************************************************************************/
/* @brief Allocate new library to be added to the lookup table.
 */
/***********************************************************************************/

extern "C" SharedObject *__LibMain(VoidPtr image) {
  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 jumping to library...\n";

  return library;
}

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