Asylo
posix_error_space.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 Asylo authors
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef ASYLO_UTIL_POSIX_ERROR_SPACE_H_
20 #define ASYLO_UTIL_POSIX_ERROR_SPACE_H_
21 
22 #include <errno.h>
23 #include <cerrno>
24 #include <string>
25 
26 #include "asylo/util/error_space.h"
27 
28 namespace asylo {
29 namespace error {
30 
31 /// The enum associated with the POSIX error-space. To avoid conflict with the
32 /// macros defined in the <cerrno> system header, all the codes in this enum are
33 /// prefixed with a "P_".
34 enum PosixError {
35  P_E2BIG = E2BIG,
36  P_EACCES = EACCES,
37  P_EADDRINUSE = EADDRINUSE,
38  P_EADDRNOTAVAIL = EADDRNOTAVAIL,
39  P_EAFNOSUPPORT = EAFNOSUPPORT,
40  P_EAGAIN = EAGAIN,
41  P_EALREADY = EALREADY,
42  P_EBADF = EBADF,
43  P_EBADMSG = EBADMSG,
44  P_EBUSY = EBUSY,
45  P_ECANCELED = ECANCELED,
46  P_ECHILD = ECHILD,
47  P_ECONNABORTED = ECONNABORTED,
48  P_ECONNREFUSED = ECONNREFUSED,
49  P_ECONNRESET = ECONNRESET,
50  P_EDEADLK = EDEADLK,
51  P_EDESTADDRREQ = EDESTADDRREQ,
52  P_EDOM = EDOM,
53  P_EDQUOT = EDQUOT,
54  P_EEXIST = EEXIST,
55  P_EFAULT = EFAULT,
56  P_EFBIG = EFBIG,
57  P_EHOSTUNREACH = EHOSTUNREACH,
58  P_EIDRM = EIDRM,
59  P_EILSEQ = EILSEQ,
60  P_EINPROGRESS = EINPROGRESS,
61  P_EINTR = EINTR,
62  P_EINVAL = EINVAL,
63  P_EIO = EIO,
64  P_EISCONN = EISCONN,
65  P_EISDIR = EISDIR,
66  P_ELOOP = ELOOP,
67  P_EMFILE = EMFILE,
68  P_EMLINK = EMLINK,
69  P_EMSGSIZE = EMSGSIZE,
70  P_EMULTIHOP = EMULTIHOP,
71  P_ENAMETOOLONG = ENAMETOOLONG,
72  P_ENETDOWN = ENETDOWN,
73  P_ENETRESET = ENETRESET,
74  P_ENETUNREACH = ENETUNREACH,
75  P_ENFILE = ENFILE,
76  P_ENOBUFS = ENOBUFS,
77  P_ENODATA = ENODATA,
78  P_ENODEV = ENODEV,
79  P_ENOENT = ENOENT,
80  P_ENOEXEC = ENOEXEC,
81  P_ENOLCK = ENOLCK,
82  P_ENOLINK = ENOLINK,
83  P_ENOMEM = ENOMEM,
84  P_ENOMSG = ENOMSG,
85  P_ENOPROTOOPT = ENOPROTOOPT,
86  P_ENOSPC = ENOSPC,
87  P_ENOSR = ENOSR,
88  P_ENOSTR = ENOSTR,
89  P_ENOSYS = ENOSYS,
90  P_ENOTCONN = ENOTCONN,
91  P_ENOTDIR = ENOTDIR,
92  P_ENOTEMPTY = ENOTEMPTY,
93  P_ENOTRECOVERABLE = ENOTRECOVERABLE,
94  P_ENOTSOCK = ENOTSOCK,
95  P_ENOTSUP = ENOTSUP,
96  P_ENOTTY = ENOTTY,
97  P_ENXIO = ENXIO,
98  // P_EOPNOTSUPP: Linux aliases this. Use P_ENOTSUP instead.
99  P_EOVERFLOW = EOVERFLOW,
100  P_EOWNERDEAD = EOWNERDEAD,
101  P_EPERM = EPERM,
102  P_EPIPE = EPIPE,
103  P_EPROTO = EPROTO,
104  P_EPROTONOSUPPORT = EPROTONOSUPPORT,
105  P_EPROTOTYPE = EPROTOTYPE,
106  P_ERANGE = ERANGE,
107  P_EROFS = EROFS,
108  P_ESPIPE = ESPIPE,
109  P_ESRCH = ESRCH,
110  P_ESTALE = ESTALE,
111  P_ETIME = ETIME,
112  P_ETIMEDOUT = ETIMEDOUT,
113  P_ETXTBSY = ETXTBSY,
114  // P_EWOULDBLOCK: Linux aliases this. Use P_EAGAIN instead.
115  P_EXDEV = EXDEV
116 };
117 
118 /// Binds the PosixErrorSpace class to the PosixError enum.
120 
121 /// An implementation of the ErrorSpace interface for POSIX error codes.
123  public:
124  using code_type = PosixError;
125 
126  PosixErrorSpace(const PosixErrorSpace &other) = delete;
127  virtual ~PosixErrorSpace() = default;
128  PosixErrorSpace &operator=(const PosixErrorSpace &other) = delete;
129 
130  /// Gets the singleton instance of PosixErrorSpace.
131  /// \return The one instance of PosixErrorSpace.
132  static ErrorSpace const *GetInstance();
133 
134  private:
135  PosixErrorSpace();
136  GoogleError PosixToGoogle(PosixError code) const;
137 };
138 
139 } // namespace error
140 } // namespace asylo
141 
142 #endif // ASYLO_UTIL_POSIX_ERROR_SPACE_H_
PosixErrorSpace(const PosixErrorSpace &other)=delete
Definition: posix_error_space.h:73
Definition: posix_error_space.h:55
Definition: posix_error_space.h:106
Definition: posix_error_space.h:57
Definition: posix_error_space.h:64
Definition: posix_error_space.h:62
PosixErrorSpace & operator=(const PosixErrorSpace &other)=delete
Definition: posix_error_space.h:75
Definition: posix_error_space.h:92
Definition: posix_error_space.h:77
Definition: posix_error_space.h:41
Definition: posix_error_space.h:51
Definition: posix_error_space.h:100
PosixError
The enum associated with the POSIX error-space.
Definition: posix_error_space.h:34
Definition: posix_error_space.h:50
Definition: posix_error_space.h:63
Definition: posix_error_space.h:70
Definition: posix_error_space.h:43
Definition: posix_error_space.h:40
Definition: posix_error_space.h:52
Definition: posix_error_space.h:87
Definition: posix_error_space.h:95
Definition: posix_error_space.h:89
Definition: posix_error_space.h:93
Definition: posix_error_space.h:44
Definition: posix_error_space.h:36
Definition: posix_error_space.h:94
Definition: posix_error_space.h:74
Definition: posix_error_space.h:91
Definition: posix_error_space.h:97
Definition: posix_error_space.h:108
Definition: posix_error_space.h:48
Definition: posix_error_space.h:60
Definition: posix_error_space.h:109
Definition: posix_error_space.h:115
Definition: posix_error_space.h:59
virtual ~PosixErrorSpace()=default
Definition: posix_error_space.h:90
Definition: posix_error_space.h:46
Definition: posix_error_space.h:111
Definition: posix_error_space.h:58
Definition: posix_error_space.h:85
Definition: posix_error_space.h:39
Definition: posix_error_space.h:110
Definition: posix_error_space.h:83
Definition: posix_error_space.h:42
Definition: posix_error_space.h:102
Definition: posix_error_space.h:76
Definition: posix_error_space.h:107
Definition: posix_error_space.h:105
Definition: posix_error_space.h:82
Definition: posix_error_space.h:78
Definition: posix_error_space.h:35
Definition: posix_error_space.h:45
Definition: posix_error_space.h:84
Definition: posix_error_space.h:67
Definition: posix_error_space.h:101
Definition: posix_error_space.h:38
Definition: aes_gcm_siv.h:37
ErrorSpace const * GetErrorSpace(ErrorSpaceAdlTag< PosixError > tag)
Binds the PosixErrorSpace class to the PosixError enum.
Definition: posix_error_space.h:47
Definition: posix_error_space.h:79
Definition: posix_error_space.h:61
Definition: posix_error_space.h:96
Definition: posix_error_space.h:80
Definition: posix_error_space.h:53
Definition: posix_error_space.h:54
Definition: posix_error_space.h:104
Definition: posix_error_space.h:49
Definition: posix_error_space.h:65
Definition: posix_error_space.h:112
Definition: posix_error_space.h:56
Definition: posix_error_space.h:103
static ErrorSpace const * GetInstance()
Gets the singleton instance of PosixErrorSpace.
Definition: posix_error_space.h:81
Definition: posix_error_space.h:69
Definition: posix_error_space.h:86
Definition: posix_error_space.h:88
Definition: posix_error_space.h:71
Definition: posix_error_space.h:37
Definition: posix_error_space.h:99
Definition: posix_error_space.h:68
Definition: posix_error_space.h:72
Definition: posix_error_space.h:113
Definition: posix_error_space.h:66