Blame view
arch/frv/kernel/uaccess.c
2.12 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 10 11 12 |
/* uaccess.c: userspace access functions * * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/mm.h> |
402344012
|
13 |
#include <linux/module.h> |
1da177e4c
|
14 15 16 17 18 19 |
#include <asm/uaccess.h> /*****************************************************************************/ /* * copy a null terminated string from userspace */ |
a8a77573c
|
20 |
long strncpy_from_user(char *dst, const char __user *src, long count) |
1da177e4c
|
21 22 23 24 |
{ unsigned long max; char *p, ch; long err = -EFAULT; |
db5c444ee
|
25 |
BUG_ON(count < 0); |
1da177e4c
|
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
p = dst; #ifndef CONFIG_MMU if ((unsigned long) src < memory_start) goto error; #endif if ((unsigned long) src >= get_addr_limit()) goto error; max = get_addr_limit() - (unsigned long) src; if ((unsigned long) count > max) { memset(dst + max, 0, count - max); count = max; } err = 0; for (; count > 0; count--, p++, src++) { __get_user_asm(err, ch, src, "ub", "=r"); if (err < 0) goto error; if (!ch) break; *p = ch; } err = p - dst; /* return length excluding NUL */ error: if (count > 0) memset(p, 0, count); /* clear remainder of buffer [security] */ return err; |
402344012
|
60 |
|
1da177e4c
|
61 |
} /* end strncpy_from_user() */ |
402344012
|
62 |
EXPORT_SYMBOL(strncpy_from_user); |
1da177e4c
|
63 64 65 66 67 68 |
/*****************************************************************************/ /* * Return the size of a string (including the ending 0) * * Return 0 on exception, a value greater than N if too long */ |
a8a77573c
|
69 |
long strnlen_user(const char __user *src, long count) |
1da177e4c
|
70 |
{ |
a8a77573c
|
71 |
const char __user *p; |
1da177e4c
|
72 73 |
long err = 0; char ch; |
db5c444ee
|
74 |
BUG_ON(count < 0); |
1da177e4c
|
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
#ifndef CONFIG_MMU if ((unsigned long) src < memory_start) return 0; #endif if ((unsigned long) src >= get_addr_limit()) return 0; for (p = src; count > 0; count--, p++) { __get_user_asm(err, ch, p, "ub", "=r"); if (err < 0) return 0; if (!ch) break; } return p - src + 1; /* return length including NUL */ |
402344012
|
93 |
|
1da177e4c
|
94 |
} /* end strnlen_user() */ |
402344012
|
95 96 |
EXPORT_SYMBOL(strnlen_user); |