add -fPIC option to the C compiler, required in f31
[vsys.git] / splice_stub.c
1 /* This module allows data between vsys clients and servers to be copied in kernel -
2  * and some of these copies to be eliminated through page rewrites */
3
4 #define SPLICE_SYSCALL  313
5 #define TEE_SYSCALL     315
6 #define SPLICE_F_NONBLOCK 0x02
7
8 #include <string.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include <sys/syscall.h>
13 #include <caml/mlvalues.h>
14 #include <caml/memory.h>
15 #include <caml/alloc.h>
16 #include <caml/custom.h>
17 #include <caml/fail.h>
18 #include <caml/signals.h>
19
20 CAMLprim value stub_splice(value fd_in, value fd_out, value len)
21 {
22         CAMLparam3(fd_in, fd_out, len);
23         long ret;
24         ret = syscall(SPLICE_SYSCALL, Int_val(fd_in), NULL, Int_val(fd_out),NULL, Int_val(len), SPLICE_F_NONBLOCK);
25         if (ret == -1 && errno!=EAGAIN) {
26                 caml_failwith("Splice system call returned -1");
27         }
28         CAMLreturn(Val_int(ret));
29 }
30
31 CAMLprim value stub_tee(value fd_in, value fd_out, value len)
32 {
33         CAMLparam3(fd_in, fd_out, len);
34         long ret;
35         ret = syscall(TEE_SYSCALL,Int_val(fd_in), Int_val(fd_out), Int_val(len), SPLICE_F_NONBLOCK);
36         if (ret == -1 && errno!=EAGAIN) {
37                 caml_failwith(strerror(errno));
38         }
39         CAMLreturn(Val_int(ret));
40 }