Re: [PATCH v7 3.2-rc2 5/30] uprobes: copy of the originalinstruction.

From: Peter Zijlstra
Date: Mon Nov 28 2011 - 09:24:05 EST


On Fri, 2011-11-18 at 16:37 +0530, Srikar Dronamraju wrote:
> +static int __copy_insn(struct address_space *mapping,
> + struct vm_area_struct *vma, char *insn,
> + unsigned long nbytes, unsigned long offset)
> +{
> + struct file *filp = vma->vm_file;
> + struct page *page;
> + void *vaddr;
> + unsigned long off1;
> + unsigned long idx;
> +
> + if (!filp)
> + return -EINVAL;
> +
> + idx = (unsigned long)(offset >> PAGE_CACHE_SHIFT);
> + off1 = offset &= ~PAGE_MASK;
> +
> + /*
> + * Ensure that the page that has the original instruction is
> + * populated and in page-cache.
> + */
> + page = read_mapping_page(mapping, idx, filp);
> + if (IS_ERR(page))
> + return -ENOMEM;
> +
> + vaddr = kmap_atomic(page);
> + memcpy(insn, vaddr + off1, nbytes);
> + kunmap_atomic(vaddr);
> + page_cache_release(page);
> + return 0;
> +}
> +
> +static int copy_insn(struct uprobe *uprobe, struct vm_area_struct *vma,
> + unsigned long addr)
> +{
> + struct address_space *mapping;
> + int bytes;
> + unsigned long nbytes;
> +
> + addr &= ~PAGE_MASK;
> + nbytes = PAGE_SIZE - addr;
> + mapping = uprobe->inode->i_mapping;
> +
> + /* Instruction at end of binary; copy only available bytes */
> + if (uprobe->offset + MAX_UINSN_BYTES > uprobe->inode->i_size)
> + bytes = uprobe->inode->i_size - uprobe->offset;
> + else
> + bytes = MAX_UINSN_BYTES;
> +
> + /* Instruction at the page-boundary; copy bytes in second page */
> + if (nbytes < bytes) {
> + if (__copy_insn(mapping, vma, uprobe->insn + nbytes,
> + bytes - nbytes, uprobe->offset + nbytes))
> + return -ENOMEM;

You just lost your possible -EINVAL return value.

> +
> + bytes = nbytes;
> + }
> + return __copy_insn(mapping, vma, uprobe->insn, bytes, uprobe->offset);
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/