x86-64

Assembly x86 brk() call use

喜欢而已 提交于 2019-11-29 07:48:17
i am trying to dynamically allocate memory into the heap and then assign values in those memory addresses. I understand how to allocate the memory but how would i assign for example the value in a register to that first dynamic memory address? This is what i have so far:` push rbp mov rbp, rsp ;initialize an empy stack to create activation records for the rest of the subroutines mov rax, 0x2d ;linux system call for brk() mov rbx, 0x0 ;to get the adress of the first adress we are allocating we must have 0 in rbx int 0x80 ;calls the linux operating system kernel for assistance mov [brk

Syscall from inline asm in x86_64 Linux?

穿精又带淫゛_ 提交于 2019-11-29 07:47:35
问题 Why does this print garbage instead of exiting my program gracefully? I use system calls this way on BSD, and I wonder what would I need to make it work in Linux. int main(int argc, char **argv) { __asm ("movq $1,%rax; movq $0,%rdi; syscall"); /* exit(0) ? */ return 0; } Thanks. 回答1: Why does this print garbage instead of exiting my program gracefully? Per CESA-2009-001, "Syscall 1 is exit on i386 but write on x86_64". what would I need to make it work in Linux Use the syscall ordinals from

Why is RCX not used for passing parameters to system calls, being replaced with R10? [duplicate]

守給你的承諾、 提交于 2019-11-29 07:38:47
This question already has an answer here: Linux x64: why does r10 come before r8 and r9 in syscalls? 2 answers According to System V X86-64 ABI , function calls in the applications use the following sequence of registers to pass integer arguments: rdi, rsi, rdx, rcx, r8, r9 But system call arguments (other than syscall number) are passed in another sequence of registers: rdi, rsi, rdx, r10, r8, r9 Why does the kernel use r10 instead of rcx for the fourth argument? Is it somehow related to the fact that rcx is not preserved while r10 is? X86-64 system calls use syscall instruction. This

Using interrupt 0x80 on 64-bit Linux [duplicate]

对着背影说爱祢 提交于 2019-11-29 07:28:11
This question already has an answer here: What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code? 1 answer I have a simple 64-bit assembly program which is intended to print an 'O' and 'K' followed by a newline. However, the 'K' is never printed. One of the goals of the programs is to print the value in the lower bits of the rax register as ASCII letter. The program is specifically for 64-bit Linux, written for educational purposes, so there is no need to use C-style system calls. I suspect that the problem either lies with mov QWORD [rsp], rax or mov rcx, rsp . Currently, the

zero out top 32 bits of 64-bit register

[亡魂溺海] 提交于 2019-11-29 07:24:18
Using amd64 assembly, whats the best way to zero out the top 32 bits of a 64-bit register, e.g. zero out the bits of rax that are not covered by eax? It appears that I cannot and the whole register against a 64-bit constant. movl %eax, %eax or mov eax, eax , depending on the assembler in use. see: Intel® 64 and IA-32 Architectures - Software Developer’s Manual, Volume 1 , 3.4.1.1 : General-Purpose Registers in 64-Bit Mode. 32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the destination general-purpose register. I should also add, in regards to @HansPassant's

Making assembly function inline in x64 Visual Studio

寵の児 提交于 2019-11-29 07:22:45
I know that MSVC compiler in x64 mode does not support inline assembly snippets of code, and in order to use assembly code you have to define your function in some external my_asm_funcs.asm file like that: my_asm_func PROC mov rax, rcx ret my_asm_func ENDP And then in your .c or .h file you define a header for the function like that: int my_asm_func(int x); Although that solution answers many concerns, but I am still interested in making that assembly code function to be inline, in other words - after compilation I don't want any "calls" to my_asm_func , I just want this piece of assembly to

How to install python2.6-devel package under CentOs 5

两盒软妹~` 提交于 2019-11-29 07:06:09
I need to install mysql-python under python2.6. mysql-python package needs python2.6-devel package that depends on the libpython2.6.so.1.0(64bit) I found on the net some python2.6-devel packages, but can't find libpython2.6 Server architecture is x86_64. Maybe someone have this lib, or know where i can find it. Thanks for help) I have the same issue and this wonderful link solved it for me... http://blog.milford.io/2010/08/new-method-for-installing-python-2-6-4-with-mysql-python-on-centos-5-5/ I followed some of the steps out of order because I was a little antsy and got some interesting error

Anyone can understand how gettimeofday works?

耗尽温柔 提交于 2019-11-29 06:53:36
gettimeofday is a syscall of x86-86 according to this page (just search gettimeofday in the box): int gettimeofday(struct timeval *tv, struct timezone *tz); I thought the disas should be easy anough, just prepare the two pointers and call the related syscall . But its disas is doing much more: (gdb) disas gettimeofday Dump of assembler code for function gettimeofday: 0x00000034f408c2d0 <gettimeofday+0>: sub $0x8,%rsp 0x00000034f408c2d4 <gettimeofday+4>: mov $0xffffffffff600000,%rax 0x00000034f408c2db <gettimeofday+11>: callq *%rax 0x00000034f408c2dd <gettimeofday+13>: cmp $0xfffff001,%eax

How to optimize function return values in C and C++ on x86-64?

一笑奈何 提交于 2019-11-29 06:11:06
The x86-64 ABI specifies two return registers: rax and rdx , both 64-bits (8 bytes) in size. Assuming that x86-64 is the only targeted platform, which of these two functions: uint64_t f(uint64_t * const secondReturnValue) { /* Calculate a and b. */ *secondReturnValue = b; return a; } std::pair<uint64_t, uint64_t> g() { /* Calculate a and b, same as in f() above. */ return { a, b }; } would yield better performance, given the current state of C/C++ compilers targeting x86-64? Are there any pitfalls performance-wise using one or the other version? Are compilers (GCC, Clang) always able to

Can an x64 application use x86 assemblies - and vice versa?

前提是你 提交于 2019-11-29 05:26:13
My application is built as a x64 application. After moving to VS2010 I got some problems which seems to be related to some x64/x86 mismatch in referenced dlls. Now I'm moving to target .NET4, and I get even more similar problems . My question is: What precautions do I need to take regarding mixing x64 and x86. Can it be done at all? I thought x64 applications should be able to use x86 dlls without problems. No? What about the other way? Can a x86 application reference an x64 dll - as long as it is being run on an x64 platform? What are the pitfalls I need to be aware of? No, a 64-bit process