1
/*********************************************************
2
* Copyright (C) 2007 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation version 2 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* You should have received a copy of the GNU General Public License along
14
* with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
*********************************************************/
23
* Common logging functions for Linux kernel modules.
26
#include "driver-config.h"
27
#include "compat_kernel.h"
28
#include "compat_sched.h"
29
#include <asm/current.h>
31
#include "driverLog.h"
33
#define LINUXLOG_BUFFER_SIZE 1024
35
static const char *driverLogPrefix = "";
38
* vsnprintf was born in 2.4.10. Fall back on vsprintf if we're
41
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 10)
42
# define vsnprintf(str, size, fmt, args) vsprintf(str, fmt, args)
47
*----------------------------------------------------------------------------
51
* Initializes the Linux logging.
59
*----------------------------------------------------------------------------
63
DriverLog_Init(const char *prefix) // IN
65
driverLogPrefix = prefix ? prefix : "";
70
*----------------------------------------------------------------------
74
* Log error message from a Linux module.
82
*----------------------------------------------------------------------
86
DriverLogPrint(const char *level, // IN: KERN_* constant
87
const char *fmt, // IN: error format string
88
va_list args) // IN: arguments for format string
90
static char staticBuf[LINUXLOG_BUFFER_SIZE];
96
* By default, use a small buffer on the stack (thread safe). If it is too
97
* small, fall back to a larger static buffer (not thread safe).
100
if (vsnprintf(stackBuf, sizeof stackBuf, fmt, args2) < sizeof stackBuf) {
103
vsnprintf(staticBuf, sizeof staticBuf, fmt, args);
108
printk("%s%s[%d]: %s", level, driverLogPrefix, current->pid, buf);
113
*----------------------------------------------------------------------
117
* Warning messages from kernel module: logged into kernel log
126
*----------------------------------------------------------------------
130
Warning(const char *fmt, ...) // IN: warning format string
135
DriverLogPrint(KERN_WARNING, fmt, args);
141
*----------------------------------------------------------------------
145
* Log messages from kernel module: logged into kernel log
146
* as debug information.
154
*----------------------------------------------------------------------
158
Log(const char *fmt, ...) // IN: log format string
163
* Use the kernel log with at least a KERN_DEBUG level
164
* so it doesn't garbage the screen at (re)boot time on RedHat 6.0.
168
DriverLogPrint(KERN_DEBUG, fmt, args);
174
*----------------------------------------------------------------------
178
* ASSERTION failures and Panics from kernel module get here.
179
* Message is logged to the kernel log and on console.
187
*----------------------------------------------------------------------
191
Panic(const char *fmt, ...) // IN: panic format string
196
DriverLogPrint(KERN_EMERG, fmt, args);
202
/* Should die with %cs unwritable, or at least with page fault. */
203
asm volatile("movb $0, %cs:(0)");