Hi,
The following code is just not working
#define STACK_SIZE 1524
static void mt_allocate_stack(struct thread_struct *mythrd)
{
unsigned int sp = 0;
void *stck;
stck = (void *)malloc(STACK_SIZE);
/*
* get double word aligned SP -- stacks grow from high
* to low
*/
sp = (unsigned int)&((stck));
sp = sp + STACK_SIZE;
while((sp % 8) != 0)
sp--;
#ifdef linux
/*
* keep double word aligned but put in enough
* space to handle local variables for MtSched
*/
(mythrd->saved_state[0]).__jmpbuf[JB_BP] = (int)sp;
(mythrd->saved_state[0]).__jmpbuf[JB_SP] = (int)sp-500;
#endif
void mt_sched()
{
fprintf(stdout,"\n Inside the mt_sched");
fflush(stdout);
if ( setjmp(current_thread->saved_state) == 0 )
{
mt_allocate_stack(current_thread);
fprintf(stdout,"\n Jumping to thread = %u",current_thread->thread_id);
fflush(stdout);
longjmp(current_thread->saved_state, 2);
}
else
{
fprintf(stdout,"\n\n Calling the function = ");
fflush(stdout);
}
}
}
All I am doing here is saving a state and then allocating a new stack and storing the pointer in the saved state.
But the code seg faults at this is line
else
{
fprintf(stdout,"\n\n Calling the function = ");
fflush(stdout);
}
It does not matter what I put in this else statement it always segfaults.
Can somebody tell me why is that happening.
The following code is just not working
#define STACK_SIZE 1524
static void mt_allocate_stack(struct thread_struct *mythrd)
{
unsigned int sp = 0;
void *stck;
stck = (void *)malloc(STACK_SIZE);
/*
* get double word aligned SP -- stacks grow from high
* to low
*/
sp = (unsigned int)&((stck));
sp = sp + STACK_SIZE;
while((sp % 8) != 0)
sp--;
#ifdef linux
/*
* keep double word aligned but put in enough
* space to handle local variables for MtSched
*/
(mythrd->saved_state[0]).__jmpbuf[JB_BP] = (int)sp;
(mythrd->saved_state[0]).__jmpbuf[JB_SP] = (int)sp-500;
#endif
void mt_sched()
{
fprintf(stdout,"\n Inside the mt_sched");
fflush(stdout);
if ( setjmp(current_thread->saved_state) == 0 )
{
mt_allocate_stack(current_thread);
fprintf(stdout,"\n Jumping to thread = %u",current_thread->thread_id);
fflush(stdout);
longjmp(current_thread->saved_state, 2);
}
else
{
fprintf(stdout,"\n\n Calling the function = ");
fflush(stdout);
}
}
}
All I am doing here is saving a state and then allocating a new stack and storing the pointer in the saved state.
But the code seg faults at this is line
else
{
fprintf(stdout,"\n\n Calling the function = ");
fflush(stdout);
}
It does not matter what I put in this else statement it always segfaults.
Can somebody tell me why is that happening.