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 intenrla␊ |
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 | void Symbols_start()␊ |
16 | {␊ |
17 | }␊ |
18 | ␊ |
19 | unsigned int lookup_symbol(const char* symbol, int(*strcmp)(const char*, const char*))␊ |
20 | {␊ |
21 | ␉int upperLimit = sizeof(symbolList) / sizeof(symbolList[0]) - 1;␉␉␊ |
22 | ␉int lowerLimit = 0;␊ |
23 | ␉int compareIndex = (upperLimit - lowerLimit) >> 1; // Midpoint␊ |
24 | ␉int result;␊ |
25 | ␉␊ |
26 | ␉while((result = strcmp(symbol, symbolList[compareIndex].symbol)) != 0)␊ |
27 | ␉{␊ |
28 | ␉␉if(result > 0)␉// We need to search a HIGHER index␊ |
29 | ␉␉{␊ |
30 | ␉␉␉if(compareIndex != lowerLimit)␊ |
31 | ␉␉␉{␊ |
32 | ␉␉␉␉lowerLimit = compareIndex;␊ |
33 | ␉␉␉}␊ |
34 | ␉␉␉else␊ |
35 | ␉␉␉{␊ |
36 | ␉␉␉␉return 0xFFFFFFFF;␉// Symbol not found␊ |
37 | ␉␉␉}␊ |
38 | ␉␉␉compareIndex = (upperLimit + lowerLimit + 1) >> 1;␉// Midpoint, round up␊ |
39 | ␉␉}␊ |
40 | ␉␉else // We Need to search a LOWER index␊ |
41 | ␉␉{␊ |
42 | ␉␉␉if(compareIndex != upperLimit)␊ |
43 | ␉␉␉{␊ |
44 | ␉␉␉␉upperLimit = compareIndex;␊ |
45 | ␉␉␉}␊ |
46 | ␉␉␉else␊ |
47 | ␉␉␉{␊ |
48 | ␉␉␉␉return 0xFFFFFFFF;␉// Symbol not found␊ |
49 | ␉␉␉}␊ |
50 | ␉␉␉compareIndex = (upperLimit + lowerLimit) >> 1;␉// Midpoint, round down␊ |
51 | ␉␉}␊ |
52 | ␉}␊ |
53 | ␉return symbolList[compareIndex].addr;␊ |
54 | }␊ |
55 | ␊ |
56 | ␊ |
57 | #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))␊ |
58 | ␊ |
59 | long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0};␊ |
60 | ␊ |
61 | static void __guard_setup(void) __attribute__((constructor));␊ |
62 | void __stack_chk_fail(void);␊ |
63 | ␊ |
64 | static void␊ |
65 | __guard_setup(void)␊ |
66 | {␉␊ |
67 | ␉/* Here the protector switches the guard␊ |
68 | to the "terminator canary", and cannot report failure */␊ |
69 | ␉((char*)__stack_chk_guard)[0] = 0; ((char*)__stack_chk_guard)[1] = 0;␊ |
70 | ␉((char*)__stack_chk_guard)[2] = '\n'; ((char*)__stack_chk_guard)[3] = 255;␉␊ |
71 | ␊ |
72 | }␊ |
73 | ␊ |
74 | void␊ |
75 | __stack_chk_fail()␊ |
76 | {␊ |
77 | for(;;);␊ |
78 | } |