[okl4-developer] Questions about pd_ref and roottask pagefault

Yang Xi Yang.Xi at nicta.com.au
Tue Apr 15 17:37:54 EST 2008



On Tue, 15 Apr 2008 16:11:21 +1000, Nelson Tam <nelson at ok-labs.com> wrote:
> Hi Yang,
> 
> On 09/04/2008, at 5:05 PM, yangxi wrote:
>>
>> Yesterday, I re-installed UBUNTU to my laptop, with the same toolchain
>> but there is a roottask pagefault. When I copy the build system to
>> paulaner and compile it, the roottask disappear.
>>
>> I figure out the reason is that in function get_pd(iguana_server.c),
>> there is the_pd = (struct pd *)(pd_ref & ~IID_MASK). But the return
>> value of pd_create(malloc in it) function is not always align on 8
>> bytes
>> bound. For example it return 0x80027824 for struct pd *. So the get_pd
>> will return the NULL and the pd_ext_l4_space(_pd) does not check
>> whether
>> it is NULL and read the address of _pd->extension. After I change
>> the_pd
>> = (struct pd*)(pd_ref), there is no page fault.
>>
>> My question is
>> 1)What is the function of (struct pd *)(pd_ref &~IID_MASK), what is
>> the
>> function of the low 3 bits of pd_ref?
>> 2)If iguana use the low three bits for other security function, why
>> malloc will return a pointer not align on 8 bytes?
> 
> Each objref_t returned by Iguana should be aligned to 8 bytes.  As
> you've correctly noted, the last 3 bits of each objref_t is used to
> represent the rwx permissions on the object.  That's why pd and thread
> objects in Iguana are not malloc()'ed, but allocated from a pool of
> free structures.
I solved this problem by change the __initial_heap(sys_morecore.c), I add the __attribute__((aligned(8))) to the Header __initial_heap[0x10000/sizeof(Header)]. In the k_r_malloc.h you declare the union header to
union header{
     struct {
              union header *ptr:
              unsigned size;
             }s;
     Align x;
};
Yeah, the ALign is "long long",it wants gcc puts the Header __initial_heap to 8bytes align. If the __initial_heap is 8bytes align then every thing get from it will be 8 bytes align, unfortunately, in my laptop gcc does not do it like that. So I have to add the __attribute__((aligned(8))) to keep it 8 bytes align.
> 
> Can you please confirm whether there is a malloc() in pd_create()?
> There shouldn't be one if you're using the 1.5 public release.
> --
Yeah, I use 1.5, pd_create()->pd_list_create_back()->dl_list_create_back()->malloc()->Get the memory from the __initial_heap, bu the __initial_heap not 8 byte align.

I think the gcc will not align on the 8 bytes default.
> (nt)
> 
> Nelson Tam
> 
> 
> 




More information about the Developer mailing list