| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: uaccess.h,v 1.5 2021/12/19 00:55:01 riastradh Exp $ */ | | 1 | /* $NetBSD: uaccess.h,v 1.6 2021/12/19 01:39:41 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -62,26 +62,37 @@ copy_to_user(void *user_addr, const void | | | @@ -62,26 +62,37 @@ copy_to_user(void *user_addr, const void |
62 | /* XXX errno NetBSD->Linux */ | | 62 | /* XXX errno NetBSD->Linux */ |
63 | return -copyout(kernel_addr, user_addr, len); | | 63 | return -copyout(kernel_addr, user_addr, len); |
64 | } | | 64 | } |
65 | | | 65 | |
66 | #define get_user(KERNEL_LVAL, USER_PTR) \ | | 66 | #define get_user(KERNEL_LVAL, USER_PTR) \ |
67 | copy_from_user(&(KERNEL_LVAL), (USER_PTR), sizeof(*(USER_PTR)) + \ | | 67 | copy_from_user(&(KERNEL_LVAL), (USER_PTR), sizeof(*(USER_PTR)) + \ |
68 | 0*sizeof(&(KERNEL_LVAL) - (USER_PTR))) | | 68 | 0*sizeof(&(KERNEL_LVAL) - (USER_PTR))) |
69 | | | 69 | |
70 | #define put_user(KERNEL_RVAL, USER_PTR) ({ \ | | 70 | #define put_user(KERNEL_RVAL, USER_PTR) ({ \ |
71 | const typeof(*(USER_PTR)) __put_user_tmp = (KERNEL_RVAL); \ | | 71 | const typeof(*(USER_PTR)) __put_user_tmp = (KERNEL_RVAL); \ |
72 | copy_to_user((USER_PTR), &__put_user_tmp, sizeof(__put_user_tmp)); \ | | 72 | copy_to_user((USER_PTR), &__put_user_tmp, sizeof(__put_user_tmp)); \ |
73 | }) | | 73 | }) |
74 | | | 74 | |
| | | 75 | #define __get_user get_user |
| | | 76 | #define __put_user put_user |
| | | 77 | |
| | | 78 | #define user_access_begin() __nothing |
| | | 79 | #define user_access_end() __nothing |
| | | 80 | |
| | | 81 | #define unsafe_put_user(KERNEL_RVAL, USER_PTR, LABEL) do { \ |
| | | 82 | if (__put_user(KERNEL_RVAL, USER_PTR)) \ |
| | | 83 | goto LABEL; \ |
| | | 84 | } while (0) |
| | | 85 | |
75 | static inline size_t | | 86 | static inline size_t |
76 | clear_user(void __user *user_ptr, size_t size) | | 87 | clear_user(void __user *user_ptr, size_t size) |
77 | { | | 88 | { |
78 | char __user *p = user_ptr; | | 89 | char __user *p = user_ptr; |
79 | size_t n = size; | | 90 | size_t n = size; |
80 | | | 91 | |
81 | /* | | 92 | /* |
82 | * This loop which sets up a fault handler on every iteration | | 93 | * This loop which sets up a fault handler on every iteration |
83 | * is not going to win any speed records, but it'll do to copy | | 94 | * is not going to win any speed records, but it'll do to copy |
84 | * out an int. | | 95 | * out an int. |
85 | */ | | 96 | */ |
86 | while (n --> 0) { | | 97 | while (n --> 0) { |
87 | if (subyte(p, 0) != 0) | | 98 | if (subyte(p, 0) != 0) |