SlideShare a Scribd company logo
1 of 65
Download to read offline


!2
!3
!4
!5
!6
!7
!8
!9
!10
!11
!12
#include <stdio.h>
int main()
{
printf("hello world!n");
return 0;
}
!13
$ ls
helloworld helloworld.c
$ file helloworld.c
# helloworld.c: C source, ASCII text
$ file helloworld
# helloworld: ELF 64-bit LSB pie executable,
x86-64, version 1 (SYSV), dynamically linked,
interpreter /lib64/ld-linux-x86-64.so.2, for
GNU/Linux 3.2.0,
BuildID[sha1]=02ed1e530f48620e34b1abc02079fc1
17ebb2279, not stripped
!14
$ ls -alh
# -rwxr-xr-x 1 root root 17K Nov 4 23:21
helloworld
# -rw-r--r-- 1 root root 62 Nov 4 23:20
helloworld.c
!15
$ cat helloworld
{¥rtf1¥ansi
¥deff1{¥fonttbl{¥f1¥fmodern¥fprq1¥fcharset0
Courier New;}}{¥colortbl;
¥red224¥green234¥blue238;¥red00¥green00¥blue0
0;¥red191¥green03¥blue03;¥red176¥green126¥blu
e00;¥red131¥green129¥blue131;¥red131¥green129
¥blue131;¥red255¥green00¥blue255;¥red00¥green
130¥blue00;¥red12
……
!16
$ gdb helloworld
(gdb) disass main
# Dump of assembler code for function main:
# 0x0000000000001135 <+0>: push rbp
# 0x0000000000001136 <+1>: mov rbp,rsp
# 0x0000000000001139 <+4>: lea rdi,
[rip+0xec4] # 0x2004
# 0x0000000000001140 <+11>: mov eax,0x0
# 0x0000000000001145 <+16>: call 0x1030
<printf@plt>
# 0x000000000000114a <+21>: mov eax,0x0
# 0x000000000000114f <+26>: pop rbp
# 0x0000000000001150 <+27>: ret
# End of assembler dump.
!17
$ gdb helloworld
(gdb) disass main
# Dump of assembler code for function main:
# 0x0000000000001135 <+0>: push rbp
# 0x0000000000001136 <+1>: mov rbp,rsp
# 0x0000000000001139 <+4>: lea rdi,
[rip+0xec4] # 0x2004
# 0x0000000000001140 <+11>: mov eax,0x0
# 0x0000000000001145 <+16>: call 0x1030
<printf@plt>
# 0x000000000000114a <+21>: mov eax,0x0
# 0x000000000000114f <+26>: pop rbp
# 0x0000000000001150 <+27>: ret
# End of assembler dump.
!18
$ file helloworldmac
helloworldmac: Mach-O 64-bit x86_64
executable, flags:<NOUNDEFS|DYLDLINK|
TWOLEVEL|PIE>
!19
$ ./helloworldmac
zsh: exec format error: ./helloworldmac
!20
!21
!22
!23
!24
(gdb) disass main
Dump of assembler code for function main:
0x0000000000001135 <+0>: push rbp
0x0000000000001136 <+1>: mov rbp,rsp
0x0000000000001139 <+4>: lea rdi,
[rip+0xec4] # 0x2004
0x0000000000001140 <+11>:mov eax,0x0
0x0000000000001145 <+16>:call 0x1030
<printf@plt>
0x000000000000114a <+21>:mov eax,0x0
0x000000000000114f <+26>:pop rbp
0x0000000000001150 <+27>:ret
End of assembler dump.
!25
!26
!27
!28
!29
!30


!31
!32
void test_function(int a, int b, int c, int d)
{
int flag;
char buffer[10];
flag = 31337; //
buffer[0] = 'A';
}
int main()
{
test_function(1, 2, 3, 4); //
}
!33
gdb -q ./stack_example
Reading symbols from ./stack_example...done.
(gdb) list
1
2 void test_function(int a, int b, int c, int d)
3 {
4 int flag;
5 char buffer[10];
6
7 flag = 31337;
8 buffer[0] = 'A';
9 }
10
(gdb) list
11 int main()
12 {
13 test_function(1, 2, 3, 4);
14 test_function(5,6,7,8);
15 }
16
(gdb) break 13
Breakpoint 1 at 0x1147: file stack_example.c, line 13.
(gdb) break test_function
Breakpoint 2 at 0x1135: file stack_example.c, line 7.
(gdb) break 14
Breakpoint 3 at 0x1160: file stack_example.c, line 14.
!34
(gdb) run
Starting program: /root/rg/stack_example
Breakpoint 1, main () at stack_example.c:13
13 test_function(1, 2, 3, 4);
(gdb) i r rsp rbp
rsp 0x7fffffffe350 0x7fffffffe350
rbp 0x7fffffffe350 0x7fffffffe350
(gdb) cont
Continuing.
Breakpoint 2, test_function (a=1, b=2, c=3, d=4) at stack_example.c:7
7 flag = 31337;
(gdb) i r rsp rbp
rsp 0x7fffffffe340 0x7fffffffe340
rbp 0x7fffffffe340 0x7fffffffe340
(gdb) cont
Continuing.
Breakpoint 3, main () at stack_example.c:14
14 test_function(5,6,7,8);
(gdb) i r rsp rbp
rsp 0x7fffffffe350 0x7fffffffe350
rbp 0x7fffffffe350 0x7fffffffe350
!35
$ gcc -g -o memory_segments memory_seguments.c
!36
$ ./memory_segments
data segment:
global_init_var 0xaecf0040
static_init_var 0xaecf0044
bss segment
global_var 0xaecf0050
static_var 0xaecf004c
heap segment
heap_var_ptr 0xb098c260
stack segment
stack_var 0x9fefb384
function() stack_var 0x9fefb36c
!37
!38
!39
#include <stdio.h>
int main()
{
printf("hello world!n");
return 0;
}
!40


!41
!42
$ strace ./helloworld

execve("./helloworld", ["./helloworld"], 0x7ffc2b36e160 /*
29 vars */) = 0
brk(NULL) = 0x55f838726000
.
.
.
mprotect(0x7f313a6c9000, 4096, PROT_READ) = 0
munmap(0x7f313a67e000, 145183) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136,
0), ...}) = 0
brk(NULL) = 0x55f838726000
brk(0x55f838747000) = 0x55f838747000
write(1, "hello world!", 12hello world!) = 12
exit_group(0) = ?
+++ exited with 0 +++
!43
!44
!45
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main()
{
int fd1, fd2;
fd1 = open("helloworld.c", O_RDONLY);
close(fd1);
fd2 = open("helloworld.c", O_RDONLY);
close(fd2);
printf("fd1 = %d, fd2 = %dn", fd1, fd2);
fd1 = open("helloworld.c", O_RDONLY);
fd2 = open("helloworld.c", O_RDONLY);
close(fd1);
close(fd2);
printf("fd1 = %d, fd2 = %dn", fd1, fd2);
}
$ ./a.out
fd1 = 3, fd2 = 3
fd1 = 3, fd2 = 4
!46
cat tatsu-cat.c
#include <fcntl.h>
#include <unistd.h>
#define N 1024
int main(int argc, char *argv[])
{
int fd, buflen;
char buf[N];
if (argc < 2)
_exit(1);
for (int i = 1; i < argc; i++)
{
if ((fd = open(argv[i], O_RDONLY)) < 0)
{
close(fd);
continue;
}
while ((buflen = read(fd, buf, N)) > 0)
write(1, buf, buflen);
close(fd);
}
return 0;
}
!47
!48
$ gdb helloworld
(gdb) disass main
# Dump of assembler code for function main:
# 0x0000000000001135 <+0>: push rbp
# 0x0000000000001136 <+1>: mov rbp,rsp
# 0x0000000000001139 <+4>: lea rdi,
[rip+0xec4] # 0x2004
# 0x0000000000001140 <+11>: mov eax,0x0
# 0x0000000000001145 <+16>: call 0x1030
<printf@plt>
# 0x000000000000114a <+21>: mov eax,0x0
# 0x000000000000114f <+26>: pop rbp
# 0x0000000000001150 <+27>: ret
# End of assembler dump.
!49
$ gdb helloworld
(gdb) disass main
# Dump of assembler code for function main:
# 0x0000000000001135 <+0>: push rbp
#
!50
$ gdb helloworld
(gdb) disass main
# Dump of assembler code for function main:
# 0x0000000000001135 <+0>: push rbp
#
!51




!52
!53
!54
!55
!56
!57
!58
!59
!60
!61
!62
!63
!64
!65

More Related Content

What's hot

JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyYasuharu Nakano
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練Sheng-Hao Ma
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHPThomas Weinert
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with itFlavien Raynaud
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...akaptur
 
Jakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheelJakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheeltcurdt
 
GDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしようGDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしようSatoshi Noda
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)hasan0812
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldtcurdt
 
我在豆瓣使用Emacs
我在豆瓣使用Emacs我在豆瓣使用Emacs
我在豆瓣使用Emacs董 伟明
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to ProveKazuho Oku
 
2² C# 4.0 and .NET 4 Selected Features
2² C# 4.0 and .NET 4 Selected Features2² C# 4.0 and .NET 4 Selected Features
2² C# 4.0 and .NET 4 Selected FeaturesMustafa Isik
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan Barber
 

What's hot (20)

C99[2]
C99[2]C99[2]
C99[2]
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
Vcs28
Vcs28Vcs28
Vcs28
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with it
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
Jakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheelJakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheel
 
GDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしようGDG DevFest Kyoto 2014 これからのGoの話をしよう
GDG DevFest Kyoto 2014 これからのGoの話をしよう
 
Chat code
Chat codeChat code
Chat code
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real world
 
Codes
CodesCodes
Codes
 
我在豆瓣使用Emacs
我在豆瓣使用Emacs我在豆瓣使用Emacs
我在豆瓣使用Emacs
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to Prove
 
2² C# 4.0 and .NET 4 Selected Features
2² C# 4.0 and .NET 4 Selected Features2² C# 4.0 and .NET 4 Selected Features
2² C# 4.0 and .NET 4 Selected Features
 
Arp
ArpArp
Arp
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 

Similar to プログラム実行の話と
OSとメモリの挙動の話

Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기Ji Hun Kim
 
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)Masashi Shibata
 
Load-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADLoad-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADDharmalingam Ganesan
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughterQuinn Wilton
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate CompilersFunctional Thursday
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019corehard_by
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash FeaturesNati Cohen
 
SFO15-500: VIXL
SFO15-500: VIXLSFO15-500: VIXL
SFO15-500: VIXLLinaro
 
Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science Chucheng Hsieh
 
Common Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by ExampleCommon Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by ExampleGanesh Samarthyam
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersAppier
 
Exploring the x64
Exploring the x64Exploring the x64
Exploring the x64FFRI, Inc.
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonakaptur
 

Similar to プログラム実行の話と
OSとメモリの挙動の話 (20)

Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 
Marat-Slides
Marat-SlidesMarat-Slides
Marat-Slides
 
3
33
3
 
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
 
Load-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADLoad-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOAD
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
 
Vcs23
Vcs23Vcs23
Vcs23
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash Features
 
SFO15-500: VIXL
SFO15-500: VIXLSFO15-500: VIXL
SFO15-500: VIXL
 
Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science
 
Vcs16
Vcs16Vcs16
Vcs16
 
Common Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by ExampleCommon Intermediate Language (.NET) by Example
Common Intermediate Language (.NET) by Example
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
 
20141106 asfws unicode_hacks
20141106 asfws unicode_hacks20141106 asfws unicode_hacks
20141106 asfws unicode_hacks
 
Exploring the x64
Exploring the x64Exploring the x64
Exploring the x64
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 

Recently uploaded

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
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
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
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
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
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
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
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
 
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
 
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
 
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
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 

Recently uploaded (20)

Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
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
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
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
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
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
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
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
 
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...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
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...
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 

プログラム実行の話と
OSとメモリの挙動の話

  • 1.
  • 2. !2
  • 3. !3
  • 4. !4
  • 5. !5
  • 6. !6
  • 7. !7
  • 8. !8
  • 9. !9
  • 10. !10
  • 11. !11
  • 12. !12
  • 13. #include <stdio.h> int main() { printf("hello world!n"); return 0; } !13
  • 14. $ ls helloworld helloworld.c $ file helloworld.c # helloworld.c: C source, ASCII text $ file helloworld # helloworld: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=02ed1e530f48620e34b1abc02079fc1 17ebb2279, not stripped !14
  • 15. $ ls -alh # -rwxr-xr-x 1 root root 17K Nov 4 23:21 helloworld # -rw-r--r-- 1 root root 62 Nov 4 23:20 helloworld.c !15
  • 16. $ cat helloworld {¥rtf1¥ansi ¥deff1{¥fonttbl{¥f1¥fmodern¥fprq1¥fcharset0 Courier New;}}{¥colortbl; ¥red224¥green234¥blue238;¥red00¥green00¥blue0 0;¥red191¥green03¥blue03;¥red176¥green126¥blu e00;¥red131¥green129¥blue131;¥red131¥green129 ¥blue131;¥red255¥green00¥blue255;¥red00¥green 130¥blue00;¥red12 …… !16
  • 17. $ gdb helloworld (gdb) disass main # Dump of assembler code for function main: # 0x0000000000001135 <+0>: push rbp # 0x0000000000001136 <+1>: mov rbp,rsp # 0x0000000000001139 <+4>: lea rdi, [rip+0xec4] # 0x2004 # 0x0000000000001140 <+11>: mov eax,0x0 # 0x0000000000001145 <+16>: call 0x1030 <printf@plt> # 0x000000000000114a <+21>: mov eax,0x0 # 0x000000000000114f <+26>: pop rbp # 0x0000000000001150 <+27>: ret # End of assembler dump. !17
  • 18. $ gdb helloworld (gdb) disass main # Dump of assembler code for function main: # 0x0000000000001135 <+0>: push rbp # 0x0000000000001136 <+1>: mov rbp,rsp # 0x0000000000001139 <+4>: lea rdi, [rip+0xec4] # 0x2004 # 0x0000000000001140 <+11>: mov eax,0x0 # 0x0000000000001145 <+16>: call 0x1030 <printf@plt> # 0x000000000000114a <+21>: mov eax,0x0 # 0x000000000000114f <+26>: pop rbp # 0x0000000000001150 <+27>: ret # End of assembler dump. !18
  • 19. $ file helloworldmac helloworldmac: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK| TWOLEVEL|PIE> !19
  • 20. $ ./helloworldmac zsh: exec format error: ./helloworldmac !20
  • 21. !21
  • 22. !22
  • 23. !23
  • 24. !24
  • 25. (gdb) disass main Dump of assembler code for function main: 0x0000000000001135 <+0>: push rbp 0x0000000000001136 <+1>: mov rbp,rsp 0x0000000000001139 <+4>: lea rdi, [rip+0xec4] # 0x2004 0x0000000000001140 <+11>:mov eax,0x0 0x0000000000001145 <+16>:call 0x1030 <printf@plt> 0x000000000000114a <+21>:mov eax,0x0 0x000000000000114f <+26>:pop rbp 0x0000000000001150 <+27>:ret End of assembler dump. !25
  • 26. !26
  • 27. !27
  • 28. !28
  • 29. !29
  • 30. !30
  • 32. !32
  • 33. void test_function(int a, int b, int c, int d) { int flag; char buffer[10]; flag = 31337; // buffer[0] = 'A'; } int main() { test_function(1, 2, 3, 4); // } !33
  • 34. gdb -q ./stack_example Reading symbols from ./stack_example...done. (gdb) list 1 2 void test_function(int a, int b, int c, int d) 3 { 4 int flag; 5 char buffer[10]; 6 7 flag = 31337; 8 buffer[0] = 'A'; 9 } 10 (gdb) list 11 int main() 12 { 13 test_function(1, 2, 3, 4); 14 test_function(5,6,7,8); 15 } 16 (gdb) break 13 Breakpoint 1 at 0x1147: file stack_example.c, line 13. (gdb) break test_function Breakpoint 2 at 0x1135: file stack_example.c, line 7. (gdb) break 14 Breakpoint 3 at 0x1160: file stack_example.c, line 14. !34
  • 35. (gdb) run Starting program: /root/rg/stack_example Breakpoint 1, main () at stack_example.c:13 13 test_function(1, 2, 3, 4); (gdb) i r rsp rbp rsp 0x7fffffffe350 0x7fffffffe350 rbp 0x7fffffffe350 0x7fffffffe350 (gdb) cont Continuing. Breakpoint 2, test_function (a=1, b=2, c=3, d=4) at stack_example.c:7 7 flag = 31337; (gdb) i r rsp rbp rsp 0x7fffffffe340 0x7fffffffe340 rbp 0x7fffffffe340 0x7fffffffe340 (gdb) cont Continuing. Breakpoint 3, main () at stack_example.c:14 14 test_function(5,6,7,8); (gdb) i r rsp rbp rsp 0x7fffffffe350 0x7fffffffe350 rbp 0x7fffffffe350 0x7fffffffe350 !35
  • 36. $ gcc -g -o memory_segments memory_seguments.c !36
  • 37. $ ./memory_segments data segment: global_init_var 0xaecf0040 static_init_var 0xaecf0044 bss segment global_var 0xaecf0050 static_var 0xaecf004c heap segment heap_var_ptr 0xb098c260 stack segment stack_var 0x9fefb384 function() stack_var 0x9fefb36c !37
  • 38. !38
  • 39. !39
  • 40. #include <stdio.h> int main() { printf("hello world!n"); return 0; } !40
  • 42. !42
  • 43. $ strace ./helloworld
 execve("./helloworld", ["./helloworld"], 0x7ffc2b36e160 /* 29 vars */) = 0 brk(NULL) = 0x55f838726000 . . . mprotect(0x7f313a6c9000, 4096, PROT_READ) = 0 munmap(0x7f313a67e000, 145183) = 0 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0 brk(NULL) = 0x55f838726000 brk(0x55f838747000) = 0x55f838747000 write(1, "hello world!", 12hello world!) = 12 exit_group(0) = ? +++ exited with 0 +++ !43
  • 44. !44
  • 45. !45
  • 46. #include <stdio.h> #include <fcntl.h> #include <unistd.h> int main() { int fd1, fd2; fd1 = open("helloworld.c", O_RDONLY); close(fd1); fd2 = open("helloworld.c", O_RDONLY); close(fd2); printf("fd1 = %d, fd2 = %dn", fd1, fd2); fd1 = open("helloworld.c", O_RDONLY); fd2 = open("helloworld.c", O_RDONLY); close(fd1); close(fd2); printf("fd1 = %d, fd2 = %dn", fd1, fd2); } $ ./a.out fd1 = 3, fd2 = 3 fd1 = 3, fd2 = 4 !46
  • 47. cat tatsu-cat.c #include <fcntl.h> #include <unistd.h> #define N 1024 int main(int argc, char *argv[]) { int fd, buflen; char buf[N]; if (argc < 2) _exit(1); for (int i = 1; i < argc; i++) { if ((fd = open(argv[i], O_RDONLY)) < 0) { close(fd); continue; } while ((buflen = read(fd, buf, N)) > 0) write(1, buf, buflen); close(fd); } return 0; } !47
  • 48. !48
  • 49. $ gdb helloworld (gdb) disass main # Dump of assembler code for function main: # 0x0000000000001135 <+0>: push rbp # 0x0000000000001136 <+1>: mov rbp,rsp # 0x0000000000001139 <+4>: lea rdi, [rip+0xec4] # 0x2004 # 0x0000000000001140 <+11>: mov eax,0x0 # 0x0000000000001145 <+16>: call 0x1030 <printf@plt> # 0x000000000000114a <+21>: mov eax,0x0 # 0x000000000000114f <+26>: pop rbp # 0x0000000000001150 <+27>: ret # End of assembler dump. !49
  • 50. $ gdb helloworld (gdb) disass main # Dump of assembler code for function main: # 0x0000000000001135 <+0>: push rbp # !50
  • 51. $ gdb helloworld (gdb) disass main # Dump of assembler code for function main: # 0x0000000000001135 <+0>: push rbp # !51
  • 53. !53
  • 54. !54
  • 55. !55
  • 56. !56
  • 57. !57
  • 58. !58
  • 59. !59
  • 60. !60
  • 61. !61
  • 62. !62
  • 63. !63
  • 64. !64
  • 65. !65