<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Linuxoffset on bramp.net</title>
    <link>https://blog.bramp.net/</link>
    <description>Recent content in Linuxoffset on bramp.net</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-GB</language>
    <lastBuildDate>Sun, 11 Jan 2009 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.bramp.net/tags/linuxoffset/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>linuxoffsets for FreeBSD</title>
      <link>https://blog.bramp.net/post/2009/01/11/linuxoffsets-for-freebsd/</link>
      <pubDate>Sun, 11 Jan 2009 00:00:00 +0000</pubDate>
      
      <guid>https://blog.bramp.net/post/2009/01/11/linuxoffsets-for-freebsd/</guid>
      <description><p>VMWare 6 and above has this neat debugging functionality where you can attach gdb running on a host, to a guest running inside VMWare. This allows you to debug a running kernel, or on linux running processes.</p>
<p>However, VMWare seems to have coded a bit of a hack to allow gdb to understand what process/threads are inside the virtual machine. Now this hack involves using something called linuxoffsets, which provides the offset for certain fields in a linux kernel struct.</p>
<p>So I thought I could abuse these offsets, and hopefully make them work for FreeBSD. The Linux offsets are:</p>















<table class="table">
  <thead>
      <tr>
          <th></th>
          <th>Linux Values</th>
          <th>FreeBSD 7.1 Values</th>
          <th>Notes</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>&lt;version&gt;</td>
          <td></td>
          <td></td>
          <td>Version number of linux kernel, ie 0x020609 (2.6.9)</td>
      </tr>
      <tr>
          <td>&lt;mm&gt;</td>
          <td>task_struct-&gt;mm</td>
          <td></td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;next_task&gt;</td>
          <td>task_struct-&gt;next_task (linux &lt; 2.4.15)</td>
          <td>struct proc-&gt;p_list-&gt;le_next</td>
          <td>Pointer to next task struct</td>
      </tr>
      <tr>
          <td>&lt;tasks&gt;</td>
          <td>task_struct-&gt;tasks (linux &gt;= 2.4.15)</td>
          <td>0</td>
          <td>Pointers to prev and next task struct</td>
      </tr>
      <tr>
          <td>&lt;comm&gt;</td>
          <td>task_struct-&gt;comm</td>
          <td>struct proc-&gt;p_comm</td>
          <td>executable name</td>
      </tr>
      <tr>
          <td>&lt;pid&gt;</td>
          <td>task_struct-&gt;pid</td>
          <td>struct proc-&gt;p_pid</td>
          <td>pid of the process</td>
      </tr>
      <tr>
          <td>&lt;thread&gt;</td>
          <td>task_struct-&gt;thread</td>
          <td></td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;pgd&gt;</td>
          <td>mm_struct-&gt;pgd</td>
          <td></td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;rsp0/esp0&gt;</td>
          <td>thread_struct-&gt;rsp0 (or thread_struct-&gt;esp0 32bit)</td>
          <td>struct thread-&gt;td_sigstk-&gt;ss_sp</td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;fs&gt;</td>
          <td>thread_struct-&gt;fs</td>
          <td></td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;threadsize&gt;</td>
          <td>0x2000 or sizeof(union thread_union-&gt;stack) (linux &gt;= 2.6)</td>
          <td></td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;grouplead&gt;</td>
          <td>task_struct-&gt;group_leader (linux &gt;= 2.6.11)</td>
          <td>0</td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;threadgroup&gt;</td>
          <td>task_struct-&gt;thread_group (linux &gt;= 2.6.11)</td>
          <td>0</td>
          <td></td>
      </tr>
      <tr>
          <td>&lt;commsize&gt;</td>
          <td>sizeof(struct task_struct-&gt;comm)</td>
          <td>sizeof(struct proc-&gt;p_comm)</td>
          <td>executable name’s max len</td>
      </tr>
  </tbody>
</table>

<p>However, after some time I feel this isn’t going to be possible. Each value represents a offset into a Linux task_struct struct, however, nothing represents the location of the first task_struct in RAM. I suspect VMWare is figuring out the location via some other means. Since FreeBSD doesn’t have a task_struct it most likely won’t be able to find what it needs.</p>
<p>Regardless I’ve posted this entry in case someone wants to continue my work. However, not all is lost as my next solution involves playing with gdb-python.</p>
</description>
    </item>
    
  </channel>
</rss>
