smallworld-re 1.0.3__py3-none-any.whl → 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. smallworld/analyses/__init__.py +8 -0
  2. smallworld/analyses/analysis.py +8 -67
  3. smallworld/analyses/code_coverage.py +1 -2
  4. smallworld/analyses/colorizer.py +301 -534
  5. smallworld/analyses/colorizer_def_use.py +217 -0
  6. smallworld/analyses/colorizer_summary.py +173 -83
  7. smallworld/analyses/field_detection/field_analysis.py +7 -8
  8. smallworld/analyses/field_detection/hints.py +1 -1
  9. smallworld/analyses/field_detection/malloc.py +2 -2
  10. smallworld/analyses/trace_execution.py +160 -0
  11. smallworld/analyses/trace_execution_types.py +42 -0
  12. smallworld/analyses/unstable/angr/divergence.py +1 -2
  13. smallworld/analyses/unstable/angr/model.py +5 -6
  14. smallworld/analyses/unstable/angr_nwbt.py +3 -4
  15. smallworld/analyses/unstable/code_coverage.py +2 -3
  16. smallworld/analyses/unstable/code_reachable.py +2 -3
  17. smallworld/analyses/unstable/control_flow_tracer.py +2 -3
  18. smallworld/analyses/unstable/pointer_finder.py +2 -3
  19. smallworld/analyses/unstable/utils/tui.py +71 -0
  20. smallworld/emulators/__init__.py +3 -1
  21. smallworld/emulators/angr/angr.py +30 -9
  22. smallworld/emulators/angr/machdefs/__init__.py +2 -0
  23. smallworld/emulators/angr/machdefs/aarch64.py +1 -1
  24. smallworld/emulators/angr/machdefs/amd64.py +0 -4
  25. smallworld/emulators/angr/machdefs/arm.py +0 -2
  26. smallworld/emulators/angr/machdefs/i386.py +0 -2
  27. smallworld/emulators/angr/machdefs/loongarch.py +340 -0
  28. smallworld/emulators/angr/machdefs/machdef.py +1 -8
  29. smallworld/emulators/angr/machdefs/mips.py +0 -2
  30. smallworld/emulators/angr/machdefs/mips64.py +0 -2
  31. smallworld/emulators/angr/machdefs/ppc.py +1 -2
  32. smallworld/emulators/angr/machdefs/riscv.py +8 -10
  33. smallworld/emulators/angr/machdefs/xtensa.py +7 -4
  34. smallworld/emulators/emulator.py +22 -0
  35. smallworld/emulators/ghidra/__init__.py +37 -0
  36. smallworld/emulators/ghidra/ghidra.py +513 -0
  37. smallworld/emulators/ghidra/machdefs/__init__.py +31 -0
  38. smallworld/emulators/ghidra/machdefs/aarch64.py +289 -0
  39. smallworld/emulators/ghidra/machdefs/amd64.py +185 -0
  40. smallworld/emulators/ghidra/machdefs/arm.py +370 -0
  41. smallworld/emulators/ghidra/machdefs/i386.py +109 -0
  42. smallworld/emulators/ghidra/machdefs/loongarch.py +162 -0
  43. smallworld/emulators/ghidra/machdefs/machdef.py +81 -0
  44. smallworld/emulators/ghidra/machdefs/mips.py +163 -0
  45. smallworld/emulators/ghidra/machdefs/mips64.py +186 -0
  46. smallworld/emulators/ghidra/machdefs/ppc.py +98 -0
  47. smallworld/emulators/ghidra/machdefs/riscv.py +208 -0
  48. smallworld/emulators/ghidra/machdefs/xtensa.py +21 -0
  49. smallworld/emulators/ghidra/typing.py +28 -0
  50. smallworld/emulators/hookable.py +18 -4
  51. smallworld/emulators/panda/machdefs/__init__.py +2 -2
  52. smallworld/emulators/panda/machdefs/aarch64.py +186 -11
  53. smallworld/emulators/panda/machdefs/amd64.py +103 -11
  54. smallworld/emulators/panda/machdefs/arm.py +216 -20
  55. smallworld/emulators/panda/machdefs/i386.py +30 -7
  56. smallworld/emulators/panda/machdefs/machdef.py +9 -16
  57. smallworld/emulators/panda/machdefs/mips.py +49 -5
  58. smallworld/emulators/panda/machdefs/mips64.py +57 -5
  59. smallworld/emulators/panda/machdefs/ppc.py +38 -13
  60. smallworld/emulators/panda/panda.py +146 -44
  61. smallworld/emulators/unicorn/__init__.py +2 -0
  62. smallworld/emulators/unicorn/machdefs/aarch64.py +253 -264
  63. smallworld/emulators/unicorn/machdefs/amd64.py +254 -259
  64. smallworld/emulators/unicorn/machdefs/arm.py +200 -212
  65. smallworld/emulators/unicorn/machdefs/i386.py +84 -90
  66. smallworld/emulators/unicorn/machdefs/machdef.py +2 -23
  67. smallworld/emulators/unicorn/machdefs/mips.py +127 -135
  68. smallworld/emulators/unicorn/unicorn.py +52 -13
  69. smallworld/helpers.py +4 -19
  70. smallworld/hinting/hinting.py +22 -192
  71. smallworld/hinting/hints.py +50 -18
  72. smallworld/instructions/bsid.py +8 -8
  73. smallworld/logging.py +4 -2
  74. smallworld/platforms/__init__.py +12 -0
  75. smallworld/platforms/defs/__init__.py +36 -0
  76. smallworld/platforms/defs/aarch64.py +450 -0
  77. smallworld/platforms/defs/amd64.py +463 -0
  78. smallworld/platforms/defs/arm.py +519 -0
  79. smallworld/platforms/defs/i386.py +258 -0
  80. smallworld/platforms/defs/loongarch.py +270 -0
  81. smallworld/platforms/defs/mips.py +321 -0
  82. smallworld/platforms/defs/mips64.py +313 -0
  83. smallworld/platforms/defs/platformdef.py +97 -0
  84. smallworld/platforms/defs/powerpc.py +259 -0
  85. smallworld/platforms/defs/riscv.py +257 -0
  86. smallworld/platforms/defs/xtensa.py +96 -0
  87. smallworld/{platforms.py → platforms/platforms.py} +3 -0
  88. smallworld/state/cpus/__init__.py +2 -0
  89. smallworld/state/cpus/aarch64.py +0 -9
  90. smallworld/state/cpus/amd64.py +6 -28
  91. smallworld/state/cpus/arm.py +0 -11
  92. smallworld/state/cpus/cpu.py +0 -11
  93. smallworld/state/cpus/i386.py +0 -7
  94. smallworld/state/cpus/loongarch.py +299 -0
  95. smallworld/state/cpus/mips.py +4 -47
  96. smallworld/state/cpus/mips64.py +18 -58
  97. smallworld/state/cpus/powerpc.py +2 -9
  98. smallworld/state/cpus/riscv.py +1 -11
  99. smallworld/state/cpus/xtensa.py +0 -5
  100. smallworld/state/memory/code.py +38 -2
  101. smallworld/state/memory/elf/__init__.py +5 -1
  102. smallworld/state/memory/elf/coredump/__init__.py +3 -0
  103. smallworld/state/memory/elf/coredump/coredump.py +46 -0
  104. smallworld/state/memory/elf/coredump/prstatus/__init__.py +27 -0
  105. smallworld/state/memory/elf/coredump/prstatus/aarch64.py +46 -0
  106. smallworld/state/memory/elf/coredump/prstatus/amd64.py +40 -0
  107. smallworld/state/memory/elf/coredump/prstatus/arm.py +53 -0
  108. smallworld/state/memory/elf/coredump/prstatus/i386.py +30 -0
  109. smallworld/state/memory/elf/coredump/prstatus/mips.py +55 -0
  110. smallworld/state/memory/elf/coredump/prstatus/mips64.py +57 -0
  111. smallworld/state/memory/elf/coredump/prstatus/ppc.py +82 -0
  112. smallworld/state/memory/elf/coredump/prstatus/prstatus.py +129 -0
  113. smallworld/state/memory/elf/elf.py +211 -57
  114. smallworld/state/memory/elf/register_state.py +36 -0
  115. smallworld/state/memory/elf/rela/__init__.py +2 -0
  116. smallworld/state/memory/elf/rela/aarch64.py +3 -1
  117. smallworld/state/memory/elf/rela/amd64.py +4 -2
  118. smallworld/state/memory/elf/rela/arm.py +4 -2
  119. smallworld/state/memory/elf/rela/i386.py +4 -2
  120. smallworld/state/memory/elf/rela/loongarch.py +32 -0
  121. smallworld/state/memory/elf/rela/mips.py +39 -18
  122. smallworld/state/memory/elf/rela/ppc.py +31 -14
  123. smallworld/state/memory/elf/structs.py +3 -0
  124. smallworld/state/memory/heap.py +2 -2
  125. smallworld/state/memory/memory.py +18 -0
  126. smallworld/state/memory/pe/__init__.py +3 -0
  127. smallworld/state/memory/pe/pe.py +361 -0
  128. smallworld/state/memory/pe/structs.py +60 -0
  129. smallworld/state/memory/stack/__init__.py +2 -0
  130. smallworld/state/memory/stack/loongarch.py +26 -0
  131. smallworld/state/models/__init__.py +29 -2
  132. smallworld/state/models/aarch64/__init__.py +1 -0
  133. smallworld/state/models/aarch64/systemv/__init__.py +6 -0
  134. smallworld/state/models/aarch64/systemv/c99/__init__.py +12 -0
  135. smallworld/state/models/aarch64/systemv/c99/signal.py +16 -0
  136. smallworld/state/models/aarch64/systemv/c99/stdio.py +265 -0
  137. smallworld/state/models/aarch64/systemv/c99/stdlib.py +169 -0
  138. smallworld/state/models/aarch64/systemv/c99/string.py +139 -0
  139. smallworld/state/models/aarch64/systemv/c99/time.py +61 -0
  140. smallworld/state/models/aarch64/systemv/posix/__init__.py +6 -0
  141. smallworld/state/models/aarch64/systemv/posix/libgen.py +16 -0
  142. smallworld/state/models/aarch64/systemv/posix/signal.py +157 -0
  143. smallworld/state/models/aarch64/systemv/systemv.py +80 -0
  144. smallworld/state/models/amd64/__init__.py +1 -0
  145. smallworld/state/models/amd64/systemv/__init__.py +6 -0
  146. smallworld/state/models/amd64/systemv/c99/__init__.py +12 -0
  147. smallworld/state/models/amd64/systemv/c99/signal.py +16 -0
  148. smallworld/state/models/amd64/systemv/c99/stdio.py +265 -0
  149. smallworld/state/models/amd64/systemv/c99/stdlib.py +169 -0
  150. smallworld/state/models/amd64/systemv/c99/string.py +139 -0
  151. smallworld/state/models/amd64/systemv/c99/time.py +61 -0
  152. smallworld/state/models/amd64/systemv/posix/__init__.py +6 -0
  153. smallworld/state/models/amd64/systemv/posix/libgen.py +16 -0
  154. smallworld/state/models/amd64/systemv/posix/signal.py +157 -0
  155. smallworld/state/models/amd64/systemv/systemv.py +78 -0
  156. smallworld/state/models/armel/__init__.py +1 -0
  157. smallworld/state/models/armel/systemv/__init__.py +6 -0
  158. smallworld/state/models/armel/systemv/c99/__init__.py +12 -0
  159. smallworld/state/models/armel/systemv/c99/signal.py +16 -0
  160. smallworld/state/models/armel/systemv/c99/stdio.py +265 -0
  161. smallworld/state/models/armel/systemv/c99/stdlib.py +169 -0
  162. smallworld/state/models/armel/systemv/c99/string.py +139 -0
  163. smallworld/state/models/armel/systemv/c99/time.py +61 -0
  164. smallworld/state/models/armel/systemv/posix/__init__.py +6 -0
  165. smallworld/state/models/armel/systemv/posix/libgen.py +16 -0
  166. smallworld/state/models/armel/systemv/posix/signal.py +157 -0
  167. smallworld/state/models/armel/systemv/systemv.py +82 -0
  168. smallworld/state/models/armhf/__init__.py +1 -0
  169. smallworld/state/models/armhf/systemv/__init__.py +6 -0
  170. smallworld/state/models/armhf/systemv/c99/__init__.py +12 -0
  171. smallworld/state/models/armhf/systemv/c99/signal.py +16 -0
  172. smallworld/state/models/armhf/systemv/c99/stdio.py +265 -0
  173. smallworld/state/models/armhf/systemv/c99/stdlib.py +169 -0
  174. smallworld/state/models/armhf/systemv/c99/string.py +139 -0
  175. smallworld/state/models/armhf/systemv/c99/time.py +61 -0
  176. smallworld/state/models/armhf/systemv/posix/__init__.py +6 -0
  177. smallworld/state/models/armhf/systemv/posix/libgen.py +16 -0
  178. smallworld/state/models/armhf/systemv/posix/signal.py +157 -0
  179. smallworld/state/models/armhf/systemv/systemv.py +77 -0
  180. smallworld/state/models/c99/__init__.py +12 -0
  181. smallworld/state/models/c99/fmt_print.py +915 -0
  182. smallworld/state/models/c99/fmt_scan.py +864 -0
  183. smallworld/state/models/c99/math.py +362 -0
  184. smallworld/state/models/c99/signal.py +71 -0
  185. smallworld/state/models/c99/stdio.py +1305 -0
  186. smallworld/state/models/c99/stdlib.py +595 -0
  187. smallworld/state/models/c99/string.py +674 -0
  188. smallworld/state/models/c99/time.py +340 -0
  189. smallworld/state/models/c99/utils.py +89 -0
  190. smallworld/state/models/cstd.py +759 -0
  191. smallworld/state/models/errno.py +581 -0
  192. smallworld/state/models/filedesc.py +515 -0
  193. smallworld/state/models/i386/__init__.py +1 -0
  194. smallworld/state/models/i386/systemv/__init__.py +6 -0
  195. smallworld/state/models/i386/systemv/c99/__init__.py +12 -0
  196. smallworld/state/models/i386/systemv/c99/signal.py +16 -0
  197. smallworld/state/models/i386/systemv/c99/stdio.py +265 -0
  198. smallworld/state/models/i386/systemv/c99/stdlib.py +169 -0
  199. smallworld/state/models/i386/systemv/c99/string.py +139 -0
  200. smallworld/state/models/i386/systemv/c99/time.py +61 -0
  201. smallworld/state/models/i386/systemv/posix/__init__.py +6 -0
  202. smallworld/state/models/i386/systemv/posix/libgen.py +16 -0
  203. smallworld/state/models/i386/systemv/posix/signal.py +157 -0
  204. smallworld/state/models/i386/systemv/systemv.py +71 -0
  205. smallworld/state/models/loongarch64/__init__.py +1 -0
  206. smallworld/state/models/loongarch64/systemv/__init__.py +6 -0
  207. smallworld/state/models/loongarch64/systemv/c99/__init__.py +12 -0
  208. smallworld/state/models/loongarch64/systemv/c99/signal.py +16 -0
  209. smallworld/state/models/loongarch64/systemv/c99/stdio.py +265 -0
  210. smallworld/state/models/loongarch64/systemv/c99/stdlib.py +169 -0
  211. smallworld/state/models/loongarch64/systemv/c99/string.py +139 -0
  212. smallworld/state/models/loongarch64/systemv/c99/time.py +61 -0
  213. smallworld/state/models/loongarch64/systemv/posix/__init__.py +6 -0
  214. smallworld/state/models/loongarch64/systemv/posix/libgen.py +16 -0
  215. smallworld/state/models/loongarch64/systemv/posix/signal.py +157 -0
  216. smallworld/state/models/loongarch64/systemv/systemv.py +83 -0
  217. smallworld/state/models/mips/__init__.py +1 -0
  218. smallworld/state/models/mips/systemv/__init__.py +6 -0
  219. smallworld/state/models/mips/systemv/c99/__init__.py +12 -0
  220. smallworld/state/models/mips/systemv/c99/signal.py +16 -0
  221. smallworld/state/models/mips/systemv/c99/stdio.py +265 -0
  222. smallworld/state/models/mips/systemv/c99/stdlib.py +169 -0
  223. smallworld/state/models/mips/systemv/c99/string.py +139 -0
  224. smallworld/state/models/mips/systemv/c99/time.py +61 -0
  225. smallworld/state/models/mips/systemv/posix/__init__.py +6 -0
  226. smallworld/state/models/mips/systemv/posix/libgen.py +16 -0
  227. smallworld/state/models/mips/systemv/posix/signal.py +157 -0
  228. smallworld/state/models/mips/systemv/systemv.py +78 -0
  229. smallworld/state/models/mips64/__init__.py +1 -0
  230. smallworld/state/models/mips64/systemv/__init__.py +6 -0
  231. smallworld/state/models/mips64/systemv/c99/__init__.py +12 -0
  232. smallworld/state/models/mips64/systemv/c99/signal.py +16 -0
  233. smallworld/state/models/mips64/systemv/c99/stdio.py +265 -0
  234. smallworld/state/models/mips64/systemv/c99/stdlib.py +169 -0
  235. smallworld/state/models/mips64/systemv/c99/string.py +139 -0
  236. smallworld/state/models/mips64/systemv/c99/time.py +61 -0
  237. smallworld/state/models/mips64/systemv/posix/__init__.py +6 -0
  238. smallworld/state/models/mips64/systemv/posix/libgen.py +16 -0
  239. smallworld/state/models/mips64/systemv/posix/signal.py +157 -0
  240. smallworld/state/models/mips64/systemv/systemv.py +98 -0
  241. smallworld/state/models/mips64el/__init__.py +1 -0
  242. smallworld/state/models/mips64el/systemv/__init__.py +6 -0
  243. smallworld/state/models/mips64el/systemv/c99/__init__.py +12 -0
  244. smallworld/state/models/mips64el/systemv/c99/signal.py +16 -0
  245. smallworld/state/models/mips64el/systemv/c99/stdio.py +265 -0
  246. smallworld/state/models/mips64el/systemv/c99/stdlib.py +169 -0
  247. smallworld/state/models/mips64el/systemv/c99/string.py +139 -0
  248. smallworld/state/models/mips64el/systemv/c99/time.py +61 -0
  249. smallworld/state/models/mips64el/systemv/posix/__init__.py +6 -0
  250. smallworld/state/models/mips64el/systemv/posix/libgen.py +16 -0
  251. smallworld/state/models/mips64el/systemv/posix/signal.py +157 -0
  252. smallworld/state/models/mips64el/systemv/systemv.py +96 -0
  253. smallworld/state/models/mipsel/__init__.py +1 -0
  254. smallworld/state/models/mipsel/systemv/__init__.py +6 -0
  255. smallworld/state/models/mipsel/systemv/c99/__init__.py +12 -0
  256. smallworld/state/models/mipsel/systemv/c99/signal.py +16 -0
  257. smallworld/state/models/mipsel/systemv/c99/stdio.py +265 -0
  258. smallworld/state/models/mipsel/systemv/c99/stdlib.py +169 -0
  259. smallworld/state/models/mipsel/systemv/c99/string.py +139 -0
  260. smallworld/state/models/mipsel/systemv/c99/time.py +61 -0
  261. smallworld/state/models/mipsel/systemv/posix/__init__.py +6 -0
  262. smallworld/state/models/mipsel/systemv/posix/libgen.py +16 -0
  263. smallworld/state/models/mipsel/systemv/posix/signal.py +157 -0
  264. smallworld/state/models/mipsel/systemv/systemv.py +78 -0
  265. smallworld/state/models/model.py +27 -2
  266. smallworld/state/models/posix/__init__.py +6 -0
  267. smallworld/state/models/posix/libgen.py +123 -0
  268. smallworld/state/models/posix/signal.py +690 -0
  269. smallworld/state/models/powerpc/__init__.py +1 -0
  270. smallworld/state/models/powerpc/systemv/__init__.py +6 -0
  271. smallworld/state/models/powerpc/systemv/c99/__init__.py +12 -0
  272. smallworld/state/models/powerpc/systemv/c99/signal.py +16 -0
  273. smallworld/state/models/powerpc/systemv/c99/stdio.py +265 -0
  274. smallworld/state/models/powerpc/systemv/c99/stdlib.py +169 -0
  275. smallworld/state/models/powerpc/systemv/c99/string.py +139 -0
  276. smallworld/state/models/powerpc/systemv/c99/time.py +61 -0
  277. smallworld/state/models/powerpc/systemv/posix/__init__.py +6 -0
  278. smallworld/state/models/powerpc/systemv/posix/libgen.py +16 -0
  279. smallworld/state/models/powerpc/systemv/posix/signal.py +157 -0
  280. smallworld/state/models/powerpc/systemv/systemv.py +93 -0
  281. smallworld/state/models/riscv64/__init__.py +1 -0
  282. smallworld/state/models/riscv64/systemv/__init__.py +6 -0
  283. smallworld/state/models/riscv64/systemv/c99/__init__.py +12 -0
  284. smallworld/state/models/riscv64/systemv/c99/signal.py +16 -0
  285. smallworld/state/models/riscv64/systemv/c99/stdio.py +265 -0
  286. smallworld/state/models/riscv64/systemv/c99/stdlib.py +169 -0
  287. smallworld/state/models/riscv64/systemv/c99/string.py +139 -0
  288. smallworld/state/models/riscv64/systemv/c99/time.py +61 -0
  289. smallworld/state/models/riscv64/systemv/posix/__init__.py +6 -0
  290. smallworld/state/models/riscv64/systemv/posix/libgen.py +16 -0
  291. smallworld/state/models/riscv64/systemv/posix/signal.py +157 -0
  292. smallworld/state/models/riscv64/systemv/systemv.py +85 -0
  293. smallworld/state/state.py +65 -24
  294. smallworld/state/unstable/elf.py +16 -31
  295. smallworld/utils.py +6 -1
  296. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/METADATA +74 -42
  297. smallworld_re-2.0.0.dist-info/RECORD +374 -0
  298. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/WHEEL +1 -1
  299. smallworld/state/models/x86/__init__.py +0 -2
  300. smallworld/state/models/x86/microsoftcdecl.py +0 -35
  301. smallworld/state/models/x86/systemv.py +0 -240
  302. smallworld_re-1.0.3.dist-info/RECORD +0 -166
  303. /smallworld/state/models/{posix.py → _posix.py} +0 -0
  304. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/entry_points.txt +0 -0
  305. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/licenses/LICENSE.txt +0 -0
  306. {smallworld_re-1.0.3.dist-info → smallworld_re-2.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,581 @@
1
+ import abc
2
+
3
+ from ... import utils
4
+ from ...platforms import ABI, Architecture, Byteorder, Platform
5
+
6
+
7
+ class ErrnoResolver(metaclass=abc.ABCMeta):
8
+ """Errno resolver
9
+
10
+ For some UNGODLY REASON,
11
+ the System V ABIs can't agree on errno values across platforms.
12
+ """
13
+
14
+ @property
15
+ @abc.abstractmethod
16
+ def platform(self) -> Platform:
17
+ """The platform this errno resolver supports"""
18
+ raise NotImplementedError()
19
+
20
+ @property
21
+ @abc.abstractmethod
22
+ def abi(self) -> ABI:
23
+ """The ABI this errno resolver supports"""
24
+ raise NotImplementedError()
25
+
26
+ # These are the numbers from asm-generic.
27
+ # MOST architectures use these... (MIPS!!!)
28
+ errno_to_label = {
29
+ 1: "EPERM",
30
+ 2: "ENOENT",
31
+ 3: "ESRCH",
32
+ 4: "EINTR",
33
+ 5: "EIO",
34
+ 6: "ENXIO",
35
+ 7: "E2BIG",
36
+ 8: "ENOEXEC",
37
+ 9: "EBADF",
38
+ 10: "ECHILD",
39
+ 11: "EAGAIN",
40
+ 12: "ENOMEM",
41
+ 13: "EACCES",
42
+ 14: "EFAULT",
43
+ 15: "ENOTBLK",
44
+ 16: "EBUSY",
45
+ 17: "EEXIST",
46
+ 18: "EXDEV",
47
+ 19: "ENODEV",
48
+ 20: "ENOTDIR",
49
+ 21: "EISDIR",
50
+ 22: "EINVAL",
51
+ 23: "ENFILE",
52
+ 24: "EMFILE",
53
+ 25: "ENOTTY",
54
+ 26: "ETXTBSY",
55
+ 27: "EFBIG",
56
+ 28: "ENOSPC",
57
+ 29: "ESPIPE",
58
+ 30: "EROFS",
59
+ 31: "EMLINK",
60
+ 32: "EPIPE",
61
+ 33: "EDOM",
62
+ 34: "ERANGE",
63
+ 35: "EDEADLK",
64
+ 36: "ENAMETOOLONG",
65
+ 37: "ENOLCK",
66
+ 38: "ENOSYS",
67
+ 39: "ENOTEMPTY",
68
+ 40: "ELOOP",
69
+ 42: "ENOMSG",
70
+ 43: "EIDRM",
71
+ 44: "ECHRNG",
72
+ 45: "EL2NSYNC",
73
+ 46: "EL3HLT",
74
+ 47: "EL3RST",
75
+ 48: "ELNRNG",
76
+ 49: "EUNATCH",
77
+ 50: "ENOCSI",
78
+ 51: "EL2HLT",
79
+ 52: "EBADE",
80
+ 53: "EBADR",
81
+ 54: "EXFULL",
82
+ 55: "ENOANO",
83
+ 56: "EBADRQC",
84
+ 57: "EBADSLT",
85
+ 59: "EBFONT",
86
+ 60: "ENOSTR",
87
+ 61: "ENODATA",
88
+ 62: "ETIME",
89
+ 63: "ENOSR",
90
+ 64: "ENONET",
91
+ 65: "ENOPKG",
92
+ 66: "EREMOTE",
93
+ 67: "ENOLINK",
94
+ 68: "EADV",
95
+ 69: "ESRMNT",
96
+ 70: "ECOMM",
97
+ 71: "EPROTO",
98
+ 72: "EMULTIHOP",
99
+ 73: "EDOTDOT",
100
+ 74: "EBADMSG",
101
+ 75: "EOVERFLOW",
102
+ 76: "ENOTUNIQ",
103
+ 77: "EBADFD",
104
+ 78: "EREMCHG",
105
+ 79: "ELIBACC",
106
+ 80: "ELIBBAD",
107
+ 81: "ELIBSCN",
108
+ 82: "ELIBMAX",
109
+ 83: "ELIBEXEC",
110
+ 84: "EILSEQ",
111
+ 85: "ERESTART",
112
+ 86: "ESTRPIPE",
113
+ 87: "EUSERS",
114
+ 88: "ENOTSOCK",
115
+ 89: "EDESTADDRREQ",
116
+ 90: "EMSGSIZE",
117
+ 91: "EPROTOTYPE",
118
+ 92: "ENOPROTOOPT",
119
+ 93: "EPROTONOSUPPORT",
120
+ 94: "ESOCKTNOSUPPORT",
121
+ 95: "EOPNOTSUPP",
122
+ 96: "EPFNOSUPPORT",
123
+ 97: "EAFNOSUPPORT",
124
+ 98: "EADDRINUSE",
125
+ 99: "EADDRNOTAVAIL",
126
+ 100: "ENETDOWN",
127
+ 101: "ENETUNREACH",
128
+ 102: "ENETRESET",
129
+ 103: "ECONNABORTED",
130
+ 104: "ECONNRESET",
131
+ 105: "ENOBUFS",
132
+ 106: "EISCONN",
133
+ 107: "ENOTCONN",
134
+ 108: "ESHUTDOWN",
135
+ 109: "ETOOMANYREFS",
136
+ 110: "ETIMEDOUT",
137
+ 111: "ECONNREFUSED",
138
+ 112: "EHOSTDOWN",
139
+ 113: "EHOSTUNREACH",
140
+ 114: "EALREADY",
141
+ 115: "EINPROGRESS",
142
+ 116: "ESTALE",
143
+ 117: "EUCLEAN",
144
+ 118: "ENOTNAM",
145
+ 119: "ENAVAIL",
146
+ 120: "EISNAM",
147
+ 121: "EREMOTEIO",
148
+ 122: "EDQUOT",
149
+ 123: "ENOMEDIUM",
150
+ 124: "EMEDIUMTYPE",
151
+ 125: "ECANCELED",
152
+ 126: "ENOKEY",
153
+ 127: "EKEYEXPIRED",
154
+ 128: "EKEYREVOKED",
155
+ 129: "EKEYREJECTED",
156
+ 130: "EOWNERDEAD",
157
+ 131: "ENOTRECOVERABLE",
158
+ 132: "ERFKILL",
159
+ 133: "EHWPOISON",
160
+ }
161
+
162
+ label_to_description = {
163
+ "EPERM": "Operation not permitted",
164
+ "ENOENT": "No such file or directory",
165
+ "ESRCH": "No such process",
166
+ "EINTR": "Interrupted system call",
167
+ "EIO": "Input/output error",
168
+ "ENXIO": "No such device or address",
169
+ "E2BIG": "Argument list too long",
170
+ "ENOEXEC": "Exec format error",
171
+ "EBADF": "Bad file descriptor",
172
+ "ECHILD": "No child processes",
173
+ "EAGAIN": "Resource temporarily unavailable",
174
+ "ENOMEM": "Cannot allocate memory",
175
+ "EACCES": "Permission denied",
176
+ "EFAULT": "Bad address",
177
+ "ENOTBLK": "Block device required",
178
+ "EBUSY": "Device or resource busy",
179
+ "EEXIST": "File exists",
180
+ "EXDEV": "Invalid cross-device link",
181
+ "ENODEV": "No such device",
182
+ "ENOTDIR": "Not a directory",
183
+ "EISDIR": "Is a directory",
184
+ "EINVAL": "Invalid argument",
185
+ "ENFILE": "Too many open files in system",
186
+ "EMFILE": "Too many open files",
187
+ "ENOTTY": "Inappropriate ioctl for device",
188
+ "ETXTBSY": "Text file busy",
189
+ "EFBIG": "File too large",
190
+ "ENOSPC": "No space left on device",
191
+ "ESPIPE": "Illegal seek",
192
+ "EROFS": "Read-only file system",
193
+ "EMLINK": "Too many links",
194
+ "EPIPE": "Broken pipe",
195
+ "EDOM": "Numerical argument out of domain",
196
+ "ERANGE": "Numerical result out of range",
197
+ "EDEADLK": "Resource deadlock avoided",
198
+ "ENAMETOOLONG": "File name too long",
199
+ "ENOLCK": "No locks available",
200
+ "ENOSYS": "Function not implemented",
201
+ "ENOTEMPTY": "Directory not empty",
202
+ "ELOOP": "Too many levels of symbolic links",
203
+ "EWOULDBLOCK": "Resource temporarily unavailable",
204
+ "ENOMSG": "No message of desired type",
205
+ "EIDRM": "Identifier removed",
206
+ "ECHRNG": "Channel number out of range",
207
+ "EL2NSYNC": "Level 2 not synchronized",
208
+ "EL3HLT": "Level 3 halted",
209
+ "EL3RST": "Level 3 reset",
210
+ "ELNRNG": "Link number out of range",
211
+ "EUNATCH": "Protocol driver not attached",
212
+ "ENOCSI": "No CSI structure available",
213
+ "EL2HLT": "Level 2 halted",
214
+ "EBADE": "Invalid exchange",
215
+ "EBADR": "Invalid request descriptor",
216
+ "EXFULL": "Exchange full",
217
+ "ENOANO": "No anode",
218
+ "EBADRQC": "Invalid request code",
219
+ "EBADSLT": "Invalid slot",
220
+ "EDEADLCK": "Resource deadlock avoided",
221
+ "EDEADLOCK": "Resource deadlock avoided",
222
+ "EBFONT": "Bad font file format",
223
+ "ENOSTR": "Device not a stream",
224
+ "ENODATA": "No data available",
225
+ "ETIME": "Timer expired",
226
+ "ENOSR": "Out of streams resources",
227
+ "ENONET": "Machine is not on the network",
228
+ "ENOPKG": "Package not installed",
229
+ "EREMOTE": "Object is remote",
230
+ "ENOLINK": "Link has been severed",
231
+ "EADV": "Advertise error",
232
+ "ESRMNT": "Srmount error",
233
+ "ECOMM": "Communication error on send",
234
+ "EPROTO": "Protocol error",
235
+ "EMULTIHOP": "Multihop attempted",
236
+ "EDOTDOT": "RFS specific error",
237
+ "EBADMSG": "Bad message",
238
+ "EOVERFLOW": "Value too large for defined data type",
239
+ "ENOTUNIQ": "Name not unique on network",
240
+ "EBADFD": "File descriptor in bad state",
241
+ "EREMCHG": "Remote address changed",
242
+ "ELIBACC": "Can not access a needed shared library",
243
+ "ELIBBAD": "Accessing a corrupted shared library",
244
+ "ELIBSCN": ".lib section in a.out corrupted",
245
+ "ELIBMAX": "Attempting to link in too many shared libraries",
246
+ "ELIBEXEC": "Cannot exec a shared library directly",
247
+ "EILSEQ": "Invalid or incomplete multibyte or wide character",
248
+ "ERESTART": "Interrupted system call should be restarted",
249
+ "ESTRPIPE": "Streams pipe error",
250
+ "EUSERS": "Too many users",
251
+ "ENOTSOCK": "Socket operation on non-socket",
252
+ "EDESTADDRREQ": "Destination address required",
253
+ "EMSGSIZE": "Message too long",
254
+ "EPROTOTYPE": "Protocol wrong type for socket",
255
+ "ENOPROTOOPT": "Protocol not available",
256
+ "EPROTONOSUPPORT": "Protocol not supported",
257
+ "ESOCKTNOSUPPORT": "Socket type not supported",
258
+ "EOPNOTSUPP": "Operation not supported",
259
+ "EPFNOSUPPORT": "Protocol family not supported",
260
+ "EAFNOSUPPORT": "Address family not supported by protocol",
261
+ "EADDRINUSE": "Address already in use",
262
+ "EADDRNOTAVAIL": "Cannot assign requested address",
263
+ "ENETDOWN": "Network is down",
264
+ "ENETUNREACH": "Network is unreachable",
265
+ "ENETRESET": "Network dropped connection on reset",
266
+ "ECONNABORTED": "Software caused connection abort",
267
+ "ECONNRESET": "Connection reset by peer",
268
+ "ENOBUFS": "No buffer space available",
269
+ "EISCONN": "Transport endpoint is already connected",
270
+ "ENOTCONN": "Transport endpoint is not connected",
271
+ "ESHUTDOWN": "Cannot send after transport endpoint shutdown",
272
+ "ETOOMANYREFS": "Too many references: cannot splice",
273
+ "ETIMEDOUT": "Connection timed out",
274
+ "ECONNREFUSED": "Connection refused",
275
+ "EHOSTDOWN": "Host is down",
276
+ "EHOSTUNREACH": "No route to host",
277
+ "EALREADY": "Operation already in progress",
278
+ "EINPROGRESS": "Operation now in progress",
279
+ "ESTALE": "Stale file handle",
280
+ "EUCLEAN": "Structure needs cleaning",
281
+ "ENOTNAM": "Not a XENIX named type file",
282
+ "ENAVAIL": "No XENIX semaphores available",
283
+ "EISNAM": "Is a named type file",
284
+ "EREMOTEIO": "Remote I/O error",
285
+ "EDQUOT": "Disk quota exceeded",
286
+ "ENOMEDIUM": "No medium found",
287
+ "EMEDIUMTYPE": "Wrong medium type",
288
+ "ECANCELED": "Operation canceled",
289
+ "ENOKEY": "Required key not available",
290
+ "EKEYEXPIRED": "Key has expired",
291
+ "EKEYREVOKED": "Key has been revoked",
292
+ "EKEYREJECTED": "Key was rejected by service",
293
+ "EOWNERDEAD": "Owner died",
294
+ "ENOTRECOVERABLE": "State not recoverable",
295
+ "ERFKILL": "Operation not possible due to RF-kill",
296
+ "EHWPOISON": "Memory page has hardware error",
297
+ "ENOTSUP": "Operation not supported",
298
+ }
299
+
300
+ def get_label(self, errno: int) -> str:
301
+ """Get the label for an errno by its number
302
+
303
+ NOTE: Some numbers are tied to mulitple errors.
304
+ This function will always return the same label
305
+ for the same number. No guarantees
306
+ that it's the one you want in case of collision.
307
+
308
+ This will raise an exception in case of an unknown number
309
+
310
+ Arguments:
311
+ errno: The error number
312
+
313
+ Returns:
314
+ A string containing the macro defined for that number
315
+ """
316
+
317
+ if errno not in self.errno_to_label:
318
+ raise KeyError(f"Unknown errno {errno}")
319
+ return self.errno_to_label[errno]
320
+
321
+ def get_description(self, errno: int) -> str:
322
+ """Get the descriptive text for an errno by its number
323
+
324
+ NOTE: Some numbers are tied to mulitple errors.
325
+ This function will always return the same description
326
+ for the same number. No guarantees
327
+ that it's the one you want in case of collision.
328
+
329
+ This will return the string "Unknown error {errno}"
330
+ in case of an unknown number.
331
+
332
+ Arguments:
333
+ errno: The error number
334
+
335
+ Returns:
336
+ The descriptive text for this errno.
337
+ """
338
+ try:
339
+ label = self.get_label(errno)
340
+ if label not in self.label_to_description:
341
+ return f"Unknown error {errno}"
342
+ return self.label_to_description[label]
343
+ except KeyError:
344
+ return f"Unknown error {errno}"
345
+
346
+ @classmethod
347
+ def for_platform(cls, platform: Platform, abi: ABI) -> "ErrnoResolver":
348
+ """Instantiate an errno resolver by platform and ABI.
349
+
350
+ Arguments:
351
+ platform: The platform for which this resolver is defined
352
+ abi: The ABI for which this resolver is defined
353
+
354
+ Returns:
355
+ The errno resolver for this platform and ABI
356
+ """
357
+ try:
358
+ return utils.find_subclass(
359
+ cls, lambda x: x.platform == platform and x.abi == abi
360
+ )
361
+ except ValueError:
362
+ raise ValueError(f"no errno resolver for {platform} with ABI '{abi}'")
363
+
364
+
365
+ class AArch64ErrnoResolver(ErrnoResolver):
366
+ platform = Platform(Architecture.AARCH64, Byteorder.LITTLE)
367
+ abi = ABI.SYSTEMV
368
+ # aarch64 uses generic errno
369
+
370
+
371
+ class AMD64ErrnoResolver(ErrnoResolver):
372
+ platform = Platform(Architecture.X86_64, Byteorder.LITTLE)
373
+ abi = ABI.SYSTEMV
374
+ # amd64 uses generic errno
375
+
376
+
377
+ class ArmELErrnoResolver(ErrnoResolver):
378
+ platform = Platform(Architecture.ARM_V5T, Byteorder.LITTLE)
379
+ abi = ABI.SYSTEMV
380
+ # armel uses generic errno
381
+
382
+
383
+ class ArmHFErrnoResolver(ErrnoResolver):
384
+ platform = Platform(Architecture.ARM_V7A, Byteorder.LITTLE)
385
+ abi = ABI.SYSTEMV
386
+ # armhf uses generic errno
387
+
388
+
389
+ class I386ErrnoResolver(ErrnoResolver):
390
+ platform = Platform(Architecture.X86_32, Byteorder.LITTLE)
391
+ abi = ABI.SYSTEMV
392
+ # i386 uses generic errno
393
+
394
+
395
+ class LoongArch64ErrnoResolver(ErrnoResolver):
396
+ platform = Platform(Architecture.LOONGARCH64, Byteorder.LITTLE)
397
+ abi = ABI.SYSTEMV
398
+ # la64 uses generic errno
399
+
400
+
401
+ class MIPSErrnoResolver(ErrnoResolver):
402
+ abi = ABI.SYSTEMV
403
+ # MIPS Absolutely doesn't use generic errno
404
+ errno_to_label = {
405
+ 1: "EPERM",
406
+ 2: "ENOENT",
407
+ 3: "ESRCH",
408
+ 4: "EINTR",
409
+ 5: "EIO",
410
+ 6: "ENXIO",
411
+ 7: "E2BIG",
412
+ 8: "ENOEXEC",
413
+ 9: "EBADF",
414
+ 10: "ECHILD",
415
+ 11: "EAGAIN",
416
+ 12: "ENOMEM",
417
+ 13: "EACCES",
418
+ 14: "EFAULT",
419
+ 15: "ENOTBLK",
420
+ 16: "EBUSY",
421
+ 17: "EEXIST",
422
+ 18: "EXDEV",
423
+ 19: "ENODEV",
424
+ 20: "ENOTDIR",
425
+ 21: "EISDIR",
426
+ 22: "EINVAL",
427
+ 23: "ENFILE",
428
+ 24: "EMFILE",
429
+ 25: "ENOTTY",
430
+ 26: "ETXTBSY",
431
+ 27: "EFBIG",
432
+ 28: "ENOSPC",
433
+ 29: "ESPIPE",
434
+ 30: "EROFS",
435
+ 31: "EMLINK",
436
+ 32: "EPIPE",
437
+ 33: "EDOM",
438
+ 34: "ERANGE",
439
+ 35: "ENOMSG",
440
+ 36: "EIDRM",
441
+ 37: "ECHRNG",
442
+ 38: "EL2NSYNC",
443
+ 39: "EL3HLT",
444
+ 40: "EL3RST",
445
+ 41: "ELNRNG",
446
+ 42: "EUNATCH",
447
+ 43: "ENOCSI",
448
+ 44: "EL2HLT",
449
+ 45: "EDEADLK",
450
+ 46: "ENOLCK",
451
+ 50: "EBADE",
452
+ 51: "EBADR",
453
+ 52: "EXFULL",
454
+ 53: "ENOANO",
455
+ 54: "EBADRQC",
456
+ 55: "EBADSLT",
457
+ 56: "EDEADLOCK",
458
+ 59: "EBFONT",
459
+ 60: "ENOSTR",
460
+ 61: "ENODATA",
461
+ 62: "ETIME",
462
+ 63: "ENOSR",
463
+ 64: "ENONET",
464
+ 65: "ENOPKG",
465
+ 66: "EREMOTE",
466
+ 67: "ENOLINK",
467
+ 68: "EADV",
468
+ 69: "ESRMNT",
469
+ 70: "ECOMM",
470
+ 71: "EPROTO",
471
+ 73: "EDOTDOT",
472
+ 74: "EMULTIHOP",
473
+ 77: "EBADMSG",
474
+ 78: "ENAMETOOLONG",
475
+ 79: "EOVERFLOW",
476
+ 80: "ENOTUNIQ",
477
+ 81: "EBADFD",
478
+ 82: "EREMCHG",
479
+ 83: "ELIBACC",
480
+ 84: "ELIBBAD",
481
+ 85: "ELIBSCN",
482
+ 86: "ELIBMAX",
483
+ 87: "ELIBEXEC",
484
+ 88: "EILSEQ",
485
+ 89: "ENOSYS",
486
+ 90: "ELOOP",
487
+ 91: "ERESTART",
488
+ 92: "ESTRPIPE",
489
+ 93: "ENOTEMPTY",
490
+ 94: "EUSERS",
491
+ 95: "ENOTSOCK",
492
+ 96: "EDESTADDRREQ",
493
+ 97: "EMSGSIZE",
494
+ 98: "EPROTOTYPE",
495
+ 99: "ENOPROTOOPT",
496
+ 120: "EPROTONOSUPPORT",
497
+ 121: "ESOCKTNOSUPPORT",
498
+ 122: "EOPNOTSUPP",
499
+ 123: "EPFNOSUPPORT",
500
+ 124: "EAFNOSUPPORT",
501
+ 125: "EADDRINUSE",
502
+ 126: "EADDRNOTAVAIL",
503
+ 127: "ENETDOWN",
504
+ 128: "ENETUNREACH",
505
+ 129: "ENETRESET",
506
+ 130: "ECONNABORTED",
507
+ 131: "ECONNRESET",
508
+ 132: "ENOBUFS",
509
+ 133: "EISCONN",
510
+ 134: "ENOTCONN",
511
+ 135: "EUCLEAN",
512
+ 137: "ENOTNAM",
513
+ 138: "ENAVAIL",
514
+ 139: "EISNAM",
515
+ 140: "EREMOTEIO",
516
+ 141: "EINIT",
517
+ 142: "EREMDEV",
518
+ 143: "ESHUTDOWN",
519
+ 144: "ETOOMANYREFS",
520
+ 145: "ETIMEDOUT",
521
+ 146: "ECONNREFUSED",
522
+ 147: "EHOSTDOWN",
523
+ 148: "EHOSTUNREACH",
524
+ 149: "EALREADY",
525
+ 150: "EINPROGRESS",
526
+ 151: "ESTALE",
527
+ 158: "ECANCELED",
528
+ 159: "ENOMEDIUM",
529
+ 160: "EMEDIUMTYPE",
530
+ 161: "ENOKEY",
531
+ 162: "EKEYEXPIRED",
532
+ 163: "EKEYREVOKED",
533
+ 164: "EKEYREJECTED",
534
+ 165: "EOWNERDEAD",
535
+ 166: "ENOTRECOVERABLE",
536
+ 167: "ERFKILL",
537
+ 168: "EHWPOISON",
538
+ 1133: "EDQUOT",
539
+ }
540
+
541
+
542
+ class MIPSBEErrnoResolver(MIPSErrnoResolver):
543
+ platform = Platform(Architecture.MIPS32, Byteorder.BIG)
544
+ # mips uses the MIPS errno list
545
+
546
+
547
+ class MIPSELErrnoResolver(MIPSErrnoResolver):
548
+ platform = Platform(Architecture.MIPS32, Byteorder.LITTLE)
549
+ # mipsel uses the MIPS errno list
550
+
551
+
552
+ class MIPS64BEErrnoResolver(MIPSErrnoResolver):
553
+ platform = Platform(Architecture.MIPS64, Byteorder.BIG)
554
+ # mips64 uses the MIPS errno list
555
+
556
+
557
+ class MIPS64ELErrnoResolver(MIPSErrnoResolver):
558
+ platform = Platform(Architecture.MIPS64, Byteorder.LITTLE)
559
+ # mips64el uses the MIPS errno list
560
+
561
+
562
+ class PowerPCErrnoResolver(ErrnoResolver):
563
+ platform = Platform(Architecture.POWERPC32, Byteorder.BIG)
564
+ abi = ABI.SYSTEMV
565
+
566
+ # The ppc errno list is almost identical to generic,
567
+ # except that EDEADLOCK is different.
568
+ #
569
+ # In generic, it's been aliased to EDEADLK,
570
+ # although the ordering of the header suggests that at one time
571
+ # it looked like it does here.
572
+ errno_to_label = ErrnoResolver.errno_to_label | {35: "EDEADLCK", 58: "EDEADLOCK"}
573
+
574
+
575
+ class RiscV64ErrnoResolver(ErrnoResolver):
576
+ platform = Platform(Architecture.RISCV64, Byteorder.LITTLE)
577
+ abi = ABI.SYSTEMV
578
+ # riscv64 uses the generic errno list
579
+
580
+
581
+ __all__ = ["ErrnoResolver"]