about summary refs log tree commit diff stats
path: root/subx/examples
diff options
context:
space:
mode:
Diffstat (limited to 'subx/examples')
-rwxr-xr-xsubx/examples/ex12bin0 -> 167 bytes
-rw-r--r--subx/examples/ex12.subx43
2 files changed, 43 insertions, 0 deletions
diff --git a/subx/examples/ex12 b/subx/examples/ex12
new file mode 100755
index 00000000..236afe98
--- /dev/null
+++ b/subx/examples/ex12
Binary files differdiff --git a/subx/examples/ex12.subx b/subx/examples/ex12.subx
new file mode 100644
index 00000000..50c57928
--- /dev/null
+++ b/subx/examples/ex12.subx
@@ -0,0 +1,43 @@
+## example showing mmap syscall
+# Create a new segment using mmap, save the address, write to it.
+#
+# To run:
+#   $ subx translate ex12.subx ex12
+#   $ subx run ex12
+# You shouldn't get a segmentation fault.
+
+== code
+# instruction                     effective address                                                   operand     displacement    immediate
+# op          subop               mod             rm32          base        index         scale       r32
+# 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
+
+  # mmap(0x1000)
+  bb/copy                         .               .             .           .             .           .           .               mmap_new_segment/imm32  # copy to EBX
+  b8/copy                         .               .             .           .             .           .           .               0x5a/imm32/mmap         # copy 8 to EAX
+  cd/syscall  0x80/imm8
+
+  # store to *EAX
+  c7/copy                         0/mod/direct    0/rm32/EAX    .           .             .           .           .               0x34/imm32              # copy 0x34 to *EAX
+
+  # exit(EAX)
+  89/copy                         3/mod/direct    3/rm32/EBX    .           .             .           0/r32/EAX   .               .                       # copy EAX to EBX
+  b8/copy                         .               .             .           .             .           .           .               1/imm32/exit            # copy 1 to EAX
+  cd/syscall  0x80/imm8
+
+== data
+# various constants used here were found in the Linux sources (search for file mman-common.h)
+mmap_new_segment:  # type mmap_arg_struct
+  # addr
+  00 00 00 00  # null
+  # len
+  00 01 00 00  # 0x1000
+  # protection flags
+  03 00 00 00  # PROT_READ | PROT_WRITE
+  # sharing flags
+  22 00 00 00  # MAP_PRIVATE | MAP_ANONYMOUS
+  # fd
+  ff ff ff ff  # -1 since MAP_ANONYMOUS is specified
+  # offset
+  00 00 00 00  # 0 since MAP_ANONYMOUS is specified
+
+# vim:ft=subx:nowrap:tw&
>^
36d74808 ^
cdf0f349 ^





























621c64b5 ^
cdf0f349 ^

f7f40d32 ^
36d74808 ^


621c64b5 ^





cdf0f349 ^



36d74808 ^
cdf0f349 ^















621c64b5 ^




4c0c5eb5 ^
621c64b5 ^
2224e41f ^






















cdf0f349 ^


17ec4016 ^




cdf0f349 ^
f7f40d32 ^




4c0c5eb5 ^
f7f40d32 ^
cdf0f349 ^



cdf0f349 ^

b8f11f75 ^




cdf0f349 ^










cdf0f349 ^
ea19d0dc ^
cdf0f349 ^



59085fca ^



cdf0f349 ^












59e47aca ^
cdf0f349 ^











1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196