Why does this program receive a SEGV?Why doesn't “cd” work in a shell script?Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?Why does the C preprocessor interpret the word “linux” as the constant “1”?Why does ENOENT mean “No such file or directory”?How to determine whether the computer has an XT/AT keyboard in assembly?C++ code for testing the Collatz conjecture faster than hand-written assembly - why?Why does GCC use multiplication by a strange number in implementing integer division?Avoiding the JMP in the JMP CALL POP technique for shellcode NASM?Why doesn't this attempt at using sys_write do anything?Why does a syscall clobber rcx?

Do index funds really have double-digit percents annual return rates?

What is the most likely cause of short, quick, and useless reviews?

Do I need to get a noble in order to win Splendor?

Would you recommend a keyboard for beginners with or without lights in keys for learning?

MOSFET broke after attaching capacitor bank

To which airspace does the border of two adjacent airspaces belong to?

Are there photos of the Apollo LM showing disturbed lunar soil resulting from descent engine exhaust?

slowest crash on the Moon?

IEEE Registration Authority mac prefix

'This one' as a pronoun

How many days for hunting?

How to find better food in airports

Is it rude to ask my opponent to resign an online game when they have a lost endgame?

What's the difference between a share and a stock?

Did the US Climate Reference Network Show No New Warming Since 2005 in the US?

How to describe hit point damage without talking about wounds

Question about derivation of kinematics equations

Finder/Terminal: Find files that contain less than 21 lines of text

Is there a name for this metric: TN / (TN + FN)?

How could a planet have one hemisphere way warmer than the other without the planet being tidally locked?

What happens when there is no available physical memory left for SQL Server?

What does "se jouer" mean here?

How will the UK Commons debate tonight despite the prorogation?

Punishment in pacifist society



Why does this program receive a SEGV?


Why doesn't “cd” work in a shell script?Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?Why does the C preprocessor interpret the word “linux” as the constant “1”?Why does ENOENT mean “No such file or directory”?How to determine whether the computer has an XT/AT keyboard in assembly?C++ code for testing the Collatz conjecture faster than hand-written assembly - why?Why does GCC use multiplication by a strange number in implementing integer division?Avoiding the JMP in the JMP CALL POP technique for shellcode NASM?Why doesn't this attempt at using sys_write do anything?Why does a syscall clobber rcx?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have the following program, which (I think) allocates a bunch of virtual memory (by changing the system break with sys_brk), and then attempts to write to the newly allocated memory. However, I am receiving a SIGSEGV (on the very first memory write, and I don't understand why).



[OP@localhost sys_brk]$ cat out_of_memory.s 
.section .text
.globl _start

_start:
mov $12, %rax
mov $0x1000000, %rdi
syscall


# i: index of memory we are writing to (%rax)
mov $0x403000, %rax
evil_loop_start:
cmp $0x1000000, %rax
jge evil_loop_end

mov %rax, (%rax)
add 0x8, %rax
jmp evil_loop_start
evil_loop_end:
hlt









share|improve this question





















  • 1





    call sys_brk with the value of 0 to get the current brk in RAX. Add the amount of extra space you want to RAX and then call sys_brk again with the value as a parameter.

    – Michael Petch
    Mar 28 at 3:35






  • 1





    You also need to use add $0x8, %rax to add 8 to rax. You forgot the $ for an immediate value. HLT will segfault as well. You should use sys_exit syscall

    – Michael Petch
    Mar 28 at 3:40












  • @MichaelPetch Thanks. Why does HLT segfault?

    – extremeaxe5
    Mar 28 at 6:38






  • 1





    HLT is a privileged instruction and can't be run in user mode (ring 3). It can only be used in the kernel (ring 0) or real mode.

    – Michael Petch
    Mar 28 at 6:41











  • @MichaelPetch I was under the impression that segfault occurred when a program attempted an invalid memory access.

    – extremeaxe5
    Mar 28 at 6:43

















1















I have the following program, which (I think) allocates a bunch of virtual memory (by changing the system break with sys_brk), and then attempts to write to the newly allocated memory. However, I am receiving a SIGSEGV (on the very first memory write, and I don't understand why).



[OP@localhost sys_brk]$ cat out_of_memory.s 
.section .text
.globl _start

_start:
mov $12, %rax
mov $0x1000000, %rdi
syscall


# i: index of memory we are writing to (%rax)
mov $0x403000, %rax
evil_loop_start:
cmp $0x1000000, %rax
jge evil_loop_end

mov %rax, (%rax)
add 0x8, %rax
jmp evil_loop_start
evil_loop_end:
hlt









share|improve this question





















  • 1





    call sys_brk with the value of 0 to get the current brk in RAX. Add the amount of extra space you want to RAX and then call sys_brk again with the value as a parameter.

    – Michael Petch
    Mar 28 at 3:35






  • 1





    You also need to use add $0x8, %rax to add 8 to rax. You forgot the $ for an immediate value. HLT will segfault as well. You should use sys_exit syscall

    – Michael Petch
    Mar 28 at 3:40












  • @MichaelPetch Thanks. Why does HLT segfault?

    – extremeaxe5
    Mar 28 at 6:38






  • 1





    HLT is a privileged instruction and can't be run in user mode (ring 3). It can only be used in the kernel (ring 0) or real mode.

    – Michael Petch
    Mar 28 at 6:41











  • @MichaelPetch I was under the impression that segfault occurred when a program attempted an invalid memory access.

    – extremeaxe5
    Mar 28 at 6:43













1












1








1








I have the following program, which (I think) allocates a bunch of virtual memory (by changing the system break with sys_brk), and then attempts to write to the newly allocated memory. However, I am receiving a SIGSEGV (on the very first memory write, and I don't understand why).



[OP@localhost sys_brk]$ cat out_of_memory.s 
.section .text
.globl _start

_start:
mov $12, %rax
mov $0x1000000, %rdi
syscall


# i: index of memory we are writing to (%rax)
mov $0x403000, %rax
evil_loop_start:
cmp $0x1000000, %rax
jge evil_loop_end

mov %rax, (%rax)
add 0x8, %rax
jmp evil_loop_start
evil_loop_end:
hlt









share|improve this question
















I have the following program, which (I think) allocates a bunch of virtual memory (by changing the system break with sys_brk), and then attempts to write to the newly allocated memory. However, I am receiving a SIGSEGV (on the very first memory write, and I don't understand why).



[OP@localhost sys_brk]$ cat out_of_memory.s 
.section .text
.globl _start

_start:
mov $12, %rax
mov $0x1000000, %rdi
syscall


# i: index of memory we are writing to (%rax)
mov $0x403000, %rax
evil_loop_start:
cmp $0x1000000, %rax
jge evil_loop_end

mov %rax, (%rax)
add 0x8, %rax
jmp evil_loop_start
evil_loop_end:
hlt






linux assembly x86-64 system-calls gas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 3:46









Michael Petch

31.2k6 gold badges60 silver badges119 bronze badges




31.2k6 gold badges60 silver badges119 bronze badges










asked Mar 28 at 3:22









extremeaxe5extremeaxe5

2141 silver badge7 bronze badges




2141 silver badge7 bronze badges










  • 1





    call sys_brk with the value of 0 to get the current brk in RAX. Add the amount of extra space you want to RAX and then call sys_brk again with the value as a parameter.

    – Michael Petch
    Mar 28 at 3:35






  • 1





    You also need to use add $0x8, %rax to add 8 to rax. You forgot the $ for an immediate value. HLT will segfault as well. You should use sys_exit syscall

    – Michael Petch
    Mar 28 at 3:40












  • @MichaelPetch Thanks. Why does HLT segfault?

    – extremeaxe5
    Mar 28 at 6:38






  • 1





    HLT is a privileged instruction and can't be run in user mode (ring 3). It can only be used in the kernel (ring 0) or real mode.

    – Michael Petch
    Mar 28 at 6:41











  • @MichaelPetch I was under the impression that segfault occurred when a program attempted an invalid memory access.

    – extremeaxe5
    Mar 28 at 6:43












  • 1





    call sys_brk with the value of 0 to get the current brk in RAX. Add the amount of extra space you want to RAX and then call sys_brk again with the value as a parameter.

    – Michael Petch
    Mar 28 at 3:35






  • 1





    You also need to use add $0x8, %rax to add 8 to rax. You forgot the $ for an immediate value. HLT will segfault as well. You should use sys_exit syscall

    – Michael Petch
    Mar 28 at 3:40












  • @MichaelPetch Thanks. Why does HLT segfault?

    – extremeaxe5
    Mar 28 at 6:38






  • 1





    HLT is a privileged instruction and can't be run in user mode (ring 3). It can only be used in the kernel (ring 0) or real mode.

    – Michael Petch
    Mar 28 at 6:41











  • @MichaelPetch I was under the impression that segfault occurred when a program attempted an invalid memory access.

    – extremeaxe5
    Mar 28 at 6:43







1




1





call sys_brk with the value of 0 to get the current brk in RAX. Add the amount of extra space you want to RAX and then call sys_brk again with the value as a parameter.

– Michael Petch
Mar 28 at 3:35





call sys_brk with the value of 0 to get the current brk in RAX. Add the amount of extra space you want to RAX and then call sys_brk again with the value as a parameter.

– Michael Petch
Mar 28 at 3:35




1




1





You also need to use add $0x8, %rax to add 8 to rax. You forgot the $ for an immediate value. HLT will segfault as well. You should use sys_exit syscall

– Michael Petch
Mar 28 at 3:40






You also need to use add $0x8, %rax to add 8 to rax. You forgot the $ for an immediate value. HLT will segfault as well. You should use sys_exit syscall

– Michael Petch
Mar 28 at 3:40














@MichaelPetch Thanks. Why does HLT segfault?

– extremeaxe5
Mar 28 at 6:38





@MichaelPetch Thanks. Why does HLT segfault?

– extremeaxe5
Mar 28 at 6:38




1




1





HLT is a privileged instruction and can't be run in user mode (ring 3). It can only be used in the kernel (ring 0) or real mode.

– Michael Petch
Mar 28 at 6:41





HLT is a privileged instruction and can't be run in user mode (ring 3). It can only be used in the kernel (ring 0) or real mode.

– Michael Petch
Mar 28 at 6:41













@MichaelPetch I was under the impression that segfault occurred when a program attempted an invalid memory access.

– extremeaxe5
Mar 28 at 6:43





@MichaelPetch I was under the impression that segfault occurred when a program attempted an invalid memory access.

– extremeaxe5
Mar 28 at 6:43












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389684%2fwhy-does-this-program-receive-a-segv%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55389684%2fwhy-does-this-program-receive-a-segv%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현