Hi Fabrizio,

Our port of muslc to seL4 is very minimal and does not implement errno - when 
it's accessed by a thread that thread will fault. If you are in debug mode and 
that thread does not have a fault handler, you'll see a double fault, where 
seL4 will print out the details of the fault. The kernel itself is still 
running, but just the idle thread.


With respect to setting up malloc, you can take a look at the sel4bench 
project, which bootstraps an allocator for the initial process here:

 
https://github.com/seL4/sel4bench/blob/5.2.x-compatible/apps/sel4bench/src/main.c#L301


and sets up allocators in other processes (the benchmark apps) here: 
https://github.com/seL4/sel4bench/blob/5.2.x-compatible/libsel4benchsupport/src/support.c#L373


The manifest for sel4bench can be found here: 
https://github.com/seL4/sel4bench-manifest/blob/master/5.2.x.xml


Note that both of these approaches are using a static malloc - where malloc is 
allocating memory from a fixed size array configured with 
CONFIG_LIB_SEL4_MUSLC_SYS_MORECORE_BYTES. It is possible to set up a dynamic 
pool backed by a virtual memory by setting this to value to 0.


We don't have an implementation that supports errno. You could map a page at 
the address muslc expects errno to be, or set up a fault handler for your 
thread that maps pages in.


I hope this addresses some of your questions!


Anna.


________________________________
From: Devel <[email protected]> on behalf of Fabrizio Bertocci 
<[email protected]>
Sent: Tuesday, 4 July 2017 11:57 PM
To: [email protected]
Subject: [seL4] malloc & errno

Hi all,
I am facing a puzzling problem related to muslc. While running some tests with 
the ia32 simulator (qemu), have noticed that whenever I call malloc() and I run 
out of memory (because my morecore buffer is too small), I am getting some 
kernel crash.
I have traced the issue to the place where errno is set to -ENOMEM. Referencing 
to errno is platform-dependent and end up calling a function that retrieve the 
struct pthread associated and access errno as one of the field of the struct 
pthread.

What is the correct process to set up a heap from the root task in such a way 
that we can call malloc() and correctly handle error conditions through errno?

I am pretty sure I am doing something wrong in my initialization code (I have 
based my main(0 on the code from the tutorials), because I am also having other 
problems with malloc(). (even after I increase my heap area).
For example, in some cases a call to malloc() end up calling a cascade of 
functions that eventually (from inside muslc) end up calling again malloc(). As 
consequence it enters in an infinite loop that stop only after it exhaust the 
initial stack.

I could not find any clear example that show how to correctly set up a system 
to use muslc.

Can anyone point me to a good example that shows how to bootstrap a system for 
the 5.2.0 branch?

Regards,
Fabrizio Bertocci
Real-Time Innovations, Inc.
Sunnyvale, CA

_______________________________________________
Devel mailing list
[email protected]
https://sel4.systems/lists/listinfo/devel

Reply via email to