1 /*
2 * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3 * Licensed under the Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 * http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9 * PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 */
12 #ifndef MM_UACCESS_H
13 #define MM_UACCESS_H
14
15 int copy_from_user(void *kbuf, void *ubuf, size_t size);
16 int copy_to_user(void *ubuf, void *kbuf, size_t size);
17
18 /*
19 * For x86_64:
20 * In 64-bit mode, an address is considered to be in canonical form
21 * if address bits 63 through to the most-significant implemented bit
22 * by the microarchitecture are set to either all ones or all zeros.
23 * The kernel and user share the 48-bit address (0~2^48-1).
24 * As usual, we let the kernel use the top half and the user use the
25 * bottom half.
26 * So, the user address is 0 ~ 2^47-1 (USER_SPACE_END).
27 *
28 *
29 * For aarch64:
30 * With 4-level page tables:
31 * TTBR0_EL1 translates 0 ~ 2^48-1 .
32 * TTBR1_EL1 translates (0xFFFF) + 0 ~ 2^48-1.
33 * But, we only use 0 ~ USER_SPACE_END (as x86_64).
34 * With 3-level page tables:
35 * The same as x86_64.
36
37 #if __SIZEOF_POINTER__ == 4
38 #define USER_SPACE_END (0x80000000UL)
39 #else
40 #define USER_SPACE_END (0x800000000000UL)
41 #endif
42
43 */
44
45 #include <common/vars.h>
46
check_user_addr_range(vaddr_t start,size_t len)47 static inline int check_user_addr_range(vaddr_t start, size_t len)
48 {
49 if ((start + len) >= KBASE)
50 return -1;
51 return 0;
52 }
53
54 #endif /* MM_UACCESS_H */