-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check in assembly files, fix some comments, remove unused function
- Loading branch information
Showing
7 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
tests/chapter_18/valid/no_structure_parameters/size_and_offset_calculations/member_offsets.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/chapter_18/valid/params_and_returns/big_data_on_page_boundary_linux.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.bss # .bss is the last segment in the program image - the page after it will be unampped | ||
.align 4096 # force page alignment | ||
.zero 4078 # write a bunch of zeros so on_page_boundary is at the end of the page | ||
.globl on_page_boundary | ||
on_page_boundary: | ||
.zero 18 | ||
.section ".note.GNU-stack","",@progbits |
6 changes: 6 additions & 0 deletions
6
tests/chapter_18/valid/params_and_returns/big_data_on_page_boundary_osx.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.bss # .bss is the last segment in the program image - the page after it will be unampped | ||
.align 12 # force page alignment (2^12 == 4096) | ||
.zero 4078 # write a bunch of zeros so on_page_boundary is at the end of the page | ||
.globl _on_page_boundary | ||
_on_page_boundary: | ||
.zero 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
tests/chapter_18/valid/params_and_returns/return_space_address_overlap_linux.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# validate that space allocated for return address does not overlap | ||
# with storage for other objects we can access from callee (this is an ABI requirement) | ||
# case 1: overlap w/ global variable | ||
.data | ||
.globl globvar | ||
.align 8 | ||
globvar: | ||
.zero 24 | ||
.text | ||
# globvar = overlap_with_globvar() | ||
.globl overlap_with_globvar | ||
overlap_with_globvar: | ||
# load address of globvar into RSI | ||
leaq globvar(%rip), %rsi | ||
# make sure return address (in RDI) and globvar's address (in RSI) | ||
# are at least 24 bytes apart | ||
subq %rdi, %rsi | ||
# get absolute value of difference between addresses (in RSI) | ||
# (absolute value implementation from https://stackoverflow.com/a/11927940) | ||
movq %rsi, %rcx # copy RSI into RCX | ||
negq %rsi # negate RSI | ||
# if RSI is now negative, its restore original (positive) value | ||
cmovl %rcx, %rsi | ||
# compare diference to 24 | ||
cmpq $24, %rsi | ||
jl .Loverlap_detected | ||
# no overlap, so go ahead and return value | ||
movq $400, (%rdi) | ||
movq $500, 8(%rdi) | ||
movq $600, 16(%rdi) | ||
movq %rdi, %rax | ||
ret | ||
.Loverlap_detected: | ||
# space for return value overlaps w/ globvar, so exit with error code | ||
movl $1, %edi | ||
call exit | ||
|
||
# case 2: overlap w/ pointer passed as arg | ||
# x = overlap_with_pointer(&x) | ||
.globl overlap_with_pointer | ||
overlap_with_pointer: | ||
# copy pointer into RDX | ||
leaq globvar(%rip), %rdx | ||
# make sure return address (in RDI) and globvar's address (in RDX) | ||
# are at least 24 bytes apart | ||
subq %rdi, %rdx | ||
# get absolute value of difference between addresses (in RDX) | ||
# (absolute value implementation from https://stackoverflow.com/a/11927940) | ||
movq %rdx, %rcx # copy RDX into RCX | ||
negq %rdx # negate RDX | ||
# if rdx is now negative, its restore original (positive) value | ||
cmovl %rcx, %rdx | ||
# compare diference to 24 | ||
cmpq $24, %rdx | ||
jl .Loverlap_detected.0 | ||
# no overlap, so go ahead and return value | ||
# set each member to twice its original value (accessed thru RSI) | ||
# l1 | ||
movq (%rsi), %rcx | ||
imul $2, %rcx | ||
movq %rcx, (%rdi) | ||
# l2 | ||
movq 8(%rsi), %rcx | ||
imul $2, %rcx | ||
movq %rcx, 8(%rdi) | ||
# l3 | ||
movq 16(%rsi), %rcx | ||
imul $2, %rcx | ||
movq %rcx, 16(%rdi) | ||
movq %rdi, %rax | ||
ret | ||
.Loverlap_detected.0: | ||
# space for return value overlaps w/ space pointed to by argument, so exit with error code | ||
movl $3, %edi | ||
call exit |
75 changes: 75 additions & 0 deletions
75
tests/chapter_18/valid/params_and_returns/return_space_address_overlap_osx.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# validate that space allocated for return address does not overlap | ||
# with storage for other objects we can access from callee (this is an ABI requirement) | ||
# case 1: overlap w/ global variable | ||
.data | ||
.globl _globvar | ||
.align 3 | ||
_globvar: | ||
.zero 24 | ||
.text | ||
# globvar = overlap_with_globvar() | ||
.globl _overlap_with_globvar | ||
_overlap_with_globvar: | ||
# load address of globvar into RSI | ||
leaq _globvar(%rip), %rsi | ||
# make sure return address (in RDI) and globvar's address (in RSI) | ||
# are at least 24 bytes apart | ||
subq %rdi, %rsi | ||
# get absolute value of difference between addresses (in RSI) | ||
# (absolute value implementation from https://stackoverflow.com/a/11927940) | ||
movq %rsi, %rcx # copy RSI into RCX | ||
negq %rsi # negate RSI | ||
# if RSI is now negative, its restore original (positive) value | ||
cmovl %rcx, %rsi | ||
# compare diference to 24 | ||
cmpq $24, %rsi | ||
jl Loverlap_detected | ||
# no overlap, so go ahead and return value | ||
movq $400, (%rdi) | ||
movq $500, 8(%rdi) | ||
movq $600, 16(%rdi) | ||
movq %rdi, %rax | ||
ret | ||
Loverlap_detected: | ||
# space for return value overlaps w/ globvar, so exit with error code | ||
movl $1, %edi | ||
call _exit | ||
|
||
# case 2: overlap w/ pointer passed as arg | ||
# x = overlap_with_pointer(&x) | ||
.globl _overlap_with_pointer | ||
_overlap_with_pointer: | ||
# copy pointer into RDX | ||
movq %rsi, %rdx | ||
# make sure return address (in RDI) and pointer's address (in RDX) | ||
# are at least 24 bytes apart | ||
subq %rdi, %rdx | ||
# get absolute value of difference between addresses (in RDX) | ||
# (absolute value implementation from https://stackoverflow.com/a/11927940) | ||
movq %rdx, %rcx # copy RDX into RCX | ||
negq %rdx # negate RDX | ||
# if rdx is now negative, its restore original (positive) value | ||
cmovl %rcx, %rdx | ||
# compare diference to 24 | ||
cmpq $24, %rdx | ||
jl Loverlap_detected.0 | ||
# no overlap, so go ahead and return value | ||
# set each member to twice its original value (accessed thru RSI) | ||
# l1 | ||
movq (%rsi), %rcx | ||
imul $2, %rcx | ||
movq %rcx, (%rdi) | ||
# l2 | ||
movq 8(%rsi), %rcx | ||
imul $2, %rcx | ||
movq %rcx, 8(%rdi) | ||
# l3 | ||
movq 16(%rsi), %rcx | ||
imul $2, %rcx | ||
movq %rcx, 16(%rdi) | ||
movq %rdi, %rax | ||
ret | ||
Loverlap_detected.0: | ||
# space for return value overlaps w/ space pointed to by argument, so exit with error code | ||
movl $3, %edi | ||
call _exit |