~n-muench/ubuntu/quantal/open-vm-tools/open-vm-tools.may2.sid-sync

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-30 09:48:43 UTC
  • mfrom: (1.1.5 upstream) (2.4.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090530094843-gdpza57r5iqsf124
Tags: 2009.05.22-167859-1
MergingĀ upstreamĀ versionĀ 2009.05.22-167859.

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_UACCESS_H__
20
 
#   define __COMPAT_UACCESS_H__
21
 
 
22
 
 
23
 
/* User space access functions moved in 2.1.7 to asm/uaccess.h --hpreg */
24
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 1, 7)
25
 
#   include <asm/uaccess.h>
26
 
#else
27
 
#   include <asm/segment.h>
28
 
#endif
29
 
 
30
 
 
31
 
/* get_user() API modified in 2.1.4 to take 2 arguments --hpreg */
32
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 1, 4)
33
 
#   define compat_get_user get_user
34
 
#else
35
 
/*
36
 
 * We assign 0 to the variable in case of failure to prevent "`_var' might be
37
 
 * used uninitialized in this function" compiler warnings. I think it is OK,
38
 
 * because the hardware-based version in newer kernels probably has the same
39
 
 * semantics and does not guarantee that the value of _var will not be
40
 
 * modified, should the access fail --hpreg
41
 
 */
42
 
#   define compat_get_user(_var, _uvAddr) ({                        \
43
 
   int _status;                                                     \
44
 
                                                                    \
45
 
   _status = verify_area(VERIFY_READ, _uvAddr, sizeof(*(_uvAddr))); \
46
 
   if (_status == 0) {                                              \
47
 
      (_var) = get_user(_uvAddr);                                   \
48
 
   } else {                                                         \
49
 
      (_var) = 0;                                                   \
50
 
   }                                                                \
51
 
   _status;                                                         \
52
 
})
53
 
#endif
54
 
 
55
 
 
56
 
/*
57
 
 * The copy_from_user() API appeared in 2.1.4
58
 
 *
59
 
 * The emulation is not perfect here, but it is conservative: on failure, we
60
 
 * always return the total size, instead of the potentially smaller faulty
61
 
 * size --hpreg
62
 
 *
63
 
 * Since 2.5.55 copy_from_user() is no longer macro.
64
 
 */
65
 
#if !defined(copy_from_user) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 0)
66
 
#   define copy_from_user(_to, _from, _size) ( \
67
 
   verify_area(VERIFY_READ, _from, _size)      \
68
 
       ? (_size)                               \
69
 
       : (memcpy_fromfs(_to, _from, _size), 0) \
70
 
)
71
 
#   define copy_to_user(_to, _from, _size) ( \
72
 
   verify_area(VERIFY_WRITE, _to, _size)     \
73
 
       ? (_size)                             \
74
 
       : (memcpy_tofs(_to, _from, _size), 0) \
75
 
)
76
 
#endif
77
 
 
78
 
 
79
 
#endif /* __COMPAT_UACCESS_H__ */