checkers-common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * arch/arm/probes/kprobes/checkers-common.c
  3. *
  4. * Copyright (C) 2014 Huawei Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include "../decode.h"
  17. #include "../decode-arm.h"
  18. #include "checkers.h"
  19. enum probes_insn checker_stack_use_none(probes_opcode_t insn,
  20. struct arch_probes_insn *asi,
  21. const struct decode_header *h)
  22. {
  23. asi->stack_space = 0;
  24. return INSN_GOOD_NO_SLOT;
  25. }
  26. enum probes_insn checker_stack_use_unknown(probes_opcode_t insn,
  27. struct arch_probes_insn *asi,
  28. const struct decode_header *h)
  29. {
  30. asi->stack_space = -1;
  31. return INSN_GOOD_NO_SLOT;
  32. }
  33. #ifdef CONFIG_THUMB2_KERNEL
  34. enum probes_insn checker_stack_use_imm_0xx(probes_opcode_t insn,
  35. struct arch_probes_insn *asi,
  36. const struct decode_header *h)
  37. {
  38. int imm = insn & 0xff;
  39. asi->stack_space = imm;
  40. return INSN_GOOD_NO_SLOT;
  41. }
  42. /*
  43. * Different from other insn uses imm8, the real addressing offset of
  44. * STRD in T32 encoding should be imm8 * 4. See ARMARM description.
  45. */
  46. enum probes_insn checker_stack_use_t32strd(probes_opcode_t insn,
  47. struct arch_probes_insn *asi,
  48. const struct decode_header *h)
  49. {
  50. int imm = insn & 0xff;
  51. asi->stack_space = imm << 2;
  52. return INSN_GOOD_NO_SLOT;
  53. }
  54. #else
  55. enum probes_insn checker_stack_use_imm_x0x(probes_opcode_t insn,
  56. struct arch_probes_insn *asi,
  57. const struct decode_header *h)
  58. {
  59. int imm = ((insn & 0xf00) >> 4) + (insn & 0xf);
  60. asi->stack_space = imm;
  61. return INSN_GOOD_NO_SLOT;
  62. }
  63. #endif
  64. enum probes_insn checker_stack_use_imm_xxx(probes_opcode_t insn,
  65. struct arch_probes_insn *asi,
  66. const struct decode_header *h)
  67. {
  68. int imm = insn & 0xfff;
  69. asi->stack_space = imm;
  70. return INSN_GOOD_NO_SLOT;
  71. }
  72. enum probes_insn checker_stack_use_stmdx(probes_opcode_t insn,
  73. struct arch_probes_insn *asi,
  74. const struct decode_header *h)
  75. {
  76. unsigned int reglist = insn & 0xffff;
  77. int pbit = insn & (1 << 24);
  78. asi->stack_space = (hweight32(reglist) - (!pbit ? 1 : 0)) * 4;
  79. return INSN_GOOD_NO_SLOT;
  80. }
  81. const union decode_action stack_check_actions[] = {
  82. [STACK_USE_NONE] = {.decoder = checker_stack_use_none},
  83. [STACK_USE_UNKNOWN] = {.decoder = checker_stack_use_unknown},
  84. #ifdef CONFIG_THUMB2_KERNEL
  85. [STACK_USE_FIXED_0XX] = {.decoder = checker_stack_use_imm_0xx},
  86. [STACK_USE_T32STRD] = {.decoder = checker_stack_use_t32strd},
  87. #else
  88. [STACK_USE_FIXED_X0X] = {.decoder = checker_stack_use_imm_x0x},
  89. #endif
  90. [STACK_USE_FIXED_XXX] = {.decoder = checker_stack_use_imm_xxx},
  91. [STACK_USE_STMDX] = {.decoder = checker_stack_use_stmdx},
  92. };