1/* 2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23#include <stdio.h> // fprintf(), NULL 24#include <stdlib.h> // exit(), EXIT_SUCCESS 25#include <stdbool.h> 26#include <string.h> 27#include <crt_externs.h> 28#include <mach-o/ldsyms.h> 29#include "test.h" // PASS(), FAIL(), XPASS(), XFAIL() 30 31struct ProgramVars 32{ 33 const void* mh; 34 int* NXArgcPtr; 35 char*** NXArgvPtr; 36 char*** environPtr; 37 char** __prognamePtr; 38}; 39static const struct ProgramVars* sVars; 40 41// global variables defeined in crt1.o 42extern char** NXArgv; 43extern int NXArgc; 44extern char** environ; 45extern char* __progname; 46 47 48int 49main(int argc, const char* argv[]) 50{ 51 bool success = true; 52 53 if ( _NSGetArgv() != &NXArgv ) { 54 FAIL("crt-libSystem _NSGetArgv() != &NXArgv (%p!=%p) for %s", _NSGetArgv(), &NXArgv, argv[0]); 55 success = false; 56 } 57 58 if ( _NSGetArgc() != &NXArgc ) { 59 FAIL("crt-libSystem _NSGetArgc() != &NXArgc (%p!=%p) for %s", _NSGetArgc(), &NXArgc, argv[0]); 60 success = false; 61 } 62 63 if ( _NSGetEnviron() != &environ ) { 64 FAIL("crt-libSystem _NSGetEnviron() != &environv (%p!=%p) for %s", _NSGetEnviron(), &environ, argv[0]); 65 success = false; 66 } 67 68 if ( _NSGetProgname() != &__progname ) { 69 FAIL("crt-libSystem _NSGetProgname() != &__progname (%p!=%p) for %s", _NSGetProgname(), &__progname, argv[0]); 70 success = false; 71 } 72 73 if ( _NSGetMachExecuteHeader() != &_mh_execute_header ) { 74 FAIL("crt-libSystem _NSGetMachExecuteHeader() != &_mh_execute_headerv (%p!=%p) for %s", _NSGetMachExecuteHeader(), &_mh_execute_header, argv[0]); 75 success = false; 76 } 77 78 if ( sVars->NXArgvPtr != &NXArgv ) { 79 FAIL("crt-libSystem sVars->NXArgvPtr != &NXArg (%p!=%p) for %s", sVars->NXArgvPtr, &NXArgv, argv[0]); 80 success = false; 81 } 82 83 if ( sVars->NXArgcPtr != &NXArgc ) { 84 FAIL("crt-libSystem sVars->NXArgcPtr != &NXArgc (%p!=%p) for %s", sVars->NXArgcPtr, &NXArgc, argv[0]); 85 success = false; 86 } 87 88 if ( sVars->environPtr != &environ ) { 89 FAIL("crt-libSystem sVars->environPtr != &environ (%p!=%p) for %s", sVars->environPtr, &environ, argv[0]); 90 success = false; 91 } 92 93 if ( sVars->__prognamePtr != &__progname ) { 94 FAIL("crt-libSystem sVars->__prognamePtr != &__progname (%p!=%p) for %s", sVars->__prognamePtr, &__progname, argv[0]); 95 success = false; 96 } 97 98 if ( sVars->mh != &_mh_execute_header ) { 99 FAIL("crt-libSystem sVars->mh != &_mh_execute_header (%p!=%p) for %s", sVars->mh, &_mh_execute_header, argv[0]); 100 success = false; 101 } 102 103 if ( success ) 104 PASS("crt-libSystem"); 105 106 return EXIT_SUCCESS; 107} 108 109 110 111void __attribute__((constructor)) 112myInit(int argc, const char* argv[], const char* envp[], const char* apple[], const struct ProgramVars* vars) 113{ 114 sVars = vars; 115} 116 117 118 119 120 121