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 <trusty_err.h>
18 
lk_err_to_errno(int lk_err)19 int lk_err_to_errno(int lk_err) {
20     switch (lk_err) {
21     case ERR_INVALID_ARGS:
22         return EINVAL;
23 
24     case ERR_FAULT:
25         return EFAULT;
26 
27     case ERR_BUSY:
28         return EBUSY;
29 
30     case ERR_BAD_HANDLE:
31         return EBADFD;
32 
33     case ERR_TIMED_OUT:
34         return ETIMEDOUT;
35 
36     case ERR_NO_MEMORY:
37         return ENOMEM;
38 
39     default:
40         /* unhandled */
41         return EINVAL;
42     }
43 }
44 
errno_to_lk_err(int err)45 int errno_to_lk_err(int err) {
46     switch (err) {
47     case EINVAL:
48         return ERR_INVALID_ARGS;
49 
50     case EFAULT:
51         return ERR_FAULT;
52 
53     case EBUSY:
54         return ERR_BUSY;
55 
56     case EBADFD:
57         return ERR_BAD_HANDLE;
58 
59     case ETIMEDOUT:
60         return ERR_TIMED_OUT;
61 
62     case ENOMEM:
63         return ERR_NO_MEMORY;
64 
65     default:
66         return ERR_GENERIC;
67     }
68 }
69