0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <unistd.h>
0017 #include <sys/syscall.h>
0018 #include <sys/types.h>
0019 #include <sys/stat.h>
0020 #include <fcntl.h>
0021 #include <errno.h>
0022 #include <string.h>
0023 #include <stdio.h>
0024
0025 static inline ssize_t sys_read(int fd, void *buf, size_t len)
0026 {
0027 return syscall(SYS_read, fd, buf, len);
0028 }
0029
0030 int main(void)
0031 {
0032 char buf1[64];
0033 char buf2[64];
0034 int fd;
0035 ssize_t rv;
0036
0037 fd = open("/proc/self/syscall", O_RDONLY);
0038 if (fd == -1) {
0039 if (errno == ENOENT)
0040 return 4;
0041 return 1;
0042 }
0043
0044
0045 snprintf(buf1, sizeof(buf1), "%ld 0x%lx 0x%lx 0x%lx",
0046 (long)SYS_read, (long)fd, (long)buf2, (long)sizeof(buf2));
0047
0048 memset(buf2, 0, sizeof(buf2));
0049 rv = sys_read(fd, buf2, sizeof(buf2));
0050 if (rv < 0)
0051 return 1;
0052 if (rv < strlen(buf1))
0053 return 1;
0054 if (strncmp(buf1, buf2, strlen(buf1)) != 0)
0055 return 1;
0056
0057 return 0;
0058 }