Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 135 lines (113 sloc) 4.311 kb
5bf56cf @macrotis Use plblockimp to provide imp_implementationWithBlock() for OS X 10.6…
macrotis authored
1 /*
2 * Private Block ABI Structures
3 * Originally acquired frm PLBlocks and compiler_rt
4 *
5 * Copyright 2008 - 2009 Apple, Inc.
6 * Copyright 2009 - 2011 Plausible Labs Cooperative, Inc.
7 *
8 * Permission is hereby granted, free of charge,
9 * to any person obtaining a copy of this software and associated documentation
10 * files (the "Software"), to deal in the Software without restriction,
11 * including without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to permit
13 * persons to whom the Software is furnished to do so, subject to the following
14 * conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 */
28
29 #pragma once
30
31 #if defined(__i386__)
3ee0698 @Watson1978 rename the architecture name to i386 from invalid X86_32
Watson1978 authored
32 # include "blockimp_i386.h"
33 # include "blockimp_i386_stret.h"
5bf56cf @macrotis Use plblockimp to provide imp_implementationWithBlock() for OS X 10.6…
macrotis authored
34 #elif defined(__x86_64__)
35 # include "blockimp_x86_64.h"
36 # include "blockimp_x86_64_stret.h"
37 #elif defined(__arm__)
38 # include "blockimp_arm.h"
39 # include "blockimp_arm_stret.h"
40 #else
41 # error Unknown Architecture
42 #endif
43
44 #pragma mark Fallback Support
45
46 // if 1, we attempt to use Apple's official implementations
47 #define SUPPORT_APPLE_FALLBACK 0
48 #if SUPPORT_APPLE_FALLBACK
49 extern IMP imp_implementationWithBlock(void *block) WEAK_IMPORT_ATTRIBUTE;
50 extern void *imp_getBlock(IMP anImp) WEAK_IMPORT_ATTRIBUTE;
51 extern BOOL imp_removeBlock(IMP anImp) WEAK_IMPORT_ATTRIBUTE;
52 #endif
53
54 /*
55 * Block Flags
56 */
57 typedef enum {
58 /** 16-bit block reference count. */
59 BLOCK_REFCOUNT_MASK = (0xffff),
60
61 BLOCK_NEEDS_FREE = (1 << 24),
62 BLOCK_HAS_COPY_DISPOSE = (1 << 25),
63
64 /** Helpers have C++ code. */
65 BLOCK_HAS_CTOR = (1 << 26),
66
67 BLOCK_IS_GC = (1 << 27),
68 BLOCK_IS_GLOBAL = (1 << 28),
69
70 /** Block returns its aggregate value in memory (ie, the block has a structure return type). */
71 BLOCK_USE_STRET = (1 << 29),
72 } block_flags_t;
73
74
75 /*
76 * Block field flags.
77 */
78 typedef enum {
79 // see function implementation for a more complete description of these fields and combinations
80 BLOCK_FIELD_IS_OBJECT = 3, // id, NSObject, __attribute__((NSObject)), block, ...
81 BLOCK_FIELD_IS_BLOCK = 7, // a block variable
82 BLOCK_FIELD_IS_BYREF = 8, // the on stack structure holding the __block variable
83 BLOCK_FIELD_IS_WEAK = 16, // declared __weak, only used in byref copy helpers
84 BLOCK_BYREF_CALLER = 128, // called from __block (byref) copy/dispose support routines.
85 } block_field_flags_t;
86
87 /*
88 * Block description.
89 *
90 * Block descriptions are shared across all instances of a block, and
91 * provide basic information on the block size, as well as pointers
92 * to any helper functions necessary to copy or dispose of the block.
93 */
94 struct Block_descriptor {
95 /** Reserved value */
96 unsigned long int reserved;
97
98 /** Total size of the described block, including imported variables. */
99 unsigned long int size;
100
101 /** Optional block copy helper. May be NULL. */
102 void (*copy)(void *dst, void *src);
103
104 /** Optional block dispose helper. May be NULL. */
105 void (*dispose)(void *);
106 };
107
108
109 /*
110 * Block instance.
111 *
112 * The block layout defines the per-block instance state, which includes
113 * a reference to the shared block descriptor.
114 *
115 * The block's imported variables are allocated following the block
116 * descriptor member.
117 */
118 struct Block_layout {
119 /** Pointer to the block's Objective-C class. */
120 void *isa;
121
122 /** Block flags. */
123 int flags;
124
125 /** Reserved value. */
126 int reserved;
127
128 /** Block invocation function. */
129 void (*invoke)(void *, ...);
130
131 /** Shared block descriptor. */
132 struct Block_descriptor *descriptor;
133
134 // imported variables
135 };
Something went wrong with that request. Please try again.