Dmitry V. Levin | 38a34c9 | 2015-12-17 17:56:48 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2003 Russell King <rmk@arm.linux.org.uk> |
| 3 | * Copyright (c) 2011-2013 Denys Vlasenko <vda.linux@googlemail.com> |
| 4 | * Copyright (c) 2011-2015 Dmitry V. Levin <ldv@altlinux.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. The name of the author may not be used to endorse or promote products |
| 16 | * derived from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
Dmitry V. Levin | 1651051 | 2015-11-30 01:46:52 +0000 | [diff] [blame] | 30 | /* Return codes: 1 - ok, 0 - ignore, other - error. */ |
| 31 | static int |
| 32 | arch_get_scno(struct tcb *tcp) |
| 33 | { |
| 34 | long scno = 0; |
| 35 | |
| 36 | /* Note: we support only 32-bit CPUs, not 26-bit */ |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 37 | |
| 38 | #if !defined(__ARM_EABI__) || ENABLE_ARM_OABI |
Dmitry V. Levin | 1651051 | 2015-11-30 01:46:52 +0000 | [diff] [blame] | 39 | if (arm_regs.ARM_cpsr & 0x20) { |
| 40 | /* Thumb mode */ |
| 41 | goto scno_in_r7; |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 42 | } |
Dmitry V. Levin | 1651051 | 2015-11-30 01:46:52 +0000 | [diff] [blame] | 43 | /* ARM mode */ |
| 44 | /* Check EABI/OABI by examining SVC insn's low 24 bits */ |
| 45 | errno = 0; |
| 46 | scno = ptrace(PTRACE_PEEKTEXT, tcp->pid, (void *)(arm_regs.ARM_pc - 4), NULL); |
| 47 | if (errno) |
| 48 | return -1; |
| 49 | /* EABI syscall convention? */ |
| 50 | if ((unsigned long) scno != 0xef000000) { |
| 51 | /* No, it's OABI */ |
| 52 | if ((scno & 0x0ff00000) != 0x0f900000) { |
| 53 | error_msg("pid %d unknown syscall trap 0x%08lx", |
| 54 | tcp->pid, scno); |
| 55 | return -1; |
| 56 | } |
| 57 | /* Fixup the syscall number */ |
| 58 | scno &= 0x000fffff; |
| 59 | } else { |
| 60 | scno_in_r7: |
| 61 | scno = arm_regs.ARM_r7; |
| 62 | } |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 63 | #else /* __ARM_EABI__ || !ENABLE_ARM_OABI */ |
| 64 | |
Dmitry V. Levin | 1651051 | 2015-11-30 01:46:52 +0000 | [diff] [blame] | 65 | scno = arm_regs.ARM_r7; |
Dmitry V. Levin | d70d1c4 | 2015-03-22 22:13:55 +0000 | [diff] [blame] | 66 | |
| 67 | #endif |
| 68 | |
Dmitry V. Levin | 1651051 | 2015-11-30 01:46:52 +0000 | [diff] [blame] | 69 | scno = shuffle_scno(scno); |
Dmitry V. Levin | 9945ec9 | 2015-03-23 23:00:37 +0000 | [diff] [blame] | 70 | |
Dmitry V. Levin | 1651051 | 2015-11-30 01:46:52 +0000 | [diff] [blame] | 71 | /* |
| 72 | * Do some sanity checks to figure out |
| 73 | * whether it's really a syscall entry. |
| 74 | */ |
| 75 | if (arm_regs.ARM_ip && !SCNO_IN_RANGE(scno)) { |
| 76 | if (debug_flag) |
| 77 | error_msg("pid %d stray syscall exit:" |
| 78 | " ARM_ip = %ld, scno = %ld", |
| 79 | tcp->pid, arm_regs.ARM_ip, |
| 80 | shuffle_scno(scno)); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | tcp->scno = scno; |
| 85 | return 1; |
Dmitry V. Levin | 9945ec9 | 2015-03-23 23:00:37 +0000 | [diff] [blame] | 86 | } |