Skip to content

Commit 0306bb4

Browse files
chaohong-guolijinxia
authored andcommitted
Removed dead funcs in EFI stub module
Due to the last patches, some funcs in malloc.c and stdlib.h files for EFI stub module are no longer used. This commit just removes them, no other changes is being introduced. The funcs are: emalloc/efree, calloc/malloc/free, strstr/strdup Tracked-On:#1260 Signed-off-by: Chaohong Guo <chaohong.guo@intel.com> Ackedr-by: Gen Zheng <gen.zheng@intel.com>
1 parent 1d15b98 commit 0306bb4

File tree

2 files changed

+0
-177
lines changed

2 files changed

+0
-177
lines changed

hypervisor/bsp/uefi/efi/malloc.c

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -93,143 +93,6 @@ memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size,
9393
return err;
9494
}
9595

96-
/**
97-
* emalloc - Allocate memory with a strict alignment requirement
98-
* @size: size in bytes of the requested allocation
99-
* @align: the required alignment of the allocation
100-
* @addr: a pointer to the allocated address on success
101-
*
102-
* If we cannot satisfy @align we return 0.
103-
*
104-
* FIXME: This function cannot guarantee to return address under 4G,
105-
* and the hypervisor cannot handle params, which address is above 4G,
106-
* delivered from efi stub.
107-
*/
108-
EFI_STATUS emalloc(UINTN size, UINTN align, EFI_PHYSICAL_ADDRESS *addr)
109-
{
110-
UINTN map_size, map_key, desc_size;
111-
EFI_MEMORY_DESCRIPTOR *map_buf;
112-
UINTN d, map_end;
113-
UINT32 desc_version;
114-
EFI_STATUS err;
115-
UINTN nr_pages = EFI_SIZE_TO_PAGES(size);
116-
117-
err = memory_map(&map_buf, &map_size, &map_key,
118-
&desc_size, &desc_version);
119-
if (err != EFI_SUCCESS)
120-
goto fail;
121-
122-
d = (UINTN)map_buf;
123-
map_end = (UINTN)map_buf + map_size;
124-
125-
for (; d < map_end; d += desc_size) {
126-
EFI_MEMORY_DESCRIPTOR *desc;
127-
EFI_PHYSICAL_ADDRESS start, end, aligned;
128-
129-
desc = (EFI_MEMORY_DESCRIPTOR *)d;
130-
if (desc->Type != EfiConventionalMemory)
131-
continue;
132-
133-
if (desc->NumberOfPages < nr_pages)
134-
continue;
135-
136-
start = desc->PhysicalStart;
137-
end = start + (desc->NumberOfPages << EFI_PAGE_SHIFT);
138-
139-
/* Low-memory is super-precious! */
140-
if (end <= 1 << 20)
141-
continue;
142-
if (start < 1 << 20) {
143-
size -= (1 << 20) - start;
144-
start = (1 << 20);
145-
}
146-
147-
aligned = (start + align -1) & ~(align -1);
148-
149-
if ((aligned + size) <= end) {
150-
err = allocate_pages(AllocateAddress, EfiLoaderData,
151-
nr_pages, &aligned);
152-
if (err == EFI_SUCCESS) {
153-
*addr = aligned;
154-
break;
155-
}
156-
}
157-
}
158-
159-
if (d == map_end)
160-
err = EFI_OUT_OF_RESOURCES;
161-
162-
free_pool(map_buf);
163-
fail:
164-
return err;
165-
}
166-
167-
168-
/**
169-
* efree - Return memory allocated with emalloc
170-
* @memory: the address of the emalloc() allocation
171-
* @size: the size of the allocation
172-
*/
173-
void efree(EFI_PHYSICAL_ADDRESS memory, UINTN size)
174-
{
175-
UINTN nr_pages = EFI_SIZE_TO_PAGES(size);
176-
177-
free_pages(memory, nr_pages);
178-
}
179-
180-
/**
181-
* malloc - Allocate memory from the EfiLoaderData pool
182-
* @size: size in bytes of the requested allocation
183-
*
184-
* Return a pointer to an allocation of @size bytes of type
185-
* EfiLoaderData.
186-
*/
187-
void *malloc(UINTN size)
188-
{
189-
EFI_STATUS err;
190-
void *buffer;
191-
192-
err = allocate_pool(EfiLoaderData, size, &buffer);
193-
if (err != EFI_SUCCESS)
194-
buffer = NULL;
195-
196-
return buffer;
197-
}
198-
199-
/**
200-
* free - Release memory to the EfiLoaderData pool
201-
* @buffer: pointer to the malloc() allocation to free
202-
*/
203-
void free(void *buffer)
204-
{
205-
if (buffer)
206-
free_pool(buffer);
207-
}
208-
209-
/**
210-
* calloc - Allocate zeroed memory for an array of elements
211-
* @nmemb: number of elements
212-
* @size: size of each element
213-
*/
214-
void *calloc(UINTN nmemb, UINTN size)
215-
{
216-
void *buffer;
217-
218-
/*
219-
* There's no equivalent of UINTN_MAX, so for safety we refuse to
220-
* allocate anything larger than 32 bits.
221-
*/
222-
UINTN bytes = nmemb * size;
223-
if ((nmemb | size) > 0xffffU) {
224-
if (size && bytes / size != nmemb)
225-
return NULL;
226-
}
227-
228-
buffer = malloc(bytes);
229-
if (buffer)
230-
(void)memset(buffer, 0, bytes);
231-
return buffer;
232-
}
23396

23497
EFI_STATUS dump_e820(void)
23598
{

hypervisor/bsp/uefi/efi/stdlib.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@
4444
#ifndef __STDLIB_H__
4545
#define __STDLIB_H__
4646

47-
extern void *malloc(UINTN size);
48-
extern void free(void *buf);
49-
extern void *calloc(UINTN nmemb, UINTN size);
50-
51-
extern EFI_STATUS emalloc(UINTN, UINTN, EFI_PHYSICAL_ADDRESS *);
52-
extern EFI_STATUS __emalloc(UINTN, UINTN, EFI_PHYSICAL_ADDRESS *, EFI_MEMORY_TYPE);
53-
extern void efree(EFI_PHYSICAL_ADDRESS, UINTN);
5447

5548
static inline void memset(void *dstv, char ch, UINTN size)
5649
{
@@ -80,39 +73,6 @@ static inline int strlen(const char *str)
8073
return len;
8174
}
8275

83-
static inline char *strstr(const char *haystack, const char *needle)
84-
{
85-
const char *p;
86-
const char *word = NULL;
87-
int len = strlen(needle);
88-
89-
if (!len)
90-
return NULL;
91-
92-
p = haystack;
93-
while (*p) {
94-
word = p;
95-
if (!strncmpa((CHAR8 *)p, (CHAR8 *)needle, len))
96-
break;
97-
p++;
98-
word = NULL;
99-
}
100-
101-
return (char *)word;
102-
}
103-
104-
static inline char *strdup(const char *src)
105-
{
106-
int len;
107-
char *dst;
108-
109-
len = strlen(src);
110-
dst = malloc(len + 1);
111-
if (dst)
112-
memcpy(dst, src, len + 1);
113-
return dst;
114-
}
115-
11676
static inline CHAR16 *strstr_16(CHAR16 *haystack, CHAR16 *needle)
11777
{
11878
CHAR16 *p;

0 commit comments

Comments
 (0)