1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <zircon/types.h>
8 #include <stddef.h>
9 
10 #pragma GCC visibility push(hidden)
11 
12 typedef struct elf_load_info elf_load_info_t;
13 
14 // Validate the ELF headers and set up for further use.
15 // The pointer returned must be passed to elf_load_destroy when finished.
16 zx_status_t elf_load_start(zx_handle_t vmo, const void* buf, size_t buf_sz,
17                            elf_load_info_t** infop);
18 
19 // Clean up and free the data structure created by elf_load_start.
20 void elf_load_destroy(elf_load_info_t* info);
21 
22 // Check if the ELF file has a PT_INTERP header.  On success, *interp
23 // is NULL if it had none or a malloc'd string of the contents;
24 // *interp_len is strlen(*interp).
25 zx_status_t elf_load_get_interp(elf_load_info_t* info, zx_handle_t vmo,
26                                 char** interp, size_t* interp_len);
27 
28 // Check if the ELF file has a PT_GNU_STACK header, and return its p_memsz.
29 // Returns zero if no header was found.
30 size_t elf_load_get_stack_size(elf_load_info_t* info);
31 
32 // Load the file's segments into the process.
33 // If this fails, the state of the process address space is unspecified.
34 // Regardless of success/failure this does not consume |vmo|.
35 zx_status_t elf_load_finish(zx_handle_t vmar, elf_load_info_t* info,
36                             zx_handle_t vmo,
37                             zx_handle_t* segments_vmar,
38                             zx_vaddr_t* base, zx_vaddr_t* entry);
39 
40 #pragma GCC visibility pop
41