VirtualBox

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

最後變更 在這個檔案從62961是 62566,由 vboxsync 提交於 9 年 前

IPRT: More unused parameters.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 12.7 KB
 
1/* $Id: the-linux-kernel.h 62566 2016-07-26 15:16:41Z vboxsync $ */
2/** @file
3 * IPRT - Include all necessary headers for the Linux kernel.
4 */
5
6/*
7 * Copyright (C) 2006-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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#if RT_GNUC_PREREQ(4, 6)
38# pragma GCC diagnostic push
39#endif
40#if RT_GNUC_PREREQ(4, 2)
41# pragma GCC diagnostic ignored "-Wunused-parameter"
42#endif
43
44#include <linux/version.h>
45#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33)
46# include <generated/autoconf.h>
47#else
48# ifndef AUTOCONF_INCLUDED
49# include <linux/autoconf.h>
50# endif
51#endif
52
53/* We only support 2.4 and 2.6 series kernels */
54#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
55# error We only support 2.4 and 2.6 series kernels
56#endif
57#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
58# error We only support 2.4 and 2.6 series kernels
59#endif
60
61#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
62# define MODVERSIONS
63# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 71)
64# include <linux/modversions.h>
65# endif
66#endif
67#ifndef KBUILD_STR
68# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
69# define KBUILD_STR(s) s
70# else
71# define KBUILD_STR(s) #s
72# endif
73#endif
74# if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)
75# include <linux/kconfig.h> /* for macro IS_ENABLED */
76# endif
77#include <linux/string.h>
78#include <linux/spinlock.h>
79#include <linux/slab.h>
80#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
81# include <linux/semaphore.h>
82#else /* older kernels */
83# include <asm/semaphore.h>
84#endif /* older kernels */
85#include <linux/module.h>
86#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
87# include <linux/moduleparam.h>
88#endif
89#include <linux/kernel.h>
90#include <linux/init.h>
91#include <linux/fs.h>
92#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
93# include <linux/namei.h>
94#endif
95#include <linux/mm.h>
96#include <linux/pagemap.h>
97#include <linux/slab.h>
98#include <linux/time.h>
99#include <linux/sched.h>
100#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
101# include <linux/sched/rt.h>
102#endif
103#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 7)
104# include <linux/jiffies.h>
105#endif
106#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 16)
107# include <linux/ktime.h>
108# include <linux/hrtimer.h>
109#endif
110#include <linux/wait.h>
111#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 71)
112# include <linux/cpu.h>
113# include <linux/notifier.h>
114#endif
115/* For the basic additions module */
116#include <linux/pci.h>
117#include <linux/delay.h>
118#include <linux/interrupt.h>
119#include <linux/completion.h>
120#include <linux/compiler.h>
121#ifndef HAVE_UNLOCKED_IOCTL /* linux/fs.h defines this */
122# include <linux/smp_lock.h>
123#endif
124/* For the shared folders module */
125#include <linux/vmalloc.h>
126#define wchar_t linux_wchar_t
127#include <linux/nls.h>
128#undef wchar_t
129#include <asm/mman.h>
130#include <asm/io.h>
131#include <asm/uaccess.h>
132#include <asm/div64.h>
133
134/* For thread-context hooks. */
135#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) && defined(CONFIG_PREEMPT_NOTIFIERS)
136# include <linux/preempt.h>
137#endif
138
139/* for workqueue / task queues. */
140#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
141# include <linux/workqueue.h>
142#else
143# include <linux/tqueue.h>
144#endif
145
146#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
147# include <linux/kthread.h>
148#endif
149
150/* for cr4_init_shadow() / cpu_tlbstate. */
151#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 20, 0)
152# include <asm/tlbflush.h>
153#endif
154
155#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
156# include <asm/smap.h>
157#else
158static inline void clac(void) { }
159static inline void stac(void) { }
160#endif
161
162#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
163# ifndef page_to_pfn
164# define page_to_pfn(page) ((page) - mem_map)
165# endif
166#endif
167
168#ifndef DEFINE_WAIT
169# define DEFINE_WAIT(name) DECLARE_WAITQUEUE(name, current)
170#endif
171
172#ifndef __GFP_NOWARN
173# define __GFP_NOWARN 0
174#endif
175
176/*
177 * 2.4 / early 2.6 compatibility wrappers
178 */
179#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 7)
180
181# ifndef MAX_JIFFY_OFFSET
182# define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
183# endif
184
185# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 29) || LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
186
187DECLINLINE(unsigned int) jiffies_to_msecs(unsigned long cJiffies)
188{
189# if HZ <= 1000 && !(1000 % HZ)
190 return (1000 / HZ) * cJiffies;
191# elif HZ > 1000 && !(HZ % 1000)
192 return (cJiffies + (HZ / 1000) - 1) / (HZ / 1000);
193# else
194 return (cJiffies * 1000) / HZ;
195# endif
196}
197
198DECLINLINE(unsigned long) msecs_to_jiffies(unsigned int cMillies)
199{
200# if HZ > 1000
201 if (cMillies > jiffies_to_msecs(MAX_JIFFY_OFFSET))
202 return MAX_JIFFY_OFFSET;
203# endif
204# if HZ <= 1000 && !(1000 % HZ)
205 return (cMillies + (1000 / HZ) - 1) / (1000 / HZ);
206# elif HZ > 1000 && !(HZ % 1000)
207 return cMillies * (HZ / 1000);
208# else
209 return (cMillies * HZ + 999) / 1000;
210# endif
211}
212
213# endif /* < 2.4.29 || >= 2.6.0 */
214
215#endif /* < 2.6.7 */
216
217/*
218 * 2.4 compatibility wrappers
219 */
220#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
221
222# define prepare_to_wait(q, wait, state) \
223 do { \
224 add_wait_queue(q, wait); \
225 set_current_state(state); \
226 } while (0)
227
228# define after_wait(wait) \
229 do { \
230 list_del_init(&(wait)->task_list); \
231 } while (0)
232
233# define finish_wait(q, wait) \
234 do { \
235 set_current_state(TASK_RUNNING); \
236 remove_wait_queue(q, wait); \
237 } while (0)
238
239#else /* >= 2.6.0 */
240
241# define after_wait(wait) do {} while (0)
242
243#endif /* >= 2.6.0 */
244
245/** @def TICK_NSEC
246 * The time between ticks in nsec */
247#ifndef TICK_NSEC
248# define TICK_NSEC (1000000000UL / HZ)
249#endif
250
251/*
252 * This sucks soooo badly on x86! Why don't they export __PAGE_KERNEL_EXEC so PAGE_KERNEL_EXEC would be usable?
253 */
254#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8) && defined(RT_ARCH_AMD64)
255# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL_EXEC
256#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 8) && defined(PAGE_KERNEL_EXEC) && defined(CONFIG_X86_PAE)
257# ifdef __PAGE_KERNEL_EXEC
258 /* >= 2.6.27 */
259# define MY_PAGE_KERNEL_EXEC __pgprot(cpu_has_pge ? __PAGE_KERNEL_EXEC | _PAGE_GLOBAL : __PAGE_KERNEL_EXEC)
260# else
261# define MY_PAGE_KERNEL_EXEC __pgprot(cpu_has_pge ? _PAGE_KERNEL_EXEC | _PAGE_GLOBAL : _PAGE_KERNEL_EXEC)
262# endif
263#else
264# define MY_PAGE_KERNEL_EXEC PAGE_KERNEL
265#endif
266
267
268/*
269 * The redhat hack section.
270 * - The current hacks are for 2.4.21-15.EL only.
271 */
272#ifndef NO_REDHAT_HACKS
273/* accounting. */
274# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
275# ifdef VM_ACCOUNT
276# define USE_RHEL4_MUNMAP
277# endif
278# endif
279
280/* backported remap_page_range. */
281# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
282# include <asm/tlb.h>
283# ifdef tlb_vma /* probably not good enough... */
284# define HAVE_26_STYLE_REMAP_PAGE_RANGE 1
285# endif
286# endif
287
288# ifndef RT_ARCH_AMD64
289/* In 2.6.9-22.ELsmp we have to call change_page_attr() twice when changing
290 * the page attributes from PAGE_KERNEL to something else, because there appears
291 * to be a bug in one of the many patches that redhat applied.
292 * It should be safe to do this on less buggy linux kernels too. ;-)
293 */
294# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
295 do { \
296 if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) \
297 change_page_attr(pPages, cPages, prot); \
298 change_page_attr(pPages, cPages, prot); \
299 } while (0)
300# endif /* !RT_ARCH_AMD64 */
301#endif /* !NO_REDHAT_HACKS */
302
303#ifndef MY_CHANGE_PAGE_ATTR
304# ifdef RT_ARCH_AMD64 /** @todo This is a cheap hack, but it'll get around that 'else BUG();' in __change_page_attr(). */
305# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) \
306 do { \
307 change_page_attr(pPages, cPages, PAGE_KERNEL_NOCACHE); \
308 change_page_attr(pPages, cPages, prot); \
309 } while (0)
310# else
311# define MY_CHANGE_PAGE_ATTR(pPages, cPages, prot) change_page_attr(pPages, cPages, prot)
312# endif
313#endif
314
315#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
316# define MY_SET_PAGES_EXEC(pPages, cPages) set_pages_x(pPages, cPages)
317# define MY_SET_PAGES_NOEXEC(pPages, cPages) set_pages_nx(pPages, cPages)
318#else
319# define MY_SET_PAGES_EXEC(pPages, cPages) \
320 do { \
321 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
322 MY_CHANGE_PAGE_ATTR(pPages, cPages, MY_PAGE_KERNEL_EXEC); \
323 } while (0)
324# define MY_SET_PAGES_NOEXEC(pPages, cPages) \
325 do { \
326 if (pgprot_val(MY_PAGE_KERNEL_EXEC) != pgprot_val(PAGE_KERNEL)) \
327 MY_CHANGE_PAGE_ATTR(pPages, cPages, PAGE_KERNEL); \
328 } while (0)
329#endif
330
331/** @def ONE_MSEC_IN_JIFFIES
332 * The number of jiffies that make up 1 millisecond. Must be at least 1! */
333#if HZ <= 1000
334# define ONE_MSEC_IN_JIFFIES 1
335#elif !(HZ % 1000)
336# define ONE_MSEC_IN_JIFFIES (HZ / 1000)
337#else
338# define ONE_MSEC_IN_JIFFIES ((HZ + 999) / 1000)
339# error "HZ is not a multiple of 1000, the GIP stuff won't work right!"
340#endif
341
342/*
343 * Stop using the linux bool type.
344 */
345#undef bool
346
347#if RT_GNUC_PREREQ(4, 6)
348# pragma GCC diagnostic pop
349#endif
350
351/*
352 * There are post-2.6.24 kernels (confusingly with unchanged version number)
353 * which eliminate macros which were marked as deprecated.
354 */
355#ifndef __attribute_used__
356#define __attribute_used__ __used
357#endif
358
359/**
360 * Hack for shortening pointers on linux so we can stuff more stuff into the
361 * task_struct::comm field. This is used by the semaphore code but put here
362 * because we don't have any better place atm. Don't use outside IPRT, please.
363 */
364#ifdef RT_ARCH_AMD64
365# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( ((long)(addr) & (long)~UINT64_C(0xfffffff000000000)) )
366#else
367# define IPRT_DEBUG_SEMS_ADDRESS(addr) ( (long)(addr) )
368#endif
369
370/**
371 * Puts semaphore info into the task_struct::comm field if IPRT_DEBUG_SEMS is
372 * defined.
373 */
374#ifdef IPRT_DEBUG_SEMS
375# define IPRT_DEBUG_SEMS_STATE(pThis, chState) \
376 snprintf(current->comm, sizeof(current->comm), "%c%lx", (chState), IPRT_DEBUG_SEMS_ADDRESS(pThis));
377#else
378# define IPRT_DEBUG_SEMS_STATE(pThis, chState) do { } while (0)
379#endif
380
381/**
382 * Puts semaphore info into the task_struct::comm field if IPRT_DEBUG_SEMS is
383 * defined.
384 */
385#ifdef IPRT_DEBUG_SEMS
386# define IPRT_DEBUG_SEMS_STATE_RC(pThis, chState, rc) \
387 snprintf(current->comm, sizeof(current->comm), "%c%lx:%d", (chState), IPRT_DEBUG_SEMS_ADDRESS(pThis), rc);
388#else
389# define IPRT_DEBUG_SEMS_STATE_RC(pThis, chState, rc) do { } while (0)
390#endif
391
392/** @name Macros for preserving EFLAGS.AC on 3.19+/amd64 paranoid.
393 * The AMD 64 switch_to in macro in arch/x86/include/asm/switch_to.h stopped
394 * restoring flags.
395 * @{ */
396#if defined(CONFIG_X86_SMAP) || defined(RT_STRICT) || defined(IPRT_WITH_EFLAGS_AC_PRESERVING)
397# include <iprt/asm-amd64-x86.h>
398# define IPRT_X86_EFL_AC RT_BIT(18)
399# define IPRT_LINUX_SAVE_EFL_AC() RTCCUINTREG fSavedEfl = ASMGetFlags()
400# define IPRT_LINUX_RESTORE_EFL_AC() ASMSetFlags(fSavedEfl)
401# define IPRT_LINUX_RESTORE_EFL_ONLY_AC() ASMChangeFlags(~IPRT_X86_EFL_AC, fSavedEfl & IPRT_X86_EFL_AC)
402#else
403# define IPRT_LINUX_SAVE_EFL_AC() do { } while (0)
404# define IPRT_LINUX_RESTORE_EFL_AC() do { } while (0)
405# define IPRT_LINUX_RESTORE_EFL_ONLY_AC() do { } while (0)
406#endif
407/** @} */
408
409/*
410 * There are some conflicting defines in iprt/param.h, sort them out here.
411 */
412#ifndef ___iprt_param_h
413# undef PAGE_SIZE
414# undef PAGE_OFFSET_MASK
415# include <iprt/param.h>
416#endif
417
418/*
419 * Some global indicator macros.
420 */
421/** @def IPRT_LINUX_HAS_HRTIMER
422 * Whether the kernel support high resolution timers (Linux kernel versions
423 * 2.6.28 and later (hrtimer_add_expires_ns() & schedule_hrtimeout). */
424#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
425# define IPRT_LINUX_HAS_HRTIMER
426#endif
427
428/*
429 * Workqueue stuff, see initterm-r0drv-linux.c.
430 */
431#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 41)
432typedef struct work_struct RTR0LNXWORKQUEUEITEM;
433#else
434typedef struct tq_struct RTR0LNXWORKQUEUEITEM;
435#endif
436DECLHIDDEN(void) rtR0LnxWorkqueuePush(RTR0LNXWORKQUEUEITEM *pWork, void (*pfnWorker)(RTR0LNXWORKQUEUEITEM *));
437DECLHIDDEN(void) rtR0LnxWorkqueueFlush(void);
438
439
440#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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