I think I found the bit I was missing. Overall things are still pretty confusing and they might benefit from some general refactoring in which 64 bit support is designed from the get-go instead of added later, but this MR should at least be an improvement over the current situation, so I'm marking it as ready again.