1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2003. 4f08c3bdfSopenharmony_ci * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * Test for a libc bug where exiting child function by returning from 11f08c3bdfSopenharmony_ci * it caused SIGSEGV. 12f08c3bdfSopenharmony_ci */ 13f08c3bdfSopenharmony_ci 14f08c3bdfSopenharmony_ci#include <sched.h> 15f08c3bdfSopenharmony_ci#include <stdio.h> 16f08c3bdfSopenharmony_ci#include <stdlib.h> 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 19f08c3bdfSopenharmony_ci#include "clone_platform.h" 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_cistatic void *child_stack; 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic int do_child(void *arg LTP_ATTRIBUTE_UNUSED) 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci return 0; 26f08c3bdfSopenharmony_ci} 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_cistatic void verify_clone(void) 29f08c3bdfSopenharmony_ci{ 30f08c3bdfSopenharmony_ci int status; 31f08c3bdfSopenharmony_ci pid_t pid = 0; 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, 34f08c3bdfSopenharmony_ci child_stack)); 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci if (!TST_PASS) 37f08c3bdfSopenharmony_ci return; 38f08c3bdfSopenharmony_ci 39f08c3bdfSopenharmony_ci SAFE_WAITPID(pid, &status, 0); 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { 42f08c3bdfSopenharmony_ci tst_res(TPASS, "Using return in child will not cause abnormal exit"); 43f08c3bdfSopenharmony_ci return; 44f08c3bdfSopenharmony_ci } 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) { 47f08c3bdfSopenharmony_ci tst_res(TFAIL, "Use of return in child caused SIGSEGV"); 48f08c3bdfSopenharmony_ci return; 49f08c3bdfSopenharmony_ci } 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_ci tst_res(TFAIL, "Using return 0 in child the child %s", tst_strstatus(status)); 52f08c3bdfSopenharmony_ci} 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_cistatic struct tst_test test = { 55f08c3bdfSopenharmony_ci .test_all = verify_clone, 56f08c3bdfSopenharmony_ci .bufs = (struct tst_buffers []) { 57f08c3bdfSopenharmony_ci {&child_stack, .size = CHILD_STACK_SIZE}, 58f08c3bdfSopenharmony_ci {}, 59f08c3bdfSopenharmony_ci }, 60f08c3bdfSopenharmony_ci}; 61