pt-machine.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # define PT_EI __extern_always_inline
  26. # endif
  27. /* Get some notion of the current stack. Need not be exactly the top
  28. of the stack, just something somewhere in the current frame. */
  29. # define CURRENT_STACK_FRAME stack_pointer
  30. register char * stack_pointer __asm__ ("%rsp") __attribute_used__;
  31. /* Spinlock implementation; required. */
  32. PT_EI long int
  33. testandset (int *__spinlock)
  34. {
  35. long int ret;
  36. __asm__ __volatile__ (
  37. "xchgl %k0, %1"
  38. : "=r"(ret), "=m"(*__spinlock)
  39. : "0"(1), "m"(*__spinlock)
  40. : "memory");
  41. return ret;
  42. }
  43. /* Compare-and-swap for semaphores. */
  44. # define HAS_COMPARE_AND_SWAP
  45. PT_EI int
  46. __compare_and_swap (long int *__p, long int __oldval, long int __newval)
  47. {
  48. char ret;
  49. long int readval;
  50. __asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
  51. : "=q" (ret), "=m" (*__p), "=a" (readval)
  52. : "r" (__newval), "m" (*__p), "a" (__oldval)
  53. : "memory");
  54. return ret;
  55. }
  56. #endif /* !__ASSEMBLER__ */
  57. /* We want the OS to assign stack addresses. */
  58. #define FLOATING_STACKS 1
  59. /* Maximum size of the stack if the rlimit is unlimited. */
  60. #define ARCH_STACK_MAX_SIZE 32*1024*1024
  61. /* The ia32e really want some help to prevent overheating. */
  62. #define BUSY_WAIT_NOP __asm__ ("rep; nop")
  63. #endif /* pt-machine.h */