Skip to content
Snippets Groups Projects
Select Git revision
  • fcbc38b1b296cd38214891fb1fc714d52937d062
  • openEuler-1.0-LTS default protected
  • openEuler-22.09
  • OLK-5.10
  • openEuler-22.03-LTS
  • openEuler-22.03-LTS-Ascend
  • master
  • openEuler-22.03-LTS-LoongArch-NW
  • openEuler-22.09-HCK
  • openEuler-20.03-LTS-SP3
  • openEuler-21.09
  • openEuler-21.03
  • openEuler-20.09
  • 4.19.90-2210.5.0
  • 5.10.0-123.0.0
  • 5.10.0-60.63.0
  • 5.10.0-60.62.0
  • 4.19.90-2210.4.0
  • 5.10.0-121.0.0
  • 5.10.0-60.61.0
  • 4.19.90-2210.3.0
  • 5.10.0-60.60.0
  • 5.10.0-120.0.0
  • 5.10.0-60.59.0
  • 5.10.0-119.0.0
  • 4.19.90-2210.2.0
  • 4.19.90-2210.1.0
  • 5.10.0-118.0.0
  • 5.10.0-106.19.0
  • 5.10.0-60.58.0
  • 4.19.90-2209.6.0
  • 5.10.0-106.18.0
  • 5.10.0-106.17.0
33 results

insn.c

Blame
  • insn.c 15.20 KiB
    /*
     * x86 instruction analysis
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 2 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     *
     * Copyright (C) IBM Corporation, 2002, 2004, 2009
     */
    
    #ifdef __KERNEL__
    #include <linux/string.h>
    #else
    #include <string.h>
    #endif
    #include <asm/inat.h>
    #include <asm/insn.h>
    
    /* Verify next sizeof(t) bytes can be on the same instruction */
    #define validate_next(t, insn, n)	\
    	((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
    
    #define __get_next(t, insn)	\
    	({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; })
    
    #define __peek_nbyte_next(t, insn, n)	\
    	({ t r = *(t*)((insn)->next_byte + n); r; })
    
    #define get_next(t, insn)	\
    	({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
    
    #define peek_nbyte_next(t, insn, n)	\
    	({ if (unlikely(!validate_next(t, insn, n))) goto err_out; __peek_nbyte_next(t, insn, n); })
    
    #define peek_next(t, insn)	peek_nbyte_next(t, insn, 0)
    
    /**
     * insn_init() - initialize struct insn
     * @insn:	&struct insn to be initialized
     * @kaddr:	address (in kernel memory) of instruction (or copy thereof)
     * @x86_64:	!0 for 64-bit kernel or 64-bit app
     */
    void insn_init(struct insn *insn, const void *kaddr, int buf_len, int x86_64)
    {
    	/*
    	 * Instructions longer than MAX_INSN_SIZE (15 bytes) are invalid
    	 * even if the input buffer is long enough to hold them.
    	 */
    	if (buf_len > MAX_INSN_SIZE)
    		buf_len = MAX_INSN_SIZE;
    
    	memset(insn, 0, sizeof(*insn));
    	insn->kaddr = kaddr;
    	insn->end_kaddr = kaddr + buf_len;
    	insn->next_byte = kaddr;
    	insn->x86_64 = x86_64 ? 1 : 0;
    	insn->opnd_bytes = 4;
    	if (x86_64)
    		insn->addr_bytes = 8;
    	else