VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/the-linux-kernel.h@ 46474

Last change on this file since 46474 was 44867, checked in by vboxsync, 12 years ago

Linux 3.9.0 rc0 compile fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1/* $Id: the-linux-kernel.h 44867 2013-02-28 13:46:12Z vboxsync $ */
2/** @file
3 * IPRT - Include all necessary headers for the Linux kernel.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___the_linux_kernel_h
28#define ___the_linux_kernel_h
29
30/*
31 * Include iprt/types.h to install the bool wrappers.
32 * Then use the linux bool type for all the stuff include here.
33 */
34#include <iprt/types.h>
35#define bool linux_bool
36
37#include <linux/version.h>
38#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
39# include <generated/autoconf.h>
40#else
41# ifndef AUTOCONF_INCLUDED
42# include <linux/autoconf.h>
43# endif
44#endif
45
46/* We only support 2.4 and 2.6 series kernels */
47#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
48# error We only support 2.4 and 2.6 series kernels
49#endif
50#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
51# error We only support 2.4 and 2.6 series kernels
52#endif
53
54#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
55# define MODVERSIONS
56# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
57# include <linux/modversions.h>
58# endif
59#endif
60#ifndef KBUILD_STR
61# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
62# define KBUILD_STR(s) s
63# else
64# define KBUILD_STR(s) #s
65# endif
66#endif
67# if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
68# include <linux/kconfig.h> /* for macro IS_ENABLED */
69# endif
70#include <linux/string.h>
71#include <linux/spinlock.h>
72#include <linux/slab.h>
73#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
74# include <linux/semaphore.h>
75#else /* older kernels */
76# include <asm/semaphore.h>
77#endif /* older kernels */
78#include <linux/module.h>
79#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
80# include <linux/moduleparam.h>
81#endif
82#include <linux/kernel.h>
83#include <linux/init.h>
84#include <linux/fs.h>
85#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
86# include <linux/namei.h>
87#endif
88#include <linux/mm.h>
89#include <linux/pagemap.h>
90#include <linux/slab.h>
91#include <linux/time.h>
92#include <linux/sched.h>
93#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
94# include <linux/sched/rt.h>
95#endif
96#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 7)
97# include <linux/jiffies.h>
98#endif
99#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 16)
100# include <linux/ktime.h>
101# include <linux/hrtimer.h>
102#endif
103#include <linux/wait.h>
104#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 71)
105# include <linux/cpu.h>
106# include <linux/notifier.h>
107#endif
108/* For the basic additions module */
109#include <linux/pci.h>
110#include <linux/delay.h>
111#include <linux/interrupt.h>
112#include <linux/completion.h>
113#include <linux/compiler.h>
114#ifndef HAVE_UNLOCKED_IOCTL /* linux/fs.h defines this */
115# include <linux/smp_lock.h>
116#endif
117/* For the shared folders module */
118#include <linux/vmalloc.h>
119#define wchar_t linux_wchar_t
120#include <linux/nls.h>
121#undef wchar_t
122#include <asm/mman.h>
123#include <asm/io.h>
124#include <asm/uaccess.h>
125#include <asm/div64.h>
126
127/* for workqueue / task queues. */
128#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
129# include <linux/workqueue.h>
130#else
131# include <linux/tqueue.h>
132#endif
133
134#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
135# include <linux/kthread.h>
136#endif
137
138#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
139# ifndef page_to_pfn
140# define page_to_pfn(page) ((page) - mem_map)
141# endif
142#endif
143
144#ifndef DEFINE_WAIT
145# define DEFINE_WAIT(name) DECLARE_WAITQUEUE(name, current)
146#endif
147
148/*
149 * 2.4 / early 2.6 compatibility wrappers
150 */
151#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 7)
152
153# ifndef MAX_JIFFY_OFFSET
154# define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
155# endif
156
157# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 29) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
158
159DECLINLINE(unsigned int) jiffies_to_msecs(unsigned long cJiffies)
160{
161# if HZ <= 1000 && !(1000 % HZ)
162 return (1000 / HZ) * cJiffies;
163# elif HZ > 1000 && !(HZ % 1000)
164 return (cJiffies + (HZ / 1000) - 1) / (HZ / 1000);
165# else
166 return (cJiffies * 1000) / HZ;
167# endif
168}
169
170DECLINLINE(unsigned long) msecs_to_jiffies(unsigned int cMillies)
171{
172# if HZ > 1000
173 if (cMillies > jiffies_to_msecs(MAX_JIFFY_OFFSET))
174 return MAX_JIFFY_OFFSET;
175# endif
176# if HZ <= 1000 && !(1000 % HZ)
177 return (cMillies + (1000 / HZ) - 1) / (1000 / HZ);
178# elif HZ > 1000 && !(HZ % 1000)
179 return cMillies * (HZ / 1000);
180# else
181 return (cMillies * HZ + 999) / 1000;
182# endif
183}
184
185# endif /* < 2.4.29 || >= 2.6.0 */
186
187#endif /* < 2.6.7 */
188
189/*
190 * 2.4 compatibility wrappers
191 */
192#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
193
194# define prepare_to_wait(q, wait, state) \
195 do { \
196 add_wait_queue(q, wait); \
197 set_current_state(state); \
198 } while (0)
199
200# define after_wait(wait) \
201 do { \
202 list_del_init(&(wait)->task_list); \
203 } while (0)
204
205# define finish_wait(q, wait) \
206 do { \
207 set_current_state(TASK_RUNNING); \
208 remove_wait_queue(q, wait); \
209 } while (0)
210
211#else /* >= 2.6.0 */
212
213# define after_wait(wait) do {} while (0)
214
215#endif /* >= 2.6.0 */
216
217/** @def TICK_NSEC
218 * The time between ticks in nsec */
219#ifndef TICK_NSEC
220# define TICK_NSEC (1000000000UL / HZ)
221#endif
222
223/*
224 * This sucks soooo badly on x86! Why don't they export __PAGE_KERNEL_EXEC so PAGE_KERNEL_EXEC would be usable?
225 */
226#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8) && defined(RT_ARCH_AMD64)
227# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL_EXEC
228#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8) && defined(PAGE_KERNEL_EXEC) && defined(CONFIG_X86_PAE)
229# ifdef __PAGE_KERNEL_EXEC
230 /* >= 2.6.27 */
231# define MY_PAGE_KERNEL_EXEC __pgprot(cpu_has_pge ? __PAGE_KERNEL_EXEC | _PAGE_GLOBAL : __PAGE_KERNEL_EXEC)
232# else
233# define MY_PAGE_KERNEL_EXEC __pgprot(cpu_has_pge ? _PAGE_KERNEL_EXEC | _PAGE_GLOBAL : _PAGE_KERNEL_EXEC)
234# endif
235#else
236# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL
237#endif
238
239
240/*
241 * The redhat hack section.
242 * - The current hacks are for 2.4.21-15.EL only.
243 */
244#ifndef NO_REDHAT_HACKS
245/* accounting. */
246# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
247# ifdef VM_ACCOUNT
248# define USE_RHEL4_MUNMAP
249# endif
250# endif
251
252/* backported remap_page_range. */
253# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
254# include <asm/tlb.h>
255# ifdef tlb_vma /* probably not good enough... */
256# define HAVE_26_STYLE_REMAP_PAGE_RANGE 1
257# endif
258# endif
259
260# ifndef RT_ARCH_AMD64
261/* In 2.6.9-22.ELsmp we have to call change_page_attr() twice when changing
262 * the page attributes from PAGE_KERNEL to something else, because there appears
263 * to be a bug in one of the many patches that redhat applied.
264 * It should be safe to do this on less buggy linux kernels too. ;-)
265 */
266# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
267 do { \
268 if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) \
269 change_page_attr(pPages, cPages, prot); \
270 change_page_attr(pPages, cPages, prot); \
271 } while (0)
272# endif /* !RT_ARCH_AMD64 */
273#endif /* !NO_REDHAT_HACKS */
274
275#ifndef MY_CHANGE_PAGE_ATTR
276# ifdef RT_ARCH_AMD64 /** @todo This is a cheap hack, but it'll get around that 'else BUG();' in __change_page_attr(). */
277# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
278 do { \
279 change_page_attr(pPages, cPages, PAGE_KERNEL_NOCACHE); \
280 change_page_attr(pPages, cPages, prot); \
281 } while (0)
282# else
283# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) change_page_attr(pPages, cPages, prot)
284# endif
285#endif
286
287#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
288# define MY_SET_PAGES_EXEC(pPages, cPages) set_pages_x(pPages, cPages)
289# define MY_SET_PAGES_NOEXEC(pPages, cPages) set_pages_nx(pPages, cPages)
290#else
291# define MY_SET_PAGES_EXEC(pPages, cPages) \
292 do { \
293 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
294 MY_CHANGE_PAGE_ATTR(pPages, cPages, MY_PAGE_KERNEL_EXEC); \
295 } while (0)
296# define MY_SET_PAGES_NOEXEC(pPages, cPages) \
297 do { \
298 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
299 MY_CHANGE_PAGE_ATTR(pPages, cPages, PAGE_KERNEL); \
300 } while (0)
301#endif
302
303/** @def ONE_MSEC_IN_JIFFIES
304 * The number of jiffies that make up 1 millisecond. Must be at least 1! */
305#if HZ <= 1000
306# define ONE_MSEC_IN_JIFFIES 1
307#elif !(HZ % 1000)
308# define ONE_MSEC_IN_JIFFIES (HZ / 1000)
309#else
310# define ONE_MSEC_IN_JIFFIES ((HZ + 999) / 1000)
311# error "HZ is not a multiple of 1000, the GIP stuff won't work right!"
312#endif
313
314/*
315 * Stop using the linux bool type.
316 */
317#undef bool
318
319/*
320 * There are post-2.6.24 kernels (confusingly with unchanged version number)
321 * which eliminate macros which were marked as deprecated.
322 */
323#ifndef __attribute_used__
324#define __attribute_used__ __used
325#endif
326
327/**
328 * Hack for shortening pointers on linux so we can stuff more stuff into the
329 * task_struct::comm field. This is used by the semaphore code but put here
330 * because we don't have any better place atm. Don't use outside IPRT, please.
331 */
332#ifdef RT_ARCH_AMD64
333# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( ((long)(addr) & (long)~UINT64_C(0xfffffff000000000)) )
334#else
335# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( (long)(addr) )
336#endif
337
338/**
339 * Puts semaphore info into the task_struct::comm field if IPRT_DEBUG_SEMS is
340 * defined.
341 */
342#ifdef IPRT_DEBUG_SEMS
343# define IPRT_DEBUG_SEMS_STATE(pThis, chState) \
344 snprintf(current->comm, sizeof(current->comm), "%c%lx", (chState), IPRT_DEBUG_SEMS_ADDRESS(pThis));
345#else
346# define IPRT_DEBUG_SEMS_STATE(pThis, chState) do { } while (0)
347#endif
348
349/**
350 * Puts semaphore info into the task_struct::comm field if IPRT_DEBUG_SEMS is
351 * defined.
352 */
353#ifdef IPRT_DEBUG_SEMS
354# define IPRT_DEBUG_SEMS_STATE_RC(pThis, chState, rc) \
355 snprintf(current->comm, sizeof(current->comm), "%c%lx:%d", (chState), IPRT_DEBUG_SEMS_ADDRESS(pThis), rc);
356#else
357# define IPRT_DEBUG_SEMS_STATE_RC(pThis, chState, rc) do { } while (0)
358#endif
359
360/*
361 * There are some conflicting defines in iprt/param.h, sort them out here.
362 */
363#ifndef ___iprt_param_h
364# undef PAGE_SIZE
365# undef PAGE_OFFSET_MASK
366# include <iprt/param.h>
367#endif
368
369/*
370 * Some global indicator macros.
371 */
372/** @def IPRT_LINUX_HAS_HRTIMER
373 * Whether the kernel support high resolution timers (Linux kernel versions
374 * 2.6.28 and later (hrtimer_add_expires_ns() & schedule_hrtimeout). */
375#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
376# define IPRT_LINUX_HAS_HRTIMER
377#endif
378
379/*
380 * Workqueue stuff, see initterm-r0drv-linux.c.
381 */
382#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
383typedef struct work_struct RTR0LNXWORKQUEUEITEM;
384#else
385typedef struct tq_struct RTR0LNXWORKQUEUEITEM;
386#endif
387DECLHIDDEN(void) rtR0LnxWorkqueuePush(RTR0LNXWORKQUEUEITEM *pWork, void (*pfnWorker)(RTR0LNXWORKQUEUEITEM *));
388DECLHIDDEN(void) rtR0LnxWorkqueueFlush(void);
389
390
391#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette