0711 nwnss: audit stdlib allocator source split
This commit is contained in:
@@ -41,10 +41,15 @@ add_library(nwnss SHARED
|
||||
library/stdio/vprintf.c
|
||||
library/stdio/vsprintf.c
|
||||
library/stdlib/atoq.c
|
||||
library/stdlib/exit.c
|
||||
library/stdlib/free.c
|
||||
library/stdlib/freeForNCPReply.c
|
||||
library/stdlib/freePage.c
|
||||
library/stdlib/malloc.c
|
||||
library/stdlib/mallocForNCPReply.c
|
||||
library/stdlib/mallocPage.c
|
||||
library/stdlib/mallocPageWithFlags.c
|
||||
library/stdlib/realloc.c
|
||||
library/stdlib/strtol.c
|
||||
library/stdlib/atoi.c
|
||||
library/stdlib/zalloc.c
|
||||
|
||||
32
src/nwnss/library/stdlib/exit.c
Normal file
32
src/nwnss/library/stdlib/exit.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
|
|
||||
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| NetWare Advance File Services (NSS) module
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
|
|
||||
| Source(s): public_core/library/stdlib/exit.c
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| mars-nwe userspace port note:
|
||||
| Original Linux NSS already leaves LB_exitMyselfAndReturn as a no-op command
|
||||
| line/runtime boundary. Standalone libnwnss cannot kill an NLM/kernel module;
|
||||
| keep both public exit entry points as no-op status boundaries.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <library/xStdlib.h>
|
||||
|
||||
void LB_exitMyselfAndWait(struct LoadDefinitionStructure *moduleHandle, int status)
|
||||
{
|
||||
(void)moduleHandle;
|
||||
(void)status;
|
||||
}
|
||||
|
||||
void LB_exitMyselfAndReturn(struct LoadDefinitionStructure *moduleHandle, int status)
|
||||
{
|
||||
(void)moduleHandle;
|
||||
(void)status;
|
||||
}
|
||||
26
src/nwnss/library/stdlib/free.c
Normal file
26
src/nwnss/library/stdlib/free.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/****************************************************************************
|
||||
|
|
||||
| (C) Copyright 1985, 1991, 1993, 1996, 2002 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| NetWare Advance File Services (NSS) module
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
|
|
||||
| Source(s): public_core/library/stdlib/free.c
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| mars-nwe userspace port note:
|
||||
|
|
||||
| The original file is built on NSS allocation metadata and delayed-free
|
||||
| debug lists. The standalone libnwnss allocator currently maps that OS/NSS
|
||||
| memory boundary to libc, while preserving the public LB_free symbol.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
|
||||
void LB_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
29
src/nwnss/library/stdlib/freeForNCPReply.c
Normal file
29
src/nwnss/library/stdlib/freeForNCPReply.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/****************************************************************************
|
||||
|
|
||||
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| NetWare Advance File Services (NSS) module
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
|
|
||||
| Source(s): public_core/library/stdlib/freeForNCPReply.c
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| mars-nwe userspace port note:
|
||||
| See mallocForNCPReply.c. Keep the NSS/NCP reply free symbols distinct even
|
||||
| though the current userspace backing allocator is libc free.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
|
||||
void LB_freeForNCPReply(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void freeForNCPReply(void *ptr)
|
||||
{
|
||||
LB_freeForNCPReply(ptr);
|
||||
}
|
||||
@@ -3,18 +3,6 @@
|
||||
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
| This program is free software; you can redistribute it and/or
|
||||
| modify it under the terms of version 2 of the GNU General Public
|
||||
| License as published by the Free Software Foundation.
|
||||
|
|
||||
| This program is distributed in the hope that it will be useful,
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
| GNU General Public License for more details.
|
||||
|
|
||||
| You should have received a copy of the GNU General Public License
|
||||
| along with this program; if not, contact Novell, Inc.
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| NetWare Advance File Services (NSS) module
|
||||
@@ -24,11 +12,14 @@
|
||||
| Source(s): public_core/library/stdlib/malloc.c
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| This libnwnss import keeps the NSS allocator API names available outside
|
||||
| the NSS loader/runtime. The original Linux NSS file allocates through NSS
|
||||
| OS/private-stack memory helpers (nssOSAPIs.h/intmem.h/mpkPrivateAlloc).
|
||||
| The mars-nwe userspace port maps those allocation entry points to libc
|
||||
| malloc/free/realloc/calloc while preserving the original public symbols.
|
||||
| mars-nwe userspace port note:
|
||||
|
|
||||
| The original Linux NSS allocator routes through the NSS OS/private-stack
|
||||
| memory runtime (nssOSAPIs.h/intmem.h/MKL_*). That memory runtime is not yet
|
||||
| imported as a standalone userspace component, so this file keeps the NSS API
|
||||
| entry points but maps the allocation boundary onto libc. Keep this file in
|
||||
| the stdlib audit block; do not hide additional allocator aliases in public
|
||||
| NSS headers.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -44,22 +35,11 @@ void *LB_malloc(size_t size)
|
||||
|
||||
void *LB_mallocWithFlags(size_t size, unsigned int flags)
|
||||
{
|
||||
if (flags & ZERO_FILL) {
|
||||
if (flags & ZERO_FILL)
|
||||
return calloc(1, size);
|
||||
}
|
||||
return LB_malloc(size);
|
||||
}
|
||||
|
||||
void LB_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void *LB_realloc(void *ptr, size_t size)
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
|
||||
void *LB_StackAllocate(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
|
||||
32
src/nwnss/library/stdlib/mallocForNCPReply.c
Normal file
32
src/nwnss/library/stdlib/mallocForNCPReply.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
|
|
||||
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| NetWare Advance File Services (NSS) module
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
|
|
||||
| Source(s): public_core/library/stdlib/mallocForNCPReply.c
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| mars-nwe userspace port note:
|
||||
|
|
||||
| The original function allocates reply memory outside the NSS internal malloc
|
||||
| debug path because the NetWare NCP handler frees it itself. In standalone
|
||||
| libnwnss there is no separate NCP allocator yet, so preserve the symbol and
|
||||
| allocate with libc malloc.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
|
||||
void *LB_mallocForNCPReply(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *mallocForNCPReply(size_t size)
|
||||
{
|
||||
return LB_mallocForNCPReply(size);
|
||||
}
|
||||
@@ -30,7 +30,14 @@
|
||||
| and map the physical-page allocation boundary onto page-aligned libc memory.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <errno.h>
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
|
||||
#endif
|
||||
#include <omni.h>
|
||||
#include <inst.h>
|
||||
|
||||
|
||||
@@ -20,7 +20,14 @@
|
||||
| mars-nwe userspace port: preserve the NSS page allocator API while mapping
|
||||
| physical-page flags onto page-aligned libc allocation semantics.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <omni.h>
|
||||
#include <inst.h>
|
||||
|
||||
26
src/nwnss/library/stdlib/realloc.c
Normal file
26
src/nwnss/library/stdlib/realloc.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/****************************************************************************
|
||||
|
|
||||
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| NetWare Advance File Services (NSS) module
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
|
|
||||
| Source(s): public_core/library/stdlib/realloc.c
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| mars-nwe userspace port note:
|
||||
|
|
||||
| Original NSS realloc uses MKL allocation metadata to copy the previous full
|
||||
| allocation size. Until the full NSS memory runtime is imported, map the API
|
||||
| onto libc realloc semantics.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
|
||||
void *LB_realloc(void *ptr, size_t size)
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
}
|
||||
@@ -25,7 +25,14 @@
|
||||
| while mapping the physical-page allocation boundary onto page-aligned libc
|
||||
| memory.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(MARS_NWE_NWNSS_USERSPACE)
|
||||
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <omni.h>
|
||||
#include <inst.h>
|
||||
|
||||
@@ -3,18 +3,6 @@
|
||||
| (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc.
|
||||
| All Rights Reserved.
|
||||
|
|
||||
| This program is free software; you can redistribute it and/or
|
||||
| modify it under the terms of version 2 of the GNU General Public
|
||||
| License as published by the Free Software Foundation.
|
||||
|
|
||||
| This program is distributed in the hope that it will be useful,
|
||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
| GNU General Public License for more details.
|
||||
|
|
||||
| You should have received a copy of the GNU General Public License
|
||||
| along with this program; if not, contact Novell, Inc.
|
||||
|
|
||||
|***************************************************************************
|
||||
|
|
||||
| NetWare Advance File Services (NSS) module
|
||||
@@ -24,20 +12,50 @@
|
||||
| Source(s): public_core/library/stdlib/zrealloc.c
|
||||
|
|
||||
|---------------------------------------------------------------------------
|
||||
| The original NSS implementation reallocates through NSS allocation metadata
|
||||
| so newly grown tail space is zeroed up to the full OS allocation size. The
|
||||
| standalone libnwnss import cannot see that metadata, so it provides the
|
||||
| original NSS API names with libc realloc semantics until the full NSS memory
|
||||
| runtime is imported.
|
||||
| mars-nwe userspace port note:
|
||||
| Original NSS zrealloc uses MKL allocation metadata and zero-fills newly
|
||||
| grown tail space up to the OS allocation size. The userspace port has no
|
||||
| MKL metadata yet; on Linux use malloc_usable_size() to preserve the important
|
||||
| observable contract: bytes newly exposed by growth are zero-filled.
|
||||
+-------------------------------------------------------------------------*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef __linux__
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
static size_t nwnss_alloc_usable_size(void *ptr)
|
||||
{
|
||||
#ifdef __linux__
|
||||
return ptr ? malloc_usable_size(ptr) : 0;
|
||||
#else
|
||||
(void)ptr;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *LB_zrealloc(void *ptr, size_t size)
|
||||
{
|
||||
return realloc(ptr, size);
|
||||
size_t oldSize = nwnss_alloc_usable_size(ptr);
|
||||
void *newPtr;
|
||||
|
||||
if (ptr == NULL)
|
||||
return calloc(1, size);
|
||||
if (size == 0) {
|
||||
free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newPtr = realloc(ptr, size);
|
||||
if (newPtr == NULL)
|
||||
return NULL;
|
||||
|
||||
if (size > oldSize)
|
||||
memset((unsigned char *)newPtr + oldSize, 0, size - oldSize);
|
||||
return newPtr;
|
||||
}
|
||||
|
||||
void *zrealloc(void *ptr, size_t size)
|
||||
{
|
||||
return LB_zrealloc(ptr, size);
|
||||
return LB_zrealloc(ptr, size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user