source: git/omalloc/omReturn.h @ e6262c

spielwiese
Last change on this file since e6262c was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.6 KB
Line 
1/* slightly changed for use by omalloc.h */
2/*
3 * defines to get the return-address for non-dmalloc_lp malloc calls.
4 *
5 * Copyright 2000 by Gray Watson
6 *
7 * This file is part of the dmalloc package.
8 *
9 * Permission to use, copy, modify, and distribute this software for
10 * any purpose and without fee is hereby granted, provided that the
11 * above copyright notice and this permission notice appear in all
12 * copies, and that the name of Gray Watson not be used in advertising
13 * or publicity pertaining to distribution of the document or software
14 * without specific, written prior permission.
15 *
16 * Gray Watson makes no representations about the suitability of the
17 * software described herein for any purpose.  It is provided "as is"
18 * without express or implied warranty.
19 *
20 * The author may be contacted via http://dmalloc.com/
21 *
22 * $Id$
23 */
24
25/*
26 * This file contains the definition of the SET_RET_ADDR macro which
27 * is designed to contain the archecture/compiler specific hacks to
28 * determine the return-address from inside the malloc library.  With
29 * this information, the library can display caller information from
30 * calls that do not use the malloc_lp functions.
31 *
32 * Most of the archectures here have been contributed by other
33 * individuals and may need to be toggled a bit to remove local
34 * configuration differences.
35 *
36 * PLEASE send all submissions, comments, problems to the author.
37 *
38 * NOTE: examining the assembly code for x =
39 * __builtin_return_address(0); with gcc version 2+ should give you a
40 * good start on building a hack for your box.
41 */
42
43#ifndef __OM_RETURN_H__
44#define __OM_RETURN_H__
45
46/*************************************/
47
48/* for Sun SparcStations with GCC */
49#if __sparc && __GNUC__ > 1
50
51/*
52 * NOTE: %i7 seems to be more reliable than the [%fp+4] used by
53 * __builtin_return_address.  [%fp+4] is on the stack however, meaning
54 * it may be better -- less prone to be erased.  However, it produces
55 * some bogus data -- it seems to return the last return-address or
56 * something like that.
57 *
58 * Alexandre Oliva <oliva@dcc.unicamp.br> recently advised to change
59 * the "=g" to a "=m".  If you are having problems, you may want to
60 * return to the =g to see if it works.
61 */
62#define GET_RET_ADDR(file)      asm("st %%i7,%0" : \
63                                    "=m" (file) : \
64                                    /* no inputs */ )
65
66#if 0
67
68/* this was the default however =g was recommended to be changed to =m */
69#define GET_RET_ADDR(file)      asm("st %%i7,%0" : \
70                                    "=g" (file) : \
71                                    /* no inputs */ )
72
73/*
74 * This was what the gcc __builtin_return_address returned.  The above
75 * versions worked better.  It is here for reference purposes only.
76 */
77#define GET_RET_ADDR(file)      asm("ld [%%fp+4],%%o0; st %%o0,%0" : \
78                                        "=g" (file) : \
79                                        /* no inputs */ : \
80                                        "o0")
81#endif
82
83#endif /* __sparc */
84
85/*************************************/
86
87/* for i[34]86 machines with GCC */
88#if __i386 && __GNUC__ > 1
89
90#define GET_RET_ADDR(file)      asm("movl 4(%%ebp),%%eax ; movl %%eax,%0" : \
91                                    "=g" (file) : \
92                                    /* no inputs */ : \
93                                    "eax")
94
95#endif /* __i386 */
96
97/*************************************/
98
99/*
100 * For DEC Mips machines running Ultrix
101 */
102#if __mips
103
104/*
105 * I have no idea how to get inline assembly with the default cc.
106 * Anyone know how?
107 */
108
109#if 0
110
111/*
112 * NOTE: we assume here that file is global.
113 *
114 * $31 is the frame pointer.  $2 looks to be the return address but maybe
115 * not consistently.
116 */
117#define GET_RET_ADDR(file)      asm("sw $2, file")
118
119#endif
120
121#endif /* __mips */
122
123/******************************* contributions *******************************/
124
125/*
126 * For DEC Alphas running OSF.  from Dave Hill <ddhill@zk3.dec.com>
127 * and Alexandre Oliva <oliva@dcc.unicamp.br>.  Thanks guys.
128 */
129#if __alpha
130
131#ifdef __GNUC__
132
133#define GET_RET_ADDR(file)      asm("bis $26, $26, %0" : "=r" (file))
134
135#else /* __GNUC__ */
136
137#include <c_asm.h>
138
139#define GET_RET_ADDR(file)      file = (char *)asm("bis %ra,%ra,%v0")
140
141#endif /* __GNUC__ */
142
143#endif /* __alpha */
144
145/*************************************/
146
147/*
148 * For Data General workstations running DG/UX 5.4R3.00 from Joerg
149 * Wunsch <joerg_wunsch@julia.tcd-dresden.de>.
150 */
151#ifdef __m88k__
152
153/*
154 * I have no ideas about the syntax of Motorola SVR[34] assemblers.
155 * Also, there may be occasions where gcc does not set up a stack
156 * frame for some function, so the returned value should be taken with
157 * a grain of salt. For the ``average'' function calls it proved to be
158 * correct anyway -- jw
159 */
160#if !__DGUX__ || _DGUXCOFF_TARGET
161# define M88K_RET_ADDR  "ld %0,r30,4"
162#else  /* __DGUX__ && !_DGUXCOFF_TARGET: DG/UX ELF with version 3 assembler */
163# define M88K_RET_ADDR  "ld %0,#r30,4"
164#endif
165
166#define GET_RET_ADDR(file)      asm(M88K_RET_ADDR : \
167                                    "=r" (file) : \
168                                    /* no inputs */)
169
170#endif /* m88k */
171
172/*************************************/
173
174/*
175 * SGI compilers implement a C level method of accessing the return
176 * address by simply referencing the __return_address symbol. -- James
177 * Bonfield <jkb@mrc-lmb.cam.ac.uk>
178 */
179#if defined(__sgi)
180
181#define GET_RET_ADDR(file)      file = (void *)__return_address
182
183#endif /* __sgi */
184
185/*************************************/
186
187/*
188 * Stratus FTX system (UNIX_System_V 4.0 FTX release 2.3.1.1 XA/R
189 * Model 310 Intel i860XP processor)
190 *
191 * I ended up with compiling according to full-ANSI rules (using the
192 * -Xa compiler option).  This I could only do after modifying the
193 * "dmalloc.h.3" in such a way that the malloc/calloc/realloc/free
194 * definitions would no longer cause the compiler to bark with
195 * 'identifier redeclared' (I just put an #ifdef _STDLIB_H ... #endif
196 * around those functions).  -- Wim_van_Duuren@stratus.com
197 */
198#if defined(_FTX) && defined(i860)
199
200/*
201 * we first have the define the little assembly code function
202 */
203asm void ASM_GET_RET_ADDR(file)
204{
205%       reg     file;
206        mov     %r1, file
207%       mem     file;
208        st.l    %r31,-40(%fp)
209        orh     file@ha, %r0, %r31
210        st.l    %r1, file@l(%r31)
211        ld.l    -40(%fp),%r31
212%       error
213}
214#define GET_RET_ADDR(file)      ASM_GET_RET_ADDR(file)
215
216#endif /* _FTX & i860 */
217
218/*************************************/
219
220/*
221 * For HP-UX PA-RISC with gcc/g++ from Jack Perdue
222 * <j-perdue@tamu.edu>.
223 */
224#if __hpux && __hppa && __GNUC__ > 1
225
226/*
227 * This is my very first line of PA-RISC assembly ever.  I have no
228 * idea if is correct, but it seems to work.  Register 2 (%r2)
229 * contains the return address.  The code generated by x =
230 * __builtin_return_address() was considerably longer and without a
231 * PA-RISC Instruction Set guide available (not even on the web), I
232 * just put togther little tidbits of knowledge I found while looking
233 * for one to take a stab with this.  Like I said, it seems to work on
234 * my g++ code under HPUX11 on a HP V-class system.  YMMV. -- Jack
235 * Perdue (j-perdue@tamu.edu)
236 */
237#define GET_RET_ADDR(file)  asm("stw %%r2, %0" : "=m" (file) :  );
238
239#endif
240
241/*************************************/
242
243/*
244 * For Powerpc 603 based system running LynxOS 2.3.1 using gcc/gas.
245 * From Shawn Carey <smc@questra.com>.
246 */
247#if defined(__powerpc__) && defined(__GNUC__) && !defined(__OPTIMIZE__)
248
249/*
250 * This won't compile if "-O2" is used, but it seems to work fine with
251 * "-O0".  I'm no assembler expert; I was happy enough to come up with
252 * something that works at all...  :-)
253 */
254
255#define GET_RET_ADDR(file) \
256do { \
257  asm("mflr 0"); \
258  asm("stw 0,%0" : "=g" (file)); \
259} while(0)
260
261#endif /* __powerpc__ && __GNUC__ && !__OPTIMIZE__ */
262
263/*************************************/
264
265/********************************** default **********************************/
266
267/* for all others, do nothing */
268#ifndef GET_RET_ADDR
269
270#if __GNUC__ > 1
271#define GET_RET_ADDR(file) (file = __builtin_return_address(0))
272#else
273#define GET_RET_ADDR(file)      (file = 0)
274#endif
275#endif /* __GNUC__ > 1 */
276
277#endif /* ! __OM_RETURN_H__ */
Note: See TracBrowser for help on using the repository browser.