summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_example.S63
1 files changed, 37 insertions, 26 deletions
diff --git a/src/c_example.S b/src/c_example.S
index 81538c7..f410c17 100644
--- a/src/c_example.S
+++ b/src/c_example.S
@@ -57,13 +57,43 @@ main:
# movb $0x4, %al /* SYS_write */
# syscall
- # xorq %rdi, %rdi
- # xorq %rsi, %rsi
- # xorq %rax, %rax
- # movq $sysctl, %rdi
- # movq $0x0, %rsi
- # movq $0x3b, %rax /* SYS_execve */
- # syscall
+ xorq %rdi, %rdi
+ xorq %rsi, %rsi
+ xorq %rax, %rax
+ movb $0x2, %al /* SYS_fork */
+ syscall
+ cmp $0x0, %rax
+ jne next
+
+ xorq %rax, %rax
+ pushq %rbp
+ movq %rsp, %rbp
+ movq $sysctl, -32(%rbp)
+ movq $model, -24(%rbp)
+ movq $0x0, -16(%rbp)
+ movq -32(%rbp), %rdi
+ leaq -32(%rbp), %rsi
+ xorq %rdx, %rdx
+ movq $0x3b, %rax /* SYS_execve */
+ syscall
+ popq %rbp
+ retq
+
+next:
+ xorq %rdi, %rdi
+ xorq %rsi, %rsi
+ xorq %rax, %rax
+ pushq %rbp
+ movq %rsp, %rbp
+ movq $sysctl, -32(%rbp)
+ movq $ncpu, -24(%rbp)
+ movq $0x0, -16(%rbp)
+ movq -32(%rbp), %rdi
+ leaq -32(%rbp), %rsi
+ xorq %rdx, %rdx
+ movq $0x3b, %rax /* SYS_execve */
+ syscall
+ popq %rbp
# xorq %rdi, %rdi
# xorq %rsi, %rsi
@@ -74,24 +104,6 @@ main:
# movb $0x4, %al /* SYS_write */
# syscall
- xorq %rdx, %rdx
- movq $buff, %rdx
- pushq %rcx
- movq %rcx, %rcx
- movb $0x8, %cl
- movq $sysctl, (%rdx, %rcx, 1)
- movq $model, (%rdx, %rcx, 2)
- movq $0x0, (%rdx, %rcx, 4)
- xorq %rdi, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- movb $0x1, %dil
- movq (%rdx, %rcx, 1), %rsi
- movq $0x6, %rdx
- movb $0x4, %al /* SYS_write */
- syscall
- popq %rcx
-
xorq %rax, %rax
retq
@@ -104,4 +116,3 @@ main:
lscpu: .asciz "/usr/local/bin/lscpu"
model: .asciz "hw.model"
ncpu: .asciz "hw.ncpu"
- buff: .byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0