SlideShare a Scribd company logo
1 of 36
Download to read offline
Beachhead implements
new opcode on CLR JIT
.NET FRINGE JAPAN 2016 KOUJI MATSUI (@KEKYO2)
2
Kouji Matsui - kekyo
• NAGOYA city, AICHI pref., JP
• Twitter – @kekyo2 / Facebook
• ux-spiral corporation
• Microsoft Most Valuable Professional VS
and DevTech 2015-
• Certified Scrum master / Scrum product
owner
• Center CLR organizer.
• .NET/C#/F#/IL/metaprogramming or
like…
• Bike rider
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
3
You can beginning hack:
“CoreCLR”
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI
MATSUI
4
Agenda
• Introduction / Background
• How to build coreclr/corefx
• Add custom IL opcode
• Deep-dive CLR JIT
• Verify custom IL opcode to work
• Conclusion
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
5
Introduction / Background
• .NET Core is open-sourced!!
• Become clearing the .NET internal implementations.
• .NET Framework noeq .NET Core, but very interesting internal
implements anythings…
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
6
Introduction / Background
• I am joining .NET Fringe Japan organizer teams. And thinking
what about speaks first conference…
• Roslyn and corefx already exploring and explaining any people
(in Japan) … Hmm.
• If can add custom IL opcode and build custom CLR ?
Fun, interesting and understanding internal CoreCLR ! :)
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
7
How to build coreclr/corefx
• Development and test bench requirements:
• Windows 10 x64
• Visual Studio 2015 Update 3 (Using C++ compiler)
• CMake 3.6.2 (Multiplatform building tool) https://cmake.org/
• Python 3.5.2 https://www.python.org/
• Official docs: “Building and running tests on Windows”
https://github.com/dotnet/coreclr/blob/master/Documentat
ion/building/windows-test-instructions.md
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
8
How to build coreclr/corefx
• Test summary:
1. Get source codes from GitHub dotnet/coreclr, corefx.
• git clone https://github.com/dotnet/coreclr
• git clone https://github.com/dotnet/corefx
2. Build coreclr and corefx.
• Run build.cmd both coreclr and corefx.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
9
How to build coreclr/corefx
3. Test running minimum sample code using coreclr/corefx.
• Copy System.Runtime.dll and some assemblies from corefx into
coreclr.
• Compile the C# Hello world code using VS2015 C# compiler (csc.exe),
with /nostdlib /r:System.Runtime.dll and another strict options.
• Run the code, “CoreRun.exe Program.exe”
Need more informations?
see documents previous links.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
10
How to build coreclr/corefx
•TIPS!!!
• Must use stable version commits for coreclr
and corefx!
• They are developing continuously and
worldwide, 10 or more commits/day.
• Hint: Look for CI status on GitHub
coreclr/corefx page.
https://github.com/dotnet/coreclr
https://github.com/dotnet/corefx
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
11
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
12
• This is just beginning :)
• Suggest first step: Very simple spec opcode:
• Opcode name: “customcode”
• No operand, no IL stack consume/produce.
• Use opcode: affect output demonstration string to Windows Debug log.
(Use Win32 API “OutputDebugStringW”)
Add custom IL opcode
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
13
• Debug log can capture use Sysinternals DebugView utility.
https://technet.microsoft.com/en-
us/sysinternals/debugview.aspx
Add custom IL opcode
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
14
Add custom IL opcode
• Thinking what currently declared opcode for completely
nothing input/output and no side-effect in CLR ?
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
15
Add custom IL opcode
• ex: Opcode “break” – Break execution the attached debugger current
position.
https://msdn.microsoft.com/en-
us/library/system.reflection.emit.opcodes.break(v=vs.110).aspx
• “Debugger break” means raise interruption native CPU (x64), such as
“DebugBreak” API or “__debugbreak” intrinsic.
• So, maybe contains invoke these API in coreclr source codes. I can find
related code easier, try using base for this opcode…
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
16
Add custom IL opcode
• Grep special-like or unique naming opcode in coreclr:
ex: “initobj”, “ldftn” etc…
--> Opcodes declared in src/inc/opcode.def by OPDEF() macro.
• Opcode break: “CEE_BREAK”
OPDEF(CEE_BREAK, "break", Pop0, Push0, InlineNone, IPrimitive, 1,
0xFF, 0x01, BREAK)
• Add “CEE_CUSTOMCODE” for last opcode “CEE_UNUSED70”’s next:
OPDEF(CEE_CUSTOMCODE, “customcode", Pop0, Push0, InlineNone,
IPrimitive, 2, 0xFE, 0x23, NEXT)
New 2 words opcode: fe,23
Instruction move hint:
“NEXT” is execute next opcode.
(Standard behavior)
No stack consume/produce
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
17
Deep-dive CLR JIT
•Oh, I’m just declared new opcode “customcode” now!! :)
•But this opcode used no coreclr runtime…
Require giving new opcode behavior
MANUALLY
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
18
Compiler-Importer JIT_CustomCode()JIT
Deep-dive CLR JIT
•How interpret opcodes in coreclr:
Assembly file:
MSIL section Parse Call OutputDebugStringW()
Parse IL opcodes
GTNODE
Call
Peek from JIT helper
function pointer table.
Internal IL stream
tree structures
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
19
Deep-dive CLR JIT
• Compiler-Importer (src/jit/importer.cpp) is IL opcode stream
parser use declaring CEE_* macros.
• CEE_BREAK case example:
case CEE_BREAK:
op1 = gtNewHelperCallNode(CORINFO_HELP_USER_BREAKPOINT, TYP_VOID);
goto SPILL_APPEND;
• “gtNewHelperCallNode” is construction GTNODE internal tree
structure node for invoke JIT helper function.
• “CORINFO_HELP_USER_BREAKPOINT” is JIT helper function index
symbol.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
20
Deep-dive CLR JIT
• “CORINFO_HELP_USER_BREAKPOINT” declared in
src/inc/corinfo.h:
• Symbol declared in “enum CorInfoHelpFunc”. Because JIT helper
functions management by function pointer table. This table size
calculated from enum symbols count.
• And src/inc/jithelper.h:
JITHELPER(CORINFO_HELP_USER_BREAKPOINT, JIT_UserBreakpoint,
CORINFO_HELP_SIG_REG_ONLY)
REAL helper function name
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
21
Deep-dive CLR JIT
• Add “CORINFO_HELP_CUSTOMCODE” into CorInfoHelpFunc
and provide JIT helper function information by JITHELPER()
macro.
JITHELPER(CORINFO_HELP_CUSTOMCODE, JIT_CustomCode,
CORINFO_HELP_SIG_REG_ONLY)
• Back to Importer and add “CEE_CUSTOMCODE” handler:
case CEE_CUSTOMCODE:
op1 = gtNewHelperCallNode(CORINFO_HELP_CUSTOMCODE, TYP_VOID);
goto SPILL_APPEND;
• “TYP_VOID” is hold opcode value type (ex: operand type).
“customcode” opcode hold no value, so this ID is TYP_VOID.
• Importer done!
New JIT helper
function name
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
22
Deep-dive CLR JIT
• Implement JIT helper function “JIT_CustomCode”:
HCIMPL0(void, JIT_CustomCode)
{
FCALL_CONTRACT;
HELPER_METHOD_FRAME_BEGIN_NOPOLL();
::OutputDebugStringW(L"Triggered custom code!!!!!!! (for JIT)");
HELPER_METHOD_FRAME_END_POLL();
}
HCIMPLEND
• HCIMPL0(), FCALL_CONTRACT,
HELPER_METHOD_FRAME_BEGIN_NOPOLL(),
HELPER_METHOD_FRAME_END_POLL() macros are required for construct
hard-coded low level prologue/epilogue codes JIT helper functions.
• JIT helper function done!!
THIS IS CORE CODE!!
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
23
Deep-dive CLR JIT
• Anything done ?
• More two non-important points:
1. Implement interpreter-based code. Interpreter is
src/vm/interpreter.cpp.
• But Windows-x64 environments nothing to use interpreter, all
situation works only use JIT.
2. ILFormatter (src/utilcode/ilformatter.cpp).
• Format printer-friendly string from IL opcode. But default
implementation is printing uses CEE_* macro information, this
session’s custom code is not required.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
24
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
25
Verify custom IL opcode to work
• OK, ready to run… How?
• The “customcode” IL opcode can work with CLR now, but how to generate
“customcode” contained assembly??
Manually paching with BINARY EDITOR…??
(; ゚Д゚)
This is TOP SECRET:
I fogot IMAGE_DOS_HEADER, IMAGE_FILE_HEADER, IMAGE_NT_HEADER,
IMAGE_OPTIONAL_HEADER, IMAGE_DATA_DIRECTORY, IMAGE…
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
26
Verify custom IL opcode to work
• Thinking about more easy construction:
1. Compile standard C# sample code by .NET Core 1.0.
2. Use “ildasm” to disassembled.
3. Insert “customcode” opcode into disassembled IL source code.
4. Use custom-opcode enabled “idasm” to build new assembly.
• The “ilasm” and “ildasm” are built with coreclr. New opcodes
can handling from “opcode.def” automatically.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
27
Verify custom IL opcode to work
• Bootstrap test code in C#:
Generate template code from “dotnet new” command and simplied:
namespace ConsoleApplication
{
public static class Program
{
public static void Main(string[] args)
{
}
}
}
• Compile:
• dotnet restore
• dotnet build
• Storing compiled assembly: bin¥Debug¥netcoreapp1.0¥addil.dll
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
28
Verify custom IL opcode to work
• Disassembling:
• ..¥ildasm.exe bin¥Debug¥netcoreapp1.0¥addil.dll > addil.il
• Fixed attributes for referenced System.Runtime:
.assembly extern System.Runtime
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
.ver 4:2:0:0
}
Fix pubkey token and version similer to your
local built corefx binaries if different.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
29
Verify custom IL opcode to work
• Insert “customcode” opcode into Main method body:
.method public hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 8
IL_0000: nop
customcode
IL_0001: ret
}
Insert “customcode” opcode!!
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
30
Verify custom IL opcode to work
• Assemble by customcode-enabled “ilasm”:
• ..¥ilasm.exe Program.il
Success with nothing error.
If use official ilasm.exe, will cause error:
“syntax error at token ‘ret’”
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
31
Verify custom IL opcode to work
• Run the assembly and verify with DebugView:
• Before execute DbgView.exe
• ..¥CoreRun.exe Program.exe
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
32
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
33
Conclusion
• Custom IL opcode declare and implement:
• Declare opcode into opcode.def with OPDEF() macro.
• Declare JIT helper function into corinfo.h and jithelper.h with
JITHELPER() macro.
• Implement JIT helper function with HCIMPL() macros.
• Implement custom opcode handler into Compile-Importer.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
34
Conclusion
• Verification:
• Generate IL codes from disassembled C# codes with “ildasm.”
(Or, write from scratch IL codes…)
• Using custom-opcode enabled “ilasm” to generate final binary.
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
35
Conclusion
• coreclr is truly OSS: Custom IL opcode can implements with
average difficulity.
• This session explain with constraints “No operand, No stack
consume/produce opcode.”
Maybe more hard work for intermediate usage opcode design…
• But YOU CAN DO THAT!!
• This session’s demonstration code:
• https://github.com/kekyo/coreclr git branch:addil
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
36
Thank you joining my session!!
• Become slides on slideshare and my blog entry.
http://www.kekyo.net/ (Sorry blog only Japanese language)
• My twitter account @kekyo2, follow <3
• GitHub https://github.com/kekyo/ contains:
• FusionTasks, RelaxVersioner, fscx and more…
• Open conference with “Center CLR” in Aichi
pref., Japan! Join us!!
https://www.meetup.com/en-US/CenterCLR/
CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI

More Related Content

What's hot

Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...Pôle Systematic Paris-Region
 
Use MQTT in Docker on Raspberry Pi
Use MQTT in Docker on Raspberry PiUse MQTT in Docker on Raspberry Pi
Use MQTT in Docker on Raspberry PiPhilip Zheng
 
Introduction to Tensorflow.js
Introduction to Tensorflow.jsIntroduction to Tensorflow.js
Introduction to Tensorflow.jsRiza Fahmi
 
Web of Technologies
Web of TechnologiesWeb of Technologies
Web of Technologiesdynamis
 
Getting started with developing Nodejs
Getting started with developing NodejsGetting started with developing Nodejs
Getting started with developing NodejsPhil Hawksworth
 
Pulumi. Modern Infrastructure as Code.
Pulumi. Modern Infrastructure as Code.Pulumi. Modern Infrastructure as Code.
Pulumi. Modern Infrastructure as Code.Yurii Bychenok
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypalLenny Markus
 
Les nouveautés de C# 7
Les nouveautés de C# 7Les nouveautés de C# 7
Les nouveautés de C# 7Microsoft
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
C++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用するC++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用する祐司 伊藤
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 

What's hot (20)

COSCUP - Fleet
COSCUP - FleetCOSCUP - Fleet
COSCUP - Fleet
 
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...
 
Use MQTT in Docker on Raspberry Pi
Use MQTT in Docker on Raspberry PiUse MQTT in Docker on Raspberry Pi
Use MQTT in Docker on Raspberry Pi
 
Future of NodeJS
Future of NodeJSFuture of NodeJS
Future of NodeJS
 
Introduction to Tensorflow.js
Introduction to Tensorflow.jsIntroduction to Tensorflow.js
Introduction to Tensorflow.js
 
Web of Technologies
Web of TechnologiesWeb of Technologies
Web of Technologies
 
Getting started with developing Nodejs
Getting started with developing NodejsGetting started with developing Nodejs
Getting started with developing Nodejs
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
 
Super combinators
Super combinatorsSuper combinators
Super combinators
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Pulumi. Modern Infrastructure as Code.
Pulumi. Modern Infrastructure as Code.Pulumi. Modern Infrastructure as Code.
Pulumi. Modern Infrastructure as Code.
 
Kraken js at paypal
Kraken js at paypalKraken js at paypal
Kraken js at paypal
 
Les nouveautés de C# 7
Les nouveautés de C# 7Les nouveautés de C# 7
Les nouveautés de C# 7
 
Node ppt
Node pptNode ppt
Node ppt
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
(C)NodeJS
(C)NodeJS(C)NodeJS
(C)NodeJS
 
C++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用するC++からWebRTC (DataChannel)を利用する
C++からWebRTC (DataChannel)を利用する
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 

Viewers also liked

メタプログラミングでExcel仕様書よさらば
メタプログラミングでExcel仕様書よさらばメタプログラミングでExcel仕様書よさらば
メタプログラミングでExcel仕様書よさらばKouji Matsui
 
Nespのコード生成
Nespのコード生成Nespのコード生成
Nespのコード生成Kouji Matsui
 
山椒の味は大人の味
山椒の味は大人の味山椒の味は大人の味
山椒の味は大人の味Kouji Matsui
 
真Intermediate languageのキホン
真Intermediate languageのキホン真Intermediate languageのキホン
真Intermediate languageのキホンKouji Matsui
 
抽象太郎ものがたり そして伝説へ
抽象太郎ものがたり そして伝説へ抽象太郎ものがたり そして伝説へ
抽象太郎ものがたり そして伝説へKouji Matsui
 
Hello! intermediate language
Hello! intermediate languageHello! intermediate language
Hello! intermediate languageKouji Matsui
 
式の体を成して無い式を式の体を成すように式と式木で何とかする式
式の体を成して無い式を式の体を成すように式と式木で何とかする式式の体を成して無い式を式の体を成すように式と式木で何とかする式
式の体を成して無い式を式の体を成すように式と式木で何とかする式Kouji Matsui
 

Viewers also liked (7)

メタプログラミングでExcel仕様書よさらば
メタプログラミングでExcel仕様書よさらばメタプログラミングでExcel仕様書よさらば
メタプログラミングでExcel仕様書よさらば
 
Nespのコード生成
Nespのコード生成Nespのコード生成
Nespのコード生成
 
山椒の味は大人の味
山椒の味は大人の味山椒の味は大人の味
山椒の味は大人の味
 
真Intermediate languageのキホン
真Intermediate languageのキホン真Intermediate languageのキホン
真Intermediate languageのキホン
 
抽象太郎ものがたり そして伝説へ
抽象太郎ものがたり そして伝説へ抽象太郎ものがたり そして伝説へ
抽象太郎ものがたり そして伝説へ
 
Hello! intermediate language
Hello! intermediate languageHello! intermediate language
Hello! intermediate language
 
式の体を成して無い式を式の体を成すように式と式木で何とかする式
式の体を成して無い式を式の体を成すように式と式木で何とかする式式の体を成して無い式を式の体を成すように式と式木で何とかする式
式の体を成して無い式を式の体を成すように式と式木で何とかする式
 

Similar to Beachhead implements new opcode on CLR JIT

Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWERContinuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWERIndrajit Poddar
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019corehard_by
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Paris Android User Group
 
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bugWang Hao Lee
 
Kotlin The Whole Damn Family
Kotlin The Whole Damn FamilyKotlin The Whole Damn Family
Kotlin The Whole Damn FamilyGarth Gilmour
 
Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013Kevin Munc
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building BlocksMax Kleiner
 
1_International_Google_CoLab_20220307.pptx
1_International_Google_CoLab_20220307.pptx1_International_Google_CoLab_20220307.pptx
1_International_Google_CoLab_20220307.pptxFEG
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programmingmaznabili
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...Jérôme Petazzoni
 
Conan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for DevelopersConan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for DevelopersUilian Ries
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An IntroductionPOSSCON
 
Creating a Plug-In Architecture
Creating a Plug-In ArchitectureCreating a Plug-In Architecture
Creating a Plug-In Architectureondrejbalas
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014biicode
 
New Features Webinar-April
New Features Webinar-AprilNew Features Webinar-April
New Features Webinar-AprilCodefresh
 

Similar to Beachhead implements new opcode on CLR JIT (20)

STM -32
STM -32STM -32
STM -32
 
learning STM -32
learning STM -32 learning STM -32
learning STM -32
 
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWERContinuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
Continuous Integration with Cloud Foundry Concourse and Docker on OpenPOWER
 
MattsonTutorialSC14.pdf
MattsonTutorialSC14.pdfMattsonTutorialSC14.pdf
MattsonTutorialSC14.pdf
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
英文【Xu hao chen xiaobo】find your_own_ios_kernel_bug
 
Kotlin The Whole Damn Family
Kotlin The Whole Damn FamilyKotlin The Whole Damn Family
Kotlin The Whole Damn Family
 
Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building Blocks
 
1_International_Google_CoLab_20220307.pptx
1_International_Google_CoLab_20220307.pptx1_International_Google_CoLab_20220307.pptx
1_International_Google_CoLab_20220307.pptx
 
Monkey space 2013
Monkey space 2013Monkey space 2013
Monkey space 2013
 
01 Introduction to programming
01 Introduction to programming01 Introduction to programming
01 Introduction to programming
 
Introduction to Programming Lesson 01
Introduction to Programming Lesson 01Introduction to Programming Lesson 01
Introduction to Programming Lesson 01
 
From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...From development environments to production deployments with Docker, Compose,...
From development environments to production deployments with Docker, Compose,...
 
Conan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for DevelopersConan.io - The C/C++ package manager for Developers
Conan.io - The C/C++ package manager for Developers
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An Introduction
 
Creating a Plug-In Architecture
Creating a Plug-In ArchitectureCreating a Plug-In Architecture
Creating a Plug-In Architecture
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
New Features Webinar-April
New Features Webinar-AprilNew Features Webinar-April
New Features Webinar-April
 

More from Kouji Matsui

パターンでわかる! .NET Coreの非同期処理
パターンでわかる! .NET Coreの非同期処理パターンでわかる! .NET Coreの非同期処理
パターンでわかる! .NET Coreの非同期処理Kouji Matsui
 
Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018Kouji Matsui
 
Matrix signal controller and BrainPad overview
Matrix signal controller and BrainPad overviewMatrix signal controller and BrainPad overview
Matrix signal controller and BrainPad overviewKouji Matsui
 
What's Functional?
What's Functional?What's Functional?
What's Functional?Kouji Matsui
 
Pitfall for WioLTE
Pitfall for WioLTEPitfall for WioLTE
Pitfall for WioLTEKouji Matsui
 
How to make the calculator
How to make the calculatorHow to make the calculator
How to make the calculatorKouji Matsui
 
Write common, run anywhere
Write common, run anywhereWrite common, run anywhere
Write common, run anywhereKouji Matsui
 
Locality of Reference
Locality of ReferenceLocality of Reference
Locality of ReferenceKouji Matsui
 
C#でわかる こわくないMonad
C#でわかる こわくないMonadC#でわかる こわくないMonad
C#でわかる こわくないMonadKouji Matsui
 
You will be assimilated. Resistance is futile.
You will be assimilated. Resistance is futile.You will be assimilated. Resistance is futile.
You will be assimilated. Resistance is futile.Kouji Matsui
 
How to meets Async and Task
How to meets Async and TaskHow to meets Async and Task
How to meets Async and TaskKouji Matsui
 
Async deepdive before de:code
Async deepdive before de:codeAsync deepdive before de:code
Async deepdive before de:codeKouji Matsui
 
Thread affinity and CPS
Thread affinity and CPSThread affinity and CPS
Thread affinity and CPSKouji Matsui
 
Async DeepDive basics
Async DeepDive basicsAsync DeepDive basics
Async DeepDive basicsKouji Matsui
 
continuatioN Linking
continuatioN LinkingcontinuatioN Linking
continuatioN LinkingKouji Matsui
 
.NET Coreから概観する.NETのOSSへの取り組み
.NET Coreから概観する.NETのOSSへの取り組み.NET Coreから概観する.NETのOSSへの取り組み
.NET Coreから概観する.NETのOSSへの取り組みKouji Matsui
 
Win32 APIをてなずけよう
Win32 APIをてなずけようWin32 APIをてなずけよう
Win32 APIをてなずけようKouji Matsui
 
不健康なIt戦士を健康的にするアレの話
不健康なIt戦士を健康的にするアレの話不健康なIt戦士を健康的にするアレの話
不健康なIt戦士を健康的にするアレの話Kouji Matsui
 
Final LINQ extensions III
Final LINQ extensions IIIFinal LINQ extensions III
Final LINQ extensions IIIKouji Matsui
 

More from Kouji Matsui (20)

パターンでわかる! .NET Coreの非同期処理
パターンでわかる! .NET Coreの非同期処理パターンでわかる! .NET Coreの非同期処理
パターンでわかる! .NET Coreの非同期処理
 
Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018Making archive IL2C #6-55 dotnet600 2018
Making archive IL2C #6-55 dotnet600 2018
 
Matrix signal controller and BrainPad overview
Matrix signal controller and BrainPad overviewMatrix signal controller and BrainPad overview
Matrix signal controller and BrainPad overview
 
Fun with BrainPad
Fun with BrainPadFun with BrainPad
Fun with BrainPad
 
What's Functional?
What's Functional?What's Functional?
What's Functional?
 
Pitfall for WioLTE
Pitfall for WioLTEPitfall for WioLTE
Pitfall for WioLTE
 
How to make the calculator
How to make the calculatorHow to make the calculator
How to make the calculator
 
Write common, run anywhere
Write common, run anywhereWrite common, run anywhere
Write common, run anywhere
 
Locality of Reference
Locality of ReferenceLocality of Reference
Locality of Reference
 
C#でわかる こわくないMonad
C#でわかる こわくないMonadC#でわかる こわくないMonad
C#でわかる こわくないMonad
 
You will be assimilated. Resistance is futile.
You will be assimilated. Resistance is futile.You will be assimilated. Resistance is futile.
You will be assimilated. Resistance is futile.
 
How to meets Async and Task
How to meets Async and TaskHow to meets Async and Task
How to meets Async and Task
 
Async deepdive before de:code
Async deepdive before de:codeAsync deepdive before de:code
Async deepdive before de:code
 
Thread affinity and CPS
Thread affinity and CPSThread affinity and CPS
Thread affinity and CPS
 
Async DeepDive basics
Async DeepDive basicsAsync DeepDive basics
Async DeepDive basics
 
continuatioN Linking
continuatioN LinkingcontinuatioN Linking
continuatioN Linking
 
.NET Coreから概観する.NETのOSSへの取り組み
.NET Coreから概観する.NETのOSSへの取り組み.NET Coreから概観する.NETのOSSへの取り組み
.NET Coreから概観する.NETのOSSへの取り組み
 
Win32 APIをてなずけよう
Win32 APIをてなずけようWin32 APIをてなずけよう
Win32 APIをてなずけよう
 
不健康なIt戦士を健康的にするアレの話
不健康なIt戦士を健康的にするアレの話不健康なIt戦士を健康的にするアレの話
不健康なIt戦士を健康的にするアレの話
 
Final LINQ extensions III
Final LINQ extensions IIIFinal LINQ extensions III
Final LINQ extensions III
 

Recently uploaded

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Beachhead implements new opcode on CLR JIT

  • 1. Beachhead implements new opcode on CLR JIT .NET FRINGE JAPAN 2016 KOUJI MATSUI (@KEKYO2)
  • 2. 2 Kouji Matsui - kekyo • NAGOYA city, AICHI pref., JP • Twitter – @kekyo2 / Facebook • ux-spiral corporation • Microsoft Most Valuable Professional VS and DevTech 2015- • Certified Scrum master / Scrum product owner • Center CLR organizer. • .NET/C#/F#/IL/metaprogramming or like… • Bike rider CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 3. 3 You can beginning hack: “CoreCLR” CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 4. 4 Agenda • Introduction / Background • How to build coreclr/corefx • Add custom IL opcode • Deep-dive CLR JIT • Verify custom IL opcode to work • Conclusion CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 5. 5 Introduction / Background • .NET Core is open-sourced!! • Become clearing the .NET internal implementations. • .NET Framework noeq .NET Core, but very interesting internal implements anythings… CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 6. 6 Introduction / Background • I am joining .NET Fringe Japan organizer teams. And thinking what about speaks first conference… • Roslyn and corefx already exploring and explaining any people (in Japan) … Hmm. • If can add custom IL opcode and build custom CLR ? Fun, interesting and understanding internal CoreCLR ! :) CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 7. 7 How to build coreclr/corefx • Development and test bench requirements: • Windows 10 x64 • Visual Studio 2015 Update 3 (Using C++ compiler) • CMake 3.6.2 (Multiplatform building tool) https://cmake.org/ • Python 3.5.2 https://www.python.org/ • Official docs: “Building and running tests on Windows” https://github.com/dotnet/coreclr/blob/master/Documentat ion/building/windows-test-instructions.md CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 8. 8 How to build coreclr/corefx • Test summary: 1. Get source codes from GitHub dotnet/coreclr, corefx. • git clone https://github.com/dotnet/coreclr • git clone https://github.com/dotnet/corefx 2. Build coreclr and corefx. • Run build.cmd both coreclr and corefx. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 9. 9 How to build coreclr/corefx 3. Test running minimum sample code using coreclr/corefx. • Copy System.Runtime.dll and some assemblies from corefx into coreclr. • Compile the C# Hello world code using VS2015 C# compiler (csc.exe), with /nostdlib /r:System.Runtime.dll and another strict options. • Run the code, “CoreRun.exe Program.exe” Need more informations? see documents previous links. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 10. 10 How to build coreclr/corefx •TIPS!!! • Must use stable version commits for coreclr and corefx! • They are developing continuously and worldwide, 10 or more commits/day. • Hint: Look for CI status on GitHub coreclr/corefx page. https://github.com/dotnet/coreclr https://github.com/dotnet/corefx CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 11. 11 CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 12. 12 • This is just beginning :) • Suggest first step: Very simple spec opcode: • Opcode name: “customcode” • No operand, no IL stack consume/produce. • Use opcode: affect output demonstration string to Windows Debug log. (Use Win32 API “OutputDebugStringW”) Add custom IL opcode CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 13. 13 • Debug log can capture use Sysinternals DebugView utility. https://technet.microsoft.com/en- us/sysinternals/debugview.aspx Add custom IL opcode CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 14. 14 Add custom IL opcode • Thinking what currently declared opcode for completely nothing input/output and no side-effect in CLR ? CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 15. 15 Add custom IL opcode • ex: Opcode “break” – Break execution the attached debugger current position. https://msdn.microsoft.com/en- us/library/system.reflection.emit.opcodes.break(v=vs.110).aspx • “Debugger break” means raise interruption native CPU (x64), such as “DebugBreak” API or “__debugbreak” intrinsic. • So, maybe contains invoke these API in coreclr source codes. I can find related code easier, try using base for this opcode… CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 16. 16 Add custom IL opcode • Grep special-like or unique naming opcode in coreclr: ex: “initobj”, “ldftn” etc… --> Opcodes declared in src/inc/opcode.def by OPDEF() macro. • Opcode break: “CEE_BREAK” OPDEF(CEE_BREAK, "break", Pop0, Push0, InlineNone, IPrimitive, 1, 0xFF, 0x01, BREAK) • Add “CEE_CUSTOMCODE” for last opcode “CEE_UNUSED70”’s next: OPDEF(CEE_CUSTOMCODE, “customcode", Pop0, Push0, InlineNone, IPrimitive, 2, 0xFE, 0x23, NEXT) New 2 words opcode: fe,23 Instruction move hint: “NEXT” is execute next opcode. (Standard behavior) No stack consume/produce CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 17. 17 Deep-dive CLR JIT •Oh, I’m just declared new opcode “customcode” now!! :) •But this opcode used no coreclr runtime… Require giving new opcode behavior MANUALLY CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 18. 18 Compiler-Importer JIT_CustomCode()JIT Deep-dive CLR JIT •How interpret opcodes in coreclr: Assembly file: MSIL section Parse Call OutputDebugStringW() Parse IL opcodes GTNODE Call Peek from JIT helper function pointer table. Internal IL stream tree structures CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 19. 19 Deep-dive CLR JIT • Compiler-Importer (src/jit/importer.cpp) is IL opcode stream parser use declaring CEE_* macros. • CEE_BREAK case example: case CEE_BREAK: op1 = gtNewHelperCallNode(CORINFO_HELP_USER_BREAKPOINT, TYP_VOID); goto SPILL_APPEND; • “gtNewHelperCallNode” is construction GTNODE internal tree structure node for invoke JIT helper function. • “CORINFO_HELP_USER_BREAKPOINT” is JIT helper function index symbol. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 20. 20 Deep-dive CLR JIT • “CORINFO_HELP_USER_BREAKPOINT” declared in src/inc/corinfo.h: • Symbol declared in “enum CorInfoHelpFunc”. Because JIT helper functions management by function pointer table. This table size calculated from enum symbols count. • And src/inc/jithelper.h: JITHELPER(CORINFO_HELP_USER_BREAKPOINT, JIT_UserBreakpoint, CORINFO_HELP_SIG_REG_ONLY) REAL helper function name CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 21. 21 Deep-dive CLR JIT • Add “CORINFO_HELP_CUSTOMCODE” into CorInfoHelpFunc and provide JIT helper function information by JITHELPER() macro. JITHELPER(CORINFO_HELP_CUSTOMCODE, JIT_CustomCode, CORINFO_HELP_SIG_REG_ONLY) • Back to Importer and add “CEE_CUSTOMCODE” handler: case CEE_CUSTOMCODE: op1 = gtNewHelperCallNode(CORINFO_HELP_CUSTOMCODE, TYP_VOID); goto SPILL_APPEND; • “TYP_VOID” is hold opcode value type (ex: operand type). “customcode” opcode hold no value, so this ID is TYP_VOID. • Importer done! New JIT helper function name CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 22. 22 Deep-dive CLR JIT • Implement JIT helper function “JIT_CustomCode”: HCIMPL0(void, JIT_CustomCode) { FCALL_CONTRACT; HELPER_METHOD_FRAME_BEGIN_NOPOLL(); ::OutputDebugStringW(L"Triggered custom code!!!!!!! (for JIT)"); HELPER_METHOD_FRAME_END_POLL(); } HCIMPLEND • HCIMPL0(), FCALL_CONTRACT, HELPER_METHOD_FRAME_BEGIN_NOPOLL(), HELPER_METHOD_FRAME_END_POLL() macros are required for construct hard-coded low level prologue/epilogue codes JIT helper functions. • JIT helper function done!! THIS IS CORE CODE!! CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 23. 23 Deep-dive CLR JIT • Anything done ? • More two non-important points: 1. Implement interpreter-based code. Interpreter is src/vm/interpreter.cpp. • But Windows-x64 environments nothing to use interpreter, all situation works only use JIT. 2. ILFormatter (src/utilcode/ilformatter.cpp). • Format printer-friendly string from IL opcode. But default implementation is printing uses CEE_* macro information, this session’s custom code is not required. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 24. 24 CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 25. 25 Verify custom IL opcode to work • OK, ready to run… How? • The “customcode” IL opcode can work with CLR now, but how to generate “customcode” contained assembly?? Manually paching with BINARY EDITOR…?? (; ゚Д゚) This is TOP SECRET: I fogot IMAGE_DOS_HEADER, IMAGE_FILE_HEADER, IMAGE_NT_HEADER, IMAGE_OPTIONAL_HEADER, IMAGE_DATA_DIRECTORY, IMAGE… CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 26. 26 Verify custom IL opcode to work • Thinking about more easy construction: 1. Compile standard C# sample code by .NET Core 1.0. 2. Use “ildasm” to disassembled. 3. Insert “customcode” opcode into disassembled IL source code. 4. Use custom-opcode enabled “idasm” to build new assembly. • The “ilasm” and “ildasm” are built with coreclr. New opcodes can handling from “opcode.def” automatically. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 27. 27 Verify custom IL opcode to work • Bootstrap test code in C#: Generate template code from “dotnet new” command and simplied: namespace ConsoleApplication { public static class Program { public static void Main(string[] args) { } } } • Compile: • dotnet restore • dotnet build • Storing compiled assembly: bin¥Debug¥netcoreapp1.0¥addil.dll CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 28. 28 Verify custom IL opcode to work • Disassembling: • ..¥ildasm.exe bin¥Debug¥netcoreapp1.0¥addil.dll > addil.il • Fixed attributes for referenced System.Runtime: .assembly extern System.Runtime { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) .ver 4:2:0:0 } Fix pubkey token and version similer to your local built corefx binaries if different. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 29. 29 Verify custom IL opcode to work • Insert “customcode” opcode into Main method body: .method public hidebysig static void Main(string[] args) cil managed { .entrypoint .maxstack 8 IL_0000: nop customcode IL_0001: ret } Insert “customcode” opcode!! CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 30. 30 Verify custom IL opcode to work • Assemble by customcode-enabled “ilasm”: • ..¥ilasm.exe Program.il Success with nothing error. If use official ilasm.exe, will cause error: “syntax error at token ‘ret’” CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 31. 31 Verify custom IL opcode to work • Run the assembly and verify with DebugView: • Before execute DbgView.exe • ..¥CoreRun.exe Program.exe CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 32. 32 CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 33. 33 Conclusion • Custom IL opcode declare and implement: • Declare opcode into opcode.def with OPDEF() macro. • Declare JIT helper function into corinfo.h and jithelper.h with JITHELPER() macro. • Implement JIT helper function with HCIMPL() macros. • Implement custom opcode handler into Compile-Importer. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 34. 34 Conclusion • Verification: • Generate IL codes from disassembled C# codes with “ildasm.” (Or, write from scratch IL codes…) • Using custom-opcode enabled “ilasm” to generate final binary. CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 35. 35 Conclusion • coreclr is truly OSS: Custom IL opcode can implements with average difficulity. • This session explain with constraints “No operand, No stack consume/produce opcode.” Maybe more hard work for intermediate usage opcode design… • But YOU CAN DO THAT!! • This session’s demonstration code: • https://github.com/kekyo/coreclr git branch:addil CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI
  • 36. 36 Thank you joining my session!! • Become slides on slideshare and my blog entry. http://www.kekyo.net/ (Sorry blog only Japanese language) • My twitter account @kekyo2, follow <3 • GitHub https://github.com/kekyo/ contains: • FusionTasks, RelaxVersioner, fscx and more… • Open conference with “Center CLR” in Aichi pref., Japan! Join us!! https://www.meetup.com/en-US/CenterCLR/ CC-BY-SA 4.0 COPYRIGHT (C) 2016 KOUJI MATSUI