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]
Message-Id: <200803101207.20151.rusty@rustcorp.com.au>
Date:	Mon, 10 Mar 2008 12:07:19 +1100
From:	Rusty Russell <rusty@...tcorp.com.au>
To:	Al Viro <viro@...iv.linux.org.uk>
Cc:	Linus Torvalds <torvalds@...ux-foundation.org>,
	linux-kernel@...r.kernel.org, Jeff Garzik <jeff@...zik.org>
Subject: Re: [PATCH 5/5] typesafe: TIMER_INITIALIZER and setup_timer

On Thursday 06 March 2008 21:40:35 Al Viro wrote:
> extern void decay_to_pointer(void const volatile *);
> #define check_callback_type(f,x) (sizeof((0 ? decay_to_pointer(x),(f)(x) :
> (void)0), 0)) #define __setup_timer(timer, func, arg) \
> do {    \
> 	struct timer_list *__timer = (timer);   \
> 	__timer->function = (void (*)(unsigned long))(func); \
> 	__timer->data = (unsigned long)(arg);   \
> 	(void)check_callback_type(func, arg); \
> } while(0)

   Thanks for that snippet; it's much more complete than the last one I found.  
I especially like the handling of const- and volatile-taking callback fns.  
My version is uglier, pasted below.

   There are three problems I see here.  First, the lack of warning for "void 
intfn(int); DECLARE_TIMER(t, intfn, 0);", but that's relatively minor.  
Second, the change of all the users is just churn, with cast_if_type() it can 
be done over the next couple of years, if ever.

   Worst, I can't see a way to apply your technique in general, for 
non-void-returning functions (eg. interrupt handlers).

Here's the typesafe_cb () helper function from ccan (there are also 
typesafe_cb_preargs and postargs for callbacks with extra args):

/* Doesn't handle const volatile, but can be added. */
#define typesafe_cb(rettype, fn, arg)					\
	cast_if_type(cast_if_type(cast_if_type((fn),			\
					       rettype (*)(const typeof(arg)), \
					       rettype (*)(void *)),	\
				  rettype (*)(volatile typeof(arg)),	\
				  rettype (*)(void *)),			\
		     rettype (*)(typeof(arg)),				\
		     rettype (*)(void *))

> PS: apologies for missing your previous mail; ETOOBIGMBOX ;-/

That's fine, happens to all of us.  I was a little disappointed to return from 
holiday to discover that either your work or mine hadn't been merged tho :)

Cheers,
Rusty.
--
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