From 8dc965347ddf9caabacc4ca0441efe3a4ec32af8 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 17 Apr 2017 13:52:19 -0700 Subject: [PATCH] rdoff: use nasm-provided safe memory allocation and I/O We already have abort-on-error memory allocation and I/O operations in nasmlib, so use them for rdoff as well. Delete long-since-obsolete rdoff Mkfiles directory. Signed-off-by: H. Peter Anvin --- Makefile.in | 40 ++++++----- Mkfiles/msvc.mak | 35 ++++++---- Mkfiles/openwcom.mak | 35 ++++++---- include/nasmlib.h | 4 +- include/rdoff.h | 131 ++----------------------------------- nasmlib/file.c | 10 +++ rdoff/Mkfiles/Makefile.dj | 75 --------------------- rdoff/Mkfiles/Makefile.emx | 76 --------------------- rdoff/Mkfiles/Makefile.sc | 56 ---------------- rdoff/Mkfiles/Makefile.unx | 75 --------------------- rdoff/Mkfiles/README | 4 -- rdoff/collectn.c | 7 +- rdoff/hash.c | 4 +- rdoff/ldrdf.c | 93 ++++++++++++-------------- rdoff/rdf2bin.c | 8 ++- rdoff/rdfdump.c | 78 +++++++++++----------- rdoff/rdflib.c | 17 ++--- rdoff/rdfload.c | 46 ++++++------- rdoff/rdfload.h | 4 +- rdoff/rdlar.c | 6 +- rdoff/rdlib.c | 26 ++++---- rdoff/rdoff.c | 51 ++++++++------- rdoff/rdx.c | 6 +- rdoff/segtab.c | 13 ++-- rdoff/symtab.c | 16 ++--- 25 files changed, 268 insertions(+), 648 deletions(-) delete mode 100644 rdoff/Mkfiles/Makefile.dj delete mode 100644 rdoff/Mkfiles/Makefile.emx delete mode 100644 rdoff/Mkfiles/Makefile.sc delete mode 100644 rdoff/Mkfiles/Makefile.unx delete mode 100644 rdoff/Mkfiles/README diff --git a/Makefile.in b/Makefile.in index ebe793ff..b377b79c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -751,33 +751,41 @@ rdoff/collectn.$(O): rdoff/collectn.c config/config.h config/msvc.h \ rdoff/collectn.h rdoff/hash.$(O): rdoff/hash.c config/config.h config/msvc.h config/unknown.h \ config/watcom.h include/compiler.h include/nasmint.h rdoff/hash.h +rdoff/iochk.$(O): rdoff/iochk.c config/config.h config/msvc.h \ + config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ + include/nasmlib.h rdoff/ldrdf.$(O): rdoff/ldrdf.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/ldsegs.h \ - rdoff/rdlib.h rdoff/segtab.h rdoff/symtab.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/collectn.h \ + rdoff/ldsegs.h rdoff/rdfutils.h rdoff/rdlib.h rdoff/segtab.h rdoff/symtab.h rdoff/rdf2bin.$(O): rdoff/rdf2bin.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - include/nasmlib.h include/rdoff.h rdoff/rdfload.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfload.h \ + rdoff/rdfutils.h rdoff/rdfdump.$(O): rdoff/rdfdump.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - include/rdoff.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdflib.$(O): rdoff/rdflib.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdfload.$(O): rdoff/rdfload.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - include/rdoff.h rdoff/collectn.h rdoff/rdfload.h rdoff/symtab.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/collectn.h \ + rdoff/rdfload.h rdoff/rdfutils.h rdoff/symtab.h rdoff/rdlar.$(O): rdoff/rdlar.c config/config.h config/msvc.h \ config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ rdoff/rdlar.h rdoff/rdlib.$(O): rdoff/rdlib.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - include/rdoff.h rdoff/rdlar.h rdoff/rdlib.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h \ + rdoff/rdlar.h rdoff/rdlib.h rdoff/rdoff.$(O): rdoff/rdoff.c config/config.h config/msvc.h \ - config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ - include/rdoff.h + config/unknown.h config/watcom.h include/compiler.h include/error.h \ + include/nasmint.h include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdx.$(O): rdoff/rdx.c config/config.h config/msvc.h config/unknown.h \ - config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h \ - rdoff/rdfload.h rdoff/symtab.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h \ + include/nasmlib.h include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h \ + rdoff/symtab.h rdoff/segtab.$(O): rdoff/segtab.c config/config.h config/msvc.h \ config/unknown.h config/watcom.h include/compiler.h include/nasmint.h \ rdoff/segtab.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 8ddafdf0..d43e76e1 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -644,30 +644,37 @@ rdoff\collectn.$(O): rdoff\collectn.c config\msvc.h config\unknown.h \ config\watcom.h include\compiler.h include\nasmint.h rdoff\collectn.h rdoff\hash.$(O): rdoff\hash.c config\msvc.h config\unknown.h config\watcom.h \ include\compiler.h include\nasmint.h rdoff\hash.h +rdoff\iochk.$(O): rdoff\iochk.c config\msvc.h config\unknown.h \ + config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h rdoff\ldrdf.$(O): rdoff\ldrdf.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h \ - include\rdoff.h rdoff\collectn.h rdoff\ldsegs.h rdoff\rdlib.h \ - rdoff\segtab.h rdoff\symtab.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\collectn.h rdoff\ldsegs.h \ + rdoff\rdfutils.h rdoff\rdlib.h rdoff\segtab.h rdoff\symtab.h rdoff\rdf2bin.$(O): rdoff\rdf2bin.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h include\nasmlib.h \ - include\rdoff.h rdoff\rdfload.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\rdfload.h rdoff\rdfutils.h rdoff\rdfdump.$(O): rdoff\rdfdump.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\rdfutils.h rdoff\rdflib.$(O): rdoff\rdflib.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\rdfutils.h rdoff\rdfload.$(O): rdoff\rdfload.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h \ - rdoff\collectn.h rdoff\rdfload.h rdoff\symtab.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\collectn.h rdoff\rdfload.h \ + rdoff\rdfutils.h rdoff\symtab.h rdoff\rdlar.$(O): rdoff\rdlar.c config\msvc.h config\unknown.h \ config\watcom.h include\compiler.h include\nasmint.h rdoff\rdlar.h rdoff\rdlib.$(O): rdoff\rdlib.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h \ - rdoff\rdlar.h rdoff\rdlib.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\rdfutils.h rdoff\rdlar.h \ + rdoff\rdlib.h rdoff\rdoff.$(O): rdoff\rdoff.c config\msvc.h config\unknown.h \ - config\watcom.h include\compiler.h include\nasmint.h include\rdoff.h + config\watcom.h include\compiler.h include\error.h include\nasmint.h \ + include\nasmlib.h include\rdoff.h rdoff\rdfutils.h rdoff\rdx.$(O): rdoff\rdx.c config\msvc.h config\unknown.h config\watcom.h \ - include\compiler.h include\nasmint.h include\rdoff.h rdoff\rdfload.h \ - rdoff\symtab.h + include\compiler.h include\error.h include\nasmint.h include\nasmlib.h \ + include\rdoff.h rdoff\rdfload.h rdoff\rdfutils.h rdoff\symtab.h rdoff\segtab.$(O): rdoff\segtab.c config\msvc.h config\unknown.h \ config\watcom.h include\compiler.h include\nasmint.h rdoff\segtab.h rdoff\symtab.$(O): rdoff\symtab.c config\msvc.h config\unknown.h \ diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 7c626d34..b6468dd6 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -618,30 +618,37 @@ rdoff/collectn.$(O): rdoff/collectn.c config/msvc.h config/unknown.h & config/watcom.h include/compiler.h include/nasmint.h rdoff/collectn.h rdoff/hash.$(O): rdoff/hash.c config/msvc.h config/unknown.h config/watcom.h & include/compiler.h include/nasmint.h rdoff/hash.h +rdoff/iochk.$(O): rdoff/iochk.c config/msvc.h config/unknown.h & + config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h rdoff/ldrdf.$(O): rdoff/ldrdf.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h & - include/rdoff.h rdoff/collectn.h rdoff/ldsegs.h rdoff/rdlib.h & - rdoff/segtab.h rdoff/symtab.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/ldsegs.h & + rdoff/rdfutils.h rdoff/rdlib.h rdoff/segtab.h rdoff/symtab.h rdoff/rdf2bin.$(O): rdoff/rdf2bin.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h include/nasmlib.h & - include/rdoff.h rdoff/rdfload.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h rdoff/rdfdump.$(O): rdoff/rdfdump.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdflib.$(O): rdoff/rdflib.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdfload.$(O): rdoff/rdfload.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h & - rdoff/collectn.h rdoff/rdfload.h rdoff/symtab.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/collectn.h rdoff/rdfload.h & + rdoff/rdfutils.h rdoff/symtab.h rdoff/rdlar.$(O): rdoff/rdlar.c config/msvc.h config/unknown.h & config/watcom.h include/compiler.h include/nasmint.h rdoff/rdlar.h rdoff/rdlib.$(O): rdoff/rdlib.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h & - rdoff/rdlar.h rdoff/rdlib.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdlar.h & + rdoff/rdlib.h rdoff/rdoff.$(O): rdoff/rdoff.c config/msvc.h config/unknown.h & - config/watcom.h include/compiler.h include/nasmint.h include/rdoff.h + config/watcom.h include/compiler.h include/error.h include/nasmint.h & + include/nasmlib.h include/rdoff.h rdoff/rdfutils.h rdoff/rdx.$(O): rdoff/rdx.c config/msvc.h config/unknown.h config/watcom.h & - include/compiler.h include/nasmint.h include/rdoff.h rdoff/rdfload.h & - rdoff/symtab.h + include/compiler.h include/error.h include/nasmint.h include/nasmlib.h & + include/rdoff.h rdoff/rdfload.h rdoff/rdfutils.h rdoff/symtab.h rdoff/segtab.$(O): rdoff/segtab.c config/msvc.h config/unknown.h & config/watcom.h include/compiler.h include/nasmint.h rdoff/segtab.h rdoff/symtab.$(O): rdoff/symtab.c config/msvc.h config/unknown.h & diff --git a/include/nasmlib.h b/include/nasmlib.h index 747ee11c..0b2bcb17 100644 --- a/include/nasmlib.h +++ b/include/nasmlib.h @@ -101,8 +101,10 @@ char * safe_alloc nasm_strndup(const char *, size_t); #define nasm_zeron(p,n) (memset((p), 0, (n)*sizeof(*(p)))) /* - * Wrapper around fwrite() which fatal-errors on output failure. + * Wrappers around fread()/fwrite() which fatal-errors on failure. + * For fread(), only use this if EOF is supposed to be a fatal error! */ +void nasm_read(void *, size_t, FILE *); void nasm_write(const void *, size_t, FILE *); /* diff --git a/include/rdoff.h b/include/rdoff.h index 019d012d..973be8c0 100644 --- a/include/rdoff.h +++ b/include/rdoff.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * Copyright 1996-2017 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -35,9 +35,8 @@ * rdoff.h RDOFF Object File manipulation routines header file */ -#ifndef RDOFF_RDOFF_H -#define RDOFF_RDOFF_H 1 - +#ifndef RDOFF_H +#define RDOFF_H 1 /* * RDOFF definitions. They are used by RDOFF utilities and by NASM's @@ -167,126 +166,4 @@ struct CommonRec { #define SYM_GLOBAL 4 #define SYM_IMPORT 8 -/*** The following part is used only by the utilities *************************/ - -#ifdef RDOFF_UTILS - -/* Some systems don't define this automatically */ -#if !defined(strdup) -extern char *strdup(const char *); -#endif - -typedef union RDFHeaderRec { - char type; /* invariant throughout all below */ - struct GenericRec g; /* type 0 */ - struct RelocRec r; /* type == 1 / 6 */ - struct ImportRec i; /* type == 2 / 7 */ - struct ExportRec e; /* type == 3 */ - struct DLLRec d; /* type == 4 */ - struct BSSRec b; /* type == 5 */ - struct ModRec m; /* type == 8 */ - struct CommonRec c; /* type == 10 */ -} rdfheaderrec; - -struct SegmentHeaderRec { - /* information from file */ - uint16_t type; - uint16_t number; - uint16_t reserved; - int32_t length; - - /* information built up here */ - int32_t offset; - uint8_t *data; /* pointer to segment data if it exists in memory */ -}; - -typedef struct RDFFileInfo { - FILE *fp; /* file descriptor; must be open to use this struct */ - int rdoff_ver; /* should be 1; any higher => not guaranteed to work */ - int32_t header_len; - int32_t header_ofs; - - uint8_t *header_loc; /* keep location of header */ - int32_t header_fp; /* current location within header for reading */ - - struct SegmentHeaderRec seg[RDF_MAXSEGS]; - int nsegs; - - int32_t eof_offset; /* offset of the first uint8_t beyond the end of this - module */ - - char *name; /* name of module in libraries */ - int *refcount; /* pointer to reference count on file, or NULL */ -} rdffile; - -#define BUF_BLOCK_LEN 4088 /* selected to match page size (4096) - * on 80x86 machines for efficiency */ -typedef struct memorybuffer { - int length; - uint8_t buffer[BUF_BLOCK_LEN]; - struct memorybuffer *next; -} memorybuffer; - -typedef struct { - memorybuffer *buf; /* buffer containing header records */ - int nsegments; /* number of segments to be written */ - int32_t seglength; /* total length of all the segments */ -} rdf_headerbuf; - -/* segments used by RDOFF, understood by rdoffloadseg */ -#define RDOFF_CODE 0 -#define RDOFF_DATA 1 -#define RDOFF_HEADER -1 -/* mask for 'segment' in relocation records to find if relative relocation */ -#define RDOFF_RELATIVEMASK 64 -/* mask to find actual segment value in relocation records */ -#define RDOFF_SEGMENTMASK 63 - -extern int rdf_errno; - -/* rdf_errno can hold these error codes */ -enum { - /* 0 */ RDF_OK, - /* 1 */ RDF_ERR_OPEN, - /* 2 */ RDF_ERR_FORMAT, - /* 3 */ RDF_ERR_READ, - /* 4 */ RDF_ERR_UNKNOWN, - /* 5 */ RDF_ERR_HEADER, - /* 6 */ RDF_ERR_NOMEM, - /* 7 */ RDF_ERR_VER, - /* 8 */ RDF_ERR_RECTYPE, - /* 9 */ RDF_ERR_RECLEN, - /* 10 */ RDF_ERR_SEGMENT -}; - -/* utility functions */ -int32_t translateint32_t(int32_t in); -uint16_t translateint16_t(uint16_t in); -char *translatesegmenttype(uint16_t type); - -/* RDOFF file manipulation functions */ -int rdfopen(rdffile * f, const char *name); -int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name); -int rdfclose(rdffile * f); -int rdffindsegment(rdffile * f, int segno); -int rdfloadseg(rdffile * f, int segment, void *buffer); -rdfheaderrec *rdfgetheaderrec(rdffile * f); /* returns static storage */ -void rdfheaderrewind(rdffile * f); /* back to start of header */ -void rdfperror(const char *app, const char *name); - -/* functions to write a new RDOFF header to a file - - use rdfnewheader to allocate a header, rdfaddheader to add records to it, - rdfaddsegment to notify the header routines that a segment exists, and - to tell it how int32_t the segment will be. - rdfwriteheader to write the file id, object length, and header - to a file, and then rdfdoneheader to dispose of the header */ - -rdf_headerbuf *rdfnewheader(void); -int rdfaddheader(rdf_headerbuf * h, rdfheaderrec * r); -int rdfaddsegment(rdf_headerbuf * h, int32_t seglength); -int rdfwriteheader(FILE * fp, rdf_headerbuf * h); -void rdfdoneheader(rdf_headerbuf * h); - -#endif /* RDOFF_UTILS */ - -#endif /* RDOFF_RDOFF_H */ +#endif /* RDOFF_H */ diff --git a/nasmlib/file.c b/nasmlib/file.c index 95f3c52a..7552b6fb 100644 --- a/nasmlib/file.c +++ b/nasmlib/file.c @@ -33,6 +33,16 @@ #include "file.h" +void nasm_read(void *ptr, size_t size, FILE *f) +{ + size_t n = fread(ptr, 1, size, f); + if (ferror(f)) { + nasm_fatal(0, "unable to read input: %s", strerror(errno)); + } else if (n != size || feof(f)) { + nasm_fatal(0, "fatal short read on input"); + } +} + void nasm_write(const void *ptr, size_t size, FILE *f) { size_t n = fwrite(ptr, 1, size, f); diff --git a/rdoff/Mkfiles/Makefile.dj b/rdoff/Mkfiles/Makefile.dj deleted file mode 100644 index 5621ed62..00000000 --- a/rdoff/Mkfiles/Makefile.dj +++ /dev/null @@ -1,75 +0,0 @@ -# Generated automatically from Makefile.in by configure. -# -# Auto-configuring Makefile for RDOFF object file utils; part of the -# Netwide Assembler -# -# The Netwide Assembler is copyright (C) 1996 Simon Tatham and -# Julian Hall. All rights reserved. The software is -# redistributable under the license given in the file "LICENSE" -# distributed in the NASM archive. - -# You may need to adjust these values. - -prefix = /djgpp -CC = gcc -s -CFLAGS = -O2 -I.. - -# You _shouldn't_ need to adjust anything below this line. - -exec_prefix = ${prefix} -bindir = ${exec_prefix}/bin -mandir = ${prefix}/man - -INSTALL = /usr/bin/install -c -INSTALL_PROGRAM = ${INSTALL} -INSTALL_DATA = ${INSTALL} -m 644 -LN_S = ln -s - -LDRDFLIBS = rdoff.o ../nasmlib.o symtab.o hash.o collectn.o rdlib.o segtab.o -RDXLIBS = rdoff.o rdfload.o symtab.o hash.o collectn.o - -.c.o: - $(CC) -c $(CFLAGS) $*.c - -all: rdfdump ldrdf rdx rdflib rdf2bin rdf2com - -rdfdump: rdfdump.o rdoff.o - $(CC) -o rdfdump rdfdump.o rdoff.o - -ldrdf: ldrdf.o $(LDRDFLIBS) - $(CC) -o ldrdf ldrdf.o $(LDRDFLIBS) -rdx: rdx.o $(RDXLIBS) - $(CC) -o rdx rdx.o $(RDXLIBS) -rdflib: rdflib.o - $(CC) -o rdflib rdflib.o -rdf2bin: rdf2bin.o $(RDXLIBS) nasmlib.o - $(CC) -o rdf2bin rdf2bin.o $(RDXLIBS) nasmlib.o -rdf2com: - $(LN_S) rdf2bin rdf2com - -rdf2bin.o: rdf2bin.c -rdfdump.o: rdfdump.c -rdoff.o: rdoff.c rdoff.h -ldrdf.o: ldrdf.c rdoff.h ../nasmlib.h symtab.h collectn.h rdlib.h -symtab.o: symtab.c symtab.h hash.h -collectn.o: collectn.c collectn.h -rdx.o: rdx.c rdoff.h rdfload.h symtab.h -rdfload.o: rdfload.c rdfload.h rdoff.h collectn.h symtab.h -rdlib.o: rdlib.c rdlib.h -rdflib.o: rdflib.c -hash.o: hash.c hash.h -segtab.o: segtab.c segtab.h - -nasmlib.o: ../nasmlib.c ../nasmlib.h ../names.c ../nasm.h - $(CC) -c $(CFLAGS) ../nasmlib.c - -clean: - rm -f *.o rdfdump ldrdf rdx rdflib rdf2bin rdf2com - -install: rdfdump ldrdf rdx rdflib rdf2bin rdf2com - $(INSTALL_PROGRAM) rdfdump $(bindir)/rdfdump - $(INSTALL_PROGRAM) ldrdf $(bindir)/ldrdf - $(INSTALL_PROGRAM) rdx $(bindir)/rdx - $(INSTALL_PROGRAM) rdflib $(bindir)/rdflib - $(INSTALL_PROGRAM) rdf2bin $(bindir)/rdf2bin - cd $(bindir); $(LN_S) rdf2bin rdf2com diff --git a/rdoff/Mkfiles/Makefile.emx b/rdoff/Mkfiles/Makefile.emx deleted file mode 100644 index aa535886..00000000 --- a/rdoff/Mkfiles/Makefile.emx +++ /dev/null @@ -1,76 +0,0 @@ -# Generated automatically from Makefile.in by configure. -# $Id$ -# -# Auto-configuring Makefile for RDOFF object file utils; part of the -# Netwide Assembler -# -# The Netwide Assembler is copyright (C) 1996 Simon Tatham and -# Julian Hall. All rights reserved. The software is -# redistributable under the license given in the file "LICENSE" -# distributed in the NASM archive. - -top_srcdir = .. -srcdir = . -prefix = /usr/local -exec_prefix = ${prefix} -bindir = ${exec_prefix}/bin -mandir = ${prefix}/man - -CC = gcc -CFLAGS = -s -Zomf -O2 -fomit-frame-pointer -Wall -ansi -pedantic -I$(srcdir) -I$(top_srcdir) -LDFLAGS = -s -Zomf -Zexe -Zcrtdll -LIBS = -lgcc - -INSTALL = .././install-sh -c -INSTALL_PROGRAM = ${INSTALL} -INSTALL_DATA = ${INSTALL} -m 644 - -LDRDFLIBS = rdoff.o nasmlib.o symtab.o collectn.o rdlib.o segtab.o hash.o -RDXLIBS = rdoff.o rdfload.o symtab.o collectn.o hash.o - -.c.o: - $(CC) -c $(CFLAGS) -o $@ $< - -all: rdfdump ldrdf rdx rdflib rdf2bin - -rdfdump: rdfdump.o rdoff.o - $(CC) $(LDFLAGS) -o rdfdump rdfdump.o rdoff.o $(LIBS) -ldrdf: ldrdf.o $(LDRDFLIBS) - $(CC) $(LDFLAGS) -o ldrdf ldrdf.o $(LDRDFLIBS) $(LIBS) -rdx: rdx.o $(RDXLIBS) - $(CC) $(LDFLAGS) -o rdx rdx.o $(RDXLIBS) $(LIBS) -rdflib: rdflib.o - $(CC) $(LDFLAGS) -o rdflib rdflib.o $(LIBS) -rdf2bin: rdf2bin.o $(RDXLIBS) nasmlib.o - $(CC) $(LDFLAGS) -o rdf2bin rdf2bin.o $(RDXLIBS) nasmlib.o $(LIBS) - -rdf2bin.o: rdf2bin.c -rdfdump.o: rdfdump.c -rdoff.o: rdoff.c rdoff.h -ldrdf.o: ldrdf.c rdoff.h $(top_srcdir)/nasmlib.h symtab.h collectn.h rdlib.h -symtab.o: symtab.c symtab.h -collectn.o: collectn.c collectn.h -rdx.o: rdx.c rdoff.h rdfload.h symtab.h -rdfload.o: rdfload.c rdfload.h rdoff.h collectn.h symtab.h -rdlib.o: rdlib.c rdlib.h -rdflib.o: rdflib.c -segtab.o: segtab.c - -nasmlib.o: $(top_srcdir)/nasmlib.c - $(CC) -c $(CFLAGS) -o $@ $(top_srcdir)/nasmlib.c - -clean: - rm -f *.o rdfdump ldrdf rdx rdflib rdf2bin rdf2com - -spotless: clean - rm -f Makefile - -distclean: spotless - -install: rdfdump ldrdf rdx rdflib rdf2bin rdf2com - $(INSTALL_PROGRAM) rdfdump $(INSTALLROOT)$(bindir)/rdfdump - $(INSTALL_PROGRAM) ldrdf $(INSTALLROOT)$(bindir)/ldrdf - $(INSTALL_PROGRAM) rdx $(INSTALLROOT)$(bindir)/rdx - $(INSTALL_PROGRAM) rdflib $(INSTALLROOT)$(bindir)/rdflib - $(INSTALL_PROGRAM) rdf2bin $(INSTALLROOT)$(bindir)/rdf2bin - cd $(INSTALLROOT)$(bindir) && rm -f rdf2com && $(LN_S) rdf2bin rdf2com diff --git a/rdoff/Mkfiles/Makefile.sc b/rdoff/Mkfiles/Makefile.sc deleted file mode 100644 index 501d487b..00000000 --- a/rdoff/Mkfiles/Makefile.sc +++ /dev/null @@ -1,56 +0,0 @@ -# Makefile for RDOFF object file utils; part of the Netwide Assembler -# -# The Netwide Assembler is copyright (C) 1996 Simon Tatham and -# Julian Hall. All rights reserved. The software is -# redistributable under the license given in the file "LICENSE" -# distributed in the NASM archive. -# -# This Makefile is designed for use under Unix (probably fairly -# portably). - -CC = sc -CCFLAGS = -I..\ -c -a1 -mn -Nc -w2 -w7 -o+time -5 -LINK = link -LINKFLAGS = /noi /exet:NT /su:console - -OBJ=obj -EXE=.exe - -NASMLIB = ..\nasmlib.$(OBJ) -NASMLIB_H = ..\nasmlib.h -LDRDFLIBS = rdoff.$(OBJ) $(NASMLIB) symtab.$(OBJ) collectn.$(OBJ) rdlib.$(OBJ) -RDXLIBS = rdoff.$(OBJ) rdfload.$(OBJ) symtab.$(OBJ) collectn.$(OBJ) - -.c.$(OBJ): - $(CC) $(CCFLAGS) $*.c - -all : rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE) rdf2com$(EXE) - -rdfdump$(EXE) : rdfdump.$(OBJ) - $(LINK) $(LINKFLAGS) rdfdump.$(OBJ), rdfdump$(EXE); -ldrdf$(EXE) : ldrdf.$(OBJ) $(LDRDFLIBS) - $(LINK) $(LINKFLAGS) ldrdf.$(OBJ) $(LDRDFLIBS), ldrdf$(EXE); -rdx$(EXE) : rdx.$(OBJ) $(RDXLIBS) - $(LINK) $(LINKFLAGS) rdx.$(OBJ) $(RDXLIBS), rdx$(EXE); -rdflib$(EXE) : rdflib.$(OBJ) - $(LINK) $(LINKFLAGS) rdflib.$(OBJ), rdflib$(EXE); -rdf2bin$(EXE) : rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB) - $(LINK) $(LINKFLAGS) rdf2bin.$(OBJ) $(RDXLIBS) $(NASMLIB), rdf2bin$(EXE); -rdf2com$(EXE) : rdf2bin$(EXE) - copy rdf2bin$(EXE) rdf2com$(EXE) - -rdf2bin.$(OBJ) : rdf2bin.c -rdfdump.$(OBJ) : rdfdump.c -rdoff.$(OBJ) : rdoff.c rdoff.h -ldrdf.$(OBJ) : ldrdf.c rdoff.h $(NASMLIB_H) symtab.h collectn.h rdlib.h -symtab.$(OBJ) : symtab.c symtab.h -collectn.$(OBJ) : collectn.c collectn.h -rdx.$(OBJ) : rdx.c rdoff.h rdfload.h symtab.h -rdfload.$(OBJ) : rdfload.c rdfload.h rdoff.h collectn.h symtab.h -rdlib.$(OBJ) : rdlib.c rdlib.h -rdflib.$(OBJ) : rdflib.c - -clean : - del *.$(OBJ) rdfdump$(EXE) ldrdf$(EXE) rdx$(EXE) rdflib$(EXE) rdf2bin$(EXE) - - diff --git a/rdoff/Mkfiles/Makefile.unx b/rdoff/Mkfiles/Makefile.unx deleted file mode 100644 index 9041b417..00000000 --- a/rdoff/Mkfiles/Makefile.unx +++ /dev/null @@ -1,75 +0,0 @@ -# Generated automatically from Makefile.in by configure. -# -# Auto-configuring Makefile for RDOFF object file utils; part of the -# Netwide Assembler -# -# The Netwide Assembler is copyright (C) 1996 Simon Tatham and -# Julian Hall. All rights reserved. The software is -# redistributable under the license given in the file "LICENSE" -# distributed in the NASM archive. - -# You may need to adjust these values. - -prefix = /usr/local -CC = cc -CFLAGS = -O -I.. - -# You _shouldn't_ need to adjust anything below this line. - -exec_prefix = ${prefix} -bindir = ${exec_prefix}/bin -mandir = ${prefix}/man - -INSTALL = /usr/bin/install -c -INSTALL_PROGRAM = ${INSTALL} -INSTALL_DATA = ${INSTALL} -m 644 -LN_S = ln -s - -LDRDFLIBS = rdoff.o ../nasmlib.o symtab.o hash.o collectn.o rdlib.o segtab.o -RDXLIBS = rdoff.o rdfload.o symtab.o hash.o collectn.o - -.c.o: - $(CC) -c $(CFLAGS) $*.c - -all: rdfdump ldrdf rdx rdflib rdf2bin rdf2com - -rdfdump: rdfdump.o rdoff.o - $(CC) -o rdfdump rdfdump.o rdoff.o - -ldrdf: ldrdf.o $(LDRDFLIBS) - $(CC) -o ldrdf ldrdf.o $(LDRDFLIBS) -rdx: rdx.o $(RDXLIBS) - $(CC) -o rdx rdx.o $(RDXLIBS) -rdflib: rdflib.o - $(CC) -o rdflib rdflib.o -rdf2bin: rdf2bin.o $(RDXLIBS) nasmlib.o - $(CC) -o rdf2bin rdf2bin.o $(RDXLIBS) nasmlib.o -rdf2com: - $(LN_S) rdf2bin rdf2com - -rdf2bin.o: rdf2bin.c -rdfdump.o: rdfdump.c -rdoff.o: rdoff.c rdoff.h -ldrdf.o: ldrdf.c rdoff.h ../nasmlib.h symtab.h collectn.h rdlib.h -symtab.o: symtab.c symtab.h hash.h -collectn.o: collectn.c collectn.h -rdx.o: rdx.c rdoff.h rdfload.h symtab.h -rdfload.o: rdfload.c rdfload.h rdoff.h collectn.h symtab.h -rdlib.o: rdlib.c rdlib.h -rdflib.o: rdflib.c -hash.o: hash.c hash.h -segtab.o: segtab.c segtab.h - -nasmlib.o: ../nasmlib.c ../nasmlib.h ../names.c ../nasm.h - $(CC) -c $(CFLAGS) ../nasmlib.c - -clean: - rm -f *.o rdfdump ldrdf rdx rdflib rdf2bin rdf2com - -install: rdfdump ldrdf rdx rdflib rdf2bin rdf2com - $(INSTALL_PROGRAM) rdfdump $(bindir)/rdfdump - $(INSTALL_PROGRAM) ldrdf $(bindir)/ldrdf - $(INSTALL_PROGRAM) rdx $(bindir)/rdx - $(INSTALL_PROGRAM) rdflib $(bindir)/rdflib - $(INSTALL_PROGRAM) rdf2bin $(bindir)/rdf2bin - cd $(bindir); $(LN_S) rdf2bin rdf2com diff --git a/rdoff/Mkfiles/README b/rdoff/Mkfiles/README deleted file mode 100644 index 7e684992..00000000 --- a/rdoff/Mkfiles/README +++ /dev/null @@ -1,4 +0,0 @@ -These are pre-created Makefiles for various platforms, use them if -GNU autoconf/automake packages are not supported on your system. - -Copy appropriate Makefile to ../Makefile and run make. diff --git a/rdoff/collectn.c b/rdoff/collectn.c index 317c5286..d77f54b5 100644 --- a/rdoff/collectn.c +++ b/rdoff/collectn.c @@ -4,8 +4,7 @@ * This file is public domain. */ -#include "compiler.h" -#include +#include "rdfutils.h" #include "collectn.h" void collection_init(Collection * c) @@ -22,7 +21,7 @@ void **colln(Collection * c, int index) while (index >= 32) { index -= 32; if (c->next == NULL) { - c->next = malloc(sizeof(Collection)); + c->next = nasm_malloc(sizeof(Collection)); collection_init(c->next); } c = c->next; @@ -36,7 +35,7 @@ void collection_reset(Collection * c) if (c->next) { collection_reset(c->next); - free(c->next); + nasm_free(c->next); } c->next = NULL; diff --git a/rdoff/hash.c b/rdoff/hash.c index ad2b568e..f2afad0f 100644 --- a/rdoff/hash.c +++ b/rdoff/hash.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2009 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF diff --git a/rdoff/ldrdf.c b/rdoff/ldrdf.c index 2db980f0..dd80d70e 100644 --- a/rdoff/ldrdf.c +++ b/rdoff/ldrdf.c @@ -56,9 +56,7 @@ #include #include -#define RDOFF_UTILS - -#include "rdoff.h" +#include "rdfutils.h" #include "symtab.h" #include "collectn.h" #include "rdlib.h" @@ -91,9 +89,6 @@ struct modulenode { #include "ldsegs.h" -#define newstr(str) strcpy(malloc(strlen(str) + 1),str) -#define newstrcat(s1,s2) strcat(strcpy(malloc(strlen(s1)+strlen(s2)+1),s1),s2) - /* ========================================================================== * Function prototypes of private utility functions */ @@ -200,10 +195,10 @@ static void loadmodule(const char *filename) /* allocate a new module entry on the end of the modules list */ if (!modules) { - modules = malloc(sizeof(*modules)); + modules = nasm_malloc(sizeof(*modules)); lastmodule = modules; } else { - lastmodule->next = malloc(sizeof(*modules)); + lastmodule->next = nasm_malloc(sizeof(*modules)); lastmodule = lastmodule->next; } @@ -224,7 +219,7 @@ static void loadmodule(const char *filename) * factor if we decide to keep them) */ lastmodule->header = NULL; - lastmodule->name = strdup(filename); + lastmodule->name = nasm_strdup(filename); lastmodule->next = NULL; processmodule(filename, lastmodule); @@ -325,7 +320,7 @@ void processmodule(const char *filename, struct modulenode *mod) * extract symbols from the header, and dump them into the * symbol table */ - header = malloc(mod->f.header_len); + header = nasm_malloc(mod->f.header_len); if (!header) { fprintf(stderr, "ldrdf: not enough memory\n"); exit(1); @@ -420,7 +415,7 @@ void processmodule(const char *filename, struct modulenode *mod) * of this program... */ mod->f.header_loc = NULL; - free(header); + nasm_free(header); #endif @@ -524,12 +519,12 @@ void symtab_add(const char *symbol, int segment, int32_t offset) /* * this is the first declaration of this symbol */ - ste = malloc(sizeof(symtabEnt)); + ste = nasm_malloc(sizeof(symtabEnt)); if (!ste) { fprintf(stderr, "ldrdf: out of memory\n"); exit(1); } - ste->name = strdup(symbol); + ste->name = nasm_strdup(symbol); ste->segment = segment; ste->offset = offset; ste->flags = 0; @@ -571,13 +566,13 @@ static void add_library(const char *name) return; } if (!libraries) { - lastlib = libraries = malloc(sizeof(*libraries)); + lastlib = libraries = nasm_malloc(sizeof(*libraries)); if (!libraries) { fprintf(stderr, "ldrdf: out of memory\n"); exit(1); } } else { - lastlib->next = malloc(sizeof(*libraries)); + lastlib->next = nasm_malloc(sizeof(*libraries)); if (!lastlib->next) { fprintf(stderr, "ldrdf: out of memory\n"); exit(1); @@ -626,7 +621,7 @@ static int search_libraries(void) if (options.verbose > 3) printf(" looking in module `%s'\n", f.name); - header = malloc(f.header_len); + header = nasm_malloc(f.header_len); if (!header) { fprintf(stderr, "ldrdf: not enough memory\n"); exit(1); @@ -671,20 +666,20 @@ static int search_libraries(void) * there are modules on the module list by the time * we get here. */ - lastmodule->next = malloc(sizeof(*lastmodule->next)); + lastmodule->next = nasm_malloc(sizeof(*lastmodule->next)); if (!lastmodule->next) { fprintf(stderr, "ldrdf: not enough memory\n"); exit(1); } lastmodule = lastmodule->next; memcpy(&lastmodule->f, &f, sizeof(f)); - lastmodule->name = strdup(f.name); + lastmodule->name = nasm_strdup(f.name); lastmodule->next = NULL; processmodule(f.name, lastmodule); break; } if (!keepfile) { - free(f.name); + nasm_free(f.name); f.name = NULL; f.fp = NULL; } @@ -744,7 +739,7 @@ static void write_output(const char *filename) printf("\nadding generic record from binary file %s\n", generic_rec_file); - hr = (rdfheaderrec *) malloc(sizeof(struct GenericRec)); + hr = (rdfheaderrec *) nasm_malloc(sizeof(struct GenericRec)); if ((ff = fopen(generic_rec_file, "r")) == NULL) { fprintf(stderr, "ldrdf: couldn't open %s for input\n", generic_rec_file); @@ -763,7 +758,7 @@ static void write_output(const char *filename) hr->g.type = RDFREC_GENERIC; hr->g.reclen = n; rdfaddheader(rdfheader, hr); - free(hr); + nasm_free(hr); } /* @@ -774,19 +769,19 @@ static void write_output(const char *filename) if ((n < 1) || (n >= MODLIB_NAME_MAX)) { fprintf(stderr, "ldrdf: invalid length of module name `%s'\n", - modname_specified); + modname_specified); exit(1); } if (options.verbose) printf("\nadding module name record %s\n", modname_specified); - hr = (rdfheaderrec *) malloc(sizeof(struct ModRec)); + hr = (rdfheaderrec *) nasm_malloc(sizeof(struct ModRec)); hr->m.type = RDFREC_MODNAME; hr->m.reclen = n + 1; strcpy(hr->m.modname, modname_specified); rdfaddheader(rdfheader, hr); - free(hr); + nasm_free(hr); } @@ -803,7 +798,7 @@ static void write_output(const char *filename) outputseg[i].data = NULL; if (!outputseg[i].length) continue; - outputseg[i].data = malloc(outputseg[i].length); + outputseg[i].data = nasm_malloc(outputseg[i].length); if (!outputseg[i].data) { fprintf(stderr, "ldrdf: out of memory\n"); exit(1); @@ -841,7 +836,7 @@ static void write_output(const char *filename) * Perform fixups, and add new header records where required */ - header = malloc(cur->f.header_len); + header = nasm_malloc(cur->f.header_len); if (!header) { fprintf(stderr, "ldrdf: out of memory\n"); exit(1); @@ -1000,12 +995,12 @@ static void write_output(const char *filename) * future reference */ if (!se) { - se = malloc(sizeof(*se)); + se = nasm_malloc(sizeof(*se)); if (!se) { fprintf(stderr, "ldrdf: out of memory\n"); exit(1); } - se->name = strdup(hr->i.label); + se->name = nasm_strdup(hr->i.label); se->flags = 0; se->segment = availableseg++; se->offset = 0; @@ -1125,7 +1120,7 @@ static void write_output(const char *filename) } } - free(header); + nasm_free(header); done_seglocations(&segs); } @@ -1155,22 +1150,14 @@ static void write_output(const char *filename) * the output file */ for (i = 0; i < nsegs; i++) { - uint16_t s; - int32_t l; - if (i == 2) continue; - s = translateint16_t(outputseg[i].type); - fwrite(&s, 2, 1, f); - s = translateint16_t(outputseg[i].number); - fwrite(&s, 2, 1, f); - s = translateint16_t(outputseg[i].reserved); - fwrite(&s, 2, 1, f); - l = translateint32_t(outputseg[i].length); - fwrite(&l, 4, 1, f); - - fwrite(outputseg[i].data, outputseg[i].length, 1, f); + fwriteint16_t(outputseg[i].type, f); + fwriteint16_t(outputseg[i].number, f); + fwriteint16_t(outputseg[i].reserved, f); + fwriteint32_t(outputseg[i].length, f); + nasm_write(outputseg[i].data, outputseg[i].length, f); } fwritezero(10, f); @@ -1204,6 +1191,8 @@ int main(int argc, char **argv) int moduleloaded = 0; char *respstrings[128] = { 0, }; + rdoff_init(); + options.verbose = 0; options.align = 16; options.dynalink = 0; @@ -1252,11 +1241,11 @@ int main(int argc, char **argv) case 'm': if (argv[0][2] == 'n') { modname_specified = argv[1]; - argv++, argc--; - if (!argc) { - fprintf(stderr, "ldrdf: -mn expects a module name\n"); - exit(1); - } + argv++, argc--; + if (!argc) { + fprintf(stderr, "ldrdf: -mn expects a module name\n"); + exit(1); + } } break; case 'o': @@ -1317,7 +1306,7 @@ int main(int argc, char **argv) fprintf(stderr, "ldrdf: too many input files\n"); exit(1); } - *(respstrings + i) = newstr(buf); + *(respstrings + i) = nasm_strdup(buf); argc++, i++; } fclose(f); @@ -1331,8 +1320,8 @@ int main(int argc, char **argv) generic_rec_file = argv[1]; argv++, argc--; if (!argc) { - fprintf(stderr, "ldrdf: -g expects a file name\n"); - exit(1); + fprintf(stderr, "ldrdf: -g expects a file name\n"); + exit(1); } break; default: @@ -1371,12 +1360,12 @@ int main(int argc, char **argv) break; if (!strncmp(*argv, "-l", 2)) { if (libpath && (argv[0][2] != '/')) - add_library(newstrcat(libpath, *argv + 2)); + add_library(nasm_strcat(libpath, *argv + 2)); else add_library(*argv + 2); } else { if (objpath && (argv[0][0] != '/')) - loadmodule(newstrcat(objpath, *argv)); + loadmodule(nasm_strcat(objpath, *argv)); else loadmodule(*argv); moduleloaded = 1; diff --git a/rdoff/rdf2bin.c b/rdoff/rdf2bin.c index 1e33075c..1beb8245 100644 --- a/rdoff/rdf2bin.c +++ b/rdoff/rdf2bin.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2009 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -254,7 +254,7 @@ static const char *getformat(const char *pathname) const char *p; static char fmt_buf[16]; - /* + /* * Search backwards for the string "rdf2" followed by a string * of alphanumeric characters. This should handle path prefixes, * as well as extensions (e.g. C:\FOO\RDF2SREC.EXE). @@ -303,6 +303,8 @@ int main(int argc, char **argv) return 1; } + rdoff_init(); + argv++, argc--; while (argc > 2) { diff --git a/rdoff/rdfdump.c b/rdoff/rdfdump.c index 2e977ace..b483477b 100644 --- a/rdoff/rdfdump.c +++ b/rdoff/rdfdump.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2014 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -41,9 +41,7 @@ #include #include -#define RDOFF_UTILS - -#include "rdoff.h" +#include "rdfutils.h" #define PROGRAM_VERSION "2.3" @@ -57,9 +55,9 @@ static void print_header(int32_t length, int rdf_version) uint16_t rs; while (length > 0) { - fread(&t, 1, 1, infile); + nasm_read(&t, 1, infile); if (rdf_version >= 2) { - fread(&reclen, 1, 1, infile); + nasm_read(&reclen, 1, infile); } switch (t) { case RDFREC_GENERIC: /* generic record */ @@ -69,10 +67,10 @@ static void print_header(int32_t length, int rdf_version) case RDFREC_RELOC: /* relocation record */ case RDFREC_SEGRELOC: /* segment relocation */ - fread(&s, 1, 1, infile); - fread(&o, 4, 1, infile); - fread(&l, 1, 1, infile); - fread(&rs, 2, 1, infile); + nasm_read(&s, 1, infile); + nasm_read(&o, 4, infile); + nasm_read(&l, 1, infile); + nasm_read(&rs, 2, infile); printf(" %s: location (%04x:%08"PRIx32"), length %d, " "referred seg %04x\n", t == 1 ? "relocation" : "seg relocation", (int)s, @@ -88,17 +86,17 @@ static void print_header(int32_t length, int rdf_version) case RDFREC_IMPORT: /* import record */ case RDFREC_FARIMPORT: /* import far symbol */ - fread(&flags, 1, 1, infile); - fread(&rs, 2, 1, infile); + nasm_read(&flags, 1, infile); + nasm_read(&rs, 2, infile); ll = 0; if (rdf_version == 1) { do { - fread(&buf[ll], 1, 1, infile); + nasm_read(&buf[ll], 1, infile); } while (buf[ll++]); } else { for (; ll < reclen - 3; ll++) - fread(&buf[ll], 1, 1, infile); + nasm_read(&buf[ll], 1, infile); } if (t == 7) @@ -117,18 +115,18 @@ static void print_header(int32_t length, int rdf_version) break; case RDFREC_GLOBAL: /* export record */ - fread(&flags, 1, 1, infile); - fread(&s, 1, 1, infile); - fread(&o, 4, 1, infile); + nasm_read(&flags, 1, infile); + nasm_read(&s, 1, infile); + nasm_read(&o, 4, infile); ll = 0; if (rdf_version == 1) { do { - fread(&buf[ll], 1, 1, infile); + nasm_read(&buf[ll], 1, infile); } while (buf[ll++]); } else { for (; ll < reclen - 6; ll++) - fread(&buf[ll], 1, 1, infile); + nasm_read(&buf[ll], 1, infile); } printf((flags & SYM_GLOBAL) ? " export" : " public"); if (flags & SYM_FUNCTION) @@ -145,11 +143,11 @@ static void print_header(int32_t length, int rdf_version) ll = 0; if (rdf_version == 1) { do { - fread(&buf[ll], 1, 1, infile); + nasm_read(&buf[ll], 1, infile); } while (buf[ll++]); } else { for (; ll < reclen; ll++) - fread(&buf[ll], 1, 1, infile); + nasm_read(&buf[ll], 1, infile); } if (t == 4) printf(" dll: %s\n", buf); @@ -160,7 +158,7 @@ static void print_header(int32_t length, int rdf_version) break; case RDFREC_BSS: /* BSS reservation */ - fread(&ll, 4, 1, infile); + nasm_read(&ll, 4, infile); printf(" bss reservation: %08"PRIx32" bytes\n", translateint32_t(ll)); if (rdf_version == 1) length -= 5; @@ -172,11 +170,11 @@ static void print_header(int32_t length, int rdf_version) uint16_t seg, align; uint32_t size; - fread(&seg, 2, 1, infile); - fread(&size, 4, 1, infile); - fread(&align, 2, 1, infile); + nasm_read(&seg, 2, infile); + nasm_read(&size, 4, infile); + nasm_read(&align, 2, infile); for (ll = 0; ll < reclen - 8; ll++) - fread(buf + ll, 1, 1, infile); + nasm_read(buf + ll, 1, infile); printf(" common: segment %04x = %s, %"PRId32":%d\n", translateint16_t(seg), buf, translateint32_t(size), translateint16_t(align)); @@ -221,6 +219,8 @@ int main(int argc, char **argv) exit(1); } + rdoff_init(); + if (!strcmp(argv[1], "-v")) { verbose = 1; if (argc < 3) { @@ -236,7 +236,7 @@ int main(int argc, char **argv) exit(1); } - fread(id, 6, 1, infile); + nasm_read(id, 6, infile); if (strncmp(id, "RDOFF", 5)) { fputs("rdfdump: File does not contain valid RDOFF header\n", stderr); @@ -251,23 +251,23 @@ int main(int argc, char **argv) version = id[5] - '0'; if (version > 1) { - fread(&l, 4, 1, infile); + nasm_read(&l, 4, infile); objectlength = translateint32_t(l); printf("Object content size: %"PRId32" bytes\n", objectlength); } - fread(&l, 4, 1, infile); + nasm_read(&l, 4, infile); headerlength = translateint32_t(l); printf("Header (%"PRId32" bytes):\n", headerlength); print_header(headerlength, version); if (version == 1) { - fread(&l, 4, 1, infile); + nasm_read(&l, 4, infile); l = translateint32_t(l); printf("\nText segment length = %"PRId32" bytes\n", l); offset = 0; while (l--) { - fread(id, 1, 1, infile); + nasm_read(id, 1, infile); if (verbose) { if (offset % 16 == 0) printf("\n%08"PRIx32" ", offset); @@ -278,14 +278,14 @@ int main(int argc, char **argv) if (verbose) printf("\n\n"); - fread(&l, 4, 1, infile); + nasm_read(&l, 4, infile); l = translateint32_t(l); printf("Data segment length = %"PRId32" bytes\n", l); if (verbose) { offset = 0; while (l--) { - fread(id, 1, 1, infile); + nasm_read(id, 1, infile); if (offset % 16 == 0) printf("\n%08"PRIx32" ", offset); printf(" %02x", (int)(uint8_t)id[0]); @@ -295,7 +295,7 @@ int main(int argc, char **argv) } } else { do { - fread(&s, 2, 1, infile); + nasm_read(&s, 2, infile); s = translateint16_t(s); if (!s) { printf("\nNULL segment\n"); @@ -306,18 +306,18 @@ int main(int argc, char **argv) translatesegmenttype(s)); nsegments++; - fread(&s, 2, 1, infile); + nasm_read(&s, 2, infile); printf(" Number = %04X\n", (int)translateint16_t(s)); - fread(&s, 2, 1, infile); + nasm_read(&s, 2, infile); printf(" Resrvd = %04X\n", (int)translateint16_t(s)); - fread(&l, 4, 1, infile); + nasm_read(&l, 4, infile); l = translateint32_t(l); printf(" Length = %"PRId32" bytes\n", l); segmentcontentlength += l; offset = 0; while (l--) { - fread(id, 1, 1, infile); + nasm_read(id, 1, infile); if (verbose) { if (offset % 16 == 0) printf("\n%08"PRIx32" ", offset); diff --git a/rdoff/rdflib.c b/rdoff/rdflib.c index a1c3abe7..79a2085b 100644 --- a/rdoff/rdflib.c +++ b/rdoff/rdflib.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2009 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -57,6 +57,7 @@ */ #include "compiler.h" +#include "rdfutils.h" #include #include @@ -168,6 +169,8 @@ int main(int argc, char **argv) exit(1); } + rdoff_init(); + switch (argv[1][0]) { case 'c': /* create library */ fp = fopen(argv[2], "wb"); @@ -176,12 +179,10 @@ int main(int argc, char **argv) perror("rdflib"); exit(1); } - fwrite(sig_modname, 1, strlen(sig_modname) + 1, fp); - fwrite(rdl_signature, 1, strlen(rdl_signature), fp); + nasm_write(sig_modname, strlen(sig_modname) + 1, fp); + nasm_write(rdl_signature, strlen(rdl_signature), fp); t = time(NULL); - l = sizeof(t); - fwrite(&l, sizeof(l), 1, fp); - fwrite(&t, 1, l, fp); + fwriteint32_t(t, fp); fclose(fp); break; @@ -374,7 +375,7 @@ int main(int argc, char **argv) fseek(fptmp, l, SEEK_CUR); break; } else { - fwrite(buf, 1, strlen(buf) + 1, fp); /* module name */ + nasm_write(buf, strlen(buf) + 1, fp); /* module name */ if ((c = copybytes(fptmp, fp, 6)) >= '2') { l = copyint32_t(fptmp, fp); /* version 2 or above */ copybytes(fptmp, fp, l); /* entire object */ diff --git a/rdoff/rdfload.c b/rdoff/rdfload.c index 5a7ab631..6977a707 100644 --- a/rdoff/rdfload.c +++ b/rdoff/rdfload.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * - * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved + * + * Copyright 1996-2017 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -61,7 +61,7 @@ rdfmodule *rdfload(const char *filename) char *hdr; rdfheaderrec *r; - f = malloc(sizeof(rdfmodule)); + f = nasm_malloc(sizeof(rdfmodule)); if (f == NULL) { rdf_errno = RDF_ERR_NOMEM; return NULL; @@ -69,32 +69,32 @@ rdfmodule *rdfload(const char *filename) f->symtab = symtabNew(); if (!f->symtab) { - free(f); + nasm_free(f); rdf_errno = RDF_ERR_NOMEM; return NULL; } /* open the file */ if (rdfopen(&(f->f), filename)) { - free(f); + nasm_free(f); return NULL; } /* read in text and data segments, and header */ - f->t = malloc(f->f.seg[0].length); - f->d = malloc(f->f.seg[1].length); /* BSS seg allocated later */ - hdr = malloc(f->f.header_len); + f->t = nasm_malloc(f->f.seg[0].length); + f->d = nasm_malloc(f->f.seg[1].length); /* BSS seg allocated later */ + hdr = nasm_malloc(f->f.header_len); if (!f->t || !f->d || !hdr) { rdf_errno = RDF_ERR_NOMEM; rdfclose(&f->f); if (f->t) - free(f->t); + nasm_free(f->t); if (f->d) - free(f->d); - free(f); - free(hdr); + nasm_free(f->d); + nasm_free(f); + nasm_free(hdr); return NULL; } @@ -102,10 +102,10 @@ rdfmodule *rdfload(const char *filename) rdfloadseg(&f->f, RDOFF_CODE, f->t) || rdfloadseg(&f->f, RDOFF_DATA, f->d)) { rdfclose(&f->f); - free(f->t); - free(f->d); - free(f); - free(hdr); + nasm_free(f->t); + nasm_free(f->d); + nasm_free(f); + nasm_free(hdr); return NULL; } @@ -118,12 +118,12 @@ rdfmodule *rdfload(const char *filename) bsslength += r->b.amount; } - f->b = malloc(bsslength); + f->b = nasm_malloc(bsslength); if (bsslength && (!f->b)) { - free(f->t); - free(f->d); - free(f); - free(hdr); + nasm_free(f->t); + nasm_free(f->d); + nasm_free(f); + nasm_free(hdr); rdf_errno = RDF_ERR_NOMEM; return NULL; } @@ -195,7 +195,7 @@ int rdf_relocate(rdfmodule * m) e.segment == 1 ? m->datarel : /* 1 -> data */ m->bssrel); /* 2 -> bss */ e.flags = 0; - e.name = malloc(strlen(r->e.label) + 1); + e.name = nasm_malloc(strlen(r->e.label) + 1); if (!e.name) return 1; diff --git a/rdoff/rdfload.h b/rdoff/rdfload.h index 87d7ecc5..1ca5e92d 100644 --- a/rdoff/rdfload.h +++ b/rdoff/rdfload.h @@ -12,9 +12,7 @@ #ifndef RDOFF_RDFLOAD_H #define RDOFF_RDFLOAD_H 1 -#define RDOFF_UTILS - -#include "rdoff.h" +#include "rdfutils.h" typedef struct RDFModuleStruct { rdffile f; /* file structure */ diff --git a/rdoff/rdlar.c b/rdoff/rdlar.c index 98b0f8f6..419d2d0d 100644 --- a/rdoff/rdlar.c +++ b/rdoff/rdlar.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2009 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -285,6 +285,8 @@ int main(int argc, char **argv) exit(1); } + rdoff_init(); + /* Check whether some modifiers were specified */ for (i = 1; i < strlen(argv[1]); i++) { switch (c = argv[1][i]) { diff --git a/rdoff/rdlib.c b/rdoff/rdlib.c index 7f8ddac7..d8f2fc7a 100644 --- a/rdoff/rdlib.c +++ b/rdoff/rdlib.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2014 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -41,9 +41,7 @@ #include #include -#define RDOFF_UTILS - -#include "rdoff.h" +#include "rdfutils.h" #include "rdlib.h" #include "rdlar.h" @@ -92,11 +90,11 @@ int rdl_verify(const char *filename) * content * so we can handle it uniformaly with RDOFF2 modules. */ - fread(buf, 6, 1, fp); + nasm_read(buf, 6, fp); buf[6] = 0; /* Currently, nothing useful to do with signature block.. */ } else { - fread(buf, 6, 1, fp); + nasm_read(buf, 6, fp); buf[6] = 0; if (strncmp(buf, "RDOFF", 5)) { fclose(fp); @@ -106,7 +104,7 @@ int rdl_verify(const char *filename) return rdl_error = lastresult = 3; } } - fread(&length, 4, 1, fp); + nasm_read(&length, 4, fp); fseek(fp, length, SEEK_CUR); /* skip over the module */ } fclose(fp); @@ -120,7 +118,7 @@ int rdl_open(struct librarynode *lib, const char *name) return i; lib->fp = NULL; - lib->name = strdup(name); + lib->name = nasm_strdup(name); lib->referenced = 0; lib->next = NULL; return 0; @@ -165,7 +163,7 @@ int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f) if (feof(lib->fp)) break; if (!strcmp(buf + t, ".dir")) { /* skip over directory */ - fread(&l, 4, 1, lib->fp); + nasm_read(&l, 4, lib->fp); fseek(lib->fp, l, SEEK_CUR); continue; } @@ -179,7 +177,7 @@ int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f) /* * read in the header, and scan for exported symbols */ - hdr = malloc(f->header_len); + hdr = nasm_malloc(f->header_len); rdfloadseg(f, RDOFF_HEADER, hdr); while ((r = rdfgetheaderrec(f))) { @@ -187,7 +185,7 @@ int rdl_searchlib(struct librarynode *lib, const char *label, rdffile * f) continue; if (!strcmp(r->e.label, label)) { /* match! */ - free(hdr); /* reset to 'just open' */ + nasm_free(hdr); /* reset to 'just open' */ f->header_loc = NULL; /* state... */ f->header_fp = 0; return 1; @@ -254,7 +252,7 @@ int rdl_openmodule(struct librarynode *lib, int moduleno, rdffile * f) return rdl_error; } - fread(buf, 6, 1, lib->fp); + nasm_read(buf, 6, lib->fp); buf[6] = 0; if (buf[t] == '.') { /* do nothing */ @@ -272,7 +270,7 @@ int rdl_openmodule(struct librarynode *lib, int moduleno, rdffile * f) return rdl_error = 3; } - fread(&length, 4, 1, lib->fp); + nasm_read(&length, 4, lib->fp); fseek(lib->fp, length, SEEK_CUR); /* skip over the module */ } if (!--lib->referenced) { diff --git a/rdoff/rdoff.c b/rdoff/rdoff.c index ef9a5651..a015acdc 100644 --- a/rdoff/rdoff.c +++ b/rdoff/rdoff.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2014 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -47,13 +47,7 @@ #include #include -#define RDOFF_UTILS - -#include "rdoff.h" - -#define newstr(str) strcpy(malloc(strlen(str) + 1),str) -#define newstrcat(s1,s2) strcat(strcpy(malloc(strlen(s1) + strlen(s2) + 1), \ - s1),s2) +#include "rdfutils.h" /* * Comment this out to allow the module to read & write header record types @@ -72,7 +66,7 @@ static memorybuffer *newmembuf(void) { memorybuffer *t; - t = malloc(sizeof(memorybuffer)); + t = nasm_malloc(sizeof(memorybuffer)); if (!t) return NULL; @@ -134,8 +128,7 @@ static void membufdump(memorybuffer * b, FILE * fp) if (!b) return; - fwrite(b->buffer, 1, b->length, fp); - + nasm_write(b->buffer, b->length, fp); membufdump(b->next, fp); } @@ -151,7 +144,7 @@ static void freemembuf(memorybuffer * b) if (!b) return; freemembuf(b->next); - free(b); + nasm_free(b); } /* ========================================================================= @@ -233,6 +226,22 @@ const char *rdf_errors[11] = { int rdf_errno = 0; +/* ======================================================================== + * Hook for nasm_error() to work + * ======================================================================== */ +static void rdoff_verror(int severity, const char *fmt, va_list val) +{ + vfprintf(stderr, fmt, val); + + if ((severity & ERR_MASK) >= ERR_FATAL) + exit(1); +} + +void rdoff_init(void) +{ + nasm_set_verror(rdoff_verror); +} + /* ======================================================================== The library functions ======================================================================== */ @@ -326,7 +335,7 @@ int rdfopenhere(rdffile * f, FILE * fp, int *refcount, const char *name) fseek(f->fp, initpos, SEEK_SET); f->header_loc = NULL; - f->name = newstr(name); + f->name = nasm_strdup(name); f->refcount = refcount; if (refcount) (*refcount)++; @@ -339,7 +348,7 @@ int rdfclose(rdffile * f) fclose(f->fp); f->fp = NULL; } - free(f->name); + nasm_free(f->name); return 0; } @@ -510,7 +519,7 @@ void rdfheaderrewind(rdffile * f) rdf_headerbuf *rdfnewheader(void) { - rdf_headerbuf *hb = malloc(sizeof(rdf_headerbuf)); + rdf_headerbuf *hb = nasm_malloc(sizeof(rdf_headerbuf)); if (hb == NULL) return NULL; @@ -589,14 +598,12 @@ int rdfwriteheader(FILE * fp, rdf_headerbuf * h) { int32_t l, l2; - fwrite(RDOFFId, 1, strlen(RDOFFId), fp); + nasm_write(RDOFFId, strlen(RDOFFId), fp); l = membuflength(h->buf); l2 = l + 14 + 10 * h->nsegments + h->seglength; - l = translateint32_t(l); - l2 = translateint32_t(l2); - fwrite(&l2, 4, 1, fp); /* object length */ - fwrite(&l, 4, 1, fp); /* header length */ + fwriteint32_t(l, fp); + fwriteint32_t(l2, fp); membufdump(h->buf, fp); @@ -606,5 +613,5 @@ int rdfwriteheader(FILE * fp, rdf_headerbuf * h) void rdfdoneheader(rdf_headerbuf * h) { freemembuf(h->buf); - free(h); + nasm_free(h); } diff --git a/rdoff/rdx.c b/rdoff/rdx.c index 240ab592..f52e6879 100644 --- a/rdoff/rdx.c +++ b/rdoff/rdx.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2009 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -62,6 +62,8 @@ int main(int argc, char **argv) exit(255); } + rdoff_init(); + m = rdfload(argv[1]); if (!m) { diff --git a/rdoff/segtab.c b/rdoff/segtab.c index ab162a9f..3c076b6e 100644 --- a/rdoff/segtab.c +++ b/rdoff/segtab.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2014 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -31,10 +31,7 @@ * * ----------------------------------------------------------------------- */ -#include "compiler.h" - -#include -#include +#include "rdfutils.h" #include "segtab.h" struct segtabnode { @@ -76,7 +73,7 @@ static void descend_tree_add(struct segtabnode **node, struct segtabnode *n; if (*node == NULL) { - *node = malloc(sizeof(**node)); + *node = nasm_malloc(sizeof(**node)); if (!*node) { fprintf(stderr, "segment table: out of memory\n"); exit(1); @@ -149,7 +146,7 @@ static void freenode(struct segtabnode *n) return; freenode(n->left); freenode(n->right); - free(n); + nasm_free(n); } void done_seglocations(segtab * root) diff --git a/rdoff/symtab.c b/rdoff/symtab.c index 1dfee1ae..270fb89c 100644 --- a/rdoff/symtab.c +++ b/rdoff/symtab.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------- * - * + * * Copyright 1996-2009 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. @@ -14,7 +14,7 @@ * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -31,13 +31,13 @@ * * ----------------------------------------------------------------------- */ -/* +/* * symtab.c Routines to maintain and manipulate a symbol table * * These routines donated to the NASM effort by Graeme Defty. */ -#include "compiler.h" +#include "rdfutils.h" #include #include @@ -66,7 +66,7 @@ void *symtabNew(void) { symtab mytab; - mytab = (symtabTab *) calloc(SYMTABSIZE, sizeof(symtabNode *)); + mytab = (symtabTab *) nasm_calloc(SYMTABSIZE, sizeof(symtabNode *)); if (mytab == NULL) { fprintf(stderr, "symtab: out of memory\n"); exit(3); @@ -86,11 +86,11 @@ void symtabDone(void *stab) for (this = (*mytab)[i]; this; this = next) { next = this->next; - free(this); + nasm_free(this); } } - free(*mytab); + nasm_free(*mytab); } /* ------------------------------------- */ @@ -100,7 +100,7 @@ void symtabInsert(void *stab, symtabEnt * ent) symtabNode *node; int slot; - node = malloc(sizeof(symtabNode)); + node = nasm_malloc(sizeof(symtabNode)); if (node == NULL) { fprintf(stderr, "symtab: out of memory\n"); exit(3);