Phase1 -
- My initial focus for the project was to completely isolate two thread-stacks. This as a pre-requisite required to utilize the ARMv7 MMU to isolate blocks of memory dynamically. Through the first two weeks, I worked on providing support for dynamic memory isolation. Code sample.
- Once this was done, I moved on to provide high-level support for isolating thread stacks. This included a custom stack allocation mechanism and a mechanism for tracking protected thread stacks.
- The next part of the task involved providing proper context switch support for setting/unsetting memory attributes of the thread-stacks. This completed my first phase of GSoC.
- These 4 blog posts provide an explanation for my work in phase 1.
- A complete view of my work in phase 1 can be viewed here.
- The focus in phase-2 was to get an end to end working, optimized solution for strict thread-stack isolation and provide basic support for thread-stack sharing.
- A simple test in which a thread tries to read from the stack of another thread, while it has been switched out was used to test this end to end solution.
- This test laid bare some of the dormant problems with my implementation that had gone unnoticed. I discuss them and their solution in this post.
- Up until this point, I had been using separate structures for tracking protected stacks. This mechanism also used to dynamically allocate memory for these structures. I integrated these structures in the already present Stack Control structure so that they can be allocated statically, based on the number of threads that are configured through the application.
- The next part involved providing a naming mechanism for the protected thread-stacks. This was done in order to identify the memory region to be allocated from shm_open().
- After completing the basic support for thread-stack sharing, my focus in this phase was to provide support to high-level POSIX APIs for thread-stack sharing. Another important goal for this phase was to optimize my code and make it merge-ready by using more of the structures that are already present in the RTEMS codebase.
- I have discussed the rationale behind high-level design choices for stack-sharing here. The relevant code for stack-sharing can be found here.
- The above changes had some flaws. They were not optimized enough and the mechanism for stack-naming was not integrated properly to the stack control structure. These patches moved my code a bit closer to merging but some of the issues with proper integration into the stack control structure still remained.
- I also worked on providing a mechanism for the conditional configuration of thread-stack protection. This enables the user to enable the thread-stack protection conditionally at build time. This option is based on the new build system of RTEMS.
- Currently, the mechanism for isolating thread-stacks requires setting/unsetting the memory regions corresponding to the thread-stack. This can be optimized by changing the page-table base during each context switch.
- Handling of deletion of threads when their life-cycle finishes also need to be handled.
- Clone the Final_release branch from my repo.
- Since the configuration option is based on the new build system, the standard 'make' option is not compatible with this feature. Refer to Sebastian Huber's rtems-docs repo, chapter 7, for the basic setup of the new build system.
- The important point to keep in mind is to set the RTEMS_THREAD_STACK_PROTECTION option to True in my repo's config.ini file before the './waf configure' command.
- Currently, thread stack isolation and sharing work only for arm/realview_pbx_a9 BSP.
- Simulation has been done on QEMU.
- For a demonstration of the thread-stack isolation refer to the thread_stack_protection test in the testsuite. For thread-stack sharing mechanism refer to the thread_stack_sharing test.