Of course, if I'm really off base, and 21h is x86 architecture-supported,
then just tell me that and I'll be happy :)
--
nick black cs/math freshman 2430 TA[ "Don't ask Nick; he'll say to make
georgia institute of technology[ everything due the same day.
http://luckystrike.resnet.gatech.edu[ He's evil."
da...@cc.gatech.edu 404.206.1513[ -Jim G.
On Unix, the only correct way to call system functions is to call
functions provided in the libc library (this library provides more
than just the standard C library functions, it also provides the
documented way of interfacing to the OS).
If you really want to use other mean to communicate with the OS, there
is no standard way. On x86, I know of two way: call gates and
interrupt.
Linux use int 0x80. I've explained in another message on this forum
(use deja news to find it, I'vn't written on other subject in this
group) how to extract the information needed to make yourself these
calls (all the information is available but not in a single place and
not presented for assembly programmers not wanting to use the
documented way).
Yours,
-- Jean-Marc
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
And probably pretty soon there will be SYSENTER as well.
-hpa
--
"The user's computer downloads the ActiveX code and simulates a 'Blue
Screen' crash, a generally benign event most users are familiar with
and that would not necessarily arouse suspicions."
-- Security exploit description on http://www.zks.net/p3/how.asp
< Aloha. I am a big fan of the DOS functionality interrupt 21h provides, and
< the good reference to it that Ralf Brown maintains. Can someone point me in
< the direction of *nix (if it differs to a high degree, then Linux) emulation
< of the 21h utilities, and a reference to it??? Thanks.
<
< Of course, if I'm really off base, and 21h is x86 architecture-supported,
< then just tell me that and I'll be happy :)
<
< --
I read in the `assembly language journel' about how to use the linux
system call interface (int 0x80). I wrote a shell script to extract
all the function numbers for use with nasm. I run this script and save
it as syscall.mac.
#! /bin/bash
unistd=/usr/include/asm/unistd.h
date=`date`
cat <<EOF
;;;; -*- Mode: asm; asm-indent-level: 2; -*-
;;;; $date
;;;; Linux System call interrupt numbers
%ifndef SYSCALL_MAC
%define SYSCALL_MAC
EOF
# The second `y' is a y/tab/space/.
cat $unistd | \
sed -n '/^#define __NR/ {
y/#/%/
y/ / /
s/__NR//g
s/\/\\*.*\\*\///
p
}' | \
awk '{ printf ("%s %-26s %3d\n", $1,$2,$3) }'
cat <<'EOF'
%imacro syscall 0-6 nil
%ifidn %1, nil
%error "syscall needs at least one parameter"
%elifid %1
%error "Undefined system call `%1'"
%else
mov eax, dword %1
%if %0 > 1
mov ebx, %2
%if %0 > 2
mov ecx, %3
%if %0 > 3
mov edx, %4
%if %0 > 4
mov esi, %5
%if %0 > 5
mov edi, %6
%endif
%endif
%endif
%endif
%endif
int 0x80
%endif
%endmacro
%endif ; SYSCALL_MAC
EOF
### End of script
I use the following macro for c function calls.
%imacro ccall 1-*
;; function, {params}*
;; Push last parameter first, cleanup.
%rep %0-1
%rotate -1
push %1
%endrep
%rotate -1
call %1
add esp, byte ((%0-1) * 4)
%endmacro
Here is a quick example of using this.
;;; May 13, 1999 Thursday 9:55 PM
;;; execute system call using nasm macros
%include "macros.mac" ; includes `ccall' as shown above
%include "syscall.mac" ; includes the output of the above shell script
[bits 32]
global main
extern printf
section .data
text db 'PID: ',0
param db '%d',10,0
section .text
main:
ccall printf, dword text
syscall _getpid
ccall printf, dword param, eax
ret
Pretty straight forward (no error checking though). Hope this was
informative.