[英]why is va_arg returning wrong data?
I am trying to port an embedded OS to a new platform and I am facing some problems with the filesystem component. 我试图将嵌入式OS移植到新平台,并且文件系统组件遇到一些问题。 I stepped in the code to finally localize the problem: The function call relevant to my case is 我进入了代码,终于对问题进行了定位:与我的情况相关的函数调用是
// int64_t vnid = 1;
// int32_t vid = 0;
...
vnode = queue_lookup (& vnode_manager . vnode_list,
vnode_id_inspector, vnid, vid);
And here is the queue_lookup declaration: 这是queue_lookup声明:
void * queue_lookup (queue_t * queue, queue_inspector_t inspector, ...)
{
bool result;
va_list list, list_copy;
queue_link_t * item = NULL;
va_start (list, inspector);
if (queue -> status != 0)
{
for (item = queue -> head; item != NULL; item = item -> next)
{
result = false;
va_copy (list_copy, list);
result = inspector (item, list_copy);
va_end (list_copy);
if (result) break;
}
}
va_end (list);
return item;
}
and finally, here is the vnode_id_inspector declaration: 最后是vnode_id_inspector声明:
bool vnode_id_inspector (void * node, va_list list)
{
vnode_t vnode = node;
int64_t vnid = va_arg (list, int64_t);
int32_t vid = va_arg (list, int32_t);
watch (bool)
{
ensure (vnode != NULL, false);
return vnode -> id == vnid && vnode -> volume -> id == vid;
}
}
Now the problem is when I call queue_lookup with vnid=1 and vid=0, I get vnid=1 and vid=1145248 in the vnode_id_inspector ! 现在的问题是,当我用vnid = 1和vid = 0调用queue_lookup时,我在vnode_id_inspector中得到了vnid = 1和vid = 1145248!
How can I fix this issue with as minimum code change as possible ? 如何以尽可能少的代码更改来解决此问题?
Regards, 问候,
Edit: add some debug info 编辑:添加一些调试信息
(gdb) p vnode_manager . vnode_list
$44 = {lock = 1, head = 0x167770, tail = 0x167770, status = 1}
(gdb) p vnode_manager . vnode_list ->head
$45 = (queue_link_t *) 0x167770
(gdb) p *(vnode_t)vnode_manager . vnode_list ->head
$46 = {link = {next = 0x0}, id = 1, volume = 0x166370, destroy = false,
usage_counter = 1, data = 0x166430}
(gdb) p *(volume_t)((vnode_t)vnode_manager . vnode_list ->head)->volume
$47 = {link = {next = 0x0}, id = 0, root_vnid = 1, lock = 0, host_volume = 0x0,
host_vnid = -1, cmd = 0x13a768 <rootfs_cmd>, data = 0x1663d0}
I solved this issue, there was a problem in the stack alignment. 我解决了这个问题,堆栈对齐出现了问题。 I fixed it by making some adjustment in the cpu_context_switch.s to align the stack to 8bytes instead of 4bytes . 我通过使在cpu_context_switch.s一些调整以对齐堆叠到8个字节 ,而不是4字节固定它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.