x86-64

why we can't move a 64-bit immediate value to memory?

泪湿孤枕 提交于 2020-07-09 05:15:53
问题 First I am a little bit confused with the differences between movq and movabsq , my text book says: The regular movq instruction can only have immediate source operands that can be represented as 32-bit two’s-complement numbers. This value is then sign extended to produce the 64-bit value for the destination. The movabsq instruction can have an arbitrary 64-bit immediate value as its source operand and can only have a register as a destination. I have two questions to this. Question 1 The

why we can't move a 64-bit immediate value to memory?

跟風遠走 提交于 2020-07-09 05:14:31
问题 First I am a little bit confused with the differences between movq and movabsq , my text book says: The regular movq instruction can only have immediate source operands that can be represented as 32-bit two’s-complement numbers. This value is then sign extended to produce the 64-bit value for the destination. The movabsq instruction can have an arbitrary 64-bit immediate value as its source operand and can only have a register as a destination. I have two questions to this. Question 1 The

Get size of x86-64 instruction

∥☆過路亽.° 提交于 2020-07-05 07:51:12
问题 I need a function which can calculate the length of an x86-64 instruction. For example, it would be usable like so: char ret[] = { 0xc3 }; size_t length = instructionLength(ret); length would be set to 1 in this example. I do not want to include an entire disassembly library, since the only information I require is the length of the instruction. I am looking for a minimalist approach, written in C, and ideally as small as possible. 100% complete x86-64 instruction set is not strictly

How do canary words allow gcc to detect buffer overflows?

那年仲夏 提交于 2020-07-03 09:45:52
问题 I could test using strncpy() with larger source string then the destination: int main() { char *ptr = malloc(12); strcpy(ptr,"hello world!"); return 0; } Compiling with the flag -fstack-protector and using the -S option I got: .file "malloc.c" .text .globl main .type main, @function main: .LFB2: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $32, %rsp movl %edi, -20(%rbp) movq %rsi, -32(%rbp) movq %fs:40, %rax movq %rax, -8(

How do canary words allow gcc to detect buffer overflows?

喜欢而已 提交于 2020-07-03 09:45:18
问题 I could test using strncpy() with larger source string then the destination: int main() { char *ptr = malloc(12); strcpy(ptr,"hello world!"); return 0; } Compiling with the flag -fstack-protector and using the -S option I got: .file "malloc.c" .text .globl main .type main, @function main: .LFB2: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $32, %rsp movl %edi, -20(%rbp) movq %rsi, -32(%rbp) movq %fs:40, %rax movq %rax, -8(

Segfault when loading function parameter into a register

拜拜、爱过 提交于 2020-06-28 05:04:21
问题 I'm quite new to x86 assembly, and I'm trying to build off a hello world program. I'm trying to make a subroutine, that writes a single byte to stdout, but i've hit a problem. The line mov ebx, [esp+1] (to load the byte passed, when I call the subroutine) causes a segfault. I've tried xoring the ebx register with itself, to make sure that it is empty, to make sure, that it doesn't mess with the syscall _start: push 32h call _writeByte ; This just jumps to an exit routine jmp _exit _writeByte:

Problems with getcwd syscall on OSX

坚强是说给别人听的谎言 提交于 2020-06-28 02:56:07
问题 Does anyone have an idea how to get the current working directory in OSX with NASM? The syscall getcwd isn't available on osx and dtruss pwd return lots of stat sys calls. However in the manual I can't find which structure variable of stat returns the current working directory. Thanks. 回答1: That's a bit late answer, but nonetheless this can be achieved using 2 syscalls. open_nocancel 0x2000018e (or open 0x2000005) opening a file descriptor for current dir fcntl_nocancel 0x20000196 (or fcntl

Why does TZCNT work for my Sandy Bridge processor?

99封情书 提交于 2020-06-27 08:17:19
问题 I'm running a Core i7 3930k, which is of the Sandy Bridge microarchitecture. When executing the following code (compiled under MSVC19, VS2015), the results surprised me (see in comments): int wmain(int argc, wchar_t* argv[]) { uint64_t r = 0b1110'0000'0000'0000ULL; uint64_t tzcnt = _tzcnt_u64(r); cout << tzcnt << endl; // prints 13 int info[4]{}; __cpuidex(info, 7, 0); int ebx = info[1]; cout << bitset<32>(ebx) << endl; // prints 32 zeros (including the bmi1 bit) return 0; } Disassembly shows

segment limit check in AMD 64-bit mode

一世执手 提交于 2020-06-17 17:07:29
问题 I am writing my own OS for 64bit processors and I am stuck with the problem of general protection. My OS will not rely on page fault to implement user space protection mechanism, so I found there is a way to do it with segment limit checking: This presentation from VMWare http://download3.vmware.com/vmworld/2005/pac346.pdf on page 20 says: Initial AMD64 architecture did not include segmentation in 64-bit mode Segmentation also missing from EMT64T How do we protect the VMM ? 64-bit guest

storage register for scanf call in gas

倖福魔咒の 提交于 2020-06-17 15:47:06
问题 I am trying to understand scanf function a have 3 question regarding it. this is c file: #include <stdio.h> #include <stdlib.h> int main(){ int x; printf("Enter X:\n"); scanf("%i",&x); printf("You entered %d...\n",x); return 0; } and here is gas: .text .section .rodata .LC0: .string "Enter X:" .LC1: .string "%i" .LC2: .string "You entered %d...\n" .text .globl main .type main, @function main: pushq %rbp # movq %rsp, %rbp #, subq $16, %rsp #, # a.c:5: printf("Enter X:\n"); leaq .LC0(%rip),