]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/kernel-pageablekc-fixups.dtest/foo.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / kernel-pageablekc-fixups.dtest / foo.c
1
2 #include "../kernel-test-runner.h"
3
4 extern int bar();
5 __typeof(&bar) barPtr = &bar;
6
7 int foo() {
8 return barPtr() + 4;
9 }
10
11 __attribute__((constructor))
12 int test(const TestRunnerFunctions* funcs) {
13 LOG("test(): start");
14 // kernel, bar, and foo each added 1, 2, 4, so we need to return 7 to know this worked
15 int v = foo();
16 if ( v != 7 ) {
17 FAIL("foo() returned %d vs expected 7", v);
18 }
19 LOG("test(): end");
20 return 0;
21 }
22
23 int fooDirect() {
24 return bar() + 4;
25 }
26
27 // Test direct pointer fixups, ie, not via a GOT
28 __attribute__((constructor))
29 int testDirect(const TestRunnerFunctions* funcs) {
30 LOG("testDirect(): start");
31 // kernel, bar, and foo each added 1, 2, 4, so we need to return 7 to know this worked
32 int v = fooDirect();
33 if ( v != 7 ) {
34 FAIL("fooDirect() returned %d vs expected 7", v);
35 }
36 LOG("testDirect(): end");
37 return 0;
38 }