]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/crt-vars-libSystem.dtest/main.c
6eb9381136631829a261c25b3d1870334075d610
2 // BUILD: $CC main.c -o $BUILD_DIR/crt-vars-libSystem.exe
4 // RUN: ./crt-vars-libSystem.exe
9 #include <crt_externs.h>
10 #include <mach-o/ldsyms.h>
12 // This struct is passed as fifth parameter to libSystem.dylib's initializer so it record
13 // the address of crt global variables.
24 // global variables defeined in crt1.o
27 extern char** environ
;
28 extern char* __progname
;
31 static const struct ProgramVars
* sVars
;
33 void __attribute__((constructor
))
34 myInit(int argc
, const char* argv
[], const char* envp
[], const char* apple
[], const struct ProgramVars
* vars
)
40 int main(int argc
, const char* argv
[])
42 printf("[BEGIN] crt-vars-libSystem\n");
45 if ( _NSGetArgv() != &NXArgv
) {
46 printf("[FAIL] crt-libSystem: _NSGetArgv() != &NXArgv (%p!=%p) for %s", _NSGetArgv(), &NXArgv
, argv
[0]);
50 if ( _NSGetArgc() != &NXArgc
) {
51 printf("[FAIL] crt-libSystem: _NSGetArgc() != &NXArgc (%p!=%p) for %s", _NSGetArgc(), &NXArgc
, argv
[0]);
55 if ( _NSGetEnviron() != &environ
) {
56 printf("[FAIL] crt-libSystem: _NSGetEnviron() != &environv (%p!=%p) for %s", _NSGetEnviron(), &environ
, argv
[0]);
60 if ( _NSGetProgname() != &__progname
) {
61 printf("[FAIL] crt-libSystem: _NSGetProgname() != &__progname (%p!=%p) for %s", _NSGetProgname(), &__progname
, argv
[0]);
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]);
70 if ( sVars
->NXArgvPtr
!= &NXArgv
) {
71 printf("[FAIL] crt-libSystem: sVars->NXArgvPtr != &NXArg (%p!=%p) for %s", sVars
->NXArgvPtr
, &NXArgv
, argv
[0]);
75 if ( sVars
->NXArgcPtr
!= &NXArgc
) {
76 printf("[FAIL] crt-libSystem: sVars->NXArgcPtr != &NXArgc (%p!=%p) for %s", sVars
->NXArgcPtr
, &NXArgc
, argv
[0]);
80 if ( sVars
->environPtr
!= &environ
) {
81 printf("[FAIL] crt-libSystem: sVars->environPtr != &environ (%p!=%p) for %s", sVars
->environPtr
, &environ
, argv
[0]);
85 if ( sVars
->__prognamePtr
!= &__progname
) {
86 printf("[FAIL] crt-libSystem: sVars->__prognamePtr != &__progname (%p!=%p) for %s", sVars
->__prognamePtr
, &__progname
, argv
[0]);
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]);
96 printf("[PASS] crt-vars-libSystem\n");