3e6526575a
This is an initial cut at aarch64 support. I have only qemu to test it however—hopefully hardware will be coming soon. This also affects 32-bit ARM in that aarch64 chips can run 32-bit code and we would like to be able to take advantage of the crypto operations even in 32-bit mode. AES and GHASH should Just Work in this case: the -armx.pl files can be built for either 32- or 64-bit mode based on the flavour argument given to the Perl script. SHA-1 and SHA-256 don't work like this however because they've never support for multiple implementations, thus BoringSSL built for 32-bit won't use the SHA instructions on an aarch64 chip. No dedicated ChaCha20 or Poly1305 support yet. Change-Id: Ib275bc4894a365c8ec7c42f4e91af6dba3bd686c Reviewed-on: https://boringssl-review.googlesource.com/2801 Reviewed-by: Adam Langley <agl@google.com>
131 lines
3.4 KiB
C++
131 lines
3.4 KiB
C++
/* Copyright (c) 2014, Google Inc.
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
|
|
|
#include <openssl/base.h>
|
|
|
|
// This file isn't built on ARM or Aarch64 because we link statically in those
|
|
// builds and trying to override malloc in a static link doesn't work.
|
|
#if defined(__linux__) && !defined(OPENSSL_ARM) && !defined(OPENSSL_AARCH64)
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
|
|
#include <new>
|
|
|
|
|
|
/* This file defines overrides for the standard allocation functions that allow
|
|
* a given allocation to be made to fail for testing. If the program is run
|
|
* with MALLOC_NUMBER_TO_FAIL set to a base-10 number then that allocation will
|
|
* return NULL. If MALLOC_ABORT_ON_FAIL is also defined then the allocation
|
|
* will abort() rather than return NULL.
|
|
*
|
|
* This code is not thread safe. */
|
|
|
|
static uint64_t current_malloc_count = 0;
|
|
static uint64_t malloc_number_to_fail = 0;
|
|
static char failure_enabled = 0, abort_on_fail = 0;
|
|
static int in_call = 0;
|
|
|
|
extern "C" {
|
|
/* These are other names for the standard allocation functions. */
|
|
extern void *__libc_malloc(size_t size);
|
|
extern void *__libc_calloc(size_t num_elems, size_t size);
|
|
extern void *__libc_realloc(void *ptr, size_t size);
|
|
}
|
|
|
|
static void exit_handler(void) {
|
|
if (failure_enabled && current_malloc_count > malloc_number_to_fail) {
|
|
_exit(88);
|
|
}
|
|
}
|
|
|
|
static void cpp_new_handler() {
|
|
// Return to try again. It won't fail a second time.
|
|
return;
|
|
}
|
|
|
|
/* should_fail_allocation returns true if the current allocation should fail. */
|
|
static int should_fail_allocation() {
|
|
static int init = 0;
|
|
char should_fail;
|
|
|
|
if (in_call) {
|
|
return 0;
|
|
}
|
|
|
|
in_call = 1;
|
|
|
|
if (!init) {
|
|
const char *env = getenv("MALLOC_NUMBER_TO_FAIL");
|
|
if (env != NULL && env[0] != 0) {
|
|
char *endptr;
|
|
malloc_number_to_fail = strtoull(env, &endptr, 10);
|
|
if (*endptr == 0) {
|
|
failure_enabled = 1;
|
|
atexit(exit_handler);
|
|
std::set_new_handler(cpp_new_handler);
|
|
}
|
|
}
|
|
abort_on_fail = (NULL != getenv("MALLOC_ABORT_ON_FAIL"));
|
|
init = 1;
|
|
}
|
|
|
|
in_call = 0;
|
|
|
|
if (!failure_enabled) {
|
|
return 0;
|
|
}
|
|
|
|
should_fail = (current_malloc_count == malloc_number_to_fail);
|
|
current_malloc_count++;
|
|
|
|
if (should_fail && abort_on_fail) {
|
|
abort();
|
|
}
|
|
return should_fail;
|
|
}
|
|
|
|
extern "C" {
|
|
|
|
void *malloc(size_t size) {
|
|
if (should_fail_allocation()) {
|
|
return NULL;
|
|
}
|
|
|
|
return __libc_malloc(size);
|
|
}
|
|
|
|
void *calloc(size_t num_elems, size_t size) {
|
|
if (should_fail_allocation()) {
|
|
return NULL;
|
|
}
|
|
|
|
return __libc_calloc(num_elems, size);
|
|
}
|
|
|
|
void *realloc(void *ptr, size_t size) {
|
|
if (should_fail_allocation()) {
|
|
return NULL;
|
|
}
|
|
|
|
return __libc_realloc(ptr, size);
|
|
}
|
|
|
|
} // extern "C"
|
|
|
|
#endif /* defined(linux) && !ARM && !AARCH64 */
|