blob: 7258adc6a89874707f7c185f1e8b5ce3105961e5 [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2##--------------------------------------------------------------------##
3##--- Support for doing system calls. ---##
4##--- vg_syscall.S ---##
5##--------------------------------------------------------------------##
6
7/*
njnc9539842002-10-02 13:26:35 +00008 This file is part of Valgrind, an extensible x86 protected-mode
9 emulator for monitoring program execution on x86-Unixes.
sewardjde4a1d02002-03-22 01:27:54 +000010
nethercotebb1c9912004-01-04 16:43:23 +000011 Copyright (C) 2000-2004 Julian Seward
sewardjde4a1d02002-03-22 01:27:54 +000012 jseward@acm.org
sewardjde4a1d02002-03-22 01:27:54 +000013
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
njn25e49d8e72002-09-23 09:36:25 +000029 The GNU General Public License is contained in the file COPYING.
sewardjde4a1d02002-03-22 01:27:54 +000030*/
31
nethercote5a2664c2004-09-02 15:37:39 +000032#include "core_asm.h"
jsgf855d93d2003-10-13 22:26:55 +000033#include "vg_unistd.h"
sewardjde4a1d02002-03-22 01:27:54 +000034
35.globl VG_(do_syscall)
36
jsgf855d93d2003-10-13 22:26:55 +000037/*
38 Perform a Linux syscall with int 0x80
sewardjde4a1d02002-03-22 01:27:54 +000039
jsgf855d93d2003-10-13 22:26:55 +000040 Syscall args are passed on the stack
41 Int VG_(do_syscall)(Int syscall_no, ...)
42
43 This has no effect on the virtual machine; the expectation is
44 that the syscall mechanism makes no useful changes to any
45 register except %eax, which is returned.
46 */
sewardjde4a1d02002-03-22 01:27:54 +000047VG_(do_syscall):
jsgf855d93d2003-10-13 22:26:55 +000048 push %esi
49 push %edi
50 push %ebx
51 push %ebp
52 movl 16+ 4(%esp),%eax
53 movl 16+ 8(%esp),%ebx
54 movl 16+12(%esp),%ecx
55 movl 16+16(%esp),%edx
56 movl 16+20(%esp),%esi
57 movl 16+24(%esp),%edi
58 movl 16+28(%esp),%ebp
sewardjde4a1d02002-03-22 01:27:54 +000059 int $0x80
jsgf855d93d2003-10-13 22:26:55 +000060 popl %ebp
61 popl %ebx
62 popl %edi
63 popl %esi
sewardjde4a1d02002-03-22 01:27:54 +000064 ret
65
jsgf855d93d2003-10-13 22:26:55 +000066/*
67 Perform a clone system call. clone is strange because it has
68 fork()-like return-twice semantics, so it needs special
69 handling here.
70
71 int VG_(clone)(int (*fn)(void *), void *child_stack, int flags, void *arg,
72 0 4 8 12
73 pid_t *child_tid, pid_t *parent_tid)
74 16 20
75
76 */
77.globl VG_(clone)
78VG_(clone):
79#define FSZ (4+4+4) /* frame size = retaddr+ebx+edi */
80 push %ebx
81 push %edi
82 /* set up child stack with function and arg */
83 movl 4+FSZ(%esp), %ecx /* child stack */
84 movl 12+FSZ(%esp), %ebx /* fn arg */
85 movl 0+FSZ(%esp), %eax /* fn */
86 lea -8(%ecx), %ecx /* make space on stack */
87 movl %ebx, 4(%ecx) /* fn arg */
88 movl %eax, 0(%ecx) /* fn */
89
90 /* get other args to clone */
91 movl 8+FSZ(%esp), %ebx /* flags */
92 movl 20+FSZ(%esp), %edx /* parent tid * */
93 movl 16+FSZ(%esp), %edi /* child tid * */
94 movl $__NR_clone, %eax
95 int $0x80
96 testl %eax, %eax
97 jnz 1f
98
99 /* CHILD - call thread function */
100 popl %eax
101 call *%eax
102
103 /* exit with result */
104 movl %eax, %ebx
105 movl $__NR_exit, %eax
106 int $0x80
107
108 /* Hm, exit returned */
109 ud2
110
1111: /* PARENT or ERROR */
112 pop %edi
113 pop %ebx
114 ret
fitzhardinge4f10ada2004-06-03 10:00:42 +0000115
116.globl VG_(sigreturn)
117VG_(sigreturn):
118 movl $__NR_rt_sigreturn, %eax
119 int $0x80
thughes4ad52d02004-06-27 17:37:21 +0000120
121/* Let the linker know we don't need an executable stack */
122.section .note.GNU-stack,"",@progbits
123
sewardjde4a1d02002-03-22 01:27:54 +0000124##--------------------------------------------------------------------##
125##--- end vg_syscall.S ---##
126##--------------------------------------------------------------------##