tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: swapcontext() vs pthread bug



Emmanuel Dreyfus <manu%netbsd.org@localhost> wrote:

> I am now convinced NetBSD swapcontext() behavior is buggy. Below is a test
> case that shows how swapcontext() can make two different threads report the
> same pthread_self() while both are running:

There is a simple, userland-based, machine-dependent workaround that
fixes everything: unset a flag from ucontext_t uc_flags

Here is the target switch in kernel for cpu_mcontext() from
src/sys/arch/i386/i386/machdep.c 

        if ((flags & _UC_TLSBASE) != 0)
                lwp_setprivate(l, (void *)(uintptr_t)mcp->_mc_tlsbase);

Here is how to use it rom userland for our supported CPU:

amd64, arm, hppa, i386, m68k, mips:
        ctx.uc_flags &= ~_UC_TLSBASE;
alpha:
        ctx.uc_flags &= ~_UC_UNIQUE;
sh3, sparc, sparc64, vax:
        The behavior is bad and cannot be changed
powerpc: 
        The behavior is good and cannot be changed (to be verified)


What about creating a machine independant flag for amd64, arm, hppa,
i386, m68k, mips and alpha? sh3, sparc, sparc64, vax, and powerpc should
be changed to make the behavior configurable, but this is beyond what I
can do.

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index