2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
8 #include <util/kernel_cpp.h>
10 #include "runtime_loader_private.h"
13 typedef DoublyLinkedList
<RuntimeLoaderAddOn
> AddOnList
;
16 static status_t
register_defined_symbol_patcher(struct image_t
* image
,
17 runtime_loader_symbol_patcher
* _patcher
, void* cookie
);
18 static void unregister_defined_symbol_patcher(struct image_t
* image
,
19 runtime_loader_symbol_patcher
* _patcher
, void* cookie
);
20 static status_t
register_undefined_symbol_patcher(struct image_t
* image
,
21 runtime_loader_symbol_patcher
* _patcher
, void* cookie
);
22 static void unregister_undefined_symbol_patcher(struct image_t
* image
,
23 runtime_loader_symbol_patcher
* _patcher
, void* cookie
);
26 static AddOnList sAddOns
;
28 static runtime_loader_add_on_export sRuntimeLoaderAddOnExport
= {
29 register_defined_symbol_patcher
,
30 unregister_defined_symbol_patcher
,
31 register_undefined_symbol_patcher
,
32 unregister_undefined_symbol_patcher
36 // #pragma mark - add-on support functions
40 register_defined_symbol_patcher(struct image_t
* image
,
41 runtime_loader_symbol_patcher
* _patcher
, void* cookie
)
43 RuntimeLoaderSymbolPatcher
* patcher
44 = new(mynothrow
) RuntimeLoaderSymbolPatcher(_patcher
, cookie
);
48 patcher
->next
= image
->defined_symbol_patchers
;
49 image
->defined_symbol_patchers
= patcher
;
56 unregister_defined_symbol_patcher(struct image_t
* image
,
57 runtime_loader_symbol_patcher
* _patcher
, void* cookie
)
59 RuntimeLoaderSymbolPatcher
** patcher
= &image
->defined_symbol_patchers
;
60 while (*patcher
!= NULL
) {
61 if ((*patcher
)->patcher
== _patcher
&& (*patcher
)->cookie
== cookie
) {
62 RuntimeLoaderSymbolPatcher
* toDelete
= *patcher
;
63 *patcher
= (*patcher
)->next
;
67 patcher
= &(*patcher
)->next
;
73 register_undefined_symbol_patcher(struct image_t
* image
,
74 runtime_loader_symbol_patcher
* _patcher
, void* cookie
)
76 RuntimeLoaderSymbolPatcher
* patcher
77 = new(mynothrow
) RuntimeLoaderSymbolPatcher(_patcher
, cookie
);
81 patcher
->next
= image
->undefined_symbol_patchers
;
82 image
->undefined_symbol_patchers
= patcher
;
89 unregister_undefined_symbol_patcher(struct image_t
* image
,
90 runtime_loader_symbol_patcher
* _patcher
, void* cookie
)
92 RuntimeLoaderSymbolPatcher
** patcher
= &image
->undefined_symbol_patchers
;
93 while (*patcher
!= NULL
) {
94 if ((*patcher
)->patcher
== _patcher
&& (*patcher
)->cookie
== cookie
) {
95 RuntimeLoaderSymbolPatcher
* toDelete
= *patcher
;
96 *patcher
= (*patcher
)->next
;
100 patcher
= &(*patcher
)->next
;
111 // invoke static constructors
112 new(&sAddOns
) AddOnList
;
117 add_add_on(image_t
* image
, runtime_loader_add_on
* addOnStruct
)
119 RuntimeLoaderAddOn
* addOn
= new(mynothrow
) RuntimeLoaderAddOn(image
,
125 addOnStruct
->init(&gRuntimeLoader
, &sRuntimeLoaderAddOnExport
);
132 image_event(image_t
* image
, uint32 event
)
134 AddOnList::Iterator it
= sAddOns
.GetIterator();
135 while (RuntimeLoaderAddOn
* addOn
= it
.Next()) {
136 void (*function
)(image_t
* image
) = NULL
;
139 case IMAGE_EVENT_LOADED
:
140 function
= addOn
->addOn
->image_loaded
;
142 case IMAGE_EVENT_RELOCATED
:
143 function
= addOn
->addOn
->image_relocated
;
145 case IMAGE_EVENT_INITIALIZED
:
146 function
= addOn
->addOn
->image_initialized
;
148 case IMAGE_EVENT_UNINITIALIZING
:
149 function
= addOn
->addOn
->image_uninitializing
;
151 case IMAGE_EVENT_UNLOADING
:
152 function
= addOn
->addOn
->image_unloading
;
156 if (function
!= NULL
)