#include <sys/param.h>
#include <sys/mman.h>
#include "rtld_printf.h"
-#ifndef BSD
-#define MAP_COPY MAP_PRIVATE
-#define MAP_FILE 0
-#define MAP_ANON 0
-#endif
-
-#ifndef BSD /* Need do better than this */
-#define NEED_DEV_ZERO 1
-#endif
static void morecore();
static int findbucket();
int fd = -1;
int offset;
-#ifdef NEED_DEV_ZERO
- fd = open(_PATH_DEVZERO, O_RDWR, 0);
- if (fd == -1)
- perror(_PATH_DEVZERO);
-#endif
-
if (pagepool_end - pagepool_start > pagesz) {
caddr_t addr = (caddr_t)
(((long)pagepool_start + pagesz - 1) & ~(pagesz - 1));
pagepool_end = pagepool_start + n * pagesz;
pagepool_start += offset;
-#ifdef NEED_DEV_ZERO
- close(fd);
-#endif
return n;
}
int to_copy;
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;
* 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) {
#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;
void _rtld_error(const char *, ...) __printflike(1, 2);
const char *rtld_strerror(int);
Obj_Entry *map_object(int, const char *, const struct stat *);
-void *xcalloc(size_t);
+void *xcalloc(size_t, size_t);
void *xmalloc(size_t);
char *xstrdup(const char *);
extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];
#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 *
}
char *
-xstrdup(const char *s)
+xstrdup(const char *str)
{
- char *p = strdup(s);
- if (p == NULL) {
- rtld_fdputstr(STDERR_FILENO, "Out of memory\n");
- _exit(1);
- }
- return p;
+ char *copy;
+ size_t len;
+
+ len = strlen(str) + 1;
+ copy = xmalloc(len);
+ memcpy(copy, str, len);
+ return (copy);
}