include/linux/list_private.h

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

File Facts

System
Linux kernel
Corpus path
include/linux/list_private.h
Extension
.h
Size
10050 bytes
Lines
257
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

#ifndef _LINUX_LIST_PRIVATE_H
#define _LINUX_LIST_PRIVATE_H

/**
 * DOC: Private List Primitives
 *
 * Provides a set of list primitives identical in function to those in
 * ``<linux/list.h>``, but designed for cases where the embedded
 * ``&struct list_head`` is private member.
 */

#include <linux/compiler.h>
#include <linux/list.h>

#define __list_private_offset(type, member)					\
	((size_t)(&ACCESS_PRIVATE(((type *)0), member)))

/**
 * list_private_entry - get the struct for this entry
 * @ptr:	the &struct list_head pointer.
 * @type:	the type of the struct this is embedded in.
 * @member:	the identifier passed to ACCESS_PRIVATE.
 */
#define list_private_entry(ptr, type, member) ({				\
	const struct list_head *__mptr = (ptr);					\
	(type *)((char *)__mptr - __list_private_offset(type, member));		\
})

/**
 * list_private_first_entry - get the first element from a list
 * @ptr:	the list head to take the element from.
 * @type:	the type of the struct this is embedded in.
 * @member:	the identifier passed to ACCESS_PRIVATE.
 */
#define list_private_first_entry(ptr, type, member)				\
	list_private_entry((ptr)->next, type, member)

/**
 * list_private_last_entry - get the last element from a list
 * @ptr:	the list head to take the element from.
 * @type:	the type of the struct this is embedded in.
 * @member:	the identifier passed to ACCESS_PRIVATE.
 */
#define list_private_last_entry(ptr, type, member)				\
	list_private_entry((ptr)->prev, type, member)

/**
 * list_private_next_entry - get the next element in list
 * @pos:	the type * to cursor
 * @member:	the name of the list_head within the struct.
 */
#define list_private_next_entry(pos, member)					\
	list_private_entry(ACCESS_PRIVATE(pos, member).next, typeof(*(pos)), member)

/**
 * list_private_next_entry_circular - get the next element in list
 * @pos:	the type * to cursor.
 * @head:	the list head to take the element from.
 * @member:	the name of the list_head within the struct.
 *
 * Wraparound if pos is the last element (return the first element).
 * Note, that list is expected to be not empty.
 */
#define list_private_next_entry_circular(pos, head, member)			\
	(list_is_last(&ACCESS_PRIVATE(pos, member), head) ?			\
	list_private_first_entry(head, typeof(*(pos)), member) :		\
	list_private_next_entry(pos, member))

/**
 * list_private_prev_entry - get the prev element in list
 * @pos:	the type * to cursor
 * @member:	the name of the list_head within the struct.
 */
#define list_private_prev_entry(pos, member)					\
	list_private_entry(ACCESS_PRIVATE(pos, member).prev, typeof(*(pos)), member)

/**
 * list_private_prev_entry_circular - get the prev element in list
 * @pos:	the type * to cursor.
 * @head:	the list head to take the element from.
 * @member:	the name of the list_head within the struct.
 *
 * Wraparound if pos is the first element (return the last element).
 * Note, that list is expected to be not empty.
 */
#define list_private_prev_entry_circular(pos, head, member)			\
	(list_is_first(&ACCESS_PRIVATE(pos, member), head) ?			\
	list_private_last_entry(head, typeof(*(pos)), member) :			\
	list_private_prev_entry(pos, member))

Annotation

Implementation Notes