unresolved_external
unresolved_external

Reputation: 2018

How to fix SIGBUS on Solaris

I am using atomic_inc_64_nv on 64bit Solaris, returned value is casted to unsigned long. But when I run my app, it crashed and core is claming that the cause of the crash is SIGBUS. I Suspect there are could be alignment issues. How can I fix this problem?

Here is my function which uses increment

    inline unsigned long long Increment64(volatile unsigned long long * pullTarget)
    {
#if defined(LINUX)
        return Add64(pullTarget, 1ULL);
#elif defined(SOLARIS)
        return atomic_inc_64_nv((volatile unsigned long *)pullTarget) - 1ULL;
#elif defined(WIN32)
        return (unsigned long long)InterlockedIncrement64((LONGLONG volatile*)(pullTarget)) - 1ULL;
#endif // defined(LINUX)
    }

Thank you on advance.

Upvotes: 1

Views: 1127

Answers (2)

Matthew Lundberg
Matthew Lundberg

Reputation: 42679

As you have a core and have opened it in the debugger, now simply print the value contained in the variable pullTarget. (The pointer value itself, not what it points to.) You should see that it is not divisible by 8, as @MatsPetersson is correct on the cause.

Upvotes: 2

Mats Petersson
Mats Petersson

Reputation: 129464

Sparc processors do not support unaligned access. You need to make sure your pullTarget is aligned to 8 bytes. You can add some code like this to catch it:

if ((uint_ptr)pullTarget & 7) { printf("Alignment problem pullTarget = %p\n", pullTarget); }

Upvotes: 4

Related Questions