/src/kamailio/src/core/mem/pkg.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2015 Daniel-Constantin Mierla (asipto.com) |
3 | | * |
4 | | * This file is part of Kamailio, a free SIP server. |
5 | | * |
6 | | * Permission to use, copy, modify, and distribute this software for any |
7 | | * purpose with or without fee is hereby granted, provided that the above |
8 | | * copyright notice and this permission notice appear in all copies. |
9 | | * |
10 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | | */ |
18 | | |
19 | | /** |
20 | | * \file |
21 | | * \brief Main definitions for memory manager |
22 | | * |
23 | | * Main definitions for PKG memory manager, like malloc, free and realloc |
24 | | * \ingroup mem |
25 | | */ |
26 | | |
27 | | #include <string.h> |
28 | | #include <stdlib.h> |
29 | | #include <stdio.h> |
30 | | |
31 | | #include "../dprint.h" |
32 | | |
33 | | #include "pkg.h" |
34 | | |
35 | | #include "memcore.h" |
36 | | |
37 | | sr_pkg_api_t _pkg_root = {0}; |
38 | | |
39 | | /** |
40 | | * |
41 | | */ |
42 | | int pkg_init_api(sr_pkg_api_t *ap) |
43 | 0 | { |
44 | 0 | memset(&_pkg_root, 0, sizeof(sr_pkg_api_t)); |
45 | 0 | _pkg_root.mname = ap->mname; |
46 | 0 | _pkg_root.mem_pool = ap->mem_pool; |
47 | 0 | _pkg_root.mem_block = ap->mem_block; |
48 | 0 | _pkg_root.xmalloc = ap->xmalloc; |
49 | 0 | _pkg_root.xmallocxz = ap->xmallocxz; |
50 | 0 | _pkg_root.xfree = ap->xfree; |
51 | 0 | _pkg_root.xrealloc = ap->xrealloc; |
52 | 0 | _pkg_root.xreallocxf = ap->xreallocxf; |
53 | 0 | _pkg_root.xstatus = ap->xstatus; |
54 | 0 | _pkg_root.xstatus_filter = ap->xstatus_filter; |
55 | 0 | _pkg_root.xinfo = ap->xinfo; |
56 | 0 | _pkg_root.xreport = ap->xreport; |
57 | 0 | _pkg_root.xavailable = ap->xavailable; |
58 | 0 | _pkg_root.xsums = ap->xsums; |
59 | 0 | _pkg_root.xdestroy = ap->xdestroy; |
60 | 0 | _pkg_root.xmodstats = ap->xmodstats; |
61 | 0 | _pkg_root.xfmodstats = ap->xfmodstats; |
62 | 0 | return 0; |
63 | 0 | } |
64 | | |
65 | | /** |
66 | | * |
67 | | */ |
68 | | int pkg_init_manager(char *name) |
69 | 0 | { |
70 | 0 | if(strcmp(name, "fm") == 0 || strcmp(name, "f_malloc") == 0 |
71 | 0 | || strcmp(name, "fmalloc") == 0) { |
72 | | /*fast malloc*/ |
73 | 0 | return fm_malloc_init_pkg_manager(); |
74 | 0 | } else if(strcmp(name, "qm") == 0 || strcmp(name, "q_malloc") == 0 |
75 | 0 | || strcmp(name, "qmalloc") == 0) { |
76 | | /*quick malloc*/ |
77 | 0 | return qm_malloc_init_pkg_manager(); |
78 | 0 | } else if(strcmp(name, "tlsf") == 0 || strcmp(name, "tlsf_malloc") == 0) { |
79 | | /*tlsf malloc*/ |
80 | 0 | return tlsf_malloc_init_pkg_manager(); |
81 | 0 | } else if(strcmp(name, "sm") == 0) { |
82 | | /*system malloc*/ |
83 | 0 | } else { |
84 | | /*custom malloc - module*/ |
85 | 0 | } |
86 | 0 | return -1; |
87 | 0 | } |
88 | | |
89 | | |
90 | | /** |
91 | | * |
92 | | */ |
93 | | void pkg_destroy_manager(void) |
94 | 0 | { |
95 | 0 | if(_pkg_root.xdestroy) { |
96 | 0 | LM_DBG("destroying memory manager: %s\n", |
97 | 0 | (_pkg_root.mname) ? _pkg_root.mname : "unknown"); |
98 | 0 | _pkg_root.xdestroy(); |
99 | 0 | } |
100 | 0 | } |
101 | | |
102 | | /** |
103 | | * |
104 | | */ |
105 | | void pkg_print_manager(void) |
106 | 0 | { |
107 | 0 | LM_DBG("pkg - using memory manager: %s\n", |
108 | 0 | (_pkg_root.mname) ? _pkg_root.mname : "unknown"); |
109 | 0 | } |