Skip to contentSkip to conversation

lib/copperplate: remove wrapped heap function

PATCH In review Norbert Lange 2 participants 3 messages Jun 3, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib/copperplate: remove wrapped heap function

this will remove the dependency to libmodechk, the original intent was to allow RT threads call non-RT functions.
As the threads require to have weak scheduling policy, there is no need to avoid checks (which arent active in that policy).

---
 lib/copperplate/heapobj-heapmem.c | 14 +++++++-------
 lib/copperplate/heapobj-malloc.c  |  6 +++---
 lib/copperplate/registry.c        | 14 +++++++-------
 lib/copperplate/traceobj.c        |  4 ++--
 4 files changed, 19 insertions(+), 19 deletions(-)
lib/copperplate/heapobj-heapmem.c +7 -7
index 2737fa7ac..bc6e5f236 100644
@@ -33,15 +33,15 @@ int __heapobj_init_private(struct heapobj *hobj, const char *name,
 	void *_mem = mem;
 	int ret;
 
-	heap = __STD(malloc(sizeof(*heap)));
+	heap = malloc(sizeof(*heap));
 	if (heap == NULL)
 		return -ENOMEM;
 
 	if (mem == NULL) {
 		size = HEAPMEM_ARENA_SIZE(size); /* Count meta-data in. */
-		mem = __STD(malloc(size));
+		mem = malloc(size);
 		if (mem == NULL) {
-			__STD(free(heap));
+			free(heap);
 			return -ENOMEM;
 		}
 	}
@@ -57,8 +57,8 @@ int __heapobj_init_private(struct heapobj *hobj, const char *name,
 	ret = heapmem_init(hobj->pool, mem, size);
 	if (ret) {
 		if (_mem == NULL)
-			__STD(free(mem));
-		__STD(free(heap));
+			free(mem);
+		free(heap);
 		return ret;
 	}
 
@@ -99,13 +99,13 @@ int heapobj_pkg_init_private(void)
 		size = MIN_HEAPMEM_HEAPSZ;
 #endif
 	size = HEAPMEM_ARENA_SIZE(size);
-	mem = __STD(malloc(size));
+	mem = malloc(size);
 	if (mem == NULL)
 		return -ENOMEM;
 
 	ret = heapmem_init(&heapmem_main, mem, size);
 	if (ret) {
-		__STD(free(mem));
+		free(mem);
 		return ret;
 	}
 
lib/copperplate/heapobj-malloc.c +3 -3
index ec82d7821..a3918cc23 100644
@@ -92,7 +92,7 @@ void pvheapobj_destroy(struct heapobj *hobj)
 	struct pool_header *ph = hobj->pool;
 
 	__RT(pthread_mutex_destroy(&ph->lock));
-	__STD(free(ph));
+	free(ph);
 }
 
 int pvheapobj_extend(struct heapobj *hobj, size_t size, void *mem)
@@ -122,7 +122,7 @@ void *pvheapobj_alloc(struct heapobj *hobj, size_t size)
 	write_unlock(&ph->lock);
 
 	/* malloc(3) is not a cancellation point. */
-	ptr = __STD(malloc(size + sizeof(*bh)));
+	ptr = malloc(size + sizeof(*bh));
 	if (ptr == NULL) {
 		write_lock(&ph->lock);
 		goto fail;
@@ -149,7 +149,7 @@ void pvheapobj_free(struct heapobj *hobj, void *ptr)
 	write_lock(&ph->lock);
 	ph->used -= bh->size;
 	write_unlock(&ph->lock);
-	__STD(free(bh));
+	free(bh);
 }
 
 size_t pvheapobj_inquire(struct heapobj *hobj)
lib/copperplate/registry.c +7 -7
index 1d1544805..a60bf9877 100644
@@ -400,7 +400,7 @@ static int regfs_open(const char *path, struct fuse_file_info *fi)
 	}
 
 	if (fsobj->privsz) {
-		priv = __STD(malloc(fsobj->privsz));
+		priv = malloc(fsobj->privsz);
 		if (priv == NULL) {
 			ret = -ENOMEM;
 			goto done;
@@ -448,7 +448,7 @@ static int regfs_release(const char *path, struct fuse_file_info *fi)
 		CANCEL_RESTORE(svc);
 	}
 	if (priv)
-		__STD(free(priv));
+		free(priv);
 done:
 	read_unlock(&p->lock);
 	pop_cleanup_lock(&p->lock);
@@ -705,7 +705,7 @@ static int connect_regd(const char *sessdir, char **mountpt, int flags)
 	unsigned int hash;
 	socklen_t addrlen;
 
-	*mountpt = __STD(malloc(PATH_MAX));
+	*mountpt = malloc(PATH_MAX);
 	if (*mountpt == NULL)
 		return -ENOMEM;
 
@@ -720,7 +720,7 @@ static int connect_regd(const char *sessdir, char **mountpt, int flags)
 		s = __STD(socket(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0));
 		if (s < 0) {
 			ret = -errno;
-			__STD(free(*mountpt));
+			free(*mountpt);
 			return ret;
 		}
 		ret = __STD(connect(s, (struct sockaddr *)&sun, addrlen));
@@ -736,7 +736,7 @@ static int connect_regd(const char *sessdir, char **mountpt, int flags)
 		ret = -EAGAIN;
 	}
 
-	__STD(free(*mountpt));
+	free(*mountpt);
 
 	early_warning("cannot connect to registry daemon");
 
@@ -868,13 +868,13 @@ int fsobstack_grow_format(struct fsobstack *o, const char *fmt, ...)
 		       obstack_grow(&o->obstack, p, n);
 
 	       if (p != buf)
-		       __STD(free(p));
+		       free(p);
 
 	       if (n < len)
 		       return n < 0 ? -EINVAL : n;
 
 	       len = n + 1;
-	       p = __STD(malloc(len));
+	       p = malloc(len);
 	       if (p == NULL)
 		       break;
 	   }
lib/copperplate/traceobj.c +2 -2
index 8a3f4f5e6..3c4d69bf8 100644
@@ -78,7 +78,7 @@ int traceobj_init(struct traceobj *trobj, const char *label, int nr_marks)
 	trobj->cur_mark = 0;
 
 	if (nr_marks > 0) {
-		trobj->marks = __STD(malloc(sizeof(struct tracemark) * nr_marks));
+		trobj->marks = malloc(sizeof(struct tracemark) * nr_marks);
 		if (trobj->marks == NULL)
 			panic("cannot allocate mark table for tracing");
 	}
@@ -177,7 +177,7 @@ fail:
 
 void traceobj_destroy(struct traceobj *trobj)
 {
-	__STD(free(trobj->marks));
+	free(trobj->marks);
 	__RT(pthread_mutex_destroy(&trobj->lock));
 }
 
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 xeno-config: dont unconditionally link libmodechk with cobalt

Allow to build without linking to libmodechk.so.

---
 scripts/xeno-config-cobalt.in | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/xeno-config-cobalt.in +6 -2
index ae313d389..87d54fbf8 100644
@@ -15,7 +15,8 @@ XENO_CC="@CC@"
 XENO_TARGET_ARCH="@XENO_TARGET_ARCH@"
 XENO_INCLUDE_DIR="${staging}${includedir}"
 XENO_BASE_CFLAGS="-I$XENO_INCLUDE_DIR/cobalt -I$XENO_INCLUDE_DIR @XENO_USER_APP_CFLAGS@ -D__COBALT__"
-XENO_POSIX_LDFLAGS="-L${staging}${libdir} -lcobalt -lmodechk -lpthread -lrt @XENO_USER_APP_LDFLAGS@"
+XENO_COBALT_LDFLAGS="-L${staging}${libdir} -lcobalt"
+XENO_POSIX_LDFLAGS="-lpthread -lrt @XENO_USER_APP_LDFLAGS@"
 XENO_LIBRARY_DIR="${staging}${libdir}"
 LD_FILE_OPTION="@LD_FILE_OPTION@"
 
@@ -243,9 +244,11 @@ if test x$do_ldflags = xy; then
 	echo "no API specified, missing --skin before --ldflags" 1>&2
 	exit 1
     fi
+    lmodeck=
     ldflags=
     if test x$do_mode_check = xy; then
 	ldflags="`dump_wrappers modechk.wrappers`"
+	lmodeck=-lmodechk
     fi
     test x$compat = xy && ldflags="-ltrank $ldflags"
     copperplate=
@@ -283,7 +286,8 @@ if test x$do_ldflags = xy; then
 	bootstrap="${XENO_LIBRARY_DIR}/xenomai/bootstrap${codegen}.o"
     fi
     ldflags="-Wl,--no-as-needed $ldflags"
-    echo "$ldflags $copperplate $bootstrap $wrap_main $XENO_POSIX_LDFLAGS"
+    echo "$ldflags $copperplate $bootstrap $wrap_main $XENO_COBALT_LDFLAGS" \
+		"$lmodeck $XENO_POSIX_LDFLAGS"
 fi
 
 exit 0
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 2/2] xeno-config: dont unconditionally link libmodechk with cobalt

Quoted 35 lines · Norbert Lange via Xenomai

Allow to build without linking to libmodechk.so.

---
  scripts/xeno-config-cobalt.in | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
scripts/xeno-config-cobalt.in +4 -1
index ae313d389..87d54fbf8 100644
@@ -15,7 +15,8 @@ XENO_CC="@CC@"
  XENO_TARGET_ARCH="@XENO_TARGET_ARCH@"
  XENO_INCLUDE_DIR="${staging}${includedir}"
  XENO_BASE_CFLAGS="-I$XENO_INCLUDE_DIR/cobalt -I$XENO_INCLUDE_DIR @XENO_USER_APP_CFLAGS@ -D__COBALT__"
-XENO_POSIX_LDFLAGS="-L${staging}${libdir} -lcobalt -lmodechk -lpthread -lrt @XENO_USER_APP_LDFLAGS@"
+XENO_COBALT_LDFLAGS="-L${staging}${libdir} -lcobalt"
+XENO_POSIX_LDFLAGS="-lpthread -lrt @XENO_USER_APP_LDFLAGS@"
  XENO_LIBRARY_DIR="${staging}${libdir}"
  LD_FILE_OPTION="@LD_FILE_OPTION@"
 
@@ -243,9 +244,11 @@ if test x$do_ldflags = xy; then
  	echo "no API specified, missing --skin before --ldflags" 1>&2
  	exit 1
      fi
+    lmodeck=
      ldflags=
      if test x$do_mode_check = xy; then
  	ldflags="`dump_wrappers modechk.wrappers`"
+	lmodeck=-lmodechk
      fi
      test x$compat = xy && ldflags="-ltrank $ldflags"
      copperplate=

scripts/xeno-config-cobalt.in if test x$do_ldflags = xy; then · line 293

Quoted 9 lines
scripts/xeno-config-cobalt.in +2 -1
@@ -283,7 +286,8 @@ if test x$do_ldflags = xy; then
  	bootstrap="${XENO_LIBRARY_DIR}/xenomai/bootstrap${codegen}.o"
      fi
      ldflags="-Wl,--no-as-needed $ldflags"
-    echo "$ldflags $copperplate $bootstrap $wrap_main $XENO_POSIX_LDFLAGS"
+    echo "$ldflags $copperplate $bootstrap $wrap_main $XENO_COBALT_LDFLAGS" \
+		"$lmodeck $XENO_POSIX_LDFLAGS"
  fi
 
  exit 0

Thanks, both applied.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux