From: monstr@monstr.eu
To: monstr@monstr.eu
Cc: linux-kernel@vger.kernel.org, stephen.neuendorffer@xilinx.com,
john.williams@petalogix.com, microblaze-uclinux@itee.uq.edu.au
Subject: [PATCH 19/52] [microblaze] uaccess files
Date: Thu, 24 Jan 2008 16:02:54 +0100 [thread overview]
Message-ID: <64e6e541db30cc4f1ee5cd85da4bdea6024f75b8.1201107832.git.monstr@monstr.eu> (raw)
In-Reply-To: <eb28582e845efb4f2f26054630895f26fa69866e.1201107832.git.monstr@monstr.eu>
In-Reply-To: <8051f6df628e1ff896ec7d580b613da50f718fb4.1201107832.git.monstr@monstr.eu>
From: Michal Simek <monstr@monstr.eu>
Signed-off-by: Michal Simek <monstr@monstr.eu>
---
arch/microblaze/lib/uaccess.c | 43 +++++++++++++
include/asm-microblaze/uaccess.h | 126 ++++++++++++++++++++++++++++++++++++++
2 files changed, 169 insertions(+), 0 deletions(-)
create mode 100644 arch/microblaze/lib/uaccess.c
create mode 100644 include/asm-microblaze/uaccess.h
diff --git a/arch/microblaze/lib/uaccess.c b/arch/microblaze/lib/uaccess.c
new file mode 100644
index 0000000..be201a0
--- /dev/null
+++ b/arch/microblaze/lib/uaccess.c
@@ -0,0 +1,43 @@
+/*
+ * arch/microblaze/lib/uaccess.c
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ */
+
+#include <linux/string.h>
+#include <asm/uaccess.h>
+
+#include <asm/bug.h>
+
+long strnlen_user(const char *s, long n)
+{
+ return strlen(s) + 1;
+}
+
+#define __do_strncpy_from_user(dst, src, count, res) \
+ do { \
+ char *tmp; \
+ strncpy(dst, src, count); \
+ for (tmp = dst; *tmp && count > 0; tmp++, count--) \
+ ; \
+ res = (tmp - dst); \
+ } while (0)
+
+long __strncpy_from_user(char *dst, const char *src, long count)
+{
+ long res;
+ __do_strncpy_from_user(dst, src, count, res);
+ return res;
+}
+
+long strncpy_from_user(char *dst, const char *src, long count)
+{
+ long res = -EFAULT;
+ if (access_ok(VERIFY_READ, src, 1))
+ __do_strncpy_from_user(dst, src, count, res);
+ return res;
+}
diff --git a/include/asm-microblaze/uaccess.h b/include/asm-microblaze/uaccess.h
new file mode 100644
index 0000000..1ee4c63
--- /dev/null
+++ b/include/asm-microblaze/uaccess.h
@@ -0,0 +1,126 @@
+/*
+ * include/asm-microblaze/uaccess.h
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2006 Atmark Techno, Inc.
+ */
+
+#ifndef _ASM_UACCESS_H
+#define _ASM_UACCESS_H
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <asm/segment.h>
+#include <asm/string.h>
+
+#include <linux/sched.h> /* RLIMIT_FSIZE */
+/* #include <linux/errno.h> */
+
+#define VERIFY_READ 0
+#define VERIFY_WRITE 1
+
+extern int ___range_ok(unsigned long addr, unsigned long size);
+
+#define __range_ok(addr, size) \
+ ___range_ok((unsigned long)(addr), (unsigned long)(size))
+
+#define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0)
+#define __access_ok(add, size) (__range_ok((addr), (size)) == 0)
+
+extern inline int bad_user_access_length(void)
+{
+ return 0;
+}
+
+#define __get_user(var, ptr) \
+ ({ \
+ int __gu_err = 0; \
+ switch (sizeof(*(ptr))) { \
+ case 1: \
+ case 2: \
+ case 4: \
+ (var) = *(ptr); \
+ break; \
+ case 8: \
+ memcpy((void *) &(var), (ptr), 8); \
+ break; \
+ default: \
+ (var) = 0; \
+ __gu_err = __get_user_bad(); \
+ break; \
+ } \
+ __gu_err; \
+ })
+
+#define __get_user_bad() (bad_user_access_length (), (-EFAULT))
+
+#define __put_user(var, ptr) \
+ ({ \
+ int __pu_err = 0; \
+ switch (sizeof(*(ptr))) { \
+ case 1: \
+ case 2: \
+ case 4: \
+ *(ptr) = (var); \
+ break; \
+ case 8: { \
+ typeof(*(ptr)) __pu_val = var; \
+ memcpy(ptr, &__pu_val, sizeof(__pu_val));\
+ } \
+ break; \
+ default: \
+ __pu_err = __put_user_bad(); \
+ break; \
+ } \
+ __pu_err; \
+ })
+
+#define __put_user_bad() (bad_user_access_length (), (-EFAULT))
+
+#define put_user(x, ptr) __put_user(x, ptr)
+#define get_user(x, ptr) __get_user(x, ptr)
+
+#define copy_to_user(to, from, n) (memcpy(to, from, n), 0)
+#define copy_from_user(to, from, n) (memcpy(to, from, n), 0)
+
+#define __copy_to_user(to, from, n) (copy_to_user(to, from, n))
+#define __copy_from_user(to, from, n) (copy_from_user(to, from, n))
+#define __copy_to_user_inatomic(to, from, n) (__copy_to_user(to, from, n))
+#define __copy_from_user_inatomic(to, from, n) (__copy_from_user(to, from, n))
+
+#define __clear_user(addr, n) (memset((void *)addr, 0, n), 0)
+
+/*
+ * The exception table consists of pairs of addresses: the first is the
+ * address of an instruction that is allowed to fault, and the second is
+ * the address at which the program should continue. No registers are
+ * modified, so it is entirely up to the continuation code to figure out
+ * what to do.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path. This means when everything is well,
+ * we don't even have to jump over them. Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+struct exception_table_entry {
+ unsigned long insn, fixup;
+};
+
+static inline unsigned long clear_user(void *addr, unsigned long size)
+{
+ if (access_ok(VERIFY_WRITE, addr, size))
+ size = __clear_user(addr, size);
+ return size;
+}
+
+/* Returns 0 if exception not found and fixup otherwise. */
+extern unsigned long search_exception_table(unsigned long);
+
+extern long strncpy_from_user(char *dst, const char *src, long count);
+extern long strnlen_user(const char *src, long count);
+extern long __strncpy_from_user(char *dst, const char *src, long count);
+
+#endif /* _ASM_UACCESS_H */
--
1.5.4.rc4.14.g6fc74
next prev parent reply other threads:[~2008-01-26 15:59 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-24 15:02 Microblaze init port monstr
2008-01-24 15:05 ` [PATCH 01/52] [microblaze] Kconfig patches monstr
2008-01-24 15:02 ` [PATCH 10/52] [microblaze] Generic dts file for platforms monstr
2008-01-24 15:02 ` [PATCH 11/52] [microblaze] kernel modules support monstr
2008-01-26 16:27 ` Jan Engelhardt
2008-01-24 15:02 ` [PATCH 12/52] [microblaze] lmb support monstr
2008-01-27 12:51 ` Jan Engelhardt
2008-01-24 15:02 ` [PATCH 13/52] [microblaze] PVR support, cpuinfo support monstr
2008-01-24 15:02 ` [PATCH 14/52] [microblaze] defconfig file monstr
2008-01-24 15:02 ` [PATCH 15/52] [microblaze] assembler files head.S, entry.S, monstr
2008-01-24 15:02 ` [PATCH 16/52] [microblaze] supported function for memory - kernel/lib monstr
2008-01-29 21:26 ` Jan Engelhardt
2008-01-24 15:02 ` [PATCH 17/52] [microblaze] checksum support monstr
2008-01-27 11:57 ` Geert Uytterhoeven
2008-01-27 13:41 ` Michal Simek
2008-01-27 15:12 ` Geert Uytterhoeven
2008-01-29 21:30 ` Jan Engelhardt
2008-01-24 15:02 ` [PATCH 18/52] [microblaze] early_printk support monstr
2008-01-24 15:02 ` monstr [this message]
2008-01-24 15:02 ` [PATCH 20/52] [microblaze] heartbeat file monstr
2008-01-24 15:02 ` [PATCH 21/52] [microblaze] setup.c - system setting monstr
2008-01-24 15:02 ` [PATCH 22/52] [microblaze] asm-offsets monstr
2008-01-24 15:02 ` [PATCH 23/52] [microblaze] process and init task function monstr
2008-01-24 15:02 ` [PATCH 24/52] [microblaze] time support monstr
[not found] ` <47BD86F3.9030400@petalogix.com>
[not found] ` <20080221163040.5E9FA6A0056@mail168-sin.bigfish.com>
2008-03-02 19:25 ` [microblaze-uclinux] " Michal Simek
2008-01-24 15:03 ` [PATCH 25/52] [microblaze] ptrace support monstr
2008-01-24 15:03 ` [PATCH 26/52] [microblaze] IPC support monstr
2008-01-24 15:03 ` [PATCH 27/52] [microblaze] traps support monstr
2008-01-24 15:03 ` [PATCH 28/52] [microblaze] support for a.out monstr
2008-01-24 15:03 ` [PATCH 29/52] [microblaze] memory inicialization, MMU, TLB monstr
2008-01-24 15:03 ` [PATCH 30/52] [microblaze] consistent allocation & page.h, monstr
2008-01-24 15:03 ` [PATCH 31/52] [microblaze] pci header files monstr
2008-01-24 15:03 ` [PATCH 32/52] [microblaze] includes SHM*, msgbuf monstr
2008-01-24 15:03 ` [PATCH 33/52] [microblaze] bug headers files monstr
2008-01-24 15:03 ` [PATCH 34/52] [microblaze] definitions of types monstr
2008-01-24 15:03 ` [PATCH 35/52] [microblaze] ioctl support monstr
2008-01-24 15:03 ` [PATCH 36/52] [microblaze] io.h IO operations monstr
2008-01-24 15:03 ` [PATCH 37/52] [microblaze] headers for executables format FLAT, ELF monstr
2008-01-24 15:03 ` [PATCH 38/52] [microblaze] dma support monstr
2008-01-24 15:03 ` [PATCH 39/52] [microblaze] headers for irq monstr
2008-01-24 15:03 ` [PATCH 40/52] [microblaze] atomic.h bitops.h byteorder.h monstr
2008-01-24 15:03 ` [PATCH 41/52] [microblaze] headers pgalloc.h pgtable.h monstr
2008-01-24 15:03 ` [PATCH 42/52] [microblaze] system.h pvr.h processor.h monstr
2008-01-24 15:03 ` [PATCH 43/52] [microblaze] clinkage.h linkage.h sections.h kmap_types.h monstr
2008-01-24 15:03 ` [PATCH 44/52] [microblaze] stats headers monstr
2008-01-24 15:03 ` [PATCH 45/52] [microblaze] termbits.h termios.h monstr
2008-01-24 15:03 ` [PATCH 46/52] [microblaze] sigcontext.h siginfo.h monstr
2008-01-24 15:03 ` [PATCH 47/52] [microblaze] headers simple files monstr
2008-01-24 15:03 ` [PATCH 48/52] [microblaze] headers files entry.h current.h mman.h registers.h sembuf.h monstr
2008-01-24 15:03 ` [PATCH 49/52] [microblaze] device.h param.h topology.h monstr
2008-01-24 15:03 ` [PATCH 50/52] [microblaze] pool.h socket.h monstr
2008-01-24 15:03 ` [PATCH 51/52] [microblaze] fcntl.h sockios.h ucontext.h unistd.h monstr
2008-01-24 15:03 ` [PATCH 52/52] [microblaze] setup.h string.h thread_info.h monstr
2008-01-24 15:03 ` [PATCH 03/52] [microblaze] Cpuinfo handling monstr
2008-01-27 12:55 ` Jan Engelhardt
2008-01-24 15:03 ` [PATCH 04/52] [microblaze] Open firmware files monstr
2008-01-24 15:03 ` [PATCH 05/52] [microblaze] Support for semaphores monstr
2008-01-24 15:03 ` [PATCH 06/52] [microblaze] exception handling monstr
2008-01-24 15:03 ` [PATCH 07/52] [microblaze] Signal support monstr
2008-01-24 15:03 ` [PATCH 08/52] [microblaze] Interrupt handling, timer support, supported function monstr
2008-01-24 15:03 ` [PATCH 09/52] [microblaze] cache support monstr
2008-01-24 15:05 ` [PATCH 02/52] [microblaze] Makefiles for Microblaze cpu monstr
2008-01-26 17:36 ` [PATCH 01/52] [microblaze] Kconfig patches Randy Dunlap
2008-01-27 10:39 ` Michal Simek
2008-01-27 10:41 ` [PATCH 01/52] [microblaze] Kconfig patches v2 Michal Simek
2008-01-27 17:15 ` Randy Dunlap
2008-01-27 11:59 ` Microblaze init port Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=64e6e541db30cc4f1ee5cd85da4bdea6024f75b8.1201107832.git.monstr@monstr.eu \
--to=monstr@monstr.eu \
--cc=john.williams@petalogix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=microblaze-uclinux@itee.uq.edu.au \
--cc=stephen.neuendorffer@xilinx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®