x86: remove misconceptions about "sti" and halting
[akaros.git] / kern / arch / riscv / uaccess.h
1 /* Copyright (c) 2015 Google Inc
2  * Davide Libenzi <dlibenzi@google.com>
3  * See LICENSE for details.
4  *
5  * Part of this code coming from a Linux kernel file:
6  *
7  * linux/arch/x86/include/asm/uaccess.h
8  *
9  * Which, even though missing specific copyright, it is supposed to be
10  * ruled by the overall Linux copyright.
11  */
12
13 #pragma once
14
15 #include <ros/errno.h>
16 #include <compiler.h>
17 #include <stdint.h>
18 #include <umem.h>
19
20 #define ASM_STAC
21 #define ASM_CLAC
22 #define __m(x) *(x)
23
24 struct extable_ip_fixup {
25         uint64_t insn;
26         uint64_t fixup;
27 };
28
29 #define _ASM_EXTABLE_INIT()                                                                             \
30         asm volatile(                                                                                           \
31         " .pushsection \"__ex_table\",\"a\"\n"                                          \
32         " .balign 16\n"                                                                                         \
33         " .popsection\n"                                                                                        \
34         : :)
35
36 #define _ASM_EXTABLE(from, to)                                                                  \
37         " .pushsection \"__ex_table\",\"a\"\n"                                          \
38         " .balign 16\n"                                                                                         \
39         " .quad (" #from ") - .\n"                                                                      \
40         " .quad (" #to ") - .\n"                                                                        \
41         " .popsection\n"
42
43 static inline int __put_user(void *dst, const void *src, unsigned int count)
44 {
45 #warning "The __put_user() API is a stub and should be re-implemented"
46
47         memcpy(dst, src, count);
48
49         return 0;
50 }
51
52 static inline int copy_to_user(void *dst, const void *src, unsigned int count)
53 {
54 #warning "The copy_to_user() API is a stub and should be re-implemented"
55
56         int err = 0;
57
58         if (unlikely(!is_user_rwaddr(dst, count))) {
59                 err = -EFAULT;
60         } else {
61                 err = __put_user(dst, src, count);
62         }
63
64         return err;
65 }
66
67 static inline int __get_user(void *dst, const void *src, unsigned int count)
68 {
69 #warning "The __get_user() API is a stub and should be re-implemented"
70
71         memcpy(dst, src, count);
72
73         return 0;
74 }
75
76 static inline int copy_from_user(void *dst, const void *src,
77                                                                  unsigned int count)
78 {
79 #warning "The copy_from_user() API is a stub and should be re-implemented"
80
81         int err = 0;
82
83         if (unlikely(!is_user_raddr((void *) src, count))) {
84                 err = -EFAULT;
85         } else {
86                 err = __get_user(dst, src, count);
87         }
88
89         return err;
90 }
91
92 static inline uintptr_t ex_insn_addr(const struct extable_ip_fixup *x)
93 {
94         return (uintptr_t) &x->insn + x->insn;
95 }
96
97 static inline uintptr_t ex_fixup_addr(const struct extable_ip_fixup *x)
98 {
99         return (uintptr_t) &x->fixup + x->fixup;
100 }