summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/mheap.h
blob: 5b7cdfbaf8df29a09b7dd4b463b80feffdfd082a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
  Copyright (c) 2001, 2002, 2003 Eliot Dresselhaus

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef included_mheap_h
#define included_mheap_h

#include <vppinfra/vec.h>
#include <vppinfra/error.h>	/* clib_error_t */
#include <vppinfra/mem.h>	/* clib_mem_usage_t */
#include <vppinfra/format.h>	/* for unformat_input_t */

/* Allocate size bytes.  New heap and offset are returned.
   offset == ~0 means allocation failed. */
always_inline void *
mheap_get (void *v, uword size, uword * offset_return)
{
  return mheap_get_aligned (v, size, 0, 0, offset_return);
}

/* Create allocation heap of given size.
 * The actual usable size is smaller than the requested size.
 * memory_bytes must be greater than mheap_page_size + sizeof (mheap_t) + 16.
 * Otherwise, allocation may fail and return 0.
 */
void *mheap_alloc (void *memory, uword memory_bytes);
void *mheap_alloc_with_flags (void *memory, uword memory_bytes, uword flags);

#define mheap_free(v) (v) = _mheap_free(v)
void *_mheap_free (void *v);

void mheap_foreach (void *v,
		    uword (*func) (void *arg, void *v, void *elt_data,
				   uword elt_size), void *arg);

/* Format mheap data structures as string. */
u8 *format_mheap (u8 * s, va_list * va);

/* Validate internal consistency. */
void mheap_validate (void *h);

/* Query bytes used. */
uword mheap_bytes (void *v);

void mheap_usage (void *v, clib_mem_usage_t * usage);

/* Enable disable traceing. */
void mheap_trace (void *v, int enable);

/* Test routine. */
int test_mheap_main (unformat_input_t * input);

#endif /* included_mheap_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
a id='n639' href='#n639'>639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873