`copy_[to/from]_user()` / `get_user()` / `put_user()` `include/asm/uaccess.h`
Prev | Chapter 6. Common Routines | Next

## `copy_[to/from]_user()` / `get_user()` / `put_user()` `include/asm/uaccess.h`

[SLEEPS]

`put_user()` and `get_user()` 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 `-EFAULT` or 0.

`copy_to_user()` and `copy_from_user()` are more general: they copy an arbitrary amount of data to and from userspace.

### Caution

Unlike `put_user()` and `get_user()`, they return the amount of uncopied data (ie. 0 still means success).

[Yes, this moronic interface makes me cringe. The flamewar comes up every year or so. --RR.]

The functions may sleep implicitly. This should never be called outside user context (it makes no sense), with interrupts disabled, or a spinlock held.

Prev | Up | Next
Chapter 6. Common Routines | Home | `kmalloc()`/`kfree()` `include/linux/slab.h`