VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/Etherboot-src/filo/main/malloc_x.c@ 566

Last change on this file since 566 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 879 bytes
Line 
1#include <etherboot.h>
2
3#include <lib.h>
4
5void *calloc(size_t nmemb, size_t size)
6{
7 size_t alloc_size = nmemb * size;
8 void *mem;
9
10 if (alloc_size < nmemb || alloc_size < size) {
11 printf("calloc overflow: %u, %u\n", nmemb, size);
12 return 0;
13 }
14
15 mem = allot(alloc_size);
16 memset(mem, 0, alloc_size);
17
18 return mem;
19}
20
21void *realloc(void *mem, size_t size)
22{
23 size_t copy_size;
24 void *new_mem;
25 size_t *mark, addr;
26
27 if (mem == 0)
28 return allot(size);
29 if (size == 0) {
30 forget(mem);
31 return 0;
32 }
33
34 addr = virt_to_phys(mem);
35 mark = phys_to_virt(addr - sizeof(size_t));
36 copy_size = *mark;
37
38 if (size < copy_size)
39 copy_size = size;
40 /* XXX should optimze this */
41 new_mem = allot(size);
42 memcpy(new_mem, mem, copy_size);
43 forget(mem);
44 return new_mem;
45}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette