ia64/xen-unstable

view tools/vnet/libxutil/allocate.c @ 19848:5839491bbf20

[IA64] replace MAX_VCPUS with d->max_vcpus where necessary.

don't use MAX_VCPUS, and use vcpu::max_vcpus.
The changeset of 2f9e1348aa98 introduced max_vcpus to allow more vcpus
per guest. This patch is ia64 counter part.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 11:26:05 2009 +0900 (2009-06-29)
parents 9f22db685802
children
line source
1 /*
2 * Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
19 #include "allocate.h"
21 /** @file
22 * Support for allocating memory.
23 * Usable from user code or kernel code (with __KERNEL__ defined).
24 * In user code will use GC if USE_GC is defined.
25 */
27 #ifdef __KERNEL__
28 /*----------------------------------------------------------------------------*/
29 # include <linux/config.h>
30 # include <linux/slab.h>
31 # include <linux/string.h>
32 # include <linux/types.h>
34 # define DEFAULT_TYPE 0
35 # define MALLOC(n, type) kmalloc(n, type)
36 # define FREE(ptr) kfree(ptr)
38 /*----------------------------------------------------------------------------*/
39 #else /* ! __KERNEL__ */
41 # include <stdlib.h>
42 # include <string.h>
44 # define DEFAULT_TYPE 0
46 #ifdef USE_GC
47 # include "gc.h"
48 # define MALLOC(n, typ) GC_malloc(n)
49 # define FREE(ptr) (ptr=NULL)
50 //typedef void *GC_PTR;
51 //GC_PTR (*GC_oom_fn)(size_t n);
52 #else
53 # define MALLOC(n, type) malloc(n)
54 # define FREE(ptr) free(ptr)
55 #endif
57 /*----------------------------------------------------------------------------*/
58 #endif
60 /** Function to call when memory cannot be allocated. */
61 AllocateFailedFn *allocate_failed_fn = NULL;
63 /** Allocate memory and zero it.
64 * The type is only relevant when calling from kernel code,
65 * from user code it is ignored.
66 * In kernel code the values accepted by kmalloc can be used:
67 * GFP_USER, GFP_ATOMIC, GFP_KERNEL.
68 *
69 * @param size number of bytes to allocate
70 * @param type memory type to allocate (kernel only)
71 * @return pointer to the allocated memory or zero
72 * if malloc failed
73 */
74 void *allocate_type(int size, int type){
75 void *p = MALLOC(size, type);
76 if(p){
77 memzero(p, size);
78 } else if(allocate_failed_fn){
79 allocate_failed_fn(size, type);
80 }
81 return p;
82 }
84 /** Allocate memory and zero it.
85 *
86 * @param size number of bytes to allocate
87 * @return pointer to the allocated memory or zero
88 * if malloc failed
89 */
90 void *allocate(int size){
91 return allocate_type(size, DEFAULT_TYPE);
92 }
94 /** Free memory allocated by allocate().
95 * No-op if 'p' is null.
96 *
97 * @param p memory to free
98 */
99 void deallocate(void *p){
100 if(p){
101 FREE(p);
102 }
103 }
105 /** Set bytes to zero.
106 * No-op if 'p' is null.
107 *
108 * @param p memory to zero
109 * @param size number of bytes to zero
110 */
111 void memzero(void *p, int size){
112 if(p){
113 memset(p, 0, (size_t)size);
114 }
115 }