瀏覽代碼

- Make sure there is no overflow when we write strings in FxT events.
- _starpu_compute_buffers_footprint returns the footprint directly

Cédric Augonnet 14 年之前
父節點
當前提交
853e462da8
共有 2 個文件被更改,包括 23 次插入18 次删除
  1. 21 12
      src/common/fxt.h
  2. 2 6
      src/profiling/bound.c

+ 21 - 12
src/common/fxt.h

@@ -117,25 +117,30 @@ void _starpu_fxt_register_thread(unsigned);
 /* Sometimes we need something a little more specific than the wrappers from
  * FxT: these macro permit to put add an event with 3 (or 4) numbers followed
  * by a string. */
-#define STARPU_FUT_DO_PROBE3STR(CODE, P1, P2, P3, str)				\
+#define STARPU_FUT_DO_PROBE3STR(CODE, P1, P2, P3, str)			\
 do {									\
+	/* No more than FXT_MAX_PARAMS args are allowed */		\
 	/* we add a \0 just in case ... */				\
-	size_t len = strlen((str)) + 1;					\
-	unsigned nbargs = 3 + (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
+	size_t len = STARPU_MIN(strlen(str)+1, (FXT_MAX_PARAMS - 3)*sizeof(unsigned long));\
+	unsigned nbargs_str = (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
+	unsigned nbargs = 3 + nbargs_str;				\
 	size_t total_len = FUT_SIZE(nbargs);				\
-	unsigned long *futargs =						\
+	unsigned long *futargs =					\
 		fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
 	*(futargs++) = (unsigned long)(P1);				\
 	*(futargs++) = (unsigned long)(P2);				\
 	*(futargs++) = (unsigned long)(P3);				\
-	sprintf((char *)futargs, "%s", str);				\
+	snprintf((char *)futargs, len, "%s", str);			\
+	((char *)futargs)[len - 1] = '\0';				\
 } while (0);
 
 #define STARPU_FUT_DO_PROBE4STR(CODE, P1, P2, P3, P4, str)		\
 do {									\
+	/* No more than FXT_MAX_PARAMS args are allowed */		\
 	/* we add a \0 just in case ... */				\
-	size_t len = strlen((str)) + 1;					\
-	unsigned nbargs = 4 + (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
+	size_t len = STARPU_MIN(strlen(str)+1, (FXT_MAX_PARAMS - 4)*sizeof(unsigned long));\
+	unsigned nbargs_str = (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
+	unsigned nbargs = 4 + nbargs_str;				\
 	size_t total_len = FUT_SIZE(nbargs);				\
 	unsigned long *futargs =						\
 		fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
@@ -143,23 +148,27 @@ do {									\
 	*(futargs++) = (unsigned long)(P2);				\
 	*(futargs++) = (unsigned long)(P3);				\
 	*(futargs++) = (unsigned long)(P4);				\
-	sprintf((char *)futargs, "%s", str);				\
+	snprintf((char *)futargs, len, "%s", str);			\
+	((char *)futargs)[len - 1] = '\0';				\
 } while (0);
 
 #define STARPU_FUT_DO_PROBE5STR(CODE, P1, P2, P3, P4, P5, str)		\
 do {									\
+	/* No more than FXT_MAX_PARAMS args are allowed */		\
 	/* we add a \0 just in case ... */				\
-	size_t len = strlen((str)) + 1;					\
-	unsigned nbargs = 5 + (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
+	size_t len = STARPU_MIN(strlen(str)+1, (FXT_MAX_PARAMS - 5)*sizeof(unsigned long));\
+	unsigned nbargs_str = (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
+	unsigned nbargs = 5 + nbargs_str;				\
 	size_t total_len = FUT_SIZE(nbargs);				\
-	unsigned long *futargs =						\
+	unsigned long *futargs =					\
 		fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
 	*(futargs++) = (unsigned long)(P1);				\
 	*(futargs++) = (unsigned long)(P2);				\
 	*(futargs++) = (unsigned long)(P3);				\
 	*(futargs++) = (unsigned long)(P4);				\
 	*(futargs++) = (unsigned long)(P5);				\
-	sprintf((char *)futargs, "%s", str);				\
+	snprintf((char *)futargs, len, "%s", str);			\
+	((char *)futargs)[len - 1] = '\0';				\
 } while (0);
 
 

+ 2 - 6
src/profiling/bound.c

@@ -171,16 +171,13 @@ static void new_task(starpu_job_t j)
 	if (j->bound_task)
 		return;
 
-	if (STARPU_UNLIKELY(!j->footprint_is_computed))
-		_starpu_compute_buffers_footprint(j);
-
 	t = malloc(sizeof(*t));
 	memset(t, 0, sizeof(*t));
 	t->id = j->job_id;
 	t->tag_id = j->task->tag_id;
 	t->use_tag = j->task->use_tag;
 	t->cl = j->task->cl;
-	t->footprint = j->footprint;
+	t->footprint = _starpu_compute_buffers_footprint(j);
 	t->priority = j->task->priority;
 	t->deps = NULL;
 	t->depsn = 0;
@@ -209,8 +206,7 @@ void _starpu_bound_record(starpu_job_t j)
 	} else {
 		struct bound_task_pool *tp;
 
-		if (STARPU_UNLIKELY(!j->footprint_is_computed))
-			_starpu_compute_buffers_footprint(j);
+		_starpu_compute_buffers_footprint(j);
 
 		if (last && last->cl == j->task->cl && last->footprint == j->footprint)
 			tp = last;