<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><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><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"> <code class="function">copy_[to/from]_user()</code> / <code class="function">get_user()</code> / <code class="function">put_user()</code> <code class="filename">include/asm/uaccess.h</code> </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 id="routines-copy"></a> <code class="function">copy_[to/from]_user()</code> / <code class="function">get_user()</code> / <code class="function">put_user()</code> <code class="filename">include/asm/uaccess.h</code> </h2></div></div></div><p> <span class="emphasis"><em>[SLEEPS]</em></span> </p><p> <code class="function">put_user()</code> and <code class="function">get_user()</code> are used to get and put single values (such as an int, char, or long) from and to userspace. A pointer into userspace should never be simply dereferenced: data should be copied using these routines. Both return <code class="constant">-EFAULT</code> or 0. </p><p> <code class="function">copy_to_user()</code> and <code class="function">copy_from_user()</code> are more general: they copy an arbitrary amount of data to and from userspace. </p><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3><p> Unlike <code class="function">put_user()</code> and <code class="function">get_user()</code>, they return the amount of uncopied data (ie. <span class="returnvalue">0</span> still means success). </p></div><p> [Yes, this moronic interface makes me cringe. The flamewar comes up every year or so. --RR.] </p><p> The functions may sleep implicitly. This should never be called outside user context (it makes no sense), with interrupts disabled, or a spinlock held. </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> <code class="filename">include/linux/slab.h</code></td></tr></table></div></body></html>