mirror of
				https://github.com/Divested-Mobile/DivestOS-Build.git
				synced 2025-10-31 06:31:39 -04:00 
			
		
		
		
	 3a0659b9d8
			
		
	
	
		3a0659b9d8
		
	
	
	
	
		
			
			- Add the manifest - Add Pixel 2 series - Add some missing patches - More DNS files - Drop Silence in 19.1 Signed-off-by: Tad <tad@spotco.us>
		
			
				
	
	
		
			169 lines
		
	
	
	
		
			5.1 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			169 lines
		
	
	
	
		
			5.1 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 | |
| From: Daniel Micay <danielmicay@gmail.com>
 | |
| Date: Wed, 5 Dec 2018 01:51:56 -0500
 | |
| Subject: [PATCH] use Scudo on 32-bit and hardened_malloc on 64-bit
 | |
| 
 | |
| Co-authored-by: anupritaisno1 <www.anuprita804@gmail.com>
 | |
| Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
 | |
| [tad@spotco.us]: kept Lineage's scudo 32-bit workaround
 | |
| ---
 | |
|  libc/Android.bp                  | 39 +++++++++++-------------
 | |
|  libc/bionic/h_malloc_wrapper.cpp | 51 ++++++++++++++++++++++++++++++++
 | |
|  libc/bionic/malloc_common.h      |  8 +++++
 | |
|  3 files changed, 77 insertions(+), 21 deletions(-)
 | |
|  create mode 100644 libc/bionic/h_malloc_wrapper.cpp
 | |
| 
 | |
| diff --git a/libc/Android.bp b/libc/Android.bp
 | |
| index 98b878151..75b06f58c 100644
 | |
| --- a/libc/Android.bp
 | |
| +++ b/libc/Android.bp
 | |
| @@ -68,6 +68,8 @@ libc_common_flags = [
 | |
|  
 | |
|      // GWP-ASan requires platform TLS.
 | |
|      "-fno-emulated-tls",
 | |
| +
 | |
| +    "-DH_MALLOC_PREFIX",
 | |
|  ]
 | |
|  
 | |
|  // Define some common cflags
 | |
| @@ -113,33 +115,20 @@ cc_defaults {
 | |
|      ldflags: ["-Wl,-z,muldefs"],
 | |
|  
 | |
|      multilib: {
 | |
| -        lib64: {
 | |
| -            product_variables: {
 | |
| -                malloc_zero_contents: {
 | |
| -                    cflags: ["-DSCUDO_ZERO_CONTENTS"],
 | |
| -                },
 | |
| -                malloc_pattern_fill_contents: {
 | |
| -                    cflags: ["-DSCUDO_PATTERN_FILL_CONTENTS"],
 | |
| -                },
 | |
| -                malloc_not_svelte: {
 | |
| -                    cflags: ["-DUSE_SCUDO"],
 | |
| -                },
 | |
| -            },
 | |
| -        },
 | |
|          lib32: {
 | |
|              product_variables: {
 | |
|                  malloc_zero_contents: {
 | |
|                      cflags: ["-DSCUDO_ZERO_CONTENTS"],
 | |
|                  },
 | |
|                  malloc_pattern_fill_contents: {
 | |
| -                    cflags: ["-DSCUDO_PATTERN_FILL_CONTENTS"],
 | |
| +                     cflags: ["-DSCUDO_PATTERN_FILL_CONTENTS"],
 | |
|                  },
 | |
|                  malloc_not_svelte_libc32: {
 | |
| -                    cflags: ["-DUSE_SCUDO"],
 | |
| +                   cflags: ["-DUSE_SCUDO"],
 | |
|                  },
 | |
|              },
 | |
| -        },
 | |
| -    },
 | |
| +        }
 | |
| +    }
 | |
|  }
 | |
|  
 | |
|  libc_scudo_product_variables = {
 | |
| @@ -194,12 +183,20 @@ cc_defaults {
 | |
|  cc_library_static {
 | |
|      name: "libc_jemalloc_wrapper",
 | |
|      defaults: ["libc_defaults"],
 | |
| -    srcs: ["bionic/jemalloc_wrapper.cpp"],
 | |
| +    multilib: {
 | |
| +        lib32: {
 | |
| +            // Used to pull in the jemalloc/hardened_malloc include directory so that if the
 | |
| +            // library is removed, the include directory is also removed.
 | |
| +            srcs: ["bionic/jemalloc_wrapper.cpp"],
 | |
| +            static_libs: ["libjemalloc5"],
 | |
| +        },
 | |
| +        lib64: {
 | |
| +            srcs: ["bionic/h_malloc_wrapper.cpp"],
 | |
| +            static_libs: ["libhardened_malloc"],
 | |
| +        },
 | |
| +    },
 | |
|      cflags: ["-fvisibility=hidden"],
 | |
|  
 | |
| -    // Used to pull in the jemalloc include directory so that if the
 | |
| -    // library is removed, the include directory is also removed.
 | |
| -    static_libs: ["libjemalloc5"],
 | |
|  }
 | |
|  
 | |
|  // ========================================================
 | |
| diff --git a/libc/bionic/h_malloc_wrapper.cpp b/libc/bionic/h_malloc_wrapper.cpp
 | |
| new file mode 100644
 | |
| index 000000000..5fb0968c2
 | |
| --- /dev/null
 | |
| +++ b/libc/bionic/h_malloc_wrapper.cpp
 | |
| @@ -0,0 +1,51 @@
 | |
| +#include <errno.h>
 | |
| +#include <malloc.h>
 | |
| +#include <sys/param.h>
 | |
| +#include <unistd.h>
 | |
| +
 | |
| +#include <private/MallocXmlElem.h>
 | |
| +
 | |
| +#include "h_malloc.h"
 | |
| +
 | |
| +__BEGIN_DECLS
 | |
| +int h_malloc_info(int options, FILE* fp);
 | |
| +__END_DECLS
 | |
| +
 | |
| +int h_malloc_info(int options, FILE* fp) {
 | |
| +  if (options != 0) {
 | |
| +    errno = EINVAL;
 | |
| +    return -1;
 | |
| +  }
 | |
| +
 | |
| +  fflush(fp);
 | |
| +  int fd = fileno(fp);
 | |
| +  MallocXmlElem root(fd, "malloc", "version=\"jemalloc-1\"");
 | |
| +
 | |
| +  // Dump all of the large allocations in the arenas.
 | |
| +  for (size_t i = 0; i < h_mallinfo_narenas(); i++) {
 | |
| +    struct mallinfo mi = h_mallinfo_arena_info(i);
 | |
| +    if (mi.hblkhd != 0) {
 | |
| +      MallocXmlElem arena_elem(fd, "heap", "nr=\"%d\"", i);
 | |
| +      {
 | |
| +        MallocXmlElem(fd, "allocated-large").Contents("%zu", mi.ordblks);
 | |
| +        MallocXmlElem(fd, "allocated-huge").Contents("%zu", mi.uordblks);
 | |
| +        MallocXmlElem(fd, "allocated-bins").Contents("%zu", mi.fsmblks);
 | |
| +
 | |
| +        size_t total = 0;
 | |
| +        for (size_t j = 0; j < h_mallinfo_nbins(); j++) {
 | |
| +          struct mallinfo mi = h_mallinfo_bin_info(i, j);
 | |
| +          if (mi.ordblks != 0) {
 | |
| +            MallocXmlElem bin_elem(fd, "bin", "nr=\"%d\"", j);
 | |
| +            MallocXmlElem(fd, "allocated").Contents("%zu", mi.ordblks);
 | |
| +            MallocXmlElem(fd, "nmalloc").Contents("%zu", mi.uordblks);
 | |
| +            MallocXmlElem(fd, "ndalloc").Contents("%zu", mi.fordblks);
 | |
| +            total += mi.ordblks;
 | |
| +          }
 | |
| +        }
 | |
| +        MallocXmlElem(fd, "bins-total").Contents("%zu", total);
 | |
| +      }
 | |
| +    }
 | |
| +  }
 | |
| +
 | |
| +  return 0;
 | |
| +}
 | |
| diff --git a/libc/bionic/malloc_common.h b/libc/bionic/malloc_common.h
 | |
| index 4afcc4a8d..cca9e5202 100644
 | |
| --- a/libc/bionic/malloc_common.h
 | |
| +++ b/libc/bionic/malloc_common.h
 | |
| @@ -67,8 +67,16 @@ __END_DECLS
 | |
|  
 | |
|  #else
 | |
|  
 | |
| +#ifdef __LP64__
 | |
| +#include "h_malloc.h"
 | |
| +#define Malloc(function)  h_ ## function
 | |
| +__BEGIN_DECLS
 | |
| +int h_malloc_info(int options, FILE* fp);
 | |
| +__END_DECLS
 | |
| +#else
 | |
|  #include "jemalloc.h"
 | |
|  #define Malloc(function)  je_ ## function
 | |
| +#endif
 | |
|  
 | |
|  #endif
 | |
|  
 |