I want to access errno present in errno.h in assembly language in order to handle errors of write function call. I found somewhere that make call to _error in assembly language for this purpose but it is throwing errors as :
ExitNewShell.asm:71: error: symbol `_error' undefined
ExitNewShell.asm:85: error: symbol `_error' undefined
ExitNewShell.asm:98: error: symbol `_error' undefined
ExitNewShell.asm:111: error: symbol `_error' undefined
ExitNewShell.asm:124: error: symbol `_error' undefined
ExitNewShell.asm:137: error: symbol `_error' undefined
ExitNewShell.asm:150: error: symbol `_error' undefined
ExitNewShell.asm:163: error: symbol `_error' undefined
ExitNewShell.asm:176: error: symbol `_error' undefined
My assembly code : ExitNewShell.asm
[SECTION .text]
global _start
_start:
jmp ender
starter:
xor eax, eax ;clean up the registers
xor ebx, ebx
xor edx, edx
xor ecx, ecx
mov al, 4 ;syscall write
mov bl, 1 ;stdout is 1
pop ecx ;get the address of the string from the stack
mov dl, 11 ;length of the string
int 0x80
cmp eax,0xffffffff
jne exit
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff2
mov dl,14
lea ecx,[msg1]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff2:
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff3
mov dl,14
lea ecx,[msg2]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff3:
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff4
mov dl,14
lea ecx,[msg3]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff4:
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff5
mov dl,14
lea ecx,[msg4]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff5:
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff6
mov dl,14
lea ecx,[msg5]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff6:
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff7
mov dl,14
lea ecx,[msg6]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff7:
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff8
mov dl,14
lea ecx,[msg7]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff8:
call _error
mov eax,[eax]
cmp eax,0xb
jne callOff9
mov dl,14
lea ecx,[msg8]
mov bl,1
mov al,4
int 0x80
jmp exit
callOff9:
call _error
mov eax,[eax]
cmp eax,0xb
jne exit
mov dl,14
lea ecx,[msg9]
mov bl,1
mov al,4
int 0x80
jmp exit
exit:
xor eax, eax
mov al, 1 ;exit the shellcode
xor ebx,ebx
int 0x80
ender:
call starter ;put the address of the string on the stack
db 'Hello World',0xa
[SECTION .data]
msg1 db 'ERROR - EAGAIN',0
msg2 db 'ERROR - EBADF',0
msg3 db 'ERROR - EPIPE',0
msg4 db 'ERROR - EFAULT',0
msg5 db 'ERROR - EFBIG',0
msg6 db 'ERROR - EINTR',0
msg7 db 'ERROR - EINVAL',0
msg8 db 'ERROR - EIO',0
msg9 db 'ERROR - ENOSPC',0
How to access errno in assembly language?