mirror of
https://github.com/openharmony/third_party_openhitls.git
synced 2026-08-26 19:50:30 -04:00
a2275a5119
Co-authored-by: dumb<liuermeng2@huawei.com> # message auto-generated for no-merge-commit merge: merge riscv_ci into main preparing for riscv-CI Created-by: dumb Commit-by: dumb Merged-by: liwei3013 Description: preparing for riscv-CI See merge request: openHiTLS/openhitls!582 Signed-off-by: Dongjianwei001 <dongjianwei1@huawei.com>
72 lines
2.1 KiB
C
72 lines
2.1 KiB
C
/*
|
|
* This file is part of the openHiTLS project.
|
|
*
|
|
* openHiTLS is licensed under the Mulan PSL v2.
|
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
* You may obtain a copy of Mulan PSL v2 at:
|
|
*
|
|
* http://license.coscl.org.cn/MulanPSL2
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
* See the Mulan PSL v2 for more details.
|
|
*/
|
|
|
|
#ifndef STUB_REPALCE_H
|
|
#define STUB_REPALCE_H
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
#if defined(__x86_64__)
|
|
/*
|
|
* The first 14 bytes of the function entry are used to construct the jump instruction.
|
|
* Short jump instruction is 5 bytes, and Long jump instruction is 14 bytes.
|
|
*/
|
|
#define CODESIZE 14U
|
|
// TODO: the riscv codesize is not confirmed yet
|
|
#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__riscv) || defined (__riscv64)
|
|
/* ARM64 needs 16 bytes to construct the jump instruction. */
|
|
#define CODESIZE 16U
|
|
#elif defined(__arm__)
|
|
/* ARM32 needs 12 bytes to construct the jump instruction. */
|
|
#define CODESIZE 12U
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct {
|
|
void *fn;
|
|
unsigned char codeBuf[CODESIZE];
|
|
} FuncStubInfo;
|
|
|
|
/*
|
|
* Initialize the dynamic stub change function. Invoke the function once.
|
|
* return - 0:Success, non-zero:Error code
|
|
*/
|
|
int STUB_Init(void);
|
|
|
|
/*
|
|
* Replaces the specified function with the specified stub function.
|
|
* stubInfo - Record information about stub replacement, which is used for STUB_Reset restoration.
|
|
* srcFn - Functions in the source code
|
|
* stubFn - Need to replace the stub function that is inserted into the run.
|
|
* return - 0:Success, non-zero:Error code
|
|
*/
|
|
int STUB_Replace(FuncStubInfo *stubInfo, void *srcFn, const void *stubFn);
|
|
|
|
/*
|
|
* Restore the source function and remove the instrumentation.
|
|
* stubInfo - Information logged when instrumentation
|
|
* return - 0:Success, non-zero:Error code
|
|
*/
|
|
int STUB_Reset(FuncStubInfo *stubInfo);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // STUB_REPALCE_H
|