1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
|
/* $Id: kLdrDyldMod.c 81 2016-08-18 22:10:38Z bird $ */
/** @file
* kLdr - The Dynamic Loader, Dyld module methods.
*/
/*
* Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <k/kLdr.h>
#include "kLdrInternal.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** @def KLDRDYLDMOD_STRICT
* Define KLDRDYLDMOD_STRICT to enabled strict checks in kLdrDyld. */
#define KLDRDYLDMOD_STRICT 1
/** @def KLDRDYLDMOD_ASSERT
* Assert that an expression is true when KLDRDYLD_STRICT is defined.
*/
#ifdef KLDRDYLDMOD_STRICT
# define KLDRDYLDMOD_ASSERT(expr) kHlpAssert(expr)
#else
# define KLDRDYLDMOD_ASSERT(expr) do {} while (0)
#endif
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static void kldrDyldModUnlink(PKLDRDYLDMOD pMod);
/**
* Creates a module from the specified file provider instance.
*
* @returns 0 on success and *ppMod pointing to the new instance.
* On failure a non-zero kLdr status code is returned.
* @param pRdr The file provider instance.
* @param fFlags Load/search flags.
* @param ppMod Where to put the pointer to the new module on success.
*/
int kldrDyldModCreate(PKRDR pRdr, KU32 fFlags, PPKLDRDYLDMOD ppMod)
{
PKLDRDYLDMOD pMod;
PKLDRMOD pRawMod;
int rc;
*ppMod = NULL;
/** @todo deal with fFlags (exec/dll) */
/** @todo Check up the cpu architecture. */
/*
* Try open an module interpreter.
*/
rc = kLdrModOpenFromRdr(pRdr, 0 /*fFlags*/, KCPUARCH_UNKNOWN, &pRawMod);
if (rc)
return kldrDyldFailure(rc, "%s: %rc", kRdrName(pRdr), rc);
/*
* Match the module aginst the load flags.
*/
switch (pRawMod->enmType)
{
case KLDRTYPE_EXECUTABLE_FIXED:
case KLDRTYPE_EXECUTABLE_RELOCATABLE:
case KLDRTYPE_EXECUTABLE_PIC:
if (!(fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE))
{
kLdrModClose(pRawMod);
return KLDR_ERR_NOT_EXE;
}
break;
case KLDRTYPE_OBJECT: /* We can handle these as DLLs. */
case KLDRTYPE_SHARED_LIBRARY_FIXED:
case KLDRTYPE_SHARED_LIBRARY_RELOCATABLE:
case KLDRTYPE_SHARED_LIBRARY_PIC:
case KLDRTYPE_FORWARDER_DLL:
if (fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE)
{
kLdrModClose(pRawMod);
return KLDR_ERR_NOT_DLL;
}
break;
default:
KLDRDYLDMOD_ASSERT(!"Bad enmType!");
case KLDRTYPE_CORE:
return fFlags & KLDRDYLD_LOAD_FLAGS_EXECUTABLE ? KLDR_ERR_NOT_EXE : KLDR_ERR_NOT_DLL;
}
/*
* Allocate a new dyld module.
*/
pMod = (PKLDRDYLDMOD)kHlpAlloc(sizeof(*pMod));
if (pMod)
{
pMod->enmState = KLDRSTATE_OPEN;
pMod->pMod = pRawMod;
pMod->hMod = pMod;
pMod->cDepRefs = pMod->cDynRefs = pMod->cRefs = 0;
switch (pRawMod->enmType)
{
case KLDRTYPE_EXECUTABLE_FIXED:
case KLDRTYPE_EXECUTABLE_RELOCATABLE:
case KLDRTYPE_EXECUTABLE_PIC:
pMod->fExecutable = 1;
break;
default:
pMod->fExecutable = 0;
break;
}
pMod->fGlobalOrSpecific = 0;
pMod->fBindable = 0;
pMod->fInitList = 0;
pMod->fAlreadySeen = 0;
pMod->fMapped = 0;
pMod->fAllocatedTLS = 0;
pMod->f25Reserved = 0;
pMod->InitTerm.pNext = NULL;
pMod->InitTerm.pPrev = NULL;
pMod->Bind.pNext = NULL;
pMod->Bind.pPrev = NULL;
pMod->cPrereqs = 0;
pMod->papPrereqs = NULL;
pMod->u32MagicHead = KLDRDYMOD_MAGIC;
pMod->u32MagicTail = KLDRDYMOD_MAGIC;
/* it. */
pMod->Load.pNext = NULL;
pMod->Load.pPrev = kLdrDyldTail;
if (kLdrDyldTail)
kLdrDyldTail->Load.pNext = pMod;
else
kLdrDyldHead = pMod;
kLdrDyldTail = pMod;
/* deal with the remaining flags. */
if (fFlags & KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE)
kldrDyldModMarkSpecific(pMod);
else
kldrDyldModMarkGlobal(pMod);
if (fFlags & KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS)
kldrDyldModSetBindable(pMod, 0 /* not deep binable */);
else
kldrDyldModClearBindable(pMod);
/*
* We're good.
*/
*ppMod = pMod;
rc = 0;
}
else
{
kLdrModClose(pRawMod);
rc = KERR_NO_MEMORY;
}
return rc;
}
/**
* Creates a module for a native module.
*
* @returns 0 on success and *ppMod pointing to the new instance.
* On failure a non-zero kLdr status code is returned.
* @param hNativeModule The native handle.
* @param ppMod Where to put the pointer to the new module on success.
* @remark This function ain't finalized yet.
*/
int kldrDyldModCreateNative(KUPTR hNativeModule)
{
#if 0
/*
* Check if this module is already loaded by the native OS loader.
*/
rc = kld
{
#if K_OS == K_OS_OS2
HMODULE hmod = NULLHANDLE;
APIRET rc = DosQueryModuleHandle(kRdrName(pRdr), &hmod);
if (!rc)
#elif K_OS == K_OS_WINDOWS
HMODULE hmod = NULL;
if (GetModuleHandle(kRdrName(pRdr))
#else
# error "Port me"
#endif
}
#endif
return -1;
}
/**
* Destroys a module pending destruction.
*
* @param pMod The module in question.
*/
void kldrDyldModDestroy(PKLDRDYLDMOD pMod)
{
int rc;
/*
* Validate the state.
*/
switch (pMod->enmState)
{
case KLDRSTATE_PENDING_DESTROY:
case KLDRSTATE_GC:
break;
default:
KLDRDYLDMOD_ASSERT(!"Invalid state");
break;
}
KLDRDYLDMOD_ASSERT(!pMod->fInitList);
KLDRDYLDMOD_ASSERT(!pMod->cDynRefs);
KLDRDYLDMOD_ASSERT(!pMod->cDepRefs);
/*
* Ensure that the module is unmapped.
*/
if (pMod->fAllocatedTLS)
{
kLdrModFreeTLS(pMod->pMod, KLDRMOD_INT_MAP);
pMod->fAllocatedTLS = 0;
}
if (pMod->fMapped)
{
rc = kLdrModUnmap(pMod->pMod); KLDRDYLDMOD_ASSERT(!rc);
pMod->fMapped = 0;
}
/*
* Ensure it's unlinked from all chains.
*/
if (pMod->enmState < KLDRSTATE_PENDING_DESTROY)
kldrDyldModUnlink(pMod);
/*
* Free everything associated with the module.
*/
/* the prerequisite array. */
if (pMod->papPrereqs)
{
KU32 i = pMod->cPrereqs;
while (i-- > 0)
{
KLDRDYLDMOD_ASSERT(pMod->papPrereqs[i] == NULL);
pMod->papPrereqs[i] = NULL;
}
kHlpFree(pMod->papPrereqs);
pMod->papPrereqs = NULL;
pMod->cPrereqs = 0;
}
/* the module interpreter. */
if (pMod->pMod)
{
rc = kLdrModClose(pMod->pMod); KLDRDYLDMOD_ASSERT(!rc);
pMod->pMod = NULL;
}
/*
* Finally, change the module state and free the module if
* there are not more references to it. If somebody is still
* referencing it, postpone the freeing to Deref.
*/
pMod->enmState = KLDRSTATE_DESTROYED;
if (!pMod->cRefs)
{
pMod->u32MagicHead = 1;
pMod->u32MagicTail = 2;
kHlpFree(pMod);
}
}
/**
* Unlinks the module from any list it might be in.
* It is assumed that the module is at least linked into the load list.
*
* @param pMod The moduel.
*/
static void kldrDyldModUnlink(PKLDRDYLDMOD pMod)
{
/* load list */
if (pMod->Load.pNext)
pMod->Load.pNext->Load.pPrev = pMod->Load.pPrev;
else
kLdrDyldTail = pMod->Load.pPrev;
if (pMod->Load.pPrev)
pMod->Load.pPrev->Load.pNext = pMod->Load.pNext;
else
kLdrDyldHead = pMod->Load.pNext;
/* bind list */
if (pMod->fBindable)
kldrDyldModClearBindable(pMod);
/* init term */
if (pMod->fInitList)
{
KLDRDYLDMOD_ASSERT(pMod->enmState < KLDRSTATE_INITIALIZATION_FAILED);
pMod->fInitList = 0;
if (pMod->InitTerm.pNext)
pMod->InitTerm.pNext->InitTerm.pPrev = pMod->InitTerm.pPrev;
else
g_pkLdrDyldInitTail = pMod->InitTerm.pPrev;
if (pMod->InitTerm.pPrev)
pMod->InitTerm.pPrev->InitTerm.pNext = pMod->InitTerm.pNext;
else
g_pkLdrDyldInitHead = pMod->InitTerm.pNext;
}
else if (pMod->enmState > KLDRSTATE_INITIALIZATION_FAILED)
{
KLDRDYLDMOD_ASSERT(pMod->enmState >= KLDRSTATE_GOOD);
if (pMod->InitTerm.pNext)
pMod->InitTerm.pNext->InitTerm.pPrev = pMod->InitTerm.pPrev;
else
g_pkLdrDyldTermTail = pMod->InitTerm.pPrev;
if (pMod->InitTerm.pPrev)
pMod->InitTerm.pPrev->InitTerm.pNext = pMod->InitTerm.pNext;
else
g_pkLdrDyldTermHead = pMod->InitTerm.pNext;
}
pMod->InitTerm.pNext = NULL;
pMod->InitTerm.pPrev = NULL;
}
/**
* Marks a module as bindable, i.e. it'll be considered when
* resolving names the unix way.
*
* @param pMod The module.
* @param fDeep When set the module will be inserted at the head of the
* module list used to resolve symbols. This means that the
* symbols in this module will be prefered of all the other
* modules.
*/
void kldrDyldModSetBindable(PKLDRDYLDMOD pMod, unsigned fDeep)
{
KLDRDYLDMOD_ASSERT(pMod->enmState >= KLDRSTATE_OPEN && pMod->enmState < KLDRSTATE_PENDING_GC);
if (!pMod->fBindable)
{
pMod->fBindable = 1;
if (!fDeep)
{
pMod->Bind.pNext = NULL;
pMod->Bind.pPrev = g_pkLdrDyldBindTail;
if (g_pkLdrDyldBindTail)
g_pkLdrDyldBindTail->Bind.pNext = pMod;
else
g_pkLdrDyldBindHead = pMod;
g_pkLdrDyldBindTail = pMod;
}
else
{
pMod->Bind.pPrev = NULL;
pMod->Bind.pNext = g_pkLdrDyldBindHead;
if (g_pkLdrDyldBindHead)
g_pkLdrDyldBindHead->Bind.pPrev = pMod;
else
g_pkLdrDyldBindTail = pMod;
g_pkLdrDyldBindHead = pMod;
}
}
}
/**
* Marks a module as not bindable, i.e. it will not be considered when
* resolving names the unix way.
*
* @param pMod The module.
*/
void kldrDyldModClearBindable(PKLDRDYLDMOD pMod)
{
KLDRDYLDMOD_ASSERT(pMod->enmState >= KLDRSTATE_OPEN && pMod->enmState < KLDRSTATE_PENDING_DESTROY);
if (pMod->fBindable)
{
pMod->fBindable = 0;
if (pMod->Bind.pPrev)
pMod->Bind.pPrev->Bind.pNext = pMod->Bind.pNext;
else
g_pkLdrDyldBindHead = pMod->Bind.pNext;
if (pMod->Bind.pNext)
pMod->Bind.pNext->Bind.pPrev = pMod->Bind.pPrev;
else
g_pkLdrDyldBindTail = pMod->Bind.pPrev;
pMod->Bind.pNext = NULL;
pMod->Bind.pPrev = NULL;
}
}
/**
* Marks the module as global instead of being specific.
*
* A global module can be a matching result when the request
* doesn't specify a path. A specific module will not match
* unless the path also matches.
*
* @param pMod The module.
*/
void kldrDyldModMarkGlobal(PKLDRDYLDMOD pMod)
{
pMod->fGlobalOrSpecific = 1;
}
/**
* Marks the module as specific instead of global.
*
* See kldrDyldModMarkGlobal for an explanation of the two terms.
*
* @param pMod The module.
*/
void kldrDyldModMarkSpecific(PKLDRDYLDMOD pMod)
{
pMod->fGlobalOrSpecific = 0;
}
/**
* Adds a reference to the module making sure it won't be freed just yet.
*
* @param pMod The module.
*/
void kldrDyldModAddRef(PKLDRDYLDMOD pMod)
{
pMod->cRefs++;
}
/**
* Dereference a module.
*
* @param pMod
*/
void kldrDyldModDeref(PKLDRDYLDMOD pMod)
{
/* validate input */
KLDRDYLDMOD_ASSERT(pMod->cRefs > 0);
KLDRDYLDMOD_ASSERT(pMod->cRefs >= pMod->cDepRefs + pMod->cDynRefs);
KLDRDYLDMOD_ASSERT(pMod->enmState > KLDRSTATE_INVALID && pMod->enmState <= KLDRSTATE_END);
/* decrement. */
if (pMod->cRefs > 0)
pMod->cRefs--;
/* execute delayed freeing. */
if ( pMod->enmState == KLDRSTATE_DESTROYED
&& !pMod->cRefs)
{
pMod->u32MagicHead = 1;
pMod->u32MagicTail = 2;
kHlpFree(pMod);
}
}
/**
* Increment the count of modules depending on this module.
*
* @param pMod The module.
* @param pDep The module which depends on us.
*/
void kldrDyldModAddDep(PKLDRDYLDMOD pMod, PKLDRDYLDMOD pDep)
{
(void)pDep;
/* validate state */
switch (pMod->enmState)
{
case KLDRSTATE_MAPPED:
case KLDRSTATE_RELOADED:
case KLDRSTATE_LOADED_PREREQUISITES:
case KLDRSTATE_RELOADED_LOADED_PREREQUISITES:
case KLDRSTATE_PENDING_INITIALIZATION:
case KLDRSTATE_INITIALIZING:
case KLDRSTATE_GOOD:
break;
default:
KLDRDYLDMOD_ASSERT(!"invalid state");
break;
}
KLDRDYLDMOD_ASSERT(pMod->enmState > KLDRSTATE_INVALID && pMod->enmState <= KLDRSTATE_END);
pMod->cRefs++;
pMod->cDepRefs++;
}
/**
* Drop a dependency.
*
* @param pMod The module.
* @param pDep The module which depends on us.
*/
void kldrDyldModRemoveDep(PKLDRDYLDMOD pMod, PKLDRDYLDMOD pDep)
{
KLDRDYLDMOD_ASSERT(pMod->cDepRefs > 0);
if (pMod->cDepRefs == 0)
return;
KLDRDYLDMOD_ASSERT(pMod->cDepRefs <= pMod->cRefs);
KLDRDYLDMOD_ASSERT(pMod->enmState >= KLDRSTATE_MAPPED && pMod->enmState <= KLDRSTATE_PENDING_DESTROY);
pMod->cRefs--;
pMod->cDepRefs--;
if ( pMod->cDepRefs > 0
|| pMod->cDynRefs > 0)
return;
/*
* The module should be unloaded.
*/
kldrDyldModUnloadPrerequisites(pMod);
}
/**
* Increment the dynamic load count.
*
* @returns 0
* @param pMod The module.
*/
int kldrDyldModDynamicLoad(PKLDRDYLDMOD pMod)
{
KLDRDYLDMOD_ASSERT( pMod->enmState == KLDRSTATE_GOOD
|| pMod->enmState == KLDRSTATE_PENDING_INITIALIZATION
|| pMod->enmState == KLDRSTATE_INITIALIZING);
pMod->cRefs++;
pMod->cDynRefs++;
return 0;
}
/**
* Decrement the dynamic load count of the module and unload the module
* if the total reference count reaches zero.
*
* This may cause a cascade of unloading to occure. See kldrDyldModUnloadPrerequisites().
*
* @returns status code.
* @retval 0 on success.
* @retval KLDR_ERR_NOT_LOADED_DYNAMICALLY if the module wasn't loaded dynamically.
* @param pMod The module to unload.
*/
int kldrDyldModDynamicUnload(PKLDRDYLDMOD pMod)
{
if (pMod->cDynRefs == 0)
return KLDR_ERR_NOT_LOADED_DYNAMICALLY;
KLDRDYLDMOD_ASSERT(pMod->cDynRefs <= pMod->cRefs);
KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_GOOD);
pMod->cRefs--;
pMod->cDynRefs--;
if ( pMod->cDynRefs > 0
|| pMod->cDepRefs > 0)
return 0;
/*
* The module should be unloaded.
*/
kldrDyldModUnloadPrerequisites(pMod);
return 0;
}
/**
* Worker for kldrDyldModUnloadPrerequisites.
*
* @returns The number of modules that now can be unloaded.
* @param pMod The module in question.
*/
static KU32 kldrDyldModUnloadPrerequisitesOne(PKLDRDYLDMOD pMod)
{
PKLDRDYLDMOD pMod2;
KU32 cToUnload = 0;
KU32 i;
KLDRDYLDMOD_ASSERT(pMod->papPrereqs || !pMod->cPrereqs);
/*
* Release the one in this module.
*/
for (i = 0; i < pMod->cPrereqs; i++)
{
pMod2 = pMod->papPrereqs[i];
if (pMod2)
{
pMod->papPrereqs[i] = NULL;
/* do the derefering ourselves or we'll end up in a recursive loop here. */
KLDRDYLDMOD_ASSERT(pMod2->cDepRefs > 0);
KLDRDYLDMOD_ASSERT(pMod2->cRefs >= pMod2->cDepRefs);
pMod2->cDepRefs--;
pMod2->cRefs--;
cToUnload += !pMod2->cDepRefs && !pMod2->cDynRefs;
}
}
/*
* Change the state
*/
switch (pMod->enmState)
{
case KLDRSTATE_LOADED_PREREQUISITES:
case KLDRSTATE_FIXED_UP:
pMod->enmState = KLDRSTATE_PENDING_DESTROY;
kldrDyldModUnlink(pMod);
break;
case KLDRSTATE_PENDING_INITIALIZATION:
pMod->enmState = KLDRSTATE_PENDING_GC;
break;
case KLDRSTATE_RELOADED_FIXED_UP:
case KLDRSTATE_RELOADED_LOADED_PREREQUISITES:
case KLDRSTATE_GOOD:
pMod->enmState = KLDRSTATE_PENDING_TERMINATION;
break;
case KLDRSTATE_INITIALIZATION_FAILED:
break;
default:
KLDRDYLDMOD_ASSERT(!"invalid state");
break;
}
return cToUnload;
}
/**
* This is the heart of the unload code.
*
* It will recursivly (using the load list) initiate module unloading
* of all affected modules.
*
* This function will cause a state transition to PENDING_DESTROY, PENDING_GC
* or PENDING_TERMINATION depending on the module state. There is one exception
* to this, and that's INITIALIZATION_FAILED, where the state will not be changed.
*
* @param pMod The module which prerequisites should be unloaded.
*/
void kldrDyldModUnloadPrerequisites(PKLDRDYLDMOD pMod)
{
KU32 cToUnload;
/* sanity */
#ifdef KLDRDYLD_STRICT
{
PKLDRDYLDMOD pMod2;
for (pMod2 = kLdrDyldHead; pMod2; pMod2 = pMod2->Load.pNext)
KLDRDYLDMOD_ASSERT(pMod2->enmState != KLDRSTATE_GOOD || pMod2->cRefs);
}
#endif
KLDRDYLDMOD_ASSERT(pMod->papPrereqs);
/*
* Unload prereqs of the module we're called on first.
*/
cToUnload = kldrDyldModUnloadPrerequisitesOne(pMod);
/*
* Iterate the load list in a cyclic manner until there are no more
* modules that can be pushed on into unloading.
*/
while (cToUnload)
{
cToUnload = 0;
for (pMod = kLdrDyldHead; pMod; pMod = pMod->Load.pNext)
{
if ( pMod->cDepRefs
|| pMod->cDynRefs
|| pMod->enmState >= KLDRSTATE_PENDING_TERMINATION
|| pMod->enmState < KLDRSTATE_LOADED_PREREQUISITES)
continue;
cToUnload += kldrDyldModUnloadPrerequisitesOne(pMod);
}
}
}
/**
* Loads the prerequisite modules this module depends on.
*
* To find each of the prerequisite modules this method calls
* kldrDyldGetPrerequisite() and it will make sure the modules
* are added to the load stack frame.
*
* @returns 0 on success, non-zero native OS or kLdr status code on failure.
* The state is changed to LOADED_PREREQUISITES or RELOADED_LOADED_PREREQUISITES.
* @param pMod The module.
* @param pszPrefix Prefix to use when searching.
* @param pszSuffix Suffix to use when searching.
* @param enmSearch Method to use when locating the module and any modules it may depend on.
* @param fFlags Flags, a combintation of the KLDRYDLD_LOAD_FLAGS_* \#defines.
*/
int kldrDyldModLoadPrerequisites(PKLDRDYLDMOD pMod, const char *pszPrefix, const char *pszSuffix,
KLDRDYLDSEARCH enmSearch, unsigned fFlags)
{
KI32 cPrereqs;
KU32 i;
int rc = 0;
/* sanity */
switch (pMod->enmState)
{
case KLDRSTATE_MAPPED:
case KLDRSTATE_RELOADED:
break;
default:
KLDRDYLDMOD_ASSERT(!"invalid state");
return -1;
}
/*
* Query number of prerequiste modules and allocate the array.
*/
cPrereqs = kLdrModNumberOfImports(pMod->pMod, NULL);
kHlpAssert(cPrereqs >= 0);
if (pMod->cPrereqs != cPrereqs)
{
KLDRDYLDMOD_ASSERT(!pMod->papPrereqs);
pMod->papPrereqs = (PPKLDRDYLDMOD)kHlpAllocZ(sizeof(pMod->papPrereqs[0]) * cPrereqs);
if (!pMod->papPrereqs)
return KERR_NO_MEMORY;
pMod->cPrereqs = cPrereqs;
}
else
KLDRDYLDMOD_ASSERT(pMod->papPrereqs || !pMod->cPrereqs);
/*
* Iterate the prerequisites and load them.
*/
for (i = 0; i < pMod->cPrereqs; i++)
{
static char s_szPrereq[260];
PKLDRDYLDMOD pPrereqMod;
KLDRDYLDMOD_ASSERT(pMod->papPrereqs[i] == NULL);
rc = kLdrModGetImport(pMod->pMod, NULL, i, s_szPrereq, sizeof(s_szPrereq));
if (rc)
break;
rc = kldrDyldGetPrerequisite(s_szPrereq, pszPrefix, pszSuffix, enmSearch, fFlags, pMod, &pPrereqMod);
if (rc)
break;
pMod->papPrereqs[i] = pPrereqMod;
}
/* change the state regardless of what happend. */
if (pMod->enmState == KLDRSTATE_MAPPED)
pMod->enmState = KLDRSTATE_LOADED_PREREQUISITES;
else
pMod->enmState = KLDRSTATE_RELOADED_LOADED_PREREQUISITES;
return rc;
}
/**
* Maps an open module.
*
* On success the module will be in the MAPPED state.
*
* @returns 0 on success, non-zero native OS or kLdr status code on failure.
* @param pMod The module which needs to be unmapped and set pending for destruction.
*/
int kldrDyldModMap(PKLDRDYLDMOD pMod)
{
int rc;
/* sanity */
KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_OPEN);
KLDRDYLDMOD_ASSERT(!pMod->fMapped);
if (pMod->fMapped)
return 0;
/* do the job. */
rc = kLdrModMap(pMod->pMod);
if (!rc)
{
rc = kLdrModAllocTLS(pMod->pMod, KLDRMOD_INT_MAP);
if (!rc)
{
/** @todo TLS */
pMod->fMapped = 1;
pMod->enmState = KLDRSTATE_MAPPED;
}
else
kLdrModUnmap(pMod->pMod);
}
return rc;
}
/**
* Unmaps the module, unlinks it from everywhere marks it PENDING_DESTROY.
*
* @returns 0 on success, non-zero native OS or kLdr status code on failure.
* @param pMod The module which needs to be unmapped and set pending for destruction.
*/
int kldrDyldModUnmap(PKLDRDYLDMOD pMod)
{
int rc;
/* sanity */
KLDRDYLDMOD_ASSERT(pMod->cRefs > 0);
KLDRDYLDMOD_ASSERT(pMod->fMapped);
switch (pMod->enmState)
{
case KLDRSTATE_MAPPED:
case KLDRSTATE_GC:
case KLDRSTATE_PENDING_DESTROY:
break;
default:
KLDRDYLDMOD_ASSERT(!"invalid state");
return -1;
}
/* do the job. */
if (pMod->fAllocatedTLS)
{
kLdrModFreeTLS(pMod->pMod, KLDRMOD_INT_MAP);
pMod->fAllocatedTLS = 0;
}
rc = kLdrModUnmap(pMod->pMod);
if (!rc)
{
pMod->fMapped = 0;
if (pMod->enmState < KLDRSTATE_PENDING_DESTROY)
{
pMod->enmState = KLDRSTATE_PENDING_DESTROY;
kldrDyldModUnlink(pMod);
}
}
return rc;
}
/**
* Reloads the module.
*
* Reloading means that all modified pages are restored to their original
* state. Whether this includes the code segments depends on whether the fixups
* depend on the addend in the place they are fixing up - so it's format specific.
*
* @returns 0 on success, non-zero native OS or kLdr status code on failure.
* @param pMod The module which needs to be unmapped and set pending for destruction.
*/
int kldrDyldModReload(PKLDRDYLDMOD pMod)
{
int rc;
/* sanity */
KLDRDYLDMOD_ASSERT(pMod->cRefs > 0);
KLDRDYLDMOD_ASSERT(pMod->fMapped);
switch (pMod->enmState)
{
case KLDRSTATE_MAPPED:
case KLDRSTATE_GC:
case KLDRSTATE_PENDING_DESTROY:
break;
default:
KLDRDYLDMOD_ASSERT(!"invalid state");
return -1;
}
/* Free TLS before reloading. */
if (pMod->fAllocatedTLS)
{
kLdrModFreeTLS(pMod->pMod, KLDRMOD_INT_MAP);
pMod->fAllocatedTLS = 0;
}
/* Let the module interpreter do the reloading of the mapping. */
rc = kLdrModReload(pMod->pMod);
if (!rc)
{
rc = kLdrModAllocTLS(pMod->pMod, KLDRMOD_INT_MAP);
if (!rc)
{
pMod->fAllocatedTLS = 1;
pMod->enmState = KLDRSTATE_RELOADED;
}
}
return rc;
}
/**
* @copydoc FNKLDRMODGETIMPORT
* pvUser points to the KLDRDYLDMOD.
*/
static int kldrDyldModFixupGetImportCallback(PKLDRMOD pMod, KU32 iImport, KU32 iSymbol,
const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
PKLDRADDR puValue, KU32 *pfKind, void *pvUser)
{
static int s_cRecursiveCalls = 0;
PKLDRDYLDMOD pDyldMod = (PKLDRDYLDMOD)pvUser;
int rc;
/* guard against too deep forwarder recursion. */
if (s_cRecursiveCalls >= 5)
return KLDR_ERR_TOO_LONG_FORWARDER_CHAIN;
s_cRecursiveCalls++;
if (iImport != NIL_KLDRMOD_IMPORT)
{
/* specific import module search. */
PKLDRDYLDMOD pPrereqMod;
KLDRDYLDMOD_ASSERT(iImport < pDyldMod->cPrereqs);
pPrereqMod = pDyldMod->papPrereqs[iImport];
KLDRDYLDMOD_ASSERT(pPrereqMod);
KLDRDYLDMOD_ASSERT(pPrereqMod->u32MagicHead == KLDRDYMOD_MAGIC);
KLDRDYLDMOD_ASSERT(pPrereqMod->u32MagicTail == KLDRDYMOD_MAGIC);
KLDRDYLDMOD_ASSERT(pPrereqMod->enmState < KLDRSTATE_TERMINATING);
rc = kLdrModQuerySymbol(pPrereqMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP,
iSymbol, pchSymbol, cchSymbol, pszVersion,
kldrDyldModFixupGetImportCallback, pPrereqMod, puValue, pfKind);
if (rc)
{
if (pchSymbol)
kldrDyldFailure(rc, "%s[%d]->%s.%.*s%s", pDyldMod->pMod->pszName, iImport,
pPrereqMod->pMod->pszName, cchSymbol, pchSymbol, pszVersion ? pszVersion : "");
else
kldrDyldFailure(rc, "%s[%d]->%s.%d%s", pDyldMod->pMod->pszName, iImport,
pPrereqMod->pMod->pszName, iSymbol, pszVersion ? pszVersion : "");
}
}
else
{
/* bind list search. */
unsigned fFound = 0;
PKLDRDYLDMOD pBindMod = g_pkLdrDyldBindHead;
rc = 0;
while (pBindMod)
{
KU32 fKind;
KLDRADDR uValue;
rc = kLdrModQuerySymbol(pBindMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP,
iSymbol, pchSymbol, cchSymbol, pszVersion,
kldrDyldModFixupGetImportCallback, pBindMod, &uValue, &fKind);
if ( !rc
&& ( !fFound
|| !(fKind & KLDRSYMKIND_WEAK)
)
)
{
*pfKind = fKind;
*puValue = uValue;
fFound = 1;
if (!(fKind & KLDRSYMKIND_WEAK))
break;
}
/* next */
pBindMod = pBindMod->Bind.pNext;
}
rc = fFound ? 0 : KLDR_ERR_SYMBOL_NOT_FOUND;
if (!fFound)
{
if (pchSymbol)
kldrDyldFailure(rc, "%s->%.*s%s", pDyldMod->pMod->pszName, cchSymbol, pchSymbol, pszVersion ? pszVersion : "");
else
kldrDyldFailure(rc, "%s->%d%s", pDyldMod->pMod->pszName, iSymbol, pszVersion ? pszVersion : "");
}
}
s_cRecursiveCalls--;
return rc;
}
/**
* Applies fixups to a module which prerequisistes has been
* successfully loaded.
*
* @returns 0 on success, non-zero native OS or kLdr status code on failure.
* @param pMod The module which needs to be unmapped and set pending for destruction.
*/
int kldrDyldModFixup(PKLDRDYLDMOD pMod)
{
int rc;
/* sanity */
KLDRDYLDMOD_ASSERT(pMod->cRefs > 0);
KLDRDYLDMOD_ASSERT( pMod->enmState == KLDRSTATE_LOADED_PREREQUISITES
|| pMod->enmState == KLDRSTATE_RELOADED_LOADED_PREREQUISITES);
/* do the job */
rc = kLdrModFixupMapping(pMod->pMod, kldrDyldModFixupGetImportCallback, pMod);/** @todo fixme. */
if (!rc)
pMod->enmState = KLDRSTATE_FIXED_UP;
return rc;
}
/**
* Calls the module initialization entry point if any.
*
* This is considered to be a module specific thing and leave if
* to the module interpreter. They will have to deal with different
* module init practices between platforms should there be any.
*
* @returns 0 and state changed to GOOD on success.
* Non-zero OS or kLdr status code and status changed to INITIALIZATION_FAILED on failure.
* @param pMod The module that should be initialized.
*/
int kldrDyldModCallInit(PKLDRDYLDMOD pMod)
{
int rc;
KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_PENDING_INITIALIZATION);
KLDRDYLDMOD_ASSERT(!pMod->fInitList);
pMod->enmState = KLDRSTATE_INITIALIZING;
rc = kLdrModCallInit(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod);
if (!rc)
{
pMod->enmState = KLDRSTATE_GOOD;
/* push it onto the termination list.*/
pMod->InitTerm.pPrev = NULL;
pMod->InitTerm.pNext = g_pkLdrDyldTermHead;
if (g_pkLdrDyldTermHead)
g_pkLdrDyldTermHead->InitTerm.pPrev = pMod;
else
g_pkLdrDyldTermTail = pMod;
g_pkLdrDyldTermHead = pMod;
}
else
pMod->enmState = KLDRSTATE_INITIALIZATION_FAILED;
return rc;
}
/**
* Calls the module termination entry point if any.
*
* This'll change the module status to PENDING_GC.
*
* @param pMod The module that should be initialized.
*/
void kldrDyldModCallTerm(PKLDRDYLDMOD pMod)
{
KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_PENDING_TERMINATION);
pMod->enmState = KLDRSTATE_TERMINATING;
kLdrModCallTerm(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod);
pMod->enmState = KLDRSTATE_PENDING_GC;
/* unlinking on destruction. */
}
/**
* Calls the thread attach entry point if any.
*
* @returns 0 on success, non-zero on failure.
* @param pMod The module.
*/
int kldrDyldModAttachThread(PKLDRDYLDMOD pMod)
{
KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_GOOD);
return kLdrModCallThread(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod, 1 /* attach */);
}
/**
* Calls the thread detach entry point if any.
*
* @returns 0 on success, non-zero on failure.
* @param pMod The module.
*/
void kldrDyldModDetachThread(PKLDRDYLDMOD pMod)
{
KLDRDYLDMOD_ASSERT(pMod->enmState == KLDRSTATE_GOOD);
kLdrModCallThread(pMod->pMod, KLDRMOD_INT_MAP, (KUPTR)pMod->hMod, 0 /* detach */);
}
/**
* Gets the main stack, allocate it if necessary.
*
* @returns 0 on success, non-zero native OS or kLdr status code on failure.
* @param pMod The module.
* @param ppvStack Where to store the address of the stack (lowest address).
* @param pcbStack Where to store the size of the stack.
*/
int kldrDyldModGetMainStack(PKLDRDYLDMOD pMod, void **ppvStack, KSIZE *pcbStack)
{
int rc = 0;
KLDRSTACKINFO StackInfo;
KLDRDYLDMOD_ASSERT(pMod->fExecutable);
/*
* Since we might have to allocate the stack ourselves, and there will only
* ever be one main stack, we'll be keeping the main stack info in globals.
*/
if (!g_fkLdrDyldDoneMainStack)
{
rc = kLdrModGetStackInfo(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, &StackInfo);
if (!rc)
{
/* check if there is a stack size override/default. */
KSIZE cbDefOverride;
if (kHlpGetEnvUZ("KLDR_MAIN_STACK_SIZE", &cbDefOverride))
cbDefOverride = 0;
/* needs allocating? */
if ( StackInfo.LinkAddress == NIL_KLDRADDR
|| StackInfo.cbStack < cbDefOverride)
{
KSIZE cbStack = (KSIZE)K_MAX(StackInfo.cbStack, cbDefOverride);
g_pvkLdrDyldMainStack = kldrDyldOSAllocStack(cbStack);
if (g_pvkLdrDyldMainStack)
{
g_cbkLdrDyldMainStack = cbStack;
g_fkLdrDyldMainStackAllocated = 1;
}
else
rc = KLDR_ERR_MAIN_STACK_ALLOC_FAILED;
}
else
{
KLDRDYLDMOD_ASSERT(StackInfo.Address != NIL_KLDRADDR);
KLDRDYLDMOD_ASSERT(StackInfo.cbStack > 0);
g_fkLdrDyldMainStackAllocated = 0;
g_pvkLdrDyldMainStack = (void *)(KUPTR)StackInfo.Address;
KLDRDYLDMOD_ASSERT((KUPTR)g_pvkLdrDyldMainStack == StackInfo.Address);
g_cbkLdrDyldMainStack = (KSIZE)StackInfo.cbStack;
KLDRDYLDMOD_ASSERT(StackInfo.cbStack == g_cbkLdrDyldMainStack);
}
}
if (!rc)
g_fkLdrDyldDoneMainStack = 1;
}
if (!rc)
{
if (ppvStack)
*ppvStack = g_pvkLdrDyldMainStack;
if (pcbStack)
*pcbStack = g_cbkLdrDyldMainStack;
}
return rc;
}
/**
* This starts the executable module.
*
* @returns non-zero OS or kLdr status code on failure.
* (won't return on success.)
* @param pMod The executable module.
*/
int kldrDyldModStartExe(PKLDRDYLDMOD pMod)
{
int rc;
KLDRADDR MainEPAddress;
void *pvStack;
KSIZE cbStack;
KLDRDYLDMOD_ASSERT(pMod->fExecutable);
rc = kLdrModQueryMainEntrypoint(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, &MainEPAddress);
if (rc)
return rc;
rc = kldrDyldModGetMainStack(pMod, &pvStack, &cbStack);
if (rc)
return rc;
return kldrDyldOSStartExe((KUPTR)MainEPAddress, pvStack, cbStack);
}
/**
* Gets the module name.
*
* @returns 0 on success, KERR_BUFFER_OVERFLOW on failure.
* @param pMod The module.
* @param pszName Where to store the name.
* @param cchName The size of the name buffer.
*/
int kldrDyldModGetName(PKLDRDYLDMOD pMod, char *pszName, KSIZE cchName)
{
KSIZE cch = K_MIN(cchName, pMod->pMod->cchName + 1);
if (cch)
{
kHlpMemCopy(pszName, pMod->pMod->pszName, cch - 1);
pszName[cch - 1] = '\0';
}
return cchName <= pMod->pMod->cchName ? KERR_BUFFER_OVERFLOW : 0;
}
/**
* Gets the module filename.
*
* @returns 0 on success, KERR_BUFFER_OVERFLOW on failure.
* @param pMod The module.
* @param pszFilename Where to store the filename.
* @param cchFilename The size of the filename buffer.
*/
int kldrDyldModGetFilename(PKLDRDYLDMOD pMod, char *pszFilename, KSIZE cchFilename)
{
KSIZE cch = K_MIN(cchFilename, pMod->pMod->cchFilename + 1);
if (cch)
{
kHlpMemCopy(pszFilename, pMod->pMod->pszFilename, cch - 1);
pszFilename[cch - 1] = '\0';
}
return cchFilename <= pMod->pMod->cchFilename ? KERR_BUFFER_OVERFLOW : 0;
}
/**
* Gets the address/value of a symbol in the specified module.
*
* @returns 0 on success, KLDR_ERR_SYMBOL_NOT_FOUND on failure.
* @param pMod The module.
* @param uSymbolOrdinal The symbol ordinal 0. This is ignored if the name is non-zero.
* @param pszSymbolName The symbol name. Can be NULL.
* @param puValue Where to store the value. optional.
* @param pfKind Where to store the symbol kind. optional.
*/
int kldrDyldModQuerySymbol(PKLDRDYLDMOD pMod, KU32 uSymbolOrdinal, const char *pszSymbolName,
KUPTR *puValue, KU32 *pfKind)
{
int rc;
KLDRADDR uValue = 0;
KU32 fKind = 0;
rc = kLdrModQuerySymbol(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP,
uSymbolOrdinal, pszSymbolName, kHlpStrLen(pszSymbolName), NULL,
kldrDyldModFixupGetImportCallback, pMod,
&uValue, &fKind);
if (!rc)
{
if (puValue)
{
*puValue = (KUPTR)uValue;
KLDRDYLDMOD_ASSERT(*puValue == uValue);
}
if (pfKind)
*pfKind = fKind;
}
return rc;
}
|