1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001
4f08c3bdfSopenharmony_ci */
5f08c3bdfSopenharmony_ci
6f08c3bdfSopenharmony_ci/*\
7f08c3bdfSopenharmony_ci * [Description]
8f08c3bdfSopenharmony_ci *
9f08c3bdfSopenharmony_ci * Tests basic error handing of the shmdt syscall.
10f08c3bdfSopenharmony_ci *
11f08c3bdfSopenharmony_ci * -EINVAL there is no shared memory segment attached at shmaddr.
12f08c3bdfSopenharmony_ci * -EINVAL shmaddr is not aligned on a page boundary.
13f08c3bdfSopenharmony_ci */
14f08c3bdfSopenharmony_ci
15f08c3bdfSopenharmony_ci#include <sys/types.h>
16f08c3bdfSopenharmony_ci#include <sys/shm.h>
17f08c3bdfSopenharmony_ci#include "tst_test.h"
18f08c3bdfSopenharmony_ci#include "libnewipc.h"
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_cistatic void *non_attched_addr;
21f08c3bdfSopenharmony_cistatic void *unaligned_addr;
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_cistruct tcase {
24f08c3bdfSopenharmony_ci	void **addr;
25f08c3bdfSopenharmony_ci	char *des;
26f08c3bdfSopenharmony_ci} tcases[] = {
27f08c3bdfSopenharmony_ci	{&non_attched_addr, "shmdt(non_attched_addr)"},
28f08c3bdfSopenharmony_ci	{&unaligned_addr, "shmdt(unaligned_addr)"}
29f08c3bdfSopenharmony_ci};
30f08c3bdfSopenharmony_ci
31f08c3bdfSopenharmony_cistatic void verify_shmdt(unsigned int n)
32f08c3bdfSopenharmony_ci{
33f08c3bdfSopenharmony_ci	struct tcase *tc = &tcases[n];
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ci	TST_EXP_FAIL(shmdt(*tc->addr), EINVAL, "%s", tc->des);
36f08c3bdfSopenharmony_ci}
37f08c3bdfSopenharmony_ci
38f08c3bdfSopenharmony_cistatic void setup(void)
39f08c3bdfSopenharmony_ci{
40f08c3bdfSopenharmony_ci	non_attched_addr = PROBE_FREE_ADDR();
41f08c3bdfSopenharmony_ci	unaligned_addr = non_attched_addr + SHMLBA - 1;
42f08c3bdfSopenharmony_ci}
43f08c3bdfSopenharmony_ci
44f08c3bdfSopenharmony_cistatic struct tst_test test = {
45f08c3bdfSopenharmony_ci	.setup = setup,
46f08c3bdfSopenharmony_ci	.test = verify_shmdt,
47f08c3bdfSopenharmony_ci	.tcnt = ARRAY_SIZE(tcases),
48f08c3bdfSopenharmony_ci};
49