~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to modules/linux/vsock/include/compat_mm.h

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2008-08-15 21:21:40 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080815212140-05fhxj8wroosysmj
Tags: 2008.08.08-109361-1ubuntu1
* Merge from Debian unstable (LP: #258393), remaining Ubuntu change:
  - add ubuntu_toolchain_FTBFS.dpatch patch, fix FTBFS
* Update ubuntu_toolchain_FTBFS.dpatch patch for the new version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2002 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License as published by the
 
6
 * Free Software Foundation version 2 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
11
 * for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
#ifndef __COMPAT_MM_H__
 
20
#   define __COMPAT_MM_H__
 
21
 
 
22
 
 
23
#include <linux/mm.h>
 
24
 
 
25
 
 
26
/* The get_page() API appeared in 2.3.7 --hpreg */
 
27
/* Sometime during development it became function instead of macro --petr */
 
28
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0) && !defined(get_page) 
 
29
#   define get_page(_page) atomic_inc(&(_page)->count)
 
30
/* The __free_page() API is exported in 2.1.67 --hpreg */
 
31
#   if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 1, 67)
 
32
#      define put_page __free_page
 
33
#   else
 
34
#      include "compat_page.h"
 
35
 
 
36
#      define page_to_phys(_page) (page_to_pfn(_page) << PAGE_SHIFT)
 
37
#      define put_page(_page) free_page(page_to_phys(_page))
 
38
#   endif
 
39
#endif
 
40
 
 
41
 
 
42
/* page_count() is 2.4.0 invention. Unfortunately unavailable in some RedHat 
 
43
 * kernels (for example 2.4.21-4-RHEL3). */
 
44
/* It is function since 2.6.0, and hopefully RedHat will not play silly games
 
45
 * with mm_inline.h again... */
 
46
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) && !defined(page_count)
 
47
#  define page_count(page) atomic_read(&(page)->count)
 
48
#endif
 
49
 
 
50
 
 
51
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
 
52
#  define compat_vm_pgoff(vma) ((vma)->vm_offset >> PAGE_SHIFT)
 
53
 
 
54
static inline unsigned long compat_do_mmap_pgoff(struct file *file, unsigned long addr,
 
55
   unsigned long len, unsigned long prot,
 
56
   unsigned long flag, unsigned long pgoff)
 
57
{
 
58
   unsigned long ret = -EINVAL;
 
59
 
 
60
   if (pgoff < 1 << (32 - PAGE_SHIFT)) {
 
61
      ret = do_mmap(file, addr, len, prot, flag, pgoff << PAGE_SHIFT);
 
62
   }
 
63
   return ret;
 
64
}
 
65
 
 
66
#else
 
67
#  define compat_vm_pgoff(vma) (vma)->vm_pgoff
 
68
#  ifdef VMW_SKAS_MMAP
 
69
#    define compat_do_mmap_pgoff(f, a, l, p, g, o) \
 
70
                                do_mmap_pgoff(current->mm, f, a, l, p, g, o)
 
71
#  else
 
72
#    define compat_do_mmap_pgoff(f, a, l, p, g, o) \
 
73
                                do_mmap_pgoff(f, a, l, p, g, o)
 
74
#  endif
 
75
#endif
 
76
 
 
77
 
 
78
/* 2.2.x uses 0 instead of some define */
 
79
#ifndef NOPAGE_SIGBUS
 
80
#define NOPAGE_SIGBUS (0)
 
81
#endif
 
82
 
 
83
 
 
84
/* 2.2.x does not have HIGHMEM support */
 
85
#ifndef GFP_HIGHUSER
 
86
#define GFP_HIGHUSER (GFP_USER)
 
87
#endif
 
88
 
 
89
 
 
90
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
 
91
 
 
92
#include "compat_page.h"
 
93
 
 
94
static inline struct page * alloc_pages(unsigned int gfp_mask, unsigned int order)
 
95
{
 
96
   unsigned long addr;
 
97
   
 
98
   addr = __get_free_pages(gfp_mask, order);
 
99
   if (!addr) {
 
100
      return NULL;
 
101
   }
 
102
   return virt_to_page(addr);
 
103
}
 
104
#define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)
 
105
 
 
106
#endif
 
107
 
 
108
/*
 
109
 * In 2.4.14, the logic behind the UnlockPage macro was moved to the 
 
110
 * unlock_page() function. Later (in 2.5.12), the UnlockPage macro was removed
 
111
 * altogether, and nowadays everyone uses unlock_page().
 
112
 */
 
113
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 14)
 
114
#define compat_unlock_page(page) UnlockPage(page)
 
115
#else
 
116
#define compat_unlock_page(page) unlock_page(page)
 
117
#endif
 
118
 
 
119
/*
 
120
 * In 2.4.10, vmtruncate was changed from returning void to returning int.
 
121
 */
 
122
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 10)
 
123
#define compat_vmtruncate(inode, size)                                        \
 
124
({                                                                            \
 
125
   int result = 0;                                                            \
 
126
   vmtruncate(inode, size);                                                   \
 
127
   result;                                                                    \
 
128
})
 
129
#else
 
130
#define compat_vmtruncate(inode, size) vmtruncate(inode, size)
 
131
#endif
 
132
 
 
133
 
 
134
#endif /* __COMPAT_MM_H__ */