[asterisk-commits] kpfleming: branch
kpfleming/embedded-module-globals r56068 - in /team/kpflemi...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Feb 21 19:06:18 MST 2007
Author: kpfleming
Date: Wed Feb 21 20:06:16 2007
New Revision: 56068
URL: http://svn.digium.com/view/asterisk?view=rev&rev=56068
Log:
create branch to store this thing
Added:
team/kpfleming/embedded-module-globals/
- copied from r56007, trunk/
team/kpfleming/embedded-module-globals/.cleancount
- copied unchanged from r56006, trunk/.cleancount
team/kpfleming/embedded-module-globals/BUGS
- copied unchanged from r56006, trunk/BUGS
team/kpfleming/embedded-module-globals/CHANGES
- copied unchanged from r56006, trunk/CHANGES
team/kpfleming/embedded-module-globals/COPYING
- copied unchanged from r56006, trunk/COPYING
team/kpfleming/embedded-module-globals/CREDITS
- copied unchanged from r56006, trunk/CREDITS
team/kpfleming/embedded-module-globals/LICENSE
- copied unchanged from r56006, trunk/LICENSE
team/kpfleming/embedded-module-globals/Makefile
- copied unchanged from r56006, trunk/Makefile
team/kpfleming/embedded-module-globals/Makefile.moddir_rules
- copied, changed from r56006, trunk/Makefile.moddir_rules
team/kpfleming/embedded-module-globals/Makefile.rules
- copied, changed from r56006, trunk/Makefile.rules
team/kpfleming/embedded-module-globals/README
- copied unchanged from r56006, trunk/README
team/kpfleming/embedded-module-globals/UPGRADE.txt
- copied unchanged from r56006, trunk/UPGRADE.txt
team/kpfleming/embedded-module-globals/acinclude.m4
- copied unchanged from r56006, trunk/acinclude.m4
team/kpfleming/embedded-module-globals/agi/
- copied from r56006, trunk/agi/
team/kpfleming/embedded-module-globals/apps/
- copied from r56006, trunk/apps/
team/kpfleming/embedded-module-globals/bootstrap.sh
- copied unchanged from r56006, trunk/bootstrap.sh
team/kpfleming/embedded-module-globals/build_tools/
- copied from r56006, trunk/build_tools/
team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script (with props)
team/kpfleming/embedded-module-globals/cdr/
- copied from r56006, trunk/cdr/
team/kpfleming/embedded-module-globals/channels/
- copied from r56006, trunk/channels/
team/kpfleming/embedded-module-globals/codecs/
- copied from r56006, trunk/codecs/
team/kpfleming/embedded-module-globals/config.guess
- copied unchanged from r56006, trunk/config.guess
team/kpfleming/embedded-module-globals/config.sub
- copied unchanged from r56006, trunk/config.sub
team/kpfleming/embedded-module-globals/configs/
- copied from r56006, trunk/configs/
team/kpfleming/embedded-module-globals/configure
- copied unchanged from r56006, trunk/configure
team/kpfleming/embedded-module-globals/configure.ac
- copied unchanged from r56006, trunk/configure.ac
team/kpfleming/embedded-module-globals/contrib/
- copied from r56006, trunk/contrib/
team/kpfleming/embedded-module-globals/doc/
- copied from r56006, trunk/doc/
team/kpfleming/embedded-module-globals/formats/
- copied from r56006, trunk/formats/
team/kpfleming/embedded-module-globals/funcs/
- copied from r56006, trunk/funcs/
team/kpfleming/embedded-module-globals/images/
- copied from r56006, trunk/images/
team/kpfleming/embedded-module-globals/include/
- copied from r56006, trunk/include/
team/kpfleming/embedded-module-globals/install-sh
- copied unchanged from r56006, trunk/install-sh
team/kpfleming/embedded-module-globals/keys/
- copied from r56006, trunk/keys/
team/kpfleming/embedded-module-globals/main/
- copied from r56006, trunk/main/
team/kpfleming/embedded-module-globals/makeopts.in
- copied unchanged from r56006, trunk/makeopts.in
team/kpfleming/embedded-module-globals/missing
- copied unchanged from r56006, trunk/missing
team/kpfleming/embedded-module-globals/mkinstalldirs
- copied unchanged from r56006, trunk/mkinstalldirs
team/kpfleming/embedded-module-globals/pbx/
- copied from r56006, trunk/pbx/
team/kpfleming/embedded-module-globals/redhat/
- copied from r56006, trunk/redhat/
team/kpfleming/embedded-module-globals/res/
- copied from r56006, trunk/res/
team/kpfleming/embedded-module-globals/sample.call
- copied unchanged from r56006, trunk/sample.call
team/kpfleming/embedded-module-globals/sounds/
- copied from r56006, trunk/sounds/
team/kpfleming/embedded-module-globals/static-http/
- copied from r56006, trunk/static-http/
team/kpfleming/embedded-module-globals/utils/
- copied from r56006, trunk/utils/
Modified:
team/kpfleming/embedded-module-globals/include/asterisk/module.h
team/kpfleming/embedded-module-globals/main/loader.c
Copied: team/kpfleming/embedded-module-globals/Makefile.moddir_rules (from r56006, trunk/Makefile.moddir_rules)
URL: http://svn.digium.com/view/asterisk/team/kpfleming/embedded-module-globals/Makefile.moddir_rules?view=diff&rev=56068&p1=trunk/Makefile.moddir_rules&r1=56006&p2=team/kpfleming/embedded-module-globals/Makefile.moddir_rules&r2=56068
==============================================================================
--- trunk/Makefile.moddir_rules (original)
+++ team/kpfleming/embedded-module-globals/Makefile.moddir_rules Wed Feb 21 20:06:16 2007
@@ -34,11 +34,13 @@
$(LOADABLE_MODS:%=%.so): LIBS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LIB))
$(LOADABLE_MODS:%=%.so): ASTLDFLAGS+=$(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_LDFLAGS))
+$(EMBEDDED_MODS:%=%.o): ASTCFLAGS+=-DEMBEDDED_MODULE=$*
+
$(addsuffix .so,$(filter $(LOADABLE_MODS),$(C_MODS))): %.so: %.o
$(addsuffix .so,$(filter $(LOADABLE_MODS),$(CC_MODS))): %.so: %.oo
-modules.link: $(addsuffix .o,$(filter $(EMBEDDED_MODS),$(C_MODS)))
-modules.link: $(addsuffix .oo,$(filter $(EMBEDDED_MODS),$(CC_MODS)))
+modules.link: $(addsuffix .eo,$(filter $(EMBEDDED_MODS),$(C_MODS)))
+modules.link: $(addsuffix .eoo,$(filter $(EMBEDDED_MODS),$(CC_MODS)))
.PHONY: clean uninstall _all
@@ -64,11 +66,11 @@
modules.link:
@rm -f $@
- @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.o,$^)); do echo "INPUT (../$${file})" >> $@; done
- @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.o,$^)); do echo "INPUT (../$${file})" >> $@; done
+ @for file in $(patsubst %,$(SUBDIR)/%,$(filter %.eo %.eoo,$^)); do echo "INPUT (../$${file})" >> $@; done
+ @for file in $(patsubst %,$(SUBDIR)/%,$(filter-out %.eo %.eoo,$^)); do echo "INPUT (../$${file})" >> $@; done
clean::
- rm -f *.so *.o *.oo
+ rm -f *.so *.o *.oo *.eo *.eoo
rm -f .*.o.d .*.oo.d
rm -f modules.link
Copied: team/kpfleming/embedded-module-globals/Makefile.rules (from r56006, trunk/Makefile.rules)
URL: http://svn.digium.com/view/asterisk/team/kpfleming/embedded-module-globals/Makefile.rules?view=diff&rev=56068&p1=trunk/Makefile.rules&r1=56006&p2=team/kpfleming/embedded-module-globals/Makefile.rules&r2=56068
==============================================================================
--- trunk/Makefile.rules (original)
+++ team/kpfleming/embedded-module-globals/Makefile.rules Wed Feb 21 20:06:16 2007
@@ -44,6 +44,22 @@
$(CMD_PREFIX) $(CC) -o $@ -c $< $(PTHREAD_CFLAGS) $(ASTCFLAGS)
endif
+%.o: %.i
+ $(ECHO_PREFIX) echo " [CC] $< -> $@"
+ifeq ($(AST_DEVMODE),yes)
+ $(CMD_PREFIX) $(CC) -o $@ -c $< $(PTHREAD_CFLAGS) $(ASTCFLAGS) -MMD -MT $@ -MF .$(subst /,_,$@).d -MP
+else
+ $(CMD_PREFIX) $(CC) -o $@ -c $< $(PTHREAD_CFLAGS) $(ASTCFLAGS)
+endif
+
+%.i: %.c
+ $(ECHO_PREFIX) echo " [CC] $< -> $@"
+ifeq ($(AST_DEVMODE),yes)
+ $(CMD_PREFIX) $(CC) -o $@ -E $< $(PTHREAD_CFLAGS) $(ASTCFLAGS) -MMD -MT $@ -MF .$(subst /,_,$@).d -MP
+else
+ $(CMD_PREFIX) $(CC) -o $@ -E $< $(PTHREAD_CFLAGS) $(ASTCFLAGS)
+endif
+
%.o: %.s
$(ECHO_PREFIX) echo " [AS] $< -> $@"
ifeq ($(AST_DEVMODE),yes)
@@ -76,6 +92,18 @@
$(ECHO_PREFIX) echo " [LDXX] $^ -> $@"
$(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(ASTLDFLAGS) $(SOLINK) $^ $(PTHREAD_LIBS) $(LIBS)
+%.eo: %.o
+ $(ECHO_PREFIX) echo " [EMBED] $< -> $@"
+ $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_eo_script $* > .$@.ld
+ $(CMD_PREFIX) $(LD) -r -T .$@.ld -o $@ $<
+ $(CMD_PREFIX) rm -f .$@.ld
+
+%.eoo: %.o
+ $(ECHO_PREFIX) echo " [EMBED] $< -> $@"
+ $(CMD_PREFIX) $(ASTTOPDIR)/build_tools/make_linker_eo_script $* > .$@.ld
+ $(CMD_PREFIX) $(LD) -r -T .$@.ld -o $@ $<
+ $(CMD_PREFIX) rm -f .$@.ld
+
%: %.o
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
$(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(PTHREAD_CFLAGS) $(ASTLDFLAGS) $^ $(PTHREAD_LIBS) $(LIBS)
Added: team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script
URL: http://svn.digium.com/view/asterisk/team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script?view=auto&rev=56068
==============================================================================
--- team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script (added)
+++ team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script Wed Feb 21 20:06:16 2007
@@ -1,0 +1,27 @@
+#!/bin/sh
+
+cat << EOF
+SECTIONS {
+.text : { *(.text) }
+.data : { __${1}_data_start = . ; *(.data) __${1}_data_end = . ;}
+.rodata : { *(.rodata*) }
+.bss : { __${1}_bss_start = . ; *(.bss) __${1}_bss_end = . ;}
+.debug_abbrev : { *(.debug_abbrev) }
+.debug_info : { *(.debug_info) }
+.debug_line : { *(.debug_line) }
+.debug_macinfo : { *(.debug_macinfo) }
+.dtors : { *(.dtors) }
+.ctors : { *(.ctors) }
+.data.rel.local : { *(.data.rel.local) }
+.data.rel.ro.local : { *(.data.rel.ro.local) }
+.debug_frame : { *(.debug_frame) }
+.eh_frame : { *(.eh_frame) }
+.debug_loc : { *(.debug_loc) }
+.debug_pubname : { *(.debug_pubname) }
+.debug_aranges : { *(.debug_aranges) }
+.debug_ranges : { *(.debug_ranges) }
+.debug_str : { *(.debug_str) }
+.comment : { *(.comment) }
+.note.GNU-stack : { *(.note.GNU-stack) }
+}
+EOF
Propchange: team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script
------------------------------------------------------------------------------
svn:executable = *
Propchange: team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script
------------------------------------------------------------------------------
svn:keywords = Author ID Date Revision
Propchange: team/kpfleming/embedded-module-globals/build_tools/make_linker_eo_script
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/kpfleming/embedded-module-globals/include/asterisk/module.h
URL: http://svn.digium.com/view/asterisk/team/kpfleming/embedded-module-globals/include/asterisk/module.h?view=diff&rev=56068&r1=56006&r2=56068
==============================================================================
--- team/kpfleming/embedded-module-globals/include/asterisk/module.h (original)
+++ team/kpfleming/embedded-module-globals/include/asterisk/module.h Wed Feb 21 20:06:16 2007
@@ -192,6 +192,8 @@
enum ast_module_load_result (*load)(void); /* register stuff etc. Optional. */
int (*reload)(void); /* config etc. Optional. */
int (*unload)(void); /* unload. called with the module locked */
+ int (*backup_globals)(void); /* for embedded modules, backup global data */
+ void (*restore_globals)(void); /* for embedded modules, restore global data */
const char *name; /* name of the module for loader reference and CLI commands */
const char *description; /* user friendly description of the module. */
@@ -253,6 +255,75 @@
and populated at the end of the module's source file... */
const static __attribute__((unused)) struct ast_module_info *ast_module_info;
+#if defined(EMBEDDED_MODULE)
+
+#define make_var_sub(mod, type) __ ## mod ## _ ## type
+#define make_var(mod, type) make_var_sub(mod, type)
+
+extern void make_var(EMBEDDED_MODULE, bss_start);
+extern void make_var(EMBEDDED_MODULE, bss_end);
+extern void make_var(EMBEDDED_MODULE, data_start);
+extern void make_var(EMBEDDED_MODULE, data_end);
+
+static void * __attribute__((section(".embed_module"))) __global_backup;
+
+static int __backup_globals(void)
+{
+ size_t data_size = & make_var(EMBEDDED_MODULE, data_end) - & make_var(EMBEDDED_MODULE, data_start);
+
+ if (__global_backup)
+ return 0;
+
+ if (!data_size)
+ return 0;
+
+ if (!(__global_backup = ast_malloc(data_size)))
+ return -1;
+
+ memcpy(__global_backup, & make_var(EMBEDDED_MODULE, data_start), data_size);
+
+ return 0;
+}
+
+static void __restore_globals(void)
+{
+ size_t data_size = & make_var(EMBEDDED_MODULE, data_end) - & make_var(EMBEDDED_MODULE, data_start);
+ size_t bss_size = & make_var(EMBEDDED_MODULE, bss_end) - & make_var(EMBEDDED_MODULE, bss_start);
+
+ if (bss_size)
+ memset(& make_var(EMBEDDED_MODULE, bss_start), 0, bss_size);
+
+ if (!data_size || !__global_backup)
+ return;
+
+ memcpy(& make_var(EMBEDDED_MODULE, data_start), __global_backup, data_size);
+}
+
+#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \
+ static struct ast_module_info __mod_info = { \
+ .backup_globals = __backup_globals, \
+ .restore_globals = __restore_globals, \
+ .name = AST_MODULE, \
+ .flags = flags_to_set, \
+ .description = desc, \
+ .key = keystr, \
+ fields \
+ }; \
+ static void __attribute__ ((constructor)) __reg_module(void) \
+ { \
+ ast_module_register(&__mod_info); \
+ } \
+ static void __attribute__ ((destructor)) __unreg_module(void) \
+ { \
+ ast_module_unregister(&__mod_info); \
+ } \
+ const static struct ast_module_info *ast_module_info = &__mod_info
+
+#undef make_var
+#undef make_var_sub
+
+#else /* !defined(EMBEDDED_MODULE) */
+
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...) \
static struct ast_module_info __mod_info = { \
.name = AST_MODULE, \
@@ -271,6 +342,8 @@
} \
const static struct ast_module_info *ast_module_info = &__mod_info
+#endif /* !defined(EMBEDDED_MODULE) */
+
#define AST_MODULE_INFO_STANDARD(keystr, desc) \
AST_MODULE_INFO(keystr, AST_MODFLAG_DEFAULT, desc, \
.load = load_module, \
Modified: team/kpfleming/embedded-module-globals/main/loader.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/embedded-module-globals/main/loader.c?view=diff&rev=56068&r1=56006&r2=56068
==============================================================================
--- team/kpfleming/embedded-module-globals/main/loader.c (original)
+++ team/kpfleming/embedded-module-globals/main/loader.c Wed Feb 21 20:06:16 2007
@@ -483,6 +483,9 @@
if (!error)
ast_update_use_count();
+ if (!error && !mod->lib)
+ mod->info->restore_globals();
+
return res;
}
@@ -624,6 +627,11 @@
#if LOADABLE_MODULES
unload_dynamic_module(mod);
#endif
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ if (!mod->lib && mod->info->backup_globals()) {
+ ast_log(LOG_WARNING, "Module '%s' was unable to backup its global data.\n", resource_name);
return AST_MODULE_LOAD_DECLINE;
}
More information about the asterisk-commits
mailing list