| Index: emcore/trunk/tools/emcore.py |
| — | — | @@ -1159,6 +1159,60 @@ |
| 1160 | 1160 | self.logger.info(entry.name.ljust(50) + " - " + size + "\n")
|
| 1161 | 1161 | except: break
|
| 1162 | 1162 | self.emcore.dir_close(handle)
|
| | 1163 | +
|
| | 1164 | + @command
|
| | 1165 | + def malloc(self, size):
|
| | 1166 | + """ Allocates <size> bytes and returns a pointer to the allocated memory """
|
| | 1167 | + size = self._hexint(size)
|
| | 1168 | + self.logger.info("Allocating %d bytes of memory\n" % size)
|
| | 1169 | + addr = self.emcore.malloc(size)
|
| | 1170 | + self.logger.info("Allocated %d bytes of memory at 0x%x\n" % (size, addr))
|
| | 1171 | +
|
| | 1172 | + @command
|
| | 1173 | + def memalign(self, align, size):
|
| | 1174 | + """ Allocates <size> bytes aligned to <align> and returns a pointer to the allocated memory """
|
| | 1175 | + align = self._hexint(align)
|
| | 1176 | + size = self._hexint(size)
|
| | 1177 | + self.logger.info("Allocating %d bytes of memory aligned to 0x%x\n" % (size, align))
|
| | 1178 | + addr = self.emcore.memalign(align, size)
|
| | 1179 | + self.logger.info("Allocated %d bytes of memory at 0x%x\n" % (size, addr))
|
| | 1180 | +
|
| | 1181 | + @command
|
| | 1182 | + def realloc(self, ptr, size):
|
| | 1183 | + """ The size of the memory block pointed to by <ptr> is changed to the <size> bytes,
|
| | 1184 | + expanding or reducing the amount of memory available in the block.
|
| | 1185 | + Returns a pointer to the reallocated memory.
|
| | 1186 | + """
|
| | 1187 | + ptr = self._hexint(ptr)
|
| | 1188 | + size = self._hexint(size)
|
| | 1189 | + self.logger.info("Reallocating 0x%x to have the new size %d\n" % (ptr, size))
|
| | 1190 | + addr = self.emcore.realloc(ptr, size)
|
| | 1191 | + self.logger.info("Reallocated memory at 0x%x to 0x%x with the new size %d\n" % (ptr, addr, size))
|
| | 1192 | +
|
| | 1193 | + @command
|
| | 1194 | + def reownalloc(self, ptr, owner):
|
| | 1195 | + """ Changes the owner of the memory allocation <ptr> to the thread struct at addr <owner> """
|
| | 1196 | + ptr = self._hexint(ptr)
|
| | 1197 | + owner = self._hexint(owner)
|
| | 1198 | + self.logger.info("Changing owner of the memory region 0x%x to 0x%x" % (ptr, owner))
|
| | 1199 | + self.emcore.reownalloc(ptr, owner)
|
| | 1200 | + self.logger.info("Successfully changed owner of 0x%x to 0x%x" % (ptr, owner))
|
| | 1201 | +
|
| | 1202 | + @command
|
| | 1203 | + def free(self, ptr):
|
| | 1204 | + """ Frees the memory space pointed to by 'ptr' """
|
| | 1205 | + ptr = self._hexint(ptr)
|
| | 1206 | + self.logger.info("Freeing the memory region at 0x%x\n" % ptr)
|
| | 1207 | + self.emcore.free(ptr)
|
| | 1208 | + self.logger.info("Successfully freed the memory region at 0x%x\n" % ptr)
|
| | 1209 | +
|
| | 1210 | + @command
|
| | 1211 | + def free_all(self):
|
| | 1212 | + """ Frees all memory allocations created by the monitor thread """
|
| | 1213 | + self.logger.info("Freeing all memory allocations created by the monitor thread\n")
|
| | 1214 | + self.emcore.free_all()
|
| | 1215 | + self.logger.info("Successfully freed all memory allocations created by the monitor thread\n")
|
| | 1216 | +
|
| 1163 | 1217 |
|
| 1164 | 1218 | if __name__ == "__main__":
|
| 1165 | 1219 | if len(sys.argv) < 2:
|