Blame view

trunk/research/st/md.h 6.2 KB
winlin authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/* 
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 * 
 * The Original Code is the Netscape Portable Runtime library.
 * 
 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are 
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 * Rights Reserved.
 * 
 * Contributor(s):  Silicon Graphics, Inc.
 * 
 * Portions created by SGI are Copyright (C) 2000-2001 Silicon
 * Graphics, Inc.  All Rights Reserved.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL"), in which case the provisions of the GPL are applicable 
 * instead of those above.  If you wish to allow use of your 
 * version of this file only under the terms of the GPL and not to
 * allow others to use your version of this file under the MPL,
 * indicate your decision by deleting the provisions above and
 * replace them with the notice and other provisions required by
 * the GPL.  If you do not delete the provisions above, a recipient
 * may use your version of this file under either the MPL or the
 * GPL.
 */

/*
 * This file is derived directly from Netscape Communications Corporation,
 * and consists of extensive modifications made during the year(s) 1999-2000.
 */

#ifndef __ST_MD_H__
#define __ST_MD_H__

#if defined(ETIMEDOUT) && !defined(ETIME)
46
    #define ETIME ETIMEDOUT
winlin authored
47 48 49
#endif

#if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
50
    #define MAP_ANON MAP_ANONYMOUS
winlin authored
51 52 53
#endif

#ifndef MAP_FAILED
54
    #define MAP_FAILED -1
winlin authored
55 56 57 58 59
#endif

/*****************************************
 * Platform specifics
 */
60 61 62 63
#if defined (LINUX)
    /* linux ok, defined bellow */
#elif defined (AIX)
    #error "AIX not supported"
winlin authored
64
#elif defined (CYGWIN)
65
    #error "CYGWIN not supported"
winlin authored
66
#elif defined (DARWIN)
67 68 69 70 71 72 73 74
    #error "DARWIN not supported"
#elif defined (FREEBSD)
    #error "FREEBSD not supported"
#elif defined (HPUX)
    #error "HPUX not supported"
#elif defined (IRIX)
    #error "IRIX not supported"
#elif defined (NETBSD)
75
    #error "NETBSD not supported"
76
#elif defined (OPENBSD)
77
    #error "OPENBSD not supported"
78
#elif defined (OSF1)
79
    #error "OSF1 not supported"
80
#elif defined (SOLARIS)
81
    #error "SOLARIS not supported"
82 83 84
#else
    #error "Unknown OS"
#endif /* OS */
winlin authored
85
86 87 88 89 90 91 92 93 94 95 96 97
/* linux only, defined bellow */
/*
 * These are properties of the linux kernel and are the same on every
 * flavor and architecture.
 */
#define MD_USE_BSD_ANON_MMAP
#define MD_ACCEPT_NB_NOT_INHERITED
#define MD_ALWAYS_UNSERIALIZED_ACCEPT
/*
 * Modern GNU/Linux is Posix.1g compliant.
 */
#define MD_HAVE_SOCKLEN_T
winlin authored
98
99 100 101 102 103 104 105 106
/*
 * All architectures and flavors of linux have the gettimeofday
 * function but if you know of a faster way, use it.
 */
#define MD_GET_UTIME()            \
    struct timeval tv;              \
    (void) gettimeofday(&tv, NULL); \
    return (tv.tv_sec * 1000000LL + tv.tv_usec)
winlin authored
107
108
#if defined(__mips__)
winlin authored
109
    #define MD_STACK_GROWS_DOWN
110
#else /* Not or mips */
winlin authored
111
    /*
112 113 114 115 116
     * On linux, there are a few styles of jmpbuf format.  These vary based
     * on architecture/glibc combination.
     *
     * Most of the glibc based toggles were lifted from:
     * mozilla/nsprpub/pr/include/md/_linux.h
winlin authored
117 118
     */
    /*
119 120 121 122 123 124 125 126 127
     * Starting with glibc 2.4, JB_SP definitions are not public anymore.
     * They, however, can still be found in glibc source tree in
     * architecture-specific "jmpbuf-offsets.h" files.
     * Most importantly, the content of jmp_buf is mangled by setjmp to make
     * it completely opaque (the mangling can be disabled by setting the
     * LD_POINTER_GUARD environment variable before application execution).
     * Therefore we will use built-in _st_md_cxt_save/_st_md_cxt_restore
     * functions as a setjmp/longjmp replacement wherever they are available
     * unless USE_LIBC_SETJMP is defined.
winlin authored
128
     */
129
    #if defined(__i386__)
130 131
        #define MD_STACK_GROWS_DOWN
        #define MD_USE_BUILTIN_SETJMP
winlin authored
132
        
133 134 135
        #if defined(__GLIBC__) && __GLIBC__ >= 2
            #ifndef JB_SP
                #define JB_SP 4
winlin authored
136
            #endif
137 138 139 140
            #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_SP]
        #else
            /* not an error but certainly cause for caution */
            #error "Untested use of old glibc on i386"
winlin authored
141
            #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[0].__sp
142 143 144 145
        #endif
    #elif defined(__amd64__) || defined(__x86_64__)
        #define MD_STACK_GROWS_DOWN
        #define MD_USE_BUILTIN_SETJMP
winlin authored
146
        
147 148 149 150 151 152 153 154 155
        #ifndef JB_RSP
            #define JB_RSP 6
        #endif
        #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]
    #elif defined(__arm__)
        #define MD_STACK_GROWS_DOWN
        
        #if defined(__GLIBC__) && __GLIBC__ >= 2
            #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8]
winlin authored
156
        #else
157 158
            #error "ARM/Linux pre-glibc2 not supported yet"
        #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
winlin authored
159
    #else
160 161 162
        #error "Unknown CPU architecture"
    #endif /* Cases with common MD_INIT_CONTEXT and different SP locations */
#endif /* Cases with different MD_INIT_CONTEXT */
winlin authored
163
164
#if defined(MD_USE_BUILTIN_SETJMP) && !defined(USE_LIBC_SETJMP)
165
    /* i386/x86_64 */
166 167
    #define MD_SETJMP(env) _st_md_cxt_save(env)
    #define MD_LONGJMP(env, val) _st_md_cxt_restore(env, val)
winlin authored
168
    
169 170 171
    extern int _st_md_cxt_save(jmp_buf env);
    extern void _st_md_cxt_restore(jmp_buf env, int val);
#else
172
    /* arm/mips */
winlin authored
173 174
    #define MD_SETJMP(env) setjmp(env)
    #define MD_LONGJMP(env, val) longjmp(env, val)
175
#endif
winlin authored
176
winlin authored
177 178 179
/*****************************************
 * Other defines
 */
winlin authored
180
#ifndef MD_STACK_PAD_SIZE
winlin authored
181
    #define MD_STACK_PAD_SIZE 128
winlin authored
182 183 184
#endif

#if !defined(MD_HAVE_SOCKLEN_T) && !defined(socklen_t)
winlin authored
185
    #define socklen_t int
winlin authored
186 187 188
#endif

#ifndef MD_CAP_STACK
winlin authored
189
    #define MD_CAP_STACK(var_addr)
winlin authored
190 191 192 193
#endif

#endif /* !__ST_MD_H__ */