Path: blob/main/contrib/llvm-project/compiler-rt/lib/BlocksRuntime/Block_private.h
35260 views
/*1* Block_private.h2*3* Copyright 2008-2010 Apple, Inc. Permission is hereby granted, free of charge,4* to any person obtaining a copy of this software and associated documentation5* files (the "Software"), to deal in the Software without restriction,6* including without limitation the rights to use, copy, modify, merge, publish,7* distribute, sublicense, and/or sell copies of the Software, and to permit8* persons to whom the Software is furnished to do so, subject to the following9* conditions:10*11* The above copyright notice and this permission notice shall be included in12* all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22*/2324#ifndef _BLOCK_PRIVATE_H_25#define _BLOCK_PRIVATE_H_2627#if !defined(BLOCK_EXPORT)28# if defined(__cplusplus)29# define BLOCK_EXPORT extern "C"30# else31# define BLOCK_EXPORT extern32# endif33#endif3435#ifndef _MSC_VER36#include <stdbool.h>37#else38/* MSVC doesn't have <stdbool.h>. Compensate. */39typedef char bool;40#define true (bool)141#define false (bool)042#endif4344#if defined(__cplusplus)45extern "C" {46#endif474849enum {50BLOCK_REFCOUNT_MASK = (0xffff),51BLOCK_NEEDS_FREE = (1 << 24),52BLOCK_HAS_COPY_DISPOSE = (1 << 25),53BLOCK_HAS_CTOR = (1 << 26), /* Helpers have C++ code. */54BLOCK_IS_GC = (1 << 27),55BLOCK_IS_GLOBAL = (1 << 28),56BLOCK_HAS_DESCRIPTOR = (1 << 29)57};585960/* Revised new layout. */61struct Block_descriptor {62unsigned long int reserved;63unsigned long int size;64void (*copy)(void *dst, void *src);65void (*dispose)(void *);66};676869struct Block_layout {70void *isa;71int flags;72int reserved;73void (*invoke)(void *, ...);74struct Block_descriptor *descriptor;75/* Imported variables. */76};777879struct Block_byref {80void *isa;81struct Block_byref *forwarding;82int flags; /* refcount; */83int size;84void (*byref_keep)(struct Block_byref *dst, struct Block_byref *src);85void (*byref_destroy)(struct Block_byref *);86/* long shared[0]; */87};888990struct Block_byref_header {91void *isa;92struct Block_byref *forwarding;93int flags;94int size;95};969798/* Runtime support functions used by compiler when generating copy/dispose helpers. */99100enum {101/* See function implementation for a more complete description of these fields and combinations */102BLOCK_FIELD_IS_OBJECT = 3, /* id, NSObject, __attribute__((NSObject)), block, ... */103BLOCK_FIELD_IS_BLOCK = 7, /* a block variable */104BLOCK_FIELD_IS_BYREF = 8, /* the on stack structure holding the __block variable */105BLOCK_FIELD_IS_WEAK = 16, /* declared __weak, only used in byref copy helpers */106BLOCK_BYREF_CALLER = 128 /* called from __block (byref) copy/dispose support routines. */107};108109/* Runtime entry point called by compiler when assigning objects inside copy helper routines */110BLOCK_EXPORT void _Block_object_assign(void *destAddr, const void *object, const int flags);111/* BLOCK_FIELD_IS_BYREF is only used from within block copy helpers */112113114/* runtime entry point called by the compiler when disposing of objects inside dispose helper routine */115BLOCK_EXPORT void _Block_object_dispose(const void *object, const int flags);116117118119/* Other support functions */120121/* Runtime entry to get total size of a closure */122BLOCK_EXPORT unsigned long int Block_size(void *block_basic);123124125126/* the raw data space for runtime classes for blocks */127/* class+meta used for stack, malloc, and collectable based blocks */128BLOCK_EXPORT void * _NSConcreteStackBlock[32];129BLOCK_EXPORT void * _NSConcreteMallocBlock[32];130BLOCK_EXPORT void * _NSConcreteAutoBlock[32];131BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32];132BLOCK_EXPORT void * _NSConcreteGlobalBlock[32];133BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32];134135136/* the intercept routines that must be used under GC */137BLOCK_EXPORT void _Block_use_GC( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),138void (*setHasRefcount)(const void *, const bool),139void (*gc_assign_strong)(void *, void **),140void (*gc_assign_weak)(const void *, void *),141void (*gc_memmove)(void *, void *, unsigned long));142143/* earlier version, now simply transitional */144BLOCK_EXPORT void _Block_use_GC5( void *(*alloc)(const unsigned long, const bool isOne, const bool isObject),145void (*setHasRefcount)(const void *, const bool),146void (*gc_assign_strong)(void *, void **),147void (*gc_assign_weak)(const void *, void *));148149BLOCK_EXPORT void _Block_use_RR( void (*retain)(const void *),150void (*release)(const void *));151152/* make a collectable GC heap based Block. Not useful under non-GC. */153BLOCK_EXPORT void *_Block_copy_collectable(const void *aBlock);154155/* thread-unsafe diagnostic */156BLOCK_EXPORT const char *_Block_dump(const void *block);157158159/* Obsolete */160161/* first layout */162struct Block_basic {163void *isa;164int Block_flags; /* int32_t */165int Block_size; /* XXX should be packed into Block_flags */166void (*Block_invoke)(void *);167void (*Block_copy)(void *dst, void *src); /* iff BLOCK_HAS_COPY_DISPOSE */168void (*Block_dispose)(void *); /* iff BLOCK_HAS_COPY_DISPOSE */169/* long params[0]; // where const imports, __block storage references, etc. get laid down */170};171172173#if defined(__cplusplus)174}175#endif176177178#endif /* _BLOCK_PRIVATE_H_ */179180181