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.
- Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
Dependency Surface
linux/string.hasm-generic/access_ok.hlinux/unaligned.hasm/extable.h
Detected Declarations
function __get_user_fnfunction __put_user_fnfunction raw_copy_from_userfunction raw_copy_to_userfunction __put_user_fnfunction __get_user_fnfunction __clear_userfunction clear_user
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
- Immediate include surface: `linux/string.h`, `asm-generic/access_ok.h`, `linux/unaligned.h`, `asm/extable.h`.
- Detected declarations: `function __get_user_fn`, `function __put_user_fn`, `function raw_copy_from_user`, `function raw_copy_to_user`, `function __put_user_fn`, `function __get_user_fn`, `function __clear_user`, `function clear_user`.
- Atlas domain: Repository Root And Misc / include.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.