Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:45:22+00:00 2026-05-26T22:45:22+00:00

When I run my program, I get segmentation fault, so I decided to check

  • 0

When I run my program, I get segmentation fault, so I decided to check it through Valgrind. When I did, I got the following message from Valgrind. And I get the error when I use the code described here. Any idea what is going on here?

==21471== Invalid write of size 8
==21471==    at 0x4802511: _vgnU_freeres (vg_preloaded.c:64)
==21471==    by 0x38A715397F: ???
==21471==    by 0x38A6E4D549: printf (in /lib64/libc-2.5.so)
==21471==    by 0x401D52: call_func(int) (replication.cpp:752)
==21471==    by 0x6137C7: ???
==21471==    by 0x40621C: AdvanceFramesMT(void*) (pthreads.cpp:1020)
==21471==    by 0x38A7A0673C: start_thread (in /lib64/libpthread-2.5.so)
==21471==    by 0x38A6ED44BC: clone (in /lib64/libc-2.5.so)
==21471==  Address 0x612ba8 is 14216 bytes inside data symbol "func_stack"

Code

static char func_stack[16384];
static ucontext_t uctx_main[16], uctx_func[16];

void call_func( int n )
{
    printf( "Message %d!", n );
}

 if (getcontext(&uctx_func[tid]) == -1)
        handle_error("getcontext");
 uctx_func[tid].uc_stack.ss_sp = func_stack;
 uctx_func[tid].uc_stack.ss_size = sizeof(func_stack);
 uctx_func[tid].uc_link = &uctx_main[tid];
 makecontext(&uctx_func[tid], (void(*)())call_func, 1, 2);

 if (swapcontext(&uctx_main[tid], &uctx_func[tid]) == -1)
    handle_error("swapcontext");  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:45:23+00:00Added an answer on May 26, 2026 at 10:45 pm

    OK, I got it now. Actually I was using this for multiple threads. That is why uctx_main[16] and uctx_func[16] are arrays. However, I forgot to make func_stack also an array (a 2-dimensional array in fact). So I changed it to char func_stack[16][16384] and it solved the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error when I run a java program: Exception in thread
I am receiving a Segmentation Fault error when I run this program. To summarize,
I get Segmentation Fault when I try to run my program. Can someone please
Trying to run a C++ program , I get segmentation faults which appear to
When I run my program I get this error nullPointerException: null. import model.*; import
My c++ program gives me a seg fault when I run as root from
I'm using the method 'pthread_create' in my program, and get a segmentation fault INSIDE
Whenever I run my program, I get: NullReferenceException was unhandled, Object Reference not set
I have an application which get copied and run on client machines. The program
How should I run another program from within my C program? I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.