diff options
| author | H. Peter Anvin <hpa@zytor.com> | 2010-02-24 14:18:49 -0800 |
|---|---|---|
| committer | H. Peter Anvin <hpa@zytor.com> | 2010-02-24 14:18:49 -0800 |
| commit | 8a4b35805fdc6651d288a3e1c2d98aa504cb9c05 (patch) | |
| tree | 37c4bdef99996ab681e03c7a3f407563a9ff35d7 /com32/lib/sys | |
| parent | 3ae1da98a68d2f719ce17766550f7e9682ba8ae7 (diff) | |
| download | syslinux-4.00-pre25.tar.gz | |
com32: replace hard-coded bounce buffer use in com32/libsyslinux-4.00-pre25
Replace hard-coded bounce buffer uses in com32/lib with lmalloc/lfree.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32/lib/sys')
| -rw-r--r-- | com32/lib/sys/gpxe.c | 25 | ||||
| -rw-r--r-- | com32/lib/sys/open.c | 11 | ||||
| -rw-r--r-- | com32/lib/sys/vesa/initvesa.c | 52 |
3 files changed, 59 insertions, 29 deletions
diff --git a/com32/lib/sys/gpxe.c b/com32/lib/sys/gpxe.c index fae03f8f..d86da42a 100644 --- a/com32/lib/sys/gpxe.c +++ b/com32/lib/sys/gpxe.c @@ -7,39 +7,44 @@ bool is_gpxe(void) const struct syslinux_version *sv; com32sys_t reg; struct s_PXENV_FILE_CHECK_API *fca; + bool gpxe; sv = syslinux_version(); if (sv->filesystem != SYSLINUX_FS_PXELINUX) return false; /* Not PXELINUX */ - fca = __com32.cs_bounce; - memset(fca, 0, sizeof *fca); + fca = lzalloc(sizeof *fca); + if (!fca) + return false; fca->Size = sizeof *fca; fca->Magic = 0x91d447b2; memset(®, 0, sizeof reg); reg.eax.w[0] = 0x0009; reg.ebx.w[0] = 0x00e6; /* PXENV_FILE_API_CHECK */ - reg.edi.w[0] = OFFS(fca); + /* reg.edi.w[0] = OFFS(fca); */ reg.es = SEG(fca); __intcall(0x22, ®, ®); + gpxe = true; + if (reg.eflags.l & EFLAGS_CF) - return false; /* Cannot invoke PXE stack */ + gpxe = false; /* Cannot invoke PXE stack */ if (reg.eax.w[0] || fca->Status) - return false; /* PXE failure */ + gpxe = false; /* PXE failure */ if (fca->Magic != 0xe9c17b20) - return false; /* Incorrect magic */ + gpxe = false; /* Incorrect magic */ if (fca->Size < sizeof *fca) - return false; /* Short return */ + gpxe = false; /* Short return */ + /* XXX: The APIs to test for should be a passed-in option */ if (!(fca->APIMask & (1 << 5))) - return false; /* No FILE EXEC */ + gpxe = false; /* No FILE EXEC */ - return true; + lfree(fca); + return gpxe; } - diff --git a/com32/lib/sys/open.c b/com32/lib/sys/open.c index 0bd490c7..94465925 100644 --- a/com32/lib/sys/open.c +++ b/com32/lib/sys/open.c @@ -55,6 +55,7 @@ int open(const char *pathname, int flags, ...) com32sys_t regs; int fd; struct file_info *fp; + char *lm_pathname; fd = opendev(&__file_dev, NULL, flags); @@ -63,14 +64,18 @@ int open(const char *pathname, int flags, ...) fp = &__file_info[fd]; - strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size); + lm_pathname = lstrdup(pathname); + if (!lm_pathname) + return -1; regs.eax.w[0] = 0x0006; - regs.esi.w[0] = OFFS(__com32.cs_bounce); - regs.es = SEG(__com32.cs_bounce); + regs.esi.w[0] = OFFS(lm_pathname); + regs.es = SEG(lm_pathname); __com32.cs_intcall(0x22, ®s, ®s); + lfree(lm_pathname); + if ((regs.eflags.l & EFLAGS_CF) || regs.esi.w[0] == 0) { close(fd); errno = ENOENT; diff --git a/com32/lib/sys/vesa/initvesa.c b/com32/lib/sys/vesa/initvesa.c index 0a436f4c..9a1ae384 100644 --- a/com32/lib/sys/vesa/initvesa.c +++ b/com32/lib/sys/vesa/initvesa.c @@ -95,9 +95,13 @@ static int vesacon_set_mode(int x, int y) com32sys_t rm; uint8_t *rom_font; uint16_t mode, bestmode, *mode_ptr; + struct vesa_info *vi; struct vesa_general_info *gi; struct vesa_mode_info *mi; enum vesa_pixel_format pxf, bestpxf; + int err = 0; + + debug("Hello, World!\r\n"); /* Free any existing data structures */ if (__vesacon_background) { @@ -110,13 +114,15 @@ static int vesacon_set_mode(int x, int y) } /* Allocate space in the bounce buffer for these structures */ - gi = &((struct vesa_info *)__com32.cs_bounce)->gi; - mi = &((struct vesa_info *)__com32.cs_bounce)->mi; - - debug("Hello, World!\r\n"); + vi = lzalloc(sizeof *vi); + if (!vi) { + err = 10; /* Out of memory */ + goto exit; + } + gi = &vi->gi; + mi = &vi->mi; memset(&rm, 0, sizeof rm); - memset(gi, 0, sizeof *gi); gi->signature = VBE2_MAGIC; /* Get VBE2 extended data */ rm.eax.w[0] = 0x4F00; /* Get SVGA general information */ @@ -124,12 +130,18 @@ static int vesacon_set_mode(int x, int y) rm.es = SEG(gi); __intcall(0x10, &rm, &rm); - if (rm.eax.w[0] != 0x004F) - return 1; /* Function call failed */ - if (gi->signature != VESA_MAGIC) - return 2; /* No magic */ - if (gi->version < 0x0102) - return 3; /* VESA 1.2+ required */ + if (rm.eax.w[0] != 0x004F) { + err = 1; /* Function call failed */ + goto exit; + } + if (gi->signature != VESA_MAGIC) { + err = 2; /* No magic */ + goto exit; + } + if (gi->version < 0x0102) { + err = 3; /* VESA 1.2+ required */ + goto exit; + } /* Copy general info */ memcpy(&__vesa_info.gi, gi, sizeof *gi); @@ -232,8 +244,10 @@ static int vesacon_set_mode(int x, int y) } } - if (bestpxf == PXF_NONE) - return 4; /* No mode found */ + if (bestpxf == PXF_NONE) { + err = 4; /* No mode found */ + goto exit; + } mi = &__vesa_info.mi; mode = bestmode; @@ -260,8 +274,10 @@ static int vesacon_set_mode(int x, int y) mode |= 0x4000; /* Request linear framebuffer if supported */ rm.ebx.w[0] = mode; __intcall(0x10, &rm, &rm); - if (rm.eax.w[0] != 0x004F) - return 9; /* Failed to set mode */ + if (rm.eax.w[0] != 0x004F) { + err = 9; /* Failed to set mode */ + goto exit; + } __vesacon_background = calloc(mi->h_res*mi->v_res, 4); __vesacon_shadowfb = calloc(mi->h_res*mi->v_res, 4); @@ -279,7 +295,11 @@ static int vesacon_set_mode(int x, int y) __vesacon_pixel_format = bestpxf; - return 0; +exit: + if (vi) + lfree(vi); + + return err; } static int init_text_display(void) |
