diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-27 21:41:59 +0300 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-27 21:41:59 +0300 |
commit | 574f2f43948bb21d6e4187936ba5a5afccba25f6 (patch) | |
tree | 0b39aca564149e5ad30b3cc791228655ff1b1827 /shell | |
parent | fe66a0eca1bfeae0abc0fc1e7d3709f271e05e82 (diff) |
*: add optimization barrier to all "G trick" locations
Diffstat (limited to 'shell')
-rw-r--r-- | shell/Kbuild | 7 | ||||
-rw-r--r-- | shell/ash.c | 24 | ||||
-rw-r--r-- | shell/ash_ptr_hack.c | 16 | ||||
-rw-r--r-- | shell/hush.c | 5 | ||||
-rw-r--r-- | shell/msh.c | 2 |
5 files changed, 36 insertions, 18 deletions
diff --git a/shell/Kbuild b/shell/Kbuild index 36a8ffd3a..deedc24f3 100644 --- a/shell/Kbuild +++ b/shell/Kbuild @@ -5,8 +5,7 @@ # Licensed under the GPL v2, see the file LICENSE in this tarball. lib-y:= -lib-$(CONFIG_ASH) += ash.o -lib-$(CONFIG_HUSH) += hush.o -lib-$(CONFIG_MSH) += msh.o - +lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o +lib-$(CONFIG_HUSH) += hush.o +lib-$(CONFIG_MSH) += msh.o lib-$(CONFIG_CTTYHACK) += cttyhack.o diff --git a/shell/ash.c b/shell/ash.c index 9c762e2ed..9b1a73024 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -202,9 +202,8 @@ struct globals_misc { /* indicates specified signal received */ char gotsig[NSIG - 1]; }; -/* Make it reside in writable memory, yet make compiler understand that it is not going to change. */ -static struct globals_misc *const ptr_to_globals_misc __attribute__ ((section (".data"))); -#define G_misc (*ptr_to_globals_misc) +extern struct globals_misc *const ash_ptr_to_globals_misc; +#define G_misc (*ash_ptr_to_globals_misc) #define rootpid (G_misc.rootpid ) #define shlvl (G_misc.shlvl ) #define minusc (G_misc.minusc ) @@ -223,7 +222,8 @@ static struct globals_misc *const ptr_to_globals_misc __attribute__ ((section (" #define sigmode (G_misc.sigmode ) #define gotsig (G_misc.gotsig ) #define INIT_G_misc() do { \ - (*(struct globals_misc**)&ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \ + (*(struct globals_misc**)&ash_ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \ + barrier(); \ curdir = nullstr; \ physdir = nullstr; \ } while (0) @@ -1147,9 +1147,8 @@ struct globals_memstack { int herefd; // = -1; struct stack_block stackbase; }; -/* Make it reside in writable memory, yet make compiler understand that it is not going to change. */ -static struct globals_memstack *const ptr_to_globals_memstack __attribute__ ((section (".data"))); -#define G_memstack (*ptr_to_globals_memstack) +extern struct globals_memstack *const ash_ptr_to_globals_memstack; +#define G_memstack (*ash_ptr_to_globals_memstack) #define g_stackp (G_memstack.g_stackp ) #define markp (G_memstack.markp ) #define g_stacknxt (G_memstack.g_stacknxt ) @@ -1158,7 +1157,8 @@ static struct globals_memstack *const ptr_to_globals_memstack __attribute__ ((se #define herefd (G_memstack.herefd ) #define stackbase (G_memstack.stackbase ) #define INIT_G_memstack() do { \ - (*(struct globals_memstack**)&ptr_to_globals_memstack) = xzalloc(sizeof(G_memstack)); \ + (*(struct globals_memstack**)&ash_ptr_to_globals_memstack) = xzalloc(sizeof(G_memstack)); \ + barrier(); \ g_stackp = &stackbase; \ g_stacknxt = stackbase.space; \ g_stacknleft = MINSIZE; \ @@ -1778,9 +1778,8 @@ struct globals_var { struct var *vartab[VTABSIZE]; struct var varinit[ARRAY_SIZE(varinit_data)]; }; -/* Make it reside in writable memory, yet make compiler understand that it is not going to change. */ -static struct globals_var *const ptr_to_globals_var __attribute__ ((section (".data"))); -#define G_var (*ptr_to_globals_var) +extern struct globals_var *const ash_ptr_to_globals_var; +#define G_var (*ash_ptr_to_globals_var) #define shellparam (G_var.shellparam ) #define redirlist (G_var.redirlist ) #define g_nullredirs (G_var.g_nullredirs ) @@ -1789,7 +1788,8 @@ static struct globals_var *const ptr_to_globals_var __attribute__ ((section (".d #define varinit (G_var.varinit ) #define INIT_G_var() do { \ int i; \ - (*(struct globals_var**)&ptr_to_globals_var) = xzalloc(sizeof(G_var)); \ + (*(struct globals_var**)&ash_ptr_to_globals_var) = xzalloc(sizeof(G_var)); \ + barrier(); \ for (i = 0; i < ARRAY_SIZE(varinit_data); i++) { \ varinit[i].flags = varinit_data[i].flags; \ varinit[i].text = varinit_data[i].text; \ diff --git a/shell/ash_ptr_hack.c b/shell/ash_ptr_hack.c new file mode 100644 index 000000000..490b73b6d --- /dev/null +++ b/shell/ash_ptr_hack.c @@ -0,0 +1,16 @@ +/* vi: set sw=4 ts=4: */ +/* + * Copyright (C) 2008 by Denys Vlasenko <vda.linux@googlemail.com> + * + * Licensed under GPLv2, see file LICENSE in this tarball for details. + */ + +/* We cheat here. They are declared as const ptr in ash.c, + * but here we make them live in R/W memory */ +struct globals_misc; +struct globals_memstack; +struct globals_var; + +struct globals_misc *ash_ptr_to_globals_misc; +struct globals_memstack *ash_ptr_to_globals_memstack; +struct globals_var *ash_ptr_to_globals_var; diff --git a/shell/hush.c b/shell/hush.c index d9ef2390e..b44f35bdd 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -460,6 +460,9 @@ enum { run_list_level = 0 }; #endif #define charmap (G.charmap ) #define user_input_buf (G.user_input_buf ) +#define INIT_G() do { \ + SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ +} while (0) #define B_CHUNK 100 @@ -3778,7 +3781,7 @@ int hush_main(int argc, char **argv) char **e; struct variable *cur_var; - PTR_TO_GLOBALS = xzalloc(sizeof(G)); + INIT_G(); /* Deal with HUSH_VERSION */ shell_ver = const_shell_ver; /* copying struct here */ diff --git a/shell/msh.c b/shell/msh.c index 917b08a1e..569011bbd 100644 --- a/shell/msh.c +++ b/shell/msh.c @@ -705,7 +705,7 @@ struct globals { #define child_cmd (G.child_cmd ) #define iostack (G.iostack ) #define INIT_G() do { \ - PTR_TO_GLOBALS = xzalloc(sizeof(G)); \ + SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ global_env.linep = line; \ global_env.iobase = iostack; \ global_env.iop = iostack - 1; \ |