X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=compat_arch_x86.c;h=7d3b83af3c3949049f84f95267df1eb48687e311;hp=fc504c3356c95808d05cc88f5eb3742c631bc9eb;hb=53a7719131ff381866fd414cdeff4ac3dd354927;hpb=bf9de1b724767a7b0d9f32385ed3ab8623aabb71 diff --git a/compat_arch_x86.c b/compat_arch_x86.c index fc504c3..7d3b83a 100644 --- a/compat_arch_x86.c +++ b/compat_arch_x86.c @@ -3,7 +3,7 @@ * * Userspace RCU library - x86 compatibility checks * - * Copyright (c) 2009 Mathieu Desnoyers + * Copyright (c) 2009 Mathieu Desnoyers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,21 +24,21 @@ #include #include #include -#include +#include /* * It does not really matter if the constructor is called before using - * the library, as long as the caller checks if __urcu_cas_avail < 0 and calls + * the library, as long as the caller checks if __rcu_cas_avail < 0 and calls * compat_arch_init() explicitely if needed. */ -int __attribute__((constructor)) __urcu_cas_init(void); +int __attribute__((constructor)) __rcu_cas_init(void); /* * -1: unknown * 1: available * 0: unavailable */ -int __urcu_cas_avail = -1; +int __rcu_cas_avail = -1; static pthread_mutex_t compat_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -80,9 +80,9 @@ static void mutex_lock_signal_save(pthread_mutex_t *mutex, sigset_t *oldmask) int ret; /* Disable signals */ - ret = sigemptyset(&newmask); + ret = sigfillset(&newmask); assert(!ret); - ret = pthread_sigmask(SIG_SETMASK, &newmask, oldmask); + ret = pthread_sigmask(SIG_BLOCK, &newmask, oldmask); assert(!ret); ret = pthread_mutex_lock(&compat_mutex); assert(!ret); @@ -122,10 +122,11 @@ unsigned long _compat_uatomic_set(void *addr, unsigned long _new, int len) * generate an illegal instruction. Cannot catch this with * linker tricks when optimizations are disabled. */ + result = 0; __asm__ __volatile__("ud2"); } mutex_lock_signal_restore(&compat_mutex, &mask); - return _new; + return result; } unsigned long _compat_uatomic_xchg(void *addr, unsigned long _new, int len) @@ -152,6 +153,7 @@ unsigned long _compat_uatomic_xchg(void *addr, unsigned long _new, int len) * generate an illegal instruction. Cannot catch this with * linker tricks when optimizations are disabled. */ + retval = 0; /* silence gcc warnings */ __asm__ __volatile__("ud2"); } mutex_lock_signal_restore(&compat_mutex, &mask); @@ -195,12 +197,63 @@ unsigned long _compat_uatomic_cmpxchg(void *addr, unsigned long old, * generate an illegal instruction. Cannot catch this with * linker tricks when optimizations are disabled. */ + retval = 0; /* silence gcc warnings */ __asm__ __volatile__("ud2"); } mutex_lock_signal_restore(&compat_mutex, &mask); return retval; } +void _compat_uatomic_or(void *addr, unsigned long v, int len) +{ + sigset_t mask; + + mutex_lock_signal_save(&compat_mutex, &mask); + switch (len) { + case 1: + *(unsigned char *)addr |= (unsigned char)v; + break; + case 2: + *(unsigned short *)addr |= (unsigned short)v; + break; + case 4: + *(unsigned int *)addr |= (unsigned int)v; + break; + default: + /* + * generate an illegal instruction. Cannot catch this with + * linker tricks when optimizations are disabled. + */ + __asm__ __volatile__("ud2"); + } + mutex_lock_signal_restore(&compat_mutex, &mask); +} + +void _compat_uatomic_and(void *addr, unsigned long v, int len) +{ + sigset_t mask; + + mutex_lock_signal_save(&compat_mutex, &mask); + switch (len) { + case 1: + *(unsigned char *)addr &= (unsigned char)v; + break; + case 2: + *(unsigned short *)addr &= (unsigned short)v; + break; + case 4: + *(unsigned int *)addr &= (unsigned int)v; + break; + default: + /* + * generate an illegal instruction. Cannot catch this with + * linker tricks when optimizations are disabled. + */ + __asm__ __volatile__("ud2"); + } + mutex_lock_signal_restore(&compat_mutex, &mask); +} + unsigned long _compat_uatomic_add_return(void *addr, unsigned long v, int len) { sigset_t mask; @@ -225,15 +278,16 @@ unsigned long _compat_uatomic_add_return(void *addr, unsigned long v, int len) * generate an illegal instruction. Cannot catch this with * linker tricks when optimizations are disabled. */ + result = 0; /* silence gcc warnings */ __asm__ __volatile__("ud2"); } mutex_lock_signal_restore(&compat_mutex, &mask); return result; } -int __urcu_cas_init(void) +int __rcu_cas_init(void) { - if (__urcu_cas_avail < 0) - __urcu_cas_avail = compare_and_swap_is_available(); - return __urcu_cas_avail; + if (__rcu_cas_avail < 0) + __rcu_cas_avail = compare_and_swap_is_available(); + return __rcu_cas_avail; }