From 9f160f41aaee44e207fb709edec8d6493d3c4f2d Mon Sep 17 00:00:00 2001 From: Richard Lowe Date: Wed, 17 Feb 2021 16:19:26 -0600 Subject: 13565 umem should only have one text section Reviewed by: Jason King Reviewed by: Robert Mustacchi Approved by: Gordon Ross --- usr/src/lib/libumem/common/mapfile-vers | 7 ++++--- usr/src/lib/libumem/common/umem.c | 23 +++++++++++------------ usr/src/lib/libumem/i386/asm_subr.s | 15 +++++++++++---- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/usr/src/lib/libumem/common/mapfile-vers b/usr/src/lib/libumem/common/mapfile-vers index c2cdadf993..66563b3b85 100644 --- a/usr/src/lib/libumem/common/mapfile-vers +++ b/usr/src/lib/libumem/common/mapfile-vers @@ -40,11 +40,12 @@ $mapfile_version 2 $if _x86 -LOAD_SEGMENT umem { +LOAD_SEGMENT ptctext { FLAGS = READ EXECUTE; + ALIGN = 0x1000; + ROUND = 0x1000; ASSIGN_SECTION { - IS_NAME = .text; - FILE_BASENAME = asm_subr.o + IS_NAME = .ptctext; }; }; $endif diff --git a/usr/src/lib/libumem/common/umem.c b/usr/src/lib/libumem/common/umem.c index 598a45eb39..9c5e3ec829 100644 --- a/usr/src/lib/libumem/common/umem.c +++ b/usr/src/lib/libumem/common/umem.c @@ -484,18 +484,17 @@ * ----------------------------------------------- * * The last piece of this puzzle is how we actually jam ptcmalloc() into the - * PLT. To handle this, we have defined two functions, _malloc and _free and - * used a special mapfile directive to place them into the a readable, - * writeable, and executable segment. Next we use a standard #pragma weak for - * malloc and free and direct them to those symbols. By default, those symbols - * have text defined as nops for our generated functions and when they're - * invoked, they jump to the default malloc and free functions. - * - * When umem_genasm() is called, it goes through and generates new malloc() and - * free() functions in the text provided for by _malloc and _free just after the - * jump. Once both have been successfully generated, umem_genasm() nops over the - * original jump so that we now call into the genasm versions of these - * functions. + * PLT. To handle this, we have defined two functions, _malloc and _free, we + * use a standard #pragma weak for malloc and free and direct them to those + * symbols. By default, those symbols have text defined as nops for our + * generated functions and when they're invoked, they jump to the default + * malloc and free functions. + * + * When umem_genasm() is called, it makes _malloc and _free writeable and goes + * through and updates the text provided for by _malloc and _free just after + * the jump. Once both have been successfully generated, umem_genasm() nops + * over the original jump so that we now call into the genasm versions of + * these functions, and makes the functions read-only once again. * * 8.3 umem_genasm() * ----------------- diff --git a/usr/src/lib/libumem/i386/asm_subr.s b/usr/src/lib/libumem/i386/asm_subr.s index 5ad5345c6d..7f7d626487 100644 --- a/usr/src/lib/libumem/i386/asm_subr.s +++ b/usr/src/lib/libumem/i386/asm_subr.s @@ -90,8 +90,11 @@ _breakpoint(void) ret SET_SIZE(_breakpoint) #endif - - ENTRY(_malloc) + .section ".ptctext", "ax" + .globl _malloc + .type _malloc, @function + .align ASM_ENTRY_ALIGN +_malloc: jmp umem_malloc; NOP256 NOP256 @@ -100,7 +103,11 @@ _breakpoint(void) #endif SET_SIZE(_malloc) - ENTRY(_free) + .section ".ptctext","ax" + .globl _free + .type _free, @function + .align ASM_ENTRY_ALIGN +_free: jmp umem_malloc_free; NOP256 NOP256 @@ -111,5 +118,5 @@ _breakpoint(void) ANSI_PRAGMA_WEAK2(malloc,_malloc,function) ANSI_PRAGMA_WEAK2(free,_free,function) - + #endif /* lint */ -- cgit v1.2.3