summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2022-11-14 00:40:07 -0500
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-11-15 02:45:08 +0100
commitf51fc836c5b690f5448e76196dd40bdb55957a11 (patch)
treeee536320125658080ae96b1085278f83e042e7e2
parent3902cb2fcae6e2028252b5d2016bf0e99ed74980 (diff)
Initialize basic types once and print errors for duplicate definitions
For kernel server or user subsystems we would initialize basic types twice, once in main() and again for the subsystem declaration. Instead, initialize basic types when the subsystem is declared and then throw errors when types are defined multiple times. Message-Id: <Y3HUt/YAKaqMMTi3@viriathus>
-rw-r--r--migcom.c1
-rw-r--r--parser.y5
-rw-r--r--type.c16
3 files changed, 18 insertions, 4 deletions
diff --git a/migcom.c b/migcom.c
index c07e84d..e61c79b 100644
--- a/migcom.c
+++ b/migcom.c
@@ -213,7 +213,6 @@ main(int argc, char **argv)
set_program_name("mig");
parseArgs(argc, argv);
init_global();
- init_type();
LookNormal();
(void) yyparse();
diff --git a/parser.y b/parser.y
index 104f604..23294bf 100644
--- a/parser.y
+++ b/parser.y
@@ -212,6 +212,7 @@ Subsystem : SubsystemStart SubsystemMods
IsKernelUser ? ", KernelUser" : "",
IsKernelServer ? ", KernelServer" : "");
}
+ init_type();
}
;
@@ -238,7 +239,6 @@ SubsystemMod : syKernelUser
IsKernelUser = TRUE;
port_size = vm_offset_size;
port_size_in_bits = vm_offset_size_in_bits;
- init_type();
}
| syKernelServer
{
@@ -247,7 +247,6 @@ SubsystemMod : syKernelUser
IsKernelServer = TRUE;
port_size = vm_offset_size;
port_size_in_bits = vm_offset_size_in_bits;
- init_type();
}
;
@@ -351,7 +350,7 @@ TypeDecl : syType NamedTypeSpec
identifier_t name = $2->itName;
if (itLookUp(name) != itNULL)
- warn("overriding previous definition of %s", name);
+ error("overriding previous definition of %s", name);
itInsert(name, $2);
}
;
diff --git a/type.c b/type.c
index 66944d9..3846746 100644
--- a/type.c
+++ b/type.c
@@ -57,6 +57,7 @@ ipc_type_t *itWaitTimeType; /* used for dummy WaitTime args */
ipc_type_t *itMsgOptionType; /* used for dummy MsgOption args */
ipc_type_t *itShortType; /* used for the short type */
ipc_type_t *itIntType; /* used for the int type */
+static boolean_t types_initialized = FALSE;
static ipc_type_t *list = itNULL;
@@ -67,6 +68,13 @@ static ipc_type_t *list = itNULL;
ipc_type_t *
itLookUp(identifier_t name)
{
+ if (!types_initialized)
+ {
+ error("Basic types not initialized when looking up type %s. Did you "
+ "forget to define the subsystem?", name);
+ return NULL;
+ }
+
ipc_type_t *it, **last;
for (it = *(last = &list); it != itNULL; it = *(last = &it->itNext))
@@ -875,6 +883,14 @@ itMakeDeallocType(void)
void
init_type(void)
{
+ if (types_initialized)
+ {
+ error("Basic types were already initialized");
+ exit(EXIT_FAILURE);
+ }
+ /* Mark initialization here since itInsert below will require it. */
+ types_initialized = TRUE;
+
itByteType = itAlloc();
itByteType->itName = "unsigned char";
itByteType->itInName = MACH_MSG_TYPE_BYTE;