tls.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /****************************************************************************
  2. * arch/avr/include/tls.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __ARCH_AVR_INCLUDE_TLS_H
  21. #define __ARCH_AVR_INCLUDE_TLS_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <assert.h>
  27. #include <nuttx/arch.h>
  28. #include <nuttx/tls.h>
  29. /****************************************************************************
  30. * Inline Functions
  31. ****************************************************************************/
  32. /****************************************************************************
  33. * Name: up_tls_info
  34. *
  35. * Description:
  36. * Return the TLS information structure for the currently executing thread.
  37. * When TLS is enabled, up_createstack() will align allocated stacks to
  38. * the TLS_STACK_ALIGN value. An instance of the following structure will
  39. * be implicitly positioned at the "lower" end of the stack. Assuming a
  40. * "push down" stack, this is at the "far" end of the stack (and can be
  41. * clobbered if the stack overflows).
  42. *
  43. * If an MCU has a "push up" then that TLS structure will lie at the top
  44. * of the stack and stack allocation and initialization logic must take
  45. * care to preserve this structure content.
  46. *
  47. * The stack memory is fully accessible to user mode threads.
  48. *
  49. * Input Parameters:
  50. * None
  51. *
  52. * Returned Value:
  53. * A pointer to TLS info structure at the beginning of the STACK memory
  54. * allocation. This is essentially an application of the TLS_INFO(sp)
  55. * macro and has a platform dependency only in the manner in which the
  56. * stack pointer (sp) is obtained and interpreted.
  57. *
  58. ****************************************************************************/
  59. #ifdef CONFIG_TLS_ALIGNED
  60. static inline FAR struct tls_info_s *up_tls_info(void)
  61. {
  62. DEBUGASSERT(!up_interrupt_context());
  63. return TLS_INFO((uintptr_t)avr_getsp());
  64. }
  65. #else
  66. # define up_tls_info() tls_get_info()
  67. #endif
  68. #endif /* __ARCH_AVR_INCLUDE_TLS_H */