pt-machine.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #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 inline __attribute__ ((always_inline))
  25. # endif
  26. extern long int testandset (int *spinlock);
  27. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  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 */