|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2005 David Decotigny 001 /* Copyright (C) 2005 David Decotigny 002 002 003 This program is free software; you can redi 003 This program is free software; you can redistribute it and/or 004 modify it under the terms of the GNU Genera 004 modify it under the terms of the GNU General Public License 005 as published by the Free Software Foundatio 005 as published by the Free Software Foundation; either version 2 006 of the License, or (at your option) any lat 006 of the License, or (at your option) any later version. 007 007 008 This program is distributed in the hope tha 008 This program is distributed in the hope that it will be useful, 009 but WITHOUT ANY WARRANTY; without even the 009 but WITHOUT ANY WARRANTY; without even the implied warranty of 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 011 GNU General Public License for more details 011 GNU General Public License for more details. 012 012 013 You should have received a copy of the GNU 013 You should have received a copy of the GNU General Public License 014 along with this program; if not, write to t 014 along with this program; if not, write to the Free Software 015 Foundation, Inc., 59 Temple Place - Suite 3 015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 016 USA. 016 USA. 017 */ 017 */ 018 #ifndef _SOS_UACCESS_H_ 018 #ifndef _SOS_UACCESS_H_ 019 #define _SOS_UACCESS_H_ 019 #define _SOS_UACCESS_H_ 020 020 021 021 022 /** 022 /** 023 * @file uaccess.h 023 * @file uaccess.h 024 * 024 * 025 * Routines to access user-space data from ins 025 * Routines to access user-space data from inside the kernel space. 026 */ 026 */ 027 027 028 #include <sos/types.h> 028 #include <sos/types.h> 029 #include <sos/errno.h> 029 #include <sos/errno.h> 030 030 031 031 032 /** 032 /** 033 * Retrieve a bunch of data from the user spac 033 * Retrieve a bunch of data from the user space of the 034 * current_thread->process 034 * current_thread->process 035 * 035 * 036 * @return <0 on error ! Return the number of 036 * @return <0 on error ! Return the number of bytes successfully copied 037 * otherwise. 037 * otherwise. 038 */ 038 */ 039 sos_ret_t sos_memcpy_from_user(sos_vaddr_t ker 039 sos_ret_t sos_memcpy_from_user(sos_vaddr_t kernel_to, 040 sos_uaddr_t use 040 sos_uaddr_t user_from, 041 sos_size_t size 041 sos_size_t size); 042 042 043 043 044 /** 044 /** 045 * Retrieve a bunch of data from the user spac 045 * Retrieve a bunch of data from the user space of the 046 * current_thread->process and copy it in a ne 046 * current_thread->process and copy it in a newly allocated kernel 047 * area 047 * area 048 * 048 * 049 * @return NULL on error (including unresolved 049 * @return NULL on error (including unresolved page fault during 050 * transfer) 050 * transfer) 051 */ 051 */ 052 sos_ret_t sos_memdup_from_user(sos_vaddr_t * k 052 sos_ret_t sos_memdup_from_user(sos_vaddr_t * kernel_to, sos_uaddr_t from_user, 053 sos_size_t leng 053 sos_size_t length, 054 sos_ui32_t kmal 054 sos_ui32_t kmalloc_flags); 055 055 056 056 057 /** 057 /** 058 * Transfer a bunch of data to the user space 058 * Transfer a bunch of data to the user space of the 059 * current_thread->process 059 * current_thread->process 060 * 060 * 061 * @return <0 n error ! Return the number of b 061 * @return <0 n error ! Return the number of bytes successfully copied 062 * otherwise. 062 * otherwise. 063 */ 063 */ 064 sos_ret_t sos_memcpy_to_user(sos_uaddr_t user_ 064 sos_ret_t sos_memcpy_to_user(sos_uaddr_t user_to, 065 sos_vaddr_t kerne 065 sos_vaddr_t kernel_from, 066 sos_size_t size); 066 sos_size_t size); 067 067 068 068 069 /** 069 /** 070 * @return the length of the given user space 070 * @return the length of the given user space string user_str 071 * (excluding the trailing \0), up to max_len 071 * (excluding the trailing \0), up to max_len bytes. <0 on error 072 * (unresolved page fault, etc.) 072 * (unresolved page fault, etc.) 073 */ 073 */ 074 sos_ret_t sos_strnlen_from_user(sos_uaddr_t us 074 sos_ret_t sos_strnlen_from_user(sos_uaddr_t user_str, sos_size_t max_len); 075 075 076 076 077 /** 077 /** 078 * Copy the given user space string to kernel 078 * Copy the given user space string to kernel space, up to max_len 079 * bytes (including trailing \0) 079 * bytes (including trailing \0) 080 * 080 * 081 * @return SOS_OK on success, <0 otherwise (un 081 * @return SOS_OK on success, <0 otherwise (unresolved page fault, etc.) 082 */ 082 */ 083 sos_ret_t sos_strzcpy_from_user(char *kernel_t 083 sos_ret_t sos_strzcpy_from_user(char *kernel_to, sos_uaddr_t user_from, 084 sos_size_t max 084 sos_size_t max_len); 085 085 086 086 087 /** 087 /** 088 * Copy the given kernel string to user space, 088 * Copy the given kernel string to user space, up to max_len bytes 089 * (including trailing \0) 089 * (including trailing \0) 090 * 090 * 091 * @return SOS_OK on success, <0 otherwise (un 091 * @return SOS_OK on success, <0 otherwise (unresolved page fault, etc.) 092 */ 092 */ 093 sos_ret_t sos_strzcpy_to_user(sos_uaddr_t user 093 sos_ret_t sos_strzcpy_to_user(sos_uaddr_t user_to, const char *kernel_from, 094 sos_size_t max_l 094 sos_size_t max_len); 095 095 096 096 097 /** 097 /** 098 * Copy the given user space string into a new 098 * Copy the given user space string into a new allocated kernel space 099 * area of the correct size, up to max_len byt 099 * area of the correct size, up to max_len bytes (including trailing 100 * \0) 100 * \0) 101 * 101 * 102 * @return SOS_OK on success + *kernel_to is s 102 * @return SOS_OK on success + *kernel_to is set to the freshly 103 * allocated kernel string, <0 otherwise (unre 103 * allocated kernel string, <0 otherwise (unresolved page fault, etc.) 104 */ 104 */ 105 sos_ret_t sos_strndup_from_user(char ** kernel 105 sos_ret_t sos_strndup_from_user(char ** kernel_to, sos_uaddr_t from_user, 106 sos_size_t max 106 sos_size_t max_len, 107 sos_ui32_t kma 107 sos_ui32_t kmalloc_flags); 108 108 109 << 110 /* << 111 * Special functions to access both kernel/use << 112 */ << 113 /** Generic (Kernel or User) virtual address. << 114 force the compiler to signal when we call << 115 with a usual address... */ << 116 typedef struct sos_genaddr { sos_bool_t is_use << 117 sos_ui32_t addr; << 118 #define SOS_GENADDR_DECL(name,_is_user,_addr) << 119 sos_genaddr_t name = (struct sos_genaddr) { << 120 << 121 sos_ret_t sos_memcpy_generic_to(sos_genaddr_t << 122 sos_vaddr_t ke << 123 sos_size_t siz << 124 << 125 sos_ret_t sos_memcpy_generic_from(sos_vaddr_t << 126 sos_genaddr_ << 127 sos_size_t s << 128 << 129 #endif /* _SOS_UACCESS_H_ */ 109 #endif /* _SOS_UACCESS_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |