Module: sip-router
Branch: sr_3.0
Commit: b8592ad5ea877cf1299519ed209110cc59e87995
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b8592ad…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Mar 11 21:08:20 2010 +0100
mem: fix f_malloc big fragments bug
In some situation, when dealing with several big free fragments
(>16k) f_malloc would wrongly choose a fragment with a smaller
size then requested. This would create the impression that someone
arbitrarily overwrites the memory.
First symptoms were some tls crashes reported by
Klaus Darilion klaus.darilion(a)nic.at.
Reproduced using the malloc_test module.
(cherry picked from commit c7099d0a1204120277cf662cc05ab35180d89538)
---
mem/f_malloc.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mem/f_malloc.c b/mem/f_malloc.c
index c49a252..2c05fe6 100644
--- a/mem/f_malloc.c
+++ b/mem/f_malloc.c
@@ -337,7 +337,7 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
hash=fm_bmp_first_set(qm, GET_HASH(size));
if (likely(hash>=0)){
f=&(qm->free_hash[hash].first);
- if (likely(hash<=F_MALLOC_OPTIMIZE)) /* return first match */
+ if (likely(hash<=F_MALLOC_OPTIMIZE/ROUNDTO)) /* return first match */
goto found;
for(;(*f); f=&((*f)->u.nxt_free))
if ((*f)->size>=size) goto found;
@@ -346,7 +346,7 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
for(hash=GET_HASH(size);hash<F_HASH_SIZE;hash++){
f=&(qm->free_hash[hash].first);
#if 0
- if (likely(hash<=F_MALLOC_OPTIMIZE)) /* return first match */
+ if (likely(hash<=F_MALLOC_OPTIMIZE/ROUNDTO)) /* return first match */
goto found;
#endif
for(;(*f); f=&((*f)->u.nxt_free))
Module: sip-router
Branch: master
Commit: c7099d0a1204120277cf662cc05ab35180d89538
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c7099d0…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Mar 11 21:08:20 2010 +0100
mem: fix f_malloc big fragments bug
In some situation, when dealing with several big free fragments
(>16k) f_malloc would wrongly choose a fragment with a smaller
size then requested. This would create the impression that someone
arbitrarily overwrites the memory.
First symptoms were some tls crashes reported by
Klaus Darilion klaus.darilion(a)nic.at.
Reproduced using the malloc_test module.
---
mem/f_malloc.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/mem/f_malloc.c b/mem/f_malloc.c
index c49a252..2c05fe6 100644
--- a/mem/f_malloc.c
+++ b/mem/f_malloc.c
@@ -337,7 +337,7 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
hash=fm_bmp_first_set(qm, GET_HASH(size));
if (likely(hash>=0)){
f=&(qm->free_hash[hash].first);
- if (likely(hash<=F_MALLOC_OPTIMIZE)) /* return first match */
+ if (likely(hash<=F_MALLOC_OPTIMIZE/ROUNDTO)) /* return first match */
goto found;
for(;(*f); f=&((*f)->u.nxt_free))
if ((*f)->size>=size) goto found;
@@ -346,7 +346,7 @@ void* fm_malloc(struct fm_block* qm, unsigned long size)
for(hash=GET_HASH(size);hash<F_HASH_SIZE;hash++){
f=&(qm->free_hash[hash].first);
#if 0
- if (likely(hash<=F_MALLOC_OPTIMIZE)) /* return first match */
+ if (likely(hash<=F_MALLOC_OPTIMIZE/ROUNDTO)) /* return first match */
goto found;
#endif
for(;(*f); f=&((*f)->u.nxt_free))
Module: sip-router
Branch: master
Commit: 0ff010fa5777a2c9c8ef477079323828e2362781
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0ff010f…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Mar 11 19:38:04 2010 +0100
malloc_test: new module for testing/debugging memory problems
malloc_test is a new module for stressing the memory allocators
and easily simulating out-of-memory conditions or memory leaks.
Implemented RPCs:
mt.mem_alloc size - allocates size bytes
mt.mem_free [size] - frees at least size bytes. If size is missing
frees everything allocated by any malloc_test test function.
mt.mem_used - amount of currently allocated mem. by malloc_test.
mt.mem_rnd_alloc min max total [unit] - allocates total
<unit> bytes in chunks with the size randomly chosen between min
and max. <unit> is optional and can be one of b-bytes, k - kb,
m - mb, g -gb.
mt.mem_test_start min max total min_int max_int total_time [unit]
starts a malloc test that will take total_time to execute.
Memory allocations will be performed at intervals randomly
chosen between min_int and max_int (in ms). Each allocation will
have a randomly chosen size between min and max <unit> bytes.
After total <unit> bytes are allocated, everything is
released/freed again and the allocations are restarted. The
total_time is expressed in milliseconds.
Several tests can be run in the same time.
mt.mem_test_stop id - stops the test identified by id.
mt.mem_test_destroy id - destroys the test identified by id
(besides stopping it, it also frees all the data, including the
statistics).
mt.mem_test_destroy_all - destroys all the running or stopped
tests.
mt.mem_test_list [id] - Prints data about test id (running time,
total allocations, errors a.s.o.). If id is missing, it will lists
all the tests.
Script functions:
mt_mem_alloc(size) - equivalent to the mt.mem_alloc RPC.
mt_mem_free(size) - equivalent to the mt.mem_free RPC.
---
modules/malloc_test/Makefile | 15 +
modules/malloc_test/doc/Makefile | 4 +
modules/malloc_test/doc/functions.xml | 56 ++
modules/malloc_test/doc/malloc_test.xml | 47 ++
modules/malloc_test/doc/params.xml | 48 ++
modules/malloc_test/malloc_test.c | 887 +++++++++++++++++++++++++++++++
6 files changed, 1057 insertions(+), 0 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=0ff…
Module: sip-router
Branch: master
Commit: 5a9014ee4977c6afbc4b0cf65a9fad6237c2e2a6
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5a9014e…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Wed Mar 10 09:25:13 2010 +0100
make: on-the-fly dependency generation
- support on-the-fly dependency file generation with gcc >=3.0
(the dependency files are generated while compiling the object
file, eliminating another gcc+sed invocation)
- support for using makedepend -f- for generating dependencies
E.g.: make cfg MKDEP="makedepend -f-". In general gcc should be
preferred if available (use this if you don't have gcc and your
compiler doesn't generate good deps).
---
Makefile.defs | 12 ++++++++++--
Makefile.rules | 22 +++++++++++++++++++---
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/Makefile.defs b/Makefile.defs
index d334f24..a775bd9 100644
--- a/Makefile.defs
+++ b/Makefile.defs
@@ -74,6 +74,9 @@
# from the host (andrei)
# 2009-10-01 use -fsigned-char for gcc on ppc, ppc64, arm and arm6
# (on those archs char is unsigned by default) (andrei)
+# 2010-03-10 added CC_MKDEP_OPTS, which contains to the list of options
+# needed to generate dependencies on-the-fly while compiling
+# or is empty if the compiler doesn't support it (andrei)
quiet?=$(if $(filter 1 yes on,$(Q)),silent,verbose)
@@ -351,7 +354,7 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
# -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
# sed with POSIX.1 regex doesn't support |, + or ?
# (darwin, solaris ...) => this complicated expression
- MKDEP=$(CC) -MM
+ MKDEP=$(CC) -MM -MG
#transform gcc version into 2.9x or 3.0
CC_SHORTVER:=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
sed -e 's/[^0-9]*-\(.*\)/\1/'| \
@@ -360,7 +363,11 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
's/3\.[4-9]/3.4/' -e 's/4\.[0-1]\..*/4.x/' -e \
's/4\.[0-1]/4.x/' -e 's/4\.[2-9]\..*/4.2+/' -e \
's/4\.[2-9]$$/4.2+/')
-endif
+ifeq (,$(strip $(filter-out 3.0 3.4 4.x 4.2+,$(CC_SHORTVER))))
+ # dependencies can be generated on-the-fly while compiling *.c
+ CC_MKDEP_OPTS=-MMD -MP
+endif # 3.0 <= $(CC_SHORTVER) <= 4.x
+endif # gcc
ifneq (, $(findstring Sun, $(CC_LONGVER)))
CC_NAME=suncc
@@ -1947,6 +1954,7 @@ export exported_vars
saved_fixed_vars:= MAIN_NAME CFG_NAME SCR_NAME FLAVOUR INSTALL_FLAVOUR \
SRC_NAME RELEASE OS ARCH \
C_DEFS DEFS_RM PROFILE CC LD MKDEP MKTAGS LDFLAGS C_INCLUDES \
+ CC_MKDEP_OPTS \
MOD_LDFLAGS LIB_LDFLAGS UTILS_LDFLAGS LIB_SONAME LD_RPATH \
LIB_SUFFIX LIB_PREFIX \
LIBS \
diff --git a/Makefile.rules b/Makefile.rules
index 9fbf02b..f816f8b 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -25,6 +25,11 @@
# used only for "temporary" defines/includes inside modules or
# libs, C_DEFS and C_INCLUDES are used for the common stuff)
# (andrei)
+# 2010-03-09 generate dependencies when compiling .o instead of on
+# include .d and fix build errors when a .h is moved
+# support for using MKDEP="makedepend-f-" (andrei)
+# 2010-03-10 support for on the-fly dependency generation (while compiling,
+# see CC_MKDEP_OPTS) (andrei)
# check if the saved cfg corresponds with the current one
@@ -59,6 +64,19 @@ cmd_CC=$(CC) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) -c $< -o $@
cmd_LD=$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) \
-o $(NAME)
+ifeq (,$(CC_MKDEP_OPTS))
+# if CCC_MKDEP_OPTS is empty => CC cannot generate dependencies on the fly
+cmd_MKDEP=$(MKDEP) $(filter -D% -I%,$(CFLAGS)) $(C_INCLUDES) $(INCLUDES) \
+ $(C_DEFS) $(DEFS) $< \
+ | sed -e 's/\#.*//' -e '/:[ ]*$$/d' -e '/^[ ]*$$/d' \
+ -e 's|.*:|$@: $$(wildcard |' -e 's/\([^\\]\)$$/\1)/'> $*.d
+else
+# deps can be generated on the fly by cmd_CC
+cmd_CC+=$(CC_MKDEP_OPTS)
+# no MKDEP command any more
+cmd_MKDEP=
+endif # CC_MKDEP_OPTS
+
# what will be displayed if quiet==silent
silent_cmd_CC=CC ($(CC)) [$(strip $(crt_type) $(NAME))] $@
silent_cmd_LD=LD ($(LD)) [$(strip $(crt_type) $(NAME))] $@
@@ -94,9 +112,7 @@ exec_cmd= $(if $($(quiet)_cmd_$(1)),\
#implicit rules
%.o:%.c $(ALLDEP)
$(call exec_cmd,CC)
- @$(MKDEP) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) $< \
- | sed -e 's/#.*//' -e '/:[ ]*$$/d' -e '/^[ ]*$$/d' \
- -e 's#.*:#$@: $$(wildcard #g' -e 's/\([^\\]\)$$/\1)/'> $*.d
+ @$(call cmd_MKDEP)
# use RPATH and SER_LIBS if needed (make install and the module depends
# on some ser libs)