freemyipod r441 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r440‎ | r441 | r442 >
Date:01:38, 17 January 2011
Author:farthen
Status:new
Tags:
Comment:
libemcore: Implement malloc, memalign, realloc, reownalloc and free and include some test for them (libembios.py malloctest)
Modified paths:
  • /emcore/trunk/tools/libemcore.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/libemcore.py
@@ -820,6 +820,37 @@
821821 raise DeviceError("disk_unmount(volume=%d) failed with RC=0x%08X, errno=%d" % (volume, result.rc, self.errno()))
822822 return result.rc
823823
 824+ @command()
 825+ def malloc(self, size):
 826+ """ Allocates 'size' bytes and returns a pointer to the allocated memory """
 827+ result = self.lib.monitorcommand(struct.pack("IIII", 52, size, 0, 0), "III", ("ptr", None, None))
 828+ return result.ptr
 829+
 830+ @command()
 831+ def memalign(self, align, size):
 832+ """ Allocates 'size' bytes aligned to 'align' and returns a pointer to the allocated memory """
 833+ result = self.lib.monitorcommand(struct.pack("IIII", 53, align, size, 0), "III", ("ptr", None, None))
 834+ return result.ptr
 835+
 836+ @command()
 837+ def realloc(self, ptr, size):
 838+ """ The size of the memory block pointed to by 'ptr' is changed to the 'size' bytes,
 839+ expanding or reducing the amount of memory available in the block.
 840+ Returns a pointer to the reallocated memory.
 841+ """
 842+ result = self.lib.monitorcommand(struct.pack("IIII", 54, ptr, size, 0), "III", ("ptr", None, None))
 843+ return result.ptr
 844+
 845+ @command()
 846+ def reownalloc(self, ptr, owner):
 847+ """ Changes the owner of the memory allocation 'ptr' to the thread struct at addr 'owner' """
 848+ return self.lib.monitorcommand(struct.pack("IIII", 55, ptr, owner, 0), "III", (None, None, None))
 849+
 850+ @command()
 851+ def free(self, ptr):
 852+ """ Frees the memory space pointed to by 'ptr' """
 853+ return self.lib.monitorcommand(struct.pack("IIII", 56, addr, 0, 0), "III", (None, None, None))
 854+
824855
825856 class Lib(object):
826857 def __init__(self, logger):
@@ -1024,4 +1055,20 @@
10251056 if getattr(value, 'func', False):
10261057 if getattr(value.func, '_command', False):
10271058 cmddict[value.func.__name__] = value
1028 - logger.log(gendoc(cmddict))
\ No newline at end of file
 1059+ logger.log(gendoc(cmddict))
 1060+
 1061+ elif sys.argv[1] == "malloctest":
 1062+ emcore = Emcore()
 1063+ logger.log("Allocating 200 bytes of memory: ")
 1064+ addr = emcore.malloc(200)
 1065+ logger.log("0x%x\n" % addr)
 1066+ logger.log("Reallocating to 2000 bytes: ")
 1067+ addr = emcore.realloc(addr, 2000)
 1068+ logger.log("0x%x\n" % addr)
 1069+ logger.log("Freeing 0x%x\n" % addr)
 1070+ emcore.free(addr)
 1071+ logger.log("Allocating 1000 bytes of memory aligned to 100 bytes: ")
 1072+ addr = emcore.memalign(100, 1000)
 1073+ logger.log("0x%x\n" % addr)
 1074+ logger.log("Freeing 0x%x\n" % addr)
 1075+ emcore.free(addr)
\ No newline at end of file