2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * File: libkern/kernel_mach_header.h
31 * Definitions for accessing mach-o headers.
33 * NOTE: These functions work on Mach-O headers compatible with
34 * the currently running kernel, and cannot be used against mach
35 * headers other than that of the currently running kernel.
39 #ifndef _KERNEL_MACH_HEADER_
40 #define _KERNEL_MACH_HEADER_
46 #include <mach/mach_types.h>
47 #include <mach-o/loader.h>
50 #error this header for kernel use only
55 typedef struct mach_header_64 kernel_mach_header_t
;
56 typedef struct segment_command_64 kernel_segment_command_t
;
57 typedef struct section_64 kernel_section_t
;
59 #define LC_SEGMENT_KERNEL LC_SEGMENT_64
60 #define SECT_CONSTRUCTOR "__mod_init_func"
61 #define SECT_DESTRUCTOR "__mod_term_func"
65 typedef struct mach_header kernel_mach_header_t
;
66 typedef struct segment_command kernel_segment_command_t
;
67 typedef struct section kernel_section_t
;
69 #define LC_SEGMENT_KERNEL LC_SEGMENT
70 #define SECT_CONSTRUCTOR "__constructor"
71 #define SECT_DESTRUCTOR "__destructor"
75 extern kernel_mach_header_t _mh_execute_header
;
77 vm_offset_t
getlastaddr(void);
79 kernel_segment_command_t
*firstseg(void);
80 kernel_segment_command_t
*firstsegfromheader(kernel_mach_header_t
*header
);
81 kernel_segment_command_t
*nextsegfromheader(
82 kernel_mach_header_t
*header
,
83 kernel_segment_command_t
*seg
);
84 kernel_segment_command_t
*getsegbyname(const char *seg_name
);
85 kernel_segment_command_t
*getsegbynamefromheader(
86 kernel_mach_header_t
*header
,
87 const char *seg_name
);
88 void *getsegdatafromheader(kernel_mach_header_t
*, const char *, unsigned long *);
89 kernel_section_t
*getsectbyname(const char *seg_name
, const char *sect_name
);
90 kernel_section_t
*getsectbynamefromheader(
91 kernel_mach_header_t
*header
,
93 const char *sect_name
);
94 void *getsectdatafromheader(kernel_mach_header_t
*, const char *, const char *, unsigned long *);
95 kernel_section_t
*firstsect(kernel_segment_command_t
*sgp
);
96 kernel_section_t
*nextsect(kernel_segment_command_t
*sgp
, kernel_section_t
*sp
);
99 boolean_t
getsymtab(kernel_mach_header_t
*header
,
103 vm_size_t
*strtabsize
);
110 #endif /* _KERNEL_MACH_HEADER_ */