1 /* Copyright (c) 2009, 2010 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * Andrew Waterman <waterman@cs.berkeley.edu>
4 * See LICENSE for details.
6 * Functions for working with userspace's address space. */
8 #include <ros/common.h>
11 /* Is this a valid user pointer for read/write? It doesn't care if the address
12 * is paged out or even an unmapped region: simply if it is in part of the
13 * address space that could be RW user. Will also check for len bytes. */
14 static inline bool is_user_rwaddr(void *addr, size_t len);
15 /* Same deal, but read-only */
16 static inline bool is_user_raddr(void *addr, size_t len);
18 /* Can they use the area in the manner of perm? */
19 void *user_mem_check(struct proc *p, const void *DANGEROUS va, size_t len,
20 size_t align, int perm);
21 /* Kills them if they can't use the area in the manner of perm */
22 void *user_mem_assert(struct proc *p, const void *DANGEROUS va, size_t len,
23 size_t align, int perm);
25 /* Copy from proc p into the kernel's dest from src */
26 int memcpy_from_user(struct proc *p, void *dest, const void *DANGEROUS va,
29 /* Copy to proc p into va from the kernel's src */
30 int memcpy_to_user(struct proc *p, void *DANGEROUS va, const void *src,
32 /* Same as above, but sets errno */
33 int memcpy_from_user_errno(struct proc *p, void *dst, const void *src, int len);
34 int memcpy_to_user_errno(struct proc *p, void *dst, const void *src, int len);
36 /* Creates a buffer (kmalloc) and safely copies into it from va. Can return an
37 * error code. Check its response with IS_ERR(). Must be paired with
38 * user_memdup_free() if this succeeded. */
39 void *user_memdup(struct proc *p, const void *va, int len);
40 /* Same as above, but sets errno */
41 void *user_memdup_errno(struct proc *p, const void *va, int len);
42 void user_memdup_free(struct proc *p, void *va);
43 /* Same as memdup, but just does strings. still needs memdup_freed */
44 char *user_strdup(struct proc *p, const char *u_string, size_t strlen);
45 char *user_strdup_errno(struct proc *p, const char *u_string, size_t strlen);
46 void *kmalloc_errno(int len);
47 bool uva_is_kva(struct proc *p, void *uva, void *kva);
48 uintptr_t uva2kva(struct proc *p, void *uva);
50 /* UWLIM is defined as virtual address below which a process can write */
51 static inline bool is_user_rwaddr(void *addr, size_t len)
53 if (((uintptr_t)addr < UWLIM) && ((uintptr_t)addr + len <= UWLIM))
59 /* ULIM is defined as virtual address below which a process can read */
60 static inline bool is_user_raddr(void *addr, size_t len)
62 if (((uintptr_t)addr < ULIM) && ((uintptr_t)addr + len <= ULIM))