move new files out from platform support patch
[openwrt/openwrt.git] / target / linux / ubicom32 / files / arch / ubicom32 / kernel / uaccess.c
1 /*
2 * arch/ubicom32/include/asm/uaccess.c
3 * User space memory access functions for Ubicom32 architecture.
4 *
5 * (C) Copyright 2009, Ubicom, Inc.
6 *
7 * This file is part of the Ubicom32 Linux Kernel Port.
8 *
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
22 *
23 * Ubicom32 implementation derived from (with many thanks):
24 * arch/m68knommu
25 * arch/blackfin
26 * arch/parisc
27 */
28
29 #include <linux/sched.h>
30 #include <linux/mm.h>
31 #include <linux/string.h>
32 #include <linux/module.h>
33
34 #include <asm/segment.h>
35 #include <asm/uaccess.h>
36
37 extern int _stext, _etext, _sdata, _edata, _sbss, _ebss, _end;
38
39 /*
40 * __access_ok()
41 * Check that the address is in the current processes.
42 *
43 * NOTE: The kernel uses "pretend" user addresses that wind
44 * up calling access_ok() so this approach has only marginal
45 * value because you wind up with lots of false positives.
46 */
47 int __access_ok(unsigned long addr, unsigned long size)
48 {
49 // struct vm_area_struct *vma;
50
51 /*
52 * Don't do anything if we are not a running system yet.
53 */
54 if (system_state != SYSTEM_RUNNING) {
55 return 1;
56 }
57
58 /*
59 * It appears that Linux will call this function even when we are not
60 * in the context of a user space application that has a VM address
61 * space. So we must check that current and mm are valid before
62 * performing the check.
63 */
64 if ((!current) || (!current->mm)) {
65 return 1;
66 }
67
68 /*
69 * We perform some basic checks on the address to ensure that it
70 * is at least within the range of DRAM.
71 */
72 if ((addr < (int)&_etext) || (addr > memory_end)) {
73 printk(KERN_WARNING "pid=%d[%s]: range [%lx - %lx] not in memory area: [%lx - %lx]\n",
74 current->pid, current->comm,
75 addr, addr + size,
76 memory_start, memory_end);
77 return 0;
78 }
79
80 /*
81 * For nommu Linux we can check this by looking at the allowed
82 * memory map for the process.
83 *
84 * TODO: Since the kernel passes addresses in it's own space as though
85 * they were user address, we can not validate the addresses this way.
86 */
87 #if 0
88 if (!down_read_trylock(&current->mm->mmap_sem)) {
89 return 1;
90 }
91 vma = find_vma(current->mm, addr);
92 if (!vma) {
93 up_read(&current->mm->mmap_sem);
94 printk(KERN_WARNING "pid=%d[%s]: possible invalid acesss on range: [%lx - %lx]\n",
95 current->pid, current->comm, addr, addr + size);
96 return 1;
97 }
98 if ((addr + size) > vma->vm_end) {
99 up_read(&current->mm->mmap_sem);
100 printk(KERN_WARNING "pid=%d[%s]: possible invalid length on range: [%lx - %lx]\n",
101 current->pid, current->comm, addr, addr + size);
102 return 1;
103 }
104 up_read(&current->mm->mmap_sem);
105 #endif
106 return 1;
107 }
108
109 EXPORT_SYMBOL(__access_ok);