tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
"strict" weak aliases
Sometimes it is important that the type of an object matches the
type of its weak alias. See the attached patch that both adds a
type-safe __weak_alias() called __strict_weak_alias(), and fixes a buggy
__weak_alias() that __strict_weak_alias() would have caught during
compilation.
Thanks to Taylor R. Campbell for the incantation that was key
to making this work,
__unused static typeof(alias) *__weak_alias_##alias = &sym;
Does this look ok to commit?
Dave
--
David Young OJC Technologies
dyoung%ojctech.com@localhost Urbana, IL * (217) 344-0444 x24
Index: sys/sys/cdefs.h
===================================================================
RCS file: /cvsroot/src/sys/sys/cdefs.h,v
retrieving revision 1.86
diff -u -p -r1.86 cdefs.h
--- sys/sys/cdefs.h 23 Jun 2011 12:16:03 -0000 1.86
+++ sys/sys/cdefs.h 21 Jul 2011 19:04:12 -0000
@@ -63,6 +63,14 @@
#include <sys/cdefs_aout.h>
#endif
+#ifdef __GNUC__
+#define __strict_weak_alias(alias,sym)
\
+ __unused static typeof(alias) *__weak_alias_##alias = &sym; \
+ __weak_alias(alias,sym)
+#else
+#define __strict_weak_alias(alias,sym) __weak_alias(alias,sym)
+#endif
+
/*
* Optional marker for size-optimised MD calling convention.
*/
Index: sys/kern/kern_stub.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_stub.c,v
retrieving revision 1.34
diff -u -p -r1.34 kern_stub.c
--- sys/kern/kern_stub.c 6 Jul 2011 18:24:26 -0000 1.34
+++ sys/kern/kern_stub.c 21 Jul 2011 19:04:13 -0000
@@ -82,7 +82,8 @@ __KERNEL_RCSID(0, "$NetBSD: kern_stub.c,
#include <sys/userconf.h>
bool default_bus_space_is_equal(bus_space_tag_t, bus_space_tag_t);
-bool default_bus_space_handle_is_equal(bus_space_handle_t, bus_space_handle_t);
+bool default_bus_space_handle_is_equal(bus_space_tag_t, bus_space_handle_t,
+ bus_space_handle_t);
/*
* Nonexistent system call-- signal process (may want to handle it). Flag
@@ -137,8 +138,9 @@ __weak_alias(bus_space_reservation_map,
__weak_alias(bus_space_reservation_unmap, voidop);
__weak_alias(bus_space_tag_create, eopnotsupp);
__weak_alias(bus_space_tag_destroy, voidop);
-__weak_alias(bus_space_is_equal, default_bus_space_is_equal);
-__weak_alias(bus_space_handle_is_equal, default_bus_space_handle_is_equal);
+__strict_weak_alias(bus_space_is_equal, default_bus_space_is_equal);
+__strict_weak_alias(bus_space_handle_is_equal,
+ default_bus_space_handle_is_equal);
__weak_alias(userconf_bootinfo, voidop);
__weak_alias(userconf_init, voidop);
__weak_alias(userconf_prompt, voidop);
@@ -277,7 +279,8 @@ nullop(void *v)
}
bool
-default_bus_space_handle_is_equal(bus_space_handle_t h1, bus_space_handle_t h2)
+default_bus_space_handle_is_equal(bus_space_tag_t t,
+ bus_space_handle_t h1, bus_space_handle_t h2)
{
return memcmp(&h1, &h2, sizeof(h1)) == 0;
Home |
Main Index |
Thread Index |
Old Index