mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 15:14:43 +00:00
54841ab50c
The hush shell dynamically allocates (and re-allocates) memory for the argument strings in the "char *argv[]" argument vector passed to commands. Any code that modifies these pointers will cause serious corruption of the malloc data structures and crash U-Boot, so make sure the compiler can check that no such modifications are being done by changing the code into "char * const argv[]". This modification is the result of debugging a strange crash caused after adding a new command, which used the following argument processing code which has been working perfectly fine in all Unix systems since version 6 - but not so in U-Boot: int main (int argc, char **argv) { while (--argc > 0 && **++argv == '-') { /* ====> */ while (*++*argv) { switch (**argv) { case 'd': debug++; break; ... default: usage (); } } } ... } The line marked "====>" will corrupt the malloc data structures and usually cause U-Boot to crash when the next command gets executed by the shell. With the modification, the compiler will prevent this with an error: increment of read-only location '*argv' N.B.: The code above can be trivially rewritten like this: while (--argc > 0 && **++argv == '-') { char *arg = *argv; while (*++arg) { switch (*arg) { ... Signed-off-by: Wolfgang Denk <wd@denx.de> Acked-by: Mike Frysinger <vapier@gentoo.org>
70 lines
1.8 KiB
C
70 lines
1.8 KiB
C
#ifndef __KGDB_H__
|
|
#define __KGDB_H__
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#define KGDBERR_BADPARAMS 1
|
|
#define KGDBERR_NOTHEXDIG 2
|
|
#define KGDBERR_MEMFAULT 3
|
|
#define KGDBERR_NOSPACE 4
|
|
#define KGDBERR_ALIGNFAULT 5
|
|
|
|
#define KGDBDATA_MAXREGS 8
|
|
#define KGDBDATA_MAXPRIV 8
|
|
|
|
#define KGDBEXIT_TYPEMASK 0xff
|
|
|
|
#define KGDBEXIT_KILL 0
|
|
#define KGDBEXIT_CONTINUE 1
|
|
#define KGDBEXIT_SINGLE 2
|
|
|
|
#define KGDBEXIT_WITHADDR 0x100
|
|
|
|
typedef
|
|
struct {
|
|
int num;
|
|
unsigned long val;
|
|
}
|
|
kgdb_reg;
|
|
|
|
typedef
|
|
struct {
|
|
int sigval;
|
|
int extype;
|
|
unsigned long exaddr;
|
|
int nregs;
|
|
kgdb_reg regs[KGDBDATA_MAXREGS];
|
|
unsigned long private[KGDBDATA_MAXPRIV];
|
|
}
|
|
kgdb_data;
|
|
|
|
/* these functions are provided by the generic kgdb support */
|
|
extern void kgdb_init(void);
|
|
extern void kgdb_error(int);
|
|
extern int kgdb_output_string(const char *, unsigned int);
|
|
extern void breakpoint(void);
|
|
|
|
/* these functions are provided by the platform specific kgdb support */
|
|
extern void kgdb_flush_cache_range(void *, void *);
|
|
extern void kgdb_flush_cache_all(void);
|
|
extern int kgdb_setjmp(long *);
|
|
extern void kgdb_longjmp(long *, int);
|
|
extern void kgdb_enter(struct pt_regs *, kgdb_data *);
|
|
extern void kgdb_exit(struct pt_regs *, kgdb_data *);
|
|
extern int kgdb_getregs(struct pt_regs *, char *, int);
|
|
extern void kgdb_putreg(struct pt_regs *, int, char *, int);
|
|
extern void kgdb_putregs(struct pt_regs *, char *, int);
|
|
extern int kgdb_trap(struct pt_regs *);
|
|
extern void kgdb_breakpoint(int argc, char * const argv[]);
|
|
|
|
/* these functions are provided by the platform serial driver */
|
|
extern void kgdb_serial_init(void);
|
|
extern int getDebugChar(void);
|
|
extern void putDebugChar(int);
|
|
extern void putDebugStr(const char *);
|
|
extern void kgdb_interruptible(int);
|
|
|
|
/* this is referenced in the trap handler for the platform */
|
|
extern int (*debugger_exception_handler)(struct pt_regs *);
|
|
|
|
#endif /* __KGDB_H__ */
|