auxinfo.patch

dragonflybsd1, 02/17/2011 07:58 PM

Download (10.5 KB)

View differences:

sys/cpu/i386/include/elf.h
73 73
__ElfType(Auxinfo);
74 74

  
75 75
/* Values for a_type. */
76
#define AT_NULL		0	/* Terminates the vector. */
77
#define AT_IGNORE	1	/* Ignored entry. */
78
#define AT_EXECFD	2	/* File descriptor of program to load. */
79
#define AT_PHDR		3	/* Program header of program already loaded. */
80
#define AT_PHENT	4	/* Size of each program header entry. */
81
#define AT_PHNUM	5	/* Number of program header entries. */
82
#define AT_PAGESZ	6	/* Page size in bytes. */
83
#define AT_BASE		7	/* Interpreter's base address. */
84
#define AT_FLAGS	8	/* Flags (unused for i386). */
85
#define AT_ENTRY	9	/* Where interpreter should transfer control. */
76
#define	AT_NULL		0	/* Terminates the vector. */
77
#define	AT_IGNORE	1	/* Ignored entry. */
78
#define	AT_EXECFD	2	/* File descriptor of program to load. */
79
#define	AT_PHDR		3	/* Program header of program already loaded. */
80
#define	AT_PHENT	4	/* Size of each program header entry. */
81
#define	AT_PHNUM	5	/* Number of program header entries. */
82
#define	AT_PAGESZ	6	/* Page size in bytes. */
83
#define	AT_BASE		7	/* Interpreter's base address. */
84
#define	AT_FLAGS	8	/* Flags (unused for i386). */
85
#define	AT_ENTRY	9	/* Where interpreter should transfer control. */
86 86

  
87 87
/*
88 88
 * The following non-standard values are used for passing information
......
92 92
 * Unfortunately, these overlap the Linux non-standard values, so they
93 93
 * must not be used in the same context.
94 94
 */
95
#define AT_BRK		10	/* Starting point for sbrk and brk. */
96
#define AT_DEBUG	11	/* Debugging level. */
95
#define	AT_BRK		10	/* Starting point for sbrk and brk. */
96
#define	AT_DEBUG	11	/* Debugging level. */
97 97

  
98 98
/*
99 99
 * The following non-standard values are used in Linux ELF binaries.
100 100
 */
101
#define AT_NOTELF	10	/* Program is not ELF ?? */
102
#define AT_UID		11	/* Real uid. */
103
#define AT_EUID		12	/* Effective uid. */
104
#define AT_GID		13	/* Real gid. */
105
#define AT_EGID		14	/* Effective gid. */
106

  
107
#define AT_COUNT	15	/* Count of defined aux entry types. */
101
#define	AT_NOTELF	10	/* Program is not ELF ?? */
102
#define	AT_UID		11	/* Real uid. */
103
#define	AT_EUID		12	/* Effective uid. */
104
#define	AT_GID		13	/* Real gid. */
105
#define	AT_EGID		14	/* Effective gid. */
106
#define	AT_EXECPATH	15	/* Path to the executable. */
107
#define	AT_CANARY	16	/* Canary for SSP. */
108
#define	AT_CANARYLEN	17	/* Length of the canary. */
109
#define	AT_OSRELDATE	18	/* OSRELDATE. */
110
#define	AT_NCPUS	19	/* Number of CPUs. */
111
#define	AT_PAGESIZES	20	/* Pagesizes. */
112
#define	AT_PAGESIZESLEN	21	/* Number of pagesizes. */
113

  
114
#define	AT_COUNT	22	/* Count of defined aux entry types. */
108 115

  
109 116
/*
110 117
 * Relocation types.
sys/cpu/i386/include/param.h
132 132
#define IOPAGES	2		/* pages of i/o permission bitmap */
133 133
#define UPAGES	4		/* pages of u-area */
134 134

  
135
#define MAXPAGESIZES	1	/* maximum number of supported page sizes */
136

  
135 137
/*
136 138
 * Ceiling on amount of swblock kva space, can be changed via
137 139
 * kern.maxswzone /boot/loader.conf variable.
sys/cpu/x86_64/include/elf.h
101 101
#define	AT_EUID		12	/* Effective uid. */
102 102
#define	AT_GID		13	/* Real gid. */
103 103
#define	AT_EGID		14	/* Effective gid. */
104

  
105
#define	AT_COUNT	15	/* Count of defined aux entry types. */
104
#define	AT_EXECPATH	15	/* Path to the executable. */
105
#define	AT_CANARY	16	/* Canary for SSP */
106
#define	AT_CANARYLEN	17	/* Length of the canary. */
107
#define	AT_OSRELDATE	18	/* OSRELDATE. */
108
#define	AT_NCPUS	19	/* Number of CPUs. */
109
#define	AT_PAGESIZES	20	/* Pagesizes. */
110
#define	AT_PAGESIZESLEN	21	/* Number of pagesizes. */
111

  
112
#define	AT_COUNT	22	/* Count of defined aux entry types. */
106 113

  
107 114
/*
108 115
 * Relocation types.
sys/cpu/x86_64/include/param.h
147 147
#define IOPAGES	2		/* pages of i/o permission bitmap */
148 148
#define UPAGES	4		/* pages of u-area */
149 149

  
150
#define MAXPAGESIZES	1	/* maximum number of supported page sizes */
151

  
150 152
/*
151 153
 * Ceiling on amount of swblock kva space, can be changed via
152 154
 * kern.maxswzone /boot/loader.conf variable.  On 64 bit machines
sys/kern/imgact_elf.c
118 118
	MINSIGSTKSZ
119 119
};
120 120

  
121
extern int osreldate;
122

  
121 123
static Elf_Brandinfo freebsd_brand_info = {
122 124
						ELFOSABI_FREEBSD,
123 125
						"FreeBSD",
......
926 928
	AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
927 929
	AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
928 930
	AUXARGS_ENTRY(pos, AT_BASE, args->base);
931
	if (imgp->execpathp != 0)
932
		AUXARGS_ENTRY(pos, AT_EXECPATH, imgp->execpathp);
933
	AUXARGS_ENTRY(pos, AT_OSRELDATE, osreldate);
934
	if (imgp->canary != 0) {
935
		AUXARGS_ENTRY(pos, AT_CANARY, imgp->canary);
936
		AUXARGS_ENTRY(pos, AT_CANARYLEN, imgp->canarylen);
937
	}
938
	AUXARGS_ENTRY(pos, AT_NCPUS, ncpus);
939
	if (imgp->pagesizes != 0) {
940
		AUXARGS_ENTRY(pos, AT_PAGESIZES, imgp->pagesizes);
941
		AUXARGS_ENTRY(pos, AT_PAGESIZESLEN, imgp->pagesizeslen);
942
	}
929 943
	AUXARGS_ENTRY(pos, AT_NULL, 0);
930 944

  
931 945
	kfree(imgp->auxargs, M_TEMP);
......
990 1004
static int elf_puttextvp(struct proc *, elf_buf_t);
991 1005
static int elf_putfiles(struct proc *, elf_buf_t, struct file *);
992 1006

  
993
extern int osreldate;
994

  
995 1007
int
996 1008
elf_coredump(struct lwp *lp, int sig, struct vnode *vp, off_t limit)
997 1009
{
sys/kern/kern_exec.c
219 219
	imgp->vp = NULL;
220 220
	imgp->firstpage = NULL;
221 221
	imgp->ps_strings = 0;
222
	imgp->execpath = imgp->freepath = NULL;
223
	imgp->execpathp = 0;
224
	imgp->canary = 0;
225
	imgp->canarylen = 0;
226
	imgp->pagesizes = 0;
227
	imgp->pagesizeslen = 0;
222 228
	imgp->image_header = NULL;
223 229

  
224 230
interpret:
......
309 315
	}
310 316

  
311 317
	/*
318
	 * Do the best to calculate the full path to the image file.
319
	 */
320
	if (imgp->auxargs != NULL &&
321
	   ((args->fname != NULL && args->fname[0] == '/') ||
322
	    vn_fullpath(imgp->proc, imgp->vp, &imgp->execpath, &imgp->freepath, 0) !=
323
	    0))
324
		imgp->execpath = args->fname;
325

  
326
	/*
312 327
	 * Copy out strings (args and env) and initialize stack base
313 328
	 */
314 329
	stack_base = exec_copyout_strings(imgp);
......
518 533
		return (0);
519 534
	}
520 535

  
536
	kfree(imgp->freepath, M_TEMP);
537

  
521 538
exec_fail:
522 539
	/*
523 540
	 * we're done here, clear P_INEXEC if we were the ones that
......
883 900
	char *stringp, *destp;
884 901
	register_t *stack_base;
885 902
	struct ps_strings *arginfo;
903
	size_t execpath_len;
886 904
	int szsigcode;
905
	int szps;
906
	char canary[sizeof(long) * 8];
887 907

  
908
	szps = sizeof(pagesizes[0]) * MAXPAGESIZES;
888 909
	/*
889 910
	 * Calculate string base and vector table pointers.
890 911
	 * Also deal with signal trampoline code for this exec type.
891 912
	 */
913
	if (imgp->execpath != NULL && imgp->auxargs != NULL)
914
		execpath_len = strlen(imgp->execpath) + 1;
915
	else
916
		execpath_len = 0;
892 917
	arginfo = (struct ps_strings *)PS_STRINGS;
893 918
	szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
894 919
	if (stackgap_random != 0)
......
896 921
	else
897 922
		sgap = 0;
898 923
	destp =	(caddr_t)arginfo - szsigcode - SPARE_USRSPACE - sgap -
924
	    roundup(execpath_len, sizeof(char *)) -
925
	    roundup(sizeof(canary), sizeof(char *)) -
926
	    roundup(szps, sizeof(char *)) -
899 927
	    roundup((ARG_MAX - imgp->args->space), sizeof(char *));
900 928

  
901 929
	/*
......
906 934
		    ((caddr_t)arginfo - szsigcode), szsigcode);
907 935

  
908 936
	/*
937
	 * Copy the image path for the rtld.
938
	 */
939
	if (execpath_len != 0) {
940
		imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
941
		copyout(imgp->execpath, (void *)imgp->execpathp,
942
		    execpath_len);
943
	}
944

  
945
	/*
946
	 * Prepare the canary for SSP.
947
	 */
948
	karc4rand(canary, sizeof(canary));
949
	imgp->canary = (uintptr_t)arginfo - szsigcode - execpath_len -
950
	    sizeof(canary);
951
	copyout(canary, (void *)imgp->canary, sizeof(canary));
952
	imgp->canarylen = sizeof(canary);
953

  
954
	/*
955
	 * Prepare the pagesizes array.
956
	 */
957
	imgp->pagesizes = (uintptr_t)arginfo - szsigcode - execpath_len -
958
	    roundup(sizeof(canary), sizeof(char *)) - szps;
959
	copyout(pagesizes, (void *)imgp->pagesizes, szps);
960
	imgp->pagesizeslen = szps;
961

  
962
	/*
909 963
	 * If we have a valid auxargs ptr, prepare some room
910 964
	 * on the stack.
911 965
	 *
sys/kern/kern_mib.c
158 158
SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
159 159
    machine_arch, 0, "Cpu architecture");
160 160

  
161
u_long pagesizes[MAXPAGESIZES] = { PAGE_SIZE };
162

  
163
static int
164
sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS)
165
{
166
	int error = SYSCTL_OUT(req, pagesizes, sizeof(pagesizes));
167
	return (error);
168
}
169

  
170
SYSCTL_PROC(_hw, OID_AUTO, pagesizes, CTLTYPE_ULONG | CTLFLAG_RD,
171
    NULL, 0, sysctl_hw_pagesizes, "LU", "Supported page sizes");
172

  
161 173
char hostname[MAXHOSTNAMELEN];
162 174

  
163 175
static int
sys/sys/imgact.h
68 68
	struct lwbuf *firstpage;	/* first page that we mapped */
69 69
	struct lwbuf firstpage_cache;
70 70
	unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */
71
	char *execpath;
72
	unsigned long execpathp;
73
	char *freepath;
74
	unsigned long canary;
75
	int canarylen;
76
	unsigned long pagesizes;
77
	int pagesizeslen;
71 78
};
72 79

  
73 80
#ifdef _KERNEL
sys/sys/systm.h
70 70
extern u_char curpriority;	/* priority of current process */
71 71

  
72 72
extern long physmem;		/* physical memory */
73
extern u_long pagesizes[];	/* supported page sizes */
73 74

  
74 75
extern cdev_t dumpdev;		/* dump device */
75 76
extern u_int64_t dumplo64;	/* block number into dumpdev, start of dump */