2
* Copyright (c) 2005 Massachusetts Institute of Technology
3
* Copyright (c) 2007 Secure Endpoints Inc.
5
* Permission is hereby granted, free of charge, to any person
6
* obtaining a copy of this software and associated documentation
7
* files (the "Software"), to deal in the Software without
8
* restriction, including without limitation the rights to use, copy,
9
* modify, merge, publish, distribute, sublicense, and/or sell copies
10
* of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be
14
* included in all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
#include<kmminternal.h>
30
kmm_module_i * kmm_all_modules = NULL;
31
kmm_plugin_i * kmm_listed_plugins = NULL;
33
HANDLE ht_registrar = NULL;
34
DWORD tid_registrar = 0;
37
#define KMM_HASH_SIZE 31
38
hashtable * hash_plugins = NULL;
39
hashtable * hash_modules = NULL;
41
CRITICAL_SECTION cs_kmm;
42
HANDLE evt_startup = NULL;
43
HANDLE evt_exit = NULL;
46
HINSTANCE kmm_hInstance;
47
const wchar_t * kmm_facility = L"KMM";
49
KHMEXP void KHMAPI kmm_init(void)
53
EnterCriticalSection(&cs_kmm);
54
kmm_all_modules = NULL;
55
kmm_listed_plugins = NULL;
59
hash_plugins = hash_new_hashtable(
66
hash_modules = hash_new_hashtable(
73
ht_registrar = CreateThread(
83
khc_load_schema(NULL, schema_kmmconfig);
85
LeaveCriticalSection(&cs_kmm);
88
KHMEXP void KHMAPI kmm_exit(void)
93
EnterCriticalSection(&cs_kmm);
95
p = kmm_listed_plugins;
100
/* plugins that were never resolved should be kicked off the
101
list. Flipping the refcount will do that if no other
102
references exist for the plugin. The plugins that were
103
waiting for unresolved dependencies will automatically get
104
freed when the placeholders and other plugins get freed. */
105
if(p->state == KMM_PLUGIN_STATE_PLACEHOLDER) {
106
kmm_hold_plugin(kmm_handle_from_plugin(p));
107
kmm_release_plugin(kmm_handle_from_plugin(p));
115
kmm_unload_module(kmm_handle_from_module(m));
119
LeaveCriticalSection(&cs_kmm);
120
WaitForSingleObject(evt_exit, INFINITE);
122
kmq_send_thread_quit_message(tid_registrar, 0);
124
EnterCriticalSection(&cs_kmm);
126
hash_del_hashtable(hash_plugins);
127
hash_del_hashtable(hash_modules);
129
LeaveCriticalSection(&cs_kmm);
136
void kmm_dll_init(void)
138
InitializeCriticalSection(&cs_kmm);
139
evt_startup = CreateEvent(NULL, TRUE, FALSE, NULL);
140
evt_exit = CreateEvent(NULL, TRUE, TRUE, NULL);
143
void kmm_dll_exit(void)
145
DeleteCriticalSection(&cs_kmm);
147
CloseHandle(evt_startup);
152
kmm_process_attach(HINSTANCE hinstDLL) {
153
kmm_hInstance = hinstDLL;
158
kmm_process_detach(void) {