AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
uaccess.h File Reference
#include <core/system.h>
#include <core/arch.h>
#include <aquila/errno.h>

Go to the source code of this file.

Macros

#define UACCESS_LIMIT   ((uintptr_t) USER_STACK)

Functions

static int uaccess_check (const void *ptr, size_t len)
 Checks that [ptr, ptr + len) is in user space.
size_t arch_copy_user (void *dst, const void *src, size_t n)
long arch_copy_user_str (char *dst, const char *src, size_t max)
static int copyin (void *kdst, const void *usrc, size_t n)
 Copies n bytes from user memory at usrc to kdst.
static int copyout (void *udst, const void *ksrc, size_t n)
 Copies n bytes from ksrc to user memory at udst.
static size_t copyin_upto (void *kdst, const void *usrc, size_t n)
 Copies as copyin() does, but returns how many bytes were copied before a fault (0 for a range that isn't in user space): n if they all were.
static size_t copyout_upto (void *udst, const void *ksrc, size_t n)
 Copies as copyout() does, but returns how many bytes were copied before a fault: n if they all were.
static long copyinstr (char *kdst, const char *usrc, size_t max)
 Copies a string from user memory at usrc to kdst (at most max bytes, its NUL included).

Macro Definition Documentation

◆ UACCESS_LIMIT

#define UACCESS_LIMIT   ((uintptr_t) USER_STACK)

Definition at line 20 of file uaccess.h.

Referenced by copyinstr(), and uaccess_check().

Function Documentation

◆ arch_copy_user()

size_t arch_copy_user ( void * dst,
const void * src,
size_t n )

◆ arch_copy_user_str()

long arch_copy_user_str ( char * dst,
const char * src,
size_t max )

References arch_copy_user_str().

Referenced by arch_copy_user_str(), and copyinstr().

◆ copyin()

int copyin ( void * kdst,
const void * usrc,
size_t n )
inlinestatic

Copies n bytes from user memory at usrc to kdst.

Returns 0, or -EFAULT.

Definition at line 48 of file uaccess.h.

References arch_copy_user(), and uaccess_check().

◆ copyin_upto()

size_t copyin_upto ( void * kdst,
const void * usrc,
size_t n )
inlinestatic

Copies as copyin() does, but returns how many bytes were copied before a fault (0 for a range that isn't in user space): n if they all were.

Definition at line 68 of file uaccess.h.

References arch_copy_user(), and uaccess_check().

◆ copyinstr()

long copyinstr ( char * kdst,
const char * usrc,
size_t max )
inlinestatic

Copies a string from user memory at usrc to kdst (at most max bytes, its NUL included).

Returns its length, -EFAULT, or -ENAMETOOLONG if it doesn't fit.

Definition at line 83 of file uaccess.h.

References arch_copy_user_str(), MIN, and UACCESS_LIMIT.

◆ copyout()

int copyout ( void * udst,
const void * ksrc,
size_t n )
inlinestatic

Copies n bytes from ksrc to user memory at udst.

Returns 0, or -EFAULT.

Definition at line 58 of file uaccess.h.

References arch_copy_user(), and uaccess_check().

◆ copyout_upto()

size_t copyout_upto ( void * udst,
const void * ksrc,
size_t n )
inlinestatic

Copies as copyout() does, but returns how many bytes were copied before a fault: n if they all were.

Definition at line 75 of file uaccess.h.

References arch_copy_user(), and uaccess_check().

◆ uaccess_check()

int uaccess_check ( const void * ptr,
size_t len )
inlinestatic

Checks that [ptr, ptr + len) is in user space.

Returns 0 if it is, or -EFAULT. A NULL pointer is always rejected unless len is 0, so callers that accept NULL must test for it first.

Definition at line 27 of file uaccess.h.

References uaccess_check(), and UACCESS_LIMIT.

Referenced by copyin(), copyin_upto(), copyout(), copyout_upto(), sys_getrandom(), sys_mmap(), sys_pipe(), sys_read(), sys_readlinkat(), sys_recv(), sys_send(), sys_sigaction(), sys_thread_create(), sys_write(), and uaccess_check().