-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[5/10] libs/libc/elf: Load an FDPIC object. #19942
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
base: master
Are you sure you want to change the base?
Changes from all commits
f31c40d
00bbf46
f7ee36f
28c53d3
f5a8b8d
cc2b937
3f1c66a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /**************************************************************************** | ||
| * include/nuttx/fdpic.h | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. The | ||
| * ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the | ||
| * License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef __INCLUDE_NUTTX_FDPIC_H | ||
| #define __INCLUDE_NUTTX_FDPIC_H | ||
|
|
||
| /**************************************************************************** | ||
| * Included Files | ||
| ****************************************************************************/ | ||
|
|
||
| #include <nuttx/config.h> | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #include <nuttx/arch.h> | ||
| #include <nuttx/compiler.h> | ||
|
|
||
| /**************************************************************************** | ||
| * Public Types | ||
| ****************************************************************************/ | ||
|
|
||
| /* A function descriptor: what a function pointer is under FDPIC. The | ||
| * firmware branches to a code address; a module passes one of these. | ||
| */ | ||
|
|
||
| struct fdpic_desc_s | ||
| { | ||
| uintptr_t entry; /* Address of the code */ | ||
| uintptr_t got; /* Data base to install before branching */ | ||
| }; | ||
|
|
||
| /**************************************************************************** | ||
| * Inline Functions | ||
| ****************************************************************************/ | ||
|
|
||
| #ifdef CONFIG_FDPIC | ||
|
|
||
| /**************************************************************************** | ||
| * Name: fdpic_base | ||
| * | ||
| * Description: | ||
| * The data base of the calling context, from the PIC base register. | ||
| * Non-zero means the caller is an FDPIC module, zero means firmware. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| static inline uintptr_t fdpic_base(void) | ||
| { | ||
| uintptr_t base; | ||
|
|
||
| up_getpicbase(&base); | ||
| return base; | ||
| } | ||
|
|
||
| /**************************************************************************** | ||
| * Name: fdpic_callback | ||
| * | ||
| * Description: | ||
| * Resolve a function pointer from a caller that may be an FDPIC module. | ||
| * Only the entry point is taken: the data base is already in the register. | ||
| * | ||
| * Input Parameters: | ||
| * fn - The pointer as it was received. | ||
| * | ||
| * Returned Value: | ||
| * An address that can be branched to directly. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| static inline FAR void *fdpic_callback(FAR void *fn) | ||
| { | ||
| if (fn != NULL && fdpic_base() != 0) | ||
| { | ||
| return (FAR void *)((FAR struct fdpic_desc_s *)fn)->entry; | ||
| } | ||
|
|
||
| return fn; | ||
| } | ||
|
|
||
| /**************************************************************************** | ||
| * Name: fdpic_invoke | ||
| * | ||
| * Description: | ||
| * Call a resolved module entry point with the module data base in the PIC | ||
| * base register. For a callback that runs on a shared thread, which | ||
| * carries no module base. Elsewhere fdpic_callback() is enough. | ||
| * | ||
| * Input Parameters: | ||
| * arg - The one word argument. | ||
| * entry - The code address to enter, already resolved from the descriptor. | ||
| * got - The module data base to install. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| static inline void fdpic_invoke(uintptr_t arg, uintptr_t entry, | ||
| uintptr_t got) | ||
| { | ||
| up_fdpic_invoke(arg, entry, got); | ||
| } | ||
|
|
||
| #else | ||
|
|
||
| # define fdpic_base() (0) | ||
| # define fdpic_callback(fn) (fn) | ||
| # define fdpic_invoke(arg, entry, got) \ | ||
| ((void)(got), (((CODE void (*)(uintptr_t))(uintptr_t)(entry))(arg))) | ||
|
|
||
| #endif /* CONFIG_FDPIC */ | ||
|
|
||
| #endif /* __INCLUDE_NUTTX_FDPIC_H */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,19 @@ | |
| # define CONFIG_LIBC_ELF_MAXDEPEND 0 | ||
| #endif | ||
|
|
||
| /* A compacting filesystem gives its media address with a pin that holds the | ||
| * blocks in place. The loader holds the pin through a file reference, | ||
| * because the unload runs on another task. | ||
| * | ||
| * That reference is taken with file_get() and file_dup2(), which are kernel | ||
| * side, so this is for the copy of libc that runs there. | ||
| */ | ||
|
|
||
| #if defined(CONFIG_FS_PIN) && \ | ||
| (defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)) | ||
| # define HAVE_LIBC_ELF_PIN 1 | ||
| #endif | ||
|
|
||
| #ifndef CONFIG_LIBC_ELF_ALIGN_LOG2 | ||
| # define CONFIG_LIBC_ELF_ALIGN_LOG2 2 | ||
| #endif | ||
|
|
@@ -123,6 +136,7 @@ typedef CODE int (*mod_uninitializer_t)(FAR void *arg); | |
| * nexports - The number of symbols in the exported symbol table. | ||
| */ | ||
|
|
||
| struct file; | ||
| struct symtab_s; | ||
| struct mod_info_s | ||
| { | ||
|
|
@@ -252,6 +266,30 @@ struct mod_loadinfo_s | |
| * skip the copy. | ||
| */ | ||
|
|
||
| /* True if e_ident[EI_OSABI] marked this an FDPIC object. */ | ||
|
|
||
| bool fdpic; | ||
|
|
||
| #ifdef HAVE_LIBC_ELF_PIN | ||
| /* The file the pin is held through, handed to the module once it loads. */ | ||
|
|
||
| FAR struct file *pinfile; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove textpin, let's check pinfile != NULL instead |
||
| #endif | ||
|
|
||
| /* The object's data base, from DT_PLTGOT. An FDPIC module runs with this | ||
| * in the PIC base register. | ||
| */ | ||
|
|
||
| uintptr_t gotaddr; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we merge gotaddr and gotindex into one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. merging to one address loses the size, so we would need a |
||
|
|
||
| /* Pool of function descriptors behind the writable segment. Reserved | ||
| * when the segment is sized, and bounded by the relocation count. | ||
| */ | ||
|
|
||
| uintptr_t descpool; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to the real type
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can split it into an offset and a |
||
| uint16_t ndesc; /* Capacity */ | ||
| uint16_t usedesc; /* Next free slot */ | ||
|
|
||
| /* Address environment. | ||
| * | ||
| * addrenv - This is the handle created by addrenv_allocate() that can be | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add Kconfig something like FS_PIN, and let CONFIG_FS_XIPFS select it