Commit c014e15a authored by Mike Frysinger's avatar Mike Frysinger

Blackfin: convert ptrace to new memory functions

Now that we have a Blackfin memory function to figure out how to properly
access the different regions, drop the custom memory range checks in our
ptrace code and use that.  It makes the code nicer and fixes bugs where
the ptrace logic wasn't handling all the different regions.
Signed-off-by: default avatarMike Frysinger <vapier@gentoo.org>
parent 18070dd6
...@@ -206,6 +206,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) ...@@ -206,6 +206,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
{ {
int ret; int ret;
unsigned long __user *datap = (unsigned long __user *)data; unsigned long __user *datap = (unsigned long __user *)data;
void *paddr = (void *)addr;
switch (request) { switch (request) {
/* when I and D space are separate, these will need to be fixed. */ /* when I and D space are separate, these will need to be fixed. */
...@@ -215,42 +216,49 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) ...@@ -215,42 +216,49 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
case PTRACE_PEEKTEXT: /* read word at location addr. */ case PTRACE_PEEKTEXT: /* read word at location addr. */
{ {
unsigned long tmp = 0; unsigned long tmp = 0;
int copied; int copied = 0, to_copy = sizeof(tmp);
ret = -EIO; ret = -EIO;
pr_debug("ptrace: PEEKTEXT at addr 0x%08lx + %ld\n", addr, sizeof(data)); pr_debug("ptrace: PEEKTEXT at addr 0x%08lx + %i\n", addr, to_copy);
if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0) if (is_user_addr_valid(child, addr, to_copy) < 0)
break; break;
pr_debug("ptrace: user address is valid\n"); pr_debug("ptrace: user address is valid\n");
if (L1_CODE_LENGTH != 0 && addr >= get_l1_code_start() switch (bfin_mem_access_type(addr, to_copy)) {
&& addr + sizeof(tmp) <= get_l1_code_start() + L1_CODE_LENGTH) { case BFIN_MEM_ACCESS_CORE:
safe_dma_memcpy (&tmp, (const void *)(addr), sizeof(tmp)); case BFIN_MEM_ACCESS_CORE_ONLY:
copied = sizeof(tmp);
} else if (L1_DATA_A_LENGTH != 0 && addr >= L1_DATA_A_START
&& addr + sizeof(tmp) <= L1_DATA_A_START + L1_DATA_A_LENGTH) {
memcpy(&tmp, (const void *)(addr), sizeof(tmp));
copied = sizeof(tmp);
} else if (L1_DATA_B_LENGTH != 0 && addr >= L1_DATA_B_START
&& addr + sizeof(tmp) <= L1_DATA_B_START + L1_DATA_B_LENGTH) {
memcpy(&tmp, (const void *)(addr), sizeof(tmp));
copied = sizeof(tmp);
} else if (addr >= FIXED_CODE_START
&& addr + sizeof(tmp) <= FIXED_CODE_END) {
copy_from_user_page(0, 0, 0, &tmp, (const void *)(addr), sizeof(tmp));
copied = sizeof(tmp);
} else
copied = access_process_vm(child, addr, &tmp, copied = access_process_vm(child, addr, &tmp,
sizeof(tmp), 0); to_copy, 0);
if (copied)
break;
/* hrm, why didn't that work ... maybe no mapping */
if (addr >= FIXED_CODE_START &&
addr + to_copy <= FIXED_CODE_END) {
copy_from_user_page(0, 0, 0, &tmp, paddr, to_copy);
copied = to_copy;
} else if (addr >= BOOT_ROM_START) {
memcpy(&tmp, paddr, to_copy);
copied = to_copy;
}
pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp);
if (copied != sizeof(tmp))
break; break;
ret = put_user(tmp, datap); case BFIN_MEM_ACCESS_DMA:
if (safe_dma_memcpy(&tmp, paddr, to_copy))
copied = to_copy;
break;
case BFIN_MEM_ACCESS_ITEST:
if (isram_memcpy(&tmp, paddr, to_copy))
copied = to_copy;
break;
default:
copied = 0;
break;
}
pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp);
if (copied == to_copy)
ret = put_user(tmp, datap);
break; break;
} }
...@@ -294,43 +302,50 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) ...@@ -294,43 +302,50 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
/* fall through */ /* fall through */
case PTRACE_POKETEXT: /* write the word at location addr. */ case PTRACE_POKETEXT: /* write the word at location addr. */
{ {
int copied; int copied = 0, to_copy = sizeof(data);
ret = -EIO; ret = -EIO;
pr_debug("ptrace: POKETEXT at addr 0x%08lx + %ld bytes %lx\n", pr_debug("ptrace: POKETEXT at addr 0x%08lx + %i bytes %lx\n",
addr, sizeof(data), data); addr, to_copy, data);
if (is_user_addr_valid(child, addr, sizeof(data)) < 0) if (is_user_addr_valid(child, addr, to_copy) < 0)
break; break;
pr_debug("ptrace: user address is valid\n"); pr_debug("ptrace: user address is valid\n");
if (L1_CODE_LENGTH != 0 && addr >= get_l1_code_start() switch (bfin_mem_access_type(addr, to_copy)) {
&& addr + sizeof(data) <= get_l1_code_start() + L1_CODE_LENGTH) { case BFIN_MEM_ACCESS_CORE:
safe_dma_memcpy ((void *)(addr), &data, sizeof(data)); case BFIN_MEM_ACCESS_CORE_ONLY:
copied = sizeof(data);
} else if (L1_DATA_A_LENGTH != 0 && addr >= L1_DATA_A_START
&& addr + sizeof(data) <= L1_DATA_A_START + L1_DATA_A_LENGTH) {
memcpy((void *)(addr), &data, sizeof(data));
copied = sizeof(data);
} else if (L1_DATA_B_LENGTH != 0 && addr >= L1_DATA_B_START
&& addr + sizeof(data) <= L1_DATA_B_START + L1_DATA_B_LENGTH) {
memcpy((void *)(addr), &data, sizeof(data));
copied = sizeof(data);
} else if (addr >= FIXED_CODE_START
&& addr + sizeof(data) <= FIXED_CODE_END) {
copy_to_user_page(0, 0, 0, (void *)(addr), &data, sizeof(data));
copied = sizeof(data);
} else
copied = access_process_vm(child, addr, &data, copied = access_process_vm(child, addr, &data,
sizeof(data), 1); to_copy, 0);
if (copied)
break;
/* hrm, why didn't that work ... maybe no mapping */
if (addr >= FIXED_CODE_START &&
addr + to_copy <= FIXED_CODE_END) {
copy_to_user_page(0, 0, 0, paddr, &data, to_copy);
copied = to_copy;
} else if (addr >= BOOT_ROM_START) {
memcpy(paddr, &data, to_copy);
copied = to_copy;
}
pr_debug("ptrace: copied size %d\n", copied);
if (copied != sizeof(data))
break; break;
ret = 0; case BFIN_MEM_ACCESS_DMA:
if (safe_dma_memcpy(paddr, &data, to_copy))
copied = to_copy;
break;
case BFIN_MEM_ACCESS_ITEST:
if (isram_memcpy(paddr, &data, to_copy))
copied = to_copy;
break;
default:
copied = 0;
break;
}
pr_debug("ptrace: copied size %d\n", copied);
if (copied == to_copy)
ret = 0;
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment