Skip to content

Commit f55eb18

Browse files
committed
libc: Add mach-o/getsect.h and mach/exception.h macOS headers
Closes #18257.
1 parent e2fb103 commit f55eb18

File tree

3 files changed

+217
-0
lines changed

3 files changed

+217
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3+
*
4+
* @APPLE_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. Please obtain a copy of the License at
10+
* http://www.opensource.apple.com/apsl/ and read it before using this
11+
* file.
12+
*
13+
* The Original Code and all software distributed under the License are
14+
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15+
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16+
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18+
* Please see the License for the specific language governing rights and
19+
* limitations under the License.
20+
*
21+
* @APPLE_LICENSE_HEADER_END@
22+
*/
23+
#ifndef _MACH_O_GETSECT_H_
24+
#define _MACH_O_GETSECT_H_
25+
26+
#include <stdint.h>
27+
#include <mach-o/loader.h>
28+
#include <Availability.h>
29+
#include <TargetConditionals.h>
30+
31+
#ifndef __CCTOOLS_DEPRECATED
32+
#define __CCTOOLS_DEPRECATED __API_DEPRECATED("No longer supported", macos(10.0, 13.0), ios(1.0, 16.0), watchos(1.0, 8.0), tvos(1.0, 16.0))
33+
#define __CCTOOLS_DEPRECATED_MSG(_msg) __API_DEPRECATED_WITH_REPLACEMENT(_msg, macos(10.0, 13.0), ios(1.0, 16.0), watchos(1.0, 8.0), tvos(1.0, 16.0))
34+
#endif
35+
36+
37+
#ifdef __cplusplus
38+
extern "C" {
39+
#endif /* __cplusplus */
40+
41+
/*
42+
* Runtime interfaces for Mach-O programs. For both 32-bit and 64-bit programs,
43+
* where the sizes returned will be 32-bit or 64-bit based on the size of
44+
* 'unsigned long'.
45+
*/
46+
extern char *getsectdata(
47+
const char *segname,
48+
const char *sectname,
49+
unsigned long *size) __CCTOOLS_DEPRECATED_MSG("use getsectiondata()");
50+
51+
extern char *getsectdatafromFramework(
52+
const char *FrameworkName,
53+
const char *segname,
54+
const char *sectname,
55+
unsigned long *size) __CCTOOLS_DEPRECATED;
56+
57+
extern unsigned long get_end(void) __CCTOOLS_DEPRECATED;
58+
extern unsigned long get_etext(void) __CCTOOLS_DEPRECATED;
59+
extern unsigned long get_edata(void) __CCTOOLS_DEPRECATED;
60+
61+
#ifndef __LP64__
62+
/*
63+
* Runtime interfaces for 32-bit Mach-O programs.
64+
*/
65+
extern const struct section *getsectbyname(
66+
const char *segname,
67+
const char *sectname) __CCTOOLS_DEPRECATED_MSG("use getsectiondata(&__dso_handle,)");
68+
69+
extern uint8_t *getsectiondata(
70+
const struct mach_header *mhp,
71+
const char *segname,
72+
const char *sectname,
73+
unsigned long *size);
74+
75+
extern const struct segment_command *getsegbyname(
76+
const char *segname) __CCTOOLS_DEPRECATED;
77+
78+
extern uint8_t *getsegmentdata(
79+
const struct mach_header *mhp,
80+
const char *segname,
81+
unsigned long *size);
82+
83+
#else /* defined(__LP64__) */
84+
/*
85+
* Runtime interfaces for 64-bit Mach-O programs.
86+
*/
87+
extern const struct section_64 *getsectbyname(
88+
const char *segname,
89+
const char *sectname);
90+
91+
extern uint8_t *getsectiondata(
92+
const struct mach_header_64 *mhp,
93+
const char *segname,
94+
const char *sectname,
95+
unsigned long *size);
96+
97+
extern const struct segment_command_64 *getsegbyname(
98+
const char *segname) __CCTOOLS_DEPRECATED;
99+
100+
extern uint8_t *getsegmentdata(
101+
const struct mach_header_64 *mhp,
102+
const char *segname,
103+
unsigned long *size);
104+
105+
#endif /* defined(__LP64__) */
106+
107+
/*
108+
* Interfaces for tools working with 32-bit Mach-O files.
109+
*/
110+
extern char *getsectdatafromheader(
111+
const struct mach_header *mhp,
112+
const char *segname,
113+
const char *sectname,
114+
uint32_t *size) __CCTOOLS_DEPRECATED_MSG("use getsectiondata()");
115+
116+
extern const struct section *getsectbynamefromheader(
117+
const struct mach_header *mhp,
118+
const char *segname,
119+
const char *sectname) __CCTOOLS_DEPRECATED_MSG("use getsectiondata()");
120+
121+
extern const struct section *getsectbynamefromheaderwithswap(
122+
struct mach_header *mhp,
123+
const char *segname,
124+
const char *sectname,
125+
int fSwap) __CCTOOLS_DEPRECATED_MSG("use getsectiondata()");
126+
127+
/*
128+
* Interfaces for tools working with 64-bit Mach-O files.
129+
*/
130+
extern char *getsectdatafromheader_64(
131+
const struct mach_header_64 *mhp,
132+
const char *segname,
133+
const char *sectname,
134+
uint64_t *size) __CCTOOLS_DEPRECATED_MSG("use getsectiondata()");
135+
136+
extern const struct section_64 *getsectbynamefromheader_64(
137+
const struct mach_header_64 *mhp,
138+
const char *segname,
139+
const char *sectname) __CCTOOLS_DEPRECATED_MSG("use getsectiondata()");
140+
141+
extern const struct section *getsectbynamefromheaderwithswap_64(
142+
struct mach_header_64 *mhp,
143+
const char *segname,
144+
const char *sectname,
145+
int fSwap) __CCTOOLS_DEPRECATED_MSG("use getsectiondata()");
146+
147+
#ifdef __cplusplus
148+
}
149+
#endif /* __cplusplus */
150+
151+
#endif /* _MACH_O_GETSECT_H_ */
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2000 Apple Computer, 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+
/*
29+
* @OSF_COPYRIGHT@
30+
*/
31+
/*
32+
* Mach Operating System
33+
* Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34+
* All Rights Reserved.
35+
*
36+
* Permission to use, copy, modify and distribute this software and its
37+
* documentation is hereby granted, provided that both the copyright
38+
* notice and this permission notice appear in all copies of the
39+
* software, derivative works or modified versions, and any portions
40+
* thereof, and that both notices appear in supporting documentation.
41+
*
42+
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43+
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44+
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45+
*
46+
* Carnegie Mellon requests users of this software to return to
47+
*
48+
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49+
* School of Computer Science
50+
* Carnegie Mellon University
51+
* Pittsburgh PA 15213-3890
52+
*
53+
* any improvements or extensions that they make and grant Carnegie Mellon
54+
* the rights to redistribute these changes.
55+
*/
56+
57+
#ifndef _MACH_EXCEPTION_H_
58+
#define _MACH_EXCEPTION_H_
59+
60+
#include <mach/exception_types.h>
61+
62+
#endif /* _MACH_EXCEPTION_H_ */

tools/macos-headers.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124

125125
// macOS system headers
126126
#include <mach/clock.h>
127+
#include <mach/exception.h>
127128
#include <mach/mach.h>
128129
#include <mach/mach_time.h>
129130
#include <mach/thread_state.h>
@@ -196,6 +197,9 @@
196197
#include <sys/file.h>
197198
#include <malloc/malloc.h>
198199

200+
// Depended on by bdwgc
201+
#include <mach-o/getsect.h>
202+
199203
// Provided by macOS LibC
200204
#include <memory.h>
201205
#include <zlib.h>

0 commit comments

Comments
 (0)