VirtualBox

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

Last change on this file since 33995 was 33441, checked in by vboxsync, 14 years ago

Linux additions: symlinks only for Linux 2.6 guests

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

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