diff options
author | Thomas Huth <thuth@redhat.com> | 2015-12-01 10:06:12 +0100 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2015-12-02 14:54:41 +1100 |
commit | 271fd45605c119de0b600017df8ff10137a749b8 (patch) | |
tree | 23f29d104e4823b679b9ff33a0820cac7d721268 /lib/libnvram | |
parent | baa834884c90c243c1467c380ac3b4a51b42b967 (diff) | |
download | SLOF-271fd45605c119de0b600017df8ff10137a749b8.zip SLOF-271fd45605c119de0b600017df8ff10137a749b8.tar.gz SLOF-271fd45605c119de0b600017df8ff10137a749b8.tar.bz2 |
Improve stack usage with libnvram get_partition function
The Forth-to-C wrapper for get-named-nvram-partition also
uses the STRING_INIT macro. This causes heavy stack usage
in the engine() function due to the static array in that
macro. So let's rework the wrapper to do the string convertion
in a separate function instead.
Now that all users of the STRING_INIT and STRING_FROM_STACK
macros are gone, the macros can be removed, too.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib/libnvram')
-rw-r--r-- | lib/libnvram/libnvram.code | 18 | ||||
-rw-r--r-- | lib/libnvram/nvram.c | 11 | ||||
-rw-r--r-- | lib/libnvram/nvram.h | 1 |
3 files changed, 14 insertions, 16 deletions
diff --git a/lib/libnvram/libnvram.code b/lib/libnvram/libnvram.code index dd2346e..8481f57 100644 --- a/lib/libnvram/libnvram.code +++ b/lib/libnvram/libnvram.code @@ -11,17 +11,6 @@ *****************************************************************************/ #include <nvram.h> -#define STRING_INIT(str) \ - char str[255]; \ - char * str##_address; \ - int str##_length; - -#define STRING_FROM_STACK(str) \ - str##_length = TOS.u; POP; \ - str##_address = TOS.a; POP; \ - memcpy(str, str##_address, str##_length); \ - memset(str + str##_length, 0, 255 - str##_length); - PRIM(nvram_X2d_c_X40) unsigned int offset = TOS.u; TOS.u=nvram_read_byte(offset); @@ -80,21 +69,18 @@ MIRP /* get-named-nvram-partition ( name.addr name.len -- addr len FAILED? ) */ PRIM(get_X2d_named_X2d_nvram_X2d_partition) - STRING_INIT(name) partition_t partition; + int namelen = TOS.n; POP; - STRING_FROM_STACK(name) - partition = get_partition(-1, name); + partition = get_partition_fs(TOS.a, namelen); if(partition.len && partition.len != -1) { - PUSH; TOS.u = partition.addr; PUSH; TOS.u = partition.len; PUSH; TOS.u = 0; // FALSE } else { - PUSH; TOS.u = -1; // TRUE } MIRP diff --git a/lib/libnvram/nvram.c b/lib/libnvram/nvram.c index 1a4f91a..473814e 100644 --- a/lib/libnvram/nvram.c +++ b/lib/libnvram/nvram.c @@ -358,6 +358,17 @@ partition_t get_partition(unsigned int type, char *name) return ret; } +/* Get partition specified by a Forth string */ +partition_t get_partition_fs(char *name, int namelen) +{ + char buf[namelen + 1]; + + memcpy(buf, name, namelen); + buf[namelen] = 0; + + return get_partition(-1, buf); +} + void erase_nvram(int offset, int len) { int i; diff --git a/lib/libnvram/nvram.h b/lib/libnvram/nvram.h index 3fdba98..73fe444 100644 --- a/lib/libnvram/nvram.h +++ b/lib/libnvram/nvram.h @@ -51,6 +51,7 @@ char *get_nvram_buffer(int len); void free_nvram_buffer(char *buffer); int nvramlog_printf(const char* fmt, ...); partition_t get_partition(unsigned int type, char *name); +partition_t get_partition_fs(char *name, int namelen); void erase_nvram(int offset, int len); int wipe_partition(partition_t partition, int header_only); partition_t new_nvram_partition(int type, char *name, int len); |