File: compat.h

package info (click to toggle)
mol 0.9.61-6
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 6,140 kB
  • ctags: 8,491
  • sloc: ansic: 50,560; asm: 2,826; sh: 458; makefile: 373; perl: 165; lex: 135; yacc: 131
file content (143 lines) | stat: -rw-r--r-- 3,829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* 
 *   Creation Date: <2000/08/06 01:27:53 samuel>
 *   Time-stamp: <2001/09/22 14:20:57 samuel>
 *   
 *	<compat.h>
 *	
 *	Kernel Compatibility Definitions
 *   
 *   Copyright (C) 2000, 2001 Samuel Rydh (samuel@ibrium.se)
 *   
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   as published by the Free Software Foundation
 *   
 */

#ifndef _H_COMPAT
#define _H_COMPAT

#include <linux/version.h>
#ifndef __ASSEMBLY__
#include <asm/atomic.h>
#include <linux/sched.h>	/* needed by <asm/mmu_context.h> */
#include <asm/mmu_context.h>
#include <asm/time.h>
#include "molif.h"
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
#define LINUX_24
#endif

#ifndef __ASSEMBLY__

// We detect Paul's new MM implementation by the absence of MUNGE_CONTEXT
// The linux-MM change was introduced in 2.4.6
#ifndef MUNGE_CONTEXT
#define NEW_LINUX_MM
#endif


// Symbols exported from the module molsymglueN.o 
extern ulong 		msym_flush_hash_page, msym_handle_mm_fault, msym_next_mmu_context;
extern molif_t		mol_interface;		/* exported by old, patched kernels */

struct vm_area_struct;
struct mm_struct;
struct task_struct;
struct _PTE;

extern ulong		*mc_flush_hash_page;
extern atomic_t		*mc_next_mmu_context;
extern molif_t		*mc_molif;
#ifdef LINUX_24
extern int		(*mc_handle_mm_fault)( struct mm_struct *mm, 
					    struct vm_area_struct *vma,
					    unsigned long addr, int write_access);
#else
extern int		(*mc_handle_mm_fault)( struct task_struct *tsk, 
					    struct vm_area_struct *vma,
					    unsigned long addr, int write_access );
extern ulong		mc_giveup_altivec;
#endif /* LINUX_24 */

extern int linux_vers;

#ifdef LINUX_24
#define compat_clear_page(x)	clear_page( (void*)(x) );
#else
#define compat_clear_page(x)	clear_page( x );
#endif

#ifdef LINUX_24
extern inline void _tlbie(unsigned long va) 
{
        asm volatile ("tlbie %0" : : "r"(va));
}
#endif

// The mmap mm->mmap_sem semaphore changed in 2.4.3-pre5 from
// semaphore to rw_semaphore.

extern void _compat_mmap_sem_up( void *sem );
extern void _compat_mmap_sem_down( void *sem );

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
 #define MMAP_SEM_UP(x)		up(x)
 #define MMAP_SEM_DOWN(x)	down(x)
#else
 #define MMAP_SEM_UP(x)		_compat_mmap_sem_up(x)
 #define MMAP_SEM_DOWN(x)	_compat_mmap_sem_down(x)
#endif


// atomic_add_return is not exported in 2.2.

#ifdef LINUX_24 
#define compat_atomic_add_return(a,v) atomic_add_return(a,v)
#else
static __inline__ int compat_atomic_add_return(int a, atomic_t *v) {
        int t;

        __asm__ __volatile__("\n\
1:      lwarx   %0,0,%3\n\
        add     %0,%2,%0\n\
        stwcx.  %0,0,%3\n\
        bne-    1b"
        : "=&r" (t), "=m" (v->counter)
        : "r" (a), "r" (v), "m" (v->counter)
        : "cc");

        return t;
}
#endif

#ifdef LINUX_24
#define CURRENT_MM  (current->mm)
#else
/* Use CURRENT_MM instead of current->mm. This makes the MOL module 
 * less kernel version dependent. If the module is compiled with the 
 * correct headers, __current_mm_offs will always contain the correct offset.
 */
#define CURRENT_MM  (*(struct mm_struct**)((char*)current + __current_mm_offs ))
extern int __current_mm_offs;
#endif

#ifdef LINUX_24
#define compat_clear_page_reserved( ptr )	ClearPageReserved( virt_to_page(ptr))
#define compat_set_page_reserved( ptr ) 	SetPageReserved( virt_to_page(ptr) )
#else
#define compat_clear_page_reserved( ptr )	clear_bit( PG_reserved, &mem_map[MAP_NR(ptr)].flags );
#define compat_set_page_reserved( ptr ) 	set_bit( PG_reserved, &mem_map[MAP_NR(ptr)].flags )
#endif
#endif	/* __ASSEMBLY__ */

#ifdef LINUX_24
#define get_tb_frequency() 	( tb_ticks_per_jiffy * HZ )
#else
#define get_tb_frequency() 	0	/* not available on 2.2 */
#endif


#endif   /* _H_COMPAT */