L4_Myself() and the MyThread Constant

Summary

Threads are no longer able to obtain a globally unique identifier of themselves by calling L4_Myself(). L4_Myself() will now return a constant value defined as L4_myselfconst.

Motivation

This change was made to support OKL4 evolving towards a capability-based security model. As this security model considers the ability to uniquely identify a thread as a capability, this functionality can no longer be available by default to all threads in the system. Thus, by default threads do not have the capability to identify themselves and are not allowed to identify themselves to other threads.

MyThread Constant Usage

L4_Myself() now returns a constant value, L4_myselfconst. It is preferable to use L4_myselfconst rather than L4_Myself() to emphasize the fact that it is a constant.

It should be noted that the C type of L4_myselfconst is still L4_ThreadId_t, which avoids refactoring of code where unnecessary.

The only situation where L4_myselfconst is valid is when making L4 kernel system calls.

The following usage of L4_myselfconst is no longer valid:

  • A thread may not use L4_myselfconst as any L4_ThreadId_t argument for OKL4 user-level services, including the root server.

  • A thread may not pass (in a meaningful way) L4_myselfconst to other threads to identify itself.

Thread Identification

Although L4_Myself() may not be used to identify a thread to other threads, other methods of achieving the same purpose include:

The First Thread in Each PD

For protection domains (PDs) created during OKL4 initialization, an initial thread will always be created within the PD. These PDs are always defined in weaver.xml as <program> elements. The global thread identifier of the initial thread may be retrieved through the OKL4 object environment, with the key string "MAIN".

   1 /*
   2  * This is the main function of the first thread in the PD
   3  */
   4 void
   5 main(void)
   6 {
   7     L4_ThreadId_t main_tid;
   8     main_tid = thread_l4tid(env_thread(iguana_getenv("MAIN")));
   9     
  10     /* Continue execution... */
  11 }

Threads Created Dynamically (During Runtime)

Threads created using L4_ThreadControl() will need a global thread id allocated to the new thread in advance. Therefore the parent thread has complete knowledge of thread ids in existence, and may choose to pass on this information to its children threads.

Threads created using thread_create() and its variants, pd_thread_create() and eas_thread_create(), will have its global thread identifier returned to the parent thread. The parent thread may pass this information onto child threads if it so wishes. One of of doing this is via OKL4 IPC, where the child's global thread identifier is places in a message register.

The function prototypes of these functions are contained in the header files thread.h, eas.h and pd.h in libs/iguana/include/.

Threads Created Statically (By Elfweaver)

For threads that are created during OKL4 initialization by defining <thread> elements in weaver.xml, the mandatory name attribute may be used to obtain its global thread identifier. The OKL4 object environment may be queried using the capitalised name attribute as the key string.

<program name=...>
    <thread name="kung_fu" start="kung_fu_function" />
</program>

   1 /*
   2  * This is the function that thread kung_fu runs
   3  */
   4 void
   5 kung_fu_function(void)
   6 {
   7     L4_ThreadId_t kf_tid;
   8     kf_tid = thread_l4tid(env_thread(iguana_getenv("KUNG_FU")));
   9     
  10     /* Continue execution... */
  11 }

L4Myself (last edited 2008-08-11 02:34:28 by localhost)