···11-#ifndef __OBJC_CLASS_H_INCLUDED
22-#define __OBJC_CLASS_H_INCLUDED
33-#include "visibility.h"
44-55-/**
66- * Overflow bitfield. Used for bitfields that are more than 63 bits.
77- */
88-struct objc_bitfield
99-{
1010- /**
1111- * The number of elements in the values array.
1212- */
1313- int32_t length;
1414- /**
1515- * An array of values. Each 32 bits is stored in the native endian for the
1616- * platform.
1717- */
1818- int32_t values[0];
1919-};
2020-2121-struct objc_class
2222-{
2323- /**
2424- * Pointer to the metaclass for this class. The metaclass defines the
2525- * methods use when a message is sent to the class, rather than an
2626- * instance.
2727- */
2828- struct objc_class *isa;
2929- /**
3030- * Pointer to the superclass. The compiler will set this to the name of
3131- * the superclass, the runtime will initialize it to point to the real
3232- * class.
3333- */
3434- struct objc_class *super_class;
3535- /**
3636- * The name of this class. Set to the same value for both the class and
3737- * its associated metaclass.
3838- */
3939- const char *name;
4040- /**
4141- * The version of this class. This is not used by the language, but may be
4242- * set explicitly at class load time.
4343- */
4444- long version;
4545- /**
4646- * A bitfield containing various flags. See the objc_class_flags
4747- * enumerated type for possible values.
4848- */
4949- unsigned long info;
5050- /**
5151- * The size of this class. For classes using the non-fragile ABI, the
5252- * compiler will set this to a negative value The absolute value will be
5353- * the size of the instance variables defined on just this class. When
5454- * using the fragile ABI, the instance size is the size of instances of
5555- * this class, including any instance variables defined on superclasses.
5656- *
5757- * In both cases, this will be set to the size of an instance of the class
5858- * after the class is registered with the runtime.
5959- */
6060- long instance_size;
6161- /**
6262- * Metadata describing the instance variables in this class.
6363- */
6464- struct objc_ivar_list *ivars;
6565- /**
6666- * Metadata for for defining the mappings from selectors to IMPs. Linked
6767- * list of method list structures, one per class and one per category.
6868- */
6969- struct objc_method_list *methods;
7070- /**
7171- * The dispatch table for this class. Intialized and maintained by the
7272- * runtime.
7373- */
7474- void *dtable;
7575- /**
7676- * A pointer to the first subclass for this class. Filled in by the
7777- * runtime.
7878- */
7979- struct objc_class *subclass_list;
8080- /**
8181- * A pointer to the next sibling class to this. You may find all
8282- * subclasses of a given class by following the subclass_list pointer and
8383- * then subsequently following the sibling_class pointers in the
8484- * subclasses.
8585- */
8686- struct objc_class *sibling_class;
8787-8888- /**
8989- * Metadata describing the protocols adopted by this class. Not used by
9090- * the runtime.
9191- */
9292- struct objc_protocol_list *protocols;
9393- /**
9494- * Linked list of extra data attached to this class.
9595- */
9696- struct reference_list *extra_data;
9797- /**
9898- * New ABI. The following fields are only available with classes compiled to
9999- * support the new ABI. You may test whether any given class supports this
100100- * ABI by using the CLS_ISNEW_ABI() macro.
101101- */
102102-103103- /**
104104- * The version of the ABI used for this class. Zero indicates the ABI first
105105- * implemented by clang 1.0. One indicates the presence of bitmaps
106106- * indicating the offsets of strong, weak, and unretained ivars.
107107- */
108108- long abi_version;
109109-110110- /**
111111- * Array of pointers to variables where the runtime will store the ivar
112112- * offset. These may be used for faster access to non-fragile ivars if all
113113- * of the code is compiled for the new ABI. Each of these pointers should
114114- * have the mangled name __objc_ivar_offset_value_{class name}.{ivar name}
115115- *
116116- * When using the compatible non-fragile ABI, this faster form should only be
117117- * used for classes declared in the same compilation unit.
118118- *
119119- * The compiler should also emit symbols of the form
120120- * __objc_ivar_offset_{class name}.{ivar name} which are pointers to the
121121- * offset values. These should be emitted as weak symbols in every module
122122- * where they are used. The legacy-compatible ABI uses these with a double
123123- * layer of indirection.
124124- */
125125- int **ivar_offsets;
126126- /**
127127- * List of declared properties on this class (NULL if none). This contains
128128- * the accessor methods for each property.
129129- */
130130- struct objc_property_list *properties;
131131-132132- /**
133133- * GC / ARC ABI: Fields below this point only exist if abi_version is >= 1.
134134- */
135135-136136- /**
137137- * The location of all strong pointer ivars declared by this class.
138138- *
139139- * If the low bit of this field is 0, then this is a pointer to an
140140- * objc_bitfield structure. If the low bit is 1, then the remaining 63
141141- * bits are set, from low to high, for each ivar in the object that is a
142142- * strong pointer.
143143- */
144144- intptr_t strong_pointers;
145145- /**
146146- * The location of all zeroing weak pointer ivars declared by this class.
147147- * The format of this field is the same as the format of the
148148- * strong_pointers field.
149149- */
150150- intptr_t weak_pointers;
151151-};
152152-153153-/**
154154- * Structure representing the old ABI class structure. This is only ever
155155- * required so that we can take its size - struct objc_class begins with the
156156- * same fields, and you can test the new abi flag to tell whether it is safe to
157157- * access the subsequent fields.
158158- */
159159-struct legacy_abi_objc_class
160160-{
161161- struct objc_class *isa;
162162- struct objc_class *super_class;
163163- const char *name;
164164- long version;
165165- unsigned long info;
166166- long instance_size;
167167- struct objc_ivar_list *ivars;
168168- struct objc_method_list *methods;
169169- void *dtable;
170170- struct objc_class *subclass_list;
171171- struct objc_class *sibling_class;
172172- struct objc_protocol_list *protocols;
173173- void *gc_object_type;
174174-};
175175-176176-177177-/**
178178- * An enumerated type describing all of the valid flags that may be used in the
179179- * info field of a class.
180180- */
181181-enum objc_class_flags
182182-{
183183- /** This class structure represents a class. */
184184- objc_class_flag_class = (1<<0),
185185- /** This class structure represents a metaclass. */
186186- objc_class_flag_meta = (1<<1),
187187- /**
188188- * This class has been sent a +initalize message. This message is sent
189189- * exactly once to every class that is sent a message by the runtime, just
190190- * before the first other message is sent.
191191- */
192192- objc_class_flag_initialized = (1<<2),
193193- /**
194194- * The class has been initialized by the runtime. Its super_class pointer
195195- * should now point to a class, rather than a C string containing the class
196196- * name, and its subclass and sibling class links will have been assigned,
197197- * if applicable.
198198- */
199199- objc_class_flag_resolved = (1<<3),
200200- /**
201201- * The class uses the new, Objective-C 2, runtime ABI. This ABI defines an
202202- * ABI version field inside the class, and so will be used for all
203203- * subsequent versions that retain some degree of compatibility.
204204- */
205205- objc_class_flag_new_abi = (1<<4),
206206- /**
207207- * This class was created at run time and may be freed.
208208- */
209209- objc_class_flag_user_created = (1<<5),
210210- /**
211211- * Instances of this class are provide ARC-safe retain / release /
212212- * autorelease implementations.
213213- */
214214- objc_class_flag_fast_arc = (1<<6),
215215- /**
216216- * This class is a hidden class (should not be registered in the class
217217- * table nor returned from object_getClass()).
218218- */
219219- objc_class_flag_hidden_class = (1<<7),
220220- /**
221221- * This class is a hidden class used to store associated values.
222222- */
223223- objc_class_flag_assoc_class = (1<<8)
224224-};
225225-226226-#if 0
227227-228228-/**
229229- * Sets the specific class flag. Note: This is not atomic.
230230- */
231231-static inline void objc_set_class_flag(struct objc_class *aClass,
232232- enum objc_class_flags flag)
233233-{
234234- aClass->info |= (unsigned long)flag;
235235-}
236236-/**
237237- * Unsets the specific class flag. Note: This is not atomic.
238238- */
239239-static inline void objc_clear_class_flag(struct objc_class *aClass,
240240- enum objc_class_flags flag)
241241-{
242242- aClass->info &= ~(unsigned long)flag;
243243-}
244244-/**
245245- * Checks whether a specific class flag is set.
246246- */
247247-static inline BOOL objc_test_class_flag(struct objc_class *aClass,
248248- enum objc_class_flags flag)
249249-{
250250- return (aClass->info & (unsigned long)flag) == (unsigned long)flag;
251251-}
252252-253253-/**
254254- * Adds a class to the class table.
255255- */
256256-void class_table_insert(Class class);
257257-258258-/**
259259- * Array of classes used for small objects. Small objects are embedded in
260260- * their pointer. In 32-bit mode, we have one small object class (typically
261261- * used for storing 31-bit signed integers. In 64-bit mode then we can have 7,
262262- * because classes are guaranteed to be word aligned.
263263- */
264264-extern Class SmallObjectClasses[7];
265265-266266-static BOOL isSmallObject(id obj)
267267-{
268268- uintptr_t addr = ((uintptr_t)obj);
269269- return (addr & OBJC_SMALL_OBJECT_MASK) != 0;
270270-}
271271-272272-__attribute__((always_inline))
273273-static inline Class classForObject(id obj)
274274-{
275275- if (UNLIKELY(isSmallObject(obj)))
276276- {
277277- if (sizeof(Class) == 4)
278278- {
279279- return SmallObjectClasses[0];
280280- }
281281- else
282282- {
283283- uintptr_t addr = ((uintptr_t)obj);
284284- return SmallObjectClasses[(addr & OBJC_SMALL_OBJECT_MASK)];
285285- }
286286- }
287287- return obj->isa;
288288-}
289289-290290-#endif
291291-#endif //__OBJC_CLASS_H_INCLUDED
-105
src/libobjcdarwin/libobjc/properties.h
···11-#include "visibility.h"
22-33-enum PropertyAttributeKind
44-{
55- /**
66- * Property has no attributes.
77- */
88- OBJC_PR_noattr = 0x00,
99- /**
1010- * The property is declared read-only.
1111- */
1212- OBJC_PR_readonly = (1<<0),
1313- /**
1414- * The property has a getter.
1515- */
1616- OBJC_PR_getter = (1<<1),
1717- /**
1818- * The property has assign semantics.
1919- */
2020- OBJC_PR_assign = (1<<2),
2121- /**
2222- * The property is declared read-write.
2323- */
2424- OBJC_PR_readwrite = (1<<3),
2525- /**
2626- * Property has retain semantics.
2727- */
2828- OBJC_PR_retain = (1<<4),
2929- /**
3030- * Property has copy semantics.
3131- */
3232- OBJC_PR_copy = (1<<5),
3333- /**
3434- * Property is marked as non-atomic.
3535- */
3636- OBJC_PR_nonatomic = (1<<6),
3737- /**
3838- * Property has setter.
3939- */
4040- OBJC_PR_setter = (1<<7)
4141-};
4242-4343-/**
4444- * Structure used for property enumeration. Note that property enumeration is
4545- * currently quite broken on OS X, so achieving full compatibility there is
4646- * impossible. Instead, we strive to achieve compatibility with the
4747- * documentation.
4848- */
4949-struct objc_property
5050-{
5151- /**
5252- * Name of this property.
5353- */
5454- const char *name;
5555- /**
5656- * Attributes for this property. Made by ORing together
5757- * PropertyAttributeKinds.
5858- */
5959- char attributes;
6060- /**
6161- * Flag set if the property is synthesized.
6262- */
6363- const char isSynthesized;
6464- /**
6565- * Name of the getter for this property.
6666- */
6767- const char *getter_name;
6868- /**
6969- * Type encoding for the get method for this property.
7070- */
7171- const char *getter_types;
7272- /**
7373- * Name of the set method for this property.
7474- */
7575- const char *setter_name;
7676- /**
7777- * Type encoding of the setter for this property.
7878- */
7979- const char *setter_types;
8080-};
8181-8282-/**
8383- * List of property inrospection data.
8484- */
8585-struct objc_property_list
8686-{
8787- /**
8888- * Number of properties in this array.
8989- */
9090- int count;
9191- /*
9292- * The next property in a linked list.
9393- */
9494- struct objc_property_list *next;
9595- /**
9696- * List of properties.
9797- */
9898- struct objc_property properties[];
9999-};
100100-101101-/**
102102- * Constructs a property description from a list of attributes.
103103- */
104104-PRIVATE struct objc_property propertyFromAttrs(const objc_property_attribute_t *attributes,
105105- unsigned int attributeCount);
-24
src/libobjcdarwin/libobjc/visibility.h
···11-#if defined _WIN32 || defined __CYGWIN__
22-# define PUBLIC __attribute__((dllexport))
33-# define PRIVATE
44-#else
55-# define PUBLIC __attribute__ ((visibility("default")))
66-# define PRIVATE __attribute__ ((visibility("hidden")))
77-#endif
88-#ifdef NO_LEGACY
99-# define LEGACY PRIVATE
1010-#else
1111-# define LEGACY PUBLIC
1212-#endif
1313-1414-#if defined(DEBUG) || (!defined(__clang__))
1515-# include <assert.h>
1616-# define UNREACHABLE(x) assert(0 && x)
1717-# define ASSERT(x) assert(x)
1818-#else
1919-# define UNREACHABLE(x) __builtin_unreachable()
2020-# define ASSERT(x) do { if (x) __builtin_unreachable(); } while(0)
2121-#endif
2222-2323-#define LIKELY(x) __builtin_expect(x, 1)
2424-#define UNLIKELY(x) __builtin_expect(x, 0)
-8
src/libobjcdarwin/misc.mm
···11-#import <Foundation/NSException.h>
22-#include "visibility.h"
33-44-DARLING_VISIBLE extern "C" void objc_enumerationMutation(id obj)
55-{
66- [NSException raise: NSGenericException format: @"Collection %@ was mutated while being enumerated", obj];
77-}
88-
···11-#ifndef OBJC_RETURN_H
22-#define OBJC_RETURN_H
33-44-// Does nothing, but given it's signature, it will actually return
55-// the last return value (contents of eax/rax on x86)
66-extern "C" void* returnReturn();
77-88-#endif
99-
-8
src/libobjcdarwin/new/return.nasm
···11-section .note.GNU-stack noalloc noexec nowrite progbits
22-section text
33-44-global returnReturn
55-66-returnReturn:
77- ret
88-
···11-#ifndef OBJC_EXCEPTIONS_H
22-#define OBJC_EXCEPTIONS_H
33-#include <objc/runtime.h>
44-#include <setjmp.h>
55-#include "../visibility.h"
66-77-// Apple 32-bit ObjC ABI doesn't use Itanium ABI zero-cost exceptions.
88-// Instead, every try block is registered and deregistered, every catch
99-// block is tested for usability with a runtime function call and if no
1010-// match is found, the exception is thrown again to traverse the try
1111-// block chain.
1212-1313-struct TryBlock
1414-{
1515- jmp_buf buffer;
1616-1717- union
1818- {
1919- void* fourPointers[4];
2020-2121- struct
2222- {
2323- objc_object* exceptionObject;
2424- TryBlock* previousBlock;
2525- };
2626- };
2727-};
2828-2929-extern "C" {
3030-3131-// This function is called repeatedly until a handler is found
3232-DARLING_VISIBLE void __darwin_objc_exception_throw(objc_object* object);
3333-3434-// Called on every @try {
3535-DARLING_VISIBLE void objc_exception_try_enter(TryBlock* state);
3636-3737-// Called on every } of a @try block
3838-DARLING_VISIBLE void objc_exception_try_exit(TryBlock* state);
3939-4040-// Called to get the exception object
4141-DARLING_VISIBLE void* objc_exception_extract(TryBlock* state);
4242-4343-// Called to check if the handler's type is appropriate for the exception object
4444-DARLING_VISIBLE int objc_exception_match(objc_class* cls, objc_object* object);
4545-4646-}
4747-4848-#endif
4949-