본문 바로가기

Programming

x86 CR3 register

CR3 레지스터가 페이지 디렉토리를 가리킨다고해서 커널모듈상에서 그 값을 인라인 어셈블리로 찍어보니 모듈을 올릴때마다 다르게 나왔다.

어찌된 영문인지 알아보다가 아래의 문서를 찾았다. 즉 커널모듈은 insmod 나 ioctl 등, 그 모듈을 호출하는 유저프로세스의 context 를 가지고 수행되기때문에, 모듈상에서 찍은 CR3 는 유저프로세스의 CR3 가 찍히는 것이고, 이건 제각각 매번 다르게 나오는것임.

 

그리고 CR0 레지스터는 상관없이 언제나 일정한듯.

0x8005003B

 

이렇게 찍히는데 MSB 1은 페이징활성화를 의미하고 LSB 1은 protected mode 를 의미. 나머지 비트들도 다 제각각 의미가 있음

write back 캐싱을 할지말지, 등등등.

 

 

 

Does cr3 register change when a new process is scheduled ?

Let us suppose we are talking about a uni processor system. Do we
change cr3 page directory control register when a new process is
scheduled to run on the CPU.

thanks.
George
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
George Kumar [ Do, 15 Januar 2009 03:33 ] [ ID #1984927 ]

Re: Does cr3 register change when a new process is scheduled ?

yes, every process running will have a different CR3 value....easily
seen when u printk() the value from different kernel module....and the
kernel module is running in the same process context as the "insmod"
that started the kernel module....so u can see the process name is
"insmod" if u printk() the value of the process name. ie, user +
kernel mode all shared the same CR3 value, but different process will
have different value.

On Thu, Jan 15, 2009 at 10:33 AM, George Kumar <grgkumar4 [at] gmail.com> wrote:
> Let us suppose we are talking about a uni processor system. Do we
> change cr3 page directory control register when a new process is
> scheduled to run on the CPU.
>
> thanks.
> George
> --

-- 
Regards,
Peter Teoh
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo [at] vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Peter Teoh [ Do, 15 Januar 2009 03:43 ] [ ID #1984928 ]

Re: Does cr3 register change when a new process is scheduled ?

On 2009-01-15, Peter Teoh <htmldeveloper [at] gmail.com> wrote:
> yes, every process running will have a different CR3 value....easily
> seen when u printk() the value from different kernel module....and the
> kernel module is running in the same process context as the "insmod"
> that started the kernel module....so u can see the process name is
> "insmod" if u printk() the value of the process name. ie, user +
Not exactly, module is not a process. It is just some functions registered
into the kernel space. You see the process name is "insmod" is because that
you put your printk statement in the module initialization function. You
execute insmod to call the initialization function, so the module's init
function is in "insmod" process context. If you execute other command to
call ioctl to the module, and then the module is executed in other process
context.

Jeffrey

 

'Programming' 카테고리의 다른 글

Linux x86 system call table  (0) 2013.07.10
Finding symbol in libc  (0) 2013.07.10
x86 assembly 16bit prefix  (0) 2013.07.10
FreeBSD system call table  (0) 2013.07.10
Kernel module compile example  (0) 2013.07.08