/**************************************************************************/ /* COFF.H */ /* COFF data structures and related definitions used by the linker */ /**************************************************************************/ /*------------------------------------------------------------------------*/ /* COFF FILE HEADER */ /*------------------------------------------------------------------------*/ struct filehdr { unsigned short f_magic; /* magic number */ unsigned short f_nscns; /* number of sections */ long f_timdat; /* time & date stamp */ long f_symptr; /* file pointer to symtab */ long f_nsyms; /* number of symtab entries */ unsigned short f_opthdr; /* sizeof(optional hdr) */ unsigned short f_flags; /* flags */ unsigned short f_TargetID; /* for C6x = 0x0099 */ }; /*------------------------------------------------------------------------*/ /* File header flags */ /*------------------------------------------------------------------------*/ #define F_RELFLG 0x01 /* relocation info stripped from file */ #define F_EXEC 0x02 /* file is executable (no unresolved refs) */ #define F_LNNO 0x04 /* line nunbers stripped from file */ #define F_LSYMS 0x08 /* local symbols stripped from file */ #define F_GSP10 0x10 /* 34010 version */ #define F_GSP20 0x20 /* 34020 version */ #define F_SWABD 0x40 /* bytes swabbed (in names) */ #define F_AR16WR 0x80 /* byte ordering of an AR16WR (PDP-11) */ #define F_LITTLE 0x100 /* byte ordering of an AR32WR (vax) */ #define F_BIG 0x200 /* byte ordering of an AR32W (3B, maxi) */ #define F_PATCH 0x400 /* contains "patch" list in optional header */ #define F_NODF 0x400 #define F_VERSION (F_GSP10 | F_GSP20) #define F_BYTE_ORDER (F_LITTLE | F_BIG) #define FILHDR struct filehdr //#define FILHSZ sizeof(FILHDR) #define FILHSZ 22 // above rounds to align on 4 bytes which causes problems #define COFF_C67_MAGIC 0x00c2 /*------------------------------------------------------------------------*/ /* Macros to recognize magic numbers */ /*------------------------------------------------------------------------*/ #define ISMAGIC(x) (((unsigned short)(x))==(unsigned short)magic) #define ISARCHIVE(x) ((((unsigned short)(x))==(unsigned short)ARTYPE)) #define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x)) /*------------------------------------------------------------------------*/ /* OPTIONAL FILE HEADER */ /*------------------------------------------------------------------------*/ typedef struct aouthdr { short magic; /* see magic.h */ short vstamp; /* version stamp */ long tsize; /* text size in bytes, padded to FW bdry*/ long dsize; /* initialized data " " */ long bsize; /* uninitialized data " " */ long entrypt; /* entry pt. */ long text_start; /* base of text used for this file */ long data_start; /* base of data used for this file */ } AOUTHDR; #define AOUTSZ sizeof(AOUTHDR) /*----------------------------------------------------------------------*/ /* When a UNIX aout header is to be built in the optional header, */ /* the following magic numbers can appear in that header: */ /* */ /* AOUT1MAGIC : default : readonly sharable text segment */ /* AOUT2MAGIC: : writable text segment */ /* PAGEMAGIC : : configured for paging */ /*----------------------------------------------------------------------*/ #define AOUT1MAGIC 0410 #define AOUT2MAGIC 0407 #define PAGEMAGIC 0413 /*------------------------------------------------------------------------*/ /* COMMON ARCHIVE FILE STRUCTURES */ /*
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */
#include "dwm.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>

/* extern */

void *
emallocz(unsigned int size) {
	void *res = calloc(1, size);

	if(!res)
		eprint("fatal: could not malloc() %u bytes\n", size);
	return res;
}

void
eprint(const char *errstr, ...) {
	va_list ap;

	va_start(ap, errstr);
	vfprintf(stderr, errstr, ap);
	va_end(ap);
	exit(EXIT_FAILURE);
}

void
spawn(Arg arg) {
	static char *shell = NULL;

	if(!shell && !(shell = getenv("SHELL")))
		shell = "/bin/sh";
	if(!arg.cmd)
		return;
	/* The double-fork construct avoids zombie processes and keeps the code
	 * clean from stupid signal handlers. */
	if(fork() == 0) {
		if(fork() == 0) {
			if(dpy)
				close(ConnectionNumber(dpy));
			setsid();
			execl(shell, shell, "-c", arg.cmd, (char *)NULL);
			fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg.cmd);
			perror(" failed");
		}
		exit(0);
	}
	wait(0);
}
e T_ENUM 10 /* enumeration */ #define T_MOE 11 /* member of enumeration */ #define T_UCHAR 12 /* unsigned character */ #define T_USHORT 13 /* unsigned short */ #define T_UINT 14 /* unsigned integer */ #define T_ULONG 15 /* unsigned long */ /*------------------------------------------------------------------------*/ /* derived types are: */ /*------------------------------------------------------------------------*/ #define DT_NON 0 /* no derived type */ #define DT_PTR 1 /* pointer */ #define DT_FCN 2 /* function */ #define DT_ARY 3 /* array */ #define MKTYPE(basic, d1,d2,d3,d4,d5,d6) \ ((basic) | ((d1) << 4) | ((d2) << 6) | ((d3) << 8) |\ ((d4) << 10) | ((d5) << 12) | ((d6) << 14)) /*------------------------------------------------------------------------*/ /* type packing constants and macros */ /*------------------------------------------------------------------------*/ #define N_BTMASK_COFF 017 #define N_TMASK_COFF 060 #define N_TMASK1_COFF 0300 #define N_TMASK2_COFF 0360 #define N_BTSHFT_COFF 4 #define N_TSHIFT_COFF 2 #define BTYPE_COFF(x) ((x) & N_BTMASK_COFF) #define ISINT(x) (((x) >= T_CHAR && (x) <= T_LONG) || \ ((x) >= T_UCHAR && (x) <= T_ULONG) || (x) == T_ENUM) #define ISFLT_COFF(x) ((x) == T_DOUBLE || (x) == T_FLOAT) #define ISPTR_COFF(x) (((x) & N_TMASK_COFF) == (DT_PTR << N_BTSHFT_COFF)) #define ISFCN_COFF(x) (((x) & N_TMASK_COFF) == (DT_FCN << N_BTSHFT_COFF)) #define ISARY_COFF(x) (((x) & N_TMASK_COFF) == (DT_ARY << N_BTSHFT_COFF)) #define ISTAG_COFF(x) ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG) #define INCREF_COFF(x) ((((x)&~N_BTMASK_COFF)<>N_TSHIFT_COFF)&~N_BTMASK_COFF)|((x)&N_BTMASK_COFF)) /*------------------------------------------------------------------------*/ /* AUXILIARY SYMBOL ENTRY */ /*------------------------------------------------------------------------*/ union auxent { struct { long x_tagndx; /* str, un, or enum tag indx */ union { struct { unsigned short x_lnno; /* declaration line number */ unsigned short x_size; /* str, union, array size */ } x_lnsz; long x_fsize; /* size of function */ } x_misc; union { struct /* if ISFCN, tag, or .bb */ { long x_lnnoptr; /* ptr to fcn line # */ long x_endndx; /* entry ndx past block end */ } x_fcn; struct /* if ISARY, up to 4 dimen. */ { unsigned short x_dimen[DIMNUM]; } x_ary; } x_fcnary; unsigned short x_regcount; /* number of registers used by func */ } x_sym; struct { char x_fname[FILNMLEN]; } x_file; struct { long x_scnlen; /* section length */ unsigned short x_nreloc; /* number of relocation entries */ unsigned short x_nlinno; /* number of line numbers */ } x_scn; }; #define SYMENT struct syment #define SYMESZ 18 /* sizeof(SYMENT) */ #define AUXENT union auxent #define AUXESZ 18 /* sizeof(AUXENT) */ /*------------------------------------------------------------------------*/ /* NAMES OF "SPECIAL" SYMBOLS */ /*------------------------------------------------------------------------*/ #define _STEXT ".text" #define _ETEXT "etext" #define _SDATA ".data" #define _EDATA "edata" #define _SBSS ".bss" #define _END "end" #define _CINITPTR "cinit" /*--------------------------------------------------------------------------*/ /* ENTRY POINT SYMBOLS */ /*--------------------------------------------------------------------------*/ #define _START "_start" #define _MAIN "_main" /* _CSTART "_c_int00" (defined in params.h) */ #define _TVORIG "_tvorig" #define _TORIGIN "_torigin" #define _DORIGIN "_dorigin" #define _SORIGIN "_sorigin"