]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/crt-vars-libSystem.dtest/main.c
dyld-750.5.tar.gz
[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 #include "test_support.h"
13
14 // This struct is passed as fifth parameter to libSystem.dylib's initializer so it record
15 // the address of crt global variables.
16 struct ProgramVars
17 {
18 const void* mh;
19 int* NXArgcPtr;
20 char*** NXArgvPtr;
21 char*** environPtr;
22 char** __prognamePtr;
23 };
24
25
26 // global variables defeined in crt1.o
27 extern char** NXArgv;
28 extern int NXArgc;
29 extern char** environ;
30 extern char* __progname;
31
32
33 static const struct ProgramVars* sVars;
34
35 void __attribute__((constructor))
36 myInit(int argc, const char* argv[], const char* envp[], const char* apple[], const struct ProgramVars* vars)
37 {
38 sVars = vars;
39 }
40
41 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
42 if ( _NSGetArgv() != &NXArgv ) {
43 FAIL("_NSGetArgv() != &NXArgv (%p!=%p) for %s", _NSGetArgv(), &NXArgv, argv[0]);
44 }
45
46 if ( _NSGetArgc() != &NXArgc ) {
47 FAIL("_NSGetArgc() != &NXArgc (%p!=%p) for %s", _NSGetArgc(), &NXArgc, argv[0]);
48 }
49
50 if ( _NSGetEnviron() != &environ ) {
51 FAIL("_NSGetEnviron() != &environv (%p!=%p) for %s", _NSGetEnviron(), &environ, argv[0]);
52 }
53
54 if ( _NSGetProgname() != &__progname ) {
55 FAIL("_NSGetProgname() != &__progname (%p!=%p) for %s", _NSGetProgname(), &__progname, argv[0]);
56 }
57
58 if ( _NSGetMachExecuteHeader() != &_mh_execute_header ) {
59 FAIL("_NSGetMachExecuteHeader() != &_mh_execute_headerv (%p!=%p) for %s", _NSGetMachExecuteHeader(), &_mh_execute_header, argv[0]);
60 }
61
62 if ( sVars->NXArgvPtr != &NXArgv ) {
63 FAIL("sVars->NXArgvPtr != &NXArg (%p!=%p) for %s", sVars->NXArgvPtr, &NXArgv, argv[0]);
64 }
65
66 if ( sVars->NXArgcPtr != &NXArgc ) {
67 FAIL("sVars->NXArgcPtr != &NXArgc (%p!=%p) for %s", sVars->NXArgcPtr, &NXArgc, argv[0]);
68 }
69
70 if ( sVars->environPtr != &environ ) {
71 FAIL("sVars->environPtr != &environ (%p!=%p) for %s", sVars->environPtr, &environ, argv[0]);
72 }
73
74 if ( sVars->__prognamePtr != &__progname ) {
75 FAIL("sVars->__prognamePtr != &__progname (%p!=%p) for %s", sVars->__prognamePtr, &__progname, argv[0]);
76 }
77
78 if ( sVars->mh != &_mh_execute_header ) {
79 FAIL("sVars->mh != &_mh_execute_header (%p!=%p) for %s", sVars->mh, &_mh_execute_header, argv[0]);
80 }
81 PASS("Success");
82 }
83