[haiku-development] Re: debugging memory allocations

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 05 Jul 2010 17:46:08 +0200

On 2010-07-05 at 16:20:03 [+0200], Lucian Adrian Grijincu 
<lucian.grijincu@xxxxxxxxx> wrote:
> 
> I'm having some problems regarding the Haiku+LKL interaction.
> 
> 
> == Question ==
> 
> How can I debug memory layout problems from the KDL console?
> I'd like to find out the access rights for kernel pages.

ATM there's no command that tells you exactly how a virtual page is mapped. 
I've been wanting to add such a command for some time, but somehow never 
got to it. The "page" command can provide you with information that will 
probably suffice for your purpose. Usage is "page -v -m <address>". If the 
virtual address ("-v") is mapped to a physical memory page, the management 
information for page is printed including "all mappings" for this page 
("-m"). There you'll also find with what permissions the page is mapped and 
whether it is modified or accessed.

You can also use "area <address>" to print information on the area (for 
userland addresses: all areas) the address lies in. This also includes the 
(high level) protection flags in numeric form, so you'll have to compare 
manually with the B_[KERNEL_]{READ,WRITE,EXECUTE}_AREA flags. Kernel 
code/data areas are usually locked into memory upon creation, meaning that, 
unless something went wrong in the lower layers later, all pages in it will 
be mapped with the respective permissions.

> == Problem ==
> LKL boots the Linux kernel and is able to correctly free it's
> resources when it is unloaded.
> 
> I managed to mount/unmount an EXT4 partition and list the files in
> it's root directory (just a silly test to see that things really
> work).
> 
> However I've reached a problem: after loading/unloading a few times
> the Linux kernel and mounting/unmounting the same partition a few
> times during the Hiaku boot process, I sometimes get a page fault that
> says that the instruction at address 0x80234e09 (an example) cannot
> access the memory at address 0x80234e09 (the kernel wants to run some
> code, but cannot execute that code).
> 
> I guess this can happen in cases where the code misses execution
> permissions (as I've said in a previous email I had to hack into
> Haiku's add-on loader to accommodate a combined .text+.data section as
> with LKL) or when the code was unmapped from memory.

More likely the latter, since we don't support non-executable mapping on 
any hardware yet.

> The instruction is only sometimes from lkl. It happened a few times
> while in what should be normal performing Haiku code.
> 
> An illustrative example: it once happened while executing the x86
> 'halt' asm instruction (on the idle cpu thread).

That sounds somewhat weird. Particularly that you know what instruction it 
was while the kernel failed to execute it.

CU, Ingo

Other related posts: