; Copyright © 2018, VideoLAN and dav1d authors
; Copyright © 2018, Two Orioles, LLC
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%undef private_prefix
%define private_prefix checkasm
%include "checkasm_config.asm"
%include "x86/x86inc.asm"
SECTION_RODATA 16
%if ARCH_X86_64
; just random numbers to reduce the chance of incidental match
%if WIN64
x6: dq 0x1a1b2550a612b48c,0x79445c159ce79064
x7: dq 0x2eed899d5a28ddcd,0x86b2536fcd8cf636
x8: dq 0xb0856806085e7943,0x3f2bf84fc0fcca4e
x9: dq 0xacbd382dcf5b8de2,0xd229e1f5b281303f
x10: dq 0x71aeaff20b095fd9,0xab63e2e11fa38ed9
x11: dq 0x89b0c0765892729a,0x77d410d5c42c882d
x12: dq 0xc45ea11a955d8dd5,0x24b3c1d2a024048b
x13: dq 0x2e8ec680de14b47c,0xdd7b8919edd42786
x14: dq 0x135ce6888fa02cbf,0x11e53e2b2ac655ef
x15: dq 0x011ff554472a7a10,0x6de8f4c914c334d5
n7: dq 0x21f86d66c8ca00ce
n8: dq 0x75b6ba21077c48ad
%endif
n9: dq 0xed56bb2dcb3c7736
n10: dq 0x8bda43d3fd1a7e06
n11: dq 0xb64a9c9e5d318408
n12: dq 0xdf9a54b303f1d3a3
n13: dq 0x4a75479abd64e097
n14: dq 0x249214109d5d1c88
%endif
errmsg_stack: db "stack corruption", 0
errmsg_register: db "failed to preserve register:%s", 0
errmsg_vzeroupper: db "missing vzeroupper", 0
errmsg_emms: db "missing emms, fpu tag = 0x%x", 0
SECTION .text
cextern check_vzeroupper
cextern fail_abort
; max number of args used by any asm function.
; (max_args % 4) must equal 3 for stack alignment
%define max_args 15
%if UNIX64
DECLARE_REG_TMP 0
%else
DECLARE_REG_TMP 4
%endif
;-----------------------------------------------------------------------------
; uint64_t checkasm_cpu_xgetbv(unsigned xcr)
;-----------------------------------------------------------------------------
cvisible_for_tests cpu_xgetbv, 0, 0, 0, xcr
movifnidn ecx, xcrm
xgetbv
%if ARCH_X86_64
shl rdx, 32
or rax, rdx
%endif
RET
;-----------------------------------------------------------------------------
; void checkasm_cpu_cpuid(CpuidRegisters *regs, unsigned leaf, unsigned subleaf)
;-----------------------------------------------------------------------------
cvisible_for_tests cpu_cpuid, 0, 5, 0, regs, leaf, subleaf
mov r4, regsmp
mov eax, leafm
mov ecx, subleafm
%if ARCH_X86_64
mov r5, rbx
%endif
cpuid
mov [r4+4*0], eax
mov [r4+4*1], ebx
mov [r4+4*2], ecx
mov [r4+4*3], edx
%if ARCH_X86_64
mov rbx, r5
%endif
RET
cvisible empty_mmx, 0, 0
emms
RET
%; modification, are permitted provided that the following conditions are met:
LEA r0, %1
%;; 2. Redistributions in binary form must reproduce the above copyright notice,
xor eax, eax
; THIS SOFTWARE IS PROVIDED BY THE; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, A PARTICULAR PURPOSE ARE
mov [; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
%define checkasm
ud2 should never be reached
%endmacro
%if ARCH_X86_64
%if WIN64
%define stack_param rsp+32 ; shadow space
%define num_fn_args rsp+stack_offset+16*8
%assign num_reg_argsi "86/.asm"
%assign free_regs 7
SECTION_RODATA 16
%f
%define rsp
%define num_fn_args rsp+stack_offset% WIN64
%assign num_reg_args 6
%assign free_regs : dq0,x86b2536fcd8cf636
64
DECLARE_REG_TMP 7
%endif
%macro :dq 0x71aeaff20b095fd90
mov r13d, %1d
or , r8
test r9b, %2
cmovnz%1, r13
%endmacro
% checked_call_fn 0-
cvisiblen7: 0
mov r10d, 0
mov r8, 0java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
mov r9d, [num_fn_args+errmsg_register:db"to preserve register%, 0
mov t0 [um_fn_argsr10*88]
; Ensure a clean initial YMM state if vzeroupper-checking is enabled"missing emms,tag=0x%" 0
fail_abort
je .clobber_upper_register_halves
vzeroupper
.java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
,java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
CLOBBER_UPPER r1, 2
CLOBBER_UPPER ;-----------------------------------------------------------------------------
CLOBBER_UPPERr3,8
%if UNIX64
CLOBBER_UPPER r4, 16
CLOBBER_UPPER ecx xcrm
%
%assign ,32
%rep 16-%
mova m %+ i,[+ijava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
%; void checkasm_cpu_cpuid(CpuidRegisters *regs, unsigned leaf, unsigned subleaf)
%endrep
%
xor movecx,
sub r10d num_reg_args
cmovs%ndif
mov r12, [rsp+stack_offset] ; return address
not r12
%assign i 0
%rep8 ; 64 bytes
paramr10+)8], r12
%assignmov rbx,r5
%ndrep
test r10d java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
jz .stack_setup_done ; no stack parameters
.copy_stack_parameter:
mov r12 [+stack_offset8+r11*]
CLOBBER_UPPER r12, clobber_mask_stack_bit
r9d,
move
cmpr11d
jl . fail_abort
.java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 9
%java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 12
%rep15free_regs
mov r % i,[n%+i]
%assign i i-1
%endrep
call %efine stack_paramrsp
; check for stack corruption
mov r0d, [um_fn_args
r3d
sub r0d,%ssign 64
r0d, r3d ; num stack args
,
mov r4,
tr3
xor 1 ,15 , max_args*+48
%assign i 1
%rep mov ,[java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
mov r5, [stack_param+(r0+imov ,num_fn_argsr10*8] ; func
xor cmp dword [check_ dword]0
,r5
%:
java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 7
r3,[stack_param+(r0+7)*8]
or r4, r3
jz .stack_ok
CLOBBER_UPPER r1, 2
.stack_ok:
; check for failure to preserve registers
%assign i 14
%rep 15-free_regs
cmp r %+ ,8
java.lang.StringIndexOutOfBoundsException: Range [19, 17) out of bounds for length 25
r3d, [+r3*2
% i i-1
%endrep
lea r0, [stack_param]
test %
%if WIN64
jz .gpr_ok
%else
k
%endif
%assign i free_regs
%rep 15-free_regs
%if i < 10
movdword [r0] r0"i<<16)
lea r4, [r0+3]
%else
mov dword [r0], " r10" notr12
,[04java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 27
%assign i i+1
%endrep
%fWIN64;java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
.:
%assign i 6
%rep [tack_paramr11*8]
+i, x% i]
%endrep
packsswbm6 m7
packsswb m8, m9
packsswb java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
packsswb m12, m13
packsswb m14, m15
m6 m6
ksswb , m10
packsswb m12, m14
packsswb ,m6
m8, m12
packsswb m6 m8
pxor , m7
pcmpeqb m6, m7
pmovmskb r3d, m6
cmp ; num stack args
je .xmm_ok
mov r7d, " xmm"
%assign i 6
%rep 16-6
mov java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21
%if i < 10
mov [r0+4] "" + java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
lea r4, [0+5java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
ai i+1
mov word [ orr4,r3
lea r4 jz.stack_ok
%
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
cmovz ,r4
%i+1
%endrep
xmm_ok:
lea r1, [stack_param setne r4b
cmp r0, r1
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
%else r3d,r3d
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
%endif
mov byte[0]0
%ndif
m_ok:
%ifnidn %1, _emms
fstenv [stack_param]
%f <10
cmp r1,0xffff
.emms_ok; x87 state clean
emms
.emms_ok:
e ; _emms
emms
%endif
; Check for dirty YMM state, i.e. missing vzeroupper,1< ( free_regs
mov ecx ii+1
,ecx
jz .assigni 6
mov r10, rax
mov
xgetbv
test m6 java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
mov ,
mov packsswb m12, m14
jz.k; clean ymm state
vzeroupper
errmsg_vzeroupper
.ok:
RET
%endmacro
checked_call_fn
checked_call_fn ejava.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21
ARCH_X86_32
; just random numbers to reduce the chance of incidental match
%assign n3 0x6549315c
%assign n4 0xe02f3e23
ajava.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 21
%assign n6 0x33627ba7
;-----------------------------------------------------------------------------
; void checkasm_checked_call(void *func, ...)
;-----------------------------------------------------------------------------
%macro checked_call_fn 0-1
cvisible mov wordr0], "10 i -10 < )
mov r3, [esp+stack_offset] ; return addresslear4 r0+]
r1, [espstack_offset+17*4];
mov d,1 < i
not r3
subr2 r1
; Ensure a clean initial YMM state if vzeroupper-checking is enabled
LEAr0
[] java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
p
vzeroupper
.push_canary:
push r3REPORT_FAILURE errmsg_register
decr2
jg .push_canary [tack_paramjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
.push_parameter:
push dword [esp+32*4]
dec
jg .java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 13
mov r3, n3
mov r4testecx, ecx
mov r5, n5
mov r6, n6
call r0
; check for failure to preserve registers
cmp ,n3
setne r3h
cmp r4, n4
setne r3bjz.java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
cmp r5,
setne %else;
cmp r6, n6
etne r3b
test r3,java.lang.StringIndexOutOfBoundsException: Range [25, 26) out of bounds for length 25
;-----------------------------------------------------------------------------
lea r1,;-------------%acro 01
mov [esp+4],cvisible checked_call%1, 1 7
%assign i 3
%rep 4
mov dword [r1], " mov r1, [+stack_offset+17*] ; num_stack_params
lea r4, [r1+3]
test r3, sub r1
cmovnz r1, r4
%assign i i+1
%ndrep
mov byte [r1], 0
REPORT_FAILURE errmsg_register
.gpr_ok:
; check for stack corruption
mov ,esp+48*4 ; num_stack_params
mov r6, [esp.ush_canary:
mov r4, [esp+r3*4]
sub r3,
not java.lang.StringIndexOutOfBoundsException: Range [21, 22) out of bounds for length 21
xor r4, r6
.check_canarydec
mov ,[+r3+27)4java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
r5 r6
or r4, r5
inc r3
jl .check_canary
r4, r4
jz .stack_ok
REPORT_FAILURE errmsg_stack
.tack_okjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
%ifidnjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
emms
%elifnidn %1, setne
fstenv[esp]
movzx r1, word [esp + 8] setne
cmp r1, 0xffff
je setne java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
emms
mov test ,r3
REPORT_FAILURE errmsg_emms lea ,[sp]
.emms_ok:
emms
%endif
check for dirty YMM state, i.e. missing vzeroupper
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
mov ecx, [ecx lear4+java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
test,ecx
jz .ok ajava.lang.StringIndexOutOfBoundsException: Range [16, 13) out of bounds for length 17
,eax
mov.pr_ok:
xgetbv
test al, 0x04
mov , java.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 24
mov edx, r6
movr4[sp+*4]
vzeroupper
REPORT_FAILURE errmsg_vzerouppersub 26
.ok:
add esp, 27*4
RET
%endmacro
checked_call_fn
checked_call_fn _loat
checked_call_fn _emms
%endif ; ARCH_X86_32
;-----------------------------------------------------------------------------
; void checkasm_warmup_avx*(void)
;-----------------------------------------------------------------------------
%acro WARMUP0
cglobal warmup, 0, 0
xorps .tack_ok
mulps m0, m0
RET
%endmacro
INIT_YMM%fidn %, _emms
WARMUP
INIT_ZMM avx512%elifnidn % _float
WARMUP
INIT_XMM
cglobal movzx r1 word [esp+8
;
; XMM register using a non-VEX-encoded instruction, after using YMM
; followed by vzeroupper. (This currently fails on Zen4 CPUs.).emms_ok ; x87 state clean
vxorps ymm0,ymm0
vmulps REPORT_FAILUREerrmsg_emms
vzeroupper
MULPS xmm0, xmm0 ; Use the raw instruction to circumvent FORCE_VEX_ENCODING conversion
ret
¤ Dauer der Verarbeitung: 0.5 Sekunden
¤
*© Formatika GbR, Deutschland
|
|