]> git.saurik.com Git - apple/objc4.git/blob - runtime/objc-file-old.m
objc4-493.11.tar.gz
[apple/objc4.git] / runtime / objc-file-old.m
1 /*
2 * Copyright (c) 1999-2007 Apple 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 // Copyright 1988-1996 NeXT Software, Inc.
24
25 #if !__OBJC2__
26
27 #include "objc-private.h"
28 #include "objc-runtime-old.h"
29
30
31 #if TARGET_OS_WIN32
32
33 PRIVATE_EXTERN const char *_getObjcHeaderName(const headerType *head)
34 {
35 return "??";
36 }
37
38 /*
39 PRIVATE_EXTERN Module
40 _getObjcModules(const header_info *hi, size_t *nmodules)
41 {
42 if (nmodules) *nmodules = hi->os.moduleCount;
43 return hi->os.modules;
44 }
45 */
46 PRIVATE_EXTERN SEL *
47 _getObjcSelectorRefs(const header_info *hi, size_t *nmess)
48 {
49 if (nmess) *nmess = hi->os.selrefCount;
50 return hi->os.selrefs;
51 }
52
53 PRIVATE_EXTERN struct old_protocol **
54 _getObjcProtocols(const header_info *hi, size_t *nprotos)
55 {
56 if (nprotos) *nprotos = hi->os.protocolCount;
57 return hi->os.protocols;
58 }
59
60 PRIVATE_EXTERN struct old_class **
61 _getObjcClassRefs(const header_info *hi, size_t *nclasses)
62 {
63 if (nclasses) *nclasses = hi->os.clsrefCount;
64 return (struct old_class **)hi->os.clsrefs;
65 }
66
67 // __OBJC,__class_names section only emitted by CodeWarrior rdar://4951638
68 PRIVATE_EXTERN const char *
69 _getObjcClassNames(const header_info *hi, size_t *size)
70 {
71 if (size) *size = 0;
72 return NULL;
73 }
74
75 #else
76
77 #define GETSECT(name, type, sectname) \
78 PRIVATE_EXTERN type *name(const header_info *hi, size_t *outCount) \
79 { \
80 unsigned long byteCount = 0; \
81 type *data = (type *) \
82 getsectiondata(hi->mhdr, SEG_OBJC, sectname, &byteCount); \
83 *outCount = byteCount / sizeof(type); \
84 return data; \
85 }
86
87 GETSECT(_getObjcModules, struct objc_module, "__module_info");
88 GETSECT(_getObjcSelectorRefs, SEL, "__message_refs");
89 GETSECT(_getObjcClassRefs, struct old_class *, "__cls_refs");
90 GETSECT(_getObjcClassNames, const char, "__class_names");
91 // __OBJC,__class_names section only emitted by CodeWarrior rdar://4951638
92
93
94 PRIVATE_EXTERN objc_image_info *
95 _getObjcImageInfo(const headerType *mhdr, size_t *outBytes)
96 {
97 unsigned long byteCount = 0;
98 objc_image_info *info = (objc_image_info *)
99 getsectiondata(mhdr, SEG_OBJC, "__image_info", &byteCount);
100 *outBytes = byteCount;
101 return info;
102 }
103
104
105 PRIVATE_EXTERN struct old_protocol **
106 _getObjcProtocols(const header_info *hi, size_t *nprotos)
107 {
108 unsigned long size = 0;
109 struct old_protocol *protos = (struct old_protocol *)
110 getsectiondata(hi->mhdr, SEG_OBJC, "__protocol", &size);
111 *nprotos = size / sizeof(struct old_protocol);
112
113 if (!hi->os.proto_refs && *nprotos) {
114 size_t i;
115 header_info *whi = (header_info *)hi;
116 whi->os.proto_refs = (struct old_protocol **)
117 malloc(*nprotos * sizeof(*hi->os.proto_refs));
118 for (i = 0; i < *nprotos; i++) {
119 hi->os.proto_refs[i] = protos+i;
120 }
121 }
122
123 return hi->os.proto_refs;
124 }
125
126
127 static const segmentType *
128 getsegbynamefromheader(const headerType *head, const char *segname)
129 {
130 const segmentType *sgp;
131 unsigned long i;
132
133 sgp = (const segmentType *) (head + 1);
134 for (i = 0; i < head->ncmds; i++){
135 if (sgp->cmd == SEGMENT_CMD) {
136 if (strncmp(sgp->segname, segname, sizeof(sgp->segname)) == 0) {
137 return sgp;
138 }
139 }
140 sgp = (const segmentType *)((char *)sgp + sgp->cmdsize);
141 }
142 return NULL;
143 }
144
145 PRIVATE_EXTERN BOOL
146 _hasObjcContents(const header_info *hi)
147 {
148 // Look for an __OBJC,* section other than __OBJC,__image_info
149 const segmentType *seg = getsegbynamefromheader(hi->mhdr, "__OBJC");
150 const sectionType *sect;
151 uint32_t i;
152 for (i = 0; i < seg->nsects; i++) {
153 sect = ((const sectionType *)(seg+1))+i;
154 if (0 != strncmp(sect->sectname, "__image_info", 12)) {
155 return YES;
156 }
157 }
158
159 return NO;
160 }
161
162
163 #endif
164
165 #endif