From: Igor V. Kovalenko <igor.v.kovalenko(a)gmail.com>
- add dictlimit variable to store dictionary memory size
- change herewrite() to check for overflow if dictlimit is set
- sparc64: set dictlimit to allocated amount
Signed-off-by: Igor V. Kovalenko <igor.v.kovalenko(a)gmail.com>
---
arch/sparc64/openbios.c | 2 ++
kernel/dict.c | 1 +
kernel/forth.c | 8 ++++++++
kernel/include/dict.h | 1 +
4 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/arch/sparc64/openbios.c b/arch/sparc64/openbios.c
index 2f1a955..67849e1 100644
--- a/arch/sparc64/openbios.c
+++ b/arch/sparc64/openbios.c
@@ -519,6 +519,8 @@ int openbios(void)
collect_sys_info(&sys_info);
dict = malloc(DICTIONARY_SIZE);
+ dictlimit = DICTIONARY_SIZE;
+
load_dictionary((char *)sys_info.dict_start,
(unsigned long)sys_info.dict_end
- (unsigned long)sys_info.dict_start);
diff --git a/kernel/dict.c b/kernel/dict.c
index 34b97f3..822c923 100644
--- a/kernel/dict.c
+++ b/kernel/dict.c
@@ -21,6 +21,7 @@
unsigned char *dict = NULL;
ucell *last;
cell dicthead = 0;
+ucell dictlimit = 0;
/* lfa2nfa
* converts a link field address to a name field address,
diff --git a/kernel/forth.c b/kernel/forth.c
index 5fc53d3..2876709 100644
--- a/kernel/forth.c
+++ b/kernel/forth.c
@@ -851,6 +851,14 @@ static void herewrite(void)
#ifdef CONFIG_DEBUG_INTERNAL
printk("here!: new value: %x\n", tmp);
#endif
+
+ if (dictlimit && dicthead >= dictlimit) {
+ printk("Dictionary space overflow:"
+ " dicthead=" FMT_ucellx
+ " dictlimit=" FMT_ucellx
+ "\n",
+ dicthead, dictlimit);
+ }
}
diff --git a/kernel/include/dict.h b/kernel/include/dict.h
index 7e8c320..cc30f99 100644
--- a/kernel/include/dict.h
+++ b/kernel/include/dict.h
@@ -50,6 +50,7 @@ extern ucell PC;
extern unsigned char *dict;
extern cell dicthead;
+extern ucell dictlimit;
extern ucell *last;
#ifdef FCOMPILER
extern ucell *trampoline;