tools/testing/selftests/mm/mseal_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/mseal_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/mm/mseal_test.c
Extension
.c
Size
45686 bytes
Lines
1990
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

if (sscanf(line, "%lx-%lx %4s", &addr_start, &addr_end, protstr) == 3) {
			if (addr_start == (uintptr_t) addr) {
				size = addr_end - addr_start;
				if (protstr[0] == 'r')
					*prot |= 0x4;
				if (protstr[1] == 'w')
					*prot |= 0x2;
				if (protstr[2] == 'x')
					*prot |= 0x1;
				break;
			}
		}
	}
	fclose(maps);
	return size;
}

/*
 * define sys_xyx to call syscall directly.
 */
static int sys_mseal(void *start, size_t len)
{
	int sret;

	errno = 0;
	sret = syscall(__NR_mseal, start, len, 0);
	return sret;
}

static int sys_mprotect(void *ptr, size_t size, unsigned long prot)
{
	int sret;

	errno = 0;
	sret = syscall(__NR_mprotect, ptr, size, prot);
	return sret;
}

static int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
		unsigned long pkey)
{
	int sret;

	errno = 0;
	sret = syscall(__NR_pkey_mprotect, ptr, size, orig_prot, pkey);
	return sret;
}

static int sys_munmap(void *ptr, size_t size)
{
	int sret;

	errno = 0;
	sret = syscall(__NR_munmap, ptr, size);
	return sret;
}

static int sys_madvise(void *start, size_t len, int types)
{
	int sret;

	errno = 0;
	sret = syscall(__NR_madvise, start, len, types);
	return sret;
}

static void *sys_mremap(void *addr, size_t old_len, size_t new_len,
	unsigned long flags, void *new_addr)
{
	void *sret;

	errno = 0;
	sret = (void *) syscall(__NR_mremap, addr, old_len, new_len, flags, new_addr);
	return sret;
}

static int sys_pkey_alloc(unsigned long flags, unsigned long init_val)
{
	int ret = syscall(__NR_pkey_alloc, flags, init_val);

	return ret;
}

static unsigned int __read_pkey_reg(void)
{
	unsigned int pkey_reg = 0;
#if defined(__i386__) || defined(__x86_64__) /* arch */
	unsigned int eax, edx;
	unsigned int ecx = 0;

Annotation

Implementation Notes