1998-07-24 22:48:14 +04:00
|
|
|
/* $NetBSD: common.h,v 1.7 1998/07/24 18:48:14 veego Exp $ */
|
1996-10-18 09:36:42 +04:00
|
|
|
|
1995-06-03 17:16:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1993,1995 Paul Kranenburg
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Paul Kranenburg.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1995-06-05 04:13:05 +04:00
|
|
|
#include <string.h>
|
1995-06-03 17:16:03 +04:00
|
|
|
|
|
|
|
#ifdef DYNAMIC
|
1995-06-05 04:13:05 +04:00
|
|
|
|
1995-06-03 17:16:03 +04:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <a.out.h>
|
|
|
|
#ifndef N_GETMAGIC
|
|
|
|
#define N_GETMAGIC(x) ((x).a_magic)
|
|
|
|
#endif
|
|
|
|
#ifndef N_BSSADDR
|
|
|
|
#define N_BSSADDR(x) (N_DATADDR(x)+(x).a_data)
|
|
|
|
#endif
|
1995-06-05 04:13:05 +04:00
|
|
|
|
1995-06-03 17:16:03 +04:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#ifdef sun
|
|
|
|
#define MAP_COPY MAP_PRIVATE
|
|
|
|
#define MAP_ANON 0
|
|
|
|
#endif
|
1995-06-05 04:13:05 +04:00
|
|
|
|
|
|
|
#include <dlfcn.h>
|
1998-05-13 01:25:18 +04:00
|
|
|
#include <link.h>
|
1995-06-03 17:16:03 +04:00
|
|
|
|
|
|
|
extern struct _dynamic _DYNAMIC;
|
|
|
|
static void __load_rtld __P((struct _dynamic *));
|
1998-07-24 22:48:14 +04:00
|
|
|
extern quad_t __syscall __P((quad_t, ...));
|
1995-06-16 01:41:41 +04:00
|
|
|
int _callmain __P((void));
|
|
|
|
static char *_strrchr __P((char *, char));
|
1995-06-03 17:16:03 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
static char *_getenv __P((char *));
|
|
|
|
static int _strncmp __P((char *, char *, int));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef sun
|
|
|
|
#define LDSO "/usr/lib/ld.so"
|
|
|
|
#endif
|
|
|
|
#ifdef BSD
|
|
|
|
#define LDSO "/usr/libexec/ld.so"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need these system calls, but can't use library stubs
|
|
|
|
*/
|
|
|
|
#define _exit(v) __syscall(SYS_exit, (v))
|
|
|
|
#define open(name, f, m) __syscall(SYS_open, (name), (f), (m))
|
|
|
|
#define close(fd) __syscall(SYS_close, (fd))
|
|
|
|
#define read(fd, s, n) __syscall(SYS_read, (fd), (s), (n))
|
|
|
|
#define write(fd, s, n) __syscall(SYS_write, (fd), (s), (n))
|
|
|
|
#define dup(fd) __syscall(SYS_dup, (fd))
|
|
|
|
#define dup2(fd, fdnew) __syscall(SYS_dup2, (fd), (fdnew))
|
|
|
|
#ifdef sun
|
|
|
|
#define mmap(addr, len, prot, flags, fd, off) \
|
|
|
|
__syscall(SYS_mmap, (addr), (len), (prot), _MAP_NEW|(flags), (fd), (off))
|
|
|
|
#else
|
|
|
|
#define mmap(addr, len, prot, flags, fd, off) \
|
|
|
|
__syscall(SYS___syscall, (quad_t)SYS_mmap, (addr), (len), (prot), (flags), \
|
|
|
|
(fd), 0, (off_t)(off))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _FATAL(str) \
|
|
|
|
write(2, str, sizeof(str)), \
|
|
|
|
_exit(1);
|
|
|
|
|
|
|
|
#endif /* DYNAMIC */
|
1995-06-05 04:13:05 +04:00
|
|
|
|
|
|
|
extern int main __P((int, char **, char **));
|
|
|
|
#ifdef MCRT0
|
|
|
|
extern void monstartup __P((u_long, u_long));
|
|
|
|
extern void _mcleanup __P((void));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char **environ;
|
|
|
|
int errno;
|
|
|
|
static char empty[1];
|
|
|
|
char *__progname = empty;
|
1996-12-08 01:31:25 +03:00
|
|
|
struct ps_strings;
|
|
|
|
struct ps_strings *__ps_strings = 0;
|
1995-06-16 01:41:41 +04:00
|
|
|
#ifndef DYNAMIC
|
|
|
|
#define _strrchr strrchr
|
|
|
|
#endif
|
1995-06-05 04:13:05 +04:00
|
|
|
|
|
|
|
extern unsigned char etext;
|
|
|
|
extern unsigned char eprol asm ("eprol");
|
|
|
|
|