123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336 |
- #if !__OBJC2__
- #include "objc-private.h"
- #include "objc-runtime-old.h"
- #include "objc-file-old.h"
- #include "objc-cache-old.h"
- #include "objc-loadmethod.h"
- typedef struct _objc_unresolved_category
- {
- struct _objc_unresolved_category *next;
- old_category *cat;
- long version;
- } _objc_unresolved_category;
- typedef struct _PendingSubclass
- {
- Class subclass;
- struct _PendingSubclass *next;
- } PendingSubclass;
- typedef struct _PendingClassRef
- {
- Class *ref;
-
- struct _PendingClassRef *next;
- } PendingClassRef;
- static uintptr_t classHash(void *info, Class data);
- static int classIsEqual(void *info, Class name, Class cls);
- static int _objc_defaultClassHandler(const char *clsName);
- static inline NXMapTable *pendingClassRefsMapTable(void);
- static inline NXMapTable *pendingSubclassesMapTable(void);
- static void pendClassInstallation(Class cls, const char *superName);
- static void pendClassReference(Class *ref, const char *className, bool isMeta);
- static void resolve_references_to_class(Class cls);
- static void resolve_subclasses_of_class(Class cls);
- static void really_connect_class(Class cls, Class supercls);
- static bool connect_class(Class cls);
- static void map_method_descs (struct objc_method_description_list * methods, bool copy);
- static void _objcTweakMethodListPointerForClass(Class cls);
- static inline void _objc_add_category(Class cls, old_category *category, int version);
- static bool _objc_add_category_flush_caches(Class cls, old_category *category, int version);
- static _objc_unresolved_category *reverse_cat(_objc_unresolved_category *cat);
- static void resolve_categories_for_class(Class cls);
- static bool _objc_register_category(old_category *cat, int version);
- void (*callbackFunction)(Class, Category) = 0;
- NXHashTable * class_hash = 0;
- static NXHashTablePrototype classHashPrototype =
- {
- (uintptr_t (*) (const void *, const void *)) classHash,
- (int (*)(const void *, const void *, const void *)) classIsEqual,
- NXNoEffectFree, 0
- };
- static NXHashTable *unconnected_class_hash = nil;
- NXHashTable *_objc_debug_class_hash = nil;
- static NXMapTable * category_hash = nil;
- static NXMapTable * pendingClassRefsMap = nil;
- static NXMapTable * pendingSubclassesMap = nil;
- static NXMapTable *protocol_map = nil;
- static NXMapTable *protocol_ext_map = nil;
- static int (*objc_classHandler) (const char *) = _objc_defaultClassHandler;
- static BOOL (*_objc_classLoader)(const char *) = nil;
- void objc_dump_class_hash(void)
- {
- NXHashTable *table;
- unsigned count;
- Class data;
- NXHashState state;
- table = class_hash;
- count = 0;
- state = NXInitHashState (table);
- while (NXNextHashState (table, &state, (void **) &data))
- printf ("class %d: %s\n", ++count, data->nameForLogging());
- }
- void _objc_init_class_hash(void)
- {
-
- if (class_hash)
- return;
-
-
-
-
-
-
-
- class_hash = NXCreateHashTable(classHashPrototype, 16, nil);
- _objc_debug_class_hash = class_hash;
- }
- int objc_getClassList(Class *buffer, int bufferLen)
- {
- NXHashState state;
- Class cls;
- int cnt, num;
- mutex_locker_t lock(classLock);
- if (!class_hash) return 0;
- num = NXCountHashTable(class_hash);
- if (nil == buffer) return num;
- cnt = 0;
- state = NXInitHashState(class_hash);
- while (cnt < bufferLen &&
- NXNextHashState(class_hash, &state, (void **)&cls))
- {
- buffer[cnt++] = cls;
- }
- return num;
- }
- Class *
- objc_copyClassList(unsigned int *outCount)
- {
- Class *result;
- unsigned int count;
- mutex_locker_t lock(classLock);
- result = nil;
- count = class_hash ? NXCountHashTable(class_hash) : 0;
- if (count > 0) {
- Class cls;
- NXHashState state = NXInitHashState(class_hash);
- result = (Class *)malloc((1+count) * sizeof(Class));
- count = 0;
- while (NXNextHashState(class_hash, &state, (void **)&cls)) {
- result[count++] = cls;
- }
- result[count] = nil;
- }
-
- if (outCount) *outCount = count;
- return result;
- }
- Protocol * __unsafe_unretained *
- objc_copyProtocolList(unsigned int *outCount)
- {
- int count, i;
- Protocol *proto;
- const char *name;
- NXMapState state;
- Protocol **result;
- mutex_locker_t lock(classLock);
- count = NXCountMapTable(protocol_map);
- if (count == 0) {
- if (outCount) *outCount = 0;
- return nil;
- }
- result = (Protocol **)calloc(1 + count, sizeof(Protocol *));
- i = 0;
- state = NXInitMapState(protocol_map);
- while (NXNextMapState(protocol_map, &state,
- (const void **)&name, (const void **)&proto))
- {
- result[i++] = proto;
- }
-
- result[i++] = nil;
- assert(i == count+1);
- if (outCount) *outCount = count;
- return result;
- }
- void *objc_getClasses(void)
- {
- OBJC_WARN_DEPRECATED;
-
- return class_hash;
- }
- static uintptr_t classHash(void *info, Class data)
- {
-
- if (!data)
- return 0;
-
- return _objc_strhash (data->mangledName());
- }
- static int classIsEqual(void *info, Class name, Class cls)
- {
-
- return strcmp(name->mangledName(), cls->mangledName()) == 0;
- }
- static NXHashTable *future_class_hash = nil;
- static NXMapTable *future_class_to_original_class_map = nil;
- static NXMapTable *original_class_to_future_class_map = nil;
- #define FUTURE_COUNT 32
- static void setOriginalClassForFutureClass(Class futureClass,
- Class originalClass)
- {
- if (!future_class_to_original_class_map) {
- future_class_to_original_class_map =
- NXCreateMapTable(NXPtrValueMapPrototype, FUTURE_COUNT);
- original_class_to_future_class_map =
- NXCreateMapTable(NXPtrValueMapPrototype, FUTURE_COUNT);
- }
- NXMapInsert (future_class_to_original_class_map,
- futureClass, originalClass);
- NXMapInsert (original_class_to_future_class_map,
- originalClass, futureClass);
- if (PrintFuture) {
- _objc_inform("FUTURE: using %p instead of %p for %s", (void*)futureClass, (void*)originalClass, originalClass->name);
- }
- }
- static Class
- getFutureClassForOriginalClass(Class originalClass)
- {
- if (!original_class_to_future_class_map) return Nil;
- return (Class)NXMapGet(original_class_to_future_class_map, originalClass);
- }
- static void makeFutureClass(Class cls, const char *name)
- {
-
- if (!future_class_hash) {
- future_class_hash =
- NXCreateHashTable(classHashPrototype, FUTURE_COUNT, nil);
- }
- cls->name = strdup(name);
- NXHashInsert(future_class_hash, cls);
- if (PrintFuture) {
- _objc_inform("FUTURE: reserving %p for %s", (void*)cls, name);
- }
- }
- Class _objc_allocateFutureClass(const char *name)
- {
- Class cls;
- if (future_class_hash) {
- objc_class query;
- query.name = name;
- if ((cls = (Class)NXHashGet(future_class_hash, &query))) {
-
- return cls;
- }
- }
- cls = _calloc_class(sizeof(objc_class));
- makeFutureClass(cls, name);
- return cls;
- }
- Class objc_getFutureClass(const char *name)
- {
- Class cls;
-
-
- cls = look_up_class(name, YES, NO);
- if (cls) {
- if (PrintFuture) {
- _objc_inform("FUTURE: found %p already in use for %s",
- (void*)cls, name);
- }
- return cls;
- }
-
-
-
-
- return _objc_allocateFutureClass(name);
- }
- BOOL _class_isFutureClass(Class cls)
- {
- return cls && cls->isFuture();
- }
- bool objc_class::isFuture()
- {
- return future_class_hash && NXHashGet(future_class_hash, this);
- }
- static int _objc_defaultClassHandler(const char *clsName)
- {
-
- return 0;
- }
- void objc_setClassHandler(int (*userSuppliedHandler)(const char *))
- {
- OBJC_WARN_DEPRECATED;
- objc_classHandler = userSuppliedHandler;
- }
- void _objc_setClassLoader(BOOL (*newClassLoader)(const char *))
- {
- _objc_classLoader = newClassLoader;
- }
- Protocol *objc_getProtocol(const char *name)
- {
- mutex_locker_t lock(classLock);
- if (!protocol_map) return nil;
- return (Protocol *)NXMapGet(protocol_map, name);
- }
- Class look_up_class(const char *aClassName, bool includeUnconnected,
- bool includeClassHandler)
- {
- bool includeClassLoader = YES;
- Class result = nil;
- struct objc_class query;
- query.name = aClassName;
- retry:
- if (!result && class_hash) {
-
- mutex_locker_t lock(classLock);
- result = (Class)NXHashGet(class_hash, &query);
- }
- if (!result && includeUnconnected && unconnected_class_hash) {
-
- mutex_locker_t lock(classLock);
- result = (Class)NXHashGet(unconnected_class_hash, &query);
- }
- if (!result && includeClassLoader && _objc_classLoader) {
-
- if ((*_objc_classLoader)(aClassName)) {
-
- includeClassLoader = NO;
- goto retry;
- }
- }
- if (!result && includeClassHandler && objc_classHandler) {
-
- if ((*objc_classHandler)(aClassName)) {
-
- includeClassLoader = NO;
- includeClassHandler = NO;
- goto retry;
- }
- }
- return result;
- }
- bool objc_class::isConnected()
- {
- mutex_locker_t lock(classLock);
- return NXHashMember(class_hash, this);
- }
- static inline NXMapTable *pendingClassRefsMapTable(void)
- {
-
- if (!pendingClassRefsMap) {
- pendingClassRefsMap = NXCreateMapTable(NXStrValueMapPrototype, 10);
- }
-
-
- return pendingClassRefsMap;
- }
- static inline NXMapTable *pendingSubclassesMapTable(void)
- {
-
- if (!pendingSubclassesMap) {
- pendingSubclassesMap = NXCreateMapTable(NXStrValueMapPrototype, 10);
- }
-
-
- return pendingSubclassesMap;
- }
- static void pendClassInstallation(Class cls, const char *superName)
- {
- NXMapTable *table;
- PendingSubclass *pending;
- PendingSubclass *oldList;
- PendingSubclass *l;
-
-
- table = pendingSubclassesMapTable ();
-
- oldList = (PendingSubclass *)NXMapGet(table, superName);
- for (l = oldList; l != nil; l = l->next) {
- if (l->subclass == cls) return;
- }
-
-
- pending = (PendingSubclass *)malloc(sizeof(PendingSubclass));
- pending->subclass = cls;
-
-
- pending->next = oldList;
-
-
- NXMapKeyCopyingInsert (table, superName, pending);
- }
- static void pendClassReference(Class *ref, const char *className, bool isMeta)
- {
- NXMapTable *table;
- PendingClassRef *pending;
-
-
- table = pendingClassRefsMapTable ();
-
-
- pending = (PendingClassRef *)malloc(sizeof(PendingClassRef));
- pending->ref = ref;
- if (isMeta) {
- pending->ref = (Class *)((uintptr_t)pending->ref | 1);
- }
-
-
- pending->next = (PendingClassRef *)NXMapGet(table, className);
-
-
- NXMapKeyCopyingInsert (table, className, pending);
- if (PrintConnecting) {
- _objc_inform("CONNECT: pended reference to class '%s%s' at %p",
- className, isMeta ? " (meta)" : "", (void *)ref);
- }
- }
- static void resolve_references_to_class(Class cls)
- {
- PendingClassRef *pending;
-
- if (!pendingClassRefsMap) return;
- pending = (PendingClassRef *)NXMapGet(pendingClassRefsMap, cls->name);
- if (!pending) return;
- NXMapKeyFreeingRemove(pendingClassRefsMap, cls->name);
- if (PrintConnecting) {
- _objc_inform("CONNECT: resolving references to class '%s'", cls->name);
- }
- while (pending) {
- PendingClassRef *next = pending->next;
- if (pending->ref) {
- bool isMeta = (uintptr_t)pending->ref & 1;
- Class *ref =
- (Class *)((uintptr_t)pending->ref & ~(uintptr_t)1);
- *ref = isMeta ? cls->ISA() : cls;
- }
- free(pending);
- pending = next;
- }
- if (NXCountMapTable(pendingClassRefsMap) == 0) {
- NXFreeMapTable(pendingClassRefsMap);
- pendingClassRefsMap = nil;
- }
- }
- static void resolve_subclasses_of_class(Class cls)
- {
- PendingSubclass *pending;
-
- if (!pendingSubclassesMap) return;
- pending = (PendingSubclass *)NXMapGet(pendingSubclassesMap, cls->name);
- if (!pending) return;
- NXMapKeyFreeingRemove(pendingSubclassesMap, cls->name);
-
- if (NXCountMapTable(pendingSubclassesMap) == 0) {
- NXFreeMapTable(pendingSubclassesMap);
- pendingSubclassesMap = nil;
- }
- if (PrintConnecting) {
- _objc_inform("CONNECT: resolving subclasses of class '%s'", cls->name);
- }
- while (pending) {
- PendingSubclass *next = pending->next;
- if (pending->subclass) connect_class(pending->subclass);
- free(pending);
- pending = next;
- }
- }
- static void really_connect_class(Class cls,
- Class supercls)
- {
- Class oldCls;
-
- set_superclass(cls, supercls, YES);
-
- cls->info |= CLS_CONNECTED;
- {
- mutex_locker_t lock(classLock);
-
-
- NXHashRemove(unconnected_class_hash, cls);
- oldCls = (Class)NXHashInsert(class_hash, cls);
-
-
- if (NXCountHashTable(unconnected_class_hash) == 0) {
- NXFreeHashTable(unconnected_class_hash);
- unconnected_class_hash = nil;
- }
-
-
-
- assert(!oldCls);
- }
-
-
- resolve_references_to_class(cls);
-
- resolve_subclasses_of_class(cls);
-
-
-
-
- if (DebugFragileSuperclasses && cls->ivars && cls->ivars->ivar_count) {
- Class ivar_cls = supercls;
-
- while (ivar_cls &&
- (!ivar_cls->ivars || ivar_cls->ivars->ivar_count == 0))
- {
- ivar_cls = ivar_cls->superclass;
- }
- if (ivar_cls) {
-
- old_ivar *super_ivar =
- &ivar_cls->ivars->ivar_list[ivar_cls->ivars->ivar_count - 1];
- old_ivar *self_ivar =
- &cls->ivars->ivar_list[0];
-
- if (self_ivar->ivar_offset <= super_ivar->ivar_offset) {
- _objc_inform("WARNING: ivars of superclass '%s' and "
- "subclass '%s' overlap; superclass may have "
- "changed since subclass was compiled",
- ivar_cls->name, cls->name);
- }
- }
- }
- }
- static bool connect_class(Class cls)
- {
- if (cls->isConnected()) {
-
-
- return TRUE;
- }
- else if (cls->superclass == nil) {
-
-
- if (PrintConnecting) {
- _objc_inform("CONNECT: class '%s' now connected (root class)",
- cls->name);
- }
- really_connect_class(cls, nil);
- return TRUE;
- }
- else {
-
-
-
-
-
- char *supercls_name = (char *)cls->superclass;
- Class supercls;
-
- if (nil == (supercls = look_up_class(supercls_name, YES, YES))) {
-
-
- pendClassInstallation(cls, supercls_name);
- if (PrintConnecting) {
- _objc_inform("CONNECT: class '%s' NOT connected (missing super)", cls->name);
- }
- return FALSE;
- }
-
- if (! connect_class(supercls)) {
-
-
- pendClassInstallation(cls, supercls_name);
- if (PrintConnecting) {
- _objc_inform("CONNECT: class '%s' NOT connected (unconnected super)", cls->name);
- }
- return FALSE;
- }
-
-
-
- if (PrintConnecting) {
- _objc_inform("CONNECT: class '%s' now connected", cls->name);
- }
- really_connect_class(cls, supercls);
- return TRUE;
- }
- }
- static bool _objc_read_categories_from_image (header_info * hi)
- {
- Module mods;
- size_t midx;
- bool needFlush = NO;
- if (hi->info()->isReplacement()) {
-
- return NO;
- }
-
- mods = hi->mod_ptr;
-
-
-
- midx = hi->mod_count;
- while (midx-- > 0) {
- unsigned int index;
- unsigned int total;
-
-
- if (mods[midx].symtab == nil)
- continue;
-
-
-
- total = mods[midx].symtab->cls_def_cnt +
- mods[midx].symtab->cat_def_cnt;
-
-
- index = total;
- while (index-- > mods[midx].symtab->cls_def_cnt) {
- old_category *cat = (old_category *)mods[midx].symtab->defs[index];
- needFlush |= _objc_register_category(cat, (int)mods[midx].version);
- }
- }
- return needFlush;
- }
- static void _objc_read_classes_from_image(header_info *hi)
- {
- unsigned int index;
- unsigned int midx;
- Module mods;
- int isBundle = headerIsBundle(hi);
- if (hi->info()->isReplacement()) {
-
- return;
- }
-
-
-
-
- {
- mutex_locker_t lock(classLock);
- if (hi->mhdr() != libobjc_header && _NXHashCapacity(class_hash) < 1024) {
- _NXHashRehashToCapacity(class_hash, 1024);
- }
- }
-
- mods = hi->mod_ptr;
- for (midx = 0; midx < hi->mod_count; midx += 1)
- {
-
- if (mods[midx].symtab == nil)
- continue;
-
- for (index = 0; index < mods[midx].symtab->cls_def_cnt; index += 1)
- {
- Class newCls, oldCls;
- bool rejected;
-
- newCls = (Class)mods[midx].symtab->defs[index];
-
-
- if (isBundle) newCls->info |= CLS_FROM_BUNDLE;
- if (isBundle) newCls->ISA()->info |= CLS_FROM_BUNDLE;
-
- if (newCls->cache == nil)
- newCls->cache = (Cache) &_objc_empty_cache;
- if (newCls->ISA()->cache == nil)
- newCls->ISA()->cache = (Cache) &_objc_empty_cache;
-
- newCls->ISA()->version = mods[midx].version;
-
- newCls->info |= CLS_NO_METHOD_ARRAY|CLS_NO_PROPERTY_ARRAY;
- newCls->ISA()->info |= CLS_NO_METHOD_ARRAY|CLS_NO_PROPERTY_ARRAY;
-
- newCls->info |= CLS_LEAF;
- newCls->ISA()->info |= CLS_LEAF;
- if (mods[midx].version >= 6) {
-
- newCls->info |= CLS_EXT;
- newCls->ISA()->info |= CLS_EXT;
- }
-
- if (_class_hasLoadMethod(newCls)) {
- newCls->ISA()->info |= CLS_HAS_LOAD_METHOD;
- }
-
- {
- mutex_locker_t lock(classLock);
- if (future_class_hash) {
- Class futureCls = (Class)
- NXHashRemove(future_class_hash, newCls);
- if (futureCls) {
-
-
- free((char *)futureCls->name);
- memcpy(futureCls, newCls, sizeof(objc_class));
- setOriginalClassForFutureClass(futureCls, newCls);
- newCls = futureCls;
-
- if (NXCountHashTable(future_class_hash) == 0) {
- NXFreeHashTable(future_class_hash);
- future_class_hash = nil;
- }
- }
- }
-
- if (!unconnected_class_hash) {
- unconnected_class_hash =
- NXCreateHashTable(classHashPrototype, 128, nil);
- }
-
- if ((oldCls = (Class)NXHashGet(class_hash, newCls)) ||
- (oldCls = (Class)NXHashGet(unconnected_class_hash, newCls)))
- {
-
- inform_duplicate(newCls->name, oldCls, newCls);
- rejected = YES;
- }
- else {
- NXHashInsert(unconnected_class_hash, newCls);
- rejected = NO;
- }
- }
- if (!rejected) {
-
- resolve_categories_for_class(newCls);
- }
- }
- }
- }
- static void _objc_connect_classes_from_image(header_info *hi)
- {
- unsigned int index;
- unsigned int midx;
- Module mods;
- bool replacement = hi->info()->isReplacement();
-
- mods = hi->mod_ptr;
- for (midx = 0; midx < hi->mod_count; midx += 1)
- {
-
- if (mods[midx].symtab == nil)
- continue;
-
- for (index = 0; index < mods[midx].symtab->cls_def_cnt; index += 1)
- {
- Class cls = (Class)mods[midx].symtab->defs[index];
- if (! replacement) {
- bool connected;
- Class futureCls = getFutureClassForOriginalClass(cls);
- if (futureCls) {
-
-
-
-
- const char *super_name = (const char *) cls->superclass;
- if (super_name) cls->superclass = objc_getClass(super_name);
- cls = futureCls;
- }
- connected = connect_class(cls);
- if (connected && callbackFunction) {
- (*callbackFunction)(cls, 0);
- }
- } else {
-
-
- const char *super_name = (const char *) cls->superclass;
- if (super_name) {
- cls->superclass = objc_getClass(super_name);
-
- cls->ISA()->superclass = cls->superclass->ISA();
- } else {
-
-
-
- cls->ISA()->superclass = cls;
- }
- }
- }
- }
- }
- static void fix_class_ref(Class *ref, const char *name, bool isMeta)
- {
- Class cls;
-
-
-
- cls = look_up_class(name, NO, YES);
- if (cls) {
-
- *ref = isMeta ? cls->ISA() : cls;
- } else {
-
-
- pendClassReference (ref, name, isMeta);
- *ref = nil;
- }
- }
- static void _objc_map_class_refs_for_image (header_info * hi)
- {
- Class *cls_refs;
- size_t count;
- unsigned int index;
-
- cls_refs = _getObjcClassRefs (hi, &count);
- if (cls_refs) {
-
- for (index = 0; index < count; index += 1) {
-
- const char *name = (const char *) cls_refs[index];
- if (!name) continue;
- fix_class_ref(&cls_refs[index], name, NO );
- }
- }
- }
- static void removePendingReferences(Class *refs, size_t count)
- {
- Class *end = refs + count;
- if (!refs) return;
- if (!pendingClassRefsMap) return;
-
-
-
- {
- const char *key;
- PendingClassRef *pending;
- NXMapState state = NXInitMapState(pendingClassRefsMap);
- while(NXNextMapState(pendingClassRefsMap, &state,
- (const void **)&key, (const void **)&pending))
- {
- for ( ; pending != nil; pending = pending->next) {
- if (pending->ref >= refs && pending->ref < end) {
- pending->ref = nil;
- }
- }
- }
- }
- }
- static void _objc_remove_pending_class_refs_in_image(header_info *hi)
- {
- Class *cls_refs;
- size_t count;
-
- cls_refs = _getObjcClassRefs(hi, &count);
- removePendingReferences(cls_refs, count);
- }
- static inline void map_selrefs(SEL *sels, size_t count, bool copy)
- {
- size_t index;
- if (!sels) return;
- mutex_locker_t lock(selLock);
-
- for (index = 0; index < count; index += 1)
- {
- SEL sel;
-
- sel = sel_registerNameNoLock((const char *) sels[index], copy);
-
-
- if (sels[index] != sel) {
- sels[index] = sel;
- }
- }
- }
- static void map_method_descs (struct objc_method_description_list * methods, bool copy)
- {
- int index;
- if (!methods) return;
- mutex_locker_t lock(selLock);
-
- for (index = 0; index < methods->count; index += 1)
- {
- struct objc_method_description * method;
- SEL sel;
-
- method = &methods->list[index];
-
- sel = sel_registerNameNoLock((const char *) method->name, copy);
-
-
- if (method->name != sel)
- method->name = sel;
- }
- }
- static old_protocol_ext *ext_for_protocol(old_protocol *proto)
- {
- if (!proto) return nil;
- if (!protocol_ext_map) return nil;
- else return (old_protocol_ext *)NXMapGet(protocol_ext_map, proto);
- }
- static struct objc_method_description *
- lookup_method(struct objc_method_description_list *mlist, SEL aSel)
- {
- if (mlist) {
- int i;
- for (i = 0; i < mlist->count; i++) {
- if (mlist->list[i].name == aSel) {
- return mlist->list+i;
- }
- }
- }
- return nil;
- }
- struct objc_method_description *
- lookup_protocol_method(old_protocol *proto, SEL aSel,
- bool isRequiredMethod, bool isInstanceMethod,
- bool recursive)
- {
- struct objc_method_description *m = nil;
- old_protocol_ext *ext;
- if (isRequiredMethod) {
- if (isInstanceMethod) {
- m = lookup_method(proto->instance_methods, aSel);
- } else {
- m = lookup_method(proto->class_methods, aSel);
- }
- } else if ((ext = ext_for_protocol(proto))) {
- if (isInstanceMethod) {
- m = lookup_method(ext->optional_instance_methods, aSel);
- } else {
- m = lookup_method(ext->optional_class_methods, aSel);
- }
- }
- if (!m && recursive && proto->protocol_list) {
- int i;
- for (i = 0; !m && i < proto->protocol_list->count; i++) {
- m = lookup_protocol_method(proto->protocol_list->list[i], aSel,
- isRequiredMethod,isInstanceMethod,true);
- }
- }
- return m;
- }
- const char *protocol_getName(Protocol *p)
- {
- old_protocol *proto = oldprotocol(p);
- if (!proto) return "nil";
- return proto->protocol_name;
- }
- struct objc_method_description
- protocol_getMethodDescription(Protocol *p, SEL aSel,
- BOOL isRequiredMethod, BOOL isInstanceMethod)
- {
- struct objc_method_description empty = {nil, nil};
- old_protocol *proto = oldprotocol(p);
- struct objc_method_description *desc;
- if (!proto) return empty;
- desc = lookup_protocol_method(proto, aSel,
- isRequiredMethod, isInstanceMethod, true);
- if (desc) return *desc;
- else return empty;
- }
- struct objc_method_description *
- protocol_copyMethodDescriptionList(Protocol *p,
- BOOL isRequiredMethod,
- BOOL isInstanceMethod,
- unsigned int *outCount)
- {
- struct objc_method_description_list *mlist = nil;
- old_protocol *proto = oldprotocol(p);
- old_protocol_ext *ext;
- unsigned int i, count;
- struct objc_method_description *result;
- if (!proto) {
- if (outCount) *outCount = 0;
- return nil;
- }
- if (isRequiredMethod) {
- if (isInstanceMethod) {
- mlist = proto->instance_methods;
- } else {
- mlist = proto->class_methods;
- }
- } else if ((ext = ext_for_protocol(proto))) {
- if (isInstanceMethod) {
- mlist = ext->optional_instance_methods;
- } else {
- mlist = ext->optional_class_methods;
- }
- }
- if (!mlist) {
- if (outCount) *outCount = 0;
- return nil;
- }
-
- count = mlist->count;
- result = (struct objc_method_description *)
- calloc(count + 1, sizeof(struct objc_method_description));
- for (i = 0; i < count; i++) {
- result[i] = mlist->list[i];
- }
- if (outCount) *outCount = count;
- return result;
- }
- objc_property_t
- protocol_getProperty(Protocol *p, const char *name,
- BOOL isRequiredProperty, BOOL isInstanceProperty)
- {
- old_protocol *proto = oldprotocol(p);
- old_protocol_ext *ext;
- old_protocol_list *proto_list;
- if (!proto || !name) return nil;
-
- if (!isRequiredProperty) {
-
- return nil;
- }
- if ((ext = ext_for_protocol(proto))) {
- old_property_list *plist;
- if (isInstanceProperty) plist = ext->instance_properties;
- else if (ext->hasClassPropertiesField()) plist = ext->class_properties;
- else plist = nil;
- if (plist) {
- uint32_t i;
- for (i = 0; i < plist->count; i++) {
- old_property *prop = property_list_nth(plist, i);
- if (0 == strcmp(name, prop->name)) {
- return (objc_property_t)prop;
- }
- }
- }
- }
- if ((proto_list = proto->protocol_list)) {
- int i;
- for (i = 0; i < proto_list->count; i++) {
- objc_property_t prop =
- protocol_getProperty((Protocol *)proto_list->list[i], name,
- isRequiredProperty, isInstanceProperty);
- if (prop) return prop;
- }
- }
-
- return nil;
- }
- objc_property_t *
- protocol_copyPropertyList2(Protocol *p, unsigned int *outCount,
- BOOL isRequiredProperty, BOOL isInstanceProperty)
- {
- old_property **result = nil;
- old_protocol_ext *ext;
- old_property_list *plist;
-
- old_protocol *proto = oldprotocol(p);
- if (! (ext = ext_for_protocol(proto)) || !isRequiredProperty) {
-
- if (outCount) *outCount = 0;
- return nil;
- }
- if (isInstanceProperty) plist = ext->instance_properties;
- else if (ext->hasClassPropertiesField()) plist = ext->class_properties;
- else plist = nil;
- result = copyPropertyList(plist, outCount);
-
- return (objc_property_t *)result;
- }
- objc_property_t *protocol_copyPropertyList(Protocol *p, unsigned int *outCount)
- {
- return protocol_copyPropertyList2(p, outCount, YES, YES);
- }
- Protocol * __unsafe_unretained *
- protocol_copyProtocolList(Protocol *p, unsigned int *outCount)
- {
- unsigned int count = 0;
- Protocol **result = nil;
- old_protocol *proto = oldprotocol(p);
-
- if (!proto) {
- if (outCount) *outCount = 0;
- return nil;
- }
- if (proto->protocol_list) {
- count = (unsigned int)proto->protocol_list->count;
- }
- if (count > 0) {
- unsigned int i;
- result = (Protocol **)malloc((count+1) * sizeof(Protocol *));
- for (i = 0; i < count; i++) {
- result[i] = (Protocol *)proto->protocol_list->list[i];
- }
- result[i] = nil;
- }
- if (outCount) *outCount = count;
- return result;
- }
- BOOL protocol_conformsToProtocol(Protocol *self_gen, Protocol *other_gen)
- {
- old_protocol *self = oldprotocol(self_gen);
- old_protocol *other = oldprotocol(other_gen);
- if (!self || !other) {
- return NO;
- }
- if (0 == strcmp(self->protocol_name, other->protocol_name)) {
- return YES;
- }
- if (self->protocol_list) {
- int i;
- for (i = 0; i < self->protocol_list->count; i++) {
- old_protocol *proto = self->protocol_list->list[i];
- if (0 == strcmp(other->protocol_name, proto->protocol_name)) {
- return YES;
- }
- if (protocol_conformsToProtocol((Protocol *)proto, other_gen)) {
- return YES;
- }
- }
- }
- return NO;
- }
- BOOL protocol_isEqual(Protocol *self, Protocol *other)
- {
- if (self == other) return YES;
- if (!self || !other) return NO;
- if (!protocol_conformsToProtocol(self, other)) return NO;
- if (!protocol_conformsToProtocol(other, self)) return NO;
- return YES;
- }
- const char *
- _protocol_getMethodTypeEncoding(Protocol *proto_gen, SEL sel,
- BOOL isRequiredMethod, BOOL isInstanceMethod)
- {
- old_protocol *proto = oldprotocol(proto_gen);
- if (!proto) return nil;
- old_protocol_ext *ext = ext_for_protocol(proto);
- if (!ext) return nil;
- if (ext->size < offsetof(old_protocol_ext, extendedMethodTypes) + sizeof(ext->extendedMethodTypes)) return nil;
- if (! ext->extendedMethodTypes) return nil;
- struct objc_method_description *m =
- lookup_protocol_method(proto, sel,
- isRequiredMethod, isInstanceMethod, false);
- if (!m) {
-
- if (proto->protocol_list) {
- for (int i = 0; i < proto->protocol_list->count; i++) {
- const char *enc =
- _protocol_getMethodTypeEncoding((Protocol *)proto->protocol_list->list[i], sel, isRequiredMethod, isInstanceMethod);
- if (enc) return enc;
- }
- }
- return nil;
- }
-
- int i = 0;
- if (isRequiredMethod && isInstanceMethod) {
- i += ((uintptr_t)m - (uintptr_t)proto->instance_methods) / sizeof(proto->instance_methods->list[0]);
- goto done;
- } else if (proto->instance_methods) {
- i += proto->instance_methods->count;
- }
- if (isRequiredMethod && !isInstanceMethod) {
- i += ((uintptr_t)m - (uintptr_t)proto->class_methods) / sizeof(proto->class_methods->list[0]);
- goto done;
- } else if (proto->class_methods) {
- i += proto->class_methods->count;
- }
- if (!isRequiredMethod && isInstanceMethod) {
- i += ((uintptr_t)m - (uintptr_t)ext->optional_instance_methods) / sizeof(ext->optional_instance_methods->list[0]);
- goto done;
- } else if (ext->optional_instance_methods) {
- i += ext->optional_instance_methods->count;
- }
- if (!isRequiredMethod && !isInstanceMethod) {
- i += ((uintptr_t)m - (uintptr_t)ext->optional_class_methods) / sizeof(ext->optional_class_methods->list[0]);
- goto done;
- } else if (ext->optional_class_methods) {
- i += ext->optional_class_methods->count;
- }
- done:
- return ext->extendedMethodTypes[i];
- }
- Protocol *
- objc_allocateProtocol(const char *name)
- {
- Class cls = objc_getClass("__IncompleteProtocol");
- assert(cls);
- mutex_locker_t lock(classLock);
- if (NXMapGet(protocol_map, name)) return nil;
- old_protocol *result = (old_protocol *)
- calloc(1, sizeof(old_protocol)
- + sizeof(old_protocol_ext));
- old_protocol_ext *ext = (old_protocol_ext *)(result+1);
-
- result->isa = cls;
- result->protocol_name = strdup(name);
- ext->size = sizeof(old_protocol_ext);
-
- NXMapInsert(protocol_ext_map, result, result+1);
- return (Protocol *)result;
- }
- void objc_registerProtocol(Protocol *proto_gen)
- {
- old_protocol *proto = oldprotocol(proto_gen);
- Class oldcls = objc_getClass("__IncompleteProtocol");
- Class cls = objc_getClass("Protocol");
- mutex_locker_t lock(classLock);
- if (proto->isa == cls) {
- _objc_inform("objc_registerProtocol: protocol '%s' was already "
- "registered!", proto->protocol_name);
- return;
- }
- if (proto->isa != oldcls) {
- _objc_inform("objc_registerProtocol: protocol '%s' was not allocated "
- "with objc_allocateProtocol!", proto->protocol_name);
- return;
- }
- proto->isa = cls;
- NXMapKeyCopyingInsert(protocol_map, proto->protocol_name, proto);
- }
- void
- protocol_addProtocol(Protocol *proto_gen, Protocol *addition_gen)
- {
- old_protocol *proto = oldprotocol(proto_gen);
- old_protocol *addition = oldprotocol(addition_gen);
- Class cls = objc_getClass("__IncompleteProtocol");
- if (!proto_gen) return;
- if (!addition_gen) return;
- mutex_locker_t lock(classLock);
- if (proto->isa != cls) {
- _objc_inform("protocol_addProtocol: modified protocol '%s' is not "
- "under construction!", proto->protocol_name);
- return;
- }
- if (addition->isa == cls) {
- _objc_inform("protocol_addProtocol: added protocol '%s' is still "
- "under construction!", addition->protocol_name);
- return;
- }
-
- old_protocol_list *protolist = proto->protocol_list;
- if (protolist) {
- size_t size = sizeof(old_protocol_list)
- + protolist->count * sizeof(protolist->list[0]);
- protolist = (old_protocol_list *)
- realloc(protolist, size);
- } else {
- protolist = (old_protocol_list *)
- calloc(1, sizeof(old_protocol_list));
- }
- protolist->list[protolist->count++] = addition;
- proto->protocol_list = protolist;
- }
- static void
- _protocol_addMethod(struct objc_method_description_list **list, SEL name, const char *types)
- {
- if (!*list) {
- *list = (struct objc_method_description_list *)
- calloc(sizeof(struct objc_method_description_list), 1);
- } else {
- size_t size = sizeof(struct objc_method_description_list)
- + (*list)->count * sizeof(struct objc_method_description);
- *list = (struct objc_method_description_list *)
- realloc(*list, size);
- }
- struct objc_method_description *desc = &(*list)->list[(*list)->count++];
- desc->name = name;
- desc->types = strdup(types ?: "");
- }
- void
- protocol_addMethodDescription(Protocol *proto_gen, SEL name, const char *types,
- BOOL isRequiredMethod, BOOL isInstanceMethod)
- {
- old_protocol *proto = oldprotocol(proto_gen);
- Class cls = objc_getClass("__IncompleteProtocol");
- if (!proto_gen) return;
- mutex_locker_t lock(classLock);
- if (proto->isa != cls) {
- _objc_inform("protocol_addMethodDescription: protocol '%s' is not "
- "under construction!", proto->protocol_name);
- return;
- }
- if (isRequiredMethod && isInstanceMethod) {
- _protocol_addMethod(&proto->instance_methods, name, types);
- } else if (isRequiredMethod && !isInstanceMethod) {
- _protocol_addMethod(&proto->class_methods, name, types);
- } else if (!isRequiredMethod && isInstanceMethod) {
- old_protocol_ext *ext = (old_protocol_ext *)(proto+1);
- _protocol_addMethod(&ext->optional_instance_methods, name, types);
- } else {
- old_protocol_ext *ext = (old_protocol_ext *)(proto+1);
- _protocol_addMethod(&ext->optional_class_methods, name, types);
- }
- }
- static void
- _protocol_addProperty(old_property_list **plist, const char *name,
- const objc_property_attribute_t *attrs,
- unsigned int count)
- {
- if (!*plist) {
- *plist = (old_property_list *)
- calloc(sizeof(old_property_list), 1);
- (*plist)->entsize = sizeof(old_property);
- } else {
- *plist = (old_property_list *)
- realloc(*plist, sizeof(old_property_list)
- + (*plist)->count * (*plist)->entsize);
- }
- old_property *prop = property_list_nth(*plist, (*plist)->count++);
- prop->name = strdup(name);
- prop->attributes = copyPropertyAttributeString(attrs, count);
- }
- void
- protocol_addProperty(Protocol *proto_gen, const char *name,
- const objc_property_attribute_t *attrs,
- unsigned int count,
- BOOL isRequiredProperty, BOOL isInstanceProperty)
- {
- old_protocol *proto = oldprotocol(proto_gen);
- Class cls = objc_getClass("__IncompleteProtocol");
- if (!proto) return;
- if (!name) return;
- mutex_locker_t lock(classLock);
-
- if (proto->isa != cls) {
- _objc_inform("protocol_addProperty: protocol '%s' is not "
- "under construction!", proto->protocol_name);
- return;
- }
- old_protocol_ext *ext = ext_for_protocol(proto);
- if (isRequiredProperty && isInstanceProperty) {
- _protocol_addProperty(&ext->instance_properties, name, attrs, count);
- }
- else if (isRequiredProperty && !isInstanceProperty) {
- _protocol_addProperty(&ext->class_properties, name, attrs, count);
- }
-
-
-
-
-
-
- }
- static bool versionIsExt(uintptr_t version, const char *names, size_t size)
- {
-
-
-
-
-
- if (version < 4096 ) {
- return NO;
- }
- if (version >= (uintptr_t)names && version < (uintptr_t)(names + size)) {
- return NO;
- }
- return YES;
- }
- static void fix_protocol(old_protocol *proto, Class protocolClass,
- bool isBundle, const char *names, size_t names_size)
- {
- uintptr_t version;
- if (!proto) return;
- version = (uintptr_t)proto->isa;
-
- proto->isa = protocolClass;
-
-
- map_method_descs (proto->instance_methods, isBundle);
- map_method_descs (proto->class_methods, isBundle);
-
- if (versionIsExt(version, names, names_size)) {
- old_protocol_ext *ext = (old_protocol_ext *)version;
- NXMapInsert(protocol_ext_map, proto, ext);
- map_method_descs (ext->optional_instance_methods, isBundle);
- map_method_descs (ext->optional_class_methods, isBundle);
- }
-
-
-
-
- if (!NXMapGet(protocol_map, proto->protocol_name)) {
- NXMapKeyCopyingInsert(protocol_map, proto->protocol_name, proto);
- if (PrintProtocols) {
- _objc_inform("PROTOCOLS: protocol at %p is %s",
- proto, proto->protocol_name);
- }
- } else {
-
- if (PrintProtocols) {
- _objc_inform("PROTOCOLS: protocol at %p is %s (duplicate)",
- proto, proto->protocol_name);
- }
- }
- }
- static void _objc_fixup_protocol_objects_for_image (header_info * hi)
- {
- Class protocolClass = objc_getClass("Protocol");
- size_t count, i;
- old_protocol **protos;
- int isBundle = headerIsBundle(hi);
- const char *names;
- size_t names_size;
- mutex_locker_t lock(classLock);
-
- if (!protocol_map) {
- protocol_map =
- NXCreateMapTable(NXStrValueMapPrototype, 32);
- }
- if (!protocol_ext_map) {
- protocol_ext_map =
- NXCreateMapTable(NXPtrValueMapPrototype, 32);
- }
- protos = _getObjcProtocols(hi, &count);
- names = _getObjcClassNames(hi, &names_size);
- for (i = 0; i < count; i++) {
- fix_protocol(protos[i], protocolClass, isBundle, names, names_size);
- }
- }
- static void _objc_fixup_selector_refs (const header_info *hi)
- {
- size_t count;
- SEL *sels;
- bool preoptimized = hi->isPreoptimized();
- if (PrintPreopt) {
- if (preoptimized) {
- _objc_inform("PREOPTIMIZATION: honoring preoptimized selectors in %s",
- hi->fname());
- }
- else if (hi->info()->optimizedByDyld()) {
- _objc_inform("PREOPTIMIZATION: IGNORING preoptimized selectors in %s",
- hi->fname());
- }
- }
- if (preoptimized) return;
-
- sels = _getObjcSelectorRefs (hi, &count);
- map_selrefs(sels, count, headerIsBundle(hi));
- }
- static inline bool _is_threaded() {
- #if TARGET_OS_WIN32
- return YES;
- #else
- return pthread_is_threaded_np() != 0;
- #endif
- }
- #if !TARGET_OS_WIN32
- void
- unmap_image(const char *path __unused, const struct mach_header *mh)
- {
- recursive_mutex_locker_t lock(loadMethodLock);
- unmap_image_nolock(mh);
- }
- void
- map_images(unsigned count, const char * const paths[],
- const struct mach_header * const mhdrs[])
- {
- recursive_mutex_locker_t lock(loadMethodLock);
- map_images_nolock(count, paths, mhdrs);
- }
- extern void prepare_load_methods(const headerType *mhdr);
- void
- load_images(const char *path __unused, const struct mach_header *mh)
- {
- recursive_mutex_locker_t lock(loadMethodLock);
-
- prepare_load_methods((const headerType *)mh);
-
- call_load_methods();
- }
- #endif
- void _read_images(header_info **hList, uint32_t hCount, int totalClasses, int unoptimizedTotalClass)
- {
- uint32_t i;
- bool categoriesLoaded = NO;
- if (!class_hash) _objc_init_class_hash();
-
-
- for (i = 0; i < hCount; i++) {
- _objc_read_classes_from_image(hList[i]);
- }
-
-
-
- if (!_is_threaded()) {
- bool needFlush = NO;
- for (i = 0; i < hCount; i++) {
- needFlush |= _objc_read_categories_from_image(hList[i]);
- }
- if (needFlush) flush_marked_caches();
- categoriesLoaded = YES;
- }
-
- for (i = 0; i < hCount; i++) {
- _objc_connect_classes_from_image(hList[i]);
- }
-
- for (i = 0; i < hCount; i++) {
- _objc_map_class_refs_for_image(hList[i]);
- _objc_fixup_selector_refs(hList[i]);
- _objc_fixup_protocol_objects_for_image(hList[i]);
- }
-
-
-
- if (!categoriesLoaded) {
- bool needFlush = NO;
- for (i = 0; i < hCount; i++) {
- needFlush |= _objc_read_categories_from_image(hList[i]);
- }
- if (needFlush) flush_marked_caches();
- }
-
- }
- static void schedule_class_load(Class cls)
- {
- if (cls->info & CLS_LOADED) return;
- if (cls->superclass) schedule_class_load(cls->superclass);
- add_class_to_loadable_list(cls);
- cls->info |= CLS_LOADED;
- }
- void prepare_load_methods(const headerType *mhdr)
- {
- Module mods;
- unsigned int midx;
- header_info *hi;
- for (hi = FirstHeader; hi; hi = hi->getNext()) {
- if (mhdr == hi->mhdr()) break;
- }
- if (!hi) return;
- if (hi->info()->isReplacement()) {
-
- return;
- }
-
- mods = hi->mod_ptr;
- for (midx = 0; midx < hi->mod_count; midx += 1)
- {
- unsigned int index;
-
- if (mods[midx].symtab == nil)
- continue;
-
- for (index = 0; index < mods[midx].symtab->cls_def_cnt; index += 1)
- {
-
- Class cls = (Class)mods[midx].symtab->defs[index];
- if (cls->info & CLS_CONNECTED) {
- schedule_class_load(cls);
- }
- }
- }
-
- mods = hi->mod_ptr;
-
-
-
- midx = (unsigned int)hi->mod_count;
- while (midx-- > 0) {
- unsigned int index;
- unsigned int total;
- Symtab symtab = mods[midx].symtab;
-
- if (mods[midx].symtab == nil)
- continue;
-
-
- total = mods[midx].symtab->cls_def_cnt +
- mods[midx].symtab->cat_def_cnt;
-
-
- index = total;
- while (index-- > mods[midx].symtab->cls_def_cnt) {
- old_category *cat = (old_category *)symtab->defs[index];
- add_category_to_loadable_list((Category)cat);
- }
- }
- }
- #if TARGET_OS_WIN32
- void unload_class(Class cls)
- {
- }
- #else
- static void rependClassReferences(Class *refs, size_t count,
- uintptr_t start, uintptr_t end)
- {
- size_t i;
- if (!refs) return;
-
- for (i = 0; i < count; i++) {
- if ((uintptr_t)(refs[i]) >= start && (uintptr_t)(refs[i]) < end) {
- pendClassReference(&refs[i], refs[i]->name,
- refs[i]->info & CLS_META);
- refs[i] = nil;
- }
- }
- }
- void try_free(const void *p)
- {
- if (p && malloc_size(p)) free((void *)p);
- }
- static void unload_mlist(old_method_list *mlist)
- {
- int i;
- for (i = 0; i < mlist->method_count; i++) {
- try_free(mlist->method_list[i].method_types);
- }
- try_free(mlist);
- }
- static void unload_property_list(old_property_list *proplist)
- {
- uint32_t i;
- if (!proplist) return;
- for (i = 0; i < proplist->count; i++) {
- old_property *prop = property_list_nth(proplist, i);
- try_free(prop->name);
- try_free(prop->attributes);
- }
- try_free(proplist);
- }
- void unload_class(Class cls)
- {
-
-
- if (cls->cache && cls->cache != &_objc_empty_cache) {
- _cache_free(cls->cache);
- }
-
- if (cls->ivars) {
- int i;
- for (i = 0; i < cls->ivars->ivar_count; i++) {
- try_free(cls->ivars->ivar_list[i].ivar_name);
- try_free(cls->ivars->ivar_list[i].ivar_type);
- }
- try_free(cls->ivars);
- }
-
- if (cls->methodLists) {
-
- if (cls->info & CLS_NO_METHOD_ARRAY) {
-
- unload_mlist((old_method_list *)cls->methodLists);
- }
- else {
-
- old_method_list **mlistp;
- for (mlistp = cls->methodLists;
- *mlistp != nil && *mlistp != END_OF_METHODS_LIST;
- mlistp++)
- {
- unload_mlist(*mlistp);
- }
- free(cls->methodLists);
- }
- }
-
- old_protocol_list *protos = cls->protocols;
- while (protos) {
- old_protocol_list *dead = protos;
- protos = protos->next;
- try_free(dead);
- }
- if ((cls->info & CLS_EXT)) {
- if (cls->ext) {
-
- if (cls->ext->propertyLists) {
-
- if (cls->info & CLS_NO_PROPERTY_ARRAY) {
-
- old_property_list *proplist =
- (old_property_list *)cls->ext->propertyLists;
- unload_property_list(proplist);
- } else {
-
- old_property_list **plistp;
- for (plistp = cls->ext->propertyLists;
- *plistp != nil;
- plistp++)
- {
- unload_property_list(*plistp);
- }
- try_free(cls->ext->propertyLists);
- }
- }
-
- try_free(cls->ext->weak_ivar_layout);
-
- try_free(cls->ext);
- }
-
- try_free(cls->ivar_layout);
- }
-
- try_free(cls->name);
-
- try_free(cls);
- }
- static void _objc_remove_classes_in_image(header_info *hi)
- {
- unsigned int index;
- unsigned int midx;
- Module mods;
- mutex_locker_t lock(classLock);
-
-
- mods = hi->mod_ptr;
- for (midx = 0; midx < hi->mod_count; midx += 1)
- {
-
- if (mods[midx].symtab == nil)
- continue;
-
-
- for (index = 0; index < mods[midx].symtab->cls_def_cnt; index += 1)
- {
- Class cls;
-
-
- cls = (Class)mods[midx].symtab->defs[index];
-
- remove_class_from_loadable_list(cls);
-
- if (unconnected_class_hash && NXHashMember(unconnected_class_hash, cls)) {
- NXHashRemove(unconnected_class_hash, cls);
- if (pendingSubclassesMap) {
-
- char *supercls_name = (char *)cls->superclass;
- PendingSubclass *pending = (PendingSubclass *)
- NXMapGet(pendingSubclassesMap, supercls_name);
- for ( ; pending != nil; pending = pending->next) {
- if (pending->subclass == cls) {
- pending->subclass = Nil;
- break;
- }
- }
- }
- }
-
-
- NXHashRemove(class_hash, cls);
-
- unload_class(cls->ISA());
- unload_class(cls);
- }
- }
-
-
-
- uintptr_t seg;
- unsigned long seg_size;
- seg = (uintptr_t)getsegmentdata(hi->mhdr(), "__OBJC", &seg_size);
- header_info *other_hi;
- for (other_hi = FirstHeader; other_hi != nil; other_hi = other_hi->getNext()) {
- Class *other_refs;
- size_t count;
- if (other_hi == hi) continue;
-
- other_refs = _getObjcClassRefs(other_hi, &count);
- rependClassReferences(other_refs, count, seg, seg+seg_size);
- }
- }
- static void _objc_remove_categories_in_image(header_info *hi)
- {
- Module mods;
- unsigned int midx;
-
-
- mods = hi->mod_ptr;
-
- for (midx = 0; midx < hi->mod_count; midx++) {
- unsigned int index;
- unsigned int total;
- Symtab symtab = mods[midx].symtab;
-
-
- if (symtab == nil) continue;
-
-
-
- total = symtab->cls_def_cnt + symtab->cat_def_cnt;
-
-
- for (index = symtab->cls_def_cnt; index < total; index++) {
- old_category *cat = (old_category *)symtab->defs[index];
-
- remove_category_from_loadable_list((Category)cat);
-
- if (category_hash) {
- _objc_unresolved_category *cat_entry = (_objc_unresolved_category *)NXMapGet(category_hash, cat->class_name);
- for ( ; cat_entry != nil; cat_entry = cat_entry->next) {
- if (cat_entry->cat == cat) {
- cat_entry->cat = nil;
- break;
- }
- }
- }
- }
- }
- }
- static void unload_paranoia(header_info *hi)
- {
-
- uintptr_t seg;
- unsigned long seg_size;
- seg = (uintptr_t)getsegmentdata(hi->mhdr(), "__OBJC", &seg_size);
- _objc_inform("UNLOAD DEBUG: unloading image '%s' [%p..%p]",
- hi->fname(), (void *)seg, (void*)(seg+seg_size));
- mutex_locker_t lock(classLock);
-
- {
- Module mods;
- unsigned int midx;
-
- mods = hi->mod_ptr;
-
- for (midx = 0; midx < hi->mod_count; midx++) {
- unsigned int index;
- unsigned int total;
- Symtab symtab = mods[midx].symtab;
-
- if (symtab == nil) continue;
-
-
-
- total = symtab->cls_def_cnt + symtab->cat_def_cnt;
-
-
- for (index = symtab->cls_def_cnt; index < total; index++) {
- old_category *cat = (old_category *)symtab->defs[index];
- struct objc_class query;
- query.name = cat->class_name;
- if (NXHashMember(class_hash, &query)) {
- _objc_inform("UNLOAD DEBUG: dying image contains category '%s(%s)' on surviving class '%s'!", cat->class_name, cat->category_name, cat->class_name);
- }
- }
- }
- }
-
-
-
- {
- Class cls;
- NXHashState state;
- state = NXInitHashState(class_hash);
- while (NXNextHashState(class_hash, &state, (void **)&cls)) {
- if ((vm_address_t)cls >= seg &&
- (vm_address_t)cls < seg+seg_size)
- {
- _objc_inform("UNLOAD DEBUG: dying image contains surviving class '%s'!", cls->name);
- }
-
- if ((vm_address_t)cls->superclass >= seg &&
- (vm_address_t)cls->superclass < seg+seg_size)
- {
- _objc_inform("UNLOAD DEBUG: dying image contains superclass '%s' of surviving class '%s'!", cls->superclass->name, cls->name);
- }
- }
- }
- }
- void _unload_image(header_info *hi)
- {
- loadMethodLock.assertLocked();
-
-
-
-
- _objc_remove_classes_in_image(hi);
- _objc_remove_categories_in_image(hi);
- _objc_remove_pending_class_refs_in_image(hi);
- if (hi->proto_refs) try_free(hi->proto_refs);
-
- if (DebugUnload) unload_paranoia(hi);
- }
- #endif
- void objc_addClass (Class cls)
- {
- OBJC_WARN_DEPRECATED;
-
- mutex_locker_t lock(classLock);
-
-
-
-
- if (cls->cache == nil) {
- cls->cache = (Cache) &_objc_empty_cache;
- cls->info = CLS_CLASS;
- }
- if (cls->ISA()->cache == nil) {
- cls->ISA()->cache = (Cache) &_objc_empty_cache;
- cls->ISA()->info = CLS_META;
- }
-
-
-
-
-
-
-
- (void) NXHashInsert (class_hash, cls);
-
- if (cls->superclass && (cls->superclass->info & CLS_LEAF)) {
- cls->superclass->clearInfo(CLS_LEAF);
- cls->superclass->ISA()->clearInfo(CLS_LEAF);
- }
- }
- static void _objcTweakMethodListPointerForClass(Class cls)
- {
- old_method_list * originalList;
- const int initialEntries = 4;
- size_t mallocSize;
- old_method_list ** ptr;
-
- if (cls->methodLists && !(cls->info & CLS_NO_METHOD_ARRAY)) return;
-
- originalList = (old_method_list *) cls->methodLists;
-
- mallocSize = sizeof(old_method_list *) * initialEntries;
- ptr = (old_method_list **) calloc(1, mallocSize);
-
- ptr[initialEntries - 1] = END_OF_METHODS_LIST;
- ptr[0] = originalList;
-
- cls->methodLists = ptr;
- cls->clearInfo(CLS_NO_METHOD_ARRAY);
- }
- void _objc_insertMethods(Class cls, old_method_list *mlist, old_category *cat)
- {
- old_method_list ***list;
- old_method_list **ptr;
- ptrdiff_t endIndex;
- size_t oldSize;
- size_t newSize;
- if (!cls->methodLists) {
-
- cls->methodLists = (old_method_list **)mlist;
- cls->setInfo(CLS_NO_METHOD_ARRAY);
- return;
- }
-
- if (PrintReplacedMethods) {
- int i;
- for (i = 0; i < mlist->method_count; i++) {
- extern IMP findIMPInClass(Class cls, SEL sel);
- SEL sel = sel_registerName((char *)mlist->method_list[i].method_name);
- IMP newImp = mlist->method_list[i].method_imp;
- IMP oldImp;
- if ((oldImp = findIMPInClass(cls, sel))) {
- logReplacedMethod(cls->name, sel, ISMETA(cls),
- cat ? cat->category_name : nil,
- oldImp, newImp);
- }
- }
- }
-
- _objcTweakMethodListPointerForClass(cls);
-
- list = &cls->methodLists;
-
- ptr = *list;
- while ((*ptr != 0) && (*ptr != END_OF_METHODS_LIST))
- ptr += 1;
-
- if (*ptr == END_OF_METHODS_LIST)
- {
-
- endIndex = ptr - *list;
- oldSize = (endIndex + 1) * sizeof(void *);
- newSize = oldSize + sizeof(old_method_list *);
-
- *list = (old_method_list **)realloc(*list, newSize);
-
- bzero (&((*list)[endIndex]), newSize - oldSize);
-
- (*list)[(newSize/sizeof(void *)) - 1] = END_OF_METHODS_LIST;
-
- ptr = &((*list)[endIndex]);
- }
-
- bcopy (*list, (*list) + 1, (uint8_t *)ptr - (uint8_t *)*list);
-
- **list = mlist;
- }
- void _objc_removeMethods(Class cls, old_method_list *mlist)
- {
- old_method_list ***list;
- old_method_list **ptr;
- if (cls->methodLists == nil) {
-
- return;
- }
- if (cls->methodLists == (old_method_list **)mlist) {
-
- cls->methodLists = nil;
- return;
- }
- if (cls->info & CLS_NO_METHOD_ARRAY) {
-
- return;
- }
-
- list = &cls->methodLists;
-
- ptr = *list;
- while (*ptr != mlist) {
-
- if ( *ptr == END_OF_METHODS_LIST ) return;
- ptr += 1;
- }
-
- *ptr = 0;
-
- while (*(++ptr) != END_OF_METHODS_LIST)
- *(ptr-1) = *ptr;
- *(ptr-1) = 0;
- }
- static inline void _objc_add_category(Class cls, old_category *category, int version)
- {
- if (PrintConnecting) {
- _objc_inform("CONNECT: attaching category '%s (%s)'", cls->name, category->category_name);
- }
-
- if (category->instance_methods)
- _objc_insertMethods (cls, category->instance_methods, category);
-
- if (category->class_methods)
- _objc_insertMethods (cls->ISA(), category->class_methods, category);
-
- if ((version >= 5) && category->protocols)
- {
- if (cls->ISA()->version >= 5)
- {
- category->protocols->next = cls->protocols;
- cls->protocols = category->protocols;
- cls->ISA()->protocols = category->protocols;
- }
- else
- {
- _objc_inform ("unable to add protocols from category %s...\n", category->category_name);
- _objc_inform ("class `%s' must be recompiled\n", category->class_name);
- }
- }
-
- if (version >= 7 && category->instance_properties) {
- if (cls->ISA()->version >= 6) {
- _class_addProperties(cls, category->instance_properties);
- } else {
- _objc_inform ("unable to add instance properties from category %s...\n", category->category_name);
- _objc_inform ("class `%s' must be recompiled\n", category->class_name);
- }
- }
-
- if (version >= 7 && category->hasClassPropertiesField() &&
- category->class_properties)
- {
- if (cls->ISA()->version >= 6) {
- _class_addProperties(cls->ISA(), category->class_properties);
- } else {
- _objc_inform ("unable to add class properties from category %s...\n", category->category_name);
- _objc_inform ("class `%s' must be recompiled\n", category->class_name);
- }
- }
- }
- static bool _objc_add_category_flush_caches(Class cls, old_category *category, int version)
- {
- bool needFlush = NO;
-
- {
- mutex_locker_t lock(methodListLock);
- _objc_add_category (cls, category, version);
- }
-
- if (category->instance_methods) {
- cls->setInfo(CLS_FLUSH_CACHE);
- needFlush = YES;
- }
- if (category->class_methods) {
- cls->ISA()->setInfo(CLS_FLUSH_CACHE);
- needFlush = YES;
- }
-
- return needFlush;
- }
- static _objc_unresolved_category *reverse_cat(_objc_unresolved_category *cat)
- {
- _objc_unresolved_category *prev;
- _objc_unresolved_category *cur;
- _objc_unresolved_category *ahead;
- if (!cat) return nil;
- prev = nil;
- cur = cat;
- ahead = cat->next;
-
- while (cur) {
- ahead = cur->next;
- cur->next = prev;
- prev = cur;
- cur = ahead;
- }
- return prev;
- }
- static void resolve_categories_for_class(Class cls)
- {
- _objc_unresolved_category * pending;
- _objc_unresolved_category * next;
-
- if (!category_hash) return;
-
-
- pending = (_objc_unresolved_category *)
- NXMapKeyFreeingRemove (category_hash, cls->name);
-
-
- pending = reverse_cat(pending);
- while (pending) {
- if (pending->cat) {
-
-
-
- _objc_add_category(cls, pending->cat, (int)pending->version);
- }
-
- next = pending->next;
- free(pending);
- pending = next;
- }
- }
- void _objc_resolve_categories_for_class(Class cls)
- {
-
-
- if (ISMETA(cls)) {
- if (strncmp(cls->name, "_%", 2) == 0) {
-
-
- const char *baseName = strchr(cls->name, '%');
- cls = objc_getClass(baseName);
- } else {
- cls = objc_getClass(cls->name);
- }
- }
- resolve_categories_for_class(cls);
- }
- static bool _objc_register_category(old_category *cat, int version)
- {
- _objc_unresolved_category * new_cat;
- _objc_unresolved_category * old;
- Class theClass;
-
- if ((theClass = objc_lookUpClass(cat->class_name))) {
- return _objc_add_category_flush_caches(theClass, cat, version);
- }
-
-
-
-
-
- if ((theClass = look_up_class(cat->class_name, YES, NO))) {
- _objc_add_category(theClass, cat, version);
- return NO;
- }
-
-
- if (PrintConnecting) {
- _objc_inform("CONNECT: pending category '%s (%s)'", cat->class_name, cat->category_name);
- }
-
- if (!category_hash)
- category_hash = NXCreateMapTable(NXStrValueMapPrototype, 128);
-
- old = (_objc_unresolved_category *)
- NXMapGet (category_hash, cat->class_name);
-
-
-
- new_cat = (_objc_unresolved_category *)
- malloc(sizeof(_objc_unresolved_category));
- new_cat->next = old;
- new_cat->cat = cat;
- new_cat->version = version;
- (void) NXMapKeyCopyingInsert (category_hash, cat->class_name, new_cat);
- return NO;
- }
- const char **objc_copyImageNames(unsigned int *outCount)
- {
- header_info *hi;
- int count = 0;
- int max = HeaderCount;
- #if TARGET_OS_WIN32
- const TCHAR **names = (const TCHAR **)calloc(max+1, sizeof(TCHAR *));
- #else
- const char **names = (const char **)calloc(max+1, sizeof(char *));
- #endif
- for (hi = FirstHeader; hi != NULL && count < max; hi = hi->getNext()) {
- #if TARGET_OS_WIN32
- if (hi->moduleName) {
- names[count++] = hi->moduleName;
- }
- #else
- const char *fname = hi->fname();
- if (fname) {
- names[count++] = fname;
- }
- #endif
- }
- names[count] = NULL;
- if (count == 0) {
-
- free((void *)names);
- names = NULL;
- }
- if (outCount) *outCount = count;
- return names;
- }
- static const char **
- _objc_copyClassNamesForImage(header_info *hi, unsigned int *outCount)
- {
- Module mods;
- unsigned int m;
- const char **list;
- int count;
- int allocated;
- list = nil;
- count = 0;
- allocated = 0;
-
- mods = hi->mod_ptr;
- for (m = 0; m < hi->mod_count; m++) {
- int d;
- if (!mods[m].symtab) continue;
-
- for (d = 0; d < mods[m].symtab->cls_def_cnt; d++) {
- Class cls = (Class)mods[m].symtab->defs[d];
-
- if (cls->isConnected()) {
- if (count == allocated) {
- allocated = allocated*2 + 16;
- list = (const char **)
- realloc((void *)list, allocated * sizeof(char *));
- }
- list[count++] = cls->name;
- }
- }
- }
- if (count > 0) {
-
- if (count == allocated) {
- allocated = allocated+1;
- list = (const char **)
- realloc((void *)list, allocated * sizeof(char *));
- }
- list[count] = nil;
- }
- if (outCount) *outCount = count;
- return list;
- }
- const char **
- objc_copyClassNamesForImage(const char *image, unsigned int *outCount)
- {
- header_info *hi;
- if (!image) {
- if (outCount) *outCount = 0;
- return NULL;
- }
-
- for (hi = FirstHeader; hi != NULL; hi = hi->getNext()) {
- #if TARGET_OS_WIN32
- if (0 == wcscmp((TCHAR *)image, hi->moduleName)) break;
- #else
- if (0 == strcmp(image, hi->fname())) break;
- #endif
- }
- if (!hi) {
- if (outCount) *outCount = 0;
- return NULL;
- }
- return _objc_copyClassNamesForImage(hi, outCount);
- }
- const char **
- objc_copyClassNamesForImageHeader(const struct mach_header *mh, unsigned int *outCount)
- {
- header_info *hi;
- if (!mh) {
- if (outCount) *outCount = 0;
- return NULL;
- }
-
- for (hi = FirstHeader; hi != NULL; hi = hi->getNext()) {
- if (hi->mhdr() == (const headerType *)mh) break;
- }
- if (!hi) {
- if (outCount) *outCount = 0;
- return NULL;
- }
- return _objc_copyClassNamesForImage(hi, outCount);
- }
- Class gdb_class_getClass(Class cls)
- {
- const char *className = cls->name;
- if(!className || !strlen(className)) return Nil;
- Class rCls = look_up_class(className, NO, NO);
- return rCls;
- }
- Class gdb_object_getClass(id obj)
- {
- if (!obj) return nil;
- return gdb_class_getClass(obj->getIsa());
- }
- void objc_setMultithreaded (BOOL flag)
- {
- OBJC_WARN_DEPRECATED;
-
- }
- mutex_t selLock;
- mutex_t classLock;
- mutex_t methodListLock;
- mutex_t cacheUpdateLock;
- recursive_mutex_t loadMethodLock;
- void lock_init(void)
- {
- }
- #endif
|