Add tests for sign of NaN returned by strtod (bug 23007).
[glibc.git] / scripts / gen-tunables.awk
blob622199061a140ccd4291301126f9abc5319d0513
1 # Generate dl-tunable-list.h from dl-tunables.list
3 BEGIN {
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"
12 tunable=""
13 ns=""
14 top_ns=""
17 # Skip over blank lines and comments.
18 /^#/ {
19 next
22 /^[ \t]*$/ {
23 next
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
32 else if (ns == "") {
33 ns = $1
35 else if (tunable == "") {
36 tunable = $1
38 else {
39 printf ("Unexpected occurrence of '{': %s:%d\n", FILENAME, FNR)
40 exit 1
43 next
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.
50 if (!types[top_ns,ns,tunable]) {
51 types[top_ns,ns,tunable] = "STRING"
53 if (!minvals[top_ns,ns,tunable]) {
54 minvals[top_ns,ns,tunable] = min_of[types[top_ns,ns,tunable]]
56 if (!maxvals[top_ns,ns,tunable]) {
57 maxvals[top_ns,ns,tunable] = max_of[types[top_ns,ns,tunable]]
59 if (!env_alias[top_ns,ns,tunable]) {
60 env_alias[top_ns,ns,tunable] = "NULL"
62 if (!security_level[top_ns,ns,tunable]) {
63 security_level[top_ns,ns,tunable] = "SXID_ERASE"
66 tunable = ""
68 else if (ns != "") {
69 ns = ""
71 else if (top_ns != "") {
72 top_ns = ""
74 else {
75 printf ("syntax error: extra }: %s:%d\n", FILENAME, FNR)
76 exit 1
78 next
81 # Everything else, which could either be a tunable without any attributes or a
82 # tunable attribute.
84 if (ns == "") {
85 printf("Line %d: Invalid tunable outside a namespace: %s\n", NR, $0)
86 exit 1
89 if (tunable == "") {
90 # We encountered a tunable without any attributes, so note it with a
91 # default.
92 types[top_ns,ns,$1] = "STRING"
93 next
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])
101 if (attr == "type") {
102 types[top_ns,ns,tunable] = val
104 else if (attr == "minval") {
105 minvals[top_ns,ns,tunable] = val
107 else if (attr == "maxval") {
108 maxvals[top_ns,ns,tunable] = val
110 else if (attr == "env_alias") {
111 env_alias[top_ns,ns,tunable] = sprintf("\"%s\"", val)
113 else if (attr == "security_level") {
114 if (val == "SXID_ERASE" || val == "SXID_IGNORE" || val == "NONE") {
115 security_level[top_ns,ns,tunable] = val
117 else {
118 printf("Line %d: Invalid value (%s) for security_level: %s, ", NR, val,
120 print("Allowed values are 'SXID_ERASE', 'SXID_IGNORE', or 'NONE'")
121 exit 1
124 else if (attr == "default") {
125 if (types[top_ns,ns,tunable] == "STRING") {
126 default_val[top_ns,ns,tunable] = sprintf(".strval = \"%s\"", val);
128 else {
129 default_val[top_ns,ns,tunable] = sprintf(".numval = %s", val)
134 END {
135 if (ns != "") {
136 print "Unterminated namespace. Is a closing brace missing?"
137 exit 1
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"
145 print "#include <dl-procinfo.h>\n"
147 # Now, the enum names
148 print "\ntypedef enum"
149 print "{"
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);
157 print "} tunable_id_t;\n"
159 # Finally, the tunable list.
160 print "\n#ifdef TUNABLES_INTERNAL"
161 print "static tunable_t tunable_list[] attribute_relro = {"
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]);
172 print "};"
173 print "#endif"