kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: fs.rajat@gmail.com (Rajat Sharma)
To: kernelnewbies@lists.kernelnewbies.org
Subject: System call question
Date: Sat, 11 Jun 2011 13:01:24 +0530	[thread overview]
Message-ID: <BANLkTi=m4xUES7-Ljtzf8_22+LhMN+siEA@mail.gmail.com> (raw)
In-Reply-To: <859929.9001.qm@web137606.mail.in.yahoo.com>

sys_call_table is the array of system call handlers (function
pointers). The syntax is how you typically access an array in GAS.
%eax i.e. EAX register holder the system call number which inturn is
index into this array. since size of pointer on 32 bit platform is 4
bytes, thats why you give 4 as last argument. So, you multiply 4 with
%eax to reach at exact function pointer and then deference that
pointer with a * (i.e. like value at operator in C) and call the
system call handler function.

Formally it is called indexed memory addressing and syntax is like:

base_address(offset_address, index, size)

The data value retrieved is located at

base_address + offset_address + index * size

here in this example base_address is address of sys_call_table,
offset_address is skipped so it defaults to zero. offset address tells
you where to start your search in array, typically its not used. index
is %eax and size is 4.

I recommend "Professional Assembly Language" book by Richard Blum from
Wrox publication.

Thanks,
Rajat
On Sat, Jun 11, 2011 at 1:05 AM, Naman shekhar Mishra
<namanshekharmishra2@yahoo.in> wrote:
> Platform: x86 32 bit
> system_call() ,afetr doing some checks, looks up in the sys_call_table and
> finds the correct address of the system call and jumps to it. i.e.:
> call *sys_call_table(,%eax,4)
>
> Can you please explain this syntax to me. I think 'call' is the processor
> instruction which works on a function name.
> * is used in gas syntax to denote that the address following it is to be
> used as the jumping address. Tell me if I m wrong so far.
> () is used to index a memory location(GAS syntax again, I think). Please
> explain to me (,%eax,4). I have trouble understanding this syntax.
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>

      reply	other threads:[~2011-06-11  7:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-10 19:35 System call question Naman shekhar Mishra
2011-06-11  7:31 ` Rajat Sharma [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='BANLkTi=m4xUES7-Ljtzf8_22+LhMN+siEA@mail.gmail.com' \
    --to=fs.rajat@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).