include/asm-generic/uaccess.h

Source file repositories/reference/linux-study-clean/include/asm-generic/uaccess.h

File Facts

System
Linux kernel
Corpus path
include/asm-generic/uaccess.h
Extension
.h
Size
5608 bytes
Lines
235
Domain
Repository Root And Misc
Bucket
include
Inferred role
Repository Root And Misc: implementation source
Status
source implementation candidate

Why This File Exists

Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef __ASM_GENERIC_UACCESS_H
#define __ASM_GENERIC_UACCESS_H

/*
 * User space memory access functions, these should work
 * on any machine that has kernel and user data in the same
 * address space, e.g. all NOMMU machines.
 */
#include <linux/string.h>
#include <asm-generic/access_ok.h>

#ifdef CONFIG_UACCESS_MEMCPY
#include <linux/unaligned.h>

static __always_inline int
__get_user_fn(size_t size, const void __user *from, void *to)
{
	BUILD_BUG_ON(!__builtin_constant_p(size));

	switch (size) {
	case 1:
		*(u8 *)to = *((u8 __force *)from);
		return 0;
	case 2:
		*(u16 *)to = get_unaligned((u16 __force *)from);
		return 0;
	case 4:
		*(u32 *)to = get_unaligned((u32 __force *)from);
		return 0;
	case 8:
		*(u64 *)to = get_unaligned((u64 __force *)from);
		return 0;
	default:
		BUILD_BUG();
		return 0;
	}

}
#define __get_user_fn(sz, u, k)	__get_user_fn(sz, u, k)

static __always_inline int
__put_user_fn(size_t size, void __user *to, void *from)
{
	BUILD_BUG_ON(!__builtin_constant_p(size));

	switch (size) {
	case 1:
		*(u8 __force *)to = *(u8 *)from;
		return 0;
	case 2:
		put_unaligned(*(u16 *)from, (u16 __force *)to);
		return 0;
	case 4:
		put_unaligned(*(u32 *)from, (u32 __force *)to);
		return 0;
	case 8:
		put_unaligned(*(u64 *)from, (u64 __force *)to);
		return 0;
	default:
		BUILD_BUG();
		return 0;
	}
}
#define __put_user_fn(sz, u, k)	__put_user_fn(sz, u, k)

#define __get_kernel_nofault(dst, src, type, err_label)			\
do {									\
	*((type *)dst) = get_unaligned((type *)(src));			\
	if (0) /* make sure the label looks used to the compiler */	\
		goto err_label;						\
} while (0)

#define __put_kernel_nofault(dst, src, type, err_label)			\
do {									\
	put_unaligned(*((type *)src), (type *)(dst));			\
	if (0) /* make sure the label looks used to the compiler */	\
		goto err_label;						\
} while (0)

static inline __must_check unsigned long
raw_copy_from_user(void *to, const void __user * from, unsigned long n)
{
	memcpy(to, (const void __force *)from, n);
	return 0;
}

static inline __must_check unsigned long
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
{
	memcpy((void __force *)to, from, n);

Annotation

Implementation Notes