From 655ee2825121e149a9976e562946892efb20aea1 Mon Sep 17 00:00:00 2001 From: hunt Date: Thu, 7 Apr 2005 21:48:47 +0000 Subject: *** empty log message *** --- runtime/docs/html/copy_8c-source.html | 332 ++++++++++++++++++---------------- 1 file changed, 178 insertions(+), 154 deletions(-) (limited to 'runtime/docs/html/copy_8c-source.html') diff --git a/runtime/docs/html/copy_8c-source.html b/runtime/docs/html/copy_8c-source.html index 1d4f8652..273aa45c 100644 --- a/runtime/docs/html/copy_8c-source.html +++ b/runtime/docs/html/copy_8c-source.html @@ -4,159 +4,183 @@ -
Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages
-

copy.c

Go to the documentation of this file.
00001 #ifndef _COPY_C_
-00002 #define _COPY_C_
+
+

copy.c

Go to the documentation of this file.
00001 #ifndef _COPY_C_ /* -*- linux-c -*- */
+00002 #define _COPY_C_
 00003 
-00004 /* -*- linux-c -*- */
-00005 /** @file copy.c
-00006  * @brief Functions to copy from user space.
-00007  */
-00008 
-00009 /** @addtogroup copy Functions to copy from user space.
-00010  * Functions to copy from user space.
-00011  * None of these functions will sleep (for example to allow pages
-00012  * to be swapped in). It is possible (although rare) that the data
-00013  * in user space will not present and these functions will return an error.
-00014  * @{
-00015  */
-00016 
-00017 long _stp_strncpy_from_user(char *dst, const char __user *src, long count);
-00018 //static long __stp_strncpy_from_user(char *dst, const char __user *src, long count);
-00019 
-00020 #if defined (__i386__)
-00021 #define __stp_strncpy_from_user(dst,src,count,res)                         \
-00022 do {                                                                       \
-00023         int __d0, __d1, __d2;                                              \
-00024         __asm__ __volatile__(                                              \
-00025                 "       testl %1,%1\n"                                     \
-00026                 "       jz 2f\n"                                           \
-00027                 "0:     lodsb\n"                                           \
-00028                 "       stosb\n"                                           \
-00029                 "       testb %%al,%%al\n"                                 \
-00030                 "       jz 1f\n"                                           \
-00031                 "       decl %1\n"                                         \
-00032                 "       jnz 0b\n"                                          \
-00033                 "1:     subl %1,%0\n"                                      \
-00034                 "2:\n"                                                     \
-00035                 ".section .fixup,\"ax\"\n"                                 \
-00036                 "3:     movl %5,%0\n"                                      \
-00037                 "       jmp 2b\n"                                          \
-00038                 ".previous\n"                                              \
-00039                 ".section __ex_table,\"a\"\n"                              \
-00040                 "       .align 4\n"                                        \
-00041                 "       .long 0b,3b\n"                                     \
-00042                 ".previous"                                                \
-00043                 : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),      \
-00044                   "=&D" (__d2)                                             \
-00045                 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
-00046                 : "memory");                                               \
-00047 } while (0)
-00048 #elif defined (__x86_64__)
-00049 #define __stp_strncpy_from_user(dst,src,count,res)                         \
-00050 do {                                                                       \
-00051         long __d0, __d1, __d2;                                             \
-00052         __asm__ __volatile__(                                              \
-00053                 "       testq %1,%1\n"                                     \
-00054                 "       jz 2f\n"                                           \
-00055                 "0:     lodsb\n"                                           \
-00056                 "       stosb\n"                                           \
-00057                 "       testb %%al,%%al\n"                                 \
-00058                 "       jz 1f\n"                                           \
-00059                 "       decq %1\n"                                         \
-00060                 "       jnz 0b\n"                                          \
-00061                 "1:     subq %1,%0\n"                                      \
-00062                 "2:\n"                                                     \
-00063                 ".section .fixup,\"ax\"\n"                                 \
-00064                 "3:     movq %5,%0\n"                                      \
-00065                 "       jmp 2b\n"                                          \
-00066                 ".previous\n"                                              \
-00067                 ".section __ex_table,\"a\"\n"                              \
-00068                 "       .align 8\n"                                        \
-00069                 "       .quad 0b,3b\n"                                     \
-00070                 ".previous"                                                \
-00071                 : "=r"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),      \
-00072                   "=&D" (__d2)                                             \
-00073                 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
-00074                 : "memory");                                               \
-00075 } while (0)
-00076 #endif
-00077 
-00078 /** Copy a NULL-terminated string from userspace.
-00079  * On success, returns the length of the string (not including the trailing
-00080  * NULL).
-00081  *
-00082  * If access to userspace fails, returns -EFAULT (some data may have been
-00083  * copied).
-00084  * @param dst Destination address, in kernel space.  This buffer must be at
-00085  *         least <i>count</i> bytes long.
-00086  * @param src Source address, in user space.
-00087  * @param count Maximum number of bytes to copy, including the trailing NULL.
-00088  * 
-00089  * If <i>count</i> is smaller than the length of the string, copies 
-00090  * <i>count</i> bytes and returns <i>count</i>.
-00091  */
-00092 
-00093 long
-00094 _stp_strncpy_from_user(char *dst, const char __user *src, long count)
-00095 {
-00096         long res;
-00097         __stp_strncpy_from_user(dst, src, count, res);
-00098         return res;
-00099 }
-00100 
-00101 /** Copy a block of data from user space.
-00102  *
-00103  * If some data could not be copied, this function will pad the copied
-00104  * data to the requested size using zero bytes.
-00105 
-00106  * @param dst Destination address, in kernel space.
-00107  * @param src Source address, in user space.
-00108  * @param count Number of bytes to copy.
-00109  * @return number of bytes that could not be copied. On success, 
-00110  * this will be zero.
-00111  *
-00112  */
-00113 
-00114 unsigned long inline
-00115 _stp_copy_from_user (char *dst, const char __user *src, unsigned long count)
-00116 {
-00117         return __copy_from_user_inatomic(dst, src, count);
-00118 }
-00119 
-00120 /** Copy an argv from user space to a List.
-00121  *
-00122  * @param list A list.
-00123  * @param argv Source argv, in user space.
-00124  * @return number of elements in <i>list</i>
-00125  *
-00126  * @b Example:
-00127  * @include argv.c
-00128  */
-00129 
-00130 int _stp_copy_argv_from_user (MAP list, char __user *__user *argv)
-00131 {
-00132         char str[128];
-00133         char __user *vstr;
-00134         int len;
-00135 
-00136         if (argv)
-00137                 argv++;
-00138 
-00139         while (argv != NULL) {
-00140                 if (get_user (vstr, argv))
-00141                         break;
-00142                 
-00143                 if (vstr == NULL)
-00144                         break;
-00145                 
-00146                 len = _stp_strncpy_from_user(str, vstr, 128);
-00147                 str[len] = 0;
-00148                 _stp_list_add_str (list, str);
-00149                 argv++;
-00150         }
-00151         return list->num;
-00152 }
-00153 /** @} */
-00154 #endif /* _COPY_C_ */
+00004 #include "string.c"
+00005 
+00006 /** @file copy.c
+00007  * @brief Functions to copy from user space.
+00008  */
+00009 
+00010 /** @addtogroup copy Functions to copy from user space.
+00011  * Functions to copy from user space.
+00012  * None of these functions will sleep (for example to allow pages
+00013  * to be swapped in). It is possible (although rare) that the data
+00014  * in user space will not present and these functions will return an error.
+00015  * @{
+00016  */
+00017 
+00018 long _stp_strncpy_from_user(char *dst, const char __user *src, long count);
+00019 //static long __stp_strncpy_from_user(char *dst, const char __user *src, long count);
+00020 
+00021 #if defined (__i386__)
+00022 #define __stp_strncpy_from_user(dst,src,count,res)                         \
+00023 do {                                                                       \
+00024         int __d0, __d1, __d2;                                              \
+00025         __asm__ __volatile__(                                              \
+00026                 "       testl %1,%1\n"                                     \
+00027                 "       jz 2f\n"                                           \
+00028                 "0:     lodsb\n"                                           \
+00029                 "       stosb\n"                                           \
+00030                 "       testb %%al,%%al\n"                                 \
+00031                 "       jz 1f\n"                                           \
+00032                 "       decl %1\n"                                         \
+00033                 "       jnz 0b\n"                                          \
+00034                 "1:     subl %1,%0\n"                                      \
+00035                 "2:\n"                                                     \
+00036                 ".section .fixup,\"ax\"\n"                                 \
+00037                 "3:     movl %5,%0\n"                                      \
+00038                 "       jmp 2b\n"                                          \
+00039                 ".previous\n"                                              \
+00040                 ".section __ex_table,\"a\"\n"                              \
+00041                 "       .align 4\n"                                        \
+00042                 "       .long 0b,3b\n"                                     \
+00043                 ".previous"                                                \
+00044                 : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),      \
+00045                   "=&D" (__d2)                                             \
+00046                 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
+00047                 : "memory");                                               \
+00048 } while (0)
+00049 #elif defined (__x86_64__)
+00050 #define __stp_strncpy_from_user(dst,src,count,res)                         \
+00051 do {                                                                       \
+00052         long __d0, __d1, __d2;                                             \
+00053         __asm__ __volatile__(                                              \
+00054                 "       testq %1,%1\n"                                     \
+00055                 "       jz 2f\n"                                           \
+00056                 "0:     lodsb\n"                                           \
+00057                 "       stosb\n"                                           \
+00058                 "       testb %%al,%%al\n"                                 \
+00059                 "       jz 1f\n"                                           \
+00060                 "       decq %1\n"                                         \
+00061                 "       jnz 0b\n"                                          \
+00062                 "1:     subq %1,%0\n"                                      \
+00063                 "2:\n"                                                     \
+00064                 ".section .fixup,\"ax\"\n"                                 \
+00065                 "3:     movq %5,%0\n"                                      \
+00066                 "       jmp 2b\n"                                          \
+00067                 ".previous\n"                                              \
+00068                 ".section __ex_table,\"a\"\n"                              \
+00069                 "       .align 8\n"                                        \
+00070                 "       .quad 0b,3b\n"                                     \
+00071                 ".previous"                                                \
+00072                 : "=r"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),      \
+00073                   "=&D" (__d2)                                             \
+00074                 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
+00075                 : "memory");                                               \
+00076 } while (0)
+00077 #endif
+00078 
+00079 /** Copy a NULL-terminated string from userspace.
+00080  * On success, returns the length of the string (not including the trailing
+00081  * NULL).
+00082  *
+00083  * If access to userspace fails, returns -EFAULT (some data may have been
+00084  * copied).
+00085  * @param dst Destination address, in kernel space.  This buffer must be at
+00086  *         least <i>count</i> bytes long.
+00087  * @param src Source address, in user space.
+00088  * @param count Maximum number of bytes to copy, including the trailing NULL.
+00089  * 
+00090  * If <i>count</i> is smaller than the length of the string, copies 
+00091  * <i>count</i> bytes and returns <i>count</i>.
+00092  * @deprecated I can't think of why you wouldn't use _stp_string_from_user() instead.
+00093  */
+00094 
+00095 long
+00096 _stp_strncpy_from_user(char *dst, const char __user *src, long count)
+00097 {
+00098         long res;
+00099         __stp_strncpy_from_user(dst, src, count, res);
+00100         return res;
+00101 }
+00102 
+00103 /** Copy a String from userspace.
+00104  * Copies a string of up to \e count bytes from userspace into a String. 
+00105  * If access to userspace fails, returns -EFAULT (some data may have been
+00106  * copied).
+00107  * @param str Destination String.
+00108  * @param src Source address, in user space.
+00109  * @param count Maximum number of bytes to copy, including the trailing NULL.
+00110  * 
+00111  */
+00112 
+00113 void _stp_string_from_user (String str,  const char __user *src, long count)
+00114 {
+00115         long res;
+00116         if (count > STP_STRING_SIZE - str->len - 1)
+00117                 count = STP_STRING_SIZE - str->len - 1;
+00118         __stp_strncpy_from_user(str->buf + str->len, src, count, res);
+00119         if (res > 0) {
+00120                 str->len += res;
+00121                 str->buf[str->len] = '\0';
+00122         }
+00123 }
+00124 
+00125 /** Copy a block of data from user space.
+00126  *
+00127  * If some data could not be copied, this function will pad the copied
+00128  * data to the requested size using zero bytes.
+00129 
+00130  * @param dst Destination address, in kernel space.
+00131  * @param src Source address, in user space.
+00132  * @param count Number of bytes to copy.
+00133  * @return number of bytes that could not be copied. On success, 
+00134  * this will be zero.
+00135  *
+00136  */
+00137 
+00138 unsigned long
+00139 _stp_copy_from_user (char *dst, const char __user *src, unsigned long count)
+00140 {
+00141         return __copy_from_user_inatomic(dst, src, count);
+00142 }
+00143 
+00144 /** Copy an argv from user space to a List.
+00145  *
+00146  * @param list A list.
+00147  * @param argv Source argv, in user space.
+00148  * @return number of elements in <i>list</i>
+00149  *
+00150  * @b Example:
+00151  * @include argv.c
+00152  */
+00153 
+00154 int _stp_copy_argv_from_user (MAP list, char __user *__user *argv)
+00155 {
+00156         char str[128];
+00157         char __user *vstr;
+00158         int len;
+00159 
+00160         if (argv)
+00161                 argv++;
+00162 
+00163         while (argv != NULL) {
+00164                 if (get_user (vstr, argv))
+00165                         break;
+00166                 
+00167                 if (vstr == NULL)
+00168                         break;
+00169                 
+00170                 len = _stp_strncpy_from_user(str, vstr, 128);
+00171                 str[len] = 0;
+00172                 _stp_list_add_str (list, str);
+00173                 argv++;
+00174         }
+00175         return list->num;
+00176 }
+00177 /** @} */
+00178 #endif /* _COPY_C_ */
 
-- cgit