Microsoft MVP성태의 닷넷 이야기
.NET Framework: 509. ELEMENT_TYPE_MODIFIER의 조합 [링크 복사], [링크+제목 복사],
조회: 21794
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 9개 있습니다.)
.NET Framework: 491. 닷넷 Generic 타입의 메타 데이터 토큰 값 알아내는 방법
; https://www.sysnet.pe.kr/2/0/1848

.NET Framework: 494. 값(struct) 형식의 제네릭(Generic) 타입이 박싱되는 경우의 메타데이터 토큰 값
; https://www.sysnet.pe.kr/2/0/1857

.NET Framework: 495. CorElementType의 요소 값 설명
; https://www.sysnet.pe.kr/2/0/1860

.NET Framework: 509. ELEMENT_TYPE_MODIFIER의 조합
; https://www.sysnet.pe.kr/2/0/2894

.NET Framework: 510. 제네릭(Generic) 인자에 대한 메타데이터 등록 확인
; https://www.sysnet.pe.kr/2/0/2907

.NET Framework: 844. C# - 박싱과 언박싱
; https://www.sysnet.pe.kr/2/0/11943

.NET Framework: 955.  .NET 메서드의 Signature 바이트 코드 분석
; https://www.sysnet.pe.kr/2/0/12379

.NET Framework: 1130. C# - ELEMENT_TYPE_INTERNAL 유형의 사용 예
; https://www.sysnet.pe.kr/2/0/12903

.NET Framework: 1174. C# - ELEMENT_TYPE_FNPTR 유형의 사용 예
; https://www.sysnet.pe.kr/2/0/12998




ELEMENT_TYPE_MODIFIER의 조합

ELEMENT_TYPE_MODIFIER 조합을 알다가도 모르겠군요. ^^;

지난 글에서는 SNINativeMethodWrapper.MarshalConsumerInfo 메서드의 signature가 "SIG: 00 02 01 12 20 20 45 0f 11 30" 값이었고, 그중 0x45가 ELEMENT_TYPE_MODIFIER | ELEMENT_TYPE_PINNED의 조합인 것을 알 수 있었습니다.

그런데, .NET 2.0에 정의된 SNINativeMethodWrapper.MarshalConsumerInfo는 signature가 다릅니다.

.method private hidebysig static void  MarshalConsumerInfo(class SNINativeMethodWrapper/ConsumerInfo consumerInfo,
                                                           valuetype SNI_CONSUMER_INFO* modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) native_consumerInfo) cil managed
// SIG: 00 02 01 12 1C 20 39 0F 11 28

00 IMAGE_CEE_CS_CALLCONV_DEFAULT (static method)
02 # of arg(s)
01 ELEMENT_TYPE_VOID (return)
12 ELEMENT_TYPE_CLASS (1st arg type)
  1C (1byte - type token)
  20 ELEMENT_TYPE_CMOD_OPT
  39 ????
  0F ELEMENT_TYPE_PTR
11 ELEMENT_TYPE_VALUETYPE (2nd arg type)
  28 (1byte - type token) 

0x39라니...? ELEMENT_TYPE_MODIFIER의 값이 0x40이기 때문에 .NET 2.0 시절에는 ELEMENT_TYPE_MODIFIER로 분류되지도 않았다는 의미가 됩니다. 알수는 없지만, 억지로 조합해보면 다음과 같이 0x39를 만들 수 있습니다.

ELEMENT_TYPE_VALUETYPE = 0x11
ELEMENT_TYPE_PTR = 0x0f
                 == 20
ELEMENT_TYPE_U == 0x19

ELEMENT_TYPE_VALUETYPE | ELEMENT_TYPE_PTR | ELEMENT_TYPE_U

그런데, ".NET 4.0 (x64)"에서는 또 다른 조합이 나옵니다.

.method private hidebysig static void  MarshalConsumerInfo(class SNINativeMethodWrapper/ConsumerInfo consumerInfo,
                                                           valuetype Sni_Consumer_Info* modopt([mscorlib]System.Runtime.CompilerServices.IsImplicitlyDereferenced) native_consumerInfo) cil managed
SIG: 00 02 01 12 20 20 49 0F 11 38

0x49입니다. ELEMENT_TYPE_MODIFIER의 조합을 corhdr.h에서 보면,

ELEMENT_TYPE_MODIFIER       = 0x40,
ELEMENT_TYPE_SENTINEL       = 0x01 | ELEMENT_TYPE_MODIFIER, // sentinel for varargs
ELEMENT_TYPE_PINNED         = 0x05 | ELEMENT_TYPE_MODIFIER,
ELEMENT_TYPE_R4_HFA         = 0x06 | ELEMENT_TYPE_MODIFIER, // used only internally for R4 HFA types
ELEMENT_TYPE_R8_HFA         = 0x07 | ELEMENT_TYPE_MODIFIER, // used only internally for R8 HFA types

0x49는 도저히 나올 수 없는 조합입니다. 게다가, 이번에 공개된 .NET 4.6 Preview의 corhdr.h에 보면 ELEMENT_TYPE_R4_HFA, ELEMENT_TYPE_R8_HFA는 아예 삭제된 것을 볼 수 있습니다.

// C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\Include\um\corhdr.h

ELEMENT_TYPE_MODIFIER       = 0x40,
ELEMENT_TYPE_SENTINEL       = 0x01 | ELEMENT_TYPE_MODIFIER, // sentinel for varargs
ELEMENT_TYPE_PINNED         = 0x05 | ELEMENT_TYPE_MODIFIER,

도대체 어떻게 0x49가 나올 수 있을까 싶어 무작위로 검색해 보니, coreclr에 힌트가 나옵니다.

// https://github.com/dotnet/coreclr/blob/master/src/vm/compactlayoutwriter.h

178     enum CorElementTypeMDIL 
179     { 
180         ELEMENT_TYPE_NATIVE_VALUETYPE = 0x08 | ELEMENT_TYPE_MODIFIER 
181     }; 

위의 값을 기반으로 만들어 보면, 0x49를 이렇게 만들어 볼 수 있습니다.

0x49 == ELEMENT_TYPE_MODIFIER | 0x08 | 0x01
     == ELEMENT_TYPE_NATIVE_VALUETYPE | ELEMENT_TYPE_SENTINEL

00 IMAGE_CEE_CS_CALLCONV_DEFAULT (static method)
02 # of arg(s)
01 ELEMENT_TYPE_VOID (return)
12 ELEMENT_TYPE_CLASS (1st arg type)
  20 (1byte - type token)
  20 ELEMENT_TYPE_CMOD_OPT
  49 ELEMENT_TYPE_NATIVE_VALUETYPE | ELEMENT_TYPE_SENTINEL 
  0F ELEMENT_TYPE_PTR
11 ELEMENT_TYPE_VALUETYPE (2nd arg type)
  38 (1byte - type token)

물론, 위의 가정은 어디까지나 제 개인적인 가정입니다. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 10/24/2018]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...
NoWriterDateCnt.TitleFile(s)
13627정성태5/17/20249436오류 유형: 904. 파이썬 - UnicodeEncodeError: 'ascii' codec can't encode character '...' in position ...: ordinal not in range(128)
13626정성태5/15/202410507Phone: 15. C# MAUI - MediaElement Source 경로 지정 방법파일 다운로드1
13625정성태5/14/20249906닷넷: 2262. C# - Exception Filter 조건(when)을 갖는 catch 절의 IL 구조
13624정성태5/12/20249599Phone: 14. C# - MAUI에서 MediaElement 사용파일 다운로드1
13623정성태5/11/20249221닷넷: 2261. C# - 구글 OAuth의 JWT (JSON Web Tokens) 해석파일 다운로드1
13622정성태5/10/202410903닷넷: 2260. C# - Google 로그인 연동 (ASP.NET 예제)파일 다운로드1
13621정성태5/10/202410105오류 유형: 903. IISExpress - Failed to register URL "..." for site "..." application "/". Error description: Cannot create a file when that file already exists. (0x800700b7)
13620정성태5/9/20249525VS.NET IDE: 190. Visual Studio가 node.exe를 경유해 Edge.exe를 띄우는 경우
13619정성태5/7/202410119닷넷: 2259. C# - decimal 저장소의 비트 구조 [1]파일 다운로드1
13618정성태5/6/20249381닷넷: 2258. C# - double (배정도 실수) 저장소의 비트 구조파일 다운로드1
13617정성태5/5/202411025닷넷: 2257. C# - float (단정도 실수) 저장소의 비트 구조파일 다운로드1
13616정성태5/3/20249350닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법파일 다운로드1
13615정성태5/3/202411050닷넷: 2255. C# 배열을 Numpy ndarray 배열과 상호 변환
13614정성태5/2/202410816닷넷: 2254. C# - COM 인터페이스의 상속 시 중복으로 메서드를 선언
13613정성태5/1/20249628닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회파일 다운로드1
13612정성태4/30/202410568오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file
13611정성태4/29/20249570닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기파일 다운로드1
13610정성태4/28/202410493닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기
13609정성태4/27/202410500닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성파일 다운로드1
13608정성태4/26/202410916닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/202410928닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/202410869닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/202412338닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/20249424오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/202411180닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/202410139닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...