Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / lib / csu / common_aout / common.h
blob2c496adcd324d93668994abae3eff98f1f666bc1
1 /* $NetBSD: common.h,v 1.14 2005/12/24 22:53:15 perry Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <string.h>
34 #ifdef DYNAMIC
36 #include <sys/syscall.h>
37 #include <a.out.h>
38 #ifndef N_GETMAGIC
39 #define N_GETMAGIC(x) ((x).a_magic)
40 #endif
41 #ifndef N_BSSADDR
42 #define N_BSSADDR(x) (N_DATADDR(x)+(x).a_data)
43 #endif
45 #include <sys/mman.h>
46 #ifdef sun
47 #define MAP_ANON 0
48 #endif
50 #include <dlfcn.h>
51 #include <link.h>
53 extern struct _dynamic _DYNAMIC;
54 static void __load_rtld __P((struct _dynamic *));
55 extern int __syscall __P((int, ...));
56 int _callmain __P((void));
57 static char *_strrchr __P((char *, char));
58 #ifdef DEBUG
59 static char *_getenv __P((char *));
60 static int _strncmp __P((char *, char *, int));
61 #endif
63 #ifdef sun
64 #define LDSO "/usr/lib/ld.so"
65 #endif
66 #ifdef __NetBSD__
67 #ifndef LDSO
68 #define LDSO "/usr/libexec/ld.so"
69 #endif
70 #endif
73 * We need these system calls, but can't use library stubs
75 #define _exit(v) __syscall(SYS_exit, (v))
76 #define open(name, f, m) __syscall(SYS_open, (name), (f), (m))
77 #define close(fd) __syscall(SYS_close, (fd))
78 #define read(fd, s, n) __syscall(SYS_read, (fd), (s), (n))
79 #define write(fd, s, n) __syscall(SYS_write, (fd), (s), (n))
80 #define dup(fd) __syscall(SYS_dup, (fd))
81 #define dup2(fd, fdnew) __syscall(SYS_dup2, (fd), (fdnew))
82 #ifdef sun
83 #define mmap(addr, len, prot, flags, fd, off) \
84 __syscall(SYS_mmap, (addr), (len), (prot), _MAP_NEW|(flags), (fd), (off))
85 #else
86 #define mmap(addr, len, prot, flags, fd, off) \
87 __syscall(SYS___syscall, (quad_t)SYS_mmap, (addr), (len), (prot), (flags), \
88 (fd), 0, (off_t)(off))
89 #endif
91 #define _FATAL(str) \
92 write(2, str, sizeof(str) - 1), \
93 _exit(1);
95 #endif /* DYNAMIC */
97 extern int main __P((int, char **, char **));
98 #ifdef MCRT0
99 extern void monstartup __P((u_long, u_long));
100 extern void _mcleanup __P((void));
101 #endif
103 char **environ;
104 int errno;
105 static char empty[1];
106 char *__progname = empty;
107 struct ps_strings;
108 struct ps_strings *__ps_strings = 0;
109 #ifndef DYNAMIC
110 #define _strrchr strrchr
111 #endif
113 extern unsigned char etext;
114 extern unsigned char eprol __asm ("eprol");