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>] [day] [month] [year] [list]
Message-Id: <1245137800-5376-1-git-send-email-vapier@gentoo.org>
Date:	Tue, 16 Jun 2009 03:36:40 -0400
From:	Mike Frysinger <vapier@...too.org>
To:	linux-kernel@...r.kernel.org
Subject: [PATCH/RFC] new pr_xxx macros for init/devinit functions

The strings used in init/devinit functions normally stick around forever
even though the rest of the code/data was freed.  So create a new set of
pr_xxx macros which automatically place the strings used into the related
const sections so that when the regions get freed, the strings go as well.

Signed-off-by: Mike Frysinger <vapier@...too.org>
---
 include/linux/kernel.h |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 883cd44..988d474 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -377,6 +377,37 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 #define pr_cont(fmt, ...) \
 	printk(KERN_CONT fmt, ##__VA_ARGS__)
 
+/*
+ * Do a printk, but store the format string in a different section from the
+ * default one so that we can free the string memory when we're done with it.
+ */
+#define __pr_init(section, lvl, fmt, ...) do { \
+	static const __##section##const char __fmt[] = KERN_##lvl pr_fmt(fmt); \
+	printk(__fmt, ##__VA_ARGS__); \
+	} while (0)
+
+/* These are pr_xxx() variants that should be used in __init functions */
+#define _pr_init(lvl, fmt, ...)  __pr_init(init, lvl, fmt, ##__VA_ARGS__)
+#define pr_emerg_init(fmt, ...)   _pr_init(EMERG, fmt, ##__VA_ARGS__)
+#define pr_alert_init(fmt, ...)   _pr_init(ALERT, fmt, ##__VA_ARGS__)
+#define pr_crit_init(fmt, ...)    _pr_init(CRIT, fmt, ##__VA_ARGS__)
+#define pr_err_init(fmt, ...)     _pr_init(ERR, fmt, ##__VA_ARGS__)
+#define pr_warning_init(fmt, ...) _pr_init(WARNING, fmt, ##__VA_ARGS__)
+#define pr_notice_init(fmt, ...)  _pr_init(NOTICE, fmt, ##__VA_ARGS__)
+#define pr_info_init(fmt, ...)    _pr_init(INFO, fmt, ##__VA_ARGS__)
+#define pr_cont_init(fmt, ...)    _pr_init(CONT, fmt, ##__VA_ARGS__)
+
+/* These are pr_xxx() variants that should be used in __devinit functions */
+#define _pr_devinit(lvl, fmt, ...)  __pr_init(devinit, lvl, fmt, ##__VA_ARGS__)
+#define pr_emerg_devinit(fmt, ...)   _pr_devinit(EMERG, fmt, ##__VA_ARGS__)
+#define pr_alert_devinit(fmt, ...)   _pr_devinit(ALERT, fmt, ##__VA_ARGS__)
+#define pr_crit_devinit(fmt, ...)    _pr_devinit(CRIT, fmt, ##__VA_ARGS__)
+#define pr_err_devinit(fmt, ...)     _pr_devinit(ERR, fmt, ##__VA_ARGS__)
+#define pr_warning_devinit(fmt, ...) _pr_devinit(WARNING, fmt, ##__VA_ARGS__)
+#define pr_notice_devinit(fmt, ...)  _pr_devinit(NOTICE, fmt, ##__VA_ARGS__)
+#define pr_info_devinit(fmt, ...)    _pr_devinit(INFO, fmt, ##__VA_ARGS__)
+#define pr_cont_devinit(fmt, ...)    _pr_devinit(CONT, fmt, ##__VA_ARGS__)
+
 /* pr_devel() should produce zero code unless DEBUG is defined */
 #ifdef DEBUG
 #define pr_devel(fmt, ...) \
-- 
1.6.3.1

--
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