{"id":5493,"date":"2014-03-30T23:02:55","date_gmt":"2014-03-30T23:02:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-interpret-segment-register-accesses-on-x86-64-collection-of-common-programming-errors\/"},"modified":"2014-03-30T23:02:55","modified_gmt":"2014-03-30T23:02:55","slug":"how-to-interpret-segment-register-accesses-on-x86-64-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-interpret-segment-register-accesses-on-x86-64-collection-of-common-programming-errors\/","title":{"rendered":"How to interpret segment register accesses on x86-64?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m not sure they&#8217;ve been called <em>segment<\/em> register since the bad old days of segmented architecture. I believe the proper term is a selector (but I could be wrong).<\/p>\n<p>However, I think you just need at the first quadword (64 bits) in the <code>fs<\/code> area.<\/p>\n<p>The <code>%fs:0x0<\/code> bit means the contents of the memory at <code>fs:0<\/code>. Since you&#8217;ve used the generic <code>add<\/code> (rather than <code>addl<\/code> for example), I think it will take the data width from the target <code>%rax<\/code>.<\/p>\n<p>In terms of getting the actual value, it depends on whether you&#8217;re in legacy or long mode.<\/p>\n<p>In legacy mode, you&#8217;ll have to get the <code>fs<\/code> value and look it up in the GDT (or possibly LDT) in order to get the base address.<\/p>\n<p>In long mode, you&#8217;ll need to look at the relevant model specific registers. If you&#8217;re at this point, you&#8217;ve moved beyond my level of expertise unfortunately.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m not sure they&#8217;ve been called segment register since the bad old days of segmented architecture. I believe the proper term is a selector (but I could be wrong). However, I think you just need at the first quadword (64 bits) in the fs area. The %fs:0x0 bit means the contents of the memory at [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5493","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5493"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5493\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}