-
Notifications
You must be signed in to change notification settings - Fork 26
/
dll-alloc.cpp
84 lines (65 loc) · 1.62 KB
/
dll-alloc.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright Hannes Domani 2014 - 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <stdlib.h>
#include <windows.h>
static void *allocated = NULL;
extern "C" __declspec(dllexport) void *dll_alloc( size_t s )
{
return( allocated=malloc(s) );
}
static void *memory = NULL;
extern "C" __declspec(dllexport) void *dll_memory( void )
{
return( memory );
}
static int *one_int = NULL;
extern "C" __declspec(dllexport) int *dll_int( void )
{
return( one_int );
}
static int *arr_int = NULL;
extern "C" __declspec(dllexport) int *dll_arr( void )
{
return( arr_int );
}
static DWORD thread_id;
extern "C" __declspec(dllexport) DWORD dll_thread_id( void )
{
return( thread_id );
}
extern "C" __declspec(dllexport) void do_nothing( void* )
{
}
static char dll_text[10] = "something";
extern "C" __declspec(dllexport) char *dll_static_char( void )
{
return( dll_text );
}
static CRITICAL_SECTION cs;
extern "C" __declspec(dllexport) void dll_enter_critical_section( void )
{
EnterCriticalSection( &cs );
}
extern "C" BOOL WINAPI DllMain(
HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved )
{
(void)hinstDLL;
(void)lpvReserved;
if( fdwReason==DLL_PROCESS_ATTACH )
{
memory = malloc( 101 );
one_int = new int;
arr_int = new int[50];
thread_id = GetCurrentThreadId();
InitializeCriticalSection( &cs );
}
if( fdwReason==DLL_PROCESS_DETACH )
{
EnterCriticalSection( &cs );
free( allocated );
LeaveCriticalSection( &cs );
}
return( TRUE );
}