summaryrefslogtreecommitdiff
path: root/usr/src/common/brand/lx/lx_auxv.c
blob: 2ed5fd0517c2726536a8c1ea20eed683483e24e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2016 Joyent, Inc.
 */

#include <sys/auxv.h>
#include <sys/lx_brand.h>

/*
 * Linux does not make the distinction between 'int' and 'long' when it comes
 * to the format of the aux vector.  In order to properly clear the struct
 * padding present in the native auxv_t in 64-bit, we employ the Linux format.
 */
struct lx_auxv {
	long la_type;
	long la_val;
};

int
lx_auxv_stol(const auxv_t *ap, auxv_t *oap, const lx_elf_data_t *edp)
{
	struct lx_auxv *loap = (struct lx_auxv *)oap;

	switch (ap->a_type) {
	case AT_BASE:
		loap->la_val = edp->ed_base;
		break;
	case AT_ENTRY:
		loap->la_val = edp->ed_entry;
		break;
	case AT_PHDR:
		loap->la_val = edp->ed_phdr;
		break;
	case AT_PHENT:
		loap->la_val = edp->ed_phent;
		break;
	case AT_PHNUM:
		loap->la_val = edp->ed_phnum;
		break;
	case AT_SUN_BRAND_LX_SYSINFO_EHDR:
		loap->la_type = AT_SYSINFO_EHDR;
		loap->la_val = ap->a_un.a_val;
		return (0);
	case AT_SUN_BRAND_LX_CLKTCK:
		loap->la_type = AT_CLKTCK;
		loap->la_val = ap->a_un.a_val;
		return (0);
	case AT_SUN_AUXFLAGS:
		if ((ap->a_un.a_val & AF_SUN_SETUGID) != 0) {
			loap->la_type = AT_SECURE;
			loap->la_val = 1;
			return (0);
		} else {
			return (1);
		}
	case AT_SUN_GID:
		loap->la_type = AT_LX_EGID;
		loap->la_val = ap->a_un.a_val;
		return (0);
	case AT_SUN_RGID:
		loap->la_type = AT_LX_GID;
		loap->la_val = ap->a_un.a_val;
		return (0);
	case AT_SUN_UID:
		loap->la_type = AT_LX_EUID;
		loap->la_val = ap->a_un.a_val;
		return (0);
	case AT_SUN_RUID:
		loap->la_type = AT_LX_UID;
		loap->la_val = ap->a_un.a_val;
		return (0);
	case AT_EXECFD:
	case AT_PAGESZ:
	case AT_FLAGS:
	case AT_RANDOM:
	case AT_NULL:
		/* No translate needed */
		loap->la_val = ap->a_un.a_val;
		break;
	default:
		/* All other unrecognized entries are ignored */
		return (1);
	}
	loap->la_type = ap->a_type;
	return (0);
}