pt-machine.h 2.4 KB

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