diff --git a/src/eh_elf/eh_elf.c b/src/eh_elf/eh_elf.c new file mode 100644 index 00000000..ee4d9b02 --- /dev/null +++ b/src/eh_elf/eh_elf.c @@ -0,0 +1,16 @@ +/********** Libunwind -- eh_elf flavour ********** + * This is the eh_elf version of libunwind, made for academic purposes. + * + * Théophile Bastian + ************************************************* + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ************************************************/ + +#include "eh_elf_i.h" + diff --git a/src/eh_elf/eh_elf.h b/src/eh_elf/eh_elf.h new file mode 100644 index 00000000..90a5247a --- /dev/null +++ b/src/eh_elf/eh_elf.h @@ -0,0 +1,42 @@ +/********** Libunwind -- eh_elf flavour ********** + * This is the eh_elf version of libunwind, made for academic purposes. + * + * Théophile Bastian + ************************************************* + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ************************************************/ + +#pragma once + +#include +#include "libunwind_i.h" + +/// Store the necessary data for a single eh_elf +typedef struct { + // TODO +} eh_elf_handle_t; + +/** Initialize everything for local memory analysis + * @return 0 on success, or a negative value upon failure + **/ +int eh_elf_init_local(); + +/** Initialize everything for the remote analysis of the process of given PID + * @return 0 on success, or a negative value upon failure + **/ +int eh_elf_init_pid(pid_t pid); + +/// Cleanup everything that was allocated by eh_elf_init_* +void eh_elf_clean(); + +/** Step the cursor using eh_elf mechanisms. + * + * Return 0 if everything went file, otherwise, return a negative value. + **/ +int eh_elf_step_cursor(struct cursor *cursor); diff --git a/src/x86_64/Ginit_local.c b/src/x86_64/Ginit_local.c index 07993896..5756b4a0 100644 --- a/src/x86_64/Ginit_local.c +++ b/src/x86_64/Ginit_local.c @@ -26,6 +26,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "unwind_i.h" +#include "../eh_elf/eh_elf.h" #include "init.h" #ifdef UNW_REMOTE_ONLY @@ -41,6 +42,8 @@ unw_init_local (unw_cursor_t *cursor, ucontext_t *uc) PROTECTED int unw_init_local (unw_cursor_t *cursor, ucontext_t *uc) { + eh_elf_init_local(); + struct cursor *c = (struct cursor *) cursor; if (unlikely (!tdep_init_done)) diff --git a/src/x86_64/Ginit_remote.c b/src/x86_64/Ginit_remote.c index f3b7bb97..ffb00fc6 100644 --- a/src/x86_64/Ginit_remote.c +++ b/src/x86_64/Ginit_remote.c @@ -26,6 +26,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "init.h" +#include "../eh_elf/eh_elf.h" #include "unwind_i.h" PROTECTED int @@ -41,6 +42,8 @@ unw_init_remote (unw_cursor_t *cursor, unw_addr_space_t as, void *as_arg) Debug (1, "(cursor=%p)\n", c); + eh_elf_init_pid(as.acc.get_pid(as_arg)); + c->dwarf.as = as; if (as == unw_local_addr_space) {