2019-01-19 03:24:55 +08:00
|
|
|
#ifndef _OS_BASE_H
|
|
|
|
#define _OS_BASE_H
|
|
|
|
|
|
|
|
#define OS_CONSUME __attribute__((os_consumed))
|
|
|
|
#define OS_RETURNS_RETAINED __attribute__((os_returns_retained))
|
|
|
|
#define OS_RETURNS_RETAINED_ON_ZERO __attribute__((os_returns_retained_on_zero))
|
|
|
|
#define OS_RETURNS_RETAINED_ON_NONZERO __attribute__((os_returns_retained_on_non_zero))
|
|
|
|
#define OS_RETURNS_NOT_RETAINED __attribute__((os_returns_not_retained))
|
|
|
|
#define OS_CONSUMES_THIS __attribute__((os_consumes_this))
|
|
|
|
|
|
|
|
#define OSTypeID(type) (type::metaClass)
|
|
|
|
|
|
|
|
#define OSDynamicCast(type, inst) \
|
|
|
|
((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
|
2019-06-20 07:33:34 +08:00
|
|
|
#define OSRequiredCast(type, inst) \
|
|
|
|
((type *) OSMetaClassBase::requiredMetaCast((inst), OSTypeID(type)))
|
2019-01-19 03:24:55 +08:00
|
|
|
|
|
|
|
#define OSTypeAlloc(type) ((type *) ((type::metaClass)->alloc()))
|
|
|
|
|
|
|
|
using size_t = decltype(sizeof(int));
|
|
|
|
|
2019-06-20 07:33:39 +08:00
|
|
|
typedef int kern_return_t;
|
|
|
|
struct IORPC {};
|
|
|
|
|
2019-01-19 03:24:55 +08:00
|
|
|
struct OSMetaClass;
|
|
|
|
|
|
|
|
struct OSMetaClassBase {
|
|
|
|
static OSMetaClassBase *safeMetaCast(const OSMetaClassBase *inst,
|
|
|
|
const OSMetaClass *meta);
|
2019-06-20 07:33:34 +08:00
|
|
|
static OSMetaClassBase *requiredMetaCast(const OSMetaClassBase *inst,
|
|
|
|
const OSMetaClass *meta);
|
2019-01-19 03:24:55 +08:00
|
|
|
|
2019-01-23 03:50:47 +08:00
|
|
|
OSMetaClassBase *metaCast(const char *toMeta);
|
|
|
|
|
2019-01-19 03:24:55 +08:00
|
|
|
virtual void retain() const;
|
|
|
|
virtual void release() const;
|
2019-01-30 03:29:07 +08:00
|
|
|
|
|
|
|
virtual void taggedRetain(const void * tag = nullptr) const;
|
|
|
|
virtual void taggedRelease(const void * tag = nullptr) const;
|
|
|
|
|
2019-01-19 03:24:55 +08:00
|
|
|
virtual void free();
|
|
|
|
virtual ~OSMetaClassBase(){};
|
2019-06-20 07:33:39 +08:00
|
|
|
|
|
|
|
kern_return_t Invoke(IORPC invoke);
|
2019-01-19 03:24:55 +08:00
|
|
|
};
|
|
|
|
|
2019-06-20 07:33:39 +08:00
|
|
|
typedef kern_return_t (*OSDispatchMethod)(OSMetaClassBase *self,
|
|
|
|
const IORPC rpc);
|
|
|
|
|
2019-01-19 03:24:55 +08:00
|
|
|
struct OSObject : public OSMetaClassBase {
|
|
|
|
virtual ~OSObject(){}
|
|
|
|
|
|
|
|
unsigned int foo() { return 42; }
|
|
|
|
|
|
|
|
virtual OS_RETURNS_NOT_RETAINED OSObject *identity();
|
|
|
|
|
|
|
|
static OSObject *generateObject(int);
|
|
|
|
|
|
|
|
static OSObject *getObject();
|
|
|
|
static OSObject *GetObject();
|
|
|
|
|
|
|
|
static void * operator new(size_t size);
|
|
|
|
|
|
|
|
static const OSMetaClass * const metaClass;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OSMetaClass : public OSMetaClassBase {
|
|
|
|
virtual OSObject * alloc() const;
|
|
|
|
virtual ~OSMetaClass(){}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _OS_BASE_H */
|