Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd81b066

Browse files
authored
Move Marshal memory allocation methods into CoreLib shared partition (#41911)
* Move Marshal memory allocation methods into CoreLib shared partition* Unify behavior across platforms
1 parentc15455a commitd81b066

File tree

25 files changed

+305
-341
lines changed

25 files changed

+305
-341
lines changed

‎src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,6 @@
250250
<CompileInclude="$(CommonPath)Interop\Windows\Kernel32\Interop.HandleTypes.cs">
251251
<Link>Common\Interop\Windows\Kernel32\Interop.HandleTypes.cs</Link>
252252
</Compile>
253-
<CompileInclude="$(CommonPath)Interop\Windows\Kernel32\Interop.LocalAlloc.cs">
254-
<Link>Common\Interop\Windows\Kernel32\Interop.LocalAlloc.cs</Link>
255-
</Compile>
256-
<CompileInclude="$(CommonPath)Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs">
257-
<Link>Common\Interop\Windows\Ole32\Interop.CoTaskMemAlloc.cs</Link>
258-
</Compile>
259253
<CompileInclude="$(CommonPath)Interop\Windows\OleAut32\Interop.SysAllocStringByteLen.cs">
260254
<Link>Common\Interop\Windows\OleAut32\Interop.SysAllocStringByteLen.cs</Link>
261255
</Compile>

‎src/coreclr/src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ internal static partial class Interop
88
internalstaticpartialclassLibraries
99
{
1010
internalconststringKernel32=RuntimeHelpers.QCall;
11-
internalconststringUser32=RuntimeHelpers.QCall;
12-
internalconststringOle32=RuntimeHelpers.QCall;
1311
internalconststringOleAut32=RuntimeHelpers.QCall;
14-
internalconststringAdvapi32=RuntimeHelpers.QCall;
1512
}
1613
}

‎src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs‎

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -250,52 +250,6 @@ public static IntPtr GetHINSTANCE(Module m)
250250
[MethodImpl(MethodImplOptions.InternalCall)]
251251
internalstaticexternExceptionGetExceptionForHRInternal(interrorCode,IntPtrerrorInfo);
252252

253-
publicstaticIntPtrAllocHGlobal(IntPtrcb)
254-
{
255-
// For backwards compatibility on 32 bit platforms, ensure we pass values between
256-
// int.MaxValue and uint.MaxValue to Windows. If the binary has had the
257-
// LARGEADDRESSAWARE bit set in the PE header, it may get 3 or 4 GB of user mode
258-
// address space. It is remotely that those allocations could have succeeded,
259-
// though I couldn't reproduce that. In either case, that means we should continue
260-
// throwing an OOM instead of an ArgumentOutOfRangeException for "negative" amounts of memory.
261-
UIntPtrnumBytes;
262-
#ifTARGET_64BIT
263-
numBytes=newUIntPtr(unchecked((ulong)cb.ToInt64()));
264-
#else// 32
265-
numBytes=newUIntPtr(unchecked((uint)cb.ToInt32()));
266-
#endif
267-
268-
IntPtrpNewMem=Interop.Kernel32.LocalAlloc(Interop.Kernel32.LMEM_FIXED,unchecked(numBytes));
269-
if(pNewMem==IntPtr.Zero)
270-
{
271-
thrownewOutOfMemoryException();
272-
}
273-
274-
returnpNewMem;
275-
}
276-
277-
publicstaticvoidFreeHGlobal(IntPtrhglobal)
278-
{
279-
if(!IsNullOrWin32Atom(hglobal))
280-
{
281-
if(IntPtr.Zero!=Interop.Kernel32.LocalFree(hglobal))
282-
{
283-
ThrowExceptionForHR(GetHRForLastWin32Error());
284-
}
285-
}
286-
}
287-
288-
publicstaticIntPtrReAllocHGlobal(IntPtrpv,IntPtrcb)
289-
{
290-
IntPtrpNewMem=Interop.Kernel32.LocalReAlloc(pv,cb,Interop.Kernel32.LMEM_MOVEABLE);
291-
if(pNewMem==IntPtr.Zero)
292-
{
293-
thrownewOutOfMemoryException();
294-
}
295-
296-
returnpNewMem;
297-
}
298-
299253
#ifFEATURE_COMINTEROP
300254
/// <summary>
301255
/// Converts the CLR exception to an HRESULT. This function also sets
@@ -481,83 +435,6 @@ public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : not
481435
[MethodImpl(MethodImplOptions.InternalCall)]
482436
publicstaticexternboolIsComObject(objecto);
483437

484-
#endif// FEATURE_COMINTEROP
485-
486-
publicstaticIntPtrAllocCoTaskMem(intcb)
487-
{
488-
IntPtrpNewMem=Interop.Ole32.CoTaskMemAlloc(newUIntPtr((uint)cb));
489-
if(pNewMem==IntPtr.Zero)
490-
{
491-
thrownewOutOfMemoryException();
492-
}
493-
494-
returnpNewMem;
495-
}
496-
497-
publicstaticvoidFreeCoTaskMem(IntPtrptr)
498-
{
499-
if(!IsNullOrWin32Atom(ptr))
500-
{
501-
Interop.Ole32.CoTaskMemFree(ptr);
502-
}
503-
}
504-
505-
publicstaticIntPtrReAllocCoTaskMem(IntPtrpv,intcb)
506-
{
507-
IntPtrpNewMem=Interop.Ole32.CoTaskMemRealloc(pv,newUIntPtr((uint)cb));
508-
if(pNewMem==IntPtr.Zero&&cb!=0)
509-
{
510-
thrownewOutOfMemoryException();
511-
}
512-
513-
returnpNewMem;
514-
}
515-
516-
internalstaticIntPtrAllocBSTR(intlength)
517-
{
518-
IntPtrbstr=Interop.OleAut32.SysAllocStringLen(null,length);
519-
if(bstr==IntPtr.Zero)
520-
{
521-
thrownewOutOfMemoryException();
522-
}
523-
returnbstr;
524-
}
525-
526-
publicstaticvoidFreeBSTR(IntPtrptr)
527-
{
528-
if(!IsNullOrWin32Atom(ptr))
529-
{
530-
Interop.OleAut32.SysFreeString(ptr);
531-
}
532-
}
533-
534-
publicstaticIntPtrStringToBSTR(string?s)
535-
{
536-
if(sisnull)
537-
{
538-
returnIntPtr.Zero;
539-
}
540-
541-
IntPtrbstr=Interop.OleAut32.SysAllocStringLen(s,s.Length);
542-
if(bstr==IntPtr.Zero)
543-
{
544-
thrownewOutOfMemoryException();
545-
}
546-
547-
returnbstr;
548-
}
549-
550-
publicstaticstringPtrToStringBSTR(IntPtrptr)
551-
{
552-
if(ptr==IntPtr.Zero)
553-
{
554-
thrownewArgumentNullException(nameof(ptr));
555-
}
556-
557-
returnPtrToStringUni(ptr,(int)(SysStringByteLen(ptr)/sizeof(char)));
558-
}
559-
560-
#ifFEATURE_COMINTEROP
561438
/// <summary>
562439
/// Release the COM component and if the reference hits 0 zombie this object.
563440
/// Further usage of this Object might throw an exception

‎src/coreclr/src/System.Private.CoreLib/src/System/StubHelpers.cs‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ internal static unsafe IntPtr ConvertToNative(int flags, string strManaged, IntP
127127

128128
internalstaticvoidClearNative(IntPtrpNative)
129129
{
130-
Interop.Ole32.CoTaskMemFree(pNative);
130+
Marshal.FreeCoTaskMem(pNative);
131131
}
132132

133133
internalstaticunsafevoidConvertFixedToNative(intflags,stringstrManaged,IntPtrpNativeBuffer,intlength)
@@ -257,10 +257,7 @@ internal static unsafe IntPtr ConvertToNative(int flags, string strManaged, IntP
257257

258258
internalstaticvoidClearNative(IntPtrpNative)
259259
{
260-
if(pNative!=IntPtr.Zero)
261-
{
262-
Interop.Ole32.CoTaskMemFree(pNative);
263-
}
260+
Marshal.FreeCoTaskMem(pNative);
264261
}
265262
}
266263

@@ -412,10 +409,7 @@ internal static unsafe IntPtr ConvertToNative(string strManaged, IntPtr pNativeB
412409

413410
internalstaticvoidClearNative(IntPtrpNative)
414411
{
415-
if(IntPtr.Zero!=pNative)
416-
{
417-
Interop.OleAut32.SysFreeString(pNative);
418-
}
412+
Marshal.FreeBSTR(pNative);
419413
}
420414
}// class BSTRMarshaler
421415

@@ -476,7 +470,7 @@ internal static void ClearNative(IntPtr pNative)
476470
{
477471
if(IntPtr.Zero!=pNative)
478472
{
479-
Interop.Ole32.CoTaskMemFree((IntPtr)(((long)pNative)-sizeof(uint)));
473+
Marshal.FreeCoTaskMem((IntPtr)(((long)pNative)-sizeof(uint)));
480474
}
481475
}
482476
}// class VBByValStrMarshaler
@@ -518,10 +512,7 @@ internal static IntPtr ConvertToNative(int flags, string strManaged)
518512

519513
internalstaticvoidClearNative(IntPtrpNative)
520514
{
521-
if(IntPtr.Zero!=pNative)
522-
{
523-
Interop.OleAut32.SysFreeString(pNative);
524-
}
515+
Marshal.FreeBSTR(pNative);
525516
}
526517
}// class AnsiBSTRMarshaler
527518

@@ -1067,7 +1058,7 @@ internal void ClearNative(IntPtr pNativeHome)
10671058
// this must happen regardless of BackPropAction
10681059
Marshal.DestroyStructure(pNativeHome,layoutType);
10691060
}
1070-
Interop.Ole32.CoTaskMemFree(pNativeHome);
1061+
Marshal.FreeCoTaskMem(pNativeHome);
10711062
}
10721063
StubHelpers.DestroyCleanupList(refcleanupWorkList);
10731064
}

‎src/coreclr/src/dlls/mscordac/mscordac_unixexports.src‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ nativeStringResourceTable_mscorrc
138138
#LoadLibraryW
139139
#LoadLibraryExW
140140
#LocalAlloc
141-
#LocalReAlloc
142141
#LocalFree
143142
#MapViewOfFile
144143
#MoveFileExW

‎src/coreclr/src/pal/inc/pal.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,14 +2776,6 @@ LocalAlloc(
27762776
INUINTuFlags,
27772777
INSIZE_TuBytes);
27782778

2779-
PALIMPORT
2780-
HLOCAL
2781-
PALAPI
2782-
LocalReAlloc(
2783-
INHLOCALhMem,
2784-
INSIZE_TuBytes,
2785-
INUINTuFlags);
2786-
27872779
PALIMPORT
27882780
HLOCAL
27892781
PALAPI

‎src/coreclr/src/pal/inc/rt/palrt.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ typedef union _ULARGE_INTEGER {
303303
/******************* OLE, BSTR, VARIANT *************************/
304304

305305
STDAPI_VIS(DLLEXPORT, LPVOID) CoTaskMemAlloc(SIZE_T cb);
306-
STDAPI_VIS(DLLEXPORT, LPVOID) CoTaskMemRealloc(LPVOID pv, SIZE_T cb);
307306
STDAPI_VIS(DLLEXPORT,void) CoTaskMemFree(LPVOID pv);
308307

309308
typedef SHORT VARIANT_BOOL;

‎src/coreclr/src/pal/src/memory/local.cpp‎

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,6 @@ LocalAlloc(
6969
return (HLOCAL) lpRetVal;
7070
}
7171

72-
/*++
73-
Function:
74-
LocalReAlloc
75-
76-
See MSDN doc.
77-
--*/
78-
HLOCAL
79-
PALAPI
80-
LocalReAlloc(
81-
IN HLOCAL hMem,
82-
IN SIZE_T uBytes,
83-
IN UINT uFlags)
84-
{
85-
LPVOID lpRetVal =NULL;
86-
PERF_ENTRY(LocalReAlloc);
87-
ENTRY("LocalReAlloc (hMem=%p, uBytes=%u, uFlags=%#x)\n", hMem, uBytes, uFlags);
88-
89-
if (uFlags != LMEM_MOVEABLE)
90-
{
91-
// Currently valid iff uFlags is LMEM_MOVEABLE
92-
ASSERT("Invalid parameter uFlags=0x%x\n", uFlags);
93-
SetLastError(ERROR_INVALID_PARAMETER);
94-
goto done;
95-
}
96-
97-
if (uBytes ==0)
98-
{
99-
// PAL's realloc behaves like free for a requested size of zero bytes. Force a nonzero size to get a valid pointer.
100-
uBytes =1;
101-
}
102-
103-
lpRetVal =PAL_realloc(hMem, uBytes);
104-
105-
if (lpRetVal ==NULL)
106-
{
107-
ERROR("Not enough memory\n");
108-
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
109-
goto done;
110-
}
111-
112-
done:
113-
LOGEXIT("LocalReAlloc returning %p.\n", lpRetVal);
114-
PERF_EXIT(LocalReAlloc);
115-
return (HLOCAL)lpRetVal;
116-
}
117-
11872
/*++
11973
Function:
12074
LocalFree

‎src/coreclr/src/palrt/comem.cpp‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@
1212

1313
STDAPI_(LPVOID) CoTaskMemAlloc(SIZE_T cb)
1414
{
15-
returnLocalAlloc(LMEM_FIXED, cb);
16-
}
17-
18-
STDAPI_(LPVOID) CoTaskMemRealloc(LPVOID pv, SIZE_T cb)
19-
{
20-
returnLocalReAlloc(pv, cb, LMEM_MOVEABLE);
15+
returnmalloc(cb);
2116
}
2217

2318
STDAPI_(void) CoTaskMemFree(LPVOID pv)
2419
{
25-
LocalFree(pv);
20+
free(pv);
2621
}

‎src/coreclr/src/vm/ecalllist.h‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,15 +1054,9 @@ FCFuncStart(gPalKernel32Funcs)
10541054
QCFuncElement("CreateSemaphoreEx",CreateSemaphoreExW)
10551055
QCFuncElement("FormatMessage",FormatMessageW)
10561056
QCFuncElement("FreeEnvironmentStrings",FreeEnvironmentStringsW)
1057-
QCFuncElement("GetCurrentProcessId",GetCurrentProcessId)
1058-
QCFuncElement("GetCurrentThreadId",GetCurrentThreadId)
10591057
QCFuncElement("GetEnvironmentStrings",GetEnvironmentStringsW)
10601058
QCFuncElement("GetEnvironmentVariable",GetEnvironmentVariableW)
10611059
QCFuncElement("GetStdHandle",GetStdHandle)
1062-
QCFuncElement("GetSystemInfo",GetSystemInfo)
1063-
QCFuncElement("LocalAlloc",LocalAlloc)
1064-
QCFuncElement("LocalReAlloc",LocalReAlloc)
1065-
QCFuncElement("LocalFree",LocalFree)
10661060
QCFuncElement("OpenEvent",OpenEventW)
10671061
QCFuncElement("OpenMutex",OpenMutexW)
10681062
QCFuncElement("OpenSemaphore",OpenSemaphoreW)
@@ -1074,17 +1068,8 @@ FCFuncStart(gPalKernel32Funcs)
10741068
QCFuncElement("SetEvent",SetEvent)
10751069
QCFuncElement("WriteFile",WriteFile)
10761070
FCFuncEnd()
1077-
1078-
FCFuncStart(gPalOle32Funcs)
1079-
QCFuncElement("CoTaskMemAlloc",CoTaskMemAlloc)
1080-
QCFuncElement("CoTaskMemRealloc",CoTaskMemRealloc)
1081-
QCFuncElement("CoTaskMemFree",CoTaskMemFree)
1082-
FCFuncEnd()
1083-
10841071
FCFuncStart(gPalOleAut32Funcs)
10851072
QCFuncElement("SysAllocStringByteLen",SysAllocStringByteLen)
1086-
QCFuncElement("SysAllocStringLen",SysAllocStringLen)
1087-
QCFuncElement("SysFreeString",SysFreeString)
10881073
FCFuncEnd()
10891074
#endif
10901075

@@ -1199,7 +1184,6 @@ FCClassElement("Object", "System", gObjectFuncs)
11991184
FCClassElement("ObjectMarshaler","System.StubHelpers",gObjectMarshalerFuncs)
12001185
#endif
12011186
#ifdefTARGET_UNIX
1202-
FCClassElement("Ole32","",gPalOle32Funcs)
12031187
FCClassElement("OleAut32","",gPalOleAut32Funcs)
12041188
#endif
12051189
FCClassElement("OverlappedData","System.Threading",gOverlappedFuncs)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp