Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 40665
b: refs/heads/master
c: 53b1733
h: refs/heads/master
i:
  40663: aab061f
v: v3
  • Loading branch information
Jeff Dike authored and Linus Torvalds committed Nov 3, 2006
1 parent d9666cc commit 0dfc188
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d2c89a4284ea4ecfba77c6f2d7d6f96d52e801e5
refs/heads/master: 53b173327d283b9bdbfb0c3b6de6f0eb197819d6
9 changes: 9 additions & 0 deletions trunk/arch/um/include/sysdep-i386/barrier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __SYSDEP_I386_BARRIER_H
#define __SYSDEP_I386_BARRIER_H

/* Copied from include/asm-i386 for use by userspace. i386 has the option
* of using mfence, but I'm just using this, which works everywhere, for now.
*/
#define mb() asm volatile("lock; addl $0,0(%esp)")

#endif
7 changes: 7 additions & 0 deletions trunk/arch/um/include/sysdep-x86_64/barrier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __SYSDEP_X86_64_BARRIER_H
#define __SYSDEP_X86_64_BARRIER_H

/* Copied from include/asm-x86_64 for use by userspace. */
#define mb() asm volatile("mfence":::"memory")

#endif
31 changes: 28 additions & 3 deletions trunk/arch/um/os-Linux/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "user.h"
#include "signal_kern.h"
#include "sysdep/sigcontext.h"
#include "sysdep/barrier.h"
#include "sigcontext.h"
#include "mode.h"
#include "os.h"
Expand All @@ -34,8 +35,12 @@
#define SIGALRM_BIT 2
#define SIGALRM_MASK (1 << SIGALRM_BIT)

static int signals_enabled = 1;
static int pending = 0;
/* These are used by both the signal handlers and
* block/unblock_signals. I don't want modifications cached in a
* register - they must go straight to memory.
*/
static volatile int signals_enabled = 1;
static volatile int pending = 0;

void sig_handler(int sig, struct sigcontext *sc)
{
Expand Down Expand Up @@ -152,6 +157,12 @@ int change_sig(int signal, int on)
void block_signals(void)
{
signals_enabled = 0;
/* This must return with signals disabled, so this barrier
* ensures that writes are flushed out before the return.
* This might matter if gcc figures out how to inline this and
* decides to shuffle this code into the caller.
*/
mb();
}

void unblock_signals(void)
Expand All @@ -171,9 +182,23 @@ void unblock_signals(void)
*/
signals_enabled = 1;

/* Setting signals_enabled and reading pending must
* happen in this order.
*/
mb();

save_pending = pending;
if(save_pending == 0)
if(save_pending == 0){
/* This must return with signals enabled, so
* this barrier ensures that writes are
* flushed out before the return. This might
* matter if gcc figures out how to inline
* this (unlikely, given its size) and decides
* to shuffle this code into the caller.
*/
mb();
return;
}

pending = 0;

Expand Down

0 comments on commit 0dfc188

Please sign in to comment.