• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define _GNU_SOURCE 1
2 
3 #include <config.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/types.h>
9 #include <sys/uio.h>
10 
11 static int status = EXIT_SUCCESS;
12 
13 #ifdef HAVE_PROCESS_VM_READV
14 
test_process_vm_readv()15 static void test_process_vm_readv()
16 {
17    char lbuf[] = "123456";
18    char rbuf[] = "ABCDEF";
19 
20    struct iovec lvec[2];
21    struct iovec rvec[2];
22 
23    lvec[0].iov_base = lbuf + 1;
24    lvec[0].iov_len = 1;
25    lvec[1].iov_base = lbuf + 3;
26    lvec[1].iov_len = 2;
27 
28    rvec[0].iov_base = rbuf + 1;
29    rvec[0].iov_len = 2;
30    rvec[1].iov_base = rbuf + 4;
31    rvec[1].iov_len = 1;
32 
33    if (process_vm_readv(getpid(),
34                         lvec, 2,
35                         rvec, 2,
36                         0 ) < 0 ) {
37       perror("process_vm_readv");
38       status = EXIT_FAILURE;
39    }
40 
41    if (strcmp(lbuf, "1B3CE6") != 0) {
42       fprintf(stderr, "Expected: \"1B3CE6\"; Got: \"%s\"\n", lbuf);
43       status = EXIT_FAILURE;
44    }
45 }
46 
47 #endif /* defined( HAVE_PROCESS_VM_READV ) */
48 
49 #ifdef HAVE_PROCESS_VM_WRITEV
50 
test_process_vm_writev()51 static void test_process_vm_writev()
52 {
53    char lbuf[] = "123456";
54    char rbuf[] = "ABCDEF";
55 
56    struct iovec lvec[2];
57    struct iovec rvec[2];
58 
59    lvec[0].iov_base = lbuf + 1;
60    lvec[0].iov_len = 1;
61    lvec[1].iov_base = lbuf + 3;
62    lvec[1].iov_len = 2;
63 
64    rvec[0].iov_base = rbuf + 1;
65    rvec[0].iov_len = 2;
66    rvec[1].iov_base = rbuf + 4;
67    rvec[1].iov_len = 1;
68 
69    if (process_vm_writev(getpid(),
70                          lvec, 2,
71                          rvec, 2,
72                          0 ) < 0 ) {
73       perror("process_vm_writev");
74       status = EXIT_FAILURE;
75    }
76 
77    if (strcmp(rbuf, "A24D5F") != 0) {
78       fprintf(stderr, "Expected: \"A24D5F\"; Got: \"%s\"\n", rbuf);
79       status = EXIT_FAILURE;
80    }
81 }
82 
83 #endif /* defined( HAVE_PROCESS_VM_WRITEV ) */
84 
main(int argc,char * argv[])85 int main(int argc, char *argv[])
86 {
87 #ifdef HAVE_PROCESS_VM_READV
88    test_process_vm_readv();
89 #endif
90 #ifdef HAVE_PROCESS_VM_WRITEV
91    test_process_vm_writev();
92 #endif
93    return status;
94 }
95