1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>copy_[to/from]_user() / get_user() / put_user() include/asm/uaccess.h</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="common-routines.html" title="Chapter 6. Common Routines"><link rel="prev" href="common-routines.html" title="Chapter 6. Common Routines"><link rel="next" href="routines-kmalloc.html" title="kmalloc()/kfree() include/linux/slab.h"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"> 2 <code class="function">copy_[to/from]_user()</code> 3 / 4 <code class="function">get_user()</code> 5 / 6 <code class="function">put_user()</code> 7 <code class="filename">include/asm/uaccess.h</code> 8 </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="common-routines.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Common Routines</th><td width="20%" align="right"> <a accesskey="n" href="routines-kmalloc.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="routines-copy"></a> 9 <code class="function">copy_[to/from]_user()</code> 10 / 11 <code class="function">get_user()</code> 12 / 13 <code class="function">put_user()</code> 14 <code class="filename">include/asm/uaccess.h</code> 15 </h2></div></div></div><p> 16 <span class="emphasis"><em>[SLEEPS]</em></span> 17 </p><p> 18 <code class="function">put_user()</code> and <code class="function">get_user()</code> 19 are used to get and put single values (such as an int, char, or 20 long) from and to userspace. A pointer into userspace should 21 never be simply dereferenced: data should be copied using these 22 routines. Both return <code class="constant">-EFAULT</code> or 0. 23 </p><p> 24 <code class="function">copy_to_user()</code> and 25 <code class="function">copy_from_user()</code> are more general: they copy 26 an arbitrary amount of data to and from userspace. 27 </p><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3><p> 28 Unlike <code class="function">put_user()</code> and 29 <code class="function">get_user()</code>, they return the amount of 30 uncopied data (ie. <span class="returnvalue">0</span> still means 31 success). 32 </p></div><p> 33 [Yes, this moronic interface makes me cringe. The flamewar comes up every year or so. --RR.] 34 </p><p> 35 The functions may sleep implicitly. This should never be called 36 outside user context (it makes no sense), with interrupts 37 disabled, or a spinlock held. 38 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="common-routines.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="common-routines.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="routines-kmalloc.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 6. Common Routines </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <code class="function">kmalloc()</code>/<code class="function">kfree()</code> 39 <code class="filename">include/linux/slab.h</code></td></tr></table></div></body></html> 40