github.com/bytedance/mockey@v1.2.10/internal/monkey/mem/write_linux_amd64.s (about) 1 /* 2 * Copyright 2022 ByteDance Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "textflag.h" 18 19 #define NOP8 BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90; BYTE $0x90; 20 #define NOP64 NOP8; NOP8; NOP8; NOP8; NOP8; NOP8; NOP8; NOP8; 21 #define NOP512 NOP64; NOP64; NOP64; NOP64; NOP64; NOP64; NOP64; NOP64; 22 #define NOP4096 NOP512; NOP512; NOP512; NOP512; NOP512; NOP512; NOP512; NOP512; 23 24 #define protRW $(0x1|0x2) 25 #define mProtect $0x0a 26 27 TEXT ·write(SB),NOSPLIT,$24 28 JMP START 29 NOP4096 30 START: 31 MOVQ mProtect, AX 32 MOVQ page+24(FP), DI 33 MOVQ pageSize+32(FP), SI 34 MOVQ protRW, DX 35 SYSCALL 36 CMPQ AX, $0 37 JZ PROTECT_OK 38 JMP RETURN 39 PROTECT_OK: 40 MOVQ target+0(FP), DI 41 MOVQ data+8(FP), SI 42 MOVQ len+16(FP), CX 43 MOVQ DI, to-24(SP) 44 MOVQ SI, from-16(SP) 45 MOVQ CX, n-8(SP) 46 CALL runtime·memmove(SB) 47 MOVQ mProtect, AX 48 MOVQ page+24(FP), DI 49 MOVQ pageSize+32(FP), SI 50 MOVQ oriProt+40(FP), DX 51 SYSCALL 52 JMP RETURN 53 NOP4096 54 RETURN: 55 MOVQ AX, ret+48(FP) 56 RET