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