1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <sys/uio.h>
18 #include <trusty_err.h>
19 #include <trusty_syscalls.h>
20 #include <unistd.h>
21
readv(int fd,const struct iovec * iov,int iov_cnt)22 ssize_t readv(int fd, const struct iovec* iov, int iov_cnt) {
23 ssize_t res = _trusty_readv(fd, iov, iov_cnt);
24 if (res < 0) {
25 errno = lk_err_to_errno((int)res);
26 res = -1;
27 }
28 return res;
29 }
30
read(int fd,void * buf,size_t count)31 ssize_t read(int fd, void* buf, size_t count) {
32 struct iovec iov = {.iov_base = buf, .iov_len = count};
33 return readv(fd, &iov, 1);
34 }
35
writev(int fd,const struct iovec * iov,int iov_cnt)36 ssize_t writev(int fd, const struct iovec* iov, int iov_cnt) {
37 ssize_t res = _trusty_writev(fd, iov, iov_cnt);
38 if (res < 0) {
39 errno = lk_err_to_errno(res);
40 res = -1;
41 }
42 return res;
43 }
44
write(int fd,const void * buf,size_t count)45 ssize_t write(int fd, const void* buf, size_t count) {
46 struct iovec iov = {.iov_base = buf, .iov_len = count};
47 return writev(fd, &iov, 1);
48 }
49
trusty_readv(int fd,const struct iovec * iov,int iov_cnt)50 ssize_t trusty_readv(int fd, const struct iovec* iov, int iov_cnt) {
51 return _trusty_readv(fd, iov, iov_cnt);
52 }
53
trusty_read(int fd,void * buf,size_t count)54 ssize_t trusty_read(int fd, void* buf, size_t count) {
55 struct iovec iov = {.iov_base = buf, .iov_len = count};
56 return _trusty_readv(fd, &iov, 1);
57 }
58
trusty_writev(int fd,const struct iovec * iov,int iov_cnt)59 ssize_t trusty_writev(int fd, const struct iovec* iov, int iov_cnt) {
60 return _trusty_writev(fd, iov, iov_cnt);
61 }
62
trusty_write(int fd,const void * buf,size_t count)63 ssize_t trusty_write(int fd, const void* buf, size_t count) {
64 struct iovec iov = {.iov_base = buf, .iov_len = count};
65 return trusty_writev(fd, &iov, 1);
66 }
67