mirror of
https://github.com/UzixLS/KernelEx.git
synced 2025-07-19 07:21:20 +03:00
import KernelEx-4.0-Final
This commit is contained in:
27
kexcrt/gcc/dllcrt0.c
Normal file
27
kexcrt/gcc/dllcrt0.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <windows.h>
|
||||
#include "init.h"
|
||||
|
||||
extern BOOL WINAPI DllMain(
|
||||
HINSTANCE hDllHandle,
|
||||
DWORD dwReason,
|
||||
LPVOID lpReserved
|
||||
);
|
||||
|
||||
BOOL WINAPI _DllMainCRTStartup(
|
||||
HINSTANCE hDllHandle,
|
||||
DWORD dwReason,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
BOOL ret;
|
||||
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
__init();
|
||||
|
||||
ret = DllMain(hDllHandle, dwReason, lpReserved);
|
||||
|
||||
if (dwReason == DLL_PROCESS_DETACH)
|
||||
__exit();
|
||||
|
||||
return ret;
|
||||
}
|
105
kexcrt/gcc/init.c
Normal file
105
kexcrt/gcc/init.c
Normal file
@ -0,0 +1,105 @@
|
||||
#include <stdlib.h>
|
||||
#include "init.h"
|
||||
|
||||
#define MAX_ATEXIT 32
|
||||
|
||||
typedef void (__cdecl *_PVFV)(void);
|
||||
|
||||
static _PVFV _atexitlist[MAX_ATEXIT];
|
||||
static int _atexitlist_cnt;
|
||||
|
||||
extern _PVFV __CTOR_LIST__[];
|
||||
extern _PVFV __DTOR_LIST__[];
|
||||
|
||||
extern void _pei386_runtime_relocator (void);
|
||||
|
||||
int atexit(_PVFV func)
|
||||
{
|
||||
if (_atexitlist_cnt < MAX_ATEXIT)
|
||||
{
|
||||
_atexitlist[_atexitlist_cnt++] = func;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
__do_global_dtors (void)
|
||||
{
|
||||
static _PVFV *p = __DTOR_LIST__ + 1;
|
||||
|
||||
/*
|
||||
* Call each destructor in the destructor list until a null pointer
|
||||
* is encountered.
|
||||
*/
|
||||
while (*p)
|
||||
{
|
||||
(*(p)) ();
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__do_global_ctors (void)
|
||||
{
|
||||
unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
|
||||
unsigned i;
|
||||
|
||||
/*
|
||||
* If the first entry in the constructor list is -1 then the list
|
||||
* is terminated with a null entry. Otherwise the first entry was
|
||||
* the number of pointers in the list.
|
||||
*/
|
||||
if (nptrs == -1)
|
||||
{
|
||||
for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++)
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
* Go through the list backwards calling constructors.
|
||||
*/
|
||||
for (i = nptrs; i >= 1; i--)
|
||||
{
|
||||
__CTOR_LIST__[i] ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Register the destructors for processing on exit.
|
||||
*/
|
||||
atexit (__do_global_dtors);
|
||||
}
|
||||
|
||||
static int initialized = 0;
|
||||
|
||||
void __init(void)
|
||||
{
|
||||
_pei386_runtime_relocator();
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
initialized = 1;
|
||||
__do_global_ctors ();
|
||||
}
|
||||
}
|
||||
|
||||
static int exited = 0;
|
||||
|
||||
void __exit(void)
|
||||
{
|
||||
if (exited)
|
||||
return;
|
||||
exited = 1;
|
||||
|
||||
if (_atexitlist_cnt)
|
||||
{
|
||||
_PVFV* p;
|
||||
for (p = _atexitlist + _atexitlist_cnt - 1 ; p >= _atexitlist ; p--)
|
||||
{
|
||||
if (*p != NULL)
|
||||
(**p)();
|
||||
p--;
|
||||
}
|
||||
}
|
||||
}
|
7
kexcrt/gcc/init.h
Normal file
7
kexcrt/gcc/init.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef __INIT_H
|
||||
#define __INIT_H
|
||||
|
||||
void __init(void);
|
||||
void __exit(void);
|
||||
|
||||
#endif
|
3
kexcrt/gcc/pseudo-reloc-list.c
Normal file
3
kexcrt/gcc/pseudo-reloc-list.c
Normal file
@ -0,0 +1,3 @@
|
||||
/* Define here in .bss in case not defined by linker script. */
|
||||
char __RUNTIME_PSEUDO_RELOC_LIST_END__ = 0;
|
||||
char __RUNTIME_PSEUDO_RELOC_LIST__ = 0;
|
46
kexcrt/gcc/pseudo-reloc.c
Normal file
46
kexcrt/gcc/pseudo-reloc.c
Normal file
@ -0,0 +1,46 @@
|
||||
/* pseudo-reloc.c
|
||||
|
||||
Written by Egor Duda <deo@logos-m.ru>
|
||||
THIS SOFTWARE IS NOT COPYRIGHTED
|
||||
|
||||
This source code is offered for use in the public domain. You may
|
||||
use, modify or distribute it freely.
|
||||
|
||||
This code is distributed in the hope that it will be useful but
|
||||
WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
|
||||
DISCLAMED. This includes but is not limited to warrenties of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
extern char __RUNTIME_PSEUDO_RELOC_LIST__;
|
||||
extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
|
||||
extern char _image_base__;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DWORD addend;
|
||||
DWORD target;
|
||||
}
|
||||
runtime_pseudo_reloc;
|
||||
|
||||
static void
|
||||
do_pseudo_reloc (void* start, void* end, void* base)
|
||||
{
|
||||
DWORD reloc_target;
|
||||
runtime_pseudo_reloc* r;
|
||||
for (r = (runtime_pseudo_reloc*) start; r < (runtime_pseudo_reloc*) end; r++)
|
||||
{
|
||||
reloc_target = (DWORD) base + r->target;
|
||||
*((DWORD*) reloc_target) += r->addend;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_pei386_runtime_relocator ()
|
||||
{
|
||||
do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
|
||||
&__RUNTIME_PSEUDO_RELOC_LIST_END__,
|
||||
&_image_base__);
|
||||
}
|
Reference in New Issue
Block a user