003 File Manager
Current Path:
/usr/src/contrib/unbound/util
usr
/
src
/
contrib
/
unbound
/
util
/
📁
..
📄
alloc.c
(18.06 KB)
📄
alloc.h
(8.23 KB)
📄
as112.c
(4.16 KB)
📄
as112.h
(2.22 KB)
📄
config_file.c
(77.33 KB)
📄
config_file.h
(40.38 KB)
📄
configlexer.lex
(26.89 KB)
📄
configparser.y
(101.23 KB)
📄
configyyrename.h
(2.22 KB)
📁
data
📄
edns.c
(5.04 KB)
📄
edns.h
(3.86 KB)
📄
fptr_wlist.c
(19.07 KB)
📄
fptr_wlist.h
(12.78 KB)
📄
iana_ports.inc
(31.81 KB)
📄
locks.c
(7.88 KB)
📄
locks.h
(12.53 KB)
📄
log.c
(16.31 KB)
📄
log.h
(7.5 KB)
📄
mini_event.c
(9.73 KB)
📄
mini_event.h
(6.51 KB)
📄
module.c
(7.14 KB)
📄
module.h
(31.35 KB)
📄
net_help.c
(42.81 KB)
📄
net_help.h
(16.12 KB)
📄
netevent.c
(114.68 KB)
📄
netevent.h
(33.92 KB)
📄
random.c
(6.23 KB)
📄
random.h
(2.98 KB)
📄
rbtree.c
(16.08 KB)
📄
rbtree.h
(6.23 KB)
📄
regional.c
(6.24 KB)
📄
regional.h
(5.37 KB)
📄
rtt.c
(3.53 KB)
📄
rtt.h
(3.57 KB)
📁
shm_side
📁
storage
📄
tcp_conn_limit.c
(4.91 KB)
📄
tcp_conn_limit.h
(3.88 KB)
📄
timehist.c
(6.06 KB)
📄
timehist.h
(3.81 KB)
📄
tube.c
(17.71 KB)
📄
tube.h
(8.4 KB)
📄
ub_event.c
(11.67 KB)
📄
ub_event.h
(5.07 KB)
📄
ub_event_pluggable.c
(17.61 KB)
📄
winsock_event.c
(21.16 KB)
📄
winsock_event.h
(10.19 KB)
Editing: regional.c
/* * regional.c -- region based memory allocator. * * Copyright (c) 2001-2006, NLnet Labs. All rights reserved. * * Copyright (c) 2007, NLnet Labs. All rights reserved. * * This software is open source. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the NLNET LABS nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * \file * Regional allocator. Allocates small portions of of larger chunks. */ #include "config.h" #include "util/log.h" #include "util/regional.h" #ifdef ALIGNMENT # undef ALIGNMENT #endif /** increase size until it fits alignment of s bytes */ #define ALIGN_UP(x, s) (((x) + s - 1) & (~(s - 1))) /** what size to align on; make sure a char* fits in it. */ #define ALIGNMENT (sizeof(uint64_t)) /** Default reasonable size for chunks */ #define REGIONAL_CHUNK_SIZE 8192 #ifdef UNBOUND_ALLOC_NONREGIONAL /** All objects allocated outside of chunks, for debug */ #define REGIONAL_LARGE_OBJECT_SIZE 0 #else /** Default size for large objects - allocated outside of chunks. */ #define REGIONAL_LARGE_OBJECT_SIZE 2048 #endif struct regional* regional_create(void) { return regional_create_custom(REGIONAL_CHUNK_SIZE); } /** init regional struct with first block */ static void regional_init(struct regional* r) { size_t a = ALIGN_UP(sizeof(struct regional), ALIGNMENT); r->data = (char*)r + a; r->available = r->first_size - a; r->next = NULL; r->large_list = NULL; r->total_large = 0; } /** * Create a new region, with custom first block and large-object sizes. * @param size: length of first block. * @param large_object_size: outside of chunk allocation threshold. * @return: newly allocated regional. */ static struct regional* regional_create_custom_large_object(size_t size, size_t large_object_size) { struct regional* r; size = ALIGN_UP(size, ALIGNMENT); r = (struct regional*)malloc(size); log_assert(sizeof(struct regional) <= size); if(!r) return NULL; r->first_size = size; r->large_object_size = large_object_size; regional_init(r); return r; } struct regional* regional_create_custom(size_t size) { return regional_create_custom_large_object(size, REGIONAL_LARGE_OBJECT_SIZE); } struct regional* regional_create_nochunk(size_t size) { return regional_create_custom_large_object(size, 0); } void regional_free_all(struct regional *r) { char* p = r->next, *np; while(p) { np = *(char**)p; free(p); p = np; } p = r->large_list; while(p) { np = *(char**)p; free(p); p = np; } regional_init(r); } void regional_destroy(struct regional *r) { if(!r) return; regional_free_all(r); free(r); } void * regional_alloc(struct regional *r, size_t size) { size_t a; void *s; if( #if SIZEOF_SIZE_T == 8 (unsigned long long)size >= 0xffffffffffffff00ULL #else (unsigned)size >= (unsigned)0xffffff00UL #endif ) return NULL; /* protect against integer overflow in malloc and ALIGN_UP */ a = ALIGN_UP(size, ALIGNMENT); /* large objects */ if(a > r->large_object_size) { s = malloc(ALIGNMENT + size); if(!s) return NULL; r->total_large += ALIGNMENT+size; *(char**)s = r->large_list; r->large_list = (char*)s; return (char*)s+ALIGNMENT; } /* create a new chunk */ if(a > r->available) { s = malloc(REGIONAL_CHUNK_SIZE); if(!s) return NULL; *(char**)s = r->next; r->next = (char*)s; r->data = (char*)s + ALIGNMENT; r->available = REGIONAL_CHUNK_SIZE - ALIGNMENT; } /* put in this chunk */ r->available -= a; s = r->data; r->data += a; return s; } void * regional_alloc_init(struct regional* r, const void *init, size_t size) { void *s = regional_alloc(r, size); if(!s) return NULL; memcpy(s, init, size); return s; } void * regional_alloc_zero(struct regional *r, size_t size) { void *s = regional_alloc(r, size); if(!s) return NULL; memset(s, 0, size); return s; } char * regional_strdup(struct regional *r, const char *string) { return (char*)regional_alloc_init(r, string, strlen(string)+1); } /** * reasonably slow, but stats and get_mem are not supposed to be fast * count the number of chunks in use */ static size_t count_chunks(struct regional* r) { size_t c = 1; char* p = r->next; while(p) { c++; p = *(char**)p; } return c; } /** * also reasonably slow, counts the number of large objects */ static size_t count_large(struct regional* r) { size_t c = 0; char* p = r->large_list; while(p) { c++; p = *(char**)p; } return c; } void regional_log_stats(struct regional *r) { /* some basic assertions put here (non time critical code) */ log_assert(ALIGNMENT >= sizeof(char*)); log_assert(REGIONAL_CHUNK_SIZE > ALIGNMENT); log_assert(REGIONAL_CHUNK_SIZE-ALIGNMENT > r->large_object_size); log_assert(REGIONAL_CHUNK_SIZE >= sizeof(struct regional)); /* debug print */ log_info("regional %u chunks, %u large", (unsigned)count_chunks(r), (unsigned)count_large(r)); } size_t regional_get_mem(struct regional* r) { return r->first_size + (count_chunks(r)-1)*REGIONAL_CHUNK_SIZE + r->total_large; }
Upload File
Create Folder