svn commit: r233922 - in stable/9/libexec/rtld-elf: . ia64 powerpc64

Konstantin Belousov kib at FreeBSD.org
Thu Apr 5 10:38:08 UTC 2012


Author: kib
Date: Thu Apr  5 10:38:07 2012
New Revision: 233922
URL: http://svn.freebsd.org/changeset/base/233922

Log:
  MFC r233307:
  Use xmalloc() instead of malloc() in the places where malloc() calls
  are assumed to not fail.
  
  Make the xcalloc() calling conventions follow the calloc(3) calling
  conventions and replace unchecked calls to calloc() with calls to
  xcalloc().
  
  Remove redundand declarations from xmalloc.c, which are already
  present in rtld.h.

Modified:
  stable/9/libexec/rtld-elf/ia64/reloc.c
  stable/9/libexec/rtld-elf/powerpc64/reloc.c
  stable/9/libexec/rtld-elf/rtld.c
  stable/9/libexec/rtld-elf/rtld.h
  stable/9/libexec/rtld-elf/xmalloc.c
Directory Properties:
  stable/9/libexec/rtld-elf/   (props changed)

Modified: stable/9/libexec/rtld-elf/ia64/reloc.c
==============================================================================
--- stable/9/libexec/rtld-elf/ia64/reloc.c	Thu Apr  5 10:36:35 2012	(r233921)
+++ stable/9/libexec/rtld-elf/ia64/reloc.c	Thu Apr  5 10:38:07 2012	(r233922)
@@ -87,7 +87,7 @@ alloc_fptr(Elf_Addr target, Elf_Addr gp)
 	struct fptr* fptr;
 
 	if (next_fptr == last_fptr) {
-		current_chunk = malloc(sizeof(struct fptr_chunk));
+		current_chunk = xmalloc(sizeof(struct fptr_chunk));
 		next_fptr = &current_chunk->fptrs[0];
 		last_fptr = &current_chunk->fptrs[FPTR_CHUNK_SIZE];
 	}
@@ -116,9 +116,7 @@ alloc_fptrs(Obj_Entry *obj, bool mapped)
 		if (fptrs == MAP_FAILED)
 			fptrs = NULL;
 	} else {
-		fptrs = malloc(fbytes);
-		if (fptrs != NULL)
- 			memset(fptrs, 0, fbytes);
+		fptrs = xcalloc(1, fbytes);
 	}
 
 	/*

Modified: stable/9/libexec/rtld-elf/powerpc64/reloc.c
==============================================================================
--- stable/9/libexec/rtld-elf/powerpc64/reloc.c	Thu Apr  5 10:36:35 2012	(r233921)
+++ stable/9/libexec/rtld-elf/powerpc64/reloc.c	Thu Apr  5 10:38:07 2012	(r233922)
@@ -338,7 +338,7 @@ reloc_plt_object(Obj_Entry *obj, const E
 	reloff = rela - obj->pltrela;
 
 	if (obj->priv == NULL)
-		obj->priv = malloc(obj->pltrelasize);
+		obj->priv = xmalloc(obj->pltrelasize);
 	glink = obj->priv + reloff*sizeof(Elf_Addr)*2;
 
 	dbg(" reloc_plt_object: where=%p,reloff=%lx,glink=%p", (void *)where, reloff, glink);

Modified: stable/9/libexec/rtld-elf/rtld.c
==============================================================================
--- stable/9/libexec/rtld-elf/rtld.c	Thu Apr  5 10:36:35 2012	(r233921)
+++ stable/9/libexec/rtld-elf/rtld.c	Thu Apr  5 10:38:07 2012	(r233922)
@@ -3746,7 +3746,7 @@ tls_get_addr_slow(Elf_Addr **dtvp, int i
     /* Check dtv generation in case new modules have arrived */
     if (dtv[0] != tls_dtv_generation) {
 	wlock_acquire(rtld_bind_lock, &lockstate);
-	newdtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
+	newdtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
 	to_copy = dtv[1];
 	if (to_copy > tls_max_index)
 	    to_copy = tls_max_index;
@@ -3803,7 +3803,7 @@ allocate_tls(Obj_Entry *objs, void *oldt
 	return (oldtcb);
 
     assert(tcbsize >= TLS_TCB_SIZE);
-    tcb = calloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize);
+    tcb = xcalloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize);
     tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE);
 
     if (oldtcb != NULL) {
@@ -3819,7 +3819,7 @@ allocate_tls(Obj_Entry *objs, void *oldt
 	    }
 	}
     } else {
-	dtv = calloc(tls_max_index + 2, sizeof(Elf_Addr));
+	dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
 	tls[0] = dtv;
 	dtv[0] = tls_dtv_generation;
 	dtv[1] = tls_max_index;
@@ -3884,8 +3884,8 @@ allocate_tls(Obj_Entry *objs, void *oldt
     size = round(tls_static_space, tcbalign);
 
     assert(tcbsize >= 2*sizeof(Elf_Addr));
-    tls = calloc(1, size + tcbsize);
-    dtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
+    tls = xcalloc(1, size + tcbsize);
+    dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
 
     segbase = (Elf_Addr)(tls + size);
     ((Elf_Addr*)segbase)[0] = segbase;
@@ -4229,7 +4229,7 @@ rtld_verify_object_versions(Obj_Entry *o
      * way.
      */
     obj->vernum = maxvernum + 1;
-    obj->vertab = calloc(obj->vernum, sizeof(Ver_Entry));
+    obj->vertab = xcalloc(obj->vernum, sizeof(Ver_Entry));
 
     vd = obj->verdef;
     while (vd != NULL) {

Modified: stable/9/libexec/rtld-elf/rtld.h
==============================================================================
--- stable/9/libexec/rtld-elf/rtld.h	Thu Apr  5 10:36:35 2012	(r233921)
+++ stable/9/libexec/rtld-elf/rtld.h	Thu Apr  5 10:38:07 2012	(r233922)
@@ -58,7 +58,7 @@
 #endif
 
 #define NEW(type)	((type *) xmalloc(sizeof(type)))
-#define CNEW(type)	((type *) xcalloc(sizeof(type)))
+#define CNEW(type)	((type *) xcalloc(1, sizeof(type)))
 
 /* We might as well do booleans like C++. */
 typedef unsigned char bool;
@@ -320,7 +320,7 @@ typedef struct Struct_SymLook {
 extern void _rtld_error(const char *, ...) __printflike(1, 2);
 extern const char *rtld_strerror(int);
 extern Obj_Entry *map_object(int, const char *, const struct stat *);
-extern void *xcalloc(size_t);
+extern void *xcalloc(size_t, size_t);
 extern void *xmalloc(size_t);
 extern char *xstrdup(const char *);
 extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];

Modified: stable/9/libexec/rtld-elf/xmalloc.c
==============================================================================
--- stable/9/libexec/rtld-elf/xmalloc.c	Thu Apr  5 10:36:35 2012	(r233921)
+++ stable/9/libexec/rtld-elf/xmalloc.c	Thu Apr  5 10:38:07 2012	(r233922)
@@ -32,14 +32,17 @@
 #include "rtld.h"
 #include "rtld_printf.h"
 
-void *xcalloc(size_t);
-void *xmalloc(size_t);
-char *xstrdup(const char *);
-
 void *
-xcalloc(size_t size)
+xcalloc(size_t number, size_t size)
 {
-    return memset(xmalloc(size), 0, size);
+	void *p;
+
+	p = calloc(number, size);
+	if (p == NULL) {
+		rtld_fdputstr(STDERR_FILENO, "Out of memory\n");
+		_exit(1);
+	}
+	return (p);
 }
 
 void *


More information about the svn-src-all mailing list