Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge gen_kobject_list.py and gen_priv_stacks.py #15304

Closed
andrewboie opened this issue Apr 9, 2019 · 2 comments · Fixed by #23429
Closed

merge gen_kobject_list.py and gen_priv_stacks.py #15304

andrewboie opened this issue Apr 9, 2019 · 2 comments · Fixed by #23429
Assignees
Labels
area: Memory Protection Enhancement Changes/Updates/Additions to existing features
Milestone

Comments

@andrewboie
Copy link
Contributor

Generation of privilege mode stack buffers can take place in the main gen_kobject_list.py script, there's no actual need for them to be separate. Any data/bss for objects declared in the gperf C file already goes in an area of memory which can expand without limit.

We just need the main gperf table; for any thread's kobject, the data field will point to a struct containing the thread ID and a pointer to its stack buffer.

Should help with build times as we only need to scan the DWARF data once instead of twice.

@andrewboie andrewboie added Enhancement Changes/Updates/Additions to existing features area: Memory Protection labels Apr 9, 2019
@andrewboie andrewboie self-assigned this Apr 9, 2019
@andrewboie
Copy link
Contributor Author

Further detail:

/* Table generated by gperf, these objects are retrieved via
 * z_object_find() */
struct _k_object {
        char *name;
        u8_t perms[CONFIG_MAX_THREAD_BYTES];
        u8_t type;
        u8_t flags;
        u32_t data;
} __packed __aligned(4);

Right now each script generates a gperf hash table and instantiates some objects

gen_kobject_list.py:

  • Scan the elf binary for instances of any type of kernel object
  • Generate a table of struct _k_object for every kernel object found in the build.
  • The hash table map kernel object memory addresses to kernel object metadata (struct _k_object), where the _k_object gets instantiated by the script.
      • For any instances of k_futex, instantiate a wait_q and assign it to the futex's associated _k_object's data member
      • For any instance of sys_mutex, instantiate a k_mutex and assign it to the sys_mutex's associated k_object's data member
      • For threads, assign a numeric ID and place in the data member
      • For thread stacks, set the data member to be the size of the stack object

gen_priv_stacks.py:

  • Scan the elf binary for instances of k_thread_stack element arrays (which is what thread stacks are)
  • Generate a table mapping stack object memory addresses to pointers to privilege mode stacks
  • Generate a privilege mode stack for every stack object found, which can be looked up.

These do not have to be separate. These scripts do the same thing: perform a time-consuming analysis of the DWARF debug info to find kernel objects
We can generate the privilege mode stacks in gen_kobject_list directly just like we already do with futex waitqs, etc.
The data member for a thread stack object currently just has the stack size. Instead, create an instance of:

struct z_stack_metadata {
   char *privilege_stack;
   size_t size;
}

Populate these appropriately for every stack object found, and set the data member of the stack's struct k_object to point to it.

@andrewboie andrewboie added this to the v2.1.0 milestone Oct 6, 2019
@keylime-unicorn keylime-unicorn removed their assignment Oct 29, 2019
@andrewboie andrewboie modified the milestones: v2.1.0, v2.2.0 Oct 31, 2019
@andrewboie andrewboie self-assigned this Oct 31, 2019
@nashif nashif assigned nashif and unassigned andrewboie Nov 21, 2019
@andrewboie
Copy link
Contributor Author

Note that elf_helper.py script was split out (in a rather rough fashion) to support this extra script, so really I'd like to see gen_kobject_list.py, gen_priv_stacks.py, and elf_helper.py all combined into a single script, that creates a single gperf table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Memory Protection Enhancement Changes/Updates/Additions to existing features
Projects
None yet
4 participants