[LTP] [PATCH v6 2/3] syscalls/modify_ldt02: Refactor into new API

Cyril Hrubis chrubis@suse.cz
Mon Apr 7 14:24:29 CEST 2025


Hi!
> --- /dev/null
> +++ b/testcases/kernel/syscalls/modify_ldt/common.h
> @@ -0,0 +1,30 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) International Business Machines  Corp., 2001
> + *	07/2001 Ported by Wayne Boyer
> + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
> + */
> +
> +#ifndef COMMON_H
> +#define COMMON_H
> +
> +#include "tst_test.h"
> +#include "lapi/ldt.h"
> +
> +int create_segment(void *seg, size_t size)

This should be void now, since we are not checking the return value
anyways.

> +{
> +	struct user_desc entry = {
> +		.entry_number = 0,
> +		.base_addr = (unsigned long)seg,
> +		.limit = size,
> +		.seg_32bit = 1,
> +		.contents = 0,
> +		.read_exec_only = 0,
> +		.limit_in_pages = 0,
> +		.seg_not_present = 0,
> +	};
> +
> +	return SAFE_MODIFY_LDT(1, &entry, sizeof(entry));
> +}

...

> +	if (!pid) {
> +		signal(SIGSEGV, SIG_DFL);

We do not mess with signal handlers in the new test library, so this
shouldn't be needed.

> +		read_segment(0);
> +		exit(1);
> +	}
> +
> +	SAFE_WAITPID(pid, &status, 0);
> +	if (WEXITSTATUS(status) != 0) {
> +		tst_res(TFAIL, "Did not generate SEGV, child returned "
> +			       "unexpected status");
> +	} else {
> +		if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGSEGV))
> +			tst_res(TPASS, "generate SEGV as expected");
> +		else
> +			tst_res(TFAIL, "Did not generate SEGV");
> +	}

This should be just:

	if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGSEGV))
		tst_res(TPASS, "generate SEGV as expected");
	else
		tst_res(TFAIL, "child %s", tst_strstatus(status));

>  }
>  
> -#endif /* if defined(__i386__) */
> +static struct tst_test test = {
> +	.test_all = run,
> +	.forks_child = 1,
> +};
> +
> +#else
> +TST_TEST_TCONF("Test supported only on i386");
> +#endif /* __i386__ */
> 
> -- 
> 2.49.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list