C-syscall-64位-指针 [英] C - syscall - 64-bit - pointer

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

问题描述

我在64位Linux x86上.我需要使用syscall函数执行mmap syscall. mmap系统调用号码为9:

I am on 64-bit Linux x86. I need to execute mmap syscall using syscall function. mmap syscall number is 9:

printf("mmap-1: %lli\n", syscall(9,    0, 10, 3, 2 | 32, -1, 0));
printf("mmap-2: %lli\n", mmap(         0, 10, 3, 2 | 32, -1, 0));

但是,当我运行它时,syscall函数会给出错误的结果.

However, when I run it, the syscall function gives wrong results.

mmap-1: 2236940288
mmap-2: 140503502090240

mmap-1: 3425849344
mmap-2: 140612065181696

mmap-1: 249544704
mmap-2: 139625341366272

mmap可以正常工作,但是返回的syscall"addresss"结果为Segmentation fault. syscall中的值似乎被强制转换为32位或其他内容.

mmap works just fine, but the "addresses" returned syscall result in Segmentation fault. The values from syscall seem to be cast to 32 bits or something.

我在做什么错了?

推荐答案

找到了问题的原因:我正在使用-std=c99选项运行gcc,将其删除可以解决问题:

Found the cause of the problem: I was running gcc with -std=c99 option, removing it solved the problem:

mmap-1: 139975263928320
mmap-2: 139975263924224

我想,-std=99将syscall定义为int syscall(),而没有它的long syscall().

I guess, -std=99 defines syscall as int syscall() and without it its long syscall().

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

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