1/* 2 * Copyright 2016, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(D61_BSD) 11 */ 12 13#ifndef _REFOS_ERROR_H_ 14#define _REFOS_ERROR_H_ 15 16/* Include Kconfig variables. */ 17#include <autoconf.h> 18 19/*! @file 20 @brief RefOS Error codes. 21 22 Shared error codes for RefOS methods. 23*/ 24 25enum refos_error { 26 /*! @brief There was no error. */ 27 ESUCCESS = 0, 28 29 /*! @brief Ran out of heap, cslots or untyped memory. */ 30 ENOMEM, 31 32 /*! @brief An internal error occured with the service. */ 33 EINVALID, 34 35 /*! @brief The given client capability is invalid. */ 36 EUNKNOWNCLIENT, 37 38 /*! @brief A given parameter was invalid. */ 39 EINVALIDPARAM, 40 41 /*! @brief The server name was not found by the naming service. */ 42 ESERVERNOTFOUND, 43 44 /*! @brief The given window capability is invalid. */ 45 EINVALIDWINDOW, 46 47 /*! @brief The server is currently unavailable; try again later. */ 48 ESERVICEUNAVAILABLE, 49 50 /*! @brief Insufficient permission for the requested operation. */ 51 EACCESSDENIED, 52 53 /*! @brief Occurs when a pager service tries to map a frame where there already is one. */ 54 EUNMAPFIRST, 55 56 /*! @brief The file name was not found on the dataspace server. */ 57 EFILENOTFOUND, 58 59 /*! @brief End of file was reached. */ 60 EENDOFFILE, 61 62 /*! @brief The device was not found on the system. */ 63 EDEVICENOTFOUND, 64 65 /*! @brief The operation requires access to the param buffer but no param buffer exists */ 66 ENOPARAMBUFFER, 67 68 /*! @brief This feature has not been implemented. */ 69 EUNIMPLEMENTED, 70 71 /*! @brief Request has been delegated to another server. */ 72 EDELEGATED 73}; 74 75#ifndef __defined_err_t__ 76 typedef enum refos_error refos_err_t; 77 #define __defined_err_t__ 78#endif 79 80/*! @brief Helper function which returns the associated string with a RefOS error number. Useful for 81 printing debugging information. 82 @param err The RefOS error. 83 @return Static string containing the error variable enum name. (No ownership transfer) 84*/ 85static inline const char* 86refos_error_str(refos_err_t err) 87{ 88 switch (err) { 89 case ESUCCESS: 90 return "ESUCCESS"; 91 case ENOMEM: 92 return "ENOMEM"; 93 case EINVALID: 94 return "EINVALID"; 95 case EUNKNOWNCLIENT: 96 return "EUNKNOWNCLIENT"; 97 case EINVALIDPARAM: 98 return "EINVALIDPARAM"; 99 case ESERVERNOTFOUND: 100 return "ESERVERNOTFOUND"; 101 case EINVALIDWINDOW: 102 return "EINVALIDWINDOW"; 103 case ESERVICEUNAVAILABLE: 104 return "ESERVICEUNAVAILABLE"; 105 case EACCESSDENIED: 106 return "EACCESSDENIED"; 107 case EUNMAPFIRST: 108 return "EUNMAPFIRST"; 109 case EFILENOTFOUND: 110 return "EFILENOTFOUND"; 111 case EENDOFFILE: 112 return "EENDOFFILE"; 113 case EDEVICENOTFOUND: 114 return "EDEVICENOTFOUND"; 115 case ENOPARAMBUFFER: 116 return "ENOPARAMBUFFER"; 117 case EUNIMPLEMENTED: 118 return "EUNIMPLEMENTED"; 119 case EDELEGATED: 120 return "EDELEGATED"; 121 default: 122 return "EUNKNOWNERROR"; 123 } 124 return (const char*) 0; 125} 126 127#include <sel4/errors.h> 128 129/*! @brief Helper function to return the enum name string associated with a seL4 error. 130 @param sel4err The seL4 error number. 131 @return Static str containing the string name of the given error code. (No ownership transfer) 132*/ 133static inline const char* 134seL4_error_str(int sel4err) 135{ 136 switch (sel4err) { 137 case seL4_NoError: 138 return "seL4_NoError"; 139 case seL4_InvalidArgument: 140 return "seL4_InvalidArgument"; 141 case seL4_InvalidCapability: 142 return "seL4_InvalidCapability"; 143 case seL4_IllegalOperation: 144 return "seL4_IllegalOperation"; 145 case seL4_RangeError: 146 return "seL4_RangeError"; 147 case seL4_AlignmentError: 148 return "seL4_AlignmentError"; 149 case seL4_FailedLookup: 150 return "seL4_FailedLookup"; 151 case seL4_TruncatedMessage: 152 return "seL4_TruncatedMessage"; 153 case seL4_DeleteFirst: 154 return "seL4_DeleteFirst"; 155 case seL4_RevokeFirst: 156 return "seL4_RevokeFirst"; 157 case seL4_NotEnoughMemory: 158 return "seL4_NotEnoughMemory"; 159 default: 160 return "Unknown seL4 Error."; 161 } 162}; 163 164extern refos_err_t _refos_errno; 165 166#if CONFIG_REFOS_HALT_ON_ERRNO 167 #define REFOS_SET_ERRNO(x) _refos_errno = x; if (_refos_errno != ESUCCESS) \ 168 {\ 169 printf("REFOS call generated error in file %s line %d", __FILE__, __LINE__);\ 170 assert(!"Halt because REFOS_HALT_ON_ERRNO is enabled.");\ 171 while(1);\ 172 } 173 #define REFOS_GET_ERRNO() (_refos_errno) 174#else 175 #define REFOS_SET_ERRNO(x) (_refos_errno = x) 176 #define REFOS_GET_ERRNO() (_refos_errno) 177#endif 178#define ROS_ERRNO REFOS_GET_ERRNO 179#define ROS_SET_ERRNO REFOS_SET_ERRNO 180 181#endif /* _REFOS_ERROR_H_ */ 182