]> git.saurik.com Git - apple/xnu.git/blame - libkern/kxld/kxld_seg.h
xnu-1504.7.4.tar.gz
[apple/xnu.git] / libkern / kxld / kxld_seg.h
CommitLineData
b0d623f7
A
1/*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28#ifndef _KXLD_SEG_H_
29#define _KXLD_SEG_H_
30
31#include <mach/vm_prot.h>
32#include <sys/types.h>
33#if KERNEL
34 #include <libkern/kxld_types.h>
35#else
36 #include "kxld_types.h"
37#endif
38
39#include "kxld_array.h"
40
41struct kxld_sect;
42struct segment_command;
43struct segment_command_64;
44typedef struct kxld_seg KXLDSeg;
45
46struct kxld_seg {
47 char segname[16];
48 kxld_addr_t base_addr;
49 kxld_addr_t link_addr;
50 kxld_size_t vmsize;
51 kxld_size_t fileoff;
52 KXLDArray sects;
53 u_int flags;
54 vm_prot_t maxprot;
55 vm_prot_t initprot;
56};
57
58/*******************************************************************************
59* Constructors and Destructors
60*******************************************************************************/
61
62#if KXLD_USER_OR_ILP32
63kern_return_t kxld_seg_init_from_macho_32(KXLDSeg *seg, struct segment_command *src)
64 __attribute__((nonnull, visibility("hidden")));
65#endif /* KXLD_USER_OR_ILP32 */
66
67#if KXLD_USER_OR_LP64
68kern_return_t kxld_seg_init_from_macho_64(KXLDSeg *seg, struct segment_command_64 *src)
69 __attribute__((nonnull, visibility("hidden")));
70#endif /* KXLD_USER_OR_LP64 */
71
72#if KXLD_USER_OR_OBJECT
73kern_return_t kxld_seg_create_seg_from_sections(KXLDArray *segarray,
74 KXLDArray *sectarray)
75 __attribute__((nonnull, visibility("hidden")));
76
77kern_return_t kxld_seg_finalize_object_segment(KXLDArray *segarray,
78 KXLDArray *section_order, u_long hdrsize)
79 __attribute__((nonnull, visibility("hidden")));
80#endif /* KXLD_USER_OR_OBJECT */
81
82void kxld_seg_clear(KXLDSeg *seg)
83 __attribute__((nonnull, visibility("hidden")));
84
85void kxld_seg_deinit(KXLDSeg *seg)
86 __attribute__((nonnull, visibility("hidden")));
87
88
89/*******************************************************************************
90* Accessors
91*******************************************************************************/
92
93kxld_size_t kxld_seg_get_vmsize(const KXLDSeg *seg)
94 __attribute__((pure, nonnull, visibility("hidden")));
95
96u_long kxld_seg_get_macho_header_size(const KXLDSeg *seg, boolean_t is_32_bit)
97 __attribute__((pure, nonnull, visibility("hidden")));
98
99u_long kxld_seg_get_macho_data_size(const KXLDSeg *seg)
100 __attribute__((pure, nonnull, visibility("hidden")));
101
102kern_return_t
103kxld_seg_export_macho_to_file_buffer(const KXLDSeg *seg, u_char *buf,
104 u_long *header_offset, u_long header_size,
105 u_long *data_offset, u_long data_size,
106 boolean_t is_32_bit)
107 __attribute__((nonnull, visibility("hidden")));
108
109kern_return_t
110kxld_seg_export_macho_to_vm(const KXLDSeg *seg, u_char *buf,
111 u_long *header_offset, u_long header_size,
112 u_long data_size, kxld_addr_t file_link_addr,
113 boolean_t is_32_bit)
114 __attribute__((nonnull, visibility("hidden")));
115
116/*******************************************************************************
117* Modifiers
118*******************************************************************************/
119
120kern_return_t kxld_seg_add_section(KXLDSeg *seg, struct kxld_sect *sect)
121 __attribute__((nonnull, visibility("hidden")));
122
123/* To be called after all sections are added */
124kern_return_t kxld_seg_finish_init(KXLDSeg *seg)
125 __attribute__((nonnull, visibility("hidden")));
126
127void kxld_seg_set_vm_protections(KXLDSeg *seg, boolean_t strict_protections)
128 __attribute__((nonnull, visibility("hidden")));
129
130void kxld_seg_relocate(KXLDSeg *Seg, kxld_addr_t link_addr)
131 __attribute__((nonnull, visibility("hidden")));
132
133#endif /* _KXLD_SEG_H_ */
134