- Timestamp:
- Aug 14, 2000, 2:08:48 PM (24 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 9d605984360cf5d30bdf13e295d63c41ae1bc952
- Parents:
- ecf4ca6ad75f235385946daeae249f3bc6fd13c8
- Location:
- omalloc
- Files:
-
- 6 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
omalloc/Makefile.in
recf4ca6 r3df5b10 4 4 ### Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 ### Created: 11/99 6 ### Version: $Id: Makefile.in,v 1. 3 2000-05-31 13:34:28obachman Exp $6 ### Version: $Id: Makefile.in,v 1.4 2000-08-14 12:08:40 obachman Exp $ 7 7 ################################################################# 8 8 9 9 SHELL = /bin/sh 10 VERSION = @VERSION@ 10 11 11 12 ## 12 13 ## various paths 13 14 ## 15 prefix = @prefix@ 16 exec_prefix = @exec_prefix@ 17 14 18 # header file is installed here 15 19 includedir = @includedir@ … … 26 30 PERL = @PERL@ 27 31 LN_S = @LN_S@ 28 INSTALL = ../install-sh -c29 INSTALL_PROGRAM = ${INSTALL}30 INSTALL_DATA = ${INSTALL} -m 64431 MKINSTALLDIRS = . ./mkinstalldirs32 INSTALL = @INSTALL@ 33 INSTALL_PROGRAM = @INSTALL_PROGRAM@ 34 INSTALL_DATA = @INSTALL_DATA@ 35 MKINSTALLDIRS = ./mkinstalldirs 32 36 ## 33 37 ## compiler and linker options 34 38 ## 35 39 CFLAGS = @CFLAGS@ 36 # CFLAGS = @CFLAGS@ -Wno-unused 37 CPPFLAGS = @CPPFLAGS@ 38 DEFS = -DNDEBUG @DEFS@ 40 CPPFLAGS = -I. @CPPFLAGS@ 41 DEFS = @DEFS@ 39 42 40 43 ## 41 44 ## external config and and malloc files 42 45 ## 43 46 EXTERNAL_CONFIG_SOURCE = @EXTERNAL_CONFIG_SOURCE@ 44 47 EXTERNAL_CONFIG_HEADER = @EXTERNAL_CONFIG_HEADER@ 45 EXTERNAL_CONFIG_SOURCE = @EXTERNAL_CONFIG_SOURCE@46 48 47 49 OM_MALLOC_HEADER = @OM_MALLOC_HEADER@ … … 56 58 ### 57 59 58 59 60 # normal C source files 60 CSOURCES= \ 61 omBinPage.c omList.c omAllocEmulate.c \ 62 omAlloc.c omCheck.c omOpts.c omTrack.c \ 63 omAllocSystem.c omError.c omStats.c \ 64 omBin.c omFindExec.c omDebug.c 61 CSOURCES= \ 62 omBinPage.c omList.c omAllocEmulate.c omDebug.c \ 63 omAlloc.c omDebugCheck.c omOpts.c omGetBackTrace.c\ 64 omAllocSystem.c omError.c omStats.c omRet2Info.c \ 65 omBin.c omFindExec.c omDebugTrack.c \ 66 omalloc_provide.c 65 67 66 68 ifdef EXTERNAL_CONFIG_SOURCE … … 75 77 76 78 HEADERS= \ 77 omAlloc.h om Check.h omList.h\79 omAlloc.h omList.h omDerivedConfig.h \ 78 80 omAllocDecl.h omConfig.h omMemOps.h \ 79 omDebug.h omOpts.h 81 omDebug.h omOpts.h omInlineDecl.h \ 80 82 omAllocPrivate.h omError.h omPage.h \ 81 83 omAllocSystem.h omFindExec.h omStats.h \ 82 84 omBin.h omDefaultConfig.h omStructs.h \ 83 omBinPage.h omInline.h omTrack.h \ 84 85 OBJS := $(CSOURCES:.c=.o) $(GSOURCES:.c=.o) 86 85 omBinPage.h omInline.h omGetBackTrace.h \ 86 omReturn.h omRet2Info.h 87 88 OBJS := $(CSOURCES:.c=.o) $(GSOURCES:.c=.o) 89 OBJS_NDEBUG := $(CSOURCES:.c=.o_ndebug) $(GSOURCES:.c=.o_ndebug) 87 90 88 91 SOURCES=${CSOURCES} omGetPageSize.h omMallocSystem.h gmalloc.c dlmalloc.h dlmalloc.c \ 89 omMmap.c gmalloc.c omTables.c ommalloc.c pmalloc.h pmalloc.c 92 omMmap.c gmalloc.c omTables.c pmalloc.h pmalloc.c omalloc.c omalloc_debug.c \ 93 $(TESTSOURCES) omtTestAlloc.c 90 94 91 95 ASO_OBJS := $(ASO_SOURCES:.aso.cc=.aso) 92 96 93 DISTFILES=$(SOURCES) $(HEADERS) makeheader.pl Makefile.in \ 94 omConfig.h.in 97 DISTFILES=$(SOURCES) $(HEADERS) omtTest.h makeheader.pl Makefile.in \ 98 omConfig.h.in configure.in mkinstalldirs install-sh configure 99 95 100 ## 96 101 ## Build Targets 97 102 ## 98 99 %.o: %.c omConfig.h omTables.inc 103 %.o: %.c omConfig.h omTables.h omalloc.h omTables.inc 100 104 ${CC} ${CFLAGS} ${CPPFLAGS} ${DEFS} -c $< 105 106 %.o_ndebug: %.c omConfig.h omTables.h omalloc.h omTables.inc 107 ${CC} ${CFLAGS} ${CPPFLAGS} ${DEFS} -DOM_NDEBUG -c $< -o $@ 101 108 102 109 %.aso.o: %.aso.cc mmtables.inc … … 107 114 ./$< > $@ 108 115 109 all: lib libomalloc.h libg116 all: libomalloc.a libomalloc_ndebug.a omalloc.h omalloc.o omalloc_debug.o 110 117 111 118 lib: libomalloc.a … … 116 123 $(RANLIB) $@ 117 124 118 libomalloc.h: $(HEADERS) 119 $(PERL) makeheader.pl omAlloc.h $@ 125 libomalloc_ndebug.a: $(OBJS_NDEBUG) Makefile omConfig.h 126 rm -f $@ 127 $(AR) cr $@ $(OBJS_NDEBUG) 128 $(RANLIB) $@ 129 130 omalloc.h: $(HEADERS) 131 $(PERL) makeheader.pl -a omAlloc.h $@ 132 133 omalloc.o: omalloc.c 134 ${CC} ${CFLAGS} ${CPPFLAGS} ${DEFS} -DOM_NDEBUG -c $< -o $@ 135 136 omalloc_debug.o: omalloc_debug.c 137 ${CC} ${CFLAGS} ${CPPFLAGS} ${DEFS} -c $< -o $@ 120 138 121 139 omTables.inc: omTables 122 140 ./omTables > $@ 123 141 124 omTables: omAlloc.h omMalloc.h omConfig.h omTables.c 142 omTables.h: omTables 143 ./omTables 1 >$@ 144 145 omTables: omAllocPrivate.h omConfig.h omTables.c 125 146 ${CC} ${CFLAGS} ${CPPFLAGS} ${DEFS} -DOM_GENERATE_INC omTables.c -o omTables 126 147 … … 138 159 cp $(EXTERNAL_CONFIG_SOURCE) omExternalConfig.c 139 160 endif 161 140 162 ifdef EXTERNAL_CONFIG_HEADER 141 omExternalConfig.h: $ {EXTERNAL_CONFIG_HEADER}142 rm -fomExternalConfig.h143 cp ${EXTERNAL_CONFIG_HEADER}omExternalConfig.h163 omExternalConfig.h: $(EXTERNAL_CONFIG_HEADER) 164 cp $(EXTERNAL_CONFIG_HEADER) omExternalConfig.h 165 omDerivedConfig.h: omExternalConfig.h 144 166 endif 145 167 … … 166 188 ## install targets 167 189 ## 168 install: all 190 install: all libomalloc_p.a 169 191 $(MKINSTALLDIRS) $(libdir) 170 192 $(MKINSTALLDIRS) $(includedir) 171 193 $(INSTALL_DATA) libomalloc.a $(libdir) 172 194 $(RANLIB) $(libdir)/libomalloc.a 173 $(INSTALL_DATA) libmalloc.h $(includedir)/omAlloc.h 195 $(INSTALL_DATA) libomalloc_ndebug.a $(libdir) 196 $(RANLIB) $(libdir)/libomalloc_ndebug.a 197 $(INSTALL_DATA) libomalloc_p.a $(libdir) 198 $(RANLIB) $(libdir)/libomalloc_p.a 199 $(INSTALL_DATA) omalloc.o omalloc_debug.o $(libdir) 200 $(INSTALL_DATA) omalloc.h omalloc.c $(includedir) 201 174 202 175 203 uninstall: 176 rm -f $(includedir)/omAlloc.h $(libdir)/libomalloc.a 204 rm -f $(includedir)/omalloc.h $(includedir)/omalloc.c 205 rm -f $(libdir)/libomalloc.a $(libdir)/libomalloc_ndebug.a $(libdir)/libomalloc_p.a $(libdir)/omalloc.o $(libdir)/omalloc_debug.o 206 207 ## 208 ## dist targets 209 ## 210 dist: omalloc-$(VERSION).tgz 211 omalloc-$(VERSION).tgz: $(DISTFILES) 212 rm -rf omalloc-$(VERSION) 213 mkdir omalloc-$(VERSION) 214 cp $(DISTFILES) omalloc-$(VERSION) 215 tar czf omalloc-$(VERSION).tgz omalloc-$(VERSION) 177 216 178 217 ## … … 180 219 ## 181 220 mostlyclean: 182 -rm -f core *.d *.o *.og *.op *_d.c *.ob *.a depend *.out *.tgz omTables 183 -rm -f om Test omTest_* libomalloc*184 -rm -f omMalloc.c om Malloc.h omExternalConfig.h omExternalConfig.c221 -rm -f core *.d *.o *.og *.op *_d.c *.ob *.a depend *.out *.tgz omTables *.o_ndebug *.gp *.gprof 222 -rm -f omtTest omtTest_* libomalloc* *.bprof omtTest omtTest_* 223 -rm -f omMalloc.c omExternalConfig.h omExternalConfig.c 185 224 186 225 clean: mostlyclean 187 226 188 227 distclean: clean 189 -rm -f *~ .\#* stamp-h configure 228 -rm -f *~ .\#* stamp-h configure omMalloc.h 229 rm -rf omalloc-$(VERSION) 190 230 -rm -f omConfig.h Makefile TAGS* tags config.status config.cache config.log 191 231 … … 201 241 202 242 ## 243 ## check 244 ## 245 246 check: omtTest omtTest_ndebug 247 ./omtTest 248 ./omtTest_ndebug 249 250 ## 203 251 ## Below here is stuff for developpers 204 252 ################################################################# … … 211 259 CCM = gcc -MM -DGENERATE_DEPEND 212 260 213 CFLAGSG = -g -O - Wall -pipe261 CFLAGSG = -g -O -fno-inline-functions -Wall -pipe 214 262 DEFSG = @DEFS@ 215 263 216 264 OBJG := $(CSOURCES:.c=.og) $(GSOURCES:.c=.og) 217 265 218 %.og: %.c 266 %.og: %.c omConfig.h omTables.h omalloc.h 219 267 $(CCG) ${CFLAGSG} ${CPPFLAGS} ${DEFSG} -c $< -o $@ 220 268 … … 228 276 229 277 ## 230 ## exp naded macros231 ## 232 OBJD := $(CSOURCES:%.c=%_d.og) 233 234 %_d.c : %.c omConfig.h 278 ## expanded macros 279 ## 280 OBJD := $(CSOURCES:%.c=%_d.og) $(GSOURCES:%.c=%_d.og) 281 282 %_d.c : %.c omConfig.h omTables.h omalloc.h 235 283 $(CCG) -E -P $< | $(PERL) -p -e 's/;/;\n/g' | $(PERL) -p -e 's/\{/\n\{/g' | $(PERL) -p -e 's/\}/\n\}/g' > $@ 236 284 .PRECIOUS: %_d.c … … 249 297 CCP = gcc 250 298 251 CFLAGSP = -g -pg -O3 -a -pipe 299 CFLAGSP = -g -pg -O3 -a -pipe 252 300 DEFSP = @DEFS@ 253 301 … … 258 306 ## Profile Targets 259 307 ## 260 %.op: %.c 308 %.op: %.c omConfig.h omTables.h omalloc.h 261 309 $(CCP) ${CFLAGSP} ${CPPFLAGS} ${DEFSP} -c $< -o $@ 262 310 … … 274 322 CCB = gcc 275 323 276 CFLAGSB = -g -O3 -pipe 324 CFLAGSB = -g -O3 -pipe 277 325 DEFSB = @DEFS@ 278 326 … … 286 334 ## Profile Targets 287 335 ## 288 %.ob: %.c 336 %.ob: %.c omConfig.h omTables.h omalloc.h 289 337 $(CCB) ${CFLAGSB} ${CPPFLAGS} ${DEFSB} -c $< -o $@ 290 338 … … 299 347 ## Test program 300 348 ## 301 302 omTest_d: libd omTest_d.c omTest.d 303 $(CCG) ${CFLAGSG} ${CPPFLAGS} ${DEFSG} omTest_d.c -L. -lomalloc_d -o omTest_d 304 305 omTest_g: libg omTest.c omTest.d 306 $(CCG) ${CFLAGSG} ${CPPFLAGS} ${DEFSG} omTest.c -L. -lomalloc_g -o omTest_g 307 308 309 omTest_p: libp omTest.c omTest.d 310 $(CCP) ${CFLAGSP} ${CPPFLAGS} ${DEFSP} omTest.c -L. -lomalloc_p -o omTest_p 311 312 omTest_b: libb omTest.c omTest.d 313 $(CCB) ${CFLAGSB} ${CPPFLAGS} ${DEFSB} omTest.c /usr/lib/bmon.o -L. -lomalloc_b -o omTest_b 314 315 omTest: lib omTest.c omTest.d 316 $(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} omTest.c -L. -lomalloc -o omTest 317 318 omTest_m: lib omTest.c omTest.d 319 $(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} -DOM_TEST_MALLOC omTest.c -L. -lomalloc -o omTest_m 320 321 ## 322 ## tar and backup 323 ## 324 325 tar: 326 tar czvf omalloc.tgz $(DISTFILES) 327 328 backup: tar 329 mcopy omalloc.tgz a: 349 TESTSOURCES = omtTest.c omtTestReal.c omtTestDebug.c omtTestError.c 350 351 TEST_D := $(TESTSOURCES:.c=_d.og) 352 omtTest_d: libd $(TEST_D) 353 $(CCG) ${CFLAGSG} ${CPPFLAGS} ${DEFSG} $(TEST_D) -L. -lomalloc_d -o omtTest_d 354 355 TEST_G := $(TESTSOURCES:.c=.og) 356 omtTest_g: libg $(TEST_G) 357 $(CCG) ${CFLAGSG} ${CPPFLAGS} ${DEFSG} $(TEST_G) -L. -lomalloc_g -o omtTest_g 358 359 TEST_P := $(TESTSOURCES:.c=.op) 360 omtTest_p: libp $(TEST_P) 361 $(CCG) ${CFLAGSP} ${CPPFLAGS} ${DEFSP} $(TEST_P) -L. -lomalloc_p -o omtTest_p 362 363 TEST_B := $(TESTSOURCES:.c=.ob) 364 omtTest_b: libb $(TEST_B) 365 $(CCG) ${CFLAGSB} ${CPPFLAGS} ${DEFSB} $(TEST_B) -L. -lomalloc_b /usr/lib/bmon.o -o omtTest_b 366 367 TEST_O := $(TESTSOURCES:.c=.o) 368 omtTest: lib $(TEST_O) 369 $(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} $(TEST_O) -L. -lomalloc -o omtTest 370 371 TEST_NDEBUG_O := $(TESTSOURCES:.c=.o_ndebug) 372 omtTest_ndebug: libomalloc_ndebug.a $(TEST_NDEBUG_O) 373 $(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} $(TEST_NDEBUG_O) -DOM_NDEBUG -L. -lomalloc_ndebug -o omtTest_ndebug 374 375 %.om : %.c omalloc.h 376 $(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} -DOM_TEST_MALLOC -c $< -o $@ 377 TEST_M := $(TESTSOURCES:.c=.om) 378 omtTest_m: lib $(TEST_M) 379 $(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} -DOM_TEST_MALLOC $(TEST_M) -L. -lomalloc -o omtTest_m 380 381 ## 382 ## backup 383 ## 384 385 backup: omalloc-$(VERSION).tgz 386 mcopy -o omalloc-$(VERSION).tgz a: 330 387 331 388 ## 332 389 ## Dependencies 333 390 ## 334 %.d: %.c omConfig.h Makefile 335 echo $(@:.d=.o g) $(@:.d=.od) $(@:.d=.ob) $(@:.d=_d.c)" " \\ > $@391 %.d: %.c omConfig.h Makefile omTables.h omTables.inc omalloc.h 392 echo $(@:.d=.o_ndebug) $(@:.d=.og) $(@:.d=.od) $(@:.d=.op) $(@:.d=.ob) $(@:.d=_d.c) $(@:.d=.om)" " \\ > $@ 336 393 $(CCM) ${CPPFLAGS} ${DEFSG} $< >> $@ 337 394 338 depend: omTest.d $(CSOURCES:.c=.d) omConfig.h395 depend: $(CSOURCES:.c=.d) omConfig.h $(TESTSOURCES:.c=.d) 339 396 cat *.d >depend 340 397 -
omalloc/configure.in
recf4ca6 r3df5b10 4 4 dnl Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 dnl Created: 11/99 6 dnl Version: $Id: configure.in,v 1. 3 2000-05-31 13:34:29obachman Exp $6 dnl Version: $Id: configure.in,v 1.4 2000-08-14 12:08:42 obachman Exp $ 7 7 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll 8 8 9 9 AC_INIT(omAlloc.c) 10 11 VERSION=0.9.5 12 AC_SUBST(VERSION) 10 13 11 14 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll … … 13 16 dnl 14 17 AC_ARG_WITH( 15 external _config_h,18 external-config_h, 16 19 [ --with-external-config_h=HEADER_FILE 17 20 use HEADER_FILE for external configuration]) 18 21 AC_ARG_WITH( 19 external _config_c,22 external-config_c, 20 23 [ --with-external-config_c=C_FILE 21 24 use C_FILE for external implementations]) … … 25 28 which malloc to use, default: dlmalloc ]) 26 29 AC_ARG_WITH( 27 external _malloc_h,30 external-malloc_h, 28 31 [ --with-external-malloc-h=HEADER_FILE 29 32 use HEADER_FILE for external malloc declaration]) 30 33 AC_ARG_WITH( 31 external _malloc_c,32 [ --with-external-malloc- h=C_FILE34 external-malloc_c, 35 [ --with-external-malloc-c=C_FILE 33 36 use C_FILE for external malloc implementation]) 34 37 AC_ARG_WITH( … … 37 40 how to get page-aligned memory, default: use first possible]) 38 41 AC_ARG_WITH( 39 provide_malloc, 40 [ --with-provide-malloc 41 provide ANSI-C conforming malloc/calloc/realloc/free]) 42 AC_ARG_WITH( 43 emulate_omalloc, 42 provide-malloc, 43 [ --with-provide-malloc=yes|debug|malloc 44 provide normal|debug|underlying malloc ANSI-C conforming 45 versions of malloc|calloc|realloc|free]) 46 AC_ARG_WITH( 47 emulate-omalloc, 44 48 [ --with-emulate-omalloc 45 49 provide only omallocs interface, but do not use its features]) … … 50 54 default: if possible sloppy, else strict]) 51 55 AC_ARG_WITH( 52 dense _bins,56 dense-bins, 53 57 [ --with-dense-bins use dense bin distribution]) 54 58 AC_ARG_WITH( 55 59 inline, 56 60 [ --without-inline do not inline]) 61 AC_ARG_WITH( 62 debug, 63 [ --without-debug disable all debugging facilities]) 64 AC_ARG_WITH( 65 track, 66 [ --without-track disable debug tracking functionality]) 67 AC_ARG_WITH( 68 track-fl, 69 [ --with-track-fl track file and line numbers]) 70 AC_ARG_WITH( 71 track-return, 72 [ --with-track-return track return addresses]) 73 AC_ARG_WITH( 74 track-backtrace, 75 [ --with-track-backtrace track stack backtraces]) 57 76 AC_ARG_WITH( 58 77 internal_debug, 59 78 [ --with-internal-debug 60 79 turn on internal debugging]) 61 AC_ARG_WITH(62 mtrack,63 [ --without-mtrack disable backtrace and memory track])64 AC_ARG_WITH(65 frame_addr_func,66 [ --with_frame_addr_func=FUNC67 use FUNC as function for determening frame addr68 default: __bultin_frame_address])69 AC_ARG_WITH(70 return_addr_func,71 [ --with_return_addr_func=FUNC72 use FUNC as function for determening return addr73 default: __bultin_return_address])74 75 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll76 dnl get singuname77 dnl78 AC_MSG_CHECKING(singuname)79 AC_CACHE_VAL(ac_cv_singuname,80 ac_cv_singuname="unknown"81 if test -r "singuname.sh"; then82 if (/bin/sh singuname.sh >/dev/null 2>&1) then83 ac_cv_singuname=`/bin/sh singuname.sh`84 fi85 fi86 if test "$ac_cv_singuname" = unknown && test -r "../singuname.sh"; then87 if (/bin/sh ../singuname.sh >/dev/null 2>&1) then88 ac_cv_singuname=`/bin/sh ../singuname.sh`89 fi90 fi91 )92 AC_MSG_RESULT($ac_cv_singuname)93 if test "$ac_cv_singuname" = unknown; then94 AC_MSG_WARN(Unknown architecture: Check singuname.sh)95 ac_cv_singuname="unknown"96 fi97 98 80 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll 99 81 dnl compiler/make config 100 82 dnl 101 if test "${CFLAGS+set}" != set; then 102 CFLAGS="-O" 103 ac_cflags_set=no 104 fi 83 dnl I'm not sure why I did this 84 dnl if test "${CFLAGS+set}" != set; then 85 dnl CFLAGS="-O" 86 dnl ac_cflags_set=no 87 dnl fi 88 105 89 AC_PROG_MAKE_SET 106 90 AC_PROG_CC 107 91 AC_PROG_CPP 92 AC_PROG_RANLIB 93 AC_PROG_LN_S 94 AC_PROG_INSTALL 108 95 AC_C_CONST 109 96 AC_C_INLINE 110 AC_PROG_RANLIB111 AC_PROG_LN_S112 97 113 98 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll … … 229 214 AC_DEFINE(OM_HAVE_EXTERNAL_CONFIG_H) 230 215 EXTERNAL_CONFIG_HEADER=${with_external_config_h} 216 rm -f omExternalConfig.h 217 cp ${with_external_config_h} omExternalConfig.h 231 218 fi 232 219 if test "${with_external_config_c+set}" = set; then … … 248 235 if test "${with_malloc}" = system; then 249 236 OM_MALLOC_HEADER=omMallocSystem.h 250 if test "${with_provide_malloc}" = yes ; then251 AC_MSG_ERROR("can not provide malloc for --with _malloc=system")237 if test "${with_provide_malloc}" = yes || test "${with_provide_malloc}" = debug; then 238 AC_MSG_ERROR("can not provide malloc for --with-malloc=system") 252 239 fi 253 240 elif test "${with_malloc}" = gmalloc; then … … 261 248 AC_MSG_ERROR(need --with_external_malloc_h for external malloc) 262 249 fi 263 if test "${with_provide_malloc}" = yes ; then250 if test "${with_provide_malloc}" = yes || test "${with_provide_malloc}" = debug; then 264 251 AC_MSG_ERROR("can not provide malloc for --with_malloc=external") 265 252 fi … … 307 294 AC_DEFINE(OM_MALLOC_PROVIDES_SIZEOF_ADDR) 308 295 fi 309 310 if test "${with_provide_malloc}" = yes; then 311 AC_DEFINE(OM_PROVIDE_MALLOC) 296 297 if test "${with_provide_malloc}" = malloc; then 298 AC_DEFINE(OM_PROVIDE_MALLOC, 3) 299 elif test "${with_provide_malloc}" = debug; then 300 AC_DEFINE(OM_PROVIDE_MALLOC, 2) 301 elif test "${with_provide_malloc}" = yes; then 302 AC_DEFINE(OM_PROVIDE_MALLOC, 1) 303 else 304 AC_DEFINE(OM_PROVIDE_MALLOC, 0) 312 305 fi 313 306 … … 406 399 dnl debug and inline 407 400 dnl 401 AC_MSG_CHECKING(whether to disable debugging) 402 if test "$with_debug" != no; then 403 AC_MSG_RESULT(no) 404 else 405 AC_MSG_RESULT(yes) 406 AC_DEFINE(OM_NDEBUG) 407 with_track=no 408 fi 409 410 AC_MSG_CHECKING(whether to have tracking debug functionality) 411 if test "$with_track" != no; then 412 AC_MSG_RESULT(yes) 413 AC_DEFINE(OM_HAVE_TRACK) 414 else 415 AC_MSG_RESULT(no) 416 fi 417 408 418 AC_MSG_CHECKING(whether to use internal debug) 409 419 if test "$with_internal_debug" = yes; then … … 430 440 431 441 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll 432 dnl mtrack business 433 dnl 434 if test "$with_mtrack" != no; then 435 # get function for return address 436 if test "${with_return_addr_func+set}" = set; then 437 if test "${with_return_addr_func}" != no; then 438 ac_cv_return_addr_func=$with_return_addr_func 439 fi 440 else 441 if test "${GCC}" = yes; then 442 ac_cv_return_addr_func="__builtin_return_address" 443 fi 444 fi 445 446 # test this function 447 if test "${ac_cv_return_addr_func+set}" = set; then 448 AC_DEFINE_UNQUOTED(OM_RETURN_ADDR, $ac_cv_return_addr_func) 449 # first, check whether return addr works 450 AC_MSG_CHECKING(whether $ac_cv_return_addr_func works) 451 AC_CACHE_VAL(ac_cv_return_addr_func_works, 442 dnl backtrace business 443 dnl 444 AC_MSG_CHECKING(whether GET_RET_ADDR works) 445 AC_CACHE_VAL(ac_cv_get_return_addr_works, 452 446 AC_TRY_RUN([ 447 #include "omReturn.h" 453 448 int test_return_addr() 454 449 { 455 if (OM_RETURN_ADDR(1) != 0 && OM_RETURN_ADDR(0) != 0 && 456 OM_RETURN_ADDR(1) != OM_RETURN_ADDR(0)) return 0; 457 return 1; 458 } 459 450 char* f; 451 GET_RET_ADDR(f); 452 return (int) f; 453 } 460 454 int main() 461 455 { 462 return test_return_addr();463 } 464 ], ac_cv_ return_addr_func_works=yes,465 ac_cv_ return_addr_func_works=no,466 ac_cv_ return_addr_func_works=no))467 AC_MSG_RESULT($ac_cv_ return_addr_func_works)468 469 if test "$ac_cv_return_addr_func_works" = yes; then 470 AC_DEFINE(OM_RETURN_ADDR_WORKS) 471 # check whether return addr works with rvalues 472 AC_MSG_CHECKING(whether $ac_cv_return_addr_func takes rvalues)473 AC_CACHE_VAL(ac_cv_ return_addr_func_rvalue,456 exit(! test_return_addr()); 457 } 458 ], ac_cv_get_return_addr_works=yes, 459 ac_cv_get_return_addr_works=no, 460 ac_cv_get_return_addr_works=no)) 461 AC_MSG_RESULT($ac_cv_get_return_addr_works) 462 if test "$ac_cv_get_return_addr_works" = yes; then 463 AC_DEFINE(OM_GET_RETURN_ADDR_WORKS) 464 fi 465 466 AC_MSG_CHECKING(whether omGetBackTrace works) 467 AC_CACHE_VAL(ac_cv_get_backtrace_works, 474 468 AC_TRY_RUN([ 475 int test_return_addr(int f1, int f2) 476 { 477 if (OM_RETURN_ADDR(f1) != 0 && OM_RETURN_ADDR(f0) != 0 && 478 OM_RETURN_ADDR(f1) != OM_RETURN_ADDR(f0)) return 0; 479 return 1; 480 } 481 469 #include "omGetBackTrace.c" 470 #include <stdio.h> 471 int test_backtrace() 472 { 473 void* bt; 474 int i = omGetBackTrace(&bt, 0, 10); 475 return i; 476 } 482 477 int main() 483 478 { 484 return test_return_addr(1, 0); 485 } 486 ], ac_cv_return_addr_func_rvalue=yes, 487 ac_cv_return_addr_func_rvalue=no, 488 ac_cv_return_addr_func_rvalue=no)) 489 AC_MSG_RESULT($ac_cv_return_addr_func_rvalue) 490 if test "$ac_cv_return_addr_func_rvalue" = yes; then 491 AC_DEFINE_UNQUOTED(OM_RETURN_ADDR_RVALUE) 492 fi 493 fi # "$ac_cv_return_addr_func_works" = yes; 494 fi # "${ac_cv_return_addr_func+set}" = set; 495 496 # get function for frame address 497 if test "${with_frame_addr_func+set}" = set; then 498 if test "${with_frame_addr_func}" != no; then 499 ac_cv_frame_addr_func=$with_frame_addr_func 500 fi 501 else 502 if test "${GCC}" = yes; then 503 ac_cv_frame_addr_func="__builtin_frame_address" 504 fi 505 fi 506 507 # test this function 508 if test "${ac_cv_frame_addr_func+set}" = set; then 509 AC_DEFINE_UNQUOTED(OM_FRAME_ADDR, $ac_cv_frame_addr_func) 510 # first, check whether frame addr works 511 AC_MSG_CHECKING(whether $ac_cv_frame_addr_func works) 512 AC_CACHE_VAL(ac_cv_frame_addr_func_works, 513 AC_TRY_RUN([ 514 int test_frame_addr() 515 { 516 if (OM_FRAME_ADDR(1) != 0 && OM_FRAME_ADDR(0) != 0 && 517 OM_FRAME_ADDR(1) != OM_FRAME_ADDR(0)) return 0; 518 return 1; 519 } 520 521 int main() 522 { 523 return test_frame_addr(); 524 } 525 ], ac_cv_frame_addr_func_works=yes, 526 ac_cv_frame_addr_func_works=no, 527 ac_cv_frame_addr_func_works=no)) 528 AC_MSG_RESULT($ac_cv_frame_addr_func_works) 529 530 if test "$ac_cv_frame_addr_func_works" = yes; then 531 AC_DEFINE(OM_FRAME_ADDR_WORKS) 532 # check whether frame addr works with rvalues 533 AC_MSG_CHECKING(whether $ac_cv_frame_addr_func takes rvalues) 534 AC_CACHE_VAL(ac_cv_frame_addr_func_rvalue, 535 AC_TRY_RUN([ 536 int test_frame_addr(int f1, int f2) 537 { 538 if (OM_FRAME_ADDR(f1) != 0 && OM_FRAME_ADDR(f0) != 0 && 539 OM_FRAME_ADDR(f1) != OM_FRAME_ADDR(f0)) return 0; 540 return 1; 541 } 542 543 int main() 544 { 545 return test_frame_addr(1, 0); 546 } 547 ], ac_cv_frame_addr_func_rvalue=yes, 548 ac_cv_frame_addr_func_rvalue=no, 549 ac_cv_frame_addr_func_rvalue=no)) 550 AC_MSG_RESULT($ac_cv_frame_addr_func_rvalue) 551 if test "$ac_cv_frame_addr_func_rvalue" = yes; then 552 AC_DEFINE_UNQUOTED(OM_FRAME_ADDR_RVALUE) 553 fi 554 fi # "$ac_cv_frame_addr_func_works" = yes; 555 fi # "${ac_cv_frame_addr_func+set}" = set; 556 557 fi # "$with_mtrack" != no; 558 559 560 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll 561 dnl last but not least, let's be smart about CFLAGS 562 dnl 563 if test "${GCC}" = yes && test "$ac_cflags_set" = no ; then 564 CFLAGS="-pipe -Wall -O3 -fomit-frame-pointer" 565 fi 566 479 int i; 480 omInitGetBackTrace(); 481 i = test_backtrace(); 482 if (i == 1) exit(0); 483 else exit(i+1); 484 } 485 ], ac_cv_get_backtrace_works=yes, 486 ac_cv_get_backtrace_works=no, 487 ac_cv_get_backtrace_works=no)) 488 AC_MSG_RESULT($ac_cv_get_backtrace_works) 489 if test "$ac_cv_get_backtrace_works" = yes; then 490 AC_DEFINE(OM_GET_BACKTRACE_WORKS) 491 fi 492 493 AC_MSG_CHECKING(whether to track return addresses) 494 if test "$with_track_return" = no || test "$ac_cv_get_return_addr_works" = no; then 495 with_track_return=no 496 else 497 AC_DEFINE(OM_TRACK_RETURN) 498 with_track_return=yes 499 fi 500 AC_MSG_RESULT($with_track_return) 501 502 AC_MSG_CHECKING(whether to track files and line numbers) 503 if test "$with_track_fl" = no && test "$with_track_return" = no; then 504 with_track_fl=yes 505 fi 506 if test "${with_track_fl+set}" != set; then 507 if test "$with_track_return" = yes; then 508 with_track_fl=no 509 else 510 with_track_fl=yes 511 fi 512 fi 513 AC_MSG_RESULT($with_track_fl) 514 if test "$with_track_fl" = yes; then 515 AC_DEFINE(OM_TRACK_FILE_LINE) 516 fi 517 518 AC_MSG_CHECKING(whether to track stack backtraces) 519 if test "$with_track" != no && test "$ac_cv_get_backtrace_works" = yes && test "$with_track_backtrace" != no; then 520 with_track_backtrace=yes 521 AC_DEFINE(OM_TRACK_BACKTRACE) 522 else 523 with_track_backtrace=no 524 fi 525 AC_MSG_RESULT($with_track_backtrace) 526 527 dnl lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll 528 dnl wrap it up 529 dnl 567 530 AC_CONFIG_HEADER(omConfig.h omMalloc.h:${OM_MALLOC_HEADER}) 531 568 532 569 533 AC_OUTPUT(Makefile, \ -
omalloc/makeheader.pl
recf4ca6 r3df5b10 1 1 #!/usr/bin/perl 2 # $Id: makeheader.pl,v 1. 1.1.1 1999-11-18 17:45:53 obachman Exp $2 # $Id: makeheader.pl,v 1.2 2000-08-14 12:08:43 obachman Exp $ 3 3 # 4 4 # makeheader.pl - generate a header file out of several header file (ver 1.2). … … 20 20 if ( ( $#ARGV == -1 ) || ( $ARGV[0] =~ /-help|-\?/ ) ) { 21 21 die " 22 usage: makeheader [-?] {-I<includedir>} <templatefile> <outfile>22 usage: makeheader [-?] [-a] {-I<includedir>} <templatefile> <outfile> 23 23 24 24 This is makeheader, a header file generation tool. … … 32 32 #include \"<includefile>\" 33 33 34 in <templatefile>. 34 in <templatefile>. If <includefile> contains sections marked with 35 /*BEGINPRIVATE*/ and /*ENDPRIVATE*/ then these sections are excluded. 35 36 36 37 If you use the alternate form … … 41 42 only sections marked with /*BEGINPUBLIC*/ and /*ENDPUBLIC*/ are 42 43 pasted from <includefile> into <outfile>. 44 45 Option -a is equivalent to a /*MAKEHEADER*/ marking of all 46 #include \"<includefile>\" of <templatefile>. 43 47 44 48 <includefile> is looked up in all <includedir>s, then in the … … 54 58 $includes .= ( $1 ? $1 : shift ) . ":"; 55 59 } 60 $all = 1 if /^-a/; 56 61 } 57 62 $includes .= ".:"; … … 76 81 77 82 while( <INFILE> ) { 78 if ( /^\/\*MAKEHEADER(.*)\*\/$/ ) { 79 # check whether we have to read public part only 80 if ( $1 eq " PUBLIC ONLY" ) { 83 if ( /^\/\*MAKEHEADER(.*)\*\/$/ || ($all && /^\#include \"(.*)\"$/)) { 84 if (/^\/\*MAKEHEADER(.*)\*\/$/) 85 { 86 # check whether we have to read public part only 87 if ( $1 eq " PUBLIC ONLY" ) { 81 88 $public_only = 1; 82 } else {89 } else { 83 90 $public_only = 0; 91 } 92 $_ = <INFILE>; chop; 84 93 } 85 94 86 95 # get name of file to include 87 $_ = <INFILE>; chop;88 96 if ( /^\#include \"(.*)\"$/ ) { 89 97 $inclfile = $1; … … 110 118 } else { 111 119 # just paste contents into output 112 while ( <INCLFILE> ) { print OUTFILE $_; } 120 while ( <INCLFILE> ) 121 { 122 $exclude = 1, next if /^\/\*BEGINPRIVATE\*\/\s*$/; 123 $exclude = 0, next if /^\/\*ENDPRIVATE\*\/\s*$/; 124 print OUTFILE $_ unless $exclude; 125 } 113 126 } 114 127 close INCLFILE; -
omalloc/omAlloc.c
recf4ca6 r3df5b10 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omAlloc.c,v 1. 5 2000-05-31 13:34:29obachman Exp $6 * Version: $Id: omAlloc.c,v 1.6 2000-08-14 12:08:43 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_ALLOC_C … … 10 10 11 11 #include "omAlloc.h" 12 13 12 /******************************************************************* 14 13 * … … 18 17 19 18 omBinPage_t om_ZeroPage[] = {{0, NULL, NULL, NULL, NULL}}; 20 omBinPage_t om_CheckPage[] = {{0, NULL, NULL, NULL, NULL}};21 omBinPage_t om_LargePage[] = {{0, NULL, NULL, NULL, NULL}};22 omBin_t om_LargeBin[] = {{om_LargePage, NULL, NULL, 0, 0, 0}};23 omBin_t om_CheckBin[] = {{om_CheckPage, NULL, NULL, 0, 0, 0}};24 19 omSpecBin om_SpecBin = NULL; 25 20 26 /******************************************************************* 27 * 28 * Definition of Func 29 * 30 *******************************************************************/ 31 32 #define ALLOCBIN_FUNC_WRAPPER(func) \ 33 void* omFunc##func (omBin bin) \ 34 { \ 35 void* addr; \ 36 __omType##func (void*, addr, bin); \ 37 return addr; \ 38 } 39 40 #define REALLOCBIN_FUNC_WRAPPER(func) \ 41 void* omFunc##func (void* old_addr, omBin old_bin, omBin new_bin) \ 42 { \ 43 void* new_addr; \ 44 __omType##func (old_addr, old_bin, void*, new_addr, new_bin); \ 45 return new_addr; \ 46 } 47 48 #define ALLOCSIZE_FUNC_WRAPPER(func) \ 49 void* omFunc##func (size_t size) \ 50 { \ 51 void* addr; \ 52 __omType##func (void*, addr, size); \ 53 return addr; \ 54 } 55 56 #define REALLOCSIZE_FUNC_WRAPPER(func) \ 57 void* omFunc##func (void* old_addr, size_t old_size, size_t new_size) \ 58 { \ 59 void* new_addr; \ 60 __omType##func (old_addr, old_size, void*, new_addr, new_size); \ 61 return new_addr; \ 62 } 63 64 #define REALLOC_FUNC_WRAPPER(func) \ 65 void* omFunc##func (void* old_addr, size_t new_size) \ 66 { \ 67 void* new_addr; \ 68 __omType##func (old_addr, void*, new_addr, new_size); \ 69 return new_addr; \ 70 } 71 72 #define FREESIZE_FUNC_WRAPPER(func) \ 73 void omFunc##func (void* addr, size_t size) \ 74 { \ 75 __om##func (addr, size); \ 76 } 77 78 #define FREEBIN_FUNC_WRAPPER(func) \ 79 void omFunc##func (void* addr, omBin bin) \ 80 { \ 81 __om##func (addr, bin); \ 82 } 83 84 #define FREE_FUNC_WRAPPER(func) \ 85 void omFunc##func (void* addr) \ 86 { \ 87 __om##func (addr); \ 88 } 89 90 ALLOCBIN_FUNC_WRAPPER(AllocBin) 91 ALLOCBIN_FUNC_WRAPPER(Alloc0Bin) 92 REALLOCBIN_FUNC_WRAPPER(ReallocBin) 93 REALLOCBIN_FUNC_WRAPPER(Realloc0Bin) 94 FREEBIN_FUNC_WRAPPER(FreeBin) 95 96 ALLOCSIZE_FUNC_WRAPPER(Alloc) 97 ALLOCSIZE_FUNC_WRAPPER(Alloc0) 98 REALLOCSIZE_FUNC_WRAPPER(ReallocSize) 99 REALLOCSIZE_FUNC_WRAPPER(Realloc0Size) 100 REALLOC_FUNC_WRAPPER(Realloc) 101 REALLOC_FUNC_WRAPPER(Realloc0) 102 FREESIZE_FUNC_WRAPPER(FreeSize) 103 FREE_FUNC_WRAPPER(Free) 104 105 #ifdef OM_ALIGNMENT_NEEDS_WORK 106 ALLOCSIZE_FUNC_WRAPPER(AllocAligned) 107 ALLOCSIZE_FUNC_WRAPPER(Alloc0Aligned) 108 REALLOCSIZE_FUNC_WRAPPER(ReallocAlignedSize) 109 REALLOCSIZE_FUNC_WRAPPER(Realloc0AlignedSize) 110 REALLOC_FUNC_WRAPPER(ReallocAligned) 111 REALLOC_FUNC_WRAPPER(Realloc0Aligned) 112 #endif /* OM_ALIGNMENT_NEEDS_WORK */ 21 #include "omTables.inc" 22 113 23 114 24 /******************************************************************* … … 215 125 { 216 126 omAssume(bin->last_page != NULL); 127 /* Set this to zero, but preserve the first bit, 128 so that tracking works */ 129 #ifdef OM_HAVE_TRACK 130 bin->current_page->used_blocks &= (1 << (BIT_SIZEOF_LONG -1)); 131 #else 217 132 bin->current_page->used_blocks = 0; 133 #endif 218 134 } 219 135 … … 238 154 239 155 240 /* page->used_blocks == 0, so, either free page or reallocate to156 /* page->used_blocks <= 0, so, either free page or reallocate to 241 157 the right of current_page */ 242 158 /* … … 253 169 omAssume(page->used_blocks <= 0); 254 170 255 #ifdef OM_HAVE_DEBUG 256 if (page->used_blocks < 0) omDebugFree(addr, 0); 171 #ifdef OM_HAVE_TRACK 172 if (page->used_blocks < 0) 173 { 174 omFreeTrackAddr(addr); 175 return; 176 } 257 177 #endif 258 178 … … 267 187 else 268 188 omFreeBinPages(page, - bin->max_blocks); 269 #ifdef OM_HAVE_ DEBUG189 #ifdef OM_HAVE_TRACK 270 190 om_JustFreedPage = page; 271 191 #endif … … 297 217 /******************************************************************* 298 218 * 299 * ANSI-C malloc-conforming functions 300 * 301 *******************************************************************/ 302 303 #include "ommalloc.c" 304 305 #ifdef OM_PROVIDE_MALLOC 306 #undef malloc 307 #undef realloc 308 #undef free 309 #undef calloc 310 #define ommallocFunc malloc 311 #define omreallocFunc realloc 312 #define omfreeFunc free 313 #define omcallocFunc calloc 314 #include "ommalloc.c" 315 #endif 316 219 * DoRealloc 220 * 221 *******************************************************************/ 222 #ifdef OM_ALIGNMNET_NEEDS_WORK 223 #define DO_ZERO(flag) (flag & 1) 224 #else 225 #define DO_ZERO(flag) flag 226 #endif 227 228 void* omDoRealloc(void* old_addr, size_t new_size, int flag) 229 { 230 void* new_addr; 231 232 if (!omIsBinPageAddr(old_addr) && new_size > OM_MAX_BLOCK_SIZE) 233 { 234 if (DO_ZERO(flag)) 235 return omRealloc0Large(old_addr, new_size); 236 else 237 return omReallocLarge(old_addr, new_size); 238 } 239 else 240 { 241 size_t old_size = omSizeOfAddr(old_addr); 242 size_t min_size; 243 244 omAssume(OM_IS_ALIGNED(old_addr)); 245 246 #ifdef OM_ALIGNMENT_NEEDS_WORK 247 if (flag & 2) 248 __omTypeAllocAligned(void*, new_addr, new_size); 249 else 250 #endif 251 __omTypeAlloc(void*, new_addr, new_size); 252 253 new_size = omSizeOfAddr(new_addr); 254 min_size = (old_size < new_size ? old_size : new_size); 255 omMemcpyW(new_addr, old_addr, min_size >> LOG_SIZEOF_LONG); 256 257 if (DO_ZERO(flag) && (new_size > old_size)) 258 omMemsetW((void*) new_addr + min_size, 0, (new_size - old_size) >> LOG_SIZEOF_LONG); 259 260 __omFreeSize(old_addr, old_size); 261 262 return new_addr; 263 } 264 } 317 265 318 266 #endif /* OM_ALLOC_C */ -
omalloc/omAlloc.h
recf4ca6 r3df5b10 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omAlloc.h,v 1. 3 2000-05-31 13:34:30obachman Exp $6 * Version: $Id: omAlloc.h,v 1.4 2000-08-14 12:08:44 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_ALLOC_H … … 13 13 #include <string.h> 14 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 15 19 #include "omConfig.h" 20 #include "omDerivedConfig.h" 21 #include "omError.h" 16 22 #include "omStructs.h" 17 #include "omError.h"18 23 #include "omAllocDecl.h" 24 #include "omInlineDecl.h" 19 25 #include "omBin.h" 20 #include "omCheck.h"21 26 #include "omMemOps.h" 22 27 #include "omList.h" 23 #include "omTrack.h" 28 #include "omFindExec.h" 29 #include "omGetBackTrace.h" 30 #include "omRet2Info.h" 24 31 #include "omStats.h" 25 32 #include "omOpts.h" 26 33 #include "omBinPage.h" 27 34 #include "omAllocSystem.h" 35 #include "omTables.h" 28 36 #include "omAllocPrivate.h" 37 #include "omDebug.h" 29 38 #include "omInline.h" 30 39 40 #ifdef __cplusplus 41 } 42 #endif 43 31 44 #endif /* OM_ALLOC_H */ -
omalloc/omConfig.h.in
recf4ca6 r3df5b10 5 5 * Author: obachman (Olaf Bachmann) 6 6 * Created: 11/99 7 * Version: $Id: omConfig.h.in,v 1. 3 2000-05-31 13:34:31obachman Exp $7 * Version: $Id: omConfig.h.in,v 1.4 2000-08-14 12:08:44 obachman Exp $ 8 8 *******************************************************************/ 9 9 #ifndef OM_CONFIG_H … … 13 13 * Defines which are set by configure 14 14 ******************************************************************/ 15 /* define if you provide an external config file to be included 16 by omDefaultConfig.h */ 17 #ifndef OM_HAVE_EXTERNAL_CONFIG_H 18 #define OM_HAVE_EXTERNAL_CONFIG_H 19 #endif 15 20 /* define if you can inline */ 16 21 #ifndef OM_INLINE … … 28 33 #ifndef OM_INLINE_LOCAL 29 34 #define OM_INLINE_LOCAL static 35 #endif 36 /* defint to nothing if you do not understand const */ 37 #ifndef const 38 #undef const 30 39 #endif 31 40 /* define to the name of addr2line program, undef otherwise */ … … 77 86 #define HAVE_SYS_MMAN_H 78 87 #endif 79 /* define to func which returns ith return addr*/80 #ifndef OM_ RETURN_ADDR81 #undef OM_ RETURN_ADDR88 /* define if GET_RETURN_ADDR works */ 89 #ifndef OM_GET_RETURN_ADDR_WORK 90 #undef OM_GET_RETURN_ADDR_WORKS 82 91 #endif 83 /* define to func which returns ith frame addr */ 84 #ifndef OM_FRAME_ADDR 85 #undef OM_FRAME_ADDR 86 #endif 87 /* define if OM_RETURN_ADDR actually works */ 88 #ifndef OM_RETURN_ADDR_WORKS 89 #undef OM_RETURN_ADDR_WORKS 90 #endif 91 /* define if OM_FRAME_ADDR actually works */ 92 #ifndef OM_FRAME_ADDR_WORKS 93 #undef OM_FRAME_ADDR_WORKS 94 #endif 95 /* define if OM_RETURN_ADDR actually rvalue */ 96 #ifndef OM_RETURN_ADDR_RVALUE 97 #undef OM_RETURN_ADDR_RVALUE 98 #endif 99 /* define if OM_FRAME_ADDR actually rvalue */ 100 #ifndef OM_FRAME_ADDR_RVALUE 101 #undef OM_FRAME_ADDR_RVALUE 92 /* define if GET_RETURN_ADDR works */ 93 #ifndef OM_GET_BACKTRACE_WORK 94 #undef OM_GET_BACKTRACE_WORKS 102 95 #endif 103 96 /* Define sizeof(long) */ … … 133 126 #undef OM_MALLOC_PROVIDES_SIZEOF_ADDR 134 127 #endif 135 #ifndef OM_PROVIDE_MALLOC136 /* define if you want omalloc to provide ANSI-C conforming137 malloc/calloc/realloc/free funcs */138 #undef OM_PROVIDE_MALLOC139 #endif140 128 #ifndef OM_EMULATE_OMALLOC 141 129 /* define if you only want to emulate omalloc, but not actually use it */ … … 154 142 #undef OM_HAVE_DENSE_BIN_DISTRIBUTION 155 143 #endif 144 /* define to disable all debugging stuff */ 145 #ifndef OM_NDEBUG 146 #undef OM_NDEBUG 147 #endif 148 /* define to enable debug tracking */ 149 #ifndef OM_HAVE_TRACK 150 #undef OM_HAVE_TRACK 151 #endif 152 /* define to enable tracking of files/line numbers */ 153 #ifndef OM_TRACK_FILE_LINE 154 #undef OM_TRACK_FILE_LINE 155 #endif 156 /* define to enable tracking of return addresses */ 157 #ifndef OM_TRACK_RETURN 158 #undef OM_TRACK_RETURN 159 #endif 160 /* define to enable tracking of stack backtraces */ 161 #ifndef OM_TRACK_BACKTRACE 162 #undef OM_TRACK_BACKTRACE 163 #endif 156 164 /* define to enable internal debugging */ 157 165 #ifndef OM_INTERNAL_DEBUG 158 166 #undef OM_INTERNAL_DEBUG 159 167 #endif 160 161 /******************************************************************* 162 * Defines which are not set by configure 163 ******************************************************************/ 164 #ifndef SIZEOF_VOIDP 165 /* configure makes sure that SIZEOF_VOIDP == SIZEOF_LONG */ 166 #define SIZEOF_VOIDP SIZEOF_LONG 168 /* define to -1/0/1/2/3 if you want omalloc to provide 169 "underlying malloc"/no/normal/debug ANSI-C conforming 170 malloc/calloc/realloc/free funcs */ 171 #ifndef OM_PROVIDE_MALLOC 172 #define OM_PROVIDE_MALLOC 0 167 173 #endif 168 169 /* SIZEOF_VOIDP == 8 || SIZEOF_VOIDP == 4 checked by configure */170 #if SIZEOF_VOIDP == 8171 #define LOG_SIZEOF_LONG 3172 #define LOG_SIZEOF_VOIDP 3173 #define LOG_BIT_SIZEOF_LONG 6174 #else175 #define LOG_SIZEOF_LONG 2176 #define LOG_SIZEOF_VOIDP 2177 #define LOG_BIT_SIZEOF_LONG 5178 #endif179 180 /* SIZEOF_SYSTEM_PAGE == 4096 || SIZEOF_SYSTEM_PAGE == 8192 checked by configure */181 #if SIZEOF_SYSTEM_PAGE == 8192182 #define LOG_BIT_SIZEOF_SYSTEM_PAGE 13183 #else184 #define LOG_BIT_SIZEOF_SYSTEM_PAGE 12185 #endif186 187 #ifndef CHAR_BIT188 #define CHAR_BIT 8189 #endif190 191 #define BIT_SIZEOF_LONG (CHAR_BIT << LOG_SIZEOF_LONG)192 193 #ifdef OM_ALIGN_8194 #define SIZEOF_OM_ALIGNMENT 8195 #define SIZEOF_OM_ALIGNMENT_1 7196 #define LOG_SIZEOF_OM_ALIGNMENT 3197 #define SIZEOF_STRICT_ALIGNMENT 8198 #else199 #define SIZEOF_OM_ALIGNMENT 4200 #define SIZEOF_OM_ALIGNMENT_1 3201 #define LOG_SIZEOF_OM_ALIGNMENT 2202 #ifdef OM_ALIGNMENT_NEEDS_WORK203 #define SIZEOF_STRICT_ALIGNMENT 8204 #else205 #define SIZEOF_STRICT_ALIGNMENT 4206 #endif207 #endif208 209 #define OM_ALIGN_SIZE(size) \210 (((size) + SIZEOF_OM_ALIGNMENT_1) & (~SIZEOF_OM_ALIGNMENT_1))211 212 #define OM_STRICT_ALIGN_SIZE(size) \213 (((size) + SIZEOF_STRICT_ALIGNMENT - 1) & (~ (SIZEOF_STRICT_ALIGNMENT - 1)))214 215 216 /* define to enable assume */217 #ifndef HAVE_OM_ASSUME218 #if !defined(NDEBUG) || defined(OM_INTERNAL_DEBUG)219 #define HAVE_OM_ASSUME220 #endif221 #endif222 223 /* set to 0 to disable aso memory mamagent */224 #ifndef HAVE_ASO225 #define HAVE_ASO 1226 #endif227 #if defined(HAVE_ASO) && HAVE_ASO == 1228 /* define to enable ASO debugging */229 #undef ASO_DEBUG230 #endif231 232 #ifndef NULL233 #define NULL ((void*)0)234 #endif235 236 174 #endif /* OM_CONFIG_H */ -
omalloc/omDebug.c
recf4ca6 r3df5b10 1 1 /******************************************************************* 2 * File: om Debug.c3 * Purpose: implementation of main om Debugfunctions2 * File: omTest.c 3 * Purpose: implementation of main omTest functions 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 * Created: 11/996 * Version: $Id: omDebug.c,v 1. 3 2000-05-31 13:34:31obachman Exp $5 * Created: 7/00 6 * Version: $Id: omDebug.c,v 1.4 2000-08-14 12:08:44 obachman Exp $ 7 7 *******************************************************************/ 8 #include <limits.h> 8 9 #include "omConfig.h" 9 10 #ifdef OM_HAVE_DEBUG11 12 10 #include "omAlloc.h" 13 11 #include "omDebug.h" 12 #include "omReturn.h" 13 14 #ifndef OM_NDEBUG 14 15 /******************************************************************* 15 16 * … … 17 18 * 18 19 *******************************************************************/ 19 /* number of bytes for padding before addr: needs to > 0 and a multiple of OM_SIZEOF_STRICT_ALIGNMENT */ 20 #ifndef OM_SIZEOF_FRONT_PADDING 21 #define OM_SIZEOF_FRONT_PADDING SIZEOF_STRICT_ALIGNMENT 22 #endif 23 /* number of bytes for padding after addr: needs to be a multiple of OM_SIZEOF_STRICT_ALIGNMENT */ 24 #ifndef OM_SIZEOF_BACK_PADDING 25 #define OM_SIZEOF_BACK_PADDING SIZEOF_STRICT_ALIGNMENT 26 #endif 27 28 struct omDebugAddr_s; 29 typedef struct omDebugAddr_s omDebugAddr_t; 30 typedef omDebugAddr_t * omDebugAddr; 31 32 struct omDebugAddr_s 33 { 34 char debug; 35 char check; 36 short alloc_line; 37 char* alloc_file; 38 /* debug > 1 */ 39 void* alloc_frames[OM_MAX_FRAMES]; 40 /* debug > 2 */ 41 void* size_bin; 42 omFlags_t flags; 43 omDebugCount_t debugs; 44 /* debug > 3 */ 45 short free_line; 46 char* free_file; 47 /* debug > 4 */ 48 void* free_frames[OM_MAX_FRAMES]; 49 }; 50 51 /* this is only needed to determine SIZEOF_DEBUG_ADDR_i */ 52 static struct omDebugAddr_s debug_addr; 53 #define OM_SIZEOF_DEBUG_ADDR_1 OM_STRICT_ALIGN_SIZE(((void*)&debug_addr.alloc_frames-(void*)&debug_addr)) 54 #define OM_SIZEOF_DEBUG_ADDR_2 OM_STRICT_ALIGN_SIZE(((void*)&debug_addr.size_bin-(void*)&debug_addr)) 55 #define OM_SIZEOF_DEBUG_ADDR_3 (OM_STRICT_ALIGN_SIZE(((void*)&debug_addr.free_line-(void*)&debug_addr))+SIZEOF_FRONT_PADDING) 56 #define OM_SIZEOF_DEBUG_ADDR_4 (OM_STRICT_ALIGN_SIZE(((void*)&debug_addr.free_frames-(void*)&debug_addr))+SIZEOF_FRONT_PADDING) 57 #define OM_SIZEOF_DEBUG_ADDR_5 OM_SIZEOF_DEBUG_ADDR 58 #define OM_SIZEOF_DEBUG_ADDR (OM_STRICT_ALIGN_SIZE(sizeof(struct omDebugAddr_s)) + SIZEOF_FRONT_PADDING) 59 60 OM_INLINE_LOCAL omDebugAddr omAddr_2_DebugAddr(void* addr) 61 { 62 void* page = omGetPageOfAddr(addr); 63 size_t size = omGetTopeBinOfPage((omBinPage) page)->sizeW << LOG_SIZEOF_LONG; 64 page += SIZEOF_OM_BIN_PAGE_HEADER; 65 return (omDebugAddr) (page + (void*) (((unsigned long)addr - (unsigned long)page) / size)*size); 66 } 67 68 #define OM_BIN_FLAG 1 /* size_bin is bin, if set, else size */ 69 #define OM_USED_FLAG 2 /* is in use, if set */ 70 #define OM_FREE_FLAG 4 /* had been freed, if set */ 71 #define OM_STATIC_FLAG 8 /* if set, considered to be static, i.e. never be freed */ 72 #define OM_MAX_FLAG 64 /* define, but never use it */ 73 #define SET_FLAG(var, flag) (var |= (flag)) 74 #define CLEAR_FLAG(var, flag) (var &= ~(flag)) 75 #define IS_FLAG_SET(var, flag) (var & (flag)) 76 77 78 #define _omDebugAddr_2_OutAddr(d_addr) (((void*) d_addr) + OM_SIZEOF_DEBUG_ADDR_HEADER) 79 #define _omOutAddr_2_DebugAddr(addr) ((omDebugAddr) ((void*) addr - OM_SIZEOF_DEBUG_ADDR_HEADER)) 80 #define _omOutSize_2_DebugSize(size) (size + OM_SIZEOF_DEBUG_ADDR_HEADER + OM_SIZEOF_BACK_PADDING) 81 #define _omDebugSize_2_OutSize(size) (size - OM_SIZEOF_DEBUG_ADDR_HEADER - OM_SIZEOF_BACK_PADDING) 82 20 21 static void* __omDebugAlloc(void* size_bin, omTrackFlags_t flags, char track, OM_FLR_DECL); 22 static void* __omDebugRealloc(void* old_addr, void* old_size_bin, void* new_size_bin, 23 omError_t old_status, omTrackFlags_t old_flags, 24 omTrackFlags_t new_flags, 25 char track, OM_FLR_DECL); 26 static void __omDebugFree(void* addr, void* size_bin, omTrackFlags_t flags, OM_FLR_DECL); 27 28 void* om_KeptAddr = NULL; 29 static unsigned long om_NumberOfKeptAddrs = 0; 30 static void* om_LastKeptAddr = NULL; 31 32 /******************************************************************* 33 * 34 * Test routines 35 * 36 *******************************************************************/ 37 #define OM_CLFL check_level OM_FL_KOMMA OM_FL 38 omError_t omTestAddrBin(void* addr, omBin bin, int check_level) 39 { 40 return _omDebugAddr(addr,bin,OM_FBIN,OM_CLFL); 41 } 42 omError_t omTestAddrSize(void* addr, size_t size, int check_level) 43 { 44 return _omDebugAddr(addr,(void*)(size),OM_FSIZE,OM_CLFL); 45 } 46 omError_t omTestAddr(void* addr, int check_level) 47 { 48 return _omDebugAddr(addr,NULL, 0, OM_CLFL); 49 } 50 omError_t omtestAddrSize(void* addr, size_t size, int check_level) 51 { 52 return _omDebugAddr(addr,(void*)(size),OM_FSIZE|OM_FSLOPPY,OM_CLFL); 53 } 54 omError_t omtestAddr(void* addr, int check_level) 55 { 56 return _omDebugAddr(addr,NULL, OM_FSLOPPY, OM_CLFL); 57 } 58 59 omError_t omTestAddrAlignedBin(void* addr, omBin bin, int check_level) 60 { 61 return _omDebugAddr(addr,bin,OM_FBIN|OM_FALIGN,OM_CLFL); 62 } 63 omError_t omTestAddrAlignedSize(void* addr, size_t size, int check_level) 64 { 65 return _omDebugAddr(addr,(void*)(size),OM_FSIZE|OM_FALIGN,OM_CLFL); 66 } 67 omError_t omTestAddrAligned(void* addr, int check_level) 68 { 69 return _omDebugAddr(addr,NULL, OM_FALIGN, OM_CLFL); 70 } 71 omError_t omtestAddrAlignedSize(void* addr, size_t size, int check_level) 72 { 73 return _omDebugAddr(addr,(void*)(size),OM_FSIZE|OM_FSLOPPY|OM_FALIGN,OM_CLFL); 74 } 75 omError_t omtestAddrAligned(void* addr, int check_level) 76 { 77 return _omDebugAddr(addr,NULL, OM_FSLOPPY|OM_FALIGN, OM_CLFL); 78 } 79 80 omError_t omTestBin(omBin bin, int check_level) 81 { 82 return _omDebugBin(bin, OM_CLFL); 83 } 84 omError_t omTestMemory(int check_level) 85 { 86 return _omDebugMemory(OM_CLFL); 87 } 88 89 #undef MAX 90 #define MAX(a,b) (a > b ? a : b) 91 /******************************************************************* 92 * 93 * First level _omDebug alloc/free routines: call respective checks and dispatch 94 * to routines which do the actual work 95 * 96 *******************************************************************/ 97 void* _omDebugAlloc(void* size_bin, omTrackFlags_t flags, OM_CTFL_DECL) 98 { 99 void* addr; 100 OM_R_DEF; 101 check = MAX(check, om_Opts.MinCheck); 102 track = MAX(track, om_Opts.MinTrack); 103 104 if (check) 105 { 106 if (check > 1) 107 { 108 if (flags & OM_FBIN) 109 (void) _omCheckBin((omBin)size_bin, 1, check-1, omError_MemoryCorrupted, OM_FLR_VAL); 110 else if (check > 2) 111 { 112 omAssume(flags & OM_FSIZE); 113 (void) _omCheckMemory(check-2, omError_MemoryCorrupted, OM_FLR_VAL); 114 } 115 } 116 if (size_bin == NULL && ! (flags & OM_FSLOPPY)) 117 { 118 omReportError(omError_NullSizeAlloc, omError_NoError, OM_FLR_VAL, ""); 119 } 120 } 121 122 addr = __omDebugAlloc(size_bin, flags, track, OM_FLR_VAL); 123 83 124 #ifdef OM_INTERNAL_DEBUG 84 static void* omDebugAddr_2_OutAddr(void* d_addr) {return _omDebugAddr_2_OutAddr(d_addr);} 85 static void* omOutAddr_2_DebugAddr(void* addr) {return _omOutAddr_2_DebugAddr(addr);} 86 static size_t omOutSize_2_DebugSize(size_t size) {return _omOutSize_2_DebugSize(size);} 87 static size_t omDebugSize_2_OutSize(size_t size) {return _omOutSize_2_DebugSize(size);} 88 #else 89 #define omDebugAddr_2_OutAddr _omDebugAddr_2_OutAddr 90 #define omOutAddr_2_DebugAddr _omOutAddr_2_DebugAddr 91 #define omOutSize_2_DebugSize _omOutSize_2_DebugSize 92 #define omDebugSize_2_OutSize _omDebugSize_2_OutSize 93 #endif 94 95 static void* om_Frames[OM_MAX_FRAMES]; 96 125 (void) _omCheckAddr(addr, size_bin,flags|OM_FUSED,check, omError_InternalBug, OM_FLR); 126 #endif 127 128 return addr; 129 } 130 131 132 void* _omDebugRealloc(void* old_addr, void* old_size_bin, void* new_size_bin, 133 omTrackFlags_t old_flags, omTrackFlags_t new_flags, OM_CTFL_DECL) 134 { 135 void* new_addr = NULL; 136 omError_t status = omError_NoError; 137 OM_R_DEF; 138 check = MAX(check, om_Opts.MinCheck); 139 track = MAX(track, om_Opts.MinTrack); 140 141 if (check) 142 { 143 status = _omCheckAddr(old_addr, old_size_bin, old_flags|OM_FUSED, check, omError_NoError, OM_FLR_VAL); 144 145 if (status == omError_NoError && check > 1 && new_flags & OM_FBIN) 146 status = omDoCheckBin((omBin)new_size_bin, 1, check-1, omError_MemoryCorrupted, OM_FLR_VAL); 147 148 if (new_size_bin == NULL && !(new_flags & OM_FSLOPPY)) 149 { 150 omReportError(omError_NullSizeAlloc, omError_NoError, OM_FLR_VAL, ""); 151 new_size_bin = (void*) 1; 152 } 153 } 154 155 new_addr = __omDebugRealloc(old_addr, old_size_bin, new_size_bin, 156 status, old_flags, new_flags, track, OM_FLR_VAL); 157 #ifdef OM_INTERNAL_DEBUG 158 if (status == omError_NoError) 159 (void) _omCheckAddr(new_addr, new_size_bin,new_flags|OM_FUSED,check, omError_InternalBug, OM_FLR); 160 #endif 161 162 return new_addr; 163 } 164 165 void _omDebugFree(void* addr, void* size_bin, 166 omTrackFlags_t flags, OM_CFL_DECL) 167 { 168 OM_R_DEF; 169 check = MAX(check, om_Opts.MinCheck); 170 if (check && _omCheckAddr(addr, size_bin, flags|OM_FUSED, check, omError_NoError, OM_FLR_VAL)) return; 171 172 __omDebugFree(addr,size_bin,flags, OM_FLR_VAL); 173 174 #ifdef OM_INTERNAL_DEBUG 175 if (flags & OM_FBIN) 176 (void) _omCheckBin((omBin)size_bin, 1, check-1,omError_InternalBug, OM_FLR); 177 else 178 (void) _omCheckMemory(check-2,omError_InternalBug,OM_FLR); 179 #endif 180 } 181 182 void* _omDebugMemDup(void* addr, omTrackFlags_t flags, OM_CTFL_DECL) 183 { 184 void* ret; 185 size_t sizeW; 186 OM_R_DEF; 187 188 check = MAX(check, om_Opts.MinCheck); 189 track = MAX(track, om_Opts.MinTrack); 190 191 if (check & _omCheckAddr(addr, 0, OM_FUSED, check, omError_NoError, OM_FLR_VAL)) 192 { 193 return NULL; 194 } 195 else 196 { 197 sizeW = omSizeWOfAddr(addr); 198 } 199 200 ret = __omDebugAlloc((void*) (sizeW << LOG_SIZEOF_LONG), OM_FSIZE | flags, track, OM_FLR_VAL); 201 omMemcpyW(ret, addr, sizeW); 202 203 #ifdef OM_INTERNAL_DEBUG 204 (void) _omCheckAddr(ret, (void*) (sizeW << LOG_SIZEOF_LONG),OM_FUSED|OM_FSIZE, 205 check, omError_InternalBug, OM_FLR); 206 #endif 207 return ret; 208 } 209 210 char* _omDebugStrDup(const char* addr, OM_TFL_DECL) 211 { 212 unsigned long size, i=0; 213 char* ret; 214 OM_R_DEF; 215 216 if (addr == NULL) 217 { 218 omReportAddrError(omError_NotString, omError_NoError, addr, 0, 0, OM_FLR_VAL, "NULL String"); 219 return NULL; 220 } 221 track = MAX(track, om_Opts.MinTrack); 222 223 if (omIsBinPageAddr(addr)) 224 { 225 size = omSizeOfAddr(addr); 226 } 227 else 228 { 229 size = ULONG_MAX; 230 } 231 232 while (addr[i] != '\0' && i < size) i++; 233 if (i == size) 234 { 235 omReportAddrError(omError_NotString, omError_NoError, addr, 0, 0, OM_FLR_VAL, "Not 0 terminated"); 236 i = size-1; 237 } 238 ret = __omDebugAlloc((void*)i+1, OM_FSIZE, track, OM_FLR_VAL); 239 memcpy(ret, addr, i); 240 ret[i] = '\0'; 241 242 #ifdef OM_INTERNAL_DEBUG 243 (void) _omCheckAddr(ret, i+1,OM_FUSED|OM_FSIZE,om_Opts.MinCheck, omError_InternalBug, OM_FLR); 244 #endif 245 return ret; 246 } 247 248 omError_t _omDebugAddr(void* addr, void* bin_size, omTrackFlags_t flags, OM_CFL_DECL) 249 { 250 OM_R_DEF; 251 return _omCheckAddr(addr, bin_size, 252 OM_FUSED|flags,MAX(check,om_Opts.MinCheck),omError_NoError,OM_FLR_VAL); 253 } 254 omError_t _omDebugMemory(OM_CFL_DECL) 255 { 256 OM_R_DEF; 257 return _omCheckMemory(MAX(check, om_Opts.MinCheck), omError_NoError,OM_FLR_VAL); 258 } 259 omError_t _omDebugBin(omBin bin, OM_CFL_DECL) 260 { 261 OM_R_DEF; 262 return _omCheckBin(bin, 1, MAX(check, om_Opts.MinCheck), omError_NoError,OM_FLR_VAL); 263 } 264 97 265 /******************************************************************* 98 266 * 99 * Public routines --they are just dispatcher to equivalent first-level, 100 * i.e., _om* routines 267 * Second level _omDebug alloc/free routines: do the actual work 101 268 * 102 269 *******************************************************************/ 103 104 void* omTestAllocBin(omBin bin, char check, char debug, char* file, int line) 105 { 106 return _omTestAlloc(bin, 107 OM_BIN_FLAGS,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 108 } 109 void* omTestAlloc0Bin(omBin bin, char check, char debug, char* file, int line) 110 { 111 return _omTestAlloc(bin, 112 OM_BIN_FLAG|OM_ZERO_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 113 } 114 void* omTestReallocBin(void* old_addr, omBin old_bin, omBin new_bin, char check, char debug, char* file, int line) 115 { 116 return _omTestRealloc(old_addr, old_bin, new_bin, 117 OM_BIN_FLAG,OM_BIN_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 118 } 119 void* omTestRealloc0Bin(void* old_addr, omBin old_bin, omBin new_bin, char check, char debug, char* file, int line) 120 { 121 return _omTestRealloc(old_addr, old_bin, new_bin, 122 OM_BIN_FLAG,OM_BIN_FLAG|OM_ZERO_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 123 } 124 void omTestFreeBin(void* addr, omBin bin, char check, char* file, int line) 125 { 126 _omTestFree(addr, bin, 127 OM_BIN_FLAG,MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR); 128 } 129 130 void* omTestAlloc(size_t size, char check, char debug, char* file, int line) 131 { 132 return _omTestAlloc(size, 133 OM_SIZE_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 134 } 135 void* omTestAlloc0(size_t size, char check, char debug, char* file, int line) 136 { 137 return _omTestAlloc(size, 138 OM_SIZE_FLAG|OM_ZERO_FLAG, MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 139 } 140 void* omTestAllocAligned(size_t size, char check, char debug, char* file, int line) 141 { 142 return _omTestAlloc(size, 143 OM_SIZE_FLAG|OM_ALIGNED_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 144 } 145 void* omTestAlloc0Aligned(size_t size, char check, char debug, char* file, int line) 146 { 147 return _omTestAlloc(size, 148 OM_SIZE_FLAG|OM_ALIGNED_FLAG|OM_ZERO_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 149 } 150 151 void* omTestRealloc(void* addr, size_t new_size, char check, char debug, char* file, int line) 152 { 153 return _omTestRealloc(addr, NULL, new_size, 154 0,OM_SIZE_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 155 } 156 void* omTestRealloc0(void* addr, size_t new_size, char check, char debug, char* file, int line) 157 { 158 return _omTestRealloc(addr, NULL, new_size, 159 0, OM_SIZE_FLAG|OM_ZERO_FLAG, MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 160 } 161 void* omTestReallocAligned(void* addr, size_t new_size, char check, char debug, char* file, int line) 162 { 163 return _omTestRealloc(addr, NULL, new_size, 164 0,OM_SIZE_FLAG|OM_ALIGNED_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR); 165 } 166 void* omTestRealloc0Aligned(void* addr, size_t new_size, char check, char debug, char* file, int line) 167 { 168 return _omTestRealloc(addr, NULL, new_size, 169 0,OM_SIZE_FLAG|OM_ZERO_FLAG|OM_ALIGNED_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR,OM_REALLOC0_ALIGNED); 170 } 171 172 void* omTestReallocSize(void* addr, size_t old_size, size_t new_size, char check, char debug, char* file, int line) 173 { 174 return _omTestRealloc(addr, old_size, new_size, 175 OM_SIZE_FLAG,OM_SIZE_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR,OM_REALLOC_SIZE); 176 } 177 void* omTestRealloc0Size(void* addr, size_t old_size, size_t new_size, char check, char debug, char* file, int line) 178 { 179 return _omTestRealloc(addr, old_size, new_size, 180 OM_SIZE_FLAG,OM_SIZE_FLAG|OM_ZERO_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR,OM_REALLOC0_SIZE); 181 } 182 void* omTestReallocAlignedSize(void* addr, size_t old_size, size_t new_size, char check, char debug, char* file, int line) 183 { 184 return _omTestRealloc(addr, old_size, new_size, 185 OM_SIZE_FLAG,OM_SIZE_FLAG|OM_ALIGNED_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR,OM_REALLOC_ALIGNED_SIZE); 186 } 187 void* omTestRealloc0AlignedSize(void* addr, size_t old_size, size_t new_size, char check, char debug, char* file, int line) 188 { 189 return _omTestRealloc(addr, old_size, new_size, 190 OM_SIZE_FLAG,OM_SIZE_FLAG|OM_ZERO_FLAG|OM_ALIGNED_FLAG,MAX(check,om_Opts.MinCheck),MAX(debug,om_Opts.MinDebug),f,l,OM_DEBUG_RETURN_ADDR,OM_REALLOC0_ALIGNED_SIZE); 191 } 192 193 void omTestFreeSize(void* addr, size_t size, char check, char* file, int line) 194 { 195 _omTestFree(addr, size, 196 OM_SIZE_FLAG, MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR,OM_FREE_SIZE); 197 } 198 void omTestFree(void* addr, size_t size, char check, char* file, int line) 199 { 200 _omTestFree(addr, NULL, 201 0, MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR,OM_FREE); 202 } 203 204 omError_t omTestAddrBin(void* addr, omBin bin, char check, char* file, int line) 205 { 206 return _omTestAddr(addr, bin, 207 OM_USED_FLAG|OM_BIN_FLAG|OM_COUNT_FLAG, MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR); 208 } 209 omError_t omTestAddrSize(void* addr, size_t size, char check, char* file, int line) 210 { 211 return _omTestAddr(addr, size, 212 OM_USED_FLAG|OM_SIZE_FLAG|OM_COUNT_FLAG, MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR); 213 } 214 omError_t omTestAddr(void* adr, char check, char* file, int line) 215 { 216 return _omTestAddr(addr, NULL, 217 OM_USED_FLAG|OM_COUNT_FLAG,MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR); 218 } 219 omError_t omTestAlignedAddrBin(void* addr, omBin bin, char check, char* file, int line) 220 { 221 return _omTestAddr(addr, bin, 222 OM_USED_FLAG|OM_BIN_FLAG|OM_ALIGNED_FLAG|OM_COUNT_FLAG, MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR); 223 } 224 omError_t omTestAlignedAddr(void* adr, char check, char* file, int line) 225 { 226 return _omTestAddr(addr, bin, 227 OM_USED_FLAG|OM_BIN_FLAG|OM_ALIGNED_FLAG|OM_COUNT_FLAG,MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR); 228 } 229 omError_t omTestAlignedAddrSize(void* addr, size_t size, char check, char* file, int line) 230 { 231 return _omTestAddr(addr, bin, 232 OM_USED_FLAG|OM_BIN_FLAG|OM_ALIGNED_FLAG|OM_COUNT_FLAG, MAX(check,om_Opts.MinCheck),f,l,OM_DEBUG_RETURN_ADDR); 233 } 234 235 /* TBC */ 236 omError_t omTestBin(omBin bin, char check, char* file, int line) 237 { 238 return omError_NoError; 239 } 240 omError_t omTestMemory(char check, char debug) 241 { 242 return omError_NoError; 243 } 244 245 /******************************************************************* 246 * 247 * First level _om* routines: call respective checks and dispatch 248 * to second level, i.e., __om routines 249 * 250 *******************************************************************/ 251 static void* _omTestAlloc(void* bin_size, 252 int flags, char check, char debug,char* f,const int l,void* r) 253 { 254 void* addr; 255 256 om_ReportError = omError_MemoryCorrupted; 257 if (flags & BIN_FLAG) 258 (void) _omTestBin((omBin)bin_size,check-1,f,l,r); 259 else 260 (void) _omTestMemory(check-2,f,l,r); 261 262 addr = __omTestAlloc(bin_size, flags, debug, f, l, r); 263 264 #ifdef OM_INTERNAL_DEBUG 265 om_ReportError = omError_InternalBug; 266 (void) _omTestAddr(addr, bin_size,flags|OM_USED_FLAGS,check, __FILE__,__LINE__,0); 267 #endif 268 269 om_ReportError = omError_NoError; 270 return new_addr; 271 } 272 273 274 static void* _omTestRealloc(void* old_addr, void* old_bin_size, void* new_bin_size, 275 int old_flags, int new_flags, char check, char debug, char* f, const int l, void* r) 276 { 277 void* new_addr = NULL; 278 279 (void*) _omTestAddr(old_addr, old_flags|OM_USED_FLAG, old_bin_size, check, f, l, r); 280 281 new_addr = __omTestRealloc(old_addr, old_bin_size, new_bin_size, 282 old_flags, new_flags, debug, f, l, r); 283 #ifdef OM_INTERNAL_DEBUG 284 om_ReportError = omError_InternalBug; 285 (void) _omTestAddr(new_addr, bin_size,flags|OM_USED_FLAGS,check, __FILE__,__LINE__,0); 286 om_ReportError = omError_NoError; 287 #endif 288 289 return new_addr; 290 } 291 292 293 static void _omTestFree(void* addr, void* size_bin, 294 int flags, char check, char* f, const int l, void* r) 295 { 296 if (! _omTestAddr(addr, size_bin, flags, check, f, l, r)) 297 __omTestFree(addr,size_bin,flags,f,l,r); 298 299 #ifdef OM_INTERNAL_DEBUG 300 om_ReportError = omError_InternalBug; 301 if (flags & BIN_FLAG) 302 (void) _omTestBin((omBin)bin_size,check-1,__FILE__,__LINE__,0); 303 else 304 (void) _omTestMemory(check-2,__FILE__,__LINE__,0); 305 om_ReportError = omError_NoError; 306 #endif 307 } 308 309 310 static omError_t _omTestAddr(void* addr, void* size_bin, 311 int flags, char check, char* f, const int l, void* r) 312 { 313 if (check <= 0) return omError_NoError; 314 315 if (!__omPrimitiveTestAddr(addr, size_bin, flags, f, l, r) || 316 !__omTestAddr(addr, size_bin, flags, f, l, r)) 317 return om_ErrorStatus; 318 319 if (check > 1) 320 { 321 if (omIsDebugAddr(addr)) 322 { 323 if (! _omTestBin(omGetBinOfAddr(addr), 1,check-1, f, l, r)) 324 return om_ErrorStatus; 325 if (flags & OM_BIN_FLAG) 326 return _omTestBin((omBin) bin_size, 0, check - 1, f, l, r); 327 } 328 else 329 { 330 if (omIsBinAddr(addr)) 331 return _omTestBin(omGetBinOfAddr(addr), 0, check-1, f, l, r); 332 else if (check > 2) 333 return _omTestMemory(check-2, f, l, r); 334 } 335 } 336 337 return om_ErrorStatus = omError_NoError; 338 } 339 340 341 static omError_t _omTestBin(omBin bin, char is_debug_bin, 342 char check, char* f, const int l, void* r) 343 { 344 if (check <= 0) return omError_NoError; 345 346 if (! __omPrimitiveTestBin(bin, f, l, r) || 347 ! __omTestBin(bin, is_debug_bin, check - 1, f, l, r)) 348 return om_ErrorStatus; 349 350 if (check > 1) 351 return _omTestMemory(check - 1, f, l, r); 352 353 return om_ErrorStatus = omError_NoError; 354 } 355 356 357 static omError_t _omTestMemory(char check, char* f, const int l, void* r) 358 { 359 int i = 0; 360 omSpecBin s_bin; 361 void* addr; 362 363 if (check <= 0) return omError_NoError; 364 365 if (! omTestBinPagesReagions(check, f, l, r)) return om_ErrorStatus; 366 367 for (i=0; i<= OM_MAX_BIN_INDEX; i++) 368 { 369 if (! __omTestBin(&om_StaticBin[i], 0, check - 1, f, l, r)) 370 return om_ErrorStatus; 371 } 372 373 for (i=0; i<= OM_MAX_DEBUG_BIN_INDEX; i++) 374 { 375 if (! __omTestBin(&om_StaticDebugBin[i], 1, check -1, f, l, r)) 376 return om_ErrorStatus; 377 } 378 379 s_bin = om_SpecBin; 380 while (s_bin != NULL) 381 { 382 if (! __omTestBin(s_bin->bin, 0,check - 1, f, l, r)) 383 return om_ErrorStatus; 384 s_bin = s_bin->next; 385 } 386 387 388 addr = FirstKeptDebugAddr; 389 390 while (addr != NULL) 391 { 392 if (! __omTestAddr(addr, NULL, OM_FREE_FLAG, f, l, r)) 393 return om_ErrorStatus; 394 addr = *((void**) addr); 395 } 396 397 return om_ErrorStatus = omError_NoError; 398 } 399 400 /******************************************************************* 401 * 402 * Second level __om* routines: do the actual work, no checks, 403 * assume that everything is ok 404 * 405 *******************************************************************/ 406 static void* __omTestAlloc(void* bin_size, 407 int flags, char check, char debug,char* f,const int l,void* r) 270 static void* __omDebugAlloc(void* size_bin, omTrackFlags_t flags, char track, OM_FLR_DECL) 408 271 { 409 272 void* o_addr; 410 o_size = (flags & OM_BIN_FLAG ? ((omBin)bin)->sizeW << LOG_SIZEOF_LONG : (size_t) bin_size); 411 412 if (debug > 0) 413 { 414 omDebugAddr d_addr; 415 size_t d_size, o_size; 416 417 d_size = omOutSize_2_DebugSize(o_size, debug); 418 419 d_addr = omAllocDebugAddr(d_size); 420 421 d_addr->next = (void*) -1; 422 d_addr->debug = debug; 423 d_addr->alloc_file = f; 424 d_addr->alloc_line = l; 425 426 if (debug > 1) 427 { 428 memset(&d_addr->alloc_frames, 0, OM_MAX_FRAMES*SIZEOF_VOIDP); 429 omGetCurrentBackTrace(&d_addr->alloc_frames, OM_MAX_FRAMES, r); 430 431 if (debug > 2) 432 { 433 char* pattern; 434 435 d_addr->size_bin = size_bin; 436 d_addr->flags = flags | USED_FLAG; 437 d_addr->debugs = 0; 438 439 if (debug > 3) 440 { 441 d_addr->free_line = -1; 442 d_addr->free_file = (char*) -1; 443 444 if (debug > 4) 445 memset(&d_addr->free_frames, 0, OM_MAX_FRAMES*SIZEOF_VOIDP); 446 } 447 448 memset(omDebugAddr_2_FrontPattern(d_addr), OM_FRONT_PATTER, OM_SIZEOF_FRONT_PATTERN); 449 memset(omDebugAddr_2_BackPattern(d_addr), OM_BACK_PATTER, omDebugAddr_2_BackPatternSize(d_addr)); 450 } 451 } 452 o_addr = omDebugAddr_2_OutAddr(d_addr); 453 if (flags & OM_ZERO_FLAG) memset(o_addr, 0, o_size); 273 size_t o_size = (flags & OM_FBIN ? ((omBin)size_bin)->sizeW << LOG_SIZEOF_LONG : (size_bin != NULL ? (size_t) size_bin: 1)); 274 275 #ifdef OM_HAVE_TRACK 276 if (track > 0) 277 { 278 o_addr = omAllocTrackAddr(size_bin, flags, track, OM_FLR_VAL); 454 279 } 455 280 else 456 { 457 if (flags & OM_BIN_FLAG) 458 { 459 omBin bin = (omBin) bin_size; 460 461 if (flags & ZERO_FLAG) 462 __omTypeAllo0cBin(void*, o_addr, bin); 281 #endif 282 { 283 if (flags & OM_FBIN) 284 { 285 omBin bin = (omBin) size_bin; 286 287 if (flags & OM_FZERO) 288 __omTypeAlloc0Bin(void*, o_addr, bin); 463 289 else 464 290 __omTypeAllocBin(void*, o_addr, bin); … … 466 292 else 467 293 { 468 if (flags & ZERO_FLAG)294 if (flags & OM_FZERO) 469 295 { 470 if (flags & OM_ALIGNED_FLAG) 296 #ifdef OM_ALIGNMENT_NEEDS_WORK 297 if (flags & OM_FALIGN) 471 298 __omTypeAlloc0Aligned(void*, o_addr, o_size); 472 299 else 300 #endif 473 301 __omTypeAlloc0(void*, o_addr, o_size); 474 302 } 475 303 else 476 304 { 477 if (flags & OM_ALIGNED_FLAG) 305 #ifdef OM_ALIGNMENT_NEEDS_WORK 306 if (flags & OM_FALIGN) 478 307 __omTypeAllocAligned(void*, o_addr, o_size); 479 308 else 309 #endif 480 310 __omTypeAlloc(void*, o_addr, o_size); 481 311 } … … 483 313 } 484 314 485 if (! (flags & OM_ZERO_FLAG)) memset(o_addr, OM_INIT_PATTERN, o_size);486 487 315 return o_addr; 488 316 } 489 static omDebugAddr omAllocDebugAddr(size_t d_size) 490 { 491 omDebugAddr d_addr; 492 omBin bin; 493 494 if (d_size <= OM_MAX_DEBUG_BLOCK_SIZE) 495 bin = omSize2DebugBin(d_size); 317 318 static void* __omDebugRealloc(void* old_addr, void* old_size_bin, void* new_size_bin, 319 omError_t old_status, omTrackFlags_t old_flags, omTrackFlags_t new_flags, 320 char track, OM_FLR_DECL) 321 { 322 void* new_addr; 323 size_t old_size = (old_flags & OM_FSIZE ? (size_t) old_size_bin : 324 (omSizeOfAddr(old_addr))); 325 size_t new_size; 326 327 omAssume(new_flags & OM_FSIZE || new_flags & OM_FBIN); 328 329 if (old_addr == NULL || ((old_flags & OM_FSIZE) && old_size_bin == NULL)) 330 { 331 new_addr = __omDebugAlloc(new_size_bin, new_flags, track, OM_FLR_VAL); 332 } 333 else if (om_Opts.Keep > 0 || track > 0 || omIsTrackAddr(old_addr) || old_status != omError_NoError) 334 { 335 new_addr = __omDebugAlloc(new_size_bin, new_flags, track, OM_FLR_VAL); 336 new_size = omSizeOfAddr(new_addr); 337 old_size = omSizeOfAddr(old_addr); 338 339 memcpy(new_addr, old_addr, (old_size < new_size ? old_size : new_size)); 340 341 if ((new_flags & OM_FZERO) && new_size > old_size) 342 memset(new_addr + old_size, 0, new_size - old_size); 343 if (old_status == omError_NoError) __omDebugFree(old_addr, old_size_bin, old_flags, OM_FLR_VAL); 344 } 496 345 else 497 bin = omGetSpecBin(d_size); 498 499 __omTypeAllocBin(omTestAddr, d_addr, bin); 500 501 omAssume(bin->current_page == omGetPageOfAddr(d_addr)); 502 503 omSetDebugOfUsedBlocks(bin->current_page->used_blocks); 504 505 return d_addr; 506 } 507 508 509 static void* __omTestRealloc(void* old_addr, void* old_bin_size, void* new_bin_size, 510 int old_flags, int new_flags, char debug, char* f,const int l,void* r) 511 { 512 void* new_addr; 513 514 if (om_Opts.Keep > 0 || debug > 0 || omIsDebugAddr(old_addr)) 515 { 516 new_addr = __omTestAlloc(new_bin_size, new_flags, debug, f, l, r); 517 memcpy(new_addr, old_addr, omSizeOfAddr(old_addr)); 518 __omTestFree(old_addr, old_bin_size, old_flags, f, l, r); 519 } 520 else 521 { 522 if (new_flags & OM_BIN_FLAG) 523 { 524 omBin new_bin = (omBin) new_bin_size; 525 omBin old_bin = (omBin) old_bin_size; 346 { 347 if (new_flags & OM_FBIN) 348 { 349 omBin new_bin = (omBin) new_size_bin; 350 omBin old_bin = (omBin) old_size_bin; 526 351 527 omAssume(old_flags & OM_ BIN_FLAG);528 if (new_flags & OM_ ZERO_FLAG)352 omAssume(old_flags & OM_FBIN); 353 if (new_flags & OM_FZERO) 529 354 __omTypeRealloc0Bin(old_addr, old_bin, void*, new_addr, new_bin); 530 355 else … … 533 358 else 534 359 { 535 size_t new_size = (size_t) new_bin_size; 536 omAssume(!(new_flags & OM_BIN_FLAG) && !(old_flags & OM_BIN_FLAG)); 360 new_size = (size_t) new_size_bin; 361 if (new_size == 0) new_size = 1; 362 omAssume(!(new_flags & OM_FBIN) && !(old_flags & OM_FBIN)); 537 363 538 if ( flags & OM_SIZE_FLAG)364 if (old_flags & OM_FSIZE) 539 365 { 540 size_t old_size = (size_t) old_ bin_size;366 size_t old_size = (size_t) old_size_bin; 541 367 542 if (new_flags & OM_ ZERO_FLAG)368 if (new_flags & OM_FZERO) 543 369 { 544 if (new_flags & OM_ALIGNED_FLAG) 545 __omTypeRealloc0AlignedSize(old_addr, old_size, (void*), new_addr, new_size); 370 #ifdef OM_ALIGNMENT_NEEDS_WORK 371 if (new_flags & OM_FALIGN) 372 __omTypeRealloc0AlignedSize(old_addr, old_size, void*, new_addr, new_size); 546 373 else 547 __omTypeRealloc0Size(old_addr, old_size, (void*), new_addr, new_size); 374 #endif 375 __omTypeRealloc0Size(old_addr, old_size, void*, new_addr, new_size); 548 376 } 549 377 else 550 378 { 551 if (new_flags & OM_ALIGNED_FLAG) 552 __omTypeReallocAlignedSize(old_addr, old_size, (void*), new_addr, new_size); 379 #ifdef OM_ALIGNMENT_NEEDS_WORK 380 if (new_flags & OM_FALIGN) 381 __omTypeReallocAlignedSize(old_addr, old_size, void*, new_addr, new_size); 553 382 else 554 __omTypeReallocSize(old_addr, old_size, (void*), new_addr, new_size); 383 #endif 384 __omTypeReallocSize(old_addr, old_size, void*, new_addr, new_size); 555 385 } 556 386 } 557 387 else 558 388 { 559 if (new_flags & OM_ ZERO_FLAG)389 if (new_flags & OM_FZERO) 560 390 { 561 if (new_flags & OM_ALIGNED_FLAG) 562 __omTypeRealloc0Aligned(old_addr, (void*), new_addr, new_size); 391 #ifdef OM_ALIGNMENT_NEEDS_WORK 392 if (new_flags & OM_FALIGN) 393 __omTypeRealloc0Aligned(old_addr, void*, new_addr, new_size); 563 394 else 564 __omTypeRealloc0(old_addr, (void*), new_addr, new_size); 395 #endif 396 __omTypeRealloc0(old_addr, void*, new_addr, new_size); 565 397 } 566 398 else 567 399 { 568 if (new_flags & OM_ALIGNED_FLAG) 569 __omTypeReallocAligned(old_addr, (void*), new_addr, new_size); 400 #ifdef OM_ALIGNMENT_NEEDS_WORK 401 if (new_flags & OM_FALIGN) 402 __omTypeReallocAligned(old_addr, void*, new_addr, new_size); 570 403 else 571 __omTypeRealloc(old_addr, (void*), new_addr, new_size); 404 #endif 405 __omTypeRealloc(old_addr, void*, new_addr, new_size); 572 406 } 573 407 } 574 408 } 575 409 } 576 577 410 return new_addr; 578 411 } 579 412 580 581 unsigned long om_NumberOfKeptAddrs = 0; 582 omDebugAddr om_FirstKeptDebugAddr = NULL; 583 omDebugAddr om_LastKeptDebugAddr = NULL; 584 static void __omTestFree(void* addr, void* size_bin, int flags, char* f,const int l,void* r) 585 { 586 if (omIsDebugAddr(addr)) 587 { 588 omDebugAddr d_addr = omOutAddr_2_DebugAddr(addr); 589 590 d_addr->next = NULL; 591 592 if (d_addr->debug > 2) 593 { 594 d_addr->flags &= ~OM_USED_FLAG; 595 d_addr->flags |= OM_FREE_FLAG; 596 597 if (d_addr->debug > 3) 598 { 599 d_addr->free_line = l; 600 d_addr->free_file = f; 601 602 if (d_addr->debug > 4) 603 omGetCurrentBackTrace(&d_addr->free_frames, OM_MAX_FRAMES, r); 604 } 605 } 606 } 607 413 static omBin omGetOrigSpecBinOfAddr(void* addr) 414 { 415 if (omIsBinPageAddr(addr)) 416 { 417 #ifdef OM_HAVE_TRACK 418 if (omIsBinAddrTrackAddr(addr)) return omGetOrigSpecBinOfTrackAddr(addr); 419 else 420 #endif 421 { 422 omBin bin = omGetTopBinOfAddr(addr); 423 if (!omIsStaticNormalBin(bin)) return bin; 424 } 425 } 426 return NULL; 427 } 428 429 static void __omDebugFree(void* addr, void* size_bin, omTrackFlags_t flags, OM_FLR_DECL) 430 { 431 omBin bin = NULL; 432 433 if (addr == NULL || ((flags & OM_FSIZE) && size_bin == NULL)) return; 608 434 if (om_Opts.Keep > 0) 609 435 { 436 #ifdef OM_HAVE_TRACK 437 if (omIsTrackAddr(addr)) 438 addr = omMarkAsFreeTrackAddr(addr, 1, OM_FLR_VAL); 439 #endif 440 bin = omGetOrigSpecBinOfAddr(addr); 441 if (bin != NULL) 442 { 443 omSpecBin s_bin = omFindInGList(om_SpecBin, next, bin, (unsigned long) bin); 444 omAssume(s_bin != NULL); 445 (s_bin->ref)++; 446 } 447 610 448 if (om_NumberOfKeptAddrs) 611 449 { 612 omAssume(om_ FirstKeptDebugAddr != NULL && om_LastKeptDebugAddr != NULL &&613 ((om_NumberOfKeptAddr == 1 && om_LastKeptDebugAddr == om_FirstKeptDebugAddr) ||614 (om_NumberOfKeptAddr != 1 && om_LastKeptDebugAddr != om_FirstKeptDebugAddr)));450 omAssume(om_KeptAddr != NULL && om_LastKeptAddr != NULL && 451 ((om_NumberOfKeptAddrs == 1 && om_LastKeptAddr == om_KeptAddr) || 452 (om_NumberOfKeptAddrs != 1 && om_LastKeptAddr != om_KeptAddr))); 615 453 om_NumberOfKeptAddrs++; 616 454 *((void**) om_LastKeptAddr) = addr; 617 455 om_LastKeptAddr = addr; 456 *((void**) addr) = NULL; 618 457 } 619 458 else … … 621 460 om_NumberOfKeptAddrs = 1; 622 461 om_LastKeptAddr = addr; 623 om_ FirstKeptAddr = addr;462 om_KeptAddr = addr; 624 463 *((void**) om_LastKeptAddr) = NULL; 625 464 } … … 627 466 if (om_NumberOfKeptAddrs > om_Opts.Keep) 628 467 { 629 addr = om_FirstKeptAddr; 630 om_FirstKeptAddr = *((void**) addr); 468 omError_t status = omDoCheckAddr(om_KeptAddr, NULL, OM_FKEPT, om_Opts.MinCheck, 469 omError_MemoryCorrupted, OM_FLR_VAL); 470 addr = om_KeptAddr; 471 om_KeptAddr = *((void**) addr); 631 472 om_NumberOfKeptAddrs--; 473 if (status != omError_NoError) return; 632 474 } 633 475 else 634 476 return; 477 478 bin = omGetOrigSpecBinOfAddr(addr); 479 } 480 481 #ifdef OM_HAVE_TRACK 482 if (omIsTrackAddr(addr)) 483 { 484 omMarkAsFreeTrackAddr(addr, 0, OM_FLR_VAL); 485 omFreeTrackAddr(addr); 635 486 } 636 487 else 637 { 638 if (! omIsDebugAddr(addr)) 639 { 640 if (flags & OM_BIN_FLAG) 641 ___omFreeBin(addr); 642 else if (flags & OM_SIZE_FLAG) 643 __omFreeSize(addr, (size_t) bin_size); 644 else 645 __omFree(addr); 646 647 return; 648 } 649 } 650 651 if (omIsDebugAddr(addr)) 652 omFreeDebugAddr(addr); 653 else 654 __omFree(addr); 655 } 656 static void omFreeDebugAddr(void* d_addr) 657 { 658 omBinPage page; 659 660 omAssume(d_addr != NULL && omIsDebugAddr(d_addr)); 661 662 page = (omBinPage) omGetPageOfAddr((void*) d_addr); 663 omAssume(omIsBinPage(page)); 664 665 omUnsetDebugOfUsedBlocks(page->used_blocks); 666 667 om_JustFreedPage = NULL; 668 669 ___omFreeBin(d_addr); 670 671 if (page != om_JustFreedPage) 672 omSetDebugOfUsedBlocks(page->used_blocks); 673 } 674 675 /******************************************************************* 676 * 677 * Second level omCheck routines: do the actual checks 678 * 679 *******************************************************************/ 680 681 #define omIsAddrInValidRange(addr) 1 682 683 omError_t omCheckAddr(void* addr, void* bin_size, int flags, char level, char* f, const int l, void* r) 684 { 685 if (addr == NULL) 686 return omReportAddrError(omError_NullAddr, addr, bin_size, flags, f, l, r, ""); 687 688 if (((long) addr & (SIZEOF_OM_ALIGNMENT - 1))) 689 return omReportAddrError(omError_UnalignedAddr, addr, bin_size, flags, f, l, r, ""); 690 691 if ((flags & OM_ALIGN_FLAG) && ((long) addr & (SIZEOF_OM_STRICT_ALIGNMENT - 1))) 692 return omReportAddrError(omError_UnalignedAddr, addr, bin_size, flags, f, l, r, ""); 693 694 if (! omIsAddrInValidRange(addr)) 695 return omReportAddrError(omError_InvalidRange, addr, bin_size, flags, f, l, r, ""); 696 697 if (omIsBinPageAddr(addr)) 698 { 699 if (! omCheckPageHeader(omGetPageOfAddr(addr))) 700 return omReportAddrError(omError_MemoryCorrupted, addr, bin_size, flags, f, l, r, 701 "Page Header corrupted"); 702 703 if (omIsDebugAddr(addr)) 704 { 705 omDebugAddr d_addr = omAddr_2_DebugAddr(addr); 706 if (d_addr->debug < 0 || d_addr->debug > OM_DEBUG_MAX) 707 return omReportAddrError(omError_MemoryCorrupted, addr, bin_size, flags, f, l, r, 708 "debug:%d out of range", d_addr->debug); 709 if (omDebugAddr_2_OutAddr(d_addr) != addr) 710 return omReportAddrError(omError_FalseAddr, addr, bin_size, flags, f, l, r, 711 "omDebugAddr_2_OutAddr(d_addr):%d != addr:%d", 712 omDebugAddr_2_OutAddr(d_addr), addr); 713 if (! omCheckDebugAddr(d_addr, bin_size, flags, level, f, l, r)) 714 return om_ErrorStatus; 715 716 if (level > 1 && 717 !omCheckBinAddr(d_addr, NULL, (flags &~ OM_SIZE_FLAG) &~ OM_BIN_FLAG , level, f, l, r)) 718 return om_ErrorStatus; 719 else 720 return om_ErrorStatus = omError_NoError; 721 } 722 else 723 { 724 return omCheckBinAddr(addr, bin_size, flags, level, f, l, r); 725 } 726 } 727 else 728 { 729 return omCheckLargeAddr(addr, bin_size, flags, level, f, l, r); 730 } 731 } 732 733 omError_t omCheckLargeAddr(void* addr, void* bin_size, int flags, char level, char* f, const int l, void* r) 734 { 735 736 737 738 739 #endif /* OM_HAVE_DEBUG */ 488 #endif 489 if (om_Opts.Keep <= 0 && (flags & OM_FBIN)) 490 ___omFreeBin(addr); 491 else if (om_Opts.Keep <= 0 && (flags & OM_FSIZE)) 492 __omFreeSize(addr, (size_t) size_bin); 493 else 494 __omFree(addr); 495 496 if (bin != NULL) omUnGetSpecBin(&bin); 497 } 498 499 void omFreeKeptAddr() 500 { 501 void* next; 502 omBin bin; 503 504 while (om_KeptAddr != NULL) 505 { 506 next = *((void**)om_KeptAddr); 507 bin = omGetOrigSpecBinOfAddr(om_KeptAddr); 508 509 #ifdef OM_HAVE_TRACK 510 if (omIsTrackAddr(om_KeptAddr)) 511 { 512 omMarkAsFreeTrackAddr(om_KeptAddr, 0, OM_FLR); 513 omFreeTrackAddr(om_KeptAddr); 514 } 515 else 516 #endif 517 __omFree(om_KeptAddr); 518 519 if (bin != NULL) omUnGetSpecBin(&bin); 520 om_KeptAddr = next; 521 } 522 om_NumberOfKeptAddrs = 0; 523 om_LastKeptAddr = NULL; 524 } 525 526 #endif /* ! OM_NDEBUG */ -
omalloc/omDebug.h
recf4ca6 r3df5b10 1 1 /******************************************************************* 2 2 * File: omDebug.h 3 * Purpose: declaration of main omDebug functions3 * Purpose: declaration of common Debug/Check/Track stuff 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 * Created: 11/996 * Version: $Id: omDebug.h,v 1. 3 2000-05-31 13:34:31obachman Exp $5 * Created: 7/00 6 * Version: $Id: omDebug.h,v 1.4 2000-08-14 12:08:45 obachman Exp $ 7 7 *******************************************************************/ 8 #include "omError.h" 9 10 /* Debugging addresses and Bins */ 11 omError_t omDebugAddrBin(void* addr, omBin bin, int level); 12 omError_t omDebugAddr(void* adr, int level); 13 omError_t omDebugAddrSize(void* addr, size_t size, int level); 14 15 omError_t omDebugAlignedBinAddr(void* addr, int level); 16 omError_t omDebugAlignedBinAddrBin(void* addr, omBin bin, int level); 17 omError_t omDebugAlignedAddr(void* adr, int level); 18 omError_t omDebugAlignedAddrSize(void* addr, size_t size, int level); 19 20 omError_t omDebugBin(omBin bin, int level); 21 omError_t omDebugBins(int level); 22 23 /* combining check and alloc/free */ 24 void* omDebugAllocBin(omBin bin, int level); 25 void* omDebugAlloc0Bin(omBin bin, int level); 26 void* omDebugReallocBin(void* addr, omBin old_bin, omBin new_bin, int level); 27 void* omDebugRealloc0Bin(void* addr, omBin old_bin, omBin new_bin, int level); 28 void omDebugFreeBin(void* addr, omBin bin, int level); 29 30 void* omDebugAlloc(size_t Size, int level); 31 void* omDebugAlloc0(size_t Size, int level); 32 void* omDebugAllocAligned(size_t Size, int level); 33 void* omDebugAlloc0Aligned(size_t Size, int level); 34 35 void* omDebugRealloc(void* addr, size_t new_Size, int level); 36 void* omDebugRealloc0(void* addr, size_t new_Size, int level); 37 void* omDebugReallocAligned(void* addr, size_t new_Size, int level); 38 void* omDebugRealloc0Aligned(void* addr, size_t new_Size, int level); 39 40 void* omDebugReallocSize(void* addr, size_t old_Size, size_t new_Size, int level); 41 void* omDebugRealloc0Size(void* addr, size_t old_Size, size_t new_Size, int level); 42 void* omDebugReallocAlignedSize(void* addr, size_t old_Size, size_t new_Size, int level); 43 void* omDebugRealloc0AlignedSize(void* addr, size_t old_Size, size_t new_Size, int level); 44 45 void omDebugFreeSize(void* addr, size_t size, int level); 46 void omDebugFree(void* addr, int level); 47 48 void* omDebugAllocAlignedFunc(size_t size); 49 void* omDebugReallocAlignedFunc(void* addr, size_t new_size); 50 void omDebugFreeFunc(void* addr); 8 #ifndef OM_DEBUG_H 9 #define OM_DEBUG_H 51 10 52 11 12 #if defined(OM_NDEBUG) || ! defined(OM_HAVE_TRACK) 13 #define omIsTrackAddr(addr) 0 14 #define omIsTrackAddrPage(page) 0 15 #define omIsNormalBinPageAddr(addr) omIsBinPageAddr(addr) 16 #define omIsBinAddrTrackAddr(addr) 0 17 #else 18 #define omIsTrackAddrBinPage(bin_page) ((bin_page)->used_blocks < 0) 19 #define omIsBinAddrTrackAddr(addr) omIsTrackAddrBinPage(omGetBinPageOfAddr(addr)) 20 #define omIsTrackAddr(addr) (omIsBinPageAddr(addr) && omIsBinAddrTrackAddr(addr)) 21 #define omIsNormalBinPageAddr(addr) (omIsBinPageAddr(addr) && !omIsBinAddrTrackAddr(addr)) 22 #endif 23 24 #if defined(OM_NDEBUG) 25 #define omMarkAsStaticAddr(addr) ((void)0) 26 #define omMarkMemoryAsStatic() ((void)0) 27 #define omUnMarkAsStaticAddr() ((void)0) 28 #define omUnMarkMemoryAsStatic() ((void)0) 29 #define omFreeKeptAddr() ((void)0) 30 #define omPrintUsedAddrs(fd) ((void)0) 31 #define omPrintUsedTrackAddrs(fd) ((void)0) 32 #else 33 #define OM_FBIN 1 /* size_bin is bin */ 34 #define OM_FSIZE 2 /* size_bin is size */ 35 #define OM_FUSED 4 /* is in use, if set */ 36 #define OM_FKEPT 8 /* had been freed, if set */ 37 #define OM_FSTATIC 16 /* if set, considered to be static, i.e. never be freed */ 38 #define OM_FZERO 32 /* for Alloc0 */ 39 #define OM_FALIGN 64 /* for AllocAligned */ 40 #define OM_FSLOPPY 128 /* be sloppy about arguments */ 41 #define OM_FMAX 250 /* maximal flag: OM_FBIN and OM_FSIZE can not be at the same time, 42 and so can't OM_USED and OM_KEPT. Hence 255 - BIN - USED*/ 43 typedef unsigned char omTrackFlags_t; 44 45 void* _omDebugAlloc(void* size_bin, omTrackFlags_t flags, OM_CTFL_DECL); 46 void* _omDebugRealloc(void* old_addr, void* old_size_bin, void* new_size_bin, 47 omTrackFlags_t old_flags, omTrackFlags_t new_flags, OM_CTFL_DECL); 48 void _omDebugFree(void* addr, void* size_bin, omTrackFlags_t flags, OM_CFL_DECL); 49 void* _omDebugMemDup(void* addr, omTrackFlags_t flags, OM_CTFL_DECL); 50 char* _omDebugStrDup(const char* addr, OM_TFL_DECL); 51 52 omError_t _omDebugBin(omBin bin, OM_CFL_DECL); 53 omError_t _omDebugMemory(OM_CFL_DECL); 54 omError_t _omDebugAddr(void* addr, void* bin_size, omTrackFlags_t flags, OM_CFL_DECL); 55 56 void omFreeKeptAddr(); 57 void omPrintUsedAddrs(FILE* fd); 58 void omPrintUsedTrackAddrs(FILE* fd); 59 60 void omMarkAsStaticAddr(void* addr); 61 void omMarkMemoryAsStatic(); 62 void omUnMarkAsStaticAddr(void* addr); 63 void omUnMarkMemoryAsStatic(); 64 #endif /* ! OM_NDEBUG */ 65 66 /*BEGINPRIVATE*/ 67 68 #if defined(OM_NDEBUG) || ! defined(OM_HAVE_TRACK) 69 #define omGetUsedBlocksOfPage(page) (page->used_blocks) 70 #else 71 #define omGetUsedBlocksOfPage(page) (page->used_blocks & ~(1 << (BIT_SIZEOF_LONG -1))) 72 #endif 73 74 #ifndef OM_NDEBUG 53 75 54 76 77 void* om_KeptAddr; 78 unsigned long om_MaxAddr; 79 unsigned long om_MinAddr; 80 81 /*********************************************************************** 82 * 83 * omDebugCheck.c 84 * 85 **********************************************************************/ 86 omError_t omCheckPtr(void* ptr, omError_t report, OM_FLR_DECL); 87 omError_t _omCheckAddr(void* addr, void* size_bin, omTrackFlags_t flags, char check, 88 omError_t report, OM_FLR_DECL); 89 omError_t omDoCheckBinAddr(void* addr, void* bin_size, omTrackFlags_t flags, char level, 90 omError_t report, OM_FLR_DECL); 91 omError_t _omCheckBin(omBin bin, int normal_bin, char check, omError_t report, OM_FLR_DECL); 92 omError_t _omCheckMemory(char check, omError_t report, OM_FLR_DECL); 93 omError_t omReportAddrError(omError_t error, omError_t report, void* addr, void* bin_size, omTrackFlags_t flags, 94 OM_FLR_DECL, const char* fmt, ...); 95 omError_t omDoCheckBin(omBin bin, int normal_bin, char level, 96 omError_t report, OM_FLR_DECL); 97 int omIsKnownTopBin(omBin bin, int normal_bin); 98 void omIterateTroughAddrs(int normal, int track, void (*CallBackUsed)(void*), void (*CallBackFree)(void*)); 99 void omIterateTroughBinAddrs(omBin bin, void (*CallBackUsed)(void*), void (*CallBackFree)(void*)); 100 omError_t omDoCheckAddr(void* addr, void* bin_size, omTrackFlags_t flags, char level, 101 omError_t report, OM_FLR_DECL); 55 102 56 103 104 /*********************************************************************** 105 * 106 * omDebugTrack.c 107 * 108 **********************************************************************/ 109 #ifdef OM_HAVE_TRACK 110 extern omBin_t om_StaticTrackBin[]; 111 extern omBin om_Size2TrackBin[]; 112 #define omSmallSize2TrackBin(size) om_Size2TrackBin[((size) -1)>>LOG_SIZEOF_OM_ALIGNMENT] 113 extern omBinPage om_JustFreedPage; 114 extern void omFreeTrackAddr(void* addr); 115 extern size_t omOutSizeOfTrackAddr(void* addr); 116 extern omSpecBin om_SpecTrackBin; 57 117 118 void* omAllocTrackAddr(void* bin_size, omTrackFlags_t flags, char track, OM_FLR_DECL); 119 void* omMarkAsFreeTrackAddr(void* addr, int keep, OM_FLR_DECL); 120 omError_t omCheckTrackAddr(void* addr, void* bin_size, omTrackFlags_t flags, char level, 121 omError_t report_error, OM_FLR_DECL); 122 void omPrintTrackAddrInfo(FILE* fd, void* addr); 123 omBin omGetOrigSpecBinOfTrackAddr(void* addr); 124 size_t omOutSizeOfTrackAddr(void* addr); 125 extern int omIsStaticTrackAddr(void* addr); 126 #define omSetTrackOfUsedBlocks(ub) (ub |= (1 << (BIT_SIZEOF_LONG -1))) 127 #define omUnsetTrackOfUsedBlocks(ub) (ub &= ~(1 << (BIT_SIZEOF_LONG -1))) 128 #define omIsSetTrackOfUsedBlocks(ub) (ub & (1 << (BIT_SIZEOF_LONG -1))) 129 #else 130 #define omIsStaticTrackAddr(addr) 0 131 #endif 132 133 134 /*********************************************************************** 135 * 136 * omBinPage.c 137 * 138 **********************************************************************/ 139 int omIsKnownMemoryRegion(omBinPageRegion region); 140 omError_t omCheckBinPageRegion(omBinPageRegion region, int level, omError_t report, OM_FLR_DECL); 141 omError_t omCheckBinPageRegions(int level, omError_t report, OM_FLR_DECL); 142 omBinPageRegion omFindRegionOfAddr(void* addr); 143 int omIsAddrOnFreeBinPage(void* addr); 144 145 /*********************************************************************** 146 * 147 * Some Handy Macros 148 * 149 **********************************************************************/ 150 #define omCheckReturn(cond) \ 151 do {omError_t _status = cond; if (_status) return _status;} while (0) 152 #define omCheckReturnError(cond, error) \ 153 do {void* _status = (void*) (cond); if (_status) return omReportError(error, report, OM_FLR_VAL, "");} while (0) 154 #define omCheckReturnCorrupted(cond) \ 155 omCheckReturnError(cond, omError_MemoryCorrupted) 156 #define omAddrCheckReturn(cond) \ 157 do \ 158 { \ 159 omError_t _status = cond; \ 160 if (_status && _status != omError_MaxError) \ 161 { \ 162 omPrintAddrInfo(stderr, _status, addr, bin_size, flags, " occured for"); \ 163 return _status; \ 164 } \ 165 } while (0) 166 #define omAddrCheckReturnError(cond, error) \ 167 do {void* _status = (void*) (cond); if (_status) return omReportAddrError(error, report, addr, bin_size, flags, OM_FLR_VAL, "");} while (0) 168 #define omAddrCheckReturnCorrupted(cond) \ 169 omAddrCheckReturnError(cond, omError_MemoryCorrupted) 170 171 #endif /* ! OM_NDEBUG */ 172 /*ENDPRIVATE*/ 173 174 #endif /* OM_DEBUG_H */ -
omalloc/omFindExec.c
recf4ca6 r3df5b10 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omFindExec.c,v 1. 2 2000-05-31 13:34:31obachman Exp $6 * Version: $Id: omFindExec.c,v 1.3 2000-08-14 12:08:45 obachman Exp $ 7 7 *******************************************************************/ 8 8 … … 20 20 #define MAXPATHLEN 1024 21 21 #endif 22 23 22 24 23 /* ABSOLUTE_FILENAME_P (fname): True if fname is an absolute filename */ … … 36 35 char * omFindExec (const char *name, char* executable) 37 36 #else 38 char * omFindExec_link (const char *name, char* executable)37 static char * omFindExec_link (const char *name, char* executable) 39 38 #endif 40 39 { 41 40 char *search; 42 41 char *p; 42 #ifdef WINNT 43 char *extra = NULL; 44 #endif 43 45 char tbuf[MAXPATHLEN]; 44 46 … … 84 86 char *extra = NULL; 85 87 /* we are under msdos display */ 86 FIX ME 87 extra = (char*) AllocL((search != NULL ? strlen(search) : 0) + 3); 88 extra = (char*) omAlloc((search != NULL ? strlen(search) : 0) + 3); 88 89 strcpy(extra, ".:"); 89 90 if (search != NULL) strcat(extra, search); … … 125 126 #ifdef WINNT 126 127 if (extra != NULL) 127 FreeL(extra);128 omFree(extra); 128 129 #endif 129 130 strcpy(executable, tbuf); … … 142 143 } 143 144 } 144 145 return NULL; 146 } 145 return NULL; 146 } 147 147 148 148 #ifdef HAVE_READLINK 149 /* similar to readlink, but dont' mess up absolute pathnames */ 150 static int my_readlink(const char* name, char* buf, size_t bufsize) 151 { 152 char buf2[MAXPATHLEN]; 153 int ret; 154 155 if ((ret = readlink(name, buf2, bufsize)) > 0) 156 { 157 buf2[ret] = 0; 158 if (*name == '/' && *buf2 != '/') 159 { 160 char* last = strrchr(name, '/'); 161 int i = 0; 162 while (&(name[i]) != last) 163 { 164 buf[i] = name[i]; 165 i++; 166 } 167 buf[i] = '/'; 168 i++; 169 strcpy(&(buf[i]), buf2); 170 return i + ret; 171 } 172 else 173 { 174 strcpy(buf, buf2); 175 } 176 } 177 return ret; 178 } 149 179 150 180 #define MAX_LINK_LEVEL 10 … … 152 182 followed up to MAX_LINK_LEVEL 153 183 */ 154 int full_readlink(const char* name, char* buf, size_t bufsize)184 static int full_readlink(const char* name, char* buf, size_t bufsize) 155 185 { 156 186 int ret; 157 187 158 if ((ret= readlink(name, buf, bufsize)) > 0)188 if ((ret=my_readlink(name, buf, bufsize)) > 0) 159 189 { 160 190 char buf2[MAXPATHLEN]; … … 164 194 { 165 195 buf[ret] = '\0'; 166 if ((ret2 = readlink(buf, buf2, MAXPATHLEN)) > 0)196 if ((ret2 = my_readlink(buf, buf2, MAXPATHLEN)) > 0) 167 197 { 168 198 i++; … … 195 225 if (link != NULL && (ret=full_readlink(link, buf, MAXPATHLEN)) > 0) 196 226 { 227 char *p = strrchr(link, '/'); 228 229 230 if(p!=NULL) *(p+1)='\0'; 197 231 buf[ret]='\0'; 198 return omFindExec_link(buf, exec); 232 233 if (buf[0] != '/') 234 { 235 strcpy(exec, link); 236 strcat(exec, buf); 237 } 238 else 239 { 240 strcpy(exec, buf); 241 } 242 243 return exec; 199 244 } 200 245 return link; -
omalloc/omFindExec.h
recf4ca6 r3df5b10 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omFindExec.h,v 1. 1.1.1 1999-11-18 17:45:54obachman Exp $6 * Version: $Id: omFindExec.h,v 1.2 2000-08-14 12:08:46 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_FIND_EXEC_H 9 9 #define OM_FIND_EXEC_H 10 10 11 #include <stdio.h>12 11 /* determines absolute pathname of program prog, writes it into exec */ 13 12 /* returns exec on succes, NULL on failure */ -
omalloc/omList.c
recf4ca6 r3df5b10 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omList.c,v 1. 2 1999-11-22 18:12:59obachman Exp $6 * Version: $Id: omList.c,v 1.3 2000-08-14 12:08:46 obachman Exp $ 7 7 *******************************************************************/ 8 #include "omConfig.h" 9 8 10 #ifndef NULL 9 11 #define NULL ((void*) 0) … … 169 171 170 172 173 #ifndef OM_NDEBUG 174 #include "omAlloc.h" 175 #include "omDebug.h" 176 177 omError_t _omCheckList(void* list, int next, int level, omError_t report, OM_FLR_DECL) 178 { 179 if (level <= 1) return omError_NoError; 180 181 if (level == 1) 182 { 183 while (list != NULL) 184 { 185 omCheckReturn(omCheckPtr(list, report, OM_FLR_VAL)); 186 ITER(list); 187 } 188 } 189 else 190 { 191 void* l1 = list; 192 void* l2; 193 int l = 0, i; 194 195 l1 = list; 196 while (l1 != NULL) 197 { 198 omCheckReturn(omCheckPtr(l1, report, OM_FLR_VAL)); 199 i = 0; 200 l2 = list; 201 while (l1 != l2) 202 { 203 i++; 204 ITER(l2); 205 } 206 if (i != l) 207 return omReportError(omError_ListCycleError, report, OM_FLR_VAL, ""); 208 ITER(l1); 209 l++; 210 } 211 } 212 return omError_NoError; 213 } 214 215 omError_t _omCheckSortedList(void* list, int next, int long_field, int level, omError_t report, OM_FLR_DECL) 216 { 217 void* prev = NULL; 218 219 if (level <= 1) return omError_NoError; 220 221 if (level == 1) 222 { 223 while (list != NULL) 224 { 225 omCheckReturn(omCheckPtr(list, report, OM_FLR_VAL)); 226 if (prev != NULL && VALUE(prev, long_field) > VALUE(list, long_field)) 227 return omReportError(omError_SortedListError, report, OM_FLR_VAL, 228 "%d > %d", VALUE(prev, long_field), VALUE(list, long_field)); 229 prev = list; 230 ITER(list); 231 } 232 } 233 else 234 { 235 void* l1 = list; 236 void* l2; 237 int l = 0, i; 238 239 while (l1 != NULL) 240 { 241 omCheckReturn(omCheckPtr(l1, report, OM_FLR_VAL)); 242 if (prev != NULL && VALUE(prev, long_field) > VALUE(l1, long_field)) 243 return omReportError(omError_SortedListError, report, OM_FLR_VAL, 244 "%d > %d", VALUE(prev, long_field), VALUE(l1, long_field)); 245 i = 0; 246 l2 = list; 247 while (l1 != l2) 248 { 249 i++; 250 ITER(l2); 251 } 252 omCheckReturnError(i != l, omError_ListCycleError); 253 prev = l1; 254 ITER(l1); 255 l++; 256 } 257 } 258 return omError_NoError; 259 } 260 #endif 261 262 -
omalloc/omList.h
recf4ca6 r3df5b10 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omList.h,v 1. 1.1.1 1999-11-18 17:45:53obachman Exp $6 * Version: $Id: omList.h,v 1.2 2000-08-14 12:08:46 obachman Exp $ 7 7 *******************************************************************/ 8 8 9 9 #ifndef OM_LIST_H 10 10 #define OM_LIST_H 11 12 11 13 12 #define OM_LIST_OFFSET(ptr, name_of_offset_field) \ … … 50 49 void* _omInsertInSortedList(void* list, int next, int long_field, 51 50 void* addr); 52 51 #ifndef OM_NDEBUG 52 /* Check whether list is ok, i.e. whether addr of lists are aligned and in valid range */ 53 omError_t _omCheckList(void* list, int next, int level, omError_t report, OM_FLR_DECL); 54 /* like above, but also check that sorting is ok */ 55 omError_t _omCheckSortedList(void* list, int next, int long_field, int level, omError_t report, OM_FLR_DECL); 56 #endif 53 57 54 58 /******************************************************************** … … 68 72 _omRemoveFromList(ptr, 0, addr) 69 73 #define omFindInList(ptr, what, value) \ 70 _omFindInList(ptr, 0, OM_LIST_OFFSET(ptr, what), value)74 _omFindInList(ptr, 0, OM_LIST_OFFSET(ptr, what), (unsigned long) value) 71 75 #define omInsertInSortedList(ptr, what, addr) \ 72 76 _omInsertInSortedList(ptr, 0, OM_LIST_OFFSET(ptr, what), addr) … … 75 79 #define omRemoveFromSortedList(ptr, what, addr) \ 76 80 _omRemoveFromSortedList(ptr, 0, OM_LIST_OFFSET(ptr, what), addr) 77 81 #ifndef OM_NDEBUG 82 #define omCheckList(ptr, level, report, OM_FLR_VAL) \ 83 _omCheckList(ptr, 0, level, report, OM_FLR_VAL) 84 #define omCheckSortedList(ptr, what, level, report, OM_FLR_VAL) \ 85 _omCheckSortedList(ptr, 0, OM_LIST_OFFSET(ptr, what), level, report, OM_FLR_VAL) 86 #endif 78 87 79 88 /******************************************************************** … … 93 102 _omRemoveFromList(ptr, OM_LIST_OFFSET(ptr, next), addr) 94 103 #define omFindInGList(ptr, next, what, value) \ 95 _omFindInList(ptr, OM_LIST_OFFSET(ptr, next), OM_LIST_OFFSET(ptr, what), value)104 _omFindInList(ptr, OM_LIST_OFFSET(ptr, next), OM_LIST_OFFSET(ptr, what), (unsigned long) value) 96 105 #define omInsertInSortedGList(ptr, next, what, addr) \ 97 106 _omInsertInSortedList(ptr, OM_LIST_OFFSET(ptr, next), OM_LIST_OFFSET(ptr, what), addr) … … 100 109 #define omRemoveFromSortedGList(ptr, next, what, addr) \ 101 110 _omRemoveFromSortedList(ptr, OM_LIST_OFFSET(addr,next),OM_LIST_OFFSET(addr,what),addr) 111 #ifndef OM_NDEBUG 112 #define omCheckGList(ptr, next, level, report, OM_FLR_VAL) \ 113 _omCheckList(ptr, OM_LIST_OFFSET(ptr,next), level, report, OM_FLR_VAL) 114 #define omCheckSortedGList(ptr, next, what, level, report, OM_FLR_VAL) \ 115 _omCheckSortedList(ptr, OM_LIST_OFFSET(ptr,next), OM_LIST_OFFSET(ptr,what), level, report, OM_FLR_VAL) 116 #endif 102 117 103 118 #endif /* OM_LIST_H */ -
omalloc/omMemOps.h
recf4ca6 r3df5b10 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omMemOps.h,v 1. 1.1.1 1999-11-18 17:45:53obachman Exp $6 * Version: $Id: omMemOps.h,v 1.2 2000-08-14 12:08:46 obachman Exp $ 7 7 *******************************************************************/ 8 8 … … 28 28 #else /* ! DO_DEEP_PROFILE */ 29 29 30 #define omMemcpyW(p1, p2, l) 30 #define omMemcpyW(p1, p2, l) \ 31 31 do \ 32 32 { \ 33 33 long _i = l; \ 34 long* _s1 = (long*) p1; \35 const long* _s2 = (long*) p2; \34 long* _s1 = (long*) (p1); \ 35 const long* _s2 = (long*) (p2); \ 36 36 \ 37 37 for (;;) \ … … 46 46 while(0) 47 47 48 #define omMemcpy_nwODD(p1, p2, l) 48 #define omMemcpy_nwODD(p1, p2, l) \ 49 49 do \ 50 50 { \ 51 long _i = l- 1; \52 long* _s1 = (long*) p1; \53 const long* _s2 = (long*) p2; \51 long _i = (l) - 1; \ 52 long* _s1 = (long*) (p1); \ 53 const long* _s2 = (long*) (p2); \ 54 54 \ 55 55 *_s1++ = *_s2++; \ … … 64 64 while(0) 65 65 66 #define omMemcpy_nwEVEN(p1, p2, l) 66 #define omMemcpy_nwEVEN(p1, p2, l) \ 67 67 do \ 68 68 { \ 69 69 long _i = l; \ 70 long* _s1 = (long*) p1; \71 const long* _s2 = (long*) p2; \70 long* _s1 = (long*) (p1); \ 71 const long* _s2 = (long*) (p2); \ 72 72 \ 73 73 for (;;) \ … … 81 81 while(0) 82 82 83 #define omMemaddW(P1, P2, P3, L) 83 #define omMemaddW(P1, P2, P3, L) \ 84 84 do \ 85 85 { \ … … 98 98 while(0) 99 99 100 #define omMemadd_nwODD(P1, P2, P3, L) 100 #define omMemadd_nwODD(P1, P2, P3, L) \ 101 101 do \ 102 102 { \ … … 119 119 while(0) 120 120 121 #define omMemadd_nwEVEN(P1, P2, P3, L) 121 #define omMemadd_nwEVEN(P1, P2, P3, L) \ 122 122 do \ 123 123 { \ … … 137 137 while(0) 138 138 139 #define omMemadd_nwONE(P1, P2, P3) 139 #define omMemadd_nwONE(P1, P2, P3) \ 140 140 do \ 141 141 { \ … … 148 148 while(0) 149 149 150 #define omMemadd_nwTWO(P1, P2, P3) 150 #define omMemadd_nwTWO(P1, P2, P3) \ 151 151 do \ 152 152 { \ … … 160 160 while(0) 161 161 162 #define omMemsetW(P1, W, L) 162 #define omMemsetW(P1, W, L) \ 163 163 do \ 164 164 { \ 165 long* _p1 = (long*) P1;\165 long* _p1 = (long*) (P1); \ 166 166 unsigned long _l = L; \ 167 167 unsigned long _w = W; \ 168 168 while(_l) \ 169 169 { \ 170 *_p1++ = W;\170 *_p1++ = _w; \ 171 171 _l--; \ 172 172 } \ -
omalloc/omPage.h
recf4ca6 r3df5b10 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omPage.h,v 1. 3 2000-05-31 13:34:32obachman Exp $6 * Version: $Id: omPage.h,v 1.4 2000-08-14 12:08:46 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_PAGE_H … … 108 108 ((void*) ((long) (addr) & ~(SIZEOF_SYSTEM_PAGE -1))) 109 109 110 #define omGetBinPageOfAddr(addr) \ 111 ((omBinPage) ((long) (addr) & ~(SIZEOF_SYSTEM_PAGE -1))) 112 110 113 #define omIsAddrOnPage(addr, page) (omGetPageOfAddr(addr) == (void*) (page)) 111 114 -
omalloc/omTables.c
recf4ca6 r3df5b10 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omTables.c,v 1. 2 2000-05-31 13:34:32obachman Exp $6 * Version: $Id: omTables.c,v 1.3 2000-08-14 12:08:47 obachman Exp $ 7 7 *******************************************************************/ 8 8 … … 16 16 #include <string.h> 17 17 #include "omConfig.h" 18 #include "omAlloc.h" 18 #include "omDerivedConfig.h" 19 #include "omStructs.h" 20 #include "omAllocPrivate.h" 19 21 20 22 /* Specify the minimal number of blocks which should go into a bin */ … … 62 64 #endif /* OM_ALIGN_8 */ 63 65 64 void OutputSize2Bin(size_t *binSize, size_t max_block_size )66 void OutputSize2Bin(size_t *binSize, size_t max_block_size, int track) 65 67 { 66 68 int i, j; 67 printf("omBin om_Size2 Bin[/*%d*/] = {\n",68 max_block_size / SIZEOF_OM_ALIGNMENT);69 printf("omBin om_Size2%sBin[/*%d*/] = {\n", 70 (track? "Track" : ""), max_block_size / SIZEOF_OM_ALIGNMENT); 69 71 i=0; 70 72 j=SIZEOF_OM_ALIGNMENT; 71 73 while (j < max_block_size) 72 74 { 73 printf("&om_Static Bin[%d], /* %d */ \n", i, j);75 printf("&om_Static%sBin[%d], /* %d */ \n", (track? "Track" : ""), i, j); 74 76 if (binSize[i] == j) i++; 75 77 j += SIZEOF_OM_ALIGNMENT; 76 78 } 77 printf("&om_Static Bin[%d] /* %d */};\n\n", i, j);78 } 79 80 void OutputSize2AlignedBin(size_t *binSize, size_t max_block_size )79 printf("&om_Static%sBin[%d] /* %d */};\n\n", (track? "Track" : ""), i, j); 80 } 81 82 void OutputSize2AlignedBin(size_t *binSize, size_t max_block_size, int track) 81 83 { 82 84 int i, j; … … 86 88 _exit(1); 87 89 } 88 printf("omBin om_Size2 AlignedBin[/*%d*/] = {\n",89 max_block_size / SIZEOF_OM_ALIGNMENT);90 printf("omBin om_Size2%sBin[/*%d*/] = {\n", 91 (track ? "Track" : "Aligned"), max_block_size / SIZEOF_OM_ALIGNMENT); 90 92 i=0; 91 93 while (binSize[i] % SIZEOF_STRICT_ALIGNMENT != 0) i++; … … 93 95 while (j < max_block_size) 94 96 { 95 printf("&om_Static Bin[%d], /* %d */ \n", i, j);97 printf("&om_Static%sBin[%d], /* %d */ \n", (track ? "Track" : ""), i, j); 96 98 if (binSize[i] == j) 97 99 { … … 101 103 j += SIZEOF_OM_ALIGNMENT; 102 104 } 103 printf("&om_Static Bin[%d] /* %d */};\n\n", i, j);104 } 105 106 void OutputStaticBin(size_t *binSize, int max_bin_index )105 printf("&om_Static%sBin[%d] /* %d */};\n\n", (track ? "Track" : ""), i, j); 106 } 107 108 void OutputStaticBin(size_t *binSize, int max_bin_index, int track) 107 109 { 108 110 int i; 109 printf("omBin_t om_Static Bin[/*%d*/] = {\n", max_bin_index+1);111 printf("omBin_t om_Static%sBin[/*%d*/] = {\n", (track ? "Track" : ""), max_bin_index+1); 110 112 111 113 for (i=0; i< max_bin_index; i++) … … 162 164 } 163 165 164 int main( )166 int main(int argc, char* argv[]) 165 167 { 166 168 int max_bin_index = 0; … … 174 176 if (om_BinSize[max_bin_index] == OM_MAX_BLOCK_SIZE) break; 175 177 } 176 /* output what goes into omAllocPrivate.h */ 178 if (argc > 1) 179 { 180 /* output what goes into omTables.h */ 181 printf(" 182 #ifndef OM_TABLES_H 183 #define OM_TABLES_H 184 #define OM_MAX_BLOCK_SIZE %d 185 #define OM_MAX_BIN_INDEX %d 186 #define OM_SIZEOF_UNIQUE_MAX_BLOCK_THRESHOLD %d 187 #endif /* OM_TABLES_H */ 188 ", OM_MAX_BLOCK_SIZE, max_bin_index, GetMaxBlockThreshold()); 189 return 0; 190 } 191 177 192 printf(" 178 193 #ifndef OM_TABLES_INC 179 194 #define OM_TABLES_INC 180 181 #ifdef OM_ALLOC_PRIVATE_H 182 #define OM_MAX_BLOCK_SIZE %d 183 #define OM_MAX_BIN_INDEX %d 184 #define OM_SIZEOF_UNIQUE_MAX_BLOCK_THRESHOLD %d 185 #endif /* OM_ALLOC_PRIVATE_H */ 186 187 #ifdef OM_ALLOC_C 188 extern omBinPage_t om_ZeroPage[]; 189 ", OM_MAX_BLOCK_SIZE, max_bin_index, GetMaxBlockThreshold()); 195 "); 196 190 197 /* Output om_StaticBin */ 191 OutputStaticBin(om_BinSize, max_bin_index );198 OutputStaticBin(om_BinSize, max_bin_index, 0); 192 199 /* Output om_Size2Bin */ 193 OutputSize2Bin(om_BinSize, OM_MAX_BLOCK_SIZE); 194 195 #ifdef OM_ALIGNMENT_NEEDS_WORK 196 OutputSize2AlignedBin(om_BinSize, OM_MAX_BLOCK_SIZE); 197 #endif 198 199 printf(" 200 OutputSize2Bin(om_BinSize, OM_MAX_BLOCK_SIZE, 0); 201 202 #ifdef OM_ALIGNMENT_NEEDS_WORK 203 OutputSize2AlignedBin(om_BinSize, OM_MAX_BLOCK_SIZE, 0); 204 #endif 205 206 printf("\n#ifdef OM_HAVE_TRACK\n"); 207 /* Output om_StaticBin */ 208 OutputStaticBin(om_BinSize, max_bin_index, 1); 209 /* Output om_Size2Bin */ 210 #ifdef OM_ALIGNMENT_NEEDS_WORK 211 OutputSize2AlignedBin(om_BinSize, OM_MAX_BLOCK_SIZE, 1); 200 212 #else 201 extern omBin_t om_StaticBin[]; 202 extern omBin om_Size2Bin[]; 203 extern omBin om_Size2AlignedBin[]; 204 #endif /* OM_ALLOC_C */ 205 #endif /* OM_TABLES_INC */ 206 "); 213 OutputSize2Bin(om_BinSize, OM_MAX_BLOCK_SIZE, 1); 214 #endif 215 printf("\n#endif /* OM_HAVE_TRACK */\n"); 216 217 printf("\n#endif /* OM_TABLES_INC */\n"); 207 218 return 0; 208 219 }
Note: See TracChangeset
for help on using the changeset viewer.