gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/syscalls/linux/sigaction.cc (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <signal.h> 16 #include <sys/syscall.h> 17 18 #include "gtest/gtest.h" 19 #include "test/util/test_util.h" 20 21 namespace gvisor { 22 namespace testing { 23 24 namespace { 25 26 TEST(SigactionTest, GetLessThanOrEqualToZeroFails) { 27 struct sigaction act = {}; 28 ASSERT_THAT(sigaction(-1, nullptr, &act), SyscallFailsWithErrno(EINVAL)); 29 ASSERT_THAT(sigaction(0, nullptr, &act), SyscallFailsWithErrno(EINVAL)); 30 } 31 32 TEST(SigactionTest, SetLessThanOrEqualToZeroFails) { 33 struct sigaction act = {}; 34 ASSERT_THAT(sigaction(0, &act, nullptr), SyscallFailsWithErrno(EINVAL)); 35 ASSERT_THAT(sigaction(0, &act, nullptr), SyscallFailsWithErrno(EINVAL)); 36 } 37 38 TEST(SigactionTest, GetGreaterThanMaxFails) { 39 struct sigaction act = {}; 40 ASSERT_THAT(sigaction(SIGRTMAX + 1, nullptr, &act), 41 SyscallFailsWithErrno(EINVAL)); 42 } 43 44 TEST(SigactionTest, SetGreaterThanMaxFails) { 45 struct sigaction act = {}; 46 ASSERT_THAT(sigaction(SIGRTMAX + 1, &act, nullptr), 47 SyscallFailsWithErrno(EINVAL)); 48 } 49 50 TEST(SigactionTest, SetSigkillFails) { 51 struct sigaction act = {}; 52 ASSERT_THAT(sigaction(SIGKILL, nullptr, &act), SyscallSucceeds()); 53 ASSERT_THAT(sigaction(SIGKILL, &act, nullptr), SyscallFailsWithErrno(EINVAL)); 54 } 55 56 TEST(SigactionTest, SetSigstopFails) { 57 struct sigaction act = {}; 58 ASSERT_THAT(sigaction(SIGSTOP, nullptr, &act), SyscallSucceeds()); 59 ASSERT_THAT(sigaction(SIGSTOP, &act, nullptr), SyscallFailsWithErrno(EINVAL)); 60 } 61 62 TEST(SigactionTest, BadSigsetFails) { 63 constexpr size_t kWrongSigSetSize = 43; 64 65 struct sigaction act = {}; 66 67 // The syscall itself (rather than the libc wrapper) takes the sigset_t size. 68 ASSERT_THAT( 69 syscall(SYS_rt_sigaction, SIGTERM, nullptr, &act, kWrongSigSetSize), 70 SyscallFailsWithErrno(EINVAL)); 71 ASSERT_THAT( 72 syscall(SYS_rt_sigaction, SIGTERM, &act, nullptr, kWrongSigSetSize), 73 SyscallFailsWithErrno(EINVAL)); 74 } 75 76 } // namespace 77 78 } // namespace testing 79 } // namespace gvisor