1109905Smarkm/* LINTLIBRARY */ 234198Sjdp/*- 334198Sjdp * Copyright 1996-1998 John D. Polstra. 434198Sjdp * All rights reserved. 534198Sjdp * 634198Sjdp * Redistribution and use in source and binary forms, with or without 734198Sjdp * modification, are permitted provided that the following conditions 834198Sjdp * are met: 934198Sjdp * 1. Redistributions of source code must retain the above copyright 1034198Sjdp * notice, this list of conditions and the following disclaimer. 1134198Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1234198Sjdp * notice, this list of conditions and the following disclaimer in the 1334198Sjdp * documentation and/or other materials provided with the distribution. 1434198Sjdp * 1534198Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1634198Sjdp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1734198Sjdp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1834198Sjdp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1934198Sjdp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2034198Sjdp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2134198Sjdp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2234198Sjdp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2334198Sjdp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2434198Sjdp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2534198Sjdp */ 2634198Sjdp 27216338Sdim#include <sys/cdefs.h> 28216338Sdim__FBSDID("$FreeBSD$"); 29216338Sdim 30100167Smarkm#ifndef lint 3134198Sjdp#ifndef __GNUC__ 3234198Sjdp#error "GCC is needed to compile this file" 3334198Sjdp#endif 34100167Smarkm#endif /* lint */ 3534198Sjdp 3634198Sjdp#include <stdlib.h> 3799354Smarkm 3893399Smarkm#include "libc_private.h" 3967811Sobrien#include "crtbrand.c" 4034198Sjdp 41100167Smarkmextern int _DYNAMIC; 42100167Smarkm#pragma weak _DYNAMIC 43100167Smarkm 4434198Sjdptypedef void (*fptr)(void); 4534198Sjdp 4634198Sjdpextern void _fini(void); 4734198Sjdpextern void _init(void); 4834198Sjdpextern int main(int, char **, char **); 4934198Sjdp 5038928Sjdp#ifdef GCRT 5138928Sjdpextern void _mcleanup(void); 5238928Sjdpextern void monstartup(void *, void *); 5338928Sjdpextern int eprol; 5438928Sjdpextern int etext; 5538928Sjdp#endif 5638928Sjdp 57100167Smarkmchar **environ; 58100167Smarkmconst char *__progname = ""; 5934198Sjdp 60204756Suqsvoid _start(char **, void (*)(void)); 61204756Suqs 62100167Smarkm/* The entry function. */ 6334198Sjdpvoid 64114319Speter_start(char **ap, void (*cleanup)(void)) 6534198Sjdp{ 6699354Smarkm int argc; 6799354Smarkm char **argv; 6899354Smarkm char **env; 6999354Smarkm const char *s; 7034198Sjdp 71114319Speter argc = *(long *)(void *)ap; 72114319Speter argv = ap + 1; 73114319Speter env = ap + 2 + argc; 74245777Skib if (environ == NULL) 75245777Skib environ = env; 7699354Smarkm if (argc > 0 && argv[0] != NULL) { 7799354Smarkm __progname = argv[0]; 7899354Smarkm for (s = __progname; *s != '\0'; s++) 7999354Smarkm if (*s == '/') 8099354Smarkm __progname = s + 1; 8199354Smarkm } 8234198Sjdp 8399354Smarkm if (&_DYNAMIC != NULL) 84100167Smarkm atexit(cleanup); 85133754Sdfr else 86133754Sdfr _init_tls(); 8734198Sjdp 8838928Sjdp#ifdef GCRT 8999354Smarkm atexit(_mcleanup); 9038928Sjdp#endif 9199354Smarkm atexit(_fini); 9238928Sjdp#ifdef GCRT 9399354Smarkm monstartup(&eprol, &etext); 94151072Sbde__asm__("eprol:"); 9538928Sjdp#endif 9699354Smarkm _init(); 9799354Smarkm exit( main(argc, argv, env) ); 9834198Sjdp} 99