tools/testing/selftests/proc/proc-maps-race.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-maps-race.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/proc/proc-maps-race.c
Extension
.c
Size
29109 bytes
Lines
976
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

struct page_content {
	char *data;
	ssize_t size;
};

#define LINE_MAX_SIZE		256

struct line_content {
	char text[LINE_MAX_SIZE];
	unsigned long start_addr;
	unsigned long end_addr;
};

enum test_state {
	INIT,
	CHILD_READY,
	PARENT_READY,
	SETUP_READY,
	SETUP_MODIFY_MAPS,
	SETUP_MAPS_MODIFIED,
	SETUP_RESTORE_MAPS,
	SETUP_MAPS_RESTORED,
	TEST_READY,
	TEST_DONE,
};

enum maps_file {
	MAPS,
	SMAPS,
};

struct vma_modifier_info;

FIXTURE(proc_maps_race)
{
	struct vma_modifier_info *mod_info;
	struct page_content page1;
	struct page_content page2;
	struct line_content last_line;
	struct line_content first_line;
	unsigned long duration_sec;
	enum maps_file maps_file;
	int shared_mem_size;
	int skip_pages;
	int page_size;
	int vma_count;
	bool verbose;
	int maps_fd;
	pid_t pid;
};

FIXTURE_VARIANT(proc_maps_race)
{
	const enum maps_file maps_file;
};

FIXTURE_VARIANT_ADD(proc_maps_race, maps) {
	.maps_file = MAPS,
};

FIXTURE_VARIANT_ADD(proc_maps_race, smaps) {
	.maps_file = SMAPS,
};

typedef bool (*vma_modifier_op)(FIXTURE_DATA(proc_maps_race) *self);
typedef bool (*vma_mod_result_check_op)(struct line_content *mod_last_line,
					struct line_content *mod_first_line,
					struct line_content *restored_last_line,
					struct line_content *restored_first_line);

struct vma_modifier_info {
	int vma_count;
	void *addr;
	int prot;
	void *next_addr;
	vma_modifier_op vma_modify;
	vma_modifier_op vma_restore;
	vma_mod_result_check_op vma_mod_check;
	pthread_mutex_t sync_lock;
	pthread_cond_t sync_cond;
	enum test_state curr_state;
	bool exit;
	void *child_mapped_addr[];
};

static bool read_page(FIXTURE_DATA(proc_maps_race) *self,
		      struct page_content *page)
{
	ssize_t  bytes_read;

Annotation

Implementation Notes