All of lore.kernel.org
 help / color / mirror / Atom feed
From: harryxiyou@gmail.com (harryxiyou)
To: kernelnewbies@lists.kernelnewbies.org
Subject: [RFC]Something wrong with my module
Date: Fri, 13 Apr 2012 23:00:19 +0800	[thread overview]
Message-ID: <CAD+1EGOwo-z6dAO_rrmFZQuLO9nS_3t5ECiMxc2RWFAQfvaJCw@mail.gmail.com> (raw)
In-Reply-To: <20120412143355.GB1874@debian.debian>

On Thu, Apr 12, 2012 at 10:33 PM, Jonathan Neusch?fer
<j.neuschaefer@gmx.net> wrote:

Hi Jonathan

> On Thu, Apr 12, 2012 at 09:52:02PM +0800, harryxiyou wrote:
>> On Thu, Apr 12, 2012 at 9:03 PM, Jonathan Neusch?fer
>> <j.neuschaefer@gmx.net> wrote:
>>
>> Hi Jonathan,
>>
[...]
>>
>> I give the pid 8, state 8, and comm "jiawei" in my module. But it can
>> not print correctly. Maybe kernel can tell my bogus one,right?
>
> This has to do with the way accessing struct fields works in C:
> For each struct each field name is translated by the compiler into an
> offset which is used to compute the address of a field given the struct's
> address. When you access the pid field of a struct task_struct the offset
> will be at least around 20 * sizeof(int), which is an invalid offset to
> your struct pcb, where the offsets are (most of the time):
> ? ? ? ?pid: 0
> ? ? ? ?state: sizeof(int)
> ? ? ? ?flag: 2 * sizeof(int)
> ? ? ? ?comm: 3 * sizeof(int)
> ? ? ? ?tasks: 3 * sizeof(int) + sizeof(char *)
> (You get (an approximation of) the offset of a field by adding the size
> ?of the previous field (the compiler also adds some padding - see
> ?Documentation/unaligned-memory-access.txt in the kernel tree and
> ?http://en.wikipedia.org/wiki/Data_padding#Data_structure_padding))
>

It sounds well. I will test it, which delare a structure named 'pcb'
but including
all the fileds as task_struct structure.

Thanks
Harry Wei

      reply	other threads:[~2012-04-13 15:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12 10:16 [RFC]Something wrong with my module harryxiyou
2012-04-12 11:18 ` Kristof Provost
2012-04-12 13:40   ` harryxiyou
2012-04-12 13:59   ` Frank Ch. Eigler
2012-04-12 14:04     ` harryxiyou
2012-04-12 14:08       ` harryxiyou
2012-04-12 14:45         ` Kristof Provost
2012-04-12 13:03 ` Jonathan Neuschäfer
2012-04-12 13:52   ` harryxiyou
2012-04-12 14:33     ` Jonathan Neuschäfer
2012-04-13 15:00       ` harryxiyou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAD+1EGOwo-z6dAO_rrmFZQuLO9nS_3t5ECiMxc2RWFAQfvaJCw@mail.gmail.com \
    --to=harryxiyou@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.