]> git.ipfire.org Git - thirdparty/glibc.git/blame - scripts/gen-tunables.awk
hurd: Fix build
[thirdparty/glibc.git] / scripts / gen-tunables.awk
CommitLineData
67e58f39
SP
1# Generate dl-tunable-list.h from dl-tunables.list
2
3BEGIN {
cebcb9f8
AM
4 min_of["STRING"]="0"
5 max_of["STRING"]="0"
6 min_of["INT_32"]="INT32_MIN"
7 max_of["INT_32"]="INT32_MAX"
8 min_of["UINT_64"]="0"
9 max_of["UINT_64"]="UINT64_MAX"
10 min_of["SIZE_T"]="0"
11 max_of["SIZE_T"]="SIZE_MAX"
67e58f39
SP
12 tunable=""
13 ns=""
14 top_ns=""
15}
16
17# Skip over blank lines and comments.
18/^#/ {
19 next
20}
21
22/^[ \t]*$/ {
23 next
24}
25
26# Beginning of either a top namespace, tunable namespace or a tunable, decided
27# on the current value of TUNABLE, NS or TOP_NS.
28$2 == "{" {
29 if (top_ns == "") {
30 top_ns = $1
31 }
32 else if (ns == "") {
33 ns = $1
34 }
35 else if (tunable == "") {
36 tunable = $1
37 }
38 else {
39 printf ("Unexpected occurrence of '{': %s:%d\n", FILENAME, FNR)
40 exit 1
41 }
42
43 next
44}
45
46# End of either a top namespace, tunable namespace or a tunable.
47$1 == "}" {
48 if (tunable != "") {
49 # Tunables definition ended, now fill in default attributes.
a4de0a90
AZ
50 if (!types[top_ns,ns,tunable]) {
51 types[top_ns,ns,tunable] = "STRING"
67e58f39 52 }
a4de0a90 53 if (!minvals[top_ns,ns,tunable]) {
cebcb9f8 54 minvals[top_ns,ns,tunable] = min_of[types[top_ns,ns,tunable]]
67e58f39 55 }
a4de0a90 56 if (!maxvals[top_ns,ns,tunable]) {
cebcb9f8 57 maxvals[top_ns,ns,tunable] = max_of[types[top_ns,ns,tunable]]
67e58f39 58 }
a4de0a90
AZ
59 if (!env_alias[top_ns,ns,tunable]) {
60 env_alias[top_ns,ns,tunable] = "NULL"
67e58f39 61 }
a4de0a90
AZ
62 if (!security_level[top_ns,ns,tunable]) {
63 security_level[top_ns,ns,tunable] = "SXID_ERASE"
67e58f39
SP
64 }
65
66 tunable = ""
67 }
68 else if (ns != "") {
69 ns = ""
70 }
71 else if (top_ns != "") {
72 top_ns = ""
73 }
74 else {
75 printf ("syntax error: extra }: %s:%d\n", FILENAME, FNR)
76 exit 1
77 }
78 next
79}
80
81# Everything else, which could either be a tunable without any attributes or a
82# tunable attribute.
83{
84 if (ns == "") {
85 printf("Line %d: Invalid tunable outside a namespace: %s\n", NR, $0)
86 exit 1
87 }
88
89 if (tunable == "") {
90 # We encountered a tunable without any attributes, so note it with a
91 # default.
a4de0a90 92 types[top_ns,ns,$1] = "STRING"
67e58f39
SP
93 next
94 }
95
96 # Otherwise, we have encountered a tunable attribute.
97 split($0, arr, ":")
98 attr = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[1])
99 val = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[2])
100
101 if (attr == "type") {
a4de0a90 102 types[top_ns,ns,tunable] = val
67e58f39
SP
103 }
104 else if (attr == "minval") {
a4de0a90 105 minvals[top_ns,ns,tunable] = val
67e58f39
SP
106 }
107 else if (attr == "maxval") {
a4de0a90 108 maxvals[top_ns,ns,tunable] = val
67e58f39
SP
109 }
110 else if (attr == "env_alias") {
a4de0a90 111 env_alias[top_ns,ns,tunable] = sprintf("\"%s\"", val)
67e58f39 112 }
8b9e9c3c
SP
113 else if (attr == "security_level") {
114 if (val == "SXID_ERASE" || val == "SXID_IGNORE" || val == "NONE") {
a4de0a90 115 security_level[top_ns,ns,tunable] = val
67e58f39
SP
116 }
117 else {
65eff7fb 118 printf("Line %d: Invalid value (%s) for security_level: %s, ", NR, val,
67e58f39 119 $0)
65eff7fb 120 print("Allowed values are 'SXID_ERASE', 'SXID_IGNORE', or 'NONE'")
67e58f39
SP
121 exit 1
122 }
123 }
d1310307 124 else if (attr == "default") {
a4de0a90
AZ
125 if (types[top_ns,ns,tunable] == "STRING") {
126 default_val[top_ns,ns,tunable] = sprintf(".strval = \"%s\"", val);
d1310307
SP
127 }
128 else {
a4de0a90 129 default_val[top_ns,ns,tunable] = sprintf(".numval = %s", val)
d1310307
SP
130 }
131 }
67e58f39
SP
132}
133
134END {
135 if (ns != "") {
136 print "Unterminated namespace. Is a closing brace missing?"
137 exit 1
138 }
139
140 print "/* AUTOGENERATED by gen-tunables.awk. */"
141 print "#ifndef _TUNABLES_H_"
142 print "# error \"Do not include this file directly.\""
143 print "# error \"Include tunables.h instead.\""
144 print "#endif"
ea9b0ecb 145 print "#include <dl-procinfo.h>\n"
67e58f39
SP
146
147 # Now, the enum names
148 print "\ntypedef enum"
149 print "{"
a4de0a90
AZ
150 for (tnm in types) {
151 split (tnm, indices, SUBSEP);
152 t = indices[1];
153 n = indices[2];
154 m = indices[3];
155 printf (" TUNABLE_ENUM_NAME(%s, %s, %s),\n", t, n, m);
67e58f39
SP
156 }
157 print "} tunable_id_t;\n"
158
159 # Finally, the tunable list.
160 print "\n#ifdef TUNABLES_INTERNAL"
17284d65 161 print "static tunable_t tunable_list[] attribute_relro = {"
a4de0a90
AZ
162 for (tnm in types) {
163 split (tnm, indices, SUBSEP);
164 t = indices[1];
165 n = indices[2];
166 m = indices[3];
167 printf (" {TUNABLE_NAME_S(%s, %s, %s)", t, n, m)
168 printf (", {TUNABLE_TYPE_%s, %s, %s}, {%s}, NULL, TUNABLE_SECLEVEL_%s, %s},\n",
169 types[t,n,m], minvals[t,n,m], maxvals[t,n,m],
170 default_val[t,n,m], security_level[t,n,m], env_alias[t,n,m]);
67e58f39
SP
171 }
172 print "};"
173 print "#endif"
174}