include/linux/regset.h

Source file repositories/reference/linux-study-clean/include/linux/regset.h

File Facts

System
Linux kernel
Corpus path
include/linux/regset.h
Extension
.h
Size
11975 bytes
Lines
351
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct membuf {
	void *p;
	size_t left;
};

static inline int membuf_zero(struct membuf *s, size_t size)
{
	if (s->left) {
		if (size > s->left)
			size = s->left;
		memset(s->p, 0, size);
		s->p += size;
		s->left -= size;
	}
	return s->left;
}

static inline int membuf_write(struct membuf *s, const void *v, size_t size)
{
	if (s->left) {
		if (size > s->left)
			size = s->left;
		memcpy(s->p, v, size);
		s->p += size;
		s->left -= size;
	}
	return s->left;
}

static inline struct membuf membuf_at(const struct membuf *s, size_t offs)
{
	struct membuf n = *s;

	if (offs > n.left)
		offs = n.left;
	n.p += offs;
	n.left -= offs;

	return n;
}

/* current s->p must be aligned for v; v must be a scalar */
#define membuf_store(s, v)				\
({							\
	struct membuf *__s = (s);			\
        if (__s->left) {				\
		typeof(v) __v = (v);			\
		size_t __size = sizeof(__v);		\
		if (unlikely(__size > __s->left)) {	\
			__size = __s->left;		\
			memcpy(__s->p, &__v, __size);	\
		} else {				\
			*(typeof(__v + 0) *)__s->p = __v;	\
		}					\
		__s->p += __size;			\
		__s->left -= __size;			\
	}						\
	__s->left;})

/**
 * user_regset_active_fn - type of @active function in &struct user_regset
 * @target:	thread being examined
 * @regset:	regset being examined
 *
 * Return -%ENODEV if not available on the hardware found.
 * Return %0 if no interesting state in this thread.
 * Return >%0 number of @size units of interesting state.
 * Any get call fetching state beyond that number will
 * see the default initialization state for this data,
 * so a caller that knows what the default state is need
 * not copy it all out.
 * This call is optional; the pointer is %NULL if there
 * is no inexpensive check to yield a value < @n.
 */
typedef int user_regset_active_fn(struct task_struct *target,
				  const struct user_regset *regset);

typedef int user_regset_get2_fn(struct task_struct *target,
			       const struct user_regset *regset,
			       struct membuf to);

/**
 * user_regset_set_fn - type of @set function in &struct user_regset
 * @target:	thread being examined
 * @regset:	regset being examined
 * @pos:	offset into the regset data to access, in bytes
 * @count:	amount of data to copy, in bytes
 * @kbuf:	if not %NULL, a kernel-space pointer to copy from
 * @ubuf:	if @kbuf is %NULL, a user-space pointer to copy from
 *

Annotation

Implementation Notes