2 * arch/ubicom32/include/asm/uaccess.c
3 * User space memory access functions for Ubicom32 architecture.
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
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.
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.
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/>.
23 * Ubicom32 implementation derived from (with many thanks):
29 #include <linux/sched.h>
31 #include <linux/string.h>
32 #include <linux/module.h>
34 #include <asm/segment.h>
35 #include <asm/uaccess.h>
37 extern int _stext, _etext, _sdata, _edata, _sbss, _ebss, _end;
41 * Check that the address is in the current processes.
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.
47 int __access_ok(unsigned long addr, unsigned long size)
49 // struct vm_area_struct *vma;
52 * Don't do anything if we are not a running system yet.
54 if (system_state != SYSTEM_RUNNING) {
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.
64 if ((!current) || (!current->mm)) {
69 * We perform some basic checks on the address to ensure that it
70 * is at least within the range of DRAM.
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,
76 memory_start, memory_end);
81 * For nommu Linux we can check this by looking at the allowed
82 * memory map for the process.
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.
88 if (!down_read_trylock(¤t->mm->mmap_sem)) {
91 vma = find_vma(current->mm, addr);
93 up_read(¤t->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);
98 if ((addr + size) > vma->vm_end) {
99 up_read(¤t->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);
104 up_read(¤t->mm->mmap_sem);
109 EXPORT_SYMBOL(__access_ok);