[sheepdog] [PATCH] Fix hardcode AMD64 assembly code (RSP)

Liu Yuan namei.unix at gmail.com
Mon Jul 29 05:41:17 CEST 2013


On Sun, Jul 28, 2013 at 02:05:49AM +0800, YunQiang Su wrote:
> RSP is a register name only for AMD64 (x86_64) platform,
> while on other platform it may be another name.
> 
> On i386 (x86_32) platform, it is "esp".
> On most of RISC platform (PowerPC, SPARC, MIPS, ARM, etc),
> it is "sp".
> ---
>  include/logger.h | 23 ++++++++++++++++++++++-
>  lib/logger.c     |  5 -----
>  2 files changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/include/logger.h b/include/logger.h
> index 79eb108..81691b2 100644
> --- a/include/logger.h
> +++ b/include/logger.h
> @@ -38,10 +38,31 @@ void log_write(int prio, const char *func, int line, const char *fmt, ...)
>  void set_thread_name(const char *name, bool show_idx);
>  void get_thread_name(char *name);
>  
> +#ifdef __i386__
> +#define SP_REG "esp"
> +#elif defined(__x86_64__)
> +#define SP_REG "rsp"
> +#elif defined(__mips__) || defined(__sparc__) || \
> +      defined (__arm__) || (defined __powerpc__) || \
> +      defined (__s390__) || (defined __s390x__) || \
> +      defined (__ia64__)
> +#define SP_REG "sp"
> +#endif
> +
> +#ifdef SP_REG
> +#define dump_stack_frames() ({			\
> +	register void *current_sp asm(SP_REG);	\
> +	__dump_stack_frames(current_sp);	\
> +})
>  #define sd_dump_variable(var) ({		\
> -	register void *current_sp asm("rsp");	\
> +	register void *current_sp asm(SP_REG);	\
>  	__sd_dump_variable(#var, current_sp);	\
>  })
> +#else
> +#define dump_stack_frames() ()
> +#define sd_dump_variable(var) ()
> +#endif
> +
>  int __sd_dump_variable(const char *var, const void *base_sp);
>  void sd_backtrace(void);
>  
> diff --git a/lib/logger.c b/lib/logger.c
> index 253163d..ba55adc 100644
> --- a/lib/logger.c
> +++ b/lib/logger.c
> @@ -742,11 +742,6 @@ notrace int __sd_dump_variable(const char *var, const void *base_sp)
>  	return 0;
>  }
>  
> -#define dump_stack_frames() ({			\
> -	register void *current_sp asm("rsp");	\
> -	__dump_stack_frames(current_sp);	\
> -})

I think maybe we can remove assembly completely to get stack pointer, just define
local variable and it is already on the stack. Might need some trick to get the
exact stack pointer address.

Thanks
Yuan



More information about the sheepdog mailing list