[foreign] Handling pointers with special (negative) values
Jorn Vernee
jbvernee at xs4all.nl
Thu Oct 25 11:02:48 UTC 2018
Hello,
I was in the process of adding a windows equivalent for the getpid test.
The windows equivalent calls GetCurrentProcess [1] to get a handle to
the current process, and then calls GetProcessId [2] using that handle.
The problem is that the returned handle for the current process has a
special value, which after converting to a Java long shows up as -1.
It's type is `void *` ([3] see `HANDLE`).
The constructor of BoundedMemoryRegion checks to make sure that the base
(i.e. `min`) is not smaller than 0, but in this case it is, so an IAE is
thrown [4].
I have simply removed the check on `min` and all tests that I'm running
currently are still passing, but I don't think this is a definitive
solution. I wanted to bring this up to discuss how we should handle
pointers with special (negative) values, or pointers that otherwise end
up negative after converting to a Java long. Perhaps there was some
earlier discussion about this that I missed?
Jorn
[1] :
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getcurrentprocess
[2] :
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getprocessid
[3] :
https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types
[4] :
http://hg.openjdk.java.net/panama/dev/file/4b634b7d0cdb/src/java.base/share/classes/jdk/internal/foreign/memory/BoundedMemoryRegion.java#l74
More information about the panama-dev
mailing list