OpenSolaris邮件列表中关于系统调用的讨论
发表于:2007-06-08来源:作者:点击数:
标签:
转载自:OpenSolaris: code tarbaby Posts: 4 Registered: 6/15/05 Read Syscall implementation in solaris Posted: Jun 16, 2005 10:23 PM Click to reply to this thread Reply Whereas for linux I can find a lot of documentation on the implementati
转载自:OpenSolaris: code
tarbaby
Posts: 4
Registered: 6/15/05
Read Syscall implementation in solaris
Posted: Jun 16, 2005 10:23 PM
Click to reply to this thread Reply
Whereas for linux I can find a lot of documentation on the implementation of system calls -
calling conventions, argument types, trapping mechanism, vectors, naming conventions, and
so forth I can't find such for Solaris.
Can anyone explain or offer any pointers?
system
Posts: 10
Registered: 3/9/05
Read Re: Syscall implementation in solaris
Posted: Jun 17, 2005 12:43 AM in response to: tarbaby in response to: tarbaby
Click to reply to this thread Reply
Replying to make sure this forum is fixed.
achartre
Posts: 1
From: Grenoble, France
Registered: 3/21/05
Read Re: Syscall implementation in solaris
Posted: Jun 17, 2005 1:03 AM in response to: tarbaby in response to: tarbaby
Click to reply to this thread Reply
A system call invokes the function _syscall() with its syscall number
as the first argument and the arguments of the syscall as the next
arguments.
What _syscall() exactly does is architecture dependent so different on
Sparc, Intel and AMD64. For short, it will jump into the kernel and
pass the syscall number, the kernel will use the syscall number as an
index into the sysent[] array to find the kernel handler of the syscall
and invoke this handler with the syscall parameters.
Let's look at details on Sparc: _syscall() will execute a trap
instruction to jump into the kernel:
http://cvs.opensolaris.org/source/xref/usr/src/lib/libc/sparc/sys/syscall.s
It first stores the arguments and then does a "ta SYSCALL_TRAPNUM";
with SYSCALL_TRAPNUM equals to 8 for 32-bit syscall or 64 for 64-bit
syscall; this will generate a trap 0x108 or 0x140.
Traps are handled by the trap table which is defined in trap_table.s:
http://cvs.opensolaris.org/source/xref/usr/src/uts/sun4u/ml/trap_table.s
The entries for trap 0x108 and 0x140 are:
SYSCALL(syscall_trap32); /* 108 ILP32 system call on LP64 */
and
SYSCALL(syscall_trap) /* 140 LP64 system call */
This means that the kernel function syscall_trap32() or syscall_trap()
is going to be called through the generic trap handler sys_trap().
Then syscall_trap32()/syscall_trap() is going to retrieve the system
call handler from the array sysent32[]/sysent[] using the syscall
number as the index of this array:
http://cvs.opensolaris.org/source/xref/usr/src/uts/common/os/sysent.c
and it will invoke the function found at that entry with the specified
number of arguments which is also stored in the array.
The mechanism is the same for Intel and AMD64 except that the way to
jump into the kernel is different.
alex.
gavinm
Posts: 9
From: United Kingdom
Registered: 3/21/05
Read Re: Syscall implementation in solaris
Posted: Jun 17, 2005 1:21 AM in response to: tarbaby in response to: tarbaby
Click to reply to this thread Reply
You could have a look at my blog entry:
http://blogs.sun.com/roller/page/gavinm/20050615#sparc_system_calls
and the related blog entries it links to from Eric Schrock describing how to
add a syscall and from Russ Blaine describing x86/x64 syscalls.
Cheers
Gavin
fintanr
Posts: 7
Registered: 6/13/05
Read Re: Re: Syscall implementation in solaris
Posted: Jun 17, 2005 1:25 AM in response to: achartre in response to: achartre
Click to reply to this thread Reply
Hi,
Further to Alex's explanation Eric Schrock did a blog on how to
add a system call to Solaris which may be of interest
http://blogs.sun.com/roller/page/eschrock/20050614#how_to_add_a_system
- Fintan
--
fintanr at sun dot com http://blogs.sun.com/fintanr
@dub04 http://www.sun.com/software/solaris
_______________________________________________
opensolaris-code mailing list
opensolaris-code at opensolaris dot org
https://opensolaris.org:444/mailman/listinfo/opensolaris-code
eschrock
Posts: 33
From: Menlo Park, CA
Registered: 3/21/05
Read Re: Syscall implementation in solaris
Posted: Jun 17, 2005 1:59 AM in response to: tarbaby in response to: tarbaby
Click to reply to this thread Reply
Check out Russ Blaine's blog for a great description of the x86 syscall implementation:
http://blogs.sun.com/roller/page/rab/20050614#x86_syscall_primer
alanh
Posts: 9
From: Sydney
Registered: 6/13/05
Read Re: Syscall implementation in solaris
Posted: Jun 17, 2005 6:00 AM in response to: tarbaby in response to: tarbaby
Click to reply to this thread Reply
Carl Spalletta wrote:
> Whereas for linux I can find a lot of documentation on the implementation of system calls -
> calling conventions, argument types, trapping mechanism, vectors, naming conventions, and
> so forth I can't find such for Solaris.
>
> Can anyone explain or offer any pointers?
> This message posted from opensolaris.org
> _______________________________________________
> opensolaris-code mailing list
> opensolaris-code at opensolaris dot org
> https://opensolaris.org:444/mailman/listinfo/opensolaris-code
Carl, have a look at the following opening day blogs
http://blogs.sun.com/roller/page/gavinm/20050615#sparc_system_calls -
SPARC System Calls
http://blogs.sun.com/roller/page/eschrock/20050614#how_to_add_a_system
-How to add a system call to OpenSolaris
alan.
_______________________________________________
opensolaris-code mailing list
opensolaris-code at opensolaris dot org
https://opensolaris.org:444/mailman/listinfo/opensolaris-code
frankho
Posts: 8
Registered: 3/21/05
Read Re: Re: Syscall implementation in solaris
Posted: Jun 17, 2005 1:48 AM
Click to reply to this thread Reply
[ ... ]
> The mechanism is the same for Intel and AMD64 except that the way to
> jump into the kernel is different.
Very different.
The x86/x64 platforms use/support a total of four different system call
mechanisms:
a) AMD "syscall" instruction.
b) Intel "sysenter" instruction.
c) "int x91"
and finally support for the "x86 UNIX classic"*):
d) "lcall x27,"
To find out more about how this works and where what method is used,
search for "HWCAP" in the "Linkers & Libraries Guide" on
http://docs.sun.com, and check out the code in:
http://cvs.opensolaris.org/source/xref/usr/src/lib/libc/i386/sys/syscall.s
http://cvs.opensolaris.org/source/xref/usr/src/lib/libc/amd64/sys/syscall.s
http://cvs.opensolaris.org/source/xref/usr/src/lib/libc/i386/crt/_rtboot.s
http://cvs.opensolaris.org/source/xref/usr/src/lib/libc/amd64/crt/_rtboot.s
for the userland/libc side of it, and:
http://cvs.opensolaris.org/source/xref/usr/src/uts/i86pc/ml/syscall_asm.s
http://cvs.opensolaris.org/source/xref/usr/src/uts/i86pc/ml/syscall_asm_amd64.s
http://cvs.opensolaris.org/source/xref/usr/src/uts/i86pc/os/trap.c#998
http://cvs.opensolaris.org/source/xref/usr/src/uts/i86pc/os/trap.c#210
http://cvs.opensolaris.org/source/xref/usr/src/uts/intel/ia32/os/desctbls.c
for the kernel parts.
*) Solaris actually no longer uses "lcall x27" for its own purposes,
but since this is SysV-Standard and required for binary backward
compatibility we keep the kernel's ability to take system calls this
way.
Bye,
Frank Hofmann
_______________________________________________
opensolaris-code mailing list
opensolaris-code at opensolaris dot org
https://opensolaris.org:444/mailman/listinfo/opensolaris-code
原文转自:http://www.ltesting.net