Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Seg fault?: (10 Items)
   
Seg fault?  
Ok, so I hacked a set of VxWorks headers together and got the application library I want compiled.  I have linked the 
library and the vx2qnx library into an executable which I am now running on a QNX machine.

The problem is that I am getting seg faults on weird function calls.  I'm attaching a screen shot.  Any ideas?  This one
 is on a simple semaphore call.
Attachment: Image segFault.jpg 115.73 KB
Re: Seg fault?  
Sorry for the delayed response, 

these functions are functions inside (com_* etc) the vx works to qnx lib. Can you post some more of the code that is 
linking against the vx2qnx lib? What sort of header changes did you need to make to get to this point? 

shiv
RE: Seg fault?  
Lots of header changes to the VxWorks stuff.  It was pretty nasty, which
is why I posted my question on the forum - if there were clean ones that
everyone knows would work, I'd use those.

 

Here is an example - this is the code that is causing the segfault:

 

STATUS MTelemetryHandler::registerHandler( MTelemetryHandler * This )

{

      MTelemetryHandler* cur = first;

 

      // Create the mutex semaphore if this is the first handler

      taskLock();

      if (first == NULL)

            protect = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE

                        | SEM_INVERSION_SAFE);

      taskUnlock();

 

      // Take the mutex

      semTake (protect, WAIT_FOREVER);

 

      // Go until we find an entry point

      This->prev = NULL;

      This->next = first;

      while ((cur != NULL) && (cur->this_rank <= This->this_rank))

      {

            This->prev = cur;

            cur = cur->next;

            This->next = cur;

      }

 

....

 

 

The first call to taskLock() is what gives the seg fault.  I compiled
the vx2qnx lib with the source that came in the archive with debug
symbols, where the error is occurring in the library is shown in the
following screen cap.

 

 

 

 

 

As you can see in the call stack, I'm a couple of calls deep in the init
stuff of my application.

 

This help?

 

M

 

 

-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
Sent: Tuesday, December 08, 2009 10:38 AM
To: general-proj1116
Subject: Re: Seg fault?

 

Sorry for the delayed response, 

 

these functions are functions inside (com_* etc) the vx works to qnx
lib. Can you post some more of the code that is linking against the
vx2qnx lib? What sort of header changes did you need to make to get to
this point? 

 

shiv

 

 

 

_______________________________________________

 

General

http://community.qnx.com/sf/go/post43366

 

Attachment: Image image001.png 153.1 KB
Re: RE: Seg fault?  
One initial guess - might this have something to do with static initialization, and static constructors in C++?
Re: RE: Seg fault?  
Its possible. How early does this taskLock get invoked? Since it fails
on the first call to taskLock, does this first call occur very early
during program start?

thanks
shiv
Tue Dec  8 11:04:45 EST 2009

 --> According to Mike Medved <--
	One initial guess - might this have something to do with static
	initialization, and static constructors in C++?
	
	
	
	_______________________________________________
	
	General
	http://community.qnx.com/sf/go/post43369
	

-- 
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****
RE: RE: Seg fault?  
It is pretty early - I instantiate an ACME in main, and that is when it
happens:

int main(int argc, char* argv[]) {
    int status = 0;
    if(OXF::initialize(argc, argv, 6423, "192.168.132.1"))
        {
            Acme * p_Acme;
            p_Acme = new Acme;
            p_Acme->startBehavior();
            //#[ configuration DefaultComponent::DefaultConfig 
            //#]
            OXF::start();
            delete p_Acme;
            status = 0;
        }
    Else
....


But, by then, I would guess that statically constructed stuff would be
there already.

What is causing the seg fault is that my_tcb is null. So, obviously when
it derefs it, we are going to have problems.  The function taskLock()
which calls the __vx... func looks like this:

STATUS taskLock(void) {
	WIND_TCB			*tcb = GET_OUR_WIND_TCB();

	__vx2qnx_schedlockout(tcb, 0);
	return OK;
}

And GET_OUR_WIND_TCB is :
#define GET_OUR_WIND_TCB() \
	      (WIND_TCB *)pthread_getspecific(__vx2qnx_tcb_key)

In vx2qnx_common.h.  so the tcb pointer is null... thoughts?

-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
Sent: Tuesday, December 08, 2009 10:59 AM
To: general-proj1116
Subject: Re: RE: Seg fault?

Its possible. How early does this taskLock get invoked? Since it fails
on the first call to taskLock, does this first call occur very early
during program start?

thanks
shiv
Tue Dec  8 11:04:45 EST 2009

 --> According to Mike Medved <--
	One initial guess - might this have something to do with static
	initialization, and static constructors in C++?
	
	
	
	_______________________________________________
	
	General
	http://community.qnx.com/sf/go/post43369
	

-- 
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****



_______________________________________________

General
http://community.qnx.com/sf/go/post43370
Re: Seg fault?  
In the crash, do we know what the values of my_tcb was? (its the
argument to the function, __vx2qnx_sched_lockout

Would you be able to provide a core file, with statically linked
executable with symbols?.. so I can look at it in the debugger?

shiv
Tue Dec  8 11:09:21 EST 2009
 --> According to Mike Medved <--
	Lots of header changes to the VxWorks stuff.  It was pretty nasty, which
	is why I posted my question on the forum - if there were clean ones that
	everyone knows would work, I'd use those.
	
	 
	
	Here is an example - this is the code that is causing the segfault:
	
	 
	
	STATUS MTelemetryHandler::registerHandler( MTelemetryHandler * This )
	
	{
	
	      MTelemetryHandler* cur = first;
	
	 
	
	      // Create the mutex semaphore if this is the first handler
	
	      taskLock();
	
	      if (first == NULL)
	
	            protect = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE
	
	                        | SEM_INVERSION_SAFE);
	
	      taskUnlock();
	
	 
	
	      // Take the mutex
	
	      semTake (protect, WAIT_FOREVER);
	
	 
	
	      // Go until we find an entry point
	
	      This->prev = NULL;
	
	      This->next = first;
	
	      while ((cur != NULL) && (cur->this_rank <= This->this_rank))
	
	      {
	
	            This->prev = cur;
	
	            cur = cur->next;
	
	            This->next = cur;
	
	      }
	
	 
	
	....
	
	 
	
	 
	
	The first call to taskLock() is what gives the seg fault.  I compiled
	the vx2qnx lib with the source that came in the archive with debug
	symbols, where the error is occurring in the library is shown in the
	following screen cap.
	
	 
	
	 
	
	 
	
	 
	
	 
	
	As you can see in the call stack, I'm a couple of calls deep in the init
	stuff of my application.
	
	 
	
	This help?
	
	 
	
	M
	
	 
	
	 
	
	-----Original Message-----
	From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
	Sent: Tuesday, December 08, 2009 10:38 AM
	To: general-proj1116
	Subject: Re: Seg fault?
	
	 
	
	Sorry for the delayed response, 
	
	 
	
	these functions are functions inside (com_* etc) the vx works to qnx
	lib. Can you post some more of the code that is linking against the
	vx2qnx lib? What sort of header changes did you need to make to get to
	this point? 
	
	 
	
	shiv
	
	 
	
	 
	
	 
	
	_______________________________________________
	
	 
	
	General
	
	http://community.qnx.com/sf/go/post43366
	
	 
	
	
	
	
	
	_______________________________________________
	
	General
	http://community.qnx.com/sf/go/post43368



-- 
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****
RE: Seg fault?  
I statically linked the library, I'm not sure what a core file is... if
you explain, I'm sure I've got it/ can get it.

M

-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
Sent: Tuesday, December 08, 2009 11:04 AM
To: general-proj1116
Subject: Re: Seg fault?

In the crash, do we know what the values of my_tcb was? (its the
argument to the function, __vx2qnx_sched_lockout

Would you be able to provide a core file, with statically linked
executable with symbols?.. so I can look at it in the debugger?

shiv
Tue Dec  8 11:09:21 EST 2009
 --> According to Mike Medved <--
	Lots of header changes to the VxWorks stuff.  It was pretty
nasty, which
	is why I posted my question on the forum - if there were clean
ones that
	everyone knows would work, I'd use those.
	
	 
	
	Here is an example - this is the code that is causing the
segfault:
	
	 
	
	STATUS MTelemetryHandler::registerHandler( MTelemetryHandler *
This )
	
	{
	
	      MTelemetryHandler* cur = first;
	
	 
	
	      // Create the mutex semaphore if this is the first handler
	
	      taskLock();
	
	      if (first == NULL)
	
	            protect = semMCreate (SEM_Q_PRIORITY |
SEM_DELETE_SAFE
	
	                        | SEM_INVERSION_SAFE);
	
	      taskUnlock();
	
	 
	
	      // Take the mutex
	
	      semTake (protect, WAIT_FOREVER);
	
	 
	
	      // Go until we find an entry point
	
	      This->prev = NULL;
	
	      This->next = first;
	
	      while ((cur != NULL) && (cur->this_rank <=
This->this_rank))
	
	      {
	
	            This->prev = cur;
	
	            cur = cur->next;
	
	            This->next = cur;
	
	      }
	
	 
	
	....
	
	 
	
	 
	
	The first call to taskLock() is what gives the seg fault.  I
compiled
	the vx2qnx lib with the source that came in the archive with
debug
	symbols, where the error is occurring in the library is shown in
the
	following screen cap.
	
	 
	
	 
	
	 
	
	 
	
	 
	
	As you can see in the call stack, I'm a couple of calls deep in
the init
	stuff of my application.
	
	 
	
	This help?
	
	 
	
	M
	
	 
	
	 
	
	-----Original Message-----
	From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
	Sent: Tuesday, December 08, 2009 10:38 AM
	To: general-proj1116
	Subject: Re: Seg fault?
	
	 
	
	Sorry for the delayed response, 
	
	 
	
	these functions are functions inside (com_* etc) the vx works to
qnx
	lib. Can you post some more of the code that is linking against
the
	vx2qnx lib? What sort of header changes did you need to make to
get to
	this point? 
	
	 
	
	shiv
	
	 
	
	 
	
	 
	
	_______________________________________________
	
	 
	
	General
	
	http://community.qnx.com/sf/go/post43366
	
	 
	
	
	
	
	
	_______________________________________________
	
	General
	http://community.qnx.com/sf/go/post43368



-- 
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****



_______________________________________________

General
http://community.qnx.com/sf/go/post43372
Re: Seg fault?  
just curious do you create any tasks? 
or do u call kernelInit or usrInit any where in your code?

the only way I see the tcb being null, is if it is called from a qnx
thread, that is not a "vx works task"

shiv
Tue Dec  8 13:33:50 EST 2009

 --> According to Mike Medved <--
	I statically linked the library, I'm not sure what a core file is... if
	you explain, I'm sure I've got it/ can get it.
	
	M
	
	-----Original Message-----
	From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
	Sent: Tuesday, December 08, 2009 11:04 AM
	To: general-proj1116
	Subject: Re: Seg fault?
	
	In the crash, do we know what the values of my_tcb was? (its the
	argument to the function, __vx2qnx_sched_lockout
	
	Would you be able to provide a core file, with statically linked
	executable with symbols?.. so I can look at it in the debugger?
	
	shiv
	Tue Dec  8 11:09:21 EST 2009
	 --> According to Mike Medved <--
		Lots of header changes to the VxWorks stuff.  It was pretty
	nasty, which
		is why I posted my question on the forum - if there were clean
	ones that
		everyone knows would work, I'd use those.
		
		 
		
		Here is an example - this is the code that is causing the
	segfault:
		
		 
		
		STATUS MTelemetryHandler::registerHandler( MTelemetryHandler *
	This )
		
		{
		
		      MTelemetryHandler* cur = first;
		
		 
		
		      // Create the mutex semaphore if this is the first handler
		
		      taskLock();
		
		      if (first == NULL)
		
		            protect = semMCreate (SEM_Q_PRIORITY |
	SEM_DELETE_SAFE
		
		                        | SEM_INVERSION_SAFE);
		
		      taskUnlock();
		
		 
		
		      // Take the mutex
		
		      semTake (protect, WAIT_FOREVER);
		
		 
		
		      // Go until we find an entry point
		
		      This->prev = NULL;
		
		      This->next = first;
		
		      while ((cur != NULL) && (cur->this_rank <=
	This->this_rank))
		
		      {
		
		            This->prev = cur;
		
		            cur = cur->next;
		
		            This->next = cur;
		
		      }
		
		 
		
		....
		
		 
		
		 
		
		The first call to taskLock() is what gives the seg fault.  I
	compiled
		the vx2qnx lib with the source that came in the archive with
	debug
		symbols, where the error is occurring in the library is shown in
	the
		following screen cap.
		
		 
		
		 
		
		 
		
		 
		
		 
		
		As you can see in the call stack, I'm a couple of calls deep in
	the init
		stuff of my application.
		
		 
		
		This help?
		
		 
		
		M
		
		 
		
		 
		
		-----Original Message-----
		From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
		Sent: Tuesday, December 08, 2009 10:38 AM
		To: general-proj1116
		Subject: Re: Seg fault?
		
		 
		
		Sorry for the delayed response, 
		
		 
		
		these functions are functions inside (com_* etc) the vx works to
	qnx
		lib. Can you post some more of the code that is linking against
	the
		vx2qnx lib? What sort of header changes did you need to make to
	get to
		this point? 
		
		 
		
		shiv
		
		 
		
		 
		
		 
		
		_______________________________________________
		
		 
		
		General
		
		http://community.qnx.com/sf/go/post43366
		
		 
		
		
		
		
		
		_______________________________________________
		
		General
		http://community.qnx.com/sf/go/post43368
	
	
	
	-- 
	****
	Shiv Nagarajan,
	Kernel Developer, QNX Software Systems,
	Ottawa, Canada
	****
	
	
	
	_______________________________________________
	
	General
	http://community.qnx.com/sf/go/post43372
	
	
	
	
	_______________________________________________
	
	General
	http://community.qnx.com/sf/go/post43373
	

-- 
****
Shiv Nagarajan,
Kernel Developer, QNX Software Systems,
Ottawa, Canada
****
RE: Seg fault?  
So, yeah, what I had to do was call usrInit from my QNX main task, then
use spawnTask to spin off a VxWorks task and get that stuff rolling.
Appears to have fixed the problem...

M

-----Original Message-----
From: Shiv Nagarajan [mailto:community-noreply@qnx.com] 
Sent: Tuesday, December 08, 2009 1:28 PM
To: general-proj1116
Subject: Re: Seg fault?

just curious do you create any tasks? 
or do u call kernelInit or usrInit any where in your code?

the only way I see the tcb being null, is if it is called from a qnx
thread, that is not a "vx works task"

shiv
Tue Dec  8 13:33:50 EST 2009