Solaris 64位函数指针问题 [英] Solaris 64 bit function pointer problem

查看:28
本文介绍了Solaris 64位函数指针问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:操作系统:Sun Solaris 10处理器:AMD 64位

Environment: OS: Sun Solaris 10 Processor: AMD 64 bit

我有一个使用 net-snmp 库的应用程序.该应用程序可移植(代码级)到各种操作系统和处理器.在 net-snmp 中,您可以注册一个日志回调(一个函数指针),它会在要记录某些内容时被调用.

I have an application which uses net-snmp library. The application is portable (code level) to various OS and processor. In net-snmp, you can register a logging callback (a function pointer) which gets called when something is to be logged.

问题是当我运行应用程序时,当 net-snmp 尝试调用我注册的回调函数时,它会出现段错误.注册的回调地址是 0xffe30b90,但 net-snmp 尝试调用 0xffffffff ffe30b90.

The problem is that when I run the application, it seg faults when net-snmp tries to call the callback function I have registered. The callback address that gets registered is 0xffe30b90 but net-snmp tries to call 0xffffffff ffe30b90.

在调查的过程中,我在同一个应用程序中编写了另一个函数并注册了它.该函数被正确调用,但其地址显示为 0x52e060(无前导 ff).

While investigating, I wrote another function in the same application and registered it. That function gets called properly but it's address shows as 0x52e060 (no leading ff).

我无法弄清楚这里的问题是什么.好像是字节对齐或者指针溢出问题.

I am not able to figure out what the problem here is. It seems to be something related to byte alignment or some pointer overflow problem.

任何进一步调查的指示将不胜感激.谢谢,

Any pointers for further investigation will be appreciated. Thanks,

-法鲁克

推荐答案

听起来好像地址在某处作为有符号的 32 位 int 传递,当转换回 64 位时会进行符号扩展,添加额外的0xFFFF... 位.确保您的代码不假定 int 与任何地方的指针大小相同,因为 Solaris 64 位 ABI 使用LP64"约定,其中 int 是32 位,而 long 和指针是 64 位.

Sounds like somewhere the address is being passed through as a signed 32-bit int, which gets sign-extended when converting back to 64-bit, adding the extra 0xFFFF... bits. Make sure your code doesn't assume that int is the same size as a pointer anywhere, since the Solaris 64-bit ABI uses the "LP64" conventions, where int is 32-bits, while long and pointers are 64-bit.

这篇关于Solaris 64位函数指针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆