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