Illumos: fix wartnings
[valgrind.git] / coregrind / m_syscall.c
blob6ab20694d696ac506400a33035e1259002ba6099
2 /*--------------------------------------------------------------------*/
3 /*--- Doing syscalls. m_syscall.c ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Julian Seward
11 jseward@acm.org
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #include "pub_core_basics.h"
30 #include "pub_core_libcassert.h"
31 #include "pub_core_vki.h"
32 #include "pub_core_vkiscnums.h"
33 #include "pub_core_syscall.h"
35 /* ---------------------------------------------------------------------
36 Building syscall return values.
37 ------------------------------------------------------------------ */
39 /* Make a SysRes value from a syscall return value. This is
40 platform specific. */
42 #if defined(VGP_mips32_linux) || defined(VGP_mips64_linux)
44 SysRes VG_(mk_SysRes_mips32_linux) ( UWord v0, UWord v1, UWord a3 ) {
45 /* MIPS uses a3 != 0 to flag an error */
46 SysRes res;
47 res._isError = (a3 != (UWord)0);
48 res._val = v0;
49 res._valEx = v1;
50 return res;
53 SysRes VG_(mk_SysRes_mips64_linux) ( ULong v0, ULong v1, ULong a3 ) {
54 /* MIPS uses a3 != 0 to flag an error */
55 SysRes res;
56 res._isError = (a3 != (ULong)0);
57 res._val = v0;
58 res._valEx = v1;
59 return res;
62 /* Generic constructors. */
63 SysRes VG_(mk_SysRes_Error) ( UWord err ) {
64 SysRes r;
65 r._isError = True;
66 r._val = err;
67 r._valEx = 0;
68 return r;
71 SysRes VG_(mk_SysRes_Success) ( UWord res ) {
72 SysRes r;
73 r._isError = False;
74 r._val = res;
75 r._valEx = 0;
76 return r;
79 SysRes VG_(mk_SysRes_SuccessEx) ( UWord res, UWord resEx ) {
80 SysRes r;
81 r._isError = False;
82 r._val = res;
83 r._valEx = resEx;
84 return r;
88 #elif defined(VGO_linux) \
89 && !defined(VGP_mips32_linux) && !defined(VGP_mips64_linux)
92 From:
93 http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/unix/sysv/
94 linux/i386/sysdep.h?
95 rev=1.28&content-type=text/x-cvsweb-markup&cvsroot=glibc
97 Linux uses a negative return value to indicate syscall errors,
98 unlike most Unices, which use the condition codes' carry flag.
100 Since version 2.1 the return value of a system call might be
101 negative even if the call succeeded. E.g., the 'lseek' system call
102 might return a large offset. Therefore we must not anymore test
103 for < 0, but test for a real error by making sure the value in %eax
104 is a real error number. Linus said he will make sure the no
105 syscall returns a value in -1 .. -4095 as a valid result so we can
106 safely test with -4095.
109 SysRes VG_(mk_SysRes_nanomips_linux) ( UWord a0 ) {
110 SysRes res;
111 res._isError = (a0 > 0xFFFFF000ul);
112 res._val = a0;
113 return res;
116 SysRes VG_(mk_SysRes_x86_linux) ( Int val ) {
117 SysRes res;
118 res._isError = val >= -4095 && val <= -1;
119 if (res._isError) {
120 res._val = (UInt)(-val);
121 } else {
122 res._val = (UInt)val;
124 return res;
127 /* Similarly .. */
128 SysRes VG_(mk_SysRes_amd64_linux) ( Long val ) {
129 SysRes res;
130 res._isError = val >= -4095 && val <= -1;
131 if (res._isError) {
132 res._val = (ULong)(-val);
133 } else {
134 res._val = (ULong)val;
136 return res;
139 /* PPC uses the CR7.SO bit to flag an error (CR0 in IBM-speak) */
140 /* Note this must be in the bottom bit of the second arg */
141 SysRes VG_(mk_SysRes_ppc32_linux) ( UInt val, UInt cr0so ) {
142 SysRes res;
143 res._isError = (cr0so & 1) != 0;
144 res._val = val;
145 return res;
148 /* As per ppc32 version, for the sc instruction cr0.so must be in
149 l.s.b. of 2nd arg.
150 For the scv 0 instruction, the return value indicates failure if
151 it is -4095..-1 (i.e., it is >= -MAX_ERRNO (-4095) as an unsigned
152 comparison), in which case the error value is the negated return value. */
153 SysRes VG_(mk_SysRes_ppc64_linux) ( ULong val, ULong cr0so, UInt flag ) {
154 SysRes res;
156 if (flag == SC_FLAG) {
157 /* sc instruction */
158 res._isError = (cr0so & 1) != 0;
159 res._val = val;
160 } else if (flag == SCV_FLAG) {
161 /* scv instruction */
162 if ( (Long)val >= -4095 && (Long)val <= -1) {
163 res._isError = True;
164 res._val = (ULong)(-val);
165 } else {
166 res._isError = False;
167 res._val = (ULong)(val);
169 } else
170 vg_assert(0);
171 return res;
174 SysRes VG_(mk_SysRes_s390x_linux) ( Long val ) {
175 SysRes res;
176 res._isError = val >= -4095 && val <= -1;
177 if (res._isError) {
178 res._val = -val;
179 } else {
180 res._val = val;
182 return res;
185 SysRes VG_(mk_SysRes_arm_linux) ( Int val ) {
186 SysRes res;
187 res._isError = val >= -4095 && val <= -1;
188 if (res._isError) {
189 res._val = (UInt)(-val);
190 } else {
191 res._val = (UInt)val;
193 return res;
196 SysRes VG_(mk_SysRes_arm64_linux) ( Long val ) {
197 SysRes res;
198 res._isError = val >= -4095 && val <= -1;
199 if (res._isError) {
200 res._val = (ULong)(-val);
201 } else {
202 res._val = (ULong)val;
204 return res;
207 /* Generic constructors. */
208 SysRes VG_(mk_SysRes_Success) ( UWord res ) {
209 SysRes r;
210 r._isError = False;
211 r._val = res;
212 return r;
215 #if defined(VGP_nanomips_linux)
216 SysRes VG_(mk_SysRes_Error) ( UWord err ) {
217 SysRes r;
218 r._isError = True;
219 r._val = (UWord)(-(Word)err);
220 return r;
222 #else
223 SysRes VG_(mk_SysRes_Error) ( UWord err ) {
224 SysRes r;
225 r._isError = True;
226 r._val = err;
227 return r;
230 #endif
233 #elif defined(VGO_darwin)
235 /* Darwin: Some syscalls return a double-word result. */
236 SysRes VG_(mk_SysRes_x86_darwin) ( UChar scclass, Bool isErr,
237 UInt wHI, UInt wLO )
239 SysRes res;
240 res._wHI = 0;
241 res._wLO = 0;
242 res._mode = 0; /* invalid */
243 vg_assert(isErr == False || isErr == True);
244 vg_assert(sizeof(UWord) == sizeof(UInt));
245 switch (scclass) {
246 case VG_DARWIN_SYSCALL_CLASS_UNIX:
247 res._wLO = wLO;
248 res._wHI = wHI;
249 res._mode = isErr ? SysRes_UNIX_ERR : SysRes_UNIX_OK;
250 break;
251 case VG_DARWIN_SYSCALL_CLASS_MACH:
252 vg_assert(!isErr);
253 vg_assert(wHI == 0);
254 res._wLO = wLO;
255 res._mode = SysRes_MACH;
256 break;
257 case VG_DARWIN_SYSCALL_CLASS_MDEP:
258 vg_assert(!isErr);
259 vg_assert(wHI == 0);
260 res._wLO = wLO;
261 res._mode = SysRes_MDEP;
262 break;
263 default:
264 vg_assert(0);
266 return res;
269 SysRes VG_(mk_SysRes_amd64_darwin) ( UChar scclass, Bool isErr,
270 ULong wHI, ULong wLO )
272 SysRes res;
273 res._wHI = 0;
274 res._wLO = 0;
275 res._mode = 0; /* invalid */
276 vg_assert(isErr == False || isErr == True);
277 vg_assert(sizeof(UWord) == sizeof(ULong));
278 switch (scclass) {
279 case VG_DARWIN_SYSCALL_CLASS_UNIX:
280 res._wLO = wLO;
281 res._wHI = wHI;
282 res._mode = isErr ? SysRes_UNIX_ERR : SysRes_UNIX_OK;
283 break;
284 case VG_DARWIN_SYSCALL_CLASS_MACH:
285 vg_assert(!isErr);
286 vg_assert(wHI == 0);
287 res._wLO = wLO;
288 res._mode = SysRes_MACH;
289 break;
290 case VG_DARWIN_SYSCALL_CLASS_MDEP:
291 vg_assert(!isErr);
292 vg_assert(wHI == 0);
293 res._wLO = wLO;
294 res._mode = SysRes_MDEP;
295 break;
296 default:
297 vg_assert(0);
299 return res;
302 /* Generic constructors. We assume (without checking if this makes
303 any sense, from the caller's point of view) that these are for the
304 UNIX style of syscall. */
305 SysRes VG_(mk_SysRes_Error) ( UWord err ) {
306 SysRes r;
307 r._wHI = 0;
308 r._wLO = err;
309 r._mode = SysRes_UNIX_ERR;
310 return r;
313 SysRes VG_(mk_SysRes_Success) ( UWord res ) {
314 SysRes r;
315 r._wHI = 0;
316 r._wLO = res;
317 r._mode = SysRes_UNIX_OK;
318 return r;
322 #elif defined(VGO_solaris)
324 /* Generic constructors. */
325 SysRes VG_(mk_SysRes_Error) ( UWord err ) {
326 SysRes r;
327 r._val = err;
328 r._val2 = 0;
329 r._isError = True;
330 return r;
333 SysRes VG_(mk_SysRes_Success) ( UWord res ) {
334 SysRes r;
335 r._val = res;
336 r._val2 = 0;
337 r._isError = False;
338 return r;
341 SysRes VG_(mk_SysRes_x86_solaris) ( Bool isErr, UInt val, UInt val2 )
343 SysRes res;
345 // stay sane
346 vg_assert(isErr == True || isErr == False);
348 res._val = val;
349 res._val2 = val2;
350 res._isError = isErr;
351 return res;
354 SysRes VG_(mk_SysRes_amd64_solaris) ( Bool isErr, ULong val, ULong val2 )
356 SysRes res;
358 // stay sane
359 vg_assert(isErr == True || isErr == False);
361 res._val = val;
362 res._val2 = val2;
363 res._isError = isErr;
364 return res;
368 #elif defined(VGO_freebsd)
370 SysRes VG_(mk_SysRes_x86_freebsd) ( UInt val, UInt val2, Bool err ) {
371 SysRes r;
372 r._isError = err;
373 r._val = val;
374 r._val2 = val2;
375 return r;
378 SysRes VG_(mk_SysRes_amd64_freebsd) ( ULong val, ULong val2, Bool err ) {
379 SysRes r;
380 r._isError = err;
381 r._val = val;
382 r._val2 = val2;
383 return r;
386 SysRes VG_(mk_SysRes_arm64_freebsd) ( ULong val, ULong val2, Bool err ) {
387 SysRes r;
388 r._isError = err;
389 r._val = val;
390 r._val2 = val2;
391 return r;
394 /* Generic constructors. */
395 SysRes VG_(mk_SysRes_Error) ( UWord err ) {
396 SysRes r;
397 r._val = err;
398 r._val2 = 0;
399 r._isError = True;
400 return r;
403 SysRes VG_(mk_SysRes_Success) ( UWord res ) {
404 SysRes r;
405 r._val = res;
406 r._val2 = 0;
407 r._isError = False;
408 return r;
411 #else
412 # error "Unknown OS"
413 #endif
416 /* ---------------------------------------------------------------------
417 VG_(do_syscall): A function for doing syscalls.
418 ------------------------------------------------------------------ */
420 #if defined(VGP_x86_linux)
421 /* Incoming args (syscall number + up to 6 args) come on the stack.
422 (ie. the C calling convention).
424 The syscall number goes in %eax. The args are passed to the syscall in
425 the regs %ebx, %ecx, %edx, %esi, %edi, %ebp, ie. the kernel's syscall
426 calling convention.
428 %eax gets the return value. Not sure which registers the kernel
429 clobbers, so we preserve all the callee-save regs (%esi, %edi, %ebx,
430 %ebp).
432 extern UWord do_syscall_WRK (
433 UWord syscall_no,
434 UWord a1, UWord a2, UWord a3,
435 UWord a4, UWord a5, UWord a6
437 asm(
438 ".text\n"
439 ".globl do_syscall_WRK\n"
440 "do_syscall_WRK:\n"
441 " .cfi_startproc\n"
442 " push %esi\n"
443 " .cfi_adjust_cfa_offset 4\n"
444 " .cfi_offset %esi, -8\n"
445 " push %edi\n"
446 " .cfi_adjust_cfa_offset 4\n"
447 " .cfi_offset %edi, -12\n"
448 " push %ebx\n"
449 " .cfi_adjust_cfa_offset 4\n"
450 " .cfi_offset %ebx, -16\n"
451 " push %ebp\n"
452 " .cfi_adjust_cfa_offset 4\n"
453 " .cfi_offset %ebp, -20\n"
454 " movl 16+ 4(%esp),%eax\n"
455 " movl 16+ 8(%esp),%ebx\n"
456 " movl 16+12(%esp),%ecx\n"
457 " movl 16+16(%esp),%edx\n"
458 " movl 16+20(%esp),%esi\n"
459 " movl 16+24(%esp),%edi\n"
460 " movl 16+28(%esp),%ebp\n"
461 " int $0x80\n"
462 " popl %ebp\n"
463 " .cfi_adjust_cfa_offset -4\n"
464 " .cfi_restore %ebp\n"
465 " popl %ebx\n"
466 " .cfi_adjust_cfa_offset -4\n"
467 " .cfi_restore %ebx\n"
468 " popl %edi\n"
469 " .cfi_adjust_cfa_offset -4\n"
470 " .cfi_restore %edi\n"
471 " popl %esi\n"
472 " .cfi_adjust_cfa_offset -4\n"
473 " .cfi_restore %esi\n"
474 " ret\n"
475 " .cfi_endproc\n"
476 ".previous\n"
479 #elif defined(VGP_amd64_linux)
480 /* Incoming args (syscall number + up to 6 args) come in %rdi, %rsi,
481 %rdx, %rcx, %r8, %r9, and the last one on the stack (ie. the C
482 calling convention).
484 The syscall number goes in %rax. The args are passed to the syscall in
485 the regs %rdi, %rsi, %rdx, %r10, %r8, %r9 (yes, really %r10, not %rcx),
486 ie. the kernel's syscall calling convention.
488 %rax gets the return value. %rcx and %r11 are clobbered by the syscall;
489 no matter, they are caller-save (the syscall clobbers no callee-save
490 regs, so we don't have to do any register saving/restoring).
492 extern UWord do_syscall_WRK (
493 UWord syscall_no,
494 UWord a1, UWord a2, UWord a3,
495 UWord a4, UWord a5, UWord a6
497 asm(
498 ".text\n"
499 ".globl do_syscall_WRK\n"
500 "do_syscall_WRK:\n"
501 /* Convert function calling convention --> syscall calling
502 convention */
503 " movq %rdi, %rax\n"
504 " movq %rsi, %rdi\n"
505 " movq %rdx, %rsi\n"
506 " movq %rcx, %rdx\n"
507 " movq %r8, %r10\n"
508 " movq %r9, %r8\n"
509 " movq 8(%rsp), %r9\n" /* last arg from stack */
510 " syscall\n"
511 " ret\n"
512 ".previous\n"
515 #elif defined(VGP_ppc32_linux)
516 /* Incoming args (syscall number + up to 6 args) come in %r3:%r9.
518 The syscall number goes in %r0. The args are passed to the syscall in
519 the regs %r3:%r8, i.e. the kernel's syscall calling convention.
521 The %cr0.so bit flags an error.
522 We return the syscall return value in %r3, and the %cr0.so in
523 the lowest bit of %r4.
524 We return a ULong, of which %r3 is the high word, and %r4 the low.
525 No callee-save regs are clobbered, so no saving/restoring is needed.
527 extern ULong do_syscall_WRK (
528 UWord syscall_no,
529 UWord a1, UWord a2, UWord a3,
530 UWord a4, UWord a5, UWord a6
532 asm(
533 ".text\n"
534 ".globl do_syscall_WRK\n"
535 "do_syscall_WRK:\n"
536 " mr 0,3\n"
537 " mr 3,4\n"
538 " mr 4,5\n"
539 " mr 5,6\n"
540 " mr 6,7\n"
541 " mr 7,8\n"
542 " mr 8,9\n"
543 " sc\n" /* syscall: sets %cr0.so on error */
544 " mfcr 4\n" /* %cr -> low word of return var */
545 " rlwinm 4,4,4,31,31\n" /* rotate flag bit so to lsb, and mask it */
546 " blr\n" /* and return */
547 ".previous\n"
550 #elif defined(VGP_ppc64be_linux)
551 /* Due to the need to return 65 bits of result, this is completely
552 different from the ppc32 case. The single arg register points to a
553 7-word block containing the syscall # and the 6 args. The syscall
554 result proper is put in [0] of the block, and %cr0.so is in the
555 bottom bit of [1]. */
556 extern void do_syscall_WRK ( ULong* argblock );
557 asm(
558 ".align 2\n"
559 ".globl do_syscall_WRK\n"
560 ".section \".opd\",\"aw\"\n"
561 ".align 3\n"
562 "do_syscall_WRK:\n"
563 ".quad .do_syscall_WRK,.TOC.@tocbase,0\n"
564 ".previous\n"
565 ".type .do_syscall_WRK,@function\n"
566 ".globl .do_syscall_WRK\n"
567 ".do_syscall_WRK:\n"
568 " std 3,-16(1)\n" /* stash arg */
569 " ld 8, 48(3)\n" /* sc arg 6 */
570 " ld 7, 40(3)\n" /* sc arg 5 */
571 " ld 6, 32(3)\n" /* sc arg 4 */
572 " ld 5, 24(3)\n" /* sc arg 3 */
573 " ld 4, 16(3)\n" /* sc arg 2 */
574 " ld 0, 0(3)\n" /* sc number */
575 " ld 3, 8(3)\n" /* sc arg 1 */
576 " sc\n" /* result in r3 and cr0.so */
577 " ld 5,-16(1)\n" /* reacquire argblock ptr (r5 is caller-save) */
578 " std 3,0(5)\n" /* argblock[0] = r3 */
579 " mfcr 3\n"
580 " srwi 3,3,28\n"
581 " andi. 3,3,1\n"
582 " std 3,8(5)\n" /* argblock[1] = cr0.s0 & 1 */
583 " blr\n"
586 #elif defined(VGP_ppc64le_linux)
587 /* Due to the need to return 65 bits of result, this is completely
588 different from the ppc32 case. The single arg register points to a
589 7-word block containing the syscall # and the 6 args. The syscall
590 result proper is put in [0] of the block, and %cr0.so is in the
591 bottom bit of [1]. */
592 extern void do_syscall_WRK ( ULong* argblock );
593 /* Little Endian supports ELF version 2. In the future, it may support
594 * other versions as well.
596 asm(
597 ".align 2\n"
598 ".globl do_syscall_WRK\n"
599 ".type do_syscall_WRK,@function\n"
600 "do_syscall_WRK:\n"
601 "#if _CALL_ELF == 2" "\n"
602 "0: addis 2,12,.TOC.-0b@ha\n"
603 " addi 2,2,.TOC.-0b@l\n"
604 " .localentry do_syscall_WRK, .-do_syscall_WRK\n"
605 "#endif" "\n"
606 /* Check which system call instruction to issue*/
607 " ld 8, 56(3)\n" /* arg 7 holds sc/scv flag */
608 " cmpdi 8,1\n" /* check sc/scv flag not equal to SC_FLAG*/
609 " bne issue_scv\n"
611 /* setup and issue the sc instruction */
612 " std 3,-16(1)\n" /* stash arg */
613 " ld 8, 48(3)\n" /* sc arg 6 */
614 " ld 7, 40(3)\n" /* sc arg 5 */
615 " ld 6, 32(3)\n" /* sc arg 4 */
616 " ld 5, 24(3)\n" /* sc arg 3 */
617 " ld 4, 16(3)\n" /* sc arg 2 */
618 " ld 0, 0(3)\n" /* sc number */
619 " ld 3, 8(3)\n" /* sc arg 1 */
620 " sc\n" /* result in r3 and cr0.so */
621 " ld 5,-16(1)\n" /* reacquire argblock ptr (r5 is caller-save) */
622 " std 3,0(5)\n" /* argblock[0] = r3 */
623 " mfcr 3\n"
624 " srwi 3,3,28\n"
625 " andi. 3,3,1\n"
626 " std 3,8(5)\n" /* argblock[1] = cr0.s0 & 1 */
627 " blr\n" /* return */
629 /* setup to do scv instruction */
630 "issue_scv: "
631 /* The scv instruction requires a new stack frame */
632 " stdu 1,-80(1)\n"
633 " std 27,40(1)\n" /* save r27 to stack frame */
634 " mflr 27\n" /* Get link register */
635 " std 27,16(1)\n" /* Save link register */
637 /* setup and issue the scv instruction */
638 " std 3,-16(1)\n" /* stash arg */
639 " ld 8, 48(3)\n" /* sc arg 6 */
640 " ld 7, 40(3)\n" /* sc arg 5 */
641 " ld 6, 32(3)\n" /* sc arg 4 */
642 " ld 5, 24(3)\n" /* sc arg 3 */
643 " ld 4, 16(3)\n" /* sc arg 2 */
644 " ld 0, 0(3)\n" /* sc number */
645 " ld 3, 8(3)\n" /* sc arg 1 */
647 " .machine push\n"
648 " .machine \"power9\"\n"
649 " scv 0\n"
650 " .machine pop\n"
651 " ld 5,-16(1)\n" /* reacquire argblock ptr (r5 is caller-save) */
652 " std 3,0(5)\n" /* argblock[0] = r3 */
654 /* pop off stack frame */
655 " ld 27,16(1)\n" /* Fetch LR from frame */
656 " mtlr 27\n" /* restore LR */
657 " ld 27,40(1)\n" /* restore r27 from stack frame */
658 " addi 1,1,80\n"
659 " blr\n"
660 " .size do_syscall_WRK, .-do_syscall_WRK\n"
663 #elif defined(VGP_arm_linux)
664 /* I think the conventions are:
665 args in r0 r1 r2 r3 r4 r5
666 sysno in r7
667 return value in r0, w/ same conventions as x86-linux, viz r0 in
668 -4096 .. -1 is an error value. All other values are success
669 values.
671 extern UWord do_syscall_WRK (
672 UWord a1, UWord a2, UWord a3,
673 UWord a4, UWord a5, UWord a6,
674 UWord syscall_no
676 asm(
677 ".text\n"
678 ".globl do_syscall_WRK\n"
679 "do_syscall_WRK:\n"
680 " push {r4, r5, r7}\n"
681 " ldr r4, [sp, #12]\n"
682 " ldr r5, [sp, #16]\n"
683 " ldr r7, [sp, #20]\n"
684 " svc 0x0\n"
685 " pop {r4, r5, r7}\n"
686 " bx lr\n"
687 ".previous\n"
690 #elif defined(VGP_arm64_linux)
691 /* I think the conventions are:
692 args in r0 r1 r2 r3 r4 r5
693 sysno in r8
694 return value in r0, w/ same conventions as x86-linux, viz r0 in
695 -4096 .. -1 is an error value. All other values are success
696 values.
698 r0 to r5 remain unchanged, but syscall_no is in r6 and needs
699 to be moved to r8 (??)
701 extern UWord do_syscall_WRK (
702 UWord a1, UWord a2, UWord a3,
703 UWord a4, UWord a5, UWord a6,
704 UWord syscall_no
706 asm(
707 ".text\n"
708 ".globl do_syscall_WRK\n"
709 "do_syscall_WRK:\n"
710 " mov x8, x6\n"
711 " mov x6, 0\n"
712 " mov x7, 0\n"
713 " svc 0\n"
714 " ret\n"
715 ".previous\n"
718 #elif defined(VGP_x86_freebsd)
719 /* Incoming args (syscall number + up to 8 args) are on the stack.
720 FreeBSD has a syscall called 'syscall' that takes all args (including
721 the syscall number) off the stack. Since we're called, the return
722 address is on the stack as expected, so we can just call syscall(2)
723 and it Just Works. Error is when carry is set.
725 extern ULong do_syscall_WRK (
726 UWord syscall_no,
727 UWord a1, UWord a2, UWord a3,
728 UWord a4, UWord a5, UWord a6,
729 UWord a7, UWord a8, UInt *flags
731 asm(
732 ".text\n"
733 "do_syscall_WRK:\n"
734 " movl $0,%eax\n" /* syscall number = "syscall" (0) to avoid stack frobbing
736 " int $0x80\n"
737 " jb 1f\n"
738 " ret\n"
739 "1: movl 40(%esp),%ecx\n" /* store carry in *flags */
740 " movl $1,(%ecx)\n"
741 " ret\n"
742 ".previous\n"
745 #elif defined(VGP_amd64_freebsd)
746 /* Convert function calling convention --> SYSCALL_STD calling
747 convention
748 PJF - not sure why we don't use SYSCALL0 convention like x86
750 extern UWord do_syscall_WRK (
751 UWord syscall_no, /* %rdi */
752 UWord a1, /* %rsi */
753 UWord a2, /* %rdx */
754 UWord a3, /* %rcx */
755 UWord a4, /* %r8 */
756 UWord a5, /* %r9 */
757 UWord a6, /* 8(%rsp) */
758 UWord a7, /* 16(%rsp) */
759 UWord a8, /* 24(%rsp) */
760 UInt *flags, /* 32(%rsp) */
761 UWord *rv2 /* 40(%rsp) */
763 asm(
764 ".text\n"
765 "do_syscall_WRK:\n"
766 " pushq %rbp\n"
767 " movq %rsp, %rbp\n"
768 " movq %rdi, %rax\n" /* syscall_no */
769 " movq %rsi, %rdi\n" /* a1 */
770 " movq %rdx, %rsi\n" /* a2 */
771 " movq %rcx, %rdx\n" /* a3 */
772 " movq %r8, %r10\n" /* a4 */
773 " movq %r9, %r8\n" /* a5 */
774 " movq 16(%rbp), %r9\n" /* a6 last arg from stack, account for %rbp */
775 " movq 24(%rbp), %r11\n" /* a7 from stack */
776 " pushq %r11\n"
777 " movq 32(%rbp), %r11\n" /* a8 from stack */
778 " pushq %r11\n"
779 " subq $8,%rsp\n" /* fake return addr */
780 " syscall\n"
781 " jb 1f\n"
782 " movq 48(%rbp),%rsi\n" /* success */
783 " movq %rdx, (%rsi)\n" /* second return value */
784 " movq %rbp, %rsp\n"
785 " popq %rbp\n"
786 " ret\n"
787 "1:\n" /* error path */
788 " movq 40(%rbp), %rsi\n" /* flags */
789 " movl $1,(%rsi)\n"
790 " movq %rbp, %rsp\n"
791 " popq %rbp\n"
792 " ret\n"
793 ".previous\n"
796 #elif defined(VGP_arm64_freebsd)
799 * Arguments a1 to a8 are in registers x0 to x7.
800 * Which is just what we want for a syscall.
802 * The syscall number is on the top of the stack
803 * pointed to by sp. The flags are at sp+8 and
804 * second return value at sp+16.
807 extern UWord do_syscall_WRK (
808 UWord a1, UWord a2, UWord a3,
809 UWord a4, UWord a5, UWord a6,
810 UWord a7, UWord a8,
811 UWord syscall_no,
812 UInt *flags, UWord *rv2
814 asm(
815 ".text\n"
816 ".globl do_syscall_WRK\n"
817 "do_syscall_WRK:\n"
818 " ldr x8, [sp]\n" // retrieve syscall_no, put it in x8
819 " svc 0x0\n" // do the syscall
820 " mov x9, 1\n" // flags for error will be 1 or 0
821 " csel x9, x9, xzr, cs\n" // conditionally select 1 or 0 into x9
822 " ldr x10, [sp, #8]\n" // load the address of flags
823 " str w9, [x10]\n" // store flags result
824 " ldr x10, [sp, #16]\n" // load the addres of rv2
825 " str x1, [x10]\n" // store rv2 result
826 " ret\n"
827 ".previous\n"
830 #elif defined(VGP_x86_darwin)
832 /* Incoming args (syscall number + up to 8 args) come in on the stack
834 The kernel's syscall calling convention is:
835 * the syscall number goes in eax
836 * the args are passed to the syscall on the stack,
837 pushed onto the stack R->L (that is, the usual x86
838 calling conventions, with the leftmost arg at the lowest
839 address)
840 Call instruction:
841 * UNIX: sysenter
842 * UNIX: int $0x80
843 * MACH: int $0x81
844 * MDEP: int $0x82
845 Note that the call type can be determined from the syscall number;
846 there is no need to inspect the actual instruction. Although obviously
847 the instruction must match.
848 Return value:
849 * MACH,MDEP: the return value comes back in eax
850 * UNIX: the return value comes back in edx:eax (hi32:lo32)
851 Error:
852 * MACH,MDEP: no error is returned
853 * UNIX: the carry flag indicates success or failure
855 nb here, sizeof(UWord) == sizeof(UInt)
858 __private_extern__ ULong
859 do_syscall_unix_WRK ( UWord a1, UWord a2, UWord a3, /* 4(esp)..12(esp) */
860 UWord a4, UWord a5, UWord a6, /* 16(esp)..24(esp) */
861 UWord a7, UWord a8, /* 28(esp)..32(esp) */
862 UWord syscall_no, /* 36(esp) */
863 /*OUT*/UInt* errflag /* 40(esp) */ );
864 // Unix syscall: 64-bit return in edx:eax, with LSB in eax
865 // error indicated by carry flag: clear=good, set=bad
866 asm(".private_extern _do_syscall_unix_WRK\n"
867 "_do_syscall_unix_WRK:\n"
868 " movl 40(%esp), %ecx \n" /* assume syscall success */
869 " movl $0, (%ecx) \n"
870 " movl 36(%esp), %eax \n"
871 " int $0x80 \n"
872 " jnc 1f \n" /* jump if success */
873 " movl 40(%esp), %ecx \n" /* syscall failed - set *errflag */
874 " movl $1, (%ecx) \n"
875 " 1: ret \n"
878 __private_extern__ UInt
879 do_syscall_mach_WRK ( UWord a1, UWord a2, UWord a3, /* 4(esp)..12(esp) */
880 UWord a4, UWord a5, UWord a6, /* 16(esp)..24(esp) */
881 UWord a7, UWord a8, /* 28(esp)..32(esp) */
882 UWord syscall_no /* 36(esp) */ );
883 // Mach trap: 32-bit result in %eax, no error flag
884 asm(".private_extern _do_syscall_mach_WRK\n"
885 "_do_syscall_mach_WRK:\n"
886 " movl 36(%esp), %eax \n"
887 " int $0x81 \n"
888 " ret \n"
891 __private_extern__ UInt
892 do_syscall_mdep_WRK ( UWord a1, UWord a2, UWord a3, /* 4(esp)..12(esp) */
893 UWord a4, UWord a5, UWord a6, /* 16(esp)..24(esp) */
894 UWord a7, UWord a8, /* 28(esp)..32(esp) */
895 UWord syscall_no /* 36(esp) */ );
896 // mdep trap: 32-bit result in %eax, no error flag
897 asm(
898 ".private_extern _do_syscall_mdep_WRK\n"
899 "_do_syscall_mdep_WRK:\n"
900 " movl 36(%esp), %eax \n"
901 " int $0x82 \n"
902 " ret \n"
906 #elif defined(VGP_amd64_darwin)
908 /* Incoming args (syscall number + up to 8 args) come in registers and stack
910 The kernel's syscall calling convention is:
911 * the syscall number goes in rax
912 * the args are passed to the syscall in registers and the stack
913 * the call instruction is 'syscall'
914 Return value:
915 * MACH,MDEP: the return value comes back in rax
916 * UNIX: the return value comes back in rdx:rax (hi64:lo64)
917 Error:
918 * MACH,MDEP: no error is returned
919 * UNIX: the carry flag indicates success or failure
921 nb here, sizeof(UWord) == sizeof(ULong)
924 __private_extern__ UWord
925 do_syscall_unix_WRK ( UWord a1, UWord a2, UWord a3, /* rdi, rsi, rdx */
926 UWord a4, UWord a5, UWord a6, /* rcx, r8, r9 */
927 UWord a7, UWord a8, /* 8(rsp), 16(rsp) */
928 UWord syscall_no, /* 24(rsp) */
929 /*OUT*/ULong* errflag, /* 32(rsp) */
930 /*OUT*/ULong* res2 ); /* 40(rsp) */
931 // Unix syscall: 128-bit return in rax:rdx, with LSB in rax
932 // error indicated by carry flag: clear=good, set=bad
933 asm(".private_extern _do_syscall_unix_WRK\n"
934 "_do_syscall_unix_WRK:\n"
935 " movq %rcx, %r10 \n" /* pass rcx in r10 instead */
936 " movq 32(%rsp), %rax \n" /* assume syscall success */
937 " movq $0, (%rax) \n"
938 " movq 24(%rsp), %rax \n" /* load syscall_no */
939 " syscall \n"
940 " jnc 1f \n" /* jump if success */
941 " movq 32(%rsp), %rcx \n" /* syscall failed - set *errflag */
942 " movq $1, (%rcx) \n"
943 " 1: movq 40(%rsp), %rcx \n" /* save 2nd result word */
944 " movq %rdx, (%rcx) \n"
945 " retq \n" /* return 1st result word */
948 __private_extern__ UWord
949 do_syscall_mach_WRK ( UWord a1, UWord a2, UWord a3, /* rdi, rsi, rdx */
950 UWord a4, UWord a5, UWord a6, /* rcx, r8, r9 */
951 UWord a7, UWord a8, /* 8(rsp), 16(rsp) */
952 UWord syscall_no ); /* 24(rsp) */
953 // Mach trap: 64-bit result, no error flag
954 asm(".private_extern _do_syscall_mach_WRK\n"
955 "_do_syscall_mach_WRK:\n"
956 " movq %rcx, %r10 \n" /* pass rcx in r10 instead */
957 " movq 24(%rsp), %rax \n" /* load syscall_no */
958 " syscall \n"
959 " retq \n"
962 #elif defined(VGP_s390x_linux)
964 static UWord do_syscall_WRK (
965 UWord syscall_no,
966 UWord arg1, UWord arg2, UWord arg3,
967 UWord arg4, UWord arg5, UWord arg6
970 register UWord __arg1 asm("2") = arg1;
971 register UWord __arg2 asm("3") = arg2;
972 register UWord __arg3 asm("4") = arg3;
973 register UWord __arg4 asm("5") = arg4;
974 register UWord __arg5 asm("6") = arg5;
975 register UWord __arg6 asm("7") = arg6;
976 register ULong __svcres asm("2");
978 __asm__ __volatile__ (
979 "lgr %%r1,%1\n\t"
980 "svc 0\n\t"
981 : "=d" (__svcres)
982 : "a" (syscall_no),
983 "0" (__arg1),
984 "d" (__arg2),
985 "d" (__arg3),
986 "d" (__arg4),
987 "d" (__arg5),
988 "d" (__arg6)
989 : "1", "cc", "memory");
991 return (UWord) (__svcres);
994 #elif defined(VGP_mips32_linux)
995 /* Incoming args (syscall number + up to 6 args) come in a0 - a3 and stack.
997 The syscall number goes in v0. The args are passed to the syscall in
998 the regs a0 - a3 and stack, i.e. the kernel's syscall calling convention.
1000 (a3 != 0) flags an error.
1001 We return the syscall return value in v0.
1002 MIPS version
1004 extern int do_syscall_WRK (
1005 int a1, int a2, int a3,
1006 int a4, int a5, int a6, int a7, int syscall_no, UWord *err,
1007 UWord *valHi, UWord* valLo
1009 asm (
1010 ".text \n\t"
1011 ".globl do_syscall_WRK \n\t"
1012 ".type do_syscall_WRK, @function \n\t"
1013 ".set push \n\t"
1014 ".set noreorder \n\t"
1015 "do_syscall_WRK: \n\t"
1016 " lw $2, 28($29) \n\t"
1017 " syscall \n\t"
1018 " lw $8, 32($29) \n\t"
1019 " sw $7, ($8) \n\t"
1020 " lw $8, 36($29) \n\t"
1021 " sw $3, ($8) \n\t" /* store valHi */
1022 " lw $8, 40($29) \n\t"
1023 " jr $31 \n\t"
1024 " sw $2, ($8) \n\t" /* store valLo */
1025 ".size do_syscall_WRK, .-do_syscall_WRK \n\t"
1026 ".set pop \n\t"
1027 ".previous \n\t"
1030 #elif defined(VGP_mips64_linux)
1031 extern RegWord do_syscall_WRK ( RegWord a1, RegWord a2, RegWord a3, RegWord a4,
1032 RegWord a5, RegWord a6, RegWord a7, RegWord syscall_no,
1033 RegWord* V1_A3_val );
1034 asm (
1035 ".text \n\t"
1036 ".globl do_syscall_WRK \n\t"
1037 ".type do_syscall_WRK, @function \n\t"
1038 ".set push \n\t"
1039 ".set noreorder \n\t"
1040 "do_syscall_WRK: \n\t"
1041 " move $2, $11 \n\t"
1042 " syscall \n\t"
1043 # if defined(_ABI64)
1044 " ld $12, 0($29) \n\t"
1045 # elif defined(_ABIN32)
1046 " lw $12, 0($29) \n\t"
1047 # endif
1048 " sd $3, 0($12) \n\t" /* store v1 in V1_A3_val */
1049 " jr $31 \n\t"
1050 " sd $7, 8($12) \n\t" /* store a3 in V1_A3_val */
1051 ".size do_syscall_WRK, .-do_syscall_WRK \n\t"
1052 ".set pop \n\t"
1053 ".previous \n\t"
1056 #elif defined(VGP_nanomips_linux)
1057 extern void do_syscall_WRK (
1058 RegWord a1, RegWord a2, RegWord a3,
1059 RegWord a4, RegWord a5, RegWord a6,
1060 RegWord syscall_no, RegWord *res_a0);
1061 asm (
1062 ".text \n\t"
1063 ".globl do_syscall_WRK \n\t"
1064 ".type do_syscall_WRK, @function \n\t"
1065 ".set push \n\t"
1066 ".set noreorder \n\t"
1067 "do_syscall_WRK: \n\t"
1068 " save 32, $a7 \n\t"
1069 " move $t4, $a6 \n\t"
1070 " syscall[32] \n\t"
1071 " restore 32, $a7 \n\t"
1072 " sw $a0, 0($a7) \n\t"
1073 " jrc $ra \n\t"
1074 ".size do_syscall_WRK, .-do_syscall_WRK \n\t"
1075 ".set pop \n\t"
1076 ".previous \n\t"
1079 #elif defined(VGP_x86_solaris)
1081 extern ULong
1082 do_syscall_WRK(UWord a1, UWord a2, UWord a3, /* 4(esp)..12(esp) */
1083 UWord a4, UWord a5, UWord a6, /* 16(esp)..24(esp) */
1084 UWord a7, UWord a8, /* 28(esp)..32(esp) */
1085 UWord syscall_no, /* 36(esp) */
1086 /*OUT*/UInt *errflag); /* 40(esp) */
1087 /* Classic unix syscall.. parameters on the stack, an unused (by the kernel)
1088 return address at 0(esp), a sysno in eax, a result in edx:eax, the carry
1089 flag set on error. */
1090 __asm__ (
1091 ".text\n"
1092 ".globl do_syscall_WRK\n"
1093 "do_syscall_WRK:\n"
1094 " movl 40(%esp), %ecx\n" /* assume syscall success */
1095 " movl $0, (%ecx)\n"
1096 " movl 36(%esp), %eax\n"
1097 " int $0x91\n"
1098 " jnc 1f\n" /* jump if success */
1099 " movl 40(%esp), %ecx\n" /* syscall failed - set *errflag */
1100 " movl $1, (%ecx)\n"
1101 "1: ret\n"
1102 ".previous\n"
1105 extern ULong
1106 do_syscall_fast_WRK(UWord syscall_no); /* 4(esp) */
1107 /* Fasttrap syscall.. no parameters, a sysno in eax, a result in edx:eax,
1108 never fails (if the sysno is valid). */
1109 __asm__ (
1110 ".text\n"
1111 ".globl do_syscall_fast_WRK\n"
1112 "do_syscall_fast_WRK:\n"
1113 " movl 4(%esp), %eax\n"
1114 " int $0xD2\n"
1115 " ret\n"
1116 ".previous\n"
1119 #elif defined(VGP_amd64_solaris)
1121 extern ULong
1122 do_syscall_WRK(UWord a1, UWord a2, UWord a3, /* rdi, rsi, rdx */
1123 UWord a4, UWord a5, UWord a6, /* rcx, r8, r9 */
1124 UWord a7, UWord a8, /* 8(rsp), 16(rsp) */
1125 UWord syscall_no, /* 24(rsp) */
1126 /*OUT*/ULong *errflag, /* 32(rsp) */
1127 /*OUT*/ULong *res2); /* 40(rsp) */
1128 /* First 6 parameters in registers rdi, rsi, rdx, r10, r8, r9, next
1129 2 parameters on the stack, an unused (by the kernel) return address at
1130 0(rsp), a sysno in rax, a result in rdx:rax, the carry flag set on
1131 error. */
1132 __asm__ (
1133 ".text\n"
1134 ".globl do_syscall_WRK\n"
1135 "do_syscall_WRK:\n"
1136 " movq %rcx, %r10\n" /* pass rcx in r10 instead */
1137 " movq 32(%rsp), %rcx\n" /* assume syscall success */
1138 " movq $0, (%rcx)\n"
1139 " movq 24(%rsp), %rax\n"
1140 " syscall\n"
1141 " jnc 1f\n" /* jump if success */
1142 " movq 32(%rsp), %rcx\n" /* syscall failed - set *errflag */
1143 " movq $1, (%rcx)\n"
1144 "1: movq 40(%rsp), %rcx\n" /* save 2nd result word */
1145 " movq %rdx, (%rcx)\n"
1146 " ret\n"
1147 ".previous\n"
1150 extern ULong
1151 do_syscall_fast_WRK(UWord syscall_no, /* rdi */
1152 /*OUT*/ULong *res2); /* rsi */
1153 /* Fasttrap syscall.. no parameters, a sysno in rax, a result in rdx:rax,
1154 never fails (if the sysno is valid). */
1155 __asm__ (
1156 ".text\n"
1157 ".globl do_syscall_fast_WRK\n"
1158 "do_syscall_fast_WRK:\n"
1159 " movq %rdi, %rax\n"
1160 " int $0xD2\n"
1161 " movq %rdx, (%rsi)\n" /* save 2nd result word */
1162 " ret\n"
1163 ".previous\n"
1166 #else
1167 # error Unknown platform
1168 #endif
1171 /* Finally, the generic code. This sends the call to the right
1172 helper. */
1174 SysRes VG_(do_syscall) ( UWord sysno, RegWord a1, RegWord a2, RegWord a3,
1175 RegWord a4, RegWord a5, RegWord a6,
1176 RegWord a7, RegWord a8 )
1178 # if defined(VGP_x86_linux)
1179 UWord val = do_syscall_WRK(sysno,a1,a2,a3,a4,a5,a6);
1180 return VG_(mk_SysRes_x86_linux)( val );
1182 # elif defined(VGP_amd64_linux)
1183 UWord val = do_syscall_WRK(sysno,a1,a2,a3,a4,a5,a6);
1184 return VG_(mk_SysRes_amd64_linux)( val );
1186 # elif defined(VGP_x86_freebsd)
1187 ULong val;
1188 UInt err = 0;
1189 val = do_syscall_WRK(sysno, a1, a2, a3, a4, a5,
1190 a6, a7, a8, &err);
1191 return VG_(mk_SysRes_x86_freebsd)( (UInt)val, (UInt)(val>>32), (err & 1) != 0 ? True : False);
1193 # elif defined(VGP_amd64_freebsd)
1194 UWord val;
1195 UWord val2 = 0;
1196 UInt err = 0;
1197 val = do_syscall_WRK(sysno, a1, a2, a3, a4, a5,
1198 a6, a7, a8, &err, &val2);
1199 return VG_(mk_SysRes_amd64_freebsd)( val, val2, (err & 1) != 0 ? True : False);
1201 # elif defined(VGP_arm64_freebsd)
1202 UWord val;
1203 UWord val2 = 0;
1204 UInt err = 0;
1205 val = do_syscall_WRK(a1, a2, a3, a4, a5,
1206 a6, a7, a8, sysno, &err, &val2);
1207 return VG_(mk_SysRes_arm64_freebsd)( val, val2, (err & 1) != 0 ? True : False);
1209 # elif defined(VGP_ppc32_linux)
1210 ULong ret = do_syscall_WRK(sysno,a1,a2,a3,a4,a5,a6);
1211 UInt val = (UInt)(ret>>32);
1212 UInt cr0so = (UInt)(ret);
1213 return VG_(mk_SysRes_ppc32_linux)( val, cr0so );
1215 # elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
1216 ULong argblock[8];
1217 /* PPC system calls have at most 6 arguments. The Valgrind infrastructure
1218 supports 8 system call arguments. Argument 7 is used on PPC LE to pass
1219 the flag indicating if the sc or scv instruction should be used for the
1220 system call. */
1221 argblock[0] = sysno;
1222 argblock[1] = a1;
1223 argblock[2] = a2;
1224 argblock[3] = a3;
1225 argblock[4] = a4;
1226 argblock[5] = a5;
1227 argblock[6] = a6;
1228 argblock[7] = a7;
1229 do_syscall_WRK( &argblock[0] );
1230 return VG_(mk_SysRes_ppc64_linux)( argblock[0], argblock[1], a7 );
1232 # elif defined(VGP_arm_linux)
1233 UWord val = do_syscall_WRK(a1,a2,a3,a4,a5,a6,sysno);
1234 return VG_(mk_SysRes_arm_linux)( val );
1236 # elif defined(VGP_arm64_linux)
1237 UWord val = do_syscall_WRK(a1,a2,a3,a4,a5,a6,sysno);
1238 return VG_(mk_SysRes_arm64_linux)( val );
1240 # elif defined(VGP_x86_darwin)
1241 UInt wLO = 0, wHI = 0, err = 0;
1242 ULong u64;
1243 UChar scclass = VG_DARWIN_SYSNO_CLASS(sysno);
1244 switch (scclass) {
1245 case VG_DARWIN_SYSCALL_CLASS_UNIX:
1246 u64 = do_syscall_unix_WRK(a1,a2,a3,a4,a5,a6,a7,a8,
1247 VG_DARWIN_SYSNO_FOR_KERNEL(sysno), &err);
1248 wLO = (UInt)u64;
1249 wHI = (UInt)(u64 >> 32);
1250 break;
1251 case VG_DARWIN_SYSCALL_CLASS_MACH:
1252 wLO = do_syscall_mach_WRK(a1,a2,a3,a4,a5,a6,a7,a8,
1253 VG_DARWIN_SYSNO_FOR_KERNEL(sysno));
1254 err = 0;
1255 break;
1256 case VG_DARWIN_SYSCALL_CLASS_MDEP:
1257 wLO = do_syscall_mdep_WRK(a1,a2,a3,a4,a5,a6,a7,a8,
1258 VG_DARWIN_SYSNO_FOR_KERNEL(sysno));
1259 err = 0;
1260 break;
1261 default:
1262 vg_assert(0);
1263 break;
1265 return VG_(mk_SysRes_x86_darwin)( scclass, err ? True : False, wHI, wLO );
1267 # elif defined(VGP_amd64_darwin)
1268 ULong wLO = 0, wHI = 0, err = 0;
1269 UChar scclass = VG_DARWIN_SYSNO_CLASS(sysno);
1270 switch (scclass) {
1271 case VG_DARWIN_SYSCALL_CLASS_UNIX:
1272 wLO = do_syscall_unix_WRK(a1,a2,a3,a4,a5,a6,a7,a8,
1273 VG_DARWIN_SYSNO_FOR_KERNEL(sysno), &err, &wHI);
1274 break;
1275 case VG_DARWIN_SYSCALL_CLASS_MACH:
1276 case VG_DARWIN_SYSCALL_CLASS_MDEP:
1277 wLO = do_syscall_mach_WRK(a1,a2,a3,a4,a5,a6,a7,a8,
1278 VG_DARWIN_SYSNO_FOR_KERNEL(sysno));
1279 err = 0;
1280 break;
1281 default:
1282 vg_assert(0);
1283 break;
1285 return VG_(mk_SysRes_amd64_darwin)( scclass, err ? True : False, wHI, wLO );
1287 #elif defined(VGP_s390x_linux)
1288 UWord val;
1290 if (sysno == __NR_mmap) {
1291 ULong argbuf[6];
1293 argbuf[0] = a1;
1294 argbuf[1] = a2;
1295 argbuf[2] = a3;
1296 argbuf[3] = a4;
1297 argbuf[4] = a5;
1298 argbuf[5] = a6;
1299 val = do_syscall_WRK(sysno,(UWord)&argbuf[0],0,0,0,0,0);
1300 } else {
1301 val = do_syscall_WRK(sysno,a1,a2,a3,a4,a5,a6);
1304 return VG_(mk_SysRes_s390x_linux)( val );
1306 #elif defined(VGP_mips32_linux)
1307 UWord err = 0;
1308 UWord valHi = 0;
1309 UWord valLo = 0;
1310 (void) do_syscall_WRK(a1, a2, a3, a4, a5, a6, a7, sysno, &err, &valHi, &valLo);
1311 return VG_(mk_SysRes_mips32_linux)( valLo, valHi, (ULong)err );
1313 #elif defined(VGP_mips64_linux)
1314 RegWord v1_a3[2];
1315 v1_a3[0] = 0xFF00;
1316 v1_a3[1] = 0xFF00;
1317 RegWord V0 = do_syscall_WRK(a1, a2, a3, a4, a5, a6, a7, sysno, v1_a3);
1318 RegWord V1 = (RegWord)v1_a3[0];
1319 RegWord A3 = (RegWord)v1_a3[1];
1320 return VG_(mk_SysRes_mips64_linux)( V0, V1, A3 );
1322 #elif defined(VGP_nanomips_linux)
1323 RegWord reg_a0 = 0;
1324 do_syscall_WRK(a1, a2, a3, a4, a5, a6, sysno, &reg_a0);
1325 return VG_(mk_SysRes_nanomips_linux)(reg_a0);
1327 # elif defined(VGP_x86_solaris)
1328 UInt val, val2, err = False;
1329 Bool restart;
1330 ULong u64;
1331 UChar ssclass = VG_SOLARIS_SYSNO_CLASS(sysno);
1333 switch (ssclass) {
1334 case VG_SOLARIS_SYSCALL_CLASS_CLASSIC:
1335 /* The Solaris kernel does not restart syscalls automatically so it
1336 is done here. */
1337 do {
1338 u64 = do_syscall_WRK(a1,a2,a3,a4,a5,a6,a7,a8,
1339 VG_SOLARIS_SYSNO_INDEX(sysno), &err);
1340 val = (UInt)u64;
1341 restart = err && (val == VKI_EINTR || val == VKI_ERESTART);
1342 } while (restart);
1343 break;
1344 case VG_SOLARIS_SYSCALL_CLASS_FASTTRAP:
1345 u64 = do_syscall_fast_WRK(VG_SOLARIS_SYSNO_INDEX(sysno));
1346 break;
1347 default:
1348 vg_assert(0);
1349 break;
1352 val = (UInt)u64;
1353 val2 = (UInt)(u64 >> 32);
1354 return VG_(mk_SysRes_x86_solaris)(err ? True : False, val,
1355 err ? 0 : val2);
1357 # elif defined(VGP_amd64_solaris)
1358 ULong val, val2, err = False;
1359 Bool restart;
1360 UChar ssclass = VG_SOLARIS_SYSNO_CLASS(sysno);
1362 switch (ssclass) {
1363 case VG_SOLARIS_SYSCALL_CLASS_CLASSIC:
1364 /* The Solaris kernel does not restart syscalls automatically so it
1365 is done here. */
1366 do {
1367 val = do_syscall_WRK(a1,a2,a3,a4,a5,a6,a7,a8,
1368 VG_SOLARIS_SYSNO_INDEX(sysno), &err, &val2);
1369 restart = err && (val == VKI_EINTR || val == VKI_ERESTART);
1370 } while (restart);
1371 break;
1372 case VG_SOLARIS_SYSCALL_CLASS_FASTTRAP:
1373 val = do_syscall_fast_WRK(VG_SOLARIS_SYSNO_INDEX(sysno), &val2);
1374 break;
1375 default:
1376 vg_assert(0);
1377 break;
1380 return VG_(mk_SysRes_amd64_solaris)(err ? True : False, val,
1381 err ? 0 : val2);
1383 #else
1384 # error Unknown platform
1385 #endif
1388 /* ---------------------------------------------------------------------
1389 Names of errors.
1390 ------------------------------------------------------------------ */
1392 /* Return a string which gives the name of an error value. Note,
1393 unlike the standard C syserror fn, the returned string is not
1394 malloc-allocated or writable -- treat it as a constant.
1395 TODO: implement this properly. */
1397 const HChar* VG_(strerror) ( UWord errnum )
1399 switch (errnum) {
1400 case VKI_EPERM: return "Operation not permitted";
1401 case VKI_ENOENT: return "No such file or directory";
1402 case VKI_ESRCH: return "No such process";
1403 case VKI_EINTR: return "Interrupted system call";
1404 case VKI_EIO: return "Input/output error";
1405 case VKI_ENXIO: return "No such device or address";
1406 case VKI_E2BIG: return "Argument list too long";
1407 case VKI_ENOEXEC: return "Exec format error";
1408 case VKI_EBADF: return "Bad file descriptor";
1409 case VKI_ECHILD: return "No child processes";
1410 case VKI_EAGAIN: return "Resource temporarily unavailable";
1411 case VKI_ENOMEM: return "Cannot allocate memory";
1412 case VKI_EACCES: return "Permission denied";
1413 case VKI_EFAULT: return "Bad address";
1414 case VKI_ENOTBLK: return "Block device required";
1415 case VKI_EBUSY: return "Device or resource busy";
1416 case VKI_EEXIST: return "File exists";
1417 case VKI_EXDEV: return "Invalid cross-device link";
1418 case VKI_ENODEV: return "No such device";
1419 case VKI_ENOTDIR: return "Not a directory";
1420 case VKI_EISDIR: return "Is a directory";
1421 case VKI_EINVAL: return "Invalid argument";
1422 case VKI_ENFILE: return "Too many open files in system";
1423 case VKI_EMFILE: return "Too many open files";
1424 case VKI_ENOTTY: return "Inappropriate ioctl for device";
1425 case VKI_ETXTBSY: return "Text file busy";
1426 case VKI_EFBIG: return "File too large";
1427 case VKI_ENOSPC: return "No space left on device";
1428 case VKI_ESPIPE: return "Illegal seek";
1429 case VKI_EROFS: return "Read-only file system";
1430 case VKI_EMLINK: return "Too many links";
1431 case VKI_EPIPE: return "Broken pipe";
1432 case VKI_EDOM: return "Numerical argument out of domain";
1433 case VKI_ERANGE: return "Numerical result out of range";
1435 case VKI_ENOSYS: return "Function not implemented";
1436 case VKI_EOVERFLOW: return "Value too large for defined data type";
1437 # if defined(VKI_ERESTARTSYS)
1438 case VKI_ERESTARTSYS: return "ERESTARTSYS";
1439 # endif
1440 # if defined(VKI_ERESTART)
1441 case VKI_ERESTART: return "ERESTART";
1442 # endif
1443 default: return "VG_(strerror): unknown error";
1448 /*--------------------------------------------------------------------*/
1449 /*--- end ---*/
1450 /*--------------------------------------------------------------------*/