[syslinux] Syslinux-5.01 cmd.c32 broken: __com32 undefined

Matt Fleming matt at console-pimps.org
Fri Feb 22 07:20:23 PST 2013


On Wed, 2013-02-06 at 09:43 -0800, H. Peter Anvin wrote:
> On 02/05/2013 08:47 PM, Gene Cumm wrote:
> > Rather than acting like a typical C program using argc/argv, cmd.c32
> > uses __com32.cs_cmdline to retrieve what's passed to it.  meminfo.c32
> > uses __intcall() which in the library calls __com32.cs_intcall().  Is
> > __com32 only exposed for library functions or is there something else
> > missing in here?  Should accessing __com32.cs_cmdline be abstracted
> > via a function call for protection?  Should cmd.c32 use argc/argv
> > instead?
> 
> Well, __com32 is gone; it was an implementation detail for the older 
> versions.
> 
> > If we were to abstract/protect via a function call, I'd expect the
> > call to use strncpy/memcpy and be like:
> >
> > char *get_cmdline(char *dest, size_t n)
> >
> > or if only for abstraction
> >
> > char *get_cmdline(void)
> 
> Being able to get the raw command line rather than the parsed 
> (argc/argv) command line might be a good thing.  If so, we probably 
> would just export it as something like:
> 
> const char *cmdline(void);

something like this?

---

>From 0336fc3b147c2ecaedc9ee103d7cced624c5f8ef Mon Sep 17 00:00:00 2001
From: Matt Fleming <matt.fleming at intel.com>
Date: Fri, 22 Feb 2013 15:13:38 +0000
Subject: [PATCH] com32: Add cmdline() which returns argv[1]..argv[argc-1] as
 a string

cmd.c32 needs an equivalent of __com32.cs_cmdline now that the COMBOOT
code is dead. Introducing cmdline() which returns a string consisting
of module arguments from argv[1] to argv[argc-1], separated by spaces.

Reported-by: Gene Cumm <gene.cumm at gmail.com>
Signed-off-by: Matt Fleming <matt.fleming at intel.com>
---
 com32/include/com32.h     |  2 ++
 com32/modules/cmd.c       |  2 +-
 core/elflink/load_env32.c | 11 +++++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/com32/include/com32.h b/com32/include/com32.h
index 148d08e..80a3826 100644
--- a/com32/include/com32.h
+++ b/com32/include/com32.h
@@ -206,4 +206,6 @@ static inline far_ptr_t FAR_PTR(void *__ptr)
     return __fptr;
 }
 
+extern const char *cmdline(void);
+
 #endif /* _COM32_H */
diff --git a/com32/modules/cmd.c b/com32/modules/cmd.c
index 5d3f891..fe1e464 100644
--- a/com32/modules/cmd.c
+++ b/com32/modules/cmd.c
@@ -21,6 +21,6 @@
 
 int main(void)
 {
-    syslinux_run_command(__com32.cs_cmdline);
+    syslinux_run_command(cmdline());
     return -1;
 }
diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c
index 50ec266..2329b6d 100644
--- a/core/elflink/load_env32.c
+++ b/core/elflink/load_env32.c
@@ -186,6 +186,12 @@ out:
 	writestr("\nFailed to load ldlinux.c32");
 }
 
+static const char *__cmdline;
+__export const char *cmdline(void)
+{
+	return __cmdline;
+}
+
 __export int create_args_and_load(char *cmdline)
 {
 	char *p, **argv;
@@ -237,6 +243,11 @@ __export int create_args_and_load(char *cmdline)
 		 */
 		while (*p && isspace(*p))
 			p++;
+
+		/* Point __cmdline at argv[1..N] */
+		if (i == 0)
+			__cmdline = p;
+
 	}
 
 	/* NUL-terminate */
-- 
1.7.11.7




More information about the Syslinux mailing list