pal_error.c 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (C) 2014 Stony Brook University
  2. This file is part of Graphene Library OS.
  3. Graphene Library OS is free software: you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public License
  5. as published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. Graphene Library OS is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include "pal_error.h"
  14. struct pal_error_description {
  15. int error;
  16. const char* description;
  17. };
  18. static const struct pal_error_description pal_error_list[] = {
  19. {PAL_ERROR_SUCCESS, "Success"},
  20. {PAL_ERROR_NOTIMPLEMENTED, "Function not implemented"},
  21. {PAL_ERROR_NOTDEFINED, "Symbol not defined"},
  22. {PAL_ERROR_NOTSUPPORT, "Function not supported"},
  23. {PAL_ERROR_INVAL, "Invalid argument"},
  24. {PAL_ERROR_TOOLONG, "Name/path is too long"},
  25. {PAL_ERROR_DENIED, "Operation denied"},
  26. {PAL_ERROR_BADHANDLE, "Handle corrupted"},
  27. {PAL_ERROR_STREAMEXIST, "Stream already exists"},
  28. {PAL_ERROR_STREAMNOTEXIST, "Stream does not exist"},
  29. {PAL_ERROR_STREAMISFILE, "Stream is a file"},
  30. {PAL_ERROR_STREAMISDIR, "Stream is a directory"},
  31. {PAL_ERROR_STREAMISDEVICE, "Stream is a device"},
  32. {PAL_ERROR_INTERRUPTED, "Operation interrupted"},
  33. {PAL_ERROR_OVERFLOW, "Buffer overflowed"},
  34. {PAL_ERROR_BADADDR, "Invalid address"},
  35. {PAL_ERROR_NOMEM, "Not enough memory"},
  36. {PAL_ERROR_NOTKILLABLE, "Thread state unkillable"},
  37. {PAL_ERROR_INCONSIST, "Inconsistent system state"},
  38. {PAL_ERROR_TRYAGAIN, "Try again"},
  39. {PAL_ERROR_ENDOFSTREAM, "End of stream"},
  40. {PAL_ERROR_NOTSERVER, "Not a server"},
  41. {PAL_ERROR_NOTCONNECTION, "Not a connection"},
  42. {PAL_ERROR_CONNFAILED, "Connection failed"},
  43. {PAL_ERROR_ADDRNOTEXIST, "Resource address does not exist"},
  44. {PAL_ERROR_AFNOSUPPORT, "Address family not supported by protocol"},
  45. {PAL_ERROR_CRYPTO_FEATURE_UNAVAILABLE, "[Crypto] Feature not available"},
  46. {PAL_ERROR_CRYPTO_INVALID_CONTEXT, "[Crypto] Invalid context"},
  47. {PAL_ERROR_CRYPTO_INVALID_KEY_LENGTH, "[Crypto] Invalid key length"},
  48. {PAL_ERROR_CRYPTO_INVALID_INPUT_LENGTH, "[Crypto] Invalid input length"},
  49. {PAL_ERROR_CRYPTO_INVALID_OUTPUT_LENGTH, "[Crypto] Invalid output length"},
  50. {PAL_ERROR_CRYPTO_BAD_INPUT_DATA, "[Crypto] Bad input parameters"},
  51. {PAL_ERROR_CRYPTO_INVALID_PADDING, "[Crypto] Invalid padding"},
  52. {PAL_ERROR_CRYPTO_DATA_MISALIGNED, "[Crypto] Data misaligned"},
  53. {PAL_ERROR_CRYPTO_INVALID_FORMAT, "[Crypto] Invalid data format"},
  54. {PAL_ERROR_CRYPTO_AUTH_FAILED, "[Crypto] Authentication failed"},
  55. {PAL_ERROR_CRYPTO_IO_ERROR, "[Crypto] I/O error"},
  56. {PAL_ERROR_CRYPTO_KEY_GEN_FAILED, "[Crypto] Key generation failed"},
  57. {PAL_ERROR_CRYPTO_INVALID_KEY, "[Crypto] Invalid key"},
  58. {PAL_ERROR_CRYPTO_VERIFY_FAILED, "[Crypto] Verification failed"},
  59. {PAL_ERROR_CRYPTO_RNG_FAILED, "[Crypto] RNG failed to generate data"},
  60. {PAL_ERROR_CRYPTO_INVALID_DH_STATE, "[Crypto] Invalid DH state"},
  61. };
  62. #define PAL_ERROR_COUNT (sizeof(pal_error_list) / sizeof(pal_error_list[0]))
  63. const char* pal_strerror(int err) {
  64. for (size_t i = 0; i < PAL_ERROR_COUNT; i++)
  65. if (pal_error_list[i].error == err)
  66. return pal_error_list[i].description;
  67. return "Unknown error";
  68. }