#ifndef __DGRAPH_H__
#define __DGRAPH_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef KERNEL
#include <libsa/stdlib.h>
#include <IOKit/IOLib.h>
#else
#include <stdlib.h>
#include <mach/mach.h>
#endif
typedef struct dgraph_entry_t {
char is_kernel_component; char is_symbol_set;
char opaques;
char opaque_link;
char * name;
void * object; size_t object_length; #ifdef KERNEL
bool object_is_kmem; #endif
unsigned int dependencies_capacity;
unsigned int num_dependencies;
struct dgraph_entry_t ** dependencies;
char * expected_kmod_name;
char * expected_kmod_vers;
bool is_mapped;
int do_load; vm_address_t loaded_address; #ifndef KERNEL
char * link_output_file;
bool link_output_file_alloc;
#endif
struct mach_header * linked_image;
vm_size_t linked_image_length;
vm_address_t symbols;
vm_size_t symbols_length;
vm_address_t symbols_malloc;
vm_address_t kernel_alloc_address;
unsigned long kernel_alloc_size;
vm_address_t kernel_load_address;
unsigned long kernel_load_size;
unsigned long kernel_hdr_size;
unsigned long kernel_hdr_pad;
int need_cleanup; kmod_t kmod_id;
} dgraph_entry_t;
typedef struct {
unsigned int capacity;
unsigned int length;
dgraph_entry_t ** graph;
dgraph_entry_t ** load_order;
dgraph_entry_t * root;
char have_loaded_symbols;
char has_symbol_sets;
char has_opaque_links;
vm_address_t opaque_base_image;
vm_size_t opaque_base_length;
} dgraph_t;
typedef enum {
dgraph_error = -1,
dgraph_invalid = 0,
dgraph_valid = 1
} dgraph_error_t;
enum { kOpaqueLink = 0x01, kRawKernelLink = 0x02 };
dgraph_error_t dgraph_init(dgraph_t * dgraph);
#ifndef KERNEL
dgraph_error_t dgraph_init_with_arglist(
dgraph_t * dgraph,
int expect_addresses,
const char * dependency_delimiter,
const char * kernel_dependency_delimiter,
int argc,
char * argv[]);
#endif
void dgraph_free(
dgraph_t * dgraph,
int free_graph);
dgraph_entry_t * dgraph_find_root(dgraph_t * dgraph);
int dgraph_establish_load_order(dgraph_t * dgraph);
#ifndef KERNEL
void dgraph_print(dgraph_t * dgraph);
#endif
void dgraph_log(dgraph_t * depgraph);
dgraph_entry_t * dgraph_find_dependent(dgraph_t * dgraph, const char * name);
dgraph_entry_t * dgraph_add_dependent(
dgraph_t * dgraph,
const char * name,
#ifdef KERNEL
void * object,
size_t object_length,
bool object_is_kmem,
#endif
const char * expected_kmod_name,
const char * expected_kmod_vers,
vm_address_t load_address,
char is_kernel_component);
dgraph_entry_t * dgraph_add_dependency(
dgraph_t * dgraph,
dgraph_entry_t * current_dependent,
const char * name,
#ifdef KERNEL
void * object,
size_t object_length,
bool object_is_kmem,
#endif
const char * expected_kmod_name,
const char * expected_kmod_vers,
vm_address_t load_address,
char is_kernel_component);
#ifdef __cplusplus
}
#endif
#endif