1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 4f08c3bdfSopenharmony_ci * Author: Xie Ziyao <xieziyao@huawei.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Verify that, epoll_pwait() and epoll_pwait2() return -1 and set errno to 11f08c3bdfSopenharmony_ci * EFAULT with a sigmask points outside user's accessible address space. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci#include <sys/epoll.h> 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include "tst_test.h" 17f08c3bdfSopenharmony_ci#include "epoll_pwait_var.h" 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_cistatic int efd, sfd[2]; 20f08c3bdfSopenharmony_cistatic struct epoll_event e; 21f08c3bdfSopenharmony_cistatic void *bad_addr; 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic void run(void) 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci TST_EXP_FAIL(do_epoll_pwait(efd, &e, 1, -1, bad_addr), 26f08c3bdfSopenharmony_ci EFAULT, "with an invalid sigmask pointer"); 27f08c3bdfSopenharmony_ci} 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_cistatic void setup(void) 30f08c3bdfSopenharmony_ci{ 31f08c3bdfSopenharmony_ci epoll_pwait_init(); 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd); 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci efd = epoll_create(1); 36f08c3bdfSopenharmony_ci if (efd == -1) 37f08c3bdfSopenharmony_ci tst_brk(TBROK | TERRNO, "epoll_create()"); 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci e.events = EPOLLIN; 40f08c3bdfSopenharmony_ci if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e)) 41f08c3bdfSopenharmony_ci tst_brk(TBROK | TERRNO, "epoll_ctl(..., EPOLL_CTL_ADD, ...)"); 42f08c3bdfSopenharmony_ci SAFE_WRITE(SAFE_WRITE_ALL, sfd[1], "w", 1); 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci bad_addr = tst_get_bad_addr(NULL); 45f08c3bdfSopenharmony_ci} 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_cistatic void cleanup(void) 48f08c3bdfSopenharmony_ci{ 49f08c3bdfSopenharmony_ci if (efd > 0) 50f08c3bdfSopenharmony_ci SAFE_CLOSE(efd); 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci if (sfd[0] > 0) 53f08c3bdfSopenharmony_ci SAFE_CLOSE(sfd[0]); 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ci if (sfd[1] > 0) 56f08c3bdfSopenharmony_ci SAFE_CLOSE(sfd[1]); 57f08c3bdfSopenharmony_ci} 58f08c3bdfSopenharmony_ci 59f08c3bdfSopenharmony_cistatic struct tst_test test = { 60f08c3bdfSopenharmony_ci .test_all = run, 61f08c3bdfSopenharmony_ci .setup = setup, 62f08c3bdfSopenharmony_ci .cleanup = cleanup, 63f08c3bdfSopenharmony_ci .test_variants = TEST_VARIANTS, 64f08c3bdfSopenharmony_ci}; 65