日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

android libc 有哪些函数_Android scudo功能介绍

發(fā)布時(shí)間:2024/7/5 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android libc 有哪些函数_Android scudo功能介绍 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一 簡(jiǎn)述

前面介紹了malloc_debug功能,用來(lái)進(jìn)行內(nèi)存泄露等檢測(cè),其實(shí)android可以使用多種方法進(jìn)行內(nèi)存相關(guān)的監(jiān)控。比如利用llvm功能再編譯時(shí)添加內(nèi)存的相關(guān)檢測(cè)。Android R默認(rèn)開(kāi)啟了scudo。

scudo這個(gè)選項(xiàng)主要功能是再分配內(nèi)存時(shí)會(huì)添加64 bit的Header

// Our header requires 64 bits of storage. Having the offset saves us from

// using functions such as GetBlockBegin, that is fairly costly. Our first

// implementation used the MetaData as well, which offers the advantage of

// being stored away from the chunk itself, but accessing it was costly as

// well. The header will be atomically loaded and stored.

typedef u64 PackedHeader;

struct UnpackedHeader {

u64 Checksum : 16;

u64 ClassId : 8;

u64 SizeOrUnusedBytes : 20; // Size for Primary backed allocations, amount of

// unused bytes in the chunk for Secondary ones.

u64 State : 2; // available, allocated, or quarantined

u64 AllocType : 2; // malloc, new, new[], or memalign

u64 Offset : 16; // Offset from the beginning of the backend

// allocation to the beginning of the chunk

// itself, in multiples of MinAlignment. See

// comment about its maximum value and in init().

};

開(kāi)啟scudo后支持的報(bào)錯(cuò)類型有如下,主要是用來(lái)進(jìn)行邊界檢查,檢測(cè)內(nèi)存越界

void NORETURN reportCallocOverflow(uptr Count, uptr Size);

void NORETURN reportPvallocOverflow(uptr Size);

void NORETURN reportAllocationAlignmentTooBig(uptr Alignment,

uptr MaxAlignment);

void NORETURN reportAllocationAlignmentNotPowerOfTwo(uptr Alignment);

void NORETURN reportInvalidPosixMemalignAlignment(uptr Alignment);

void NORETURN reportInvalidAlignedAllocAlignment(uptr Size, uptr Alignment);

void NORETURN reportAllocationSizeTooBig(uptr UserSize, uptr TotalSize,

uptr MaxSize);

void NORETURN reportRssLimitExceeded();

void NORETURN reportOutOfMemory(uptr RequestedSize);

二 android R開(kāi)啟scudo功能

Android R使用的不是llvm的scudo功能,因此不是通過(guò)soong的scudo的開(kāi)啟來(lái)開(kāi)啟,主要使用如下選項(xiàng)

MALLOC_SVELTE := true

go版本默認(rèn)是關(guān)閉scudo功能的。

非go版本四都開(kāi)啟scudo功能的,不過(guò)不是通過(guò)llvm開(kāi)啟,開(kāi)啟的方法

libc_scudo_product_variables

在 libc_scudo_product_variables 中定義了 -DUSE_SCUDO,具體的內(nèi)存分配會(huì)使用libscudo下的定義,libscudo代碼在externl/scudo下,而不是llvm中。

通過(guò)搜索USE_SCUDO宏,在宏開(kāi)啟后

libc/bionic/malloc_common.h

#if defined(USE_SCUDO)

#include "scudo.h"

#define Malloc(function)scudo_ ## function

通過(guò)hook的方式,將Libscudo中的實(shí)現(xiàn)來(lái)替換Libc原有的內(nèi)存分配釋放實(shí)現(xiàn)。

三 llvm中的scudo實(shí)現(xiàn)方式

llvm的scudo主要是在代碼路徑compiler-rt\lib\scudo中,scudo只能與undefined一塊使用

The only other Sanitizer Scudo is compatible with is UBSan (eg: -fsanitize=scudo,undefined)

llvm下主要的生效方式是:

// You'll need to:

// 1) define INTERCEPTOR(int, foo, const char *bar, double baz) { ... } in

// your source file. See the notes below for cases when

// INTERCEPTOR_WITH_SUFFIX(...) should be used instead.

// 2) Call "INTERCEPT_FUNCTION(foo)" prior to the first call of "foo".

// INTERCEPT_FUNCTION(foo) evaluates to "true" iff the function was

// intercepted successfully.

在庫(kù)初始化中,INTERCEPT_FUNCTION調(diào)用替代原生的函數(shù),從而實(shí)現(xiàn)類似hook的方式。

總結(jié)

以上是生活随笔為你收集整理的android libc 有哪些函数_Android scudo功能介绍的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。