Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/util/Symbols.c

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

Archive Download this file

Revision: 1804