相关疑难解决方法(0)

如果在64位代码中使用32位int 0x80 Linux ABI会发生什么?

int 0x80在Linux上总是调用32位ABI,不管是什么模式,这就是所谓的:在args ebx,ecx...和系统调用号的/usr/include/asm/unistd_32.h.(或者在没有编译的64位内核上崩溃CONFIG_IA32_EMULATION).

64位代码应该使用syscall,从呼叫号码/usr/include/asm/unistd_64.h,并在args rdi,rsi等见什么调用约定UNIX和Linux系统上的i386和x86-64调用.如果您的问题被打上这样一个重复的,看你怎么说链接,细节应当使32位或64位代码的系统调用. 如果你想了解到底发生了什么,请继续阅读.


sys_write系统调用比syscall系统调用快,所以使用本机64位,int 0x80除非你正在编写多格式机器代码,当执行32或64位时运行相同的机器代码.(syscall始终以32位模式返回,因此它在64位用户空间中没有用,尽管它是有效的x86-64指令.)

相关:Linux系统的权威指南(在x86上)调用如何进行sysenterint 0x8032位系统调用,或sysenter64位系统调用,或调用vDSO进行"虚拟"系统调用syscall.加上有关系统调用的背景知识.


使用gettimeofday可以编写将以32位或64位模式组合的内容,因此它可以int 0x80在微基准测试结束时使用.

标准化函数和系统调用约定的官方i386和x86-64 System V psABI文档的当前PDF文件链接自https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI.

有关初学者指南,x86手册,官方文档和性能优化指南/资源,请参阅标记wiki.


但是,由于人们不断发布与使用代码的问题exit_group()在64位代码,或不小心建立64位二进制文件从源代码对于32位写的,我不知道是什么确切不会对当前的Linux怎样呢?

是否int 0x80保存/恢复所有的64位寄存器?它会将任何寄存器截断为32位吗?如果传递上半部分非零的指针args会发生什么?

如果你传递32位指针它是否有效?

linux assembly x86-64 system-calls abi

36
推荐指数
1
解决办法
4783
查看次数

x86程序集pushl/popl不能与"错误:后缀或操作数无效"

我是汇编编程的新手,在GNU汇编程序v2.20.1的Ubuntu x86_64桌面上使用Programming Ground Up.

我已经能够组装/链接执行我的代码,直到我使用pushl/popl指令来操作堆栈.以下代码无法汇编:

 .section .data  # empty

 .section .text
.globl _start
_start:
 pushl $1       # push the value 1 onto the stack
 popl %eax      # pop 1 off the stack and into the %eax register
 int $0x80      # exit the program with exit code '1'
Run Code Online (Sandbox Code Playgroud)

使用"as test.s -o test.o",这些错误出现在终端上并且未创建test.o:

test.s: Assembler messages: 
test.s:9: Error: suffix or operands invalid for 'push'
test.s:10:  Error: suffix or operands invalid for 'popl'
Run Code Online (Sandbox Code Playgroud)

我检查了文档,我用于pushl和popl的操作数是有效的.这不是一个调试问题 - 所以我的代码出了什么问题?或者是我的汇编程序?

x86 assembly x86-64

27
推荐指数
3
解决办法
3万
查看次数

当我没有指定操作数大小时,push指令压入堆栈的字节数是多少?

我可以通过这样做将4个字节压入堆栈:

push DWORD 123
Run Code Online (Sandbox Code Playgroud)

但我发现我可以在push不指定操作数大小的情况下使用:

push 123
Run Code Online (Sandbox Code Playgroud)

在这种情况下,push指令将多少字节压入堆栈?推送的字节数是否取决于操作数大小(因此在我的示例中它将推送1个字节)?

x86 assembly

11
推荐指数
2
解决办法
7188
查看次数

访问损坏的共享库

这里是代码cpuid2.s

#cpuid2.s view the cpuid vendor id string using c library calls
.section .data
output:
    .asciz "The processor Vendor ID is '%s'\n"

.section .bss
    .lcomm buffer, 12

.section .text
.global _start
_start:
    movl $0, %eax
    cpuid
    movl $buffer, %edi
    movl %ebx, (%edi)
    movl %edx, 4(%edi)
    movl %ecx, 8(%edi)
    push $buffer
    push $output
    call printf
    addl $8, %esp
    push $0
    call exit
Run Code Online (Sandbox Code Playgroud)

我按如下方式组装、链接和运行它:

as -o cpuid2.o cpuid2.s
ld -dynamic-linker /lib/ld-linux.so.2 -o cpuid2 -lc cpuid2.o
./cpuid2
bash: ./cpuid2: Accessing a …
Run Code Online (Sandbox Code Playgroud)

x86 assembly 32bit-64bit

4
推荐指数
1
解决办法
6621
查看次数

标签 统计

assembly ×4

x86 ×3

x86-64 ×2

32bit-64bit ×1

abi ×1

linux ×1

system-calls ×1