]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/crt-vars-libSystem.dtest/main.c
6eb9381136631829a261c25b3d1870334075d610
[apple/dyld.git] / testing / test-cases / crt-vars-libSystem.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/crt-vars-libSystem.exe
3
4 // RUN: ./crt-vars-libSystem.exe
5
6 #include <stdio.h>
7 #include <dlfcn.h>
8 #include <string.h>
9 #include <crt_externs.h>
10 #include <mach-o/ldsyms.h>
11
12 // This struct is passed as fifth parameter to libSystem.dylib's initializer so it record
13 // the address of crt global variables.
14 struct ProgramVars
15 {
16 const void* mh;
17 int* NXArgcPtr;
18 char*** NXArgvPtr;
19 char*** environPtr;
20 char** __prognamePtr;
21 };
22
23
24 // global variables defeined in crt1.o
25 extern char** NXArgv;
26 extern int NXArgc;
27 extern char** environ;
28 extern char* __progname;
29
30
31 static const struct ProgramVars* sVars;
32
33 void __attribute__((constructor))
34 myInit(int argc, const char* argv[], const char* envp[], const char* apple[], const struct ProgramVars* vars)
35 {
36 sVars = vars;
37 }
38
39
40 int main(int argc, const char* argv[])
41 {
42 printf("[BEGIN] crt-vars-libSystem\n");
43 bool success = true;
44
45 if ( _NSGetArgv() != &NXArgv ) {
46 printf("[FAIL] crt-libSystem: _NSGetArgv() != &NXArgv (%p!=%p) for %s", _NSGetArgv(), &NXArgv, argv[0]);
47 success = false;
48 }
49
50 if ( _NSGetArgc() != &NXArgc ) {
51 printf("[FAIL] crt-libSystem: _NSGetArgc() != &NXArgc (%p!=%p) for %s", _NSGetArgc(), &NXArgc, argv[0]);
52 success = false;
53 }
54
55 if ( _NSGetEnviron() != &environ ) {
56 printf("[FAIL] crt-libSystem: _NSGetEnviron() != &environv (%p!=%p) for %s", _NSGetEnviron(), &environ, argv[0]);
57 success = false;
58 }
59
60 if ( _NSGetProgname() != &__progname ) {
61 printf("[FAIL] crt-libSystem: _NSGetProgname() != &__progname (%p!=%p) for %s", _NSGetProgname(), &__progname, argv[0]);
62 success = false;
63 }
64
65 if ( _NSGetMachExecuteHeader() != &_mh_execute_header ) {
66 printf("[FAIL] crt-libSystem: _NSGetMachExecuteHeader() != &_mh_execute_headerv (%p!=%p) for %s", _NSGetMachExecuteHeader(), &_mh_execute_header, argv[0]);
67 success = false;
68 }
69
70 if ( sVars->NXArgvPtr != &NXArgv ) {
71 printf("[FAIL] crt-libSystem: sVars->NXArgvPtr != &NXArg (%p!=%p) for %s", sVars->NXArgvPtr, &NXArgv, argv[0]);
72 success = false;
73 }
74
75 if ( sVars->NXArgcPtr != &NXArgc ) {
76 printf("[FAIL] crt-libSystem: sVars->NXArgcPtr != &NXArgc (%p!=%p) for %s", sVars->NXArgcPtr, &NXArgc, argv[0]);
77 success = false;
78 }
79
80 if ( sVars->environPtr != &environ ) {
81 printf("[FAIL] crt-libSystem: sVars->environPtr != &environ (%p!=%p) for %s", sVars->environPtr, &environ, argv[0]);
82 success = false;
83 }
84
85 if ( sVars->__prognamePtr != &__progname ) {
86 printf("[FAIL] crt-libSystem: sVars->__prognamePtr != &__progname (%p!=%p) for %s", sVars->__prognamePtr, &__progname, argv[0]);
87 success = false;
88 }
89
90 if ( sVars->mh != &_mh_execute_header ) {
91 printf("[FAIL] crt-libSystem: sVars->mh != &_mh_execute_header (%p!=%p) for %s", sVars->mh, &_mh_execute_header, argv[0]);
92 success = false;
93 }
94
95 if ( success )
96 printf("[PASS] crt-vars-libSystem\n");
97
98 return 0;
99 }
100