{"id":106,"date":"2012-11-05T04:56:16","date_gmt":"2012-11-05T04:56:16","guid":{"rendered":"http:\/\/finaldie.com\/wordpress\/?p=106"},"modified":"2013-12-30T12:52:49","modified_gmt":"2013-12-30T12:52:49","slug":"valgrind-is-not-friendly-for-swapcontext","status":"publish","type":"post","link":"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/","title":{"rendered":"Valgrind is not friendly for swapcontext"},"content":{"rendered":"<p>Okie, long time no see &#8230; I write this only better for me to remember something what happend, something what I want to share.<\/p>\n<p>This is an experience what I&#8217;ve troubled, last week, when I tested my program about c-coroutine library, I found that a lot of critical informations in the output of valgrind. for example:<\/p>\n<pre>before switch\r\n==1897== Warning: client switching stacks?  SP change: 0x7ff0003f8 --&gt; 0x5716a58\r\n==1897==          to suppress, use: --max-stackframe=34251643296 or greater\r\n[in co1] arg=1\r\nbefore switch\r\n==1897== Warning: client switching stacks?  SP change: 0x57169f8 --&gt; 0x7ff000400\r\n==1897==          to suppress, use: --max-stackframe=34251643400 or greater\r\nafter switch\r\n[in main] after resume1 n1=10\r\nbefore switch\r\n==1897== Warning: client switching stacks?  SP change: 0x7ff0003f8 --&gt; 0x5716a00\r\n==1897==          to suppress, use: --max-stackframe=34251643384 or greater\r\n==1897==          further instances of this message will not be shown.\r\nafter switch\r\n[in co1] after yield n2=100\r\n[in co1] create co2\r\nbefore switch\r\n==1897== Invalid read of size 8\r\n==1897==    at 0x529D42C: swapcontext (swapcontext.S:94)\r\n==1897==    by 0x529F64F: ??? (in \/lib\/x86_64-linux-gnu\/libc-2.15.so)\r\n==1897==    by 0x561668F: ???\r\n==1897==  Address 0x5716bc0 is 128 bytes inside a block of size 1,049,704 alloc'd\r\n==1897==    at 0x4C2B3F8: malloc (in \/usr\/lib\/valgrind\/vgpreload_memcheck-amd64-linux.so)\r\n==1897==    by 0x4120D2: _fco_create (fco.c:134)\r\n==1897==    by 0x40AD98: test (t_fco.c:41)\r\n==1897==    by 0x412080: co_main (fco.c:217)\r\n==1897==    by 0x529F64F: ??? (in \/lib\/x86_64-linux-gnu\/libc-2.15.so)\r\n==1897==    by 0x41280A: tu_run_cases (tu_inc.c:67)\r\n==1897==    by 0x4024F2: main (main.c:33)<\/pre>\n<p>Here we can see &#8220;Invalid read of size 8&#8221; error, but after I make a deep dive, I found that there is a strange thing I have never seen that before: I read a valid memory which I actually alloc it, but valgrind prompt me something wrong in it. but when I swap from main thread context, the error has gone. Okie, so the root question is <strong>The\u00a0source and destination of swapcontext both are alloc from heap, the error will raise<\/strong>.<\/p>\n<p>For proving my point of view, we can see these lines:<\/p>\n<pre>==1897== Warning: client switching stacks?  SP change: 0x7ff0003f8 --&gt; 0x5716a58\r\n==1897==          to suppress, use: --max-stackframe=34251643296 or greater<\/pre>\n<p>When valgrind detect a switching action, we can see the warning at above, and when we swap to a new alloced context from a alloced context, we can&#8217;t see this warning instead of a Invalid read error, ok, I guess you understand what I&#8217;m talking about.<\/p>\n<p>I also found some links from internet, other people also meet this issue:<br \/>\n<a href=\"http:\/\/old.nabble.com\/Re:-Invalid-read-of-size-4-(fwd)-td118410.html\" target=\"_blank\">http:\/\/old.nabble.com\/Re:-Invalid-read-of-size-4-(fwd)-td118410.html<\/a><br \/>\n<a href=\"http:\/\/permalink.gmane.org\/gmane.comp.debugging.valgrind\/1702\" target=\"_blank\">http:\/\/permalink.gmane.org\/gmane.comp.debugging.valgrind\/1702<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Okie, long time no see &#8230; I write this only better for me to remember something what happend, something what I want to share. This is an experience what I&#8217;ve troubled, last week, when I tested my program about c-coroutine library, I found that a lot of critical informations in the output of valgrind. for &#8230; <a title=\"Valgrind is not friendly for swapcontext\" class=\"read-more\" href=\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/\" aria-label=\"More on Valgrind is not friendly for swapcontext\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Valgrind is not friendly for swapcontext - Final Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Valgrind is not friendly for swapcontext - Final Blog\" \/>\n<meta property=\"og:description\" content=\"Okie, long time no see &#8230; I write this only better for me to remember something what happend, something what I want to share. This is an experience what I&#8217;ve troubled, last week, when I tested my program about c-coroutine library, I found that a lot of critical informations in the output of valgrind. for ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/\" \/>\n<meta property=\"og:site_name\" content=\"Final Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hu.yuzhang\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-05T04:56:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-12-30T12:52:49+00:00\" \/>\n<meta name=\"author\" content=\"final\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hyzwowtools\" \/>\n<meta name=\"twitter:site\" content=\"@hyzwowtools\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"final\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/\",\"url\":\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/\",\"name\":\"Valgrind is not friendly for swapcontext - Final Blog\",\"isPartOf\":{\"@id\":\"https:\/\/finaldie.com\/blog\/#website\"},\"datePublished\":\"2012-11-05T04:56:16+00:00\",\"dateModified\":\"2013-12-30T12:52:49+00:00\",\"author\":{\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3\"},\"breadcrumb\":{\"@id\":\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/finaldie.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Valgrind is not friendly for swapcontext\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/finaldie.com\/blog\/#website\",\"url\":\"https:\/\/finaldie.com\/blog\/\",\"name\":\"Final Blog\",\"description\":\"As simple as possible...\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/finaldie.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3\",\"name\":\"final\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/finaldie.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g\",\"caption\":\"final\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Valgrind is not friendly for swapcontext - Final Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/","og_locale":"en_US","og_type":"article","og_title":"Valgrind is not friendly for swapcontext - Final Blog","og_description":"Okie, long time no see &#8230; I write this only better for me to remember something what happend, something what I want to share. This is an experience what I&#8217;ve troubled, last week, when I tested my program about c-coroutine library, I found that a lot of critical informations in the output of valgrind. for ... Read more","og_url":"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/","og_site_name":"Final Blog","article_publisher":"https:\/\/www.facebook.com\/hu.yuzhang","article_published_time":"2012-11-05T04:56:16+00:00","article_modified_time":"2013-12-30T12:52:49+00:00","author":"final","twitter_card":"summary_large_image","twitter_creator":"@hyzwowtools","twitter_site":"@hyzwowtools","twitter_misc":{"Written by":"final","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/","url":"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/","name":"Valgrind is not friendly for swapcontext - Final Blog","isPartOf":{"@id":"https:\/\/finaldie.com\/blog\/#website"},"datePublished":"2012-11-05T04:56:16+00:00","dateModified":"2013-12-30T12:52:49+00:00","author":{"@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3"},"breadcrumb":{"@id":"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/finaldie.com\/blog\/valgrind-is-not-friendly-for-swapcontext\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/finaldie.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Valgrind is not friendly for swapcontext"}]},{"@type":"WebSite","@id":"https:\/\/finaldie.com\/blog\/#website","url":"https:\/\/finaldie.com\/blog\/","name":"Final Blog","description":"As simple as possible...","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/finaldie.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/2d4c840d6e8e197f8ade98af2bd2fab3","name":"final","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/finaldie.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4c720545b79ddb0f23b527e0bbcfd9bc?s=96&r=g","caption":"final"}}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/106"}],"collection":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":5,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"predecessor-version":[{"id":197,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/posts\/106\/revisions\/197"}],"wp:attachment":[{"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/finaldie.com\/blog\/wp-json\/wp\/v2\/tags?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}