kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: mulyadi.santosa@gmail.com (Mulyadi Santosa)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Identifying whether a user-process or kernel-thread execution takes place by looking at CPU registers
Date: Thu, 12 May 2011 18:53:07 +0700	[thread overview]
Message-ID: <BANLkTinfr5U4iBqLzhFsxcGETfFXd6cpiw@mail.gmail.com> (raw)
In-Reply-To: <SNT111-DS7BDB0FA73ABADDE23481CA7890@phx.gbl>

Hi....

On Thu, May 12, 2011 at 17:55, limp <johnkyr83@hotmail.com> wrote:
> I was wondering if any other CPU register (apart from CR3) can indicate if a
> user-process or a kernel thread under it (and which one) is executed. Is it
> possible to know such a thing *only* by looking at CPU registers?

one thing you can use is by looking at so called CPL (Current
Privilege level) and check it whether it is 0. According to
http://en.wikipedia.org/wiki/X86_memory_segmentation, CPL is the lower
2 bits in CS.

However, you need to watch it continously, because user space apps
could switch to CPL=0 (which denotes kernel mode, where CPL=3 denotes
user mode) in the case of system call etc.

perhaps better is by looking at the address of mm. However, to do
this, you need to check starting from its task_struct, which is mapped
in its kernel stack in x86 AFAIK. In other arch such as ARM, AFAIK
task_struct could be simply derived from certain register.
-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

  reply	other threads:[~2011-05-12 11:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-12 10:55 Identifying whether a user-process or kernel-thread execution takes place by looking at CPU registers limp
2011-05-12 11:53 ` Mulyadi Santosa [this message]
2011-05-13  1:55   ` Dave Hylands
2011-05-14 17:55     ` limp
2011-05-14 19:12       ` Dave Hylands

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=BANLkTinfr5U4iBqLzhFsxcGETfFXd6cpiw@mail.gmail.com \
    --to=mulyadi.santosa@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).