syscall_args.h revision c70cba91
1// syscall_args.h
2
3#ifndef _SYSCALL_ARGS_H
4#define _SYSCALL_ARGS_H
5
6#include <kernel.h>
7
8
9// Hack to be able to use the IS_USER_ADDRESS macro when compiling for R5.
10#ifdef R5_MEMORY_LAYOUT
11#	undef KERNEL_BASE
12#	define KERNEL_BASE 0x0
13#endif
14
15// copy_ref_var_from_user
16template<typename T>
17inline
18status_t
19copy_ref_var_from_user(T *user, T &kernel)
20{
21	if (!IS_USER_ADDRESS(user))
22		return B_BAD_ADDRESS;
23	return user_memcpy(&kernel, user, sizeof(T));
24}
25
26
27template<typename T>
28inline
29status_t
30copy_ref_var_from_user(T *user, T &kernel, size_t size)
31{
32	if (size != sizeof(T))
33		return B_BAD_VALUE;
34	return copy_ref_var_from_user(user, kernel);
35}
36
37
38// copy_ref_var_to_user
39template<typename T>
40inline
41status_t
42copy_ref_var_to_user(T &kernel, T *user)
43{
44	if (!IS_USER_ADDRESS(user))
45		return B_BAD_ADDRESS;
46	return user_memcpy(user, &kernel, sizeof(T));
47}
48
49
50template<typename T>
51inline
52status_t
53copy_ref_var_to_user(T &kernel, T *user, size_t size)
54{
55	if (size > sizeof(T))
56		return B_BAD_VALUE;
57	if (!IS_USER_ADDRESS(user))
58		return B_BAD_ADDRESS;
59	return user_memcpy(user, &kernel, size);
60}
61
62
63#endif	// _SYSCALL_ARGS_H
64