Professional Documents
Culture Documents
CS552
Kartik Gopalan
CS552/BU/Spring2008
.long sys_unshare
/* 310 */
.long sys_foo
/* 311 */
CS552/BU/Spring2008
include/asm/unistd_32.h
/*
* This file contains the system call
numbers.
*/
#define
#define
#define
#define
#define
__NR_restart_syscall
__NR_exit
1
__NR_fork
2
__NR_read
3
__NR_write
4
#define __NR_foo
325
filp = fdt->fd[fd];
if (!filp)
goto out_unlock;
out_unlock:
spin_unlock(&files->file_lock);
return -EBADF;
}
CS552/BU/Spring2008
Call-by-reference argument
o
o
CS552/BU/Spring2008
For instance, for a no-argument system call named foo(), you'll call
http://www.ibm.com/developerworks/linux/library/l-system-calls/
CS552/BU/Spring2008
<stdio.h>
<errno.h>
<unistd.h>
<linux/unistd.h>
sleep(1);
}
return 0;
CS552/BU/Spring2008
(contd.)
CS552/BU/Spring2008
_syscall1(type,name,type1,arg1)
include/asm/unistd.h
Also, pay attention to the usage and implementation of
__syscall_return macro. What does it do?
CS552/BU/Spring2008
// define the new syscall number. Standard syscalls are defined in linux/unistd.h
#define __NR_foo 311
// generate a user-level stub
_syscall0(int,foo)
int main(void)
{
int ret;
while(1) {
// making the system call
ret = foo();
printf("ret = %d errno = %d\n", ret, errno);
sleep(1);
}
return 0;
CS552/BU/Spring2008
SYSENTER/SYSEXIT Method
This is the newest and fastest of all methods to make system calls in
Pentium class machines.
Pentium machines have long supported these new instructions as a
faster technique to enter and exit the kernel mode than the old
technique based on raising the "int 0x80" software interrupt. Newer
linux kernels have apparently adopted this technique.
The details of how this works is quite interesting and I may try to
cover this briefly in the class.
Meanwhile you can read about the details in the following links and
maybe even try it out using the example code.
http://manugarg.googlepages.com/systemcallinlinux2_6.html
http://www.win.tue.nl/~aeb/linux/lk/lk-4.html
http://manugarg.googlepages.com/aboutelfauxiliaryvectors
CS552/BU/Spring2008
/usr/src/redhat/BUILD/kernel-2.6.18/linux2.6.18.s390x/arch/s390/kernel/syscalls.S
o SYSCALL(sys_mysvc, sys_mysvc, sys_mysvc); // typical entry
/usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.s390x/include/asms390/unistd.h
o #define __NR_mysvc n and #define __NR_syscalls
n+1
/usr/src/kernels/2.6.18-92.el5-s390x/include/asm-s390/unistd.h
o Same as the BUILD UNISTD.H
CS552/BU/Spring2008