alt_errno.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef __ALT_ERRNO_H__
  2. #define __ALT_ERRNO_H__
  3. /******************************************************************************
  4. * *
  5. * License Agreement *
  6. * *
  7. * Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
  8. * All rights reserved. *
  9. * *
  10. * Permission is hereby granted, free of charge, to any person obtaining a *
  11. * copy of this software and associated documentation files (the "Software"), *
  12. * to deal in the Software without restriction, including without limitation *
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  14. * and/or sell copies of the Software, and to permit persons to whom the *
  15. * Software is furnished to do so, subject to the following conditions: *
  16. * *
  17. * The above copyright notice and this permission notice shall be included in *
  18. * all copies or substantial portions of the Software. *
  19. * *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
  26. * DEALINGS IN THE SOFTWARE. *
  27. * *
  28. * This agreement shall be governed in all respects by the laws of the State *
  29. * of California and by the laws of the United States of America. *
  30. * *
  31. * Altera does not recommend, suggest or require that this reference design *
  32. * file be used in conjunction or combination with any other product. *
  33. ******************************************************************************/
  34. /******************************************************************************
  35. * *
  36. * THIS IS A LIBRARY READ-ONLY SOURCE FILE. DO NOT EDIT. *
  37. * *
  38. ******************************************************************************/
  39. /*
  40. * errno is defined in <errno.h> so that it uses the thread local version
  41. * stored in the location pointed to by "_impure_ptr". This means that the
  42. * accesses to errno within the HAL library can cause the entirety of
  43. * of the structure pointed to by "_impure_ptr" to be added to the
  44. * users application. This can be undesirable in very small footprint systems.
  45. *
  46. * To avoid this happening, the HAL uses the macro ALT_ERRNO, defined below,
  47. * to access errno, rather than accessing it directly. This macro will only
  48. * use the thread local version if some other code has already caused it to be
  49. * included into the system, otherwise it will use the global errno value.
  50. *
  51. * This causes a slight increases in code size where errno is accessed, but
  52. * can lead to significant overall benefits in very small systems. The
  53. * increase is inconsequential when compared to the size of the structure
  54. * pointed to by _impure_ptr.
  55. *
  56. * Note that this macro accesses __errno() using an externally declared
  57. * function pointer (alt_errno). This is done so that the function call uses the
  58. * subroutine call instruction via a register rather than an immediate address.
  59. * This is important in the case that the code has been linked for a high
  60. * address, but __errno() is not being used. In this case the weak linkage
  61. * would have resulted in the instruction: "call 0" which would fail to link.
  62. */
  63. extern int* (*alt_errno) (void);
  64. /* Must define this so that values such as EBADFD are defined in errno.h. */
  65. #define __LINUX_ERRNO_EXTENSIONS__
  66. #include <errno.h>
  67. #include "alt_types.h"
  68. #undef errno
  69. extern int errno;
  70. static ALT_INLINE int* alt_get_errno(void)
  71. {
  72. return ((alt_errno) ? alt_errno() : &errno);
  73. }
  74. #define ALT_ERRNO *alt_get_errno()
  75. #endif /* __ALT_ERRNO_H__ */