I am writing a small utility in assembler. I am trying to throw an exception if one of the parameters is out of range. The bound instruction does not seem available in 64bit mode. What is the correct way to invoke this interrupt?
Asked
Active
Viewed 43 times
1
-
You should check Intel manual, to check which instruction will throw int 5, and in which cases. It is not really a nasm thing, nor a linux-kernel thing (so your tags are incorrect) – Giacomo Catenazzi Jul 27 '20 at 08:57
-
I'm going to guess this is about x86-64, adding the relevant tags. Feel free to change those if that's not the case. – Marco Bonelli Jul 27 '20 at 09:45
-
2Note that `int 5` will probably not work, for the same reason `int 0` doesn't work as an alternative to `div` overflow or by zero. - [Why linux kernel use trap gate to handle divide\_error exception?](https://stackoverflow.com/a/15501983) explains that `int 0` from user-space fails the permission check on the trap gate, resulting in a GPF instead of an actual int 0. Also, `int` may push slightly different stuff on the kernel stack than a true `div` exception would, so the kernel needs to stop people from reaching a handler that expects to return a different way. – Peter Cordes Jul 27 '20 at 13:15
-
Sorry for the mistagging. It was late and hard to keep details. The ultimate goal is to make sure a couple of parameters (array related) are within bounds. The specificity of the error can be handled via stdout. I will check the post. Thanks – bichito Jul 27 '20 at 15:27