Chameleon

Chameleon Commit Details

Date:2010-11-14 01:13:44 (8 years 8 months ago)
Author:Evan Lojewski
Commit:633
Parents: 632
Message:Bugfixes for the module system
Changes:
M/branches/meklort/i386/boot2/modules.c

File differences

branches/meklort/i386/boot2/modules.c
2222
2323
2424
25
2526
2627
2728
......
3435
3536
3637
38
39
3740
3841
3942
......
171174
172175
173176
177
174178
175
179
176180
177
178
181
182
183
179184
180
185
186
187
188
189
190
181191
182
183
184
185
186
187
188
189
192
193
194
195
196
190197
191
192
193
194
195
196
197
198
199
200
201
202
203198
204
205
206
207
208
209
210
211
212
213
214
215
216
217
199
200
201
202
203
204
205
206
207
208
209
210
211
218212
219213
220214
......
228222
229223
230224
231
232
233
234
225
226
227
228
229
235230
236
237
238
239
240
241
242
231
232
233
234
235
236
237
243238
244239
245240
246241
247
248242
249
243
250244
251245
252246
253247
254
255
256
248
257249
258
259
250
251
252
260253
261254
262255
263256
264257
265
266
267
268
269
270258
271
272
273
274
275259
276
260
277261
278
262
263
264
279265
280266
281267
......
285271
286272
287273
274
275
276
277
278
279
280
281
282
283
288284
289285
290286
......
532528
533529
534530
535
531
536532
537533
538534
......
545541
546542
547543
548
544
545
549546
550547
551548
......
714711
715712
716713
717
714
718715
719716
720717
......
726723
727724
728725
729
726
727
730728
731729
732730
......
985983
986984
987985
988
989986
990
987
991988
992989
993990
......
10441041
10451042
10461043
1047
1044
1045
10481046
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1047
1048
10631049
1064
1065
1066
1067
1068
1069
1050
1051
1052
10701053
10711054
10721055
10731056
1057
10741058
10751059
10761060
unsigned long long textAddress = 0;
unsigned long long textSection = 0;
/** Internal symbols, however there are accessor methods **/
moduleHook_t* moduleCallbacks = NULL;
moduleList_t* loadedModules = NULL;
symbolList_t* moduleSymbols = NULL;
#if DEBUG_MODULES
void print_hook_list()
{
printf("---Hook Table---\n");
moduleHook_t* hooks = moduleCallbacks;
while(hooks)
{
int execute_hook(const char* name, void* arg1, void* arg2, void* arg3, void* arg4)
{
DBG("Attempting to execute hook '%s'\n", name);
moduleHook_t* hooks = moduleCallbacks;
if(moduleCallbacks != NULL)
while(hooks && strcmp(name, hooks->name) < 0)
{
moduleHook_t* hooks = moduleCallbacks;
//DBG("%s cmp %s = %d\n", name, hooks->name, strcmp(name, hooks->name));
hooks = hooks->next;
}
while(hooks != NULL && strcmp(name, hooks->name) != 0) //TOOD: fixme
if(hooks && strcmp(name, hooks->name) == 0)
{
// Loop through all callbacks for this module
callbackList_t* callbacks = hooks->callbacks;
while(callbacks)
{
//DBG("%s cmp %s = %d\n", name, hooks->name, strcmp(name, hooks->name));
hooks = hooks->next;
}
if(strcmp(name, hooks->name) == 0)
{
// Loop through all callbacks for this module
callbackList_t* callbacks = hooks->callbacks;
DBG("Executing '%s' with callback 0x%X.\n", name, callbacks->callback);
// Execute callback
callbacks->callback(arg1, arg2, arg3, arg4);
callbacks = callbacks->next;
DBG("Hook '%s' callback executed, next is 0x%X.\n", name, callbacks);
while(callbacks)
{
DBG("Executing '%s' with callback 0x%X.\n", name, callbacks->callback);
// Execute callback
callbacks->callback(arg1, arg2, arg3, arg4);
callbacks = callbacks->next;
DBG("Hook '%s' callback executed, next is 0x%X.\n", name, callbacks);
}
DBG("Hook '%s' executed.\n", name);
return 1;
}
else
{
DBG("No callbacks for '%s' hook.\n", name);
// Callbaack for this module doesn't exist;
//verbose("Unable execute hook '%s', no callbacks registered.\n", name);
//pause();
return 0;
}
}
DBG("No hooks have been registered.\n", name);
return 0;
DBG("Hook '%s' executed.\n", name);
return 1;
}
else
{
DBG("No callbacks for '%s' hook.\n", name);
// Callbaack for this module doesn't exist;
//verbose("Unable execute hook '%s', no callbacks registered.\n", name);
//pause();
return 0;
}
}
*TODO: refactor
*/
void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*))
{
DBG("Registering %s\n", name);
// Locate Module hook
if(moduleCallbacks == NULL)
{
DBG("Adding callback for '%s' hook.\n", name);
moduleHook_t* newHook = malloc(sizeof(moduleHook_t));
if(!moduleCallbacks)
{
moduleCallbacks = malloc(sizeof(moduleHook_t));
moduleCallbacks->next = NULL;
moduleCallbacks->name = name;
// Initialize hook list
moduleCallbacks->callbacks = (callbackList_t*)malloc(sizeof(callbackList_t));
moduleCallbacks->callbacks->callback = callback;
moduleCallbacks->callbacks->next = NULL;
newHook->next = moduleCallbacks;
moduleCallbacks = newHook;
newHook->name = name;
newHook->callbacks = (callbackList_t*)malloc(sizeof(callbackList_t));
newHook->callbacks->callback = callback;
newHook->callbacks->next = NULL;
}
else
{
moduleHook_t* hooks = moduleCallbacks;
moduleHook_t* newHook = malloc(sizeof(moduleHook_t));;
while(hooks->next != NULL && strcmp(name, hooks->name) < 0)
while(hooks->next && strcmp(name, hooks->next->name) < 0)
{
hooks = hooks->next;
}
DBG("%s cmp %s = %d\n", name, hooks->name, strcmp(name, hooks->name));
if(hooks == NULL)
if(!hooks->next)
{
newHook->next = moduleCallbacks;
moduleCallbacks = newHook;
// Appent to the end
newHook->next = NULL;
hooks->next = newHook;
newHook->name = name;
newHook->callbacks = (callbackList_t*)malloc(sizeof(callbackList_t));
newHook->callbacks->callback = callback;
newHook->callbacks->next = NULL;
}
else if(strcmp(name, hooks->name) != 0)
{
newHook->next = hooks->next;
hooks->next = newHook;
newHook->name = name;
newHook->callbacks = (callbackList_t*)malloc(sizeof(callbackList_t));
newHook->callbacks->callback = callback;
newHook->callbacks->next = NULL;
}
else
else if(strcmp(name, hooks->next->name) == 0)
{
callbackList_t* callbacks = hooks->callbacks;
// We found the hook
// Hook alreday exists, add a callback to this hook
callbackList_t* callbacks = hooks->next->callbacks;
while(callbacks->next != NULL)
{
callbacks = callbacks->next;
callbacks = callbacks->next;
callbacks->next = NULL;
callbacks->callback = callback;
}
else
{
// We are too far beyond the hook
newHook->next = hooks->next;
hooks->next = newHook;
newHook->name = name;
newHook->callbacks = (callbackList_t*)malloc(sizeof(callbackList_t));
newHook->callbacks->callback = callback;
newHook->callbacks->next = NULL;
}
}
UInt8 bits = 0;
int index = 0;
int done = 0;
//int done = 0;
unsigned int i = 0;
while(/*!done &&*/ i < size)
{
case REBASE_OPCODE_DONE:
// Rebase complete.
done = 1;
//done = 1;
default:
break;
UInt32 tmp2 = 0;
UInt32 index = 0;
int done = 0;
//int done = 0;
unsigned int i = 0;
while(/*!done &&*/ i < size)
switch(opcode)
{
case BIND_OPCODE_DONE:
done = 1;
//done = 1;
default:
break;
case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM:
default:
return;
}
*location = (UInt32)newValue;
*location = (UInt32)newValue;
}
*/
void module_loaded(const char* name/*, UInt32 version, UInt32 compat*/)
{
moduleList_t* entry;
// TODO: insert sorted
moduleList_t* new_entry = malloc(sizeof(moduleList_t));
if(loadedModules == NULL)
{
loadedModules = entry = malloc(sizeof(moduleList_t));
}
else
{
entry = loadedModules;
while(entry->next)
{
entry = entry->next;
}
entry->next = malloc(sizeof(moduleList_t));
entry = entry->next;
}
new_entry->next = loadedModules;
loadedModules = new_entry;
entry->next = NULL;
entry->module = (char*)name;
entry->version = 0; //version;
entry->compat = 0; //compat;
new_entry->module = (char*)name;
new_entry->version = 0; //version;
new_entry->compat = 0; //compat;
}
int is_module_loaded(const char* name)
{
// todo sorted search
moduleList_t* entry = loadedModules;
while(entry)
{

Archive Download the corresponding diff file

Revision: 633