Quellcode durchsuchen

max: check allocation against memory overflow

Samuel Thibault vor 4 Jahren
Ursprung
Commit
01aa43f5b6
1 geänderte Dateien mit 8 neuen und 4 gelöschten Zeilen
  1. 8 4
      src/drivers/max/driver_fpga.c

+ 8 - 4
src/drivers/max/driver_fpga.c

@@ -356,12 +356,16 @@ uintptr_t _starpu_fpga_allocate_memory(unsigned dst_node, size_t size, int flags
 	/* 0 would be seen as NULL, i.e. allocation failed... */
 	// FIXME: Maxeler FPGAs want 192-byte alignment
 	static fpga_mem current_address = 8192*192;
-	fpga_mem addr;
-	// TODO: vérifier si current_address + size > taille de la LMEm
+	fpga_mem addr, next_addr;
  	addr = current_address;
-	current_address += size;
+	next_addr = current_address + size;
+	if (next_addr >= global_mem[0])
+	{
+		printf("Memory overflow\n");
+		return 0;
+	}
+	current_address = next_addr;
 	printf("fpga mem returned from allocation @: %p - %p\n",addr, addr + size);
-	//success = 0
         return (uintptr_t) addr;
 }