[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bugs-dist
Subject:    [valgrind] [Bug 306171] Boost.Context appears to cause Valgrind to crash
From:       Morten Bendiksen <morten.bendiksen () gmail ! com>
Date:       2014-06-05 15:02:53
Message-ID: bug-306171-17878-eJIgbPnKOJ () http ! bugs ! kde ! org/
[Download RAW message or body]

https://bugs.kde.org/show_bug.cgi?id=306171

Morten Bendiksen <morten.bendiksen@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |morten.bendiksen@gmail.com

--- Comment #7 from Morten Bendiksen <morten.bendiksen@gmail.com> ---
By making a stack allocator wrapper for boost couroutine, it worked for me. 

boost::coroutines::coroutine<void>::pull_type(
            [pro, this] (boost::coroutines::coroutine<void>::push_type&
new_push_ptr) {}, boost::coroutines::attributes(), valgrind_stack_allocator());

#ifdef HAVE_VALGRIND_H
#include <unordered_map>
#include <valgrind/valgrind.h>
#endif

// Wraps boost::coroutine::stack_allocator, and if Valgrind is installed
// will register stacks, so that Valgrind is not confused.
class valgrind_stack_allocator {
    boost::coroutines::stack_allocator allocator;
#ifdef HAVE_VALGRIND_H
    std::unordered_map<void*, unsigned> stack_ids;
#endif

public:
    static bool is_stack_unbound() {
        return boost::coroutines::stack_allocator::is_stack_unbound();
    }

    static std::size_t maximum_stacksize() {
        return boost::coroutines::stack_allocator::maximum_stacksize();
    }

    static std::size_t default_stacksize() {
        return boost::coroutines::stack_allocator::default_stacksize();
    }

    static std::size_t minimum_stacksize() {
        return boost::coroutines::stack_allocator::minimum_stacksize();
    }

    void allocate( boost::coroutines::stack_context & sc, std::size_t size) {
        allocator.allocate(sc, size);
#ifdef HAVE_VALGRIND_H
        auto res = stack_ids.insert(
            std::make_pair(
                sc.sp,
                VALGRIND_STACK_REGISTER(sc.sp, (((char*)sc.sp) - sc.size))));
        (void)res;
        assert(res.second);
#endif
    }

    void deallocate( boost::coroutines::stack_context & sc) {
#ifdef HAVE_VALGRIND_H
        auto id = stack_ids.find(sc.sp);
        assert(id != stack_ids.end());
        VALGRIND_STACK_DEREGISTER(id->second);
        stack_ids.erase(id);
#endif
        allocator.deallocate(sc);
    }
};

-- 
You are receiving this mail because:
You are watching all bug changes.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic