X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=compat_arch_x86.c;h=7d3b83af3c3949049f84f95267df1eb48687e311;hp=41c6848fae195cfbc6e24837a4445d3ddbd02f88;hb=94e710926b323933ec9ab76fb4fcc4cec2bcb1ed;hpb=02be55611d3b1c7bf4fdfcb3a9c98f621882d417 diff --git a/compat_arch_x86.c b/compat_arch_x86.c index 41c6848..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,7 +24,7 @@ #include #include #include -#include +#include /* * It does not really matter if the constructor is called before using @@ -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,6 +278,7 @@ 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);