1 | /*␊ |
2 | * Symbols.c␊ |
3 | * ␊ |
4 | * Module loader support module. This module is the first module to ever be loaded.␊ |
5 | * It contains a copy of each symbol inside ov the current version of chameleon as well ␊ |
6 | * as a strcmp function. Chameleon calls lookup_symbol to resolve internal symbols␊ |
7 | * when they are requested by a module. This module does *not* depend on any internal␊ |
8 | * symbols, as such it can be loaded without a symbol table initialized.␊ |
9 | *␊ |
10 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
11 | */␊ |
12 | ␊ |
13 | #include "Symbols.h"␊ |
14 | ␊ |
15 | static int strcmp(const char * s1, const char * s2);␊ |
16 | ␊ |
17 | void Symbols_start()␊ |
18 | {␊ |
19 | ␉// load_dependency("Symbols", 300);␊ |
20 | ␉//verbose("Symbols_start\n");␊ |
21 | }␊ |
22 | ␊ |
23 | unsigned int lookup_symbol(const char* symbol)␊ |
24 | {␊ |
25 | ␉if(strcmp(symbol, "dyld_stub_binder") == 0) return lookup_symbol("_dyld_stub_binder");␉// ugly hack␊ |
26 | ␉ ␊ |
27 | ␉int upperLimit = sizeof(symbolList) / sizeof(symbolList[0]) - 1;␉␉␊ |
28 | ␉int lowerLimit = 0;␊ |
29 | ␉int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint␊ |
30 | ␉int result;␊ |
31 | ␉␊ |
32 | ␉while((result = strcmp(symbol, symbolList[compareIndex].symbol)) != 0)␊ |
33 | ␉{␊ |
34 | ␉␉if(result > 0)␉// We need to search a HIGHER index␊ |
35 | ␉␉{␊ |
36 | ␉␉␉if(compareIndex != lowerLimit)␊ |
37 | ␉␉␉{␊ |
38 | ␉␉␉␉lowerLimit = compareIndex;␊ |
39 | ␉␉␉}␊ |
40 | ␉␉␉else␊ |
41 | ␉␉␉{␊ |
42 | ␉␉␉␉return 0xFFFFFFFF;␉// Symbol not found␊ |
43 | ␉␉␉}␊ |
44 | ␉␉␉compareIndex = (upperLimit + lowerLimit + 1) >> 1;␉// Midpoint, round up␊ |
45 | ␉␉}␊ |
46 | ␉␉else // We Need to search a LOWER index␊ |
47 | ␉␉{␊ |
48 | ␉␉␉if(compareIndex != upperLimit)␊ |
49 | ␉␉␉{␊ |
50 | ␉␉␉␉upperLimit = compareIndex;␊ |
51 | ␉␉␉}␊ |
52 | ␉␉␉else␊ |
53 | ␉␉␉{␊ |
54 | ␉␉␉␉return 0xFFFFFFFF;␉// Symbol not found␊ |
55 | ␉␉␉}␊ |
56 | ␉␉␉compareIndex = (upperLimit + lowerLimit) >> 1;␉// Midpoint, round down␊ |
57 | ␉␉}␊ |
58 | ␉}␊ |
59 | ␉return symbolList[compareIndex].addr;␊ |
60 | }␊ |
61 | ␊ |
62 | /*␊ |
63 | * strcmp - Copied from libsa/string.c due to symbols not able to be resolved at this point␊ |
64 | */␊ |
65 | static int strcmp(const char * s1, const char * s2)␊ |
66 | {␊ |
67 | ␉while (*s1 && (*s1 == *s2)) {␊ |
68 | ␉␉s1++;␊ |
69 | ␉␉s2++;␊ |
70 | ␉}␊ |
71 | ␉return (*s1 - *s2);␊ |
72 | }␊ |
73 | ␊ |
74 | ␊ |
75 | ␊ |
76 | |