diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-05-13 16:28:06 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-05-13 16:28:06 +0800 |
| commit | 8cbf571e56fd5ef631b51f4e5e3f181df1a529ff (patch) | |
| tree | bab065dec38cafc7ba161b5cd42515df4d8be2a9 /na/include | |
| parent | 84be4cc9baf7b0a75af18e77995184e0494b4e87 (diff) | |
| download | lume-8cbf571e56fd5ef631b51f4e5e3f181df1a529ff.tar.gz lume-8cbf571e56fd5ef631b51f4e5e3f181df1a529ff.tar.xz | |
feat: implement user-kernel memory copy functions with validation
Diffstat (limited to 'na/include')
| -rw-r--r-- | na/include/lume/uaccess.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/na/include/lume/uaccess.h b/na/include/lume/uaccess.h new file mode 100644 index 0000000..5a9ed71 --- /dev/null +++ b/na/include/lume/uaccess.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright (C) 2026 Richard Qin */ + +#pragma once + +/* + * User-space memory access — safe copy routines. + * + * Phase 2: Software page-table validation. + * Phase 3+: Exception Table (zero-cost happy path). + * + * Reference: docs/specs/syscall.md §8 + */ + +#include <lume/types.h> + +/* Copy len bytes from user address to kernel buffer. + * Returns 0 on success, -EFAULT if user address is invalid. */ +int copy_from_user(void* kernel_dst, uint64 user_src, uint64 len); + +/* Copy len bytes from kernel buffer to user address. + * Returns 0 on success, -EFAULT if user address is invalid. */ +int copy_to_user(uint64 user_dst, const void* kernel_src, uint64 len); + +/* Copy NUL-terminated string from user space. + * Returns string length (excluding NUL) or -EFAULT. */ +int64 strncpy_from_user(char* kernel_dst, uint64 user_src, uint64 max_len); |
