memcpy.S revision 68b67113a44311b3568027af5893e316f63ec556
17c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris/*
27c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * Copyright (C) 2008 The Android Open Source Project
37c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * All rights reserved.
47c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *
57c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * Redistribution and use in source and binary forms, with or without
67c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * modification, are permitted provided that the following conditions
77c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * are met:
87c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *  * Redistributions of source code must retain the above copyright
97c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *    notice, this list of conditions and the following disclaimer.
107c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *  * Redistributions in binary form must reproduce the above copyright
117c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *    notice, this list of conditions and the following disclaimer in
127c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *    the documentation and/or other materials provided with the
137c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *    distribution.
147c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris *
157c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
167c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
177c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
187c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
197c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
207c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
217c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
227c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
237c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
247c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
257c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
267c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * SUCH DAMAGE.
277c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris */
287c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris
297c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris/* Assumes neon instructions and a cache line size of 32 bytes. */
307c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris
317c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris#include <machine/asm.h>
32eb847bc8666842a3cfc9c06e8458ad1abebebaf0Elliott Hughes#include "private/libc_events.h"
337c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris
347c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris/*
357c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * This code assumes it is running on a processor that supports all arm v7
367c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * instructions, that supports neon instructions, and that has a 32 byte
377c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris * cache line.
387c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris */
397c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris
407c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris        .text
415f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .syntax unified
427c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris        .fpu    neon
435f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .thumb
445f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .thumb_func
457c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris
4659a13c122ebc4191583b67c846a95d690dcda5cfChristopher FerrisENTRY(__memcpy_chk)
475f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_startproc
4859a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        cmp         r2, r3
4916e185c9081530859c17270fbaf5798f0ea871f8Christopher Ferris        bhi         __memcpy_chk_fail
5059a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris
5159a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        // Fall through to memcpy...
525f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_endproc
5359a13c122ebc4191583b67c846a95d690dcda5cfChristopher FerrisEND(__memcpy_chk)
547c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris
557c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher FerrisENTRY(memcpy)
565f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_startproc
575f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        pld     [r1, #64]
585f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        stmfd   sp!, {r0, lr}
59a57c9c084bc686a35f4f494ce23cf2a9bb3d5d00Christopher Ferris        .save   {r0, lr}
605f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_def_cfa_offset 8
615f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_rel_offset r0, 0
625f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_rel_offset lr, 4
635f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_endproc
645f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher FerrisEND(memcpy)
657c83a1ed81a15f3e75836c1ac7d500a952f02e10Christopher Ferris
66a57c9c084bc686a35f4f494ce23cf2a9bb3d5d00Christopher Ferris#define MEMCPY_BASE         __memcpy_base
67a57c9c084bc686a35f4f494ce23cf2a9bb3d5d00Christopher Ferris#define MEMCPY_BASE_ALIGNED __memcpy_base_aligned
68a57c9c084bc686a35f4f494ce23cf2a9bb3d5d00Christopher Ferris#include "memcpy_base.S"
69a57c9c084bc686a35f4f494ce23cf2a9bb3d5d00Christopher Ferris
7032bbf8a63bb43a540cc0f1dd5037736d10b70e0bNick KralevichENTRY_PRIVATE(__memcpy_chk_fail)
715f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_startproc
725f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        // Preserve lr for backtrace.
735f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        push    {lr}
74a57c9c084bc686a35f4f494ce23cf2a9bb3d5d00Christopher Ferris        .save   {lr}
755f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_def_cfa_offset 4
765f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_rel_offset lr, 0
7759a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris
7859a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        ldr     r0, error_message
7959a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        ldr     r1, error_code
8059a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris1:
8159a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        add     r0, pc
8259a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        bl      __fortify_chk_fail
8359a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferriserror_code:
8459a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        .word   BIONIC_EVENT_MEMCPY_BUFFER_OVERFLOW
8559a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferriserror_message:
865f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .word   error_string-(1b+4)
875f45d583b0cfb4f7bed1447e8eed003a529cc69eChristopher Ferris        .cfi_endproc
88a57c9c084bc686a35f4f494ce23cf2a9bb3d5d00Christopher FerrisEND(__memcpy_chk_fail)
8959a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris
9059a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferris        .data
9159a13c122ebc4191583b67c846a95d690dcda5cfChristopher Ferriserror_string:
9268b67113a44311b3568027af5893e316f63ec556Elliott Hughes        .string     "memcpy: prevented write past end of buffer"
93