powerpc: Optimize memchr for power8
[glibc.git] / scripts / gen-tunables.awk
blobccdd0c6c71bb18717dcaee621c709ffdb159e777
1 # Generate dl-tunable-list.h from dl-tunables.list
3 BEGIN {
4 tunable=""
5 ns=""
6 top_ns=""
9 # Skip over blank lines and comments.
10 /^#/ {
11 next
14 /^[ \t]*$/ {
15 next
18 # Beginning of either a top namespace, tunable namespace or a tunable, decided
19 # on the current value of TUNABLE, NS or TOP_NS.
20 $2 == "{" {
21 if (top_ns == "") {
22 top_ns = $1
24 else if (ns == "") {
25 ns = $1
27 else if (tunable == "") {
28 tunable = $1
30 else {
31 printf ("Unexpected occurrence of '{': %s:%d\n", FILENAME, FNR)
32 exit 1
35 next
38 # End of either a top namespace, tunable namespace or a tunable.
39 $1 == "}" {
40 if (tunable != "") {
41 # Tunables definition ended, now fill in default attributes.
42 if (!types[top_ns,ns,tunable]) {
43 types[top_ns,ns,tunable] = "STRING"
45 if (!minvals[top_ns,ns,tunable]) {
46 minvals[top_ns,ns,tunable] = "0"
48 if (!maxvals[top_ns,ns,tunable]) {
49 maxvals[top_ns,ns,tunable] = "0"
51 if (!env_alias[top_ns,ns,tunable]) {
52 env_alias[top_ns,ns,tunable] = "NULL"
54 if (!security_level[top_ns,ns,tunable]) {
55 security_level[top_ns,ns,tunable] = "SXID_ERASE"
58 tunable = ""
60 else if (ns != "") {
61 ns = ""
63 else if (top_ns != "") {
64 top_ns = ""
66 else {
67 printf ("syntax error: extra }: %s:%d\n", FILENAME, FNR)
68 exit 1
70 next
73 # Everything else, which could either be a tunable without any attributes or a
74 # tunable attribute.
76 if (ns == "") {
77 printf("Line %d: Invalid tunable outside a namespace: %s\n", NR, $0)
78 exit 1
81 if (tunable == "") {
82 # We encountered a tunable without any attributes, so note it with a
83 # default.
84 types[top_ns,ns,$1] = "STRING"
85 next
88 # Otherwise, we have encountered a tunable attribute.
89 split($0, arr, ":")
90 attr = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[1])
91 val = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[2])
93 if (attr == "type") {
94 types[top_ns,ns,tunable] = val
96 else if (attr == "minval") {
97 minvals[top_ns,ns,tunable] = val
99 else if (attr == "maxval") {
100 maxvals[top_ns,ns,tunable] = val
102 else if (attr == "env_alias") {
103 env_alias[top_ns,ns,tunable] = sprintf("\"%s\"", val)
105 else if (attr == "security_level") {
106 if (val == "SXID_ERASE" || val == "SXID_IGNORE" || val == "NONE") {
107 security_level[top_ns,ns,tunable] = val
109 else {
110 printf("Line %d: Invalid value (%s) for security_level: %s, ", NR, val,
112 print("Allowed values are 'SXID_ERASE', 'SXID_IGNORE', or 'NONE'")
113 exit 1
116 else if (attr == "default") {
117 if (types[top_ns,ns,tunable] == "STRING") {
118 default_val[top_ns,ns,tunable] = sprintf(".strval = \"%s\"", val);
120 else {
121 default_val[top_ns,ns,tunable] = sprintf(".numval = %s", val)
126 END {
127 if (ns != "") {
128 print "Unterminated namespace. Is a closing brace missing?"
129 exit 1
132 print "/* AUTOGENERATED by gen-tunables.awk. */"
133 print "#ifndef _TUNABLES_H_"
134 print "# error \"Do not include this file directly.\""
135 print "# error \"Include tunables.h instead.\""
136 print "#endif"
137 print "#include <dl-procinfo.h>\n"
139 # Now, the enum names
140 print "\ntypedef enum"
141 print "{"
142 for (tnm in types) {
143 split (tnm, indices, SUBSEP);
144 t = indices[1];
145 n = indices[2];
146 m = indices[3];
147 printf (" TUNABLE_ENUM_NAME(%s, %s, %s),\n", t, n, m);
149 print "} tunable_id_t;\n"
151 # Finally, the tunable list.
152 print "\n#ifdef TUNABLES_INTERNAL"
153 print "static tunable_t tunable_list[] attribute_relro = {"
154 for (tnm in types) {
155 split (tnm, indices, SUBSEP);
156 t = indices[1];
157 n = indices[2];
158 m = indices[3];
159 printf (" {TUNABLE_NAME_S(%s, %s, %s)", t, n, m)
160 printf (", {TUNABLE_TYPE_%s, %s, %s}, {%s}, NULL, TUNABLE_SECLEVEL_%s, %s},\n",
161 types[t,n,m], minvals[t,n,m], maxvals[t,n,m],
162 default_val[t,n,m], security_level[t,n,m], env_alias[t,n,m]);
164 print "};"
165 print "#endif"