Handle globals more simply, declaring the "G" structure containing them directly in shell/hush.c.

This allows the "G" struct to show up in the debugger, so it can easily be inspected.
This commit is contained in:
Stephen Heumann 2014-11-06 13:08:38 -06:00
parent 9320c1e704
commit 3b1d003ea7
6 changed files with 7 additions and 82 deletions

View File

@ -16,8 +16,7 @@ COREUTILS_SRC = \
coreutils/test.ptr.hack.c
LIBBB_A_SRC = \
libbb/lineedit.c \
libbb/lineedptrhack.c
libbb/lineedit.c
LIBBB_B_SRC = \
libbb/appletlib.c \
@ -41,7 +40,6 @@ LIBBB_B_SRC = \
LIBBB_C_SRC = \
libbb/perror.msg.c \
libbb/signal.names.c \
libbb/ptrtoglobals.c \
libbb/safe.strncpy.c \
libbb/platform.c \
libbb/signals.c \

View File

@ -15,12 +15,10 @@ SRCS = \
libbb/perror.msg.c \
libbb/xatonum.c \
libbb/signal.names.c \
libbb/ptrtoglobals.c \
libbb/error.retval.c \
libbb/xfunc.die.c \
libbb/safe.strncpy.c \
libbb/lineedit.c \
libbb/lineedptrhack.c \
libbb/platform.c \
libbb/endofname.c \
libbb/signals.c \

View File

@ -1557,28 +1557,12 @@ extern const int const_int_1;
/* Providing hard guarantee on minimum size (think of BUFSIZ == 128) */
enum { COMMON_BUFSIZE = (BUFSIZ >= 256*sizeof(void*) ? BUFSIZ+1 : 256*sizeof(void*)) };
extern char bb_common_bufsiz1[COMMON_BUFSIZE];
/* This struct is deliberately not defined. */
/* See docs/keep_data_small.txt */
struct globals;
/* '*const' ptr makes gcc optimize code much better.
* Magic prevents ptr_to_globals from going into rodata.
* If you want to assign a value, use SET_PTR_TO_GLOBALS(x) */
extern struct globals *const ptr_to_globals;
/* At least gcc 3.4.6 on mipsel system needs optimization barrier */
#ifndef __ORCAC__
# define barrier() __asm__ __volatile__("":::"memory")
#else
# define barrier()
#endif
#define SET_PTR_TO_GLOBALS(x) do { \
(*(struct globals**)&ptr_to_globals) = (void*)(x); \
barrier(); \
} while (0)
#define FREE_PTR_TO_GLOBALS() do { \
if (ENABLE_FEATURE_CLEAN_UP) { \
free(ptr_to_globals); \
} \
} while (0)
/* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don't use it,
* use bb_default_login_shell and following defines.

View File

@ -1,23 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2008 by Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
struct lineedit_statics;
#ifndef GCC_COMBINE
/* We cheat here. It is declared as const ptr in libbb.h,
* but here we make it live in R/W memory */
struct lineedit_statics *lineedit_ptr_to_statics;
#else
/* gcc -combine will see through and complain */
/* Using alternative method which is more likely to break
* on weird architectures, compilers, linkers and so on */
struct lineedit_statics *const lineedit_ptr_to_statics __attribute__ ((section (".data")));
#endif

View File

@ -1,35 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2008 by Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
#include <errno.h>
struct globals;
#ifndef GCC_COMBINE
/* We cheat here. It is declared as const ptr in libbb.h,
* but here we make it live in R/W memory */
struct globals *ptr_to_globals;
#ifdef __GLIBC__
int *bb_errno;
#endif
#else
/* gcc -combine will see through and complain */
/* Using alternative method which is more likely to break
* on weird architectures, compilers, linkers and so on */
struct globals *const ptr_to_globals __attribute__ ((section (".data")));
#ifdef __GLIBC__
int *const bb_errno __attribute__ ((section (".data")));
#endif
#endif

View File

@ -831,21 +831,24 @@ struct globals {
#endif
char user_input_buf[ENABLE_FEATURE_EDITING ? CONFIG_FEATURE_EDITING_MAX_LEN : 2];
};
#define G (*ptr_to_globals)
static struct globals G;
/* Not #defining name to G.name - this quickly gets unwieldy
* (too many defines). Also, I actually prefer to see when a variable
* is global, thus "G." prefix is a useful hint */
#ifndef __GNO__
# define INIT_G() do { \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
/* memset(&G.sa, 0, sizeof(G.sa)); */ \
sigfillset(&G.sa.sa_mask); \
G.sa.sa_flags = SA_RESTART; \
} while (0)
#else
# define INIT_G() SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)))
# define INIT_G()
#endif
/* Used by lineedit. */
struct lineedit_statics;
struct lineedit_statics *lineedit_ptr_to_statics;
/* Function prototypes for builtins */
static int builtin_cd(char **argv) FAST_FUNC;