VirtualBox

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

Last change on this file since 8245 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1/* $Id: the-linux-kernel.h 8245 2008-04-21 17:24:28Z vboxsync $ */
2/** @file
3 * IPRT - Include all necessary headers for the Linux kernel.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___the_linux_kernel_h
32#define ___the_linux_kernel_h
33
34/*
35 * Include iprt/types.h to install the bool wrappers.
36 * Then use the linux bool type for all the stuff include here.
37 */
38#include <iprt/types.h>
39#define bool linux_bool
40
41#include <linux/autoconf.h>
42#include <linux/version.h>
43
44/* We only support 2.4 and 2.6 series kernels */
45#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
46# error We only support 2.4 and 2.6 series kernels
47#endif
48#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
49# error We only support 2.4 and 2.6 series kernels
50#endif
51
52#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
53# define MODVERSIONS
54# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
55# include <linux/modversions.h>
56# endif
57#endif
58#ifndef KBUILD_STR
59# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
60# define KBUILD_STR(s) s
61# else
62# define KBUILD_STR(s) #s
63# endif
64#endif
65#include <linux/string.h>
66#include <linux/spinlock.h>
67#include <linux/slab.h>
68#include <asm/semaphore.h>
69#include <linux/module.h>
70#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
71# include <linux/moduleparam.h>
72#endif
73#include <linux/kernel.h>
74#include <linux/init.h>
75#include <linux/fs.h>
76#include <linux/mm.h>
77#include <linux/pagemap.h>
78#include <linux/slab.h>
79#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 7)
80# include <linux/time.h>
81# include <linux/jiffies.h>
82#endif
83#include <linux/wait.h>
84/* For the basic additions module */
85#include <linux/pci.h>
86#include <linux/delay.h>
87#include <linux/interrupt.h>
88#include <linux/completion.h>
89#include <linux/compiler.h>
90#ifndef HAVE_UNLOCKED_IOCTL /* linux/fs.h defines this */
91# include <linux/smp_lock.h>
92#endif
93/* For the shared folders module */
94#include <linux/vmalloc.h>
95#define wchar_t linux_wchar_t
96#include <linux/nls.h>
97#undef wchar_t
98#include <asm/mman.h>
99#include <asm/io.h>
100#include <asm/uaccess.h>
101#include <asm/div64.h>
102
103#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
104# ifndef page_to_pfn
105# define page_to_pfn(page) ((page) - mem_map)
106# endif
107#endif
108
109#ifndef DEFINE_WAIT
110# define DEFINE_WAIT(name) DECLARE_WAITQUEUE(name, current)
111#endif
112
113/*
114 * 2.4 compatibility wrappers
115 */
116#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 7)
117
118# ifndef MAX_JIFFY_OFFSET
119# define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
120# endif
121
122#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 29) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
123
124DECLINLINE(unsigned int) jiffies_to_msecs(unsigned long cJiffies)
125{
126# if HZ <= 1000 && !(1000 % HZ)
127 return (1000 / HZ) * cJiffies;
128# elif HZ > 1000 && !(HZ % 1000)
129 return (cJiffies + (HZ / 1000) - 1) / (HZ / 1000);
130# else
131 return (cJiffies * 1000) / HZ;
132# endif
133}
134
135DECLINLINE(unsigned long) msecs_to_jiffies(unsigned int cMillies)
136{
137# if HZ > 1000
138 if (cMillies > jiffies_to_msecs(MAX_JIFFY_OFFSET))
139 return MAX_JIFFY_OFFSET;
140# endif
141# if HZ <= 1000 && !(1000 % HZ)
142 return (cMillies + (1000 / HZ) - 1) / (1000 / HZ);
143# elif HZ > 1000 && !(HZ % 1000)
144 return cMillies * (HZ / 1000);
145# else
146 return (cMillies * HZ + 999) / 1000;
147# endif
148}
149
150# endif /* < 2.4.29 || >= 2.6.0 */
151
152# define prepare_to_wait(q, wait, state) \
153 do { \
154 set_current_state(state); \
155 add_wait_queue(q, wait); \
156 } while (0)
157
158# define finish_wait(q, wait) \
159 do { \
160 remove_wait_queue(q, wait); \
161 set_current_state(TASK_RUNNING); \
162 } while (0)
163
164#endif /* < 2.6.7 */
165
166
167/*
168 * This sucks soooo badly on x86! Why don't they export __PAGE_KERNEL_EXEC so PAGE_KERNEL_EXEC would be usable?
169 */
170#if defined(RT_ARCH_AMD64)
171# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL_EXEC
172#elif defined(PAGE_KERNEL_EXEC) && defined(CONFIG_X86_PAE)
173# define MY_PAGE_KERNEL_EXEC __pgprot(cpu_has_pge ? _PAGE_KERNEL_EXEC | _PAGE_GLOBAL : _PAGE_KERNEL_EXEC)
174#else
175# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL
176#endif
177
178
179/*
180 * The redhat hack section.
181 * - The current hacks are for 2.4.21-15.EL only.
182 */
183#ifndef NO_REDHAT_HACKS
184/* accounting. */
185# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
186# ifdef VM_ACCOUNT
187# define MY_DO_MUNMAP(a,b,c) do_munmap(a, b, c, 0) /* should it be 1 or 0? */
188# endif
189# endif
190
191/* backported remap_page_range. */
192# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
193# include <asm/tlb.h>
194# ifdef tlb_vma /* probably not good enough... */
195# define HAVE_26_STYLE_REMAP_PAGE_RANGE 1
196# endif
197# endif
198
199# ifndef RT_ARCH_AMD64
200/* In 2.6.9-22.ELsmp we have to call change_page_attr() twice when changing
201 * the page attributes from PAGE_KERNEL to something else, because there appears
202 * to be a bug in one of the many patches that redhat applied.
203 * It should be safe to do this on less buggy linux kernels too. ;-)
204 */
205# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
206 do { \
207 if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) \
208 change_page_attr(pPages, cPages, prot); \
209 change_page_attr(pPages, cPages, prot); \
210 } while (0)
211# endif /* !RT_ARCH_AMD64 */
212#endif /* !NO_REDHAT_HACKS */
213
214#ifndef MY_DO_MUNMAP
215# define MY_DO_MUNMAP(a,b,c) do_munmap(a, b, c)
216#endif
217
218#ifndef MY_CHANGE_PAGE_ATTR
219# ifdef RT_ARCH_AMD64 /** @todo This is a cheap hack, but it'll get around that 'else BUG();' in __change_page_attr(). */
220# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
221 do { \
222 change_page_attr(pPages, cPages, PAGE_KERNEL_NOCACHE); \
223 change_page_attr(pPages, cPages, prot); \
224 } while (0)
225# else
226# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) change_page_attr(pPages, cPages, prot)
227# endif
228#endif
229
230#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
231# define MY_SET_PAGES_EXEC(pPages, cPages) set_pages_x(pPages, cPages)
232# define MY_SET_PAGES_NOEXEC(pPages, cPages) set_pages_nx(pPages, cPages)
233#else
234# define MY_SET_PAGES_EXEC(pPages, cPages) \
235 do { \
236 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
237 MY_CHANGE_PAGE_ATTR(pPages, cPages, MY_PAGE_KERNEL_EXEC); \
238 } while (0)
239# define MY_SET_PAGES_NOEXEC(pPages, cPages) \
240 do { \
241 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
242 MY_CHANGE_PAGE_ATTR(pPages, cPages, PAGE_KERNEL); \
243 } while (0)
244#endif
245
246#ifndef PAGE_OFFSET_MASK
247# define PAGE_OFFSET_MASK (PAGE_SIZE - 1)
248#endif
249
250/*
251 * Stop using the linux bool type.
252 */
253#undef bool
254
255/*
256 * There are post-2.6.24 kernels (confusingly with unchanged version number)
257 * which eliminate macros which were marked as deprecated.
258 */
259#ifndef __attribute_used__
260#define __attribute_used__ __used
261#endif
262
263/**
264 * Hack for shortening pointers on linux so we can stuff more stuff into the
265 * task_struct::comm field. This is used by the semaphore code but put here
266 * because we don't have any better place atm. Don't use outside IPRT, please.
267 */
268#ifdef RT_ARCH_AMD64
269# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( ((long)(addr) & (long)~UINT64_C(0xfffffff000000000)) )
270#else
271# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( (long)(addr) )
272#endif
273
274#endif
275
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