Debian Codegraph @

ptl_am/kcopyrwu.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013. Intel Corporation. All rights reserved.
3 * Copyright (c) 2006-2012. QLogic Corporation. All rights reserved.
4 * Copyright (c) 2003-2006, PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35 #include <sys/types.h>
36 #include <unistd.h>
37
38 #include "kcopyrw.h"
39
40 #define KCOPY_GET_SYSCALL 1
41 #define KCOPY_PUT_SYSCALL 2
42 #define KCOPY_ABI_SYSCALL 3
43
44 struct kcopy_syscall {
45 uint32_t tag;
46 pid_t pid;
47 uint64_t n;
48 uint64_t src;
49 uint64_t dst;
50 };
51
52 int64_t kcopy_get(int fd, pid_t pid, const void *src, void *dst, int64_t n) {
53 struct kcopy_syscall e = {
54 .tag = KCOPY_GET_SYSCALL,
55 .pid = pid,
56 .n = n,
57 .src = (uint64_t) (uintptr_t) src,
58 .dst = (uint64_t) (uintptr_t) dst
59 };
60 int64_t ret;
61
62 ret = write(fd, &e, sizeof(e));
63 if (ret == sizeof(e))
64 ret = n;
65 else if (ret > 0 && ret != sizeof(e))
66 ret = 0;
67
68 return ret;
69 }
70
71 int64_t kcopy_put(int fd, const void *src, pid_t pid, void *dst, int64_t n) {
72 struct kcopy_syscall e = {
73 .tag = KCOPY_PUT_SYSCALL,
74 .pid = pid,
75 .n = n,
76 .src = (uint64_t) (uintptr_t) src,
77 .dst = (uint64_t) (uintptr_t) dst
78 };
79 int64_t ret;
80
81 ret = write(fd, &e, sizeof(e));
82 if (ret == sizeof(e))
83 ret = n;
84 else if (ret > 0 && ret != sizeof(e))
85 ret = 0;
86
87 return ret;
88 }
89
90 int kcopy_abi(int fd) {
91 int32_t abi;
92 struct kcopy_syscall e = {
93 .tag = KCOPY_ABI_SYSCALL,
94 .dst = (uint64_t) (uintptr_t) &abi
95 };
96 int ret;
97
98 ret = write(fd, &e, sizeof(e));
99 if (ret == sizeof(e))
100 ret = abi;
101 else if (ret > 0 && ret != sizeof(e))
102 ret = 0;
103
104 return ret;
105 }