kxld_reloc.h   [plain text]


/*
 * Copyright (c) 2007-2008 Apple Inc. All rights reserved.
 *
 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Apple Public Source License
 * Version 2.0 (the 'License'). You may not use this file except in
 * compliance with the License. The rights granted to you under the License
 * may not be used to create, or enable the creation or redistribution of,
 * unlawful or unlicensed copies of an Apple operating system, or to
 * circumvent, violate, or enable the circumvention or violation of, any
 * terms of an Apple operating system software license agreement.
 * 
 * Please obtain a copy of the License at
 * http://www.opensource.apple.com/apsl/ and read it before using this file.
 * 
 * The Original Code and all software distributed under the License are
 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 * Please see the License for the specific language governing rights and
 * limitations under the License.
 * 
 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
 */
#ifndef _KXLD_RELOC_H
#define _KXLD_RELOC_H

#include <mach/machine.h>
#include <sys/types.h>
#if KERNEL
    #include <libkern/kxld_types.h>
#else
    #include "kxld_types.h"
#endif

struct kxld_array;
struct kxld_sym;
struct kxld_symtab;
typedef struct kxld_relocator KXLDRelocator;
typedef struct kxld_reloc KXLDReloc;

typedef boolean_t (*RelocHasPair)(u_int r_type);
typedef boolean_t (*RelocIsPair)(u_int r_type, u_int prev_r_type);
typedef boolean_t (*RelocHasGot)(u_int r_type);
typedef kern_return_t(*ProcessReloc)(u_char *instruction, u_int length, u_int pcrel, 
    kxld_addr_t base_pc, kxld_addr_t link_pc, kxld_addr_t link_disp, u_int type, 
    kxld_addr_t target, kxld_addr_t pair_target, boolean_t swap);

struct kxld_relocator {
    RelocHasPair reloc_has_pair;
    RelocIsPair reloc_is_pair;
    RelocHasGot reloc_has_got;
    ProcessReloc process_reloc;
    boolean_t is_32_bit;
    boolean_t swap;
};

struct kxld_reloc {
    u_int address;
    u_int target;
    u_int pair_target;
    u_int target_type:3;
    u_int pair_target_type:3;
    u_int reloc_type:4;
    u_int length:2;
    u_int pcrel:1;
};

struct kxld_array;
struct kxld_sect;
struct kxld_seg;
struct kxld_symtab;
struct relocation_info;

/*******************************************************************************
* Constructors and Destructors
*******************************************************************************/

kern_return_t kxld_relocator_init(KXLDRelocator *relocator, cpu_type_t cputype,
    cpu_subtype_t cpusubtype, boolean_t swap)
    __attribute__((nonnull,visibility("hidden")));

kern_return_t kxld_reloc_create_macho(struct kxld_array *relocarray,
    const KXLDRelocator *relocator, const struct relocation_info *srcs, 
    u_int nsrcs) __attribute__((nonnull, visibility("hidden")));

void kxld_relocator_clear(KXLDRelocator *relocator)
    __attribute__((nonnull, visibility("hidden")));

/*******************************************************************************
* Accessors
*******************************************************************************/

boolean_t kxld_relocator_has_pair(const KXLDRelocator *relocator, u_int r_type)
    __attribute__((pure, nonnull,visibility("hidden")));

boolean_t kxld_relocator_is_pair(const KXLDRelocator *relocator, u_int r_type, 
    u_int last_r_type)
    __attribute__((pure, nonnull,visibility("hidden")));

boolean_t kxld_relocator_has_got(const KXLDRelocator *relocator, u_int r_type)
    __attribute__((pure, nonnull,visibility("hidden")));

struct kxld_sym * kxld_reloc_get_symbol(const KXLDRelocator *relocator,
    const KXLDReloc *reloc, u_char *data, 
    const struct kxld_symtab *symtab)
    __attribute__((pure, nonnull(1,2,4), visibility("hidden")));

kern_return_t kxld_reloc_get_reloc_index_by_offset(const struct kxld_array *relocs, 
    kxld_size_t offset, u_int *idx)
    __attribute__((nonnull, visibility("hidden")));

KXLDReloc * kxld_reloc_get_reloc_by_offset(const struct kxld_array *relocs, 
    kxld_addr_t offset)
    __attribute__((pure, nonnull, visibility("hidden")));

/*******************************************************************************
* Modifiers
*******************************************************************************/

kern_return_t kxld_reloc_update_symindex(KXLDReloc *reloc, u_int symindex)
    __attribute__((nonnull,visibility("hidden")));

kern_return_t kxld_relocator_process_sect_reloc(const KXLDRelocator *relocator,
    const KXLDReloc *reloc, const struct kxld_sect *sect,
    const struct kxld_array *sectarray, const struct kxld_symtab *symtab)
    __attribute__((nonnull,visibility("hidden")));

kern_return_t kxld_relocator_process_table_reloc(const KXLDRelocator *relocator,
    const KXLDReloc *reloc, const struct kxld_seg *seg, u_char *file, 
    const struct kxld_array *sectarray, 
    const struct kxld_symtab *symtab)
    __attribute__((nonnull,visibility("hidden")));

#endif /* _KXLD_RELOC_H */