Hello L4 hackers, I hope you are all doing well today.
I am hoping to discuss the topic of threads to better my understanding of it, as it seems to be a major building block in L4Re. I have the following questions (using the c++ based libraries.):
1. Is Pthread the official way to create threads in an L4Re application?
2. I have made a L4 thread (to understand how threads work in L4) without the help of pthreads by setting up the Attr, which involved in setting the exception handlers(using rm()), pager (using rm()), instruction pointers, stack pointers, binding, ex_reg() and finally running. All seems well until I try printing a message. It seems seems I am unable to use the printf() function in the instruction pointer function of said thread. The error I get is : ttest | l4re_itas[rm]: unhandled read page fault at 0x141 pc=0x100f8a0 ttest | l4re_itas: rom/thread_test: Unhandled exception: PC=0x100f8a0 PFA=0x140 LdrFlgs=0x0 However, if I use printf in a pthread, none of these errors pop up. 2a. Am I using the wrong exception handler and pager (I got both from rm)? 2b. Also, the "l4_vcon_send(L4_BASE_LOG_CAP,..,...) function seems to work fine in either case, shouldn't printf() eventually call this function as after a series of indirections? 2c. What exc_handler and pager do pthreads use? Why are they able to handle the pager faults and exceptions from printf? Can I appropriate them for the L4 threads I started?
3. It seems the Virtual Machines (VMs) that are on the hypervisor are also closely related with threads. I assume these are Vcpu threads and not pthreads. 3a. Am I correct in this assumption? 3b. How are the exception handlers and pagers set up for these Vcpus?
Thank you so much for your time, David
Also, if there was a way to not display my email address as my username, that would be great.
Welcome to the list, David!
I am hoping to discuss the topic of threads to better my understanding of it, as it seems to be a major building block in L4Re. I have the following questions (using the c++ based libraries.):
- Is Pthread the official way to create threads in an L4Re application?
Presuming that the situation hasn't changed since I asked a similar question some time ago, although I cannot actually find that message at the moment, I think that the pthread library is the preferred way.
There was a message in January 2024 from someone who was wondering about a different pthread library implementation, but I don't know if that went any further than an initial enquiry.
I did consider implementing my own threading library when expanding support for Newlib as the C library in L4Re. However, since I didn't really want yet another subproject to work on, I ended up customising the existing pthread library to work with my Newlib implementation.
- I have made a L4 thread (to understand how threads work in L4) without
the help of pthreads by setting up the Attr, which involved in setting the exception handlers(using rm()), pager (using rm()), instruction pointers, stack pointers, binding, ex_reg() and finally running. All seems well until I try printing a message. It seems seems I am unable to use the printf() function in the instruction pointer function of said thread. The error I get is : ttest | l4re_itas[rm]: unhandled read page fault at 0x141 pc=0x100f8a0 ttest | l4re_itas: rom/thread_test: Unhandled exception: PC=0x100f8a0 PFA=0x140 LdrFlgs=0x0 However, if I use printf in a pthread, none of these errors pop up.
I wonder whether the underlying C library might be relying on specific structures provided by libpthread. This may well have been another reason why I decided not to make my own independent threading library.
2a. Am I using the wrong exception handler and pager (I got both from rm)? 2b. Also, the "l4_vcon_send(L4_BASE_LOG_CAP,..,...) function seems to work fine in either case, shouldn't printf() eventually call this function as after a series of indirections?
It has to get to that invocation first, and that journey may be the problem. I would recommend investigating the location of the page fault using the appropriate tools like addr2line and objdump.
2c. What exc_handler and pager do pthreads use? Why are they able tohandle the pager faults and exceptions from printf? Can I appropriate them for the L4 threads I started?
Without revisiting my own work and the existing implementation too thoroughly, I would say that threads will share the same exception handlers and pagers, these defined in the task's capability slots. (The unusual case would be the region mapper thread which has a particular purpose.)
You do need to make sure that the thread's environment is suitably populated, which you seem to have done. This, of course, involves populating the thread stack with the environment definitions. In my own framework, I do this for the main thread of a task when creating a new task, but it would obviously need doing for every new thread as well.
So, I think that your problems may be rooted in the dependencies of the C library on the pthread library, but I welcome any corrections and clarifications, not least because I am not exactly offering a comprehensive answer here!
Regards,
Paul
Hello Paul,
Thank you for your thoughtful comments and thoughts. I have read your blogs about your explorations into L4 and they certainly were helpful for my understanding. Also, thank you for suggesting tools for further investigation. If I find anything intriguing, I will for sure report back.
Thank you, David
l4-hackers@os.inf.tu-dresden.de