Guest User

proc-self-syscall failed on arm32

a guest
May 18th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.76 KB | None | 0 0
  1. am57xx-evm:/home/linaro# cat proc-self-syscall.c
  2. /*
  3.  * Copyright © 2018 Alexey Dobriyan <[email protected]>
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software for any
  6.  * purpose with or without fee is hereby granted, provided that the above
  7.  * copyright notice and this permission notice appear in all copies.
  8.  *
  9.  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10.  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11.  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12.  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15.  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16.  */
  17. #define _GNU_SOURCE
  18. #include <unistd.h>
  19. #include <sys/syscall.h>
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include <fcntl.h>
  23. #include <errno.h>
  24. #include <unistd.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27.  
  28. static inline ssize_t sys_read(int fd, void *buf, size_t len)
  29. {
  30.         return syscall(SYS_read, fd, buf, len);
  31. }
  32.  
  33. int main(void)
  34. {
  35.         char buf1[64];
  36.         char buf2[64];
  37.         int fd;
  38.         int ret;
  39.         ssize_t rv;
  40.  
  41.         fd = open("/proc/self/syscall", O_RDONLY);
  42.         if (fd == -1) {
  43.                 if (errno == ENOENT)
  44.                         return 2;
  45.                 return 1;
  46.         }
  47.  
  48.         /* Do direct system call as libc can wrap anything. */
  49.         snprintf(buf1, sizeof(buf1), "%ld 0x%lx 0x%lx 0x%lx",
  50.                  (long)SYS_read, (long)fd, (long)buf2, (long)sizeof(buf2));
  51.  
  52.         memset(buf2, 0, sizeof(buf2));
  53.         rv = sys_read(fd, buf2, sizeof(buf2));
  54.         printf("sys_read rv = %d \n", rv);
  55.         if (rv < 0) {
  56.                 printf(" %d  < 0 \n", rv);
  57.                 return 1;
  58.         }
  59.         if (rv < strlen(buf1)) {
  60.                 printf("strlen = %d \n", strlen(buf1));
  61.                 return 1;
  62.         }
  63.         ret = strncmp(buf1, buf2, strlen(buf1));
  64.         printf("ret = %d \n", ret);
  65.         if (ret != 0) {
  66.                 printf("buf1 = %s \n", buf1);
  67.                 printf("buf2 = %s \n", buf2);
  68.                 printf("strlen(buf1) = %d \n", strlen(buf1));
  69.                 return 1;
  70.         }
  71.         printf("clean exit\n");
  72.         return 0;
  73. }
  74. am57xx-evm:/home/linaro#
  75. am57xx-evm:/home/linaro# gcc  proc-self-syscall.c -o proc-self-syscall
  76. am57xx-evm:/home/linaro# ./proc-self-syscall
  77. sys_read rv = 64
  78. ret = 3
  79. buf1 = 3 0x3 0xbe947bcc 0x40
  80. buf2 = 0 0x3 0xbe947bcc 0x40 0xbe947bcc 0x40 0xbe947bcc 0xbe947b90 0xb63 0x3 0xbe947bcc 0x40
  81. strlen(buf1) = 21
  82. am57xx-evm:/home/linaro# echo $?
  83. 1
  84. am57xx-evm:/home/linaro#
Add Comment
Please, Sign In to add comment