123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- register char * stack_pointer __asm__ ("%rsp") __attribute_used__;
- PT_EI long int
- testandset (int *spinlock)
- {
- long int ret;
- __asm__ __volatile__ (
- "xchgl %k0, %1"
- : "=r"(ret), "=m"(*spinlock)
- : "0"(1), "m"(*spinlock)
- : "memory");
- return ret;
- }
- PT_EI int
- __compare_and_swap (long int *p, long int oldval, long int newval)
- {
- char ret;
- long int readval;
- __asm__ __volatile__ ("lock; cmpxchgq %3, %1; sete %0"
- : "=q" (ret), "=m" (*p), "=a" (readval)
- : "r" (newval), "m" (*p), "a" (oldval)
- : "memory");
- return ret;
- }
- ({ \
- register pthread_descr __self; \
- __asm__ ("movq %%fs:%c1,%0" : "=r" (__self) \
- : "i" (offsetof (struct _pthread_descr_struct, \
- p_header.data.self))); \
- __self; \
- })
- extern int arch_prctl (int __code, unsigned long __addr);
- { \
- if (arch_prctl (ARCH_SET_FS, (unsigned long)descr) != 0) \
- abort (); \
- }
- ({ \
- __typeof__ (descr->member) __value; \
- if (sizeof (__value) == 1) \
- __asm__ __volatile__ ("movb %%fs:%P2,%b0" \
- : "=q" (__value) \
- : "0" (0), \
- "i" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else if (sizeof (__value) == 4) \
- __asm__ __volatile__ ("movl %%fs:%P2,%k0" \
- : "=r" (__value) \
- : "0" (0), \
- "i" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else \
- { \
- if (sizeof (__value) != 8) \
- \
- abort (); \
- \
- __asm__ __volatile__ ("movq %%fs:%P1,%0" \
- : "=r" (__value) \
- : "i" (offsetof (struct _pthread_descr_struct, \
- member))); \
- } \
- __value; \
- })
- ({ \
- __typeof__ (descr->member) __value; \
- if (sizeof (__value) == 1) \
- __asm__ __volatile__ ("movb %%fs:(%2),%b0" \
- : "=q" (__value) \
- : "0" (0), \
- "r" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else if (sizeof (__value) == 4) \
- __asm__ __volatile__ ("movl %%fs:(%2),%k0" \
- : "=r" (__value) \
- : "0" (0), \
- "r" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else \
- { \
- if (sizeof (__value) != 8) \
- \
- abort (); \
- \
- __asm__ __volatile__ ("movq %%fs:(%1),%0" \
- : "=r" (__value) \
- : "r" (offsetof (struct _pthread_descr_struct, \
- member))); \
- } \
- __value; \
- })
- ({ \
- __typeof__ (descr->member) __value = (value); \
- if (sizeof (__value) == 1) \
- __asm__ __volatile__ ("movb %0,%%fs:%P1" : \
- : "q" (__value), \
- "i" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else if (sizeof (__value) == 4) \
- __asm__ __volatile__ ("movl %k0,%%fs:%P1" : \
- : "r" (__value), \
- "i" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else \
- { \
- if (sizeof (__value) != 8) \
- \
- abort (); \
- \
- __asm__ __volatile__ ("movq %0,%%fs:%P1" : \
- : "r" (__value), \
- "i" (offsetof (struct _pthread_descr_struct, \
- member))); \
- } \
- })
- ({ \
- __typeof__ (descr->member) __value = (value); \
- if (sizeof (__value) == 1) \
- __asm__ __volatile__ ("movb %0,%%fs:(%1)" : \
- : "q" (__value), \
- "r" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else if (sizeof (__value) == 4) \
- __asm__ __volatile__ ("movl %k0,%%fs:(%1)" : \
- : "r" (__value), \
- "r" (offsetof (struct _pthread_descr_struct, \
- member))); \
- else \
- { \
- if (sizeof (__value) != 8) \
- \
- abort (); \
- \
- __asm__ __volatile__ ("movq %0,%%fs:(%1)" : \
- : "r" (__value), \
- "r" (offsetof (struct _pthread_descr_struct, \
- member))); \
- } \
- })
|