pt-machine.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. x86-64 version.
  3. Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #ifndef _PT_MACHINE_H
  18. #define _PT_MACHINE_H 1
  19. #include <features.h>
  20. #ifndef __ASSEMBLER__
  21. # include <stddef.h> /* For offsetof. */
  22. # include <stdlib.h> /* For abort(). */
  23. # include <asm/prctl.h>
  24. # ifndef PT_EI
  25. # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  26. # define PT_EI static inline __attribute__((always_inline))
  27. # else
  28. # define PT_EI extern inline __attribute__((always_inline))
  29. # endif
  30. # endif
  31. /* Get some notion of the current stack. Need not be exactly the top
  32. of the stack, just something somewhere in the current frame. */
  33. # define CURRENT_STACK_FRAME stack_pointer
  34. register char * stack_pointer __asm__ ("%rsp") __attribute_used__;
  35. /* Spinlock implementation; required. */
  36. PT_EI long int
  37. testandset (int *__spinlock)
  38. {
  39. long int ret;
  40. __asm__ __volatile__ (
  41. "xchgl %k0, %1"
  42. : "=r"(ret), "=m"(*__spinlock)
  43. : "0"(1), "m"(*__spinlock)
  44. : "memory");
  45. return ret;
  46. }
  47. /* Compare-and-swap for semaphores. */
  48. # define HAS_COMPARE_AND_SWAP
  49. PT_EI int
  50. __compare_and_swap (long int *__p, long int __oldval, long int __newval)
  51. {
  52. char ret;
  53. long int readval;
  54. __asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
  55. : "=q" (ret), "=m" (*__p), "=a" (readval)
  56. : "r" (__newval), "m" (*__p), "a" (__oldval)
  57. : "memory");
  58. return ret;
  59. }
  60. #endif /* !__ASSEMBLER__ */
  61. /* We want the OS to assign stack addresses. */
  62. #define FLOATING_STACKS 1
  63. /* Maximum size of the stack if the rlimit is unlimited. */
  64. #define ARCH_STACK_MAX_SIZE 32*1024*1024
  65. /* The ia32e really want some help to prevent overheating. */
  66. #define BUSY_WAIT_NOP __asm__ ("rep; nop")
  67. #endif /* pt-machine.h */