4 #define OS_CONSUME __attribute__((os_consumed))
5 #define OS_RETURNS_RETAINED __attribute__((os_returns_retained))
6 #define OS_RETURNS_RETAINED_ON_ZERO __attribute__((os_returns_retained_on_zero))
7 #define OS_RETURNS_RETAINED_ON_NONZERO __attribute__((os_returns_retained_on_non_zero))
8 #define OS_RETURNS_NOT_RETAINED __attribute__((os_returns_not_retained))
9 #define OS_CONSUMES_THIS __attribute__((os_consumes_this))
11 #define OSTypeID(type) (type::metaClass)
13 #define OSDynamicCast(type, inst) \
14 ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
15 #define OSRequiredCast(type, inst) \
16 ((type *) OSMetaClassBase::requiredMetaCast((inst), OSTypeID(type)))
18 #define OSTypeAlloc(type) ((type *) ((type::metaClass)->alloc()))
20 using size_t = decltype(sizeof(int));
22 typedef int kern_return_t
;
27 struct OSMetaClassBase
{
28 static OSMetaClassBase
*safeMetaCast(const OSMetaClassBase
*inst
,
29 const OSMetaClass
*meta
);
30 static OSMetaClassBase
*requiredMetaCast(const OSMetaClassBase
*inst
,
31 const OSMetaClass
*meta
);
33 OSMetaClassBase
*metaCast(const char *toMeta
);
35 virtual void retain() const;
36 virtual void release() const;
38 virtual void taggedRetain(const void * tag
= nullptr) const;
39 virtual void taggedRelease(const void * tag
= nullptr) const;
42 virtual ~OSMetaClassBase(){};
44 kern_return_t
Invoke(IORPC invoke
);
47 typedef kern_return_t (*OSDispatchMethod
)(OSMetaClassBase
*self
,
50 struct OSObject
: public OSMetaClassBase
{
53 unsigned int foo() { return 42; }
55 virtual OS_RETURNS_NOT_RETAINED OSObject
*identity();
57 static OSObject
*generateObject(int);
59 static OSObject
*getObject();
60 static OSObject
*GetObject();
62 static void * operator new(size_t size
);
64 static const OSMetaClass
* const metaClass
;
67 struct OSMetaClass
: public OSMetaClassBase
{
68 virtual OSObject
* alloc() const;
69 static OSObject
* allocClassWithName(const char * name
);
70 static const OSMetaClass
*copyMetaClassWithName(const char *name
);
71 void releaseMetaClass() const;
72 virtual ~OSMetaClass(){}
75 #endif /* _OS_BASE_H */