lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 8 Dec 2014 10:42:10 -0500
From:	Steven Rostedt <rostedt@...dmis.org>
To:	"Javi Merino" <javi.merino@....com>
Cc:	linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
	punit.agrawal@....com, broonie@...nel.org,
	Dave Martin <Dave.Martin@....com>,
	Ingo Molnar <mingo@...hat.com>
Subject: Re: [RFC PATCH v6 1/9] tracing: Add array printing helpers

On Fri,  5 Dec 2014 19:04:12 +0000
"Javi Merino" <javi.merino@....com> wrote:

 
> +static const char *
> +ftrace_print_array_seq(struct trace_seq *p, const void *buf, int buf_len,
> +		       bool (*iterator)(struct trace_seq *p, const char *prefix,
> +					const void **buf, int *buf_len))
> +{
> +	const char *ret = trace_seq_buffer_ptr(p);
> +	const char *prefix = "";
> +
> +	trace_seq_putc(p, '{');
> +
> +	while (iterator(p, prefix, &buf, &buf_len))
> +		prefix = ",";
> +
> +	trace_seq_putc(p, '}');
> +	trace_seq_putc(p, 0);
> +
> +	return ret;
> +}
> +
> +#define DEFINE_PRINT_ARRAY(type, printk_type, format)			\
> +static bool								\
> +ftrace_print_array_iterator_##type(struct trace_seq *p, const char *prefix, \
> +				   const void **buf, int *buf_len)	\
> +{									\
> +	const type *__src = *buf;					\
> +									\
> +	if (*buf_len < sizeof(*__src))					\
> +		return false;						\
> +									\
> +	trace_seq_printf(p, "%s" format, prefix, (printk_type)*__src++); \
> +									\
> +	*buf = __src;							\
> +	*buf_len -= sizeof(*__src);					\
> +									\
> +	return true;							\
> +}									\
> +									\
> +const char *ftrace_print_##type##_array_seq(				\
> +	struct trace_seq *p, const type *buf, int count)		\
> +{									\
> +	return ftrace_print_array_seq(p, buf, (count) * sizeof(type),	\
> +				      ftrace_print_array_iterator_##type); \
> +}									\
> +									\
> +EXPORT_SYMBOL(ftrace_print_##type##_array_seq)
> +
> +DEFINE_PRINT_ARRAY(u8, unsigned int, "0x%x");
> +DEFINE_PRINT_ARRAY(u16, unsigned int, "0x%x");
> +DEFINE_PRINT_ARRAY(u32, unsigned int, "0x%x");
> +DEFINE_PRINT_ARRAY(u64, unsigned long long, "0x%llx");
> +

I would really like to avoid adding a bunch of macros for each type.
Can't we have something like this:

ftrace_print_array(struct trace_seq *p, void *buf, int buf_len, 
		int size)
{
	char *prefix = "";
	void *ptr = buf;

	while (ptr < buf + buf_len) {
		switch(size) {
		case 8:
			trace_seq_printf("%s0x%x", prefix,
				*(unsigned char *)ptr);
			break;
		case 16:
			trace_seq_printf("%s0x%x", prefix,
				*(unsigned short *)ptr);
			break;
		case 32:
			trace_seq_printf("%s0x%x", prefix,
				*(unsigned int *)ptr);
			break;
		case 64:
			trace_seq_printf("%s0x%llx", prefix,
				*(unsigned long long *)ptr);
			break;
		default:
			BUG();
		}
		prefix = ",";
		ptr += size;
	}

}

We probably could even make the "BUG()" into a build bug, with a little
work.

-- Steve

>  int ftrace_raw_output_prep(struct trace_iterator *iter,
>  			   struct trace_event *trace_event)
>  {

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ