1 /*
2 * Copyright (c) 2021 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #include "tests.h"
9 #include "scno.h"
10
11 #include <assert.h>
12 #include <errno.h>
13 #include <fcntl.h>
14 #include <stdio.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <sys/socket.h>
19
20 int
21 main(void)
22 {
23 int sv[2];
24 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv))
25 perror_msg_and_skip("socketpair");
26
27 unsigned int file_size = 0;
28 socklen_t optlen = sizeof(file_size);
29 if (getsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &file_size, &optlen))
30 perror_msg_and_fail("getsockopt");
31 file_size /= 4;
32
33 int reg_in = create_tmpfile(O_RDWR);
34 if (ftruncate(reg_in, file_size))
35 perror_msg_and_fail("ftruncate(%d, %u)", reg_in, file_size);
36
37 TAIL_ALLOC_OBJECT_CONST_PTR(uint64_t, p_off);
38 *p_off = 0xcafef00dfacefeedULL;
39
40 #ifdef __NR_sendfile64
41 syscall(__NR_sendfile64, sv[1], reg_in, p_off, file_size);
42 static const char name[] = "sendfile64";
43 static const unsigned long long expected = -1ULL;
44 #else
45 syscall(__NR_sendfile, sv[1], reg_in, p_off, file_size);
46 static const char name[] = "sendfile";
47 static const unsigned long long expected = (kernel_ulong_t) -1ULL;
48 #endif
49
50 printf("%s(%d, %d, [0] => [%llu], %u) = %u (INJECTED: args)\n",
51 name, sv[1], reg_in, expected, file_size, file_size);
52
53 puts("+++ exited with 0 +++");
54 return 0;
55 }