forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshmobjectmanager.cpp
More file actions
1568 lines (1283 loc) · 38.8 KB
/
shmobjectmanager.cpp
File metadata and controls
1568 lines (1283 loc) · 38.8 KB
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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
/*++
Module Name:
shmobjectmgr.cpp
Abstract:
Shared memory based object manager
--*/
#include "shmobjectmanager.hpp"
#include "shmobject.hpp"
#include "pal/cs.hpp"
#include "pal/thread.hpp"
#include "pal/procobj.hpp"
#include "pal/dbgmsg.h"
SET_DEFAULT_DEBUG_CHANNEL(PAL);
#include "pal/corunix.inl"
using namespace CorUnix;
IPalObjectManager * CorUnix::g_pObjectManager;
static
PAL_ERROR
CheckObjectTypeAndRights(
IPalObject *pobj,
CAllowedObjectTypes *paot,
DWORD dwRightsGranted,
DWORD dwRightsRequired
);
/*++
Function:
CSharedMemoryObjectManager::Initialize
Performs (possibly failing) startup tasks for the object manager
Parameters:
None
--*/
PAL_ERROR
CSharedMemoryObjectManager::Initialize(
void
)
{
PAL_ERROR palError = NO_ERROR;
ENTRY("CSharedMemoryObjectManager::Initialize (this=%p)\n", this);
InitializeListHead(&m_leNamedObjects);
InitializeListHead(&m_leAnonymousObjects);
InternalInitializeCriticalSection(&m_csListLock);
m_fListLockInitialized = TRUE;
palError = m_HandleManager.Initialize();
LOGEXIT("CSharedMemoryObjectManager::Initialize returns %d", palError);
return palError;
}
/*++
Function:
CSharedMemoryObjectManager::Shutdown
Cleans up the object manager. This routine will call cleanup routines
for all objects referenced by this process. After this routine is called
no attempt should be made to access an IPalObject.
Parameters:
pthr -- thread data for calling thread
--*/
PAL_ERROR
CSharedMemoryObjectManager::Shutdown(
CPalThread *pthr
)
{
PLIST_ENTRY ple;
CSharedMemoryObject *pshmobj;
_ASSERTE(NULL != pthr);
ENTRY("CSharedMemoryObjectManager::Shutdown (this=%p, pthr=%p)\n",
this,
pthr
);
InternalEnterCriticalSection(pthr, &m_csListLock);
SHMLock();
while (!IsListEmpty(&m_leAnonymousObjects))
{
ple = RemoveTailList(&m_leAnonymousObjects);
pshmobj = CSharedMemoryObject::GetObjectFromListLink(ple);
pshmobj->CleanupForProcessShutdown(pthr);
}
while (!IsListEmpty(&m_leNamedObjects))
{
ple = RemoveTailList(&m_leNamedObjects);
pshmobj = CSharedMemoryObject::GetObjectFromListLink(ple);
pshmobj->CleanupForProcessShutdown(pthr);
}
SHMRelease();
InternalLeaveCriticalSection(pthr, &m_csListLock);
LOGEXIT("CSharedMemoryObjectManager::Shutdown returns %d\n", NO_ERROR);
return NO_ERROR;
}
/*++
Function:
CSharedMemoryObjectManager::AllocateObject
Allocates a new object instance of the specified type.
Parameters:
pthr -- thread data for calling thread
pot -- type of object to allocate
poa -- attributes (name and SD) of object to allocate
ppobjNew -- on success, receives a reference to the new object
--*/
PAL_ERROR
CSharedMemoryObjectManager::AllocateObject(
CPalThread *pthr,
CObjectType *pot,
CObjectAttributes *poa,
IPalObject **ppobjNew // OUT
)
{
PAL_ERROR palError = NO_ERROR;
CSharedMemoryObject *pshmobj = NULL;
_ASSERTE(NULL != pthr);
_ASSERTE(NULL != pot);
_ASSERTE(NULL != poa);
_ASSERTE(NULL != ppobjNew);
ENTRY("CSharedMemoryObjectManager::AllocateObject "
"(this=%p, pthr=%p, pot=%p, poa=%p, ppobjNew=%p)\n",
this,
pthr,
pot,
poa,
ppobjNew
);
if (CObjectType::WaitableObject == pot->GetSynchronizationSupport())
{
pshmobj = InternalNew<CSharedMemoryWaitableObject>(pot, &m_csListLock);
}
else
{
pshmobj = InternalNew<CSharedMemoryObject>(pot, &m_csListLock);
}
if (NULL != pshmobj)
{
palError = pshmobj->Initialize(pthr, poa);
if (NO_ERROR == palError)
{
*ppobjNew = static_cast<IPalObject*>(pshmobj);
}
}
else
{
ERROR("Unable to allocate pshmobj\n");
palError = ERROR_OUTOFMEMORY;
}
LOGEXIT("CSharedMemoryObjectManager::AllocateObject returns %d\n", palError);
return palError;
}
/*++
Function:
CSharedMemoryObjectManager::RegisterObject
Registers a newly-allocated object instance. If the object to be registered
has a name, and a previously registered object has the same name the new
object will not be registered.
Distinguished return values:
ERROR_ALREADY_EXISTS -- an object of a compatible type was already registered
with the specified name
ERROR_INVALID_HANDLE -- an object of an incompatible type was already
registered with the specified name
Parameters:
pthr -- thread data for calling thread
pobjToRegister -- the object instance to register. This routine will always
call ReleaseReference on this instance
paot -- object types that are compatible with the new object instance
dwRightsRequested -- requested access rights for the returned handle (ignored)
pHandle -- on success, receives a handle to the registered object
ppobjRegistered -- on success, receives a reference to the registered object
instance.
--*/
PAL_ERROR
CSharedMemoryObjectManager::RegisterObject(
CPalThread *pthr,
IPalObject *pobjToRegister,
CAllowedObjectTypes *paot,
DWORD dwRightsRequested,
HANDLE *pHandle, // OUT
IPalObject **ppobjRegistered // OUT
)
{
PAL_ERROR palError = NO_ERROR;
CSharedMemoryObject *pshmobj = static_cast<CSharedMemoryObject*>(pobjToRegister);
SHMObjData *psmodNew = NULL;
CObjectAttributes *poa;
CObjectType *potObj;
IPalObject *pobjExisting;
BOOL fInherit = FALSE;
BOOL fShared = FALSE;
_ASSERTE(NULL != pthr);
_ASSERTE(NULL != pobjToRegister);
_ASSERTE(NULL != paot);
_ASSERTE(NULL != pHandle);
_ASSERTE(NULL != ppobjRegistered);
ENTRY("CSharedMemoryObjectManager::RegisterObject "
"(this=%p, pthr=%p, pobjToRegister=%p, paot=%p, "
"dwRightsRequested=%d, pHandle=%p, ppobjRegistered=%p)\n",
this,
pthr,
pobjToRegister,
paot,
dwRightsRequested,
pHandle,
ppobjRegistered
);
poa = pobjToRegister->GetObjectAttributes();
_ASSERTE(NULL != poa);
if (NULL != poa->pSecurityAttributes)
{
fInherit = poa->pSecurityAttributes->bInheritHandle;
}
potObj = pobjToRegister->GetObjectType();
fShared = (SharedObject == pshmobj->GetObjectDomain());
InternalEnterCriticalSection(pthr, &m_csListLock);
if (fShared)
{
//
// We only need to acquire the shared memory lock if this
// object is actually shared.
//
SHMLock();
}
if (0 != poa->sObjectName.GetStringLength())
{
SHMPTR shmObjectListHead = SHMNULL;
//
// The object must be shared
//
_ASSERTE(fShared);
//
// Check if an object by this name already exists
//
palError = LocateObject(
pthr,
&poa->sObjectName,
paot,
&pobjExisting
);
if (NO_ERROR == palError)
{
//
// Obtain a new handle to the existing object
//
palError = ObtainHandleForObject(
pthr,
pobjExisting,
dwRightsRequested,
fInherit,
NULL,
pHandle
);
if (NO_ERROR == palError)
{
//
// Transfer object reference to out param
//
*ppobjRegistered = pobjExisting;
palError = ERROR_ALREADY_EXISTS;
}
else
{
pobjExisting->ReleaseReference(pthr);
}
goto RegisterObjectExit;
}
else if (ERROR_INVALID_NAME != palError)
{
//
// Something different than an object not found error
// occurred. This is most likely due to a type conflict.
//
goto RegisterObjectExit;
}
//
// Insert the object on the named object lists
//
InsertTailList(&m_leNamedObjects, pshmobj->GetObjectListLink());
psmodNew = SHMPTR_TO_TYPED_PTR(SHMObjData, pshmobj->GetShmObjData());
if (NULL == psmodNew)
{
ASSERT("Failure to map shared object data\n");
palError = ERROR_INTERNAL_ERROR;
goto RegisterObjectExit;
}
shmObjectListHead = SHMGetInfo(SIID_NAMED_OBJECTS);
if (SHMNULL != shmObjectListHead)
{
SHMObjData *psmodListHead;
psmodListHead = SHMPTR_TO_TYPED_PTR(SHMObjData, shmObjectListHead);
if (NULL != psmodListHead)
{
psmodNew->shmNextObj = shmObjectListHead;
psmodListHead->shmPrevObj = pshmobj->GetShmObjData();
}
else
{
ASSERT("Failure to map shared object data\n");
palError = ERROR_INTERNAL_ERROR;
goto RegisterObjectExit;
}
}
psmodNew->fAddedToList = TRUE;
if (!SHMSetInfo(SIID_NAMED_OBJECTS, pshmobj->GetShmObjData()))
{
ASSERT("Failed to set shared named object list head\n");
palError = ERROR_INTERNAL_ERROR;
goto RegisterObjectExit;
}
}
else
{
//
// Place the object on the anonymous object list
//
InsertTailList(&m_leAnonymousObjects, pshmobj->GetObjectListLink());
}
//
// Hoist the object's immutable data (if any) into shared memory if
// the object is shared
//
if (fShared && 0 != potObj->GetImmutableDataSize())
{
VOID *pvImmutableData;
SHMObjData *psmod;
palError = pobjToRegister->GetImmutableData(&pvImmutableData);
if (NO_ERROR != palError)
{
ASSERT("Failure to obtain object immutable data\n");
goto RegisterObjectExit;
}
psmod = SHMPTR_TO_TYPED_PTR(SHMObjData, pshmobj->GetShmObjData());
if (NULL != psmod)
{
VOID *pvSharedImmutableData =
SHMPTR_TO_TYPED_PTR(VOID, psmod->shmObjImmutableData);
if (NULL != pvSharedImmutableData)
{
CopyMemory(
pvSharedImmutableData,
pvImmutableData,
potObj->GetImmutableDataSize()
);
}
else
{
ASSERT("Failure to map psmod->shmObjImmutableData\n");
palError = ERROR_INTERNAL_ERROR;
goto RegisterObjectExit;
}
}
else
{
ASSERT("Failure to map pshmobj->GetShmObjData()\n");
palError = ERROR_INTERNAL_ERROR;
goto RegisterObjectExit;
}
}
//
// Obtain a handle for the new object
//
palError = ObtainHandleForObject(
pthr,
pobjToRegister,
dwRightsRequested,
fInherit,
NULL,
pHandle
);
if (NO_ERROR == palError)
{
//
// Transfer pobjToRegister reference to out param
//
*ppobjRegistered = pobjToRegister;
pobjToRegister = NULL;
}
RegisterObjectExit:
if (fShared)
{
SHMRelease();
}
InternalLeaveCriticalSection(pthr, &m_csListLock);
if (NULL != pobjToRegister)
{
pobjToRegister->ReleaseReference(pthr);
}
LOGEXIT("CSharedMemoryObjectManager::RegisterObject return %d\n", palError);
return palError;
}
/*++
Function:
CSharedMemoryObjectManager::LocateObject
Search for a previously registered object with a give name and type
Distinguished return values:
ERROR_INVALID_NAME -- no object with the specified name was previously
registered
ERROR_INVALID_HANDLE -- an object with the specified name was previously
registered, but its type is not compatible
Parameters:
pthr -- thread data for calling thread
psObjectToLocate -- the name of the object to locate
paot -- acceptable types for the object
ppobj -- on success, receives a reference to the object instance
--*/
PAL_ERROR
CSharedMemoryObjectManager::LocateObject(
CPalThread *pthr,
CPalString *psObjectToLocate,
CAllowedObjectTypes *paot,
IPalObject **ppobj // OUT
)
{
PAL_ERROR palError = NO_ERROR;
IPalObject *pobjExisting = NULL;
SHMPTR shmSharedObjectData = SHMNULL;
SHMPTR shmObjectListEntry = SHMNULL;
SHMObjData *psmod = NULL;
LPWSTR pwsz = NULL;
_ASSERTE(NULL != pthr);
_ASSERTE(NULL != psObjectToLocate);
_ASSERTE(NULL != psObjectToLocate->GetString());
_ASSERTE(PAL_wcslen(psObjectToLocate->GetString()) == psObjectToLocate->GetStringLength());
_ASSERTE(NULL != ppobj);
ENTRY("CSharedMemoryObjectManager::LocateObject "
"(this=%p, pthr=%p, psObjectToLocate=%p, paot=%p, "
"ppobj=%p)\n",
this,
pthr,
psObjectToLocate,
paot,
ppobj
);
TRACE("Searching for object name %S\n", psObjectToLocate->GetString());
InternalEnterCriticalSection(pthr, &m_csListLock);
//
// Search the local named object list for this object
//
for (PLIST_ENTRY ple = m_leNamedObjects.Flink;
ple != &m_leNamedObjects;
ple = ple->Flink)
{
CObjectAttributes *poa;
CSharedMemoryObject *pshmobj =
CSharedMemoryObject::GetObjectFromListLink(ple);
poa = pshmobj->GetObjectAttributes();
_ASSERTE(NULL != poa);
if (poa->sObjectName.GetStringLength() != psObjectToLocate->GetStringLength())
{
continue;
}
if (0 != PAL_wcscmp(poa->sObjectName.GetString(), psObjectToLocate->GetString()))
{
continue;
}
//
// This object has the name we're looking for
//
pobjExisting = static_cast<IPalObject*>(pshmobj);
break;
}
if (NULL != pobjExisting)
{
//
// Validate the located object's type
//
if (paot->IsTypeAllowed(
pobjExisting->GetObjectType()->GetId()
))
{
TRACE("Local object exists with compatible type\n");
//
// Add a reference to the found object
//
pobjExisting->AddReference();
*ppobj = pobjExisting;
}
else
{
TRACE("Local object exists w/ incompatible type\n");
palError = ERROR_INVALID_HANDLE;
}
goto LocateObjectExit;
}
//
// Search the shared memory named object list for a matching object
//
SHMLock();
shmObjectListEntry = SHMGetInfo(SIID_NAMED_OBJECTS);
while (SHMNULL != shmObjectListEntry)
{
psmod = SHMPTR_TO_TYPED_PTR(SHMObjData, shmObjectListEntry);
if (NULL != psmod)
{
if (psmod->dwNameLength == psObjectToLocate->GetStringLength())
{
pwsz = SHMPTR_TO_TYPED_PTR(WCHAR, psmod->shmObjName);
if (NULL != pwsz)
{
if (0 == PAL_wcscmp(pwsz, psObjectToLocate->GetString()))
{
//
// This is the object we were looking for.
//
shmSharedObjectData = shmObjectListEntry;
break;
}
}
else
{
ASSERT("Unable to map psmod->shmObjName\n");
break;
}
}
shmObjectListEntry = psmod->shmNextObj;
}
else
{
ASSERT("Unable to map shmObjectListEntry\n");
break;
}
}
if (SHMNULL != shmSharedObjectData)
{
CSharedMemoryObject *pshmobj = NULL;
CObjectAttributes oa(pwsz, NULL);
//
// Check if the type is allowed
//
if (!paot->IsTypeAllowed(psmod->eTypeId))
{
TRACE("Remote object exists w/ incompatible type\n");
palError = ERROR_INVALID_HANDLE;
goto LocateObjectExitSHMRelease;
}
//
// Get the local instance of the CObjectType
//
CObjectType *pot = CObjectType::GetObjectTypeById(psmod->eTypeId);
if (NULL == pot)
{
ASSERT("Invalid object type ID in shared memory info\n");
goto LocateObjectExitSHMRelease;
}
TRACE("Remote object exists compatible type -- importing\n");
//
// Create the local state for the shared object
//
palError = ImportSharedObjectIntoProcess(
pthr,
pot,
&oa,
shmSharedObjectData,
psmod,
TRUE,
&pshmobj
);
if (NO_ERROR == palError)
{
*ppobj = static_cast<IPalObject*>(pshmobj);
}
else
{
ERROR("Failure initializing object from shared data\n");
goto LocateObjectExitSHMRelease;
}
}
else
{
//
// The object was not found
//
palError = ERROR_INVALID_NAME;
}
LocateObjectExitSHMRelease:
SHMRelease();
LocateObjectExit:
InternalLeaveCriticalSection(pthr, &m_csListLock);
LOGEXIT("CSharedMemoryObjectManager::LocateObject returns %d\n", palError);
return palError;
}
/*++
Function:
CSharedMemoryObjectManager::ObtainHandleForObject
Allocated a new handle for an object
Parameters:
pthr -- thread data for calling thread
pobj -- the object to allocate a handle for
dwRightsRequired -- the access rights to grant the handle; currently ignored
fInheritHandle -- true if the handle is inheritable; ignored for all but file
objects that represent pipes
pProcessForHandle -- the process the handle is to be used from; currently
must be NULL
pNewHandle -- on success, receives the newly allocated handle
--*/
PAL_ERROR
CSharedMemoryObjectManager::ObtainHandleForObject(
CPalThread *pthr,
IPalObject *pobj,
DWORD dwRightsRequested,
bool fInheritHandle,
IPalProcess *pProcessForHandle, // IN, OPTIONAL
HANDLE *pNewHandle // OUT
)
{
PAL_ERROR palError = NO_ERROR;
_ASSERTE(NULL != pthr);
_ASSERTE(NULL != pobj);
_ASSERTE(NULL != pNewHandle);
ENTRY("CSharedMemoryObjectManager::ObtainHandleForObject "
"(this=%p, pthr=%p, pobj=%p, dwRightsRequested=%d, "
"fInheritHandle=%p, pProcessForHandle=%p, pNewHandle=%p)\n",
this,
pthr,
pobj,
dwRightsRequested,
fInheritHandle,
pProcessForHandle,
pNewHandle
);
if (NULL != pProcessForHandle)
{
//
// Not yet supported
//
ASSERT("Caller to ObtainHandleForObject provided a process\n");
return ERROR_CALL_NOT_IMPLEMENTED;
}
palError = m_HandleManager.AllocateHandle(
pthr,
pobj,
dwRightsRequested,
fInheritHandle,
pNewHandle
);
LOGEXIT("CSharedMemoryObjectManager::ObtainHandleForObject return %d\n", palError);
return palError;
}
/*++
Function:
CSharedMemoryObjectManager::RevokeHandle
Removes a handle from the process's handle table, which in turn releases
the handle's reference on the object instance it refers to
Parameters:
pthr -- thread data for calling thread
hHandleToRevoke -- the handle to revoke
--*/
PAL_ERROR
CSharedMemoryObjectManager::RevokeHandle(
CPalThread *pthr,
HANDLE hHandleToRevoke
)
{
PAL_ERROR palError = NO_ERROR;
_ASSERTE(NULL != pthr);
ENTRY("CSharedMemoryObjectManager::RevokeHandle "
"(this=%p, pthr=%p, hHandleToRevoke=%p)\n",
this,
pthr,
hHandleToRevoke
);
palError = m_HandleManager.FreeHandle(pthr, hHandleToRevoke);
LOGEXIT("CSharedMemoryObjectManager::RevokeHandle returns %d\n", palError);
return palError;
}
/*++
Function:
CSharedMemoryObjectManager::ReferenceObjectByHandle
Returns a referenced object instance that a handle refers to
Parameters:
pthr -- thread data for calling thread
hHandleToReference -- the handle to reference
paot -- acceptable types for the underlying object
dwRightsRequired -- the access rights that the handle must have been
granted; currently ignored
ppobj -- on success, receives a reference to the object instance
--*/
PAL_ERROR
CSharedMemoryObjectManager::ReferenceObjectByHandle(
CPalThread *pthr,
HANDLE hHandleToReference,
CAllowedObjectTypes *paot,
DWORD dwRightsRequired,
IPalObject **ppobj // OUT
)
{
PAL_ERROR palError;
DWORD dwRightsGranted;
IPalObject *pobj;
_ASSERTE(NULL != pthr);
_ASSERTE(NULL != paot);
_ASSERTE(NULL != ppobj);
ENTRY("CSharedMemoryObjectManager::ReferenceObjectByHandle "
"(this=%p, pthr=%p, hHandleToReference=%p, paot=%p, "
"dwRightsRequired=%d, ppobj=%p)\n",
this,
pthr,
hHandleToReference,
paot,
dwRightsRequired,
ppobj
);
palError = m_HandleManager.GetObjectFromHandle(
pthr,
hHandleToReference,
&dwRightsGranted,
&pobj
);
if (NO_ERROR == palError)
{
palError = CheckObjectTypeAndRights(
pobj,
paot,
dwRightsGranted,
dwRightsRequired
);
if (NO_ERROR == palError)
{
//
// Transfer object reference to out parameter
//
*ppobj = pobj;
}
else
{
pobj->ReleaseReference(pthr);
}
}
LOGEXIT("CSharedMemoryObjectManager::ReferenceObjectByHandle returns %d\n",
palError
);
return palError;
}
/*++
Function:
CSharedMemoryObjectManager::ReferenceObjectByHandleArray
Returns the referenced object instances that an array of handles
refer to.
Parameters:
pthr -- thread data for calling thread
rgHandlesToReference -- the array of handles to reference
dwHandleCount -- the number of handles in the arrayu
paot -- acceptable types for the underlying objects
dwRightsRequired -- the access rights that the handles must have been
granted; currently ignored
rgpobjs -- on success, receives references to the object instances; will
be empty on failures
--*/
PAL_ERROR
CSharedMemoryObjectManager::ReferenceMultipleObjectsByHandleArray(
CPalThread *pthr,
HANDLE rghHandlesToReference[],
DWORD dwHandleCount,
CAllowedObjectTypes *paot,
DWORD dwRightsRequired,
IPalObject *rgpobjs[] // OUT (caller allocated)
)
{
PAL_ERROR palError = NO_ERROR;
IPalObject *pobj = NULL;
DWORD dwRightsGranted;
DWORD dw;
_ASSERTE(NULL != pthr);
_ASSERTE(NULL != rghHandlesToReference);
_ASSERTE(0 < dwHandleCount);
_ASSERTE(NULL != paot);
_ASSERTE(NULL != rgpobjs);
ENTRY("CSharedMemoryObjectManager::ReferenceMultipleObjectsByHandleArray "
"(this=%p, pthr=%p, rghHandlesToReference=%p, dwHandleCount=%d, "
"pAllowedTyped=%d, dwRightsRequired=%d, rgpobjs=%p)\n",
this,
pthr,
rghHandlesToReference,
dwHandleCount,
paot,
dwRightsRequired,
rgpobjs
);
m_HandleManager.Lock(pthr);
for (dw = 0; dw < dwHandleCount; dw += 1)
{
palError = m_HandleManager.GetObjectFromHandle(
pthr,
rghHandlesToReference[dw],
&dwRightsGranted,
&pobj
);
if (NO_ERROR == palError)
{
palError = CheckObjectTypeAndRights(
pobj,
paot,
dwRightsGranted,
dwRightsRequired
);
if (NO_ERROR == palError)
{
//
// Transfer reference to out array
//
rgpobjs[dw] = pobj;
pobj = NULL;
}
}
if (NO_ERROR != palError)
{
break;
}
}
//
// The handle manager lock must be released before releasing
// any object references, as ReleaseReference will acquire
// the object manager list lock (which needs to be acquired before
// the handle manager lock)
//
m_HandleManager.Unlock(pthr);
if (NO_ERROR != palError)
{
//
// dw's current value is the failing index, so we want
// to free from dw - 1.
//