* [PATCH 1/2] Introduce grub_malloc0()
@ 2009-07-15 23:40 Pavel Roskin
2009-07-15 23:40 ` [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine Pavel Roskin
2009-07-16 15:22 ` [PATCH 1/2] Introduce grub_malloc0() Vladimir 'phcoder' Serbinenko
0 siblings, 2 replies; 11+ messages in thread
From: Pavel Roskin @ 2009-07-15 23:40 UTC (permalink / raw)
To: grub-devel
Even though it's a new function added to the core, its use makes
core.img smaller. And it makes modules smaller too.
ChangeLog:
* kern/mm.c (grub_malloc0): New function.
(grub_debug_malloc0): Likewise.
* include/grub/mm.h: Declare grub_malloc0() and
grub_debug_malloc0().
* util/misc.c (grub_malloc0): New function.
* bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_malloc0()
instead of grub_malloc(), remove unneeded initializations.
* bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise.
* commands/extcmd.c (grub_extcmd_dispatcher): Likewise.
* commands/parttool.c (grub_cmd_parttool): Likewise.
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise.
* disk/raid5_recover.c (grub_raid5_recover): Likewise.
* disk/raid6_recover.c (grub_raid6_recover): Likewise.
* disk/usbms.c (grub_usbms_finddevs): Likewise.
* efiemu/mm.c (grub_efiemu_request_memalign): Likewise.
* efiemu/pnvram.c (grub_efiemu_pnvram): Likewise.
(grub_cmd_efiemu_pnvram): Likewise.
* fs/i386/pc/pxe.c (grub_pxefs_open): Likewise.
* fs/iso9660.c (grub_iso9660_mount): Likewise.
(grub_iso9660_iterate_dir): Likewise.
* fs/jfs.c (grub_jfs_opendir): Likewise.
* fs/ntfs.c (list_file): Likewise.
(grub_ntfs_mount): Likewise.
* kern/disk.c (grub_disk_open): Likewise.
* kern/dl.c (grub_dl_load_core): Likewise.
* kern/elf.c (grub_elf_file): Likewise.
* kern/env.c (grub_env_context_open): Likewise.
(grub_env_set): Likewise.
(grub_env_set_data_slot): Likewise.
* kern/file.c (grub_file_open): Likewise.
* kern/fs.c (grub_fs_blocklist_open): Likewise.
* loader/i386/multiboot.c (grub_module): Likewise.
* loader/xnu.c (grub_xnu_create_key): Likewise.
(grub_xnu_create_value): Likewise.
* normal/main.c (grub_normal_add_menu_entry): Likewise.
(read_config_file): Likewise.
* normal/menu_entry.c (make_screen): Likewise.
* partmap/sun.c (sun_partition_map_iterate): Likewise.
* script/sh/lexer.c (grub_script_lexer_init): Likewise.
* script/sh/script.c (grub_script_parse): Likewise.
* video/bitmap.c (grub_video_bitmap_create): Likewise.
* video/readers/jpeg.c (grub_video_reader_jpeg): Likewise.
* video/readers/png.c (grub_png_output_byte): Likewise.
(grub_video_reader_png): Likewise.
---
bus/usb/uhci.c | 5 +----
bus/usb/usbhub.c | 4 +---
commands/extcmd.c | 3 +--
commands/parttool.c | 7 ++-----
disk/i386/pc/biosdisk.c | 3 +--
disk/raid5_recover.c | 4 +---
disk/raid6_recover.c | 7 ++-----
disk/usbms.c | 4 +---
efiemu/mm.c | 4 +---
efiemu/pnvram.c | 6 ++----
fs/i386/pc/pxe.c | 3 +--
fs/iso9660.c | 7 ++-----
fs/jfs.c | 4 +---
fs/ntfs.c | 7 ++-----
include/grub/mm.h | 6 ++++++
kern/disk.c | 6 +-----
kern/dl.c | 7 +------
kern/elf.c | 3 +--
kern/env.c | 11 +++--------
kern/file.c | 5 +----
kern/fs.c | 5 +----
kern/mm.c | 27 +++++++++++++++++++++++++++
loader/i386/multiboot.c | 3 +--
loader/xnu.c | 7 ++-----
normal/main.c | 14 ++++----------
| 9 +--------
partmap/sun.c | 4 +---
script/sh/lexer.c | 11 +----------
script/sh/script.c | 7 +------
util/misc.c | 10 ++++++++++
video/bitmap.c | 5 +----
video/readers/jpeg.c | 3 +--
video/readers/png.c | 6 ++----
33 files changed, 85 insertions(+), 132 deletions(-)
diff --git a/bus/usb/uhci.c b/bus/usb/uhci.c
index 84cd48d..f902488 100644
--- a/bus/usb/uhci.c
+++ b/bus/usb/uhci.c
@@ -170,14 +170,11 @@ grub_uhci_pci_iter (int bus, int device, int func,
return 0;
/* Allocate memory for the controller and register it. */
- u = grub_malloc (sizeof (*u));
+ u = grub_malloc0 (sizeof (*u));
if (! u)
return 1;
u->iobase = base & GRUB_UHCI_IOMASK;
- u->framelist = 0;
- u->qh = 0;
- u->td = 0;
grub_dprintf ("uhci", "class=0x%02x 0x%02x interface 0x%02x base=0x%x\n",
class, subclass, interf, u->iobase);
diff --git a/bus/usb/usbhub.c b/bus/usb/usbhub.c
index ba0925a..336d657 100644
--- a/bus/usb/usbhub.c
+++ b/bus/usb/usbhub.c
@@ -33,13 +33,11 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
grub_usb_device_t dev;
int i;
- dev = grub_malloc (sizeof (struct grub_usb_device));
+ dev = grub_malloc0 (sizeof (struct grub_usb_device));
if (! dev)
return NULL;
dev->controller = *controller;
- dev->addr = 0;
- dev->initialized = 0;
dev->speed = speed;
grub_usb_device_initialize (dev);
diff --git a/commands/extcmd.c b/commands/extcmd.c
index a605387..2e0d993 100644
--- a/commands/extcmd.c
+++ b/commands/extcmd.c
@@ -40,8 +40,7 @@ grub_extcmd_dispatcher (struct grub_command *cmd,
maxargs++;
/* Set up the option state. */
- state = grub_malloc (sizeof (struct grub_arg_list) * maxargs);
- grub_memset (state, 0, sizeof (struct grub_arg_list) * maxargs);
+ state = grub_malloc0 (sizeof (struct grub_arg_list) * maxargs);
if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc))
{
diff --git a/commands/parttool.c b/commands/parttool.c
index c807f06..7e72791 100644
--- a/commands/parttool.c
+++ b/commands/parttool.c
@@ -242,8 +242,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
if (grub_strcmp (args[i], "help") == 0)
return show_help ();
- parsed = (int *) grub_malloc (argc * sizeof (int));
- grub_memset (parsed, 0, argc * sizeof (int));
+ parsed = (int *) grub_malloc0 (argc * sizeof (int));
for (i = 1; i < argc; i++)
if (! parsed[i])
@@ -272,9 +271,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
args[i]);
ptool = cur;
pargs = (struct grub_parttool_args *)
- grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
- grub_memset (pargs, 0,
- ptool->nargs * sizeof (struct grub_parttool_args));
+ grub_malloc0 (ptool->nargs * sizeof (struct grub_parttool_args));
for (j = i; j < argc; j++)
if (! parsed[j])
{
diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c
index 09f0ce7..a71a8f4 100644
--- a/disk/i386/pc/biosdisk.c
+++ b/disk/i386/pc/biosdisk.c
@@ -109,12 +109,11 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
disk->has_partitions = ((drive & 0x80) && (drive != cd_drive));
disk->id = drive;
- data = (struct grub_biosdisk_data *) grub_malloc (sizeof (*data));
+ data = (struct grub_biosdisk_data *) grub_malloc0 (sizeof (*data));
if (! data)
return grub_errno;
data->drive = drive;
- data->flags = 0;
if ((cd_drive) && (drive == cd_drive))
{
diff --git a/disk/raid5_recover.c b/disk/raid5_recover.c
index 31cef88..e4f1f78 100644
--- a/disk/raid5_recover.c
+++ b/disk/raid5_recover.c
@@ -32,12 +32,10 @@ grub_raid5_recover (struct grub_raid_array *array, int disknr,
int i;
size <<= GRUB_DISK_SECTOR_BITS;
- buf2 = grub_malloc (size);
+ buf2 = grub_malloc0 (size);
if (!buf2)
return grub_errno;
- grub_memset (buf, 0, size);
-
for (i = 0; i < (int) array->total_devs; i++)
{
grub_err_t err;
diff --git a/disk/raid6_recover.c b/disk/raid6_recover.c
index 3a994af..0b7242c 100644
--- a/disk/raid6_recover.c
+++ b/disk/raid6_recover.c
@@ -96,11 +96,11 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
char *pbuf = 0, *qbuf = 0;
size <<= GRUB_DISK_SECTOR_BITS;
- pbuf = grub_malloc (size);
+ pbuf = grub_malloc0 (size);
if (!pbuf)
goto quit;
- qbuf = grub_malloc (size);
+ qbuf = grub_malloc0 (size);
if (!qbuf)
goto quit;
@@ -108,9 +108,6 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
if (q == (int) array->total_devs)
q = 0;
- grub_memset (pbuf, 0, size);
- grub_memset (qbuf, 0, size);
-
pos = q + 1;
if (pos == (int) array->total_devs)
pos = 0;
diff --git a/disk/usbms.c b/disk/usbms.c
index 3c7ebaf..4c5e216 100644
--- a/disk/usbms.c
+++ b/disk/usbms.c
@@ -107,14 +107,12 @@ grub_usbms_finddevs (void)
}
devcnt++;
- usbms = grub_malloc (sizeof (struct grub_usbms_dev));
+ usbms = grub_malloc0 (sizeof (struct grub_usbms_dev));
if (! usbms)
return 1;
usbms->dev = usbdev;
usbms->interface = i;
- usbms->in = NULL;
- usbms->out = NULL;
/* Iterate over all endpoints of this interface, at least a
IN and OUT bulk endpoint are required. */
diff --git a/efiemu/mm.c b/efiemu/mm.c
index 7d6a5d4..290ca11 100644
--- a/efiemu/mm.c
+++ b/efiemu/mm.c
@@ -104,14 +104,12 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
requested_memory[type] += align_overhead + size;
/* Remember the request */
- ret = grub_malloc (sizeof (*ret));
+ ret = grub_malloc0 (sizeof (*ret));
if (!ret)
return -1;
ret->type = type;
ret->size = size;
ret->align_overhead = align_overhead;
- ret->val = 0;
- ret->next = 0;
prev = 0;
/* Add request to the end of the chain.
diff --git a/efiemu/pnvram.c b/efiemu/pnvram.c
index d5daaab..21f7d93 100644
--- a/efiemu/pnvram.c
+++ b/efiemu/pnvram.c
@@ -339,11 +339,10 @@ grub_efiemu_pnvram (void)
accuracy = 50000000;
daylight = 0;
- nvram = grub_malloc (nvramsize);
+ nvram = grub_malloc0 (nvramsize);
if (!nvram)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't allocate space for temporary pnvram storage");
- grub_memset (nvram, 0, nvramsize);
return grub_efiemu_make_nvram ();
}
@@ -365,11 +364,10 @@ grub_cmd_efiemu_pnvram (struct grub_extcmd *cmd,
accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000;
daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0;
- nvram = grub_malloc (nvramsize);
+ nvram = grub_malloc0 (nvramsize);
if (!nvram)
return grub_error (GRUB_ERR_OUT_OF_MEMORY,
"Couldn't allocate space for temporary pnvram storage");
- grub_memset (nvram, 0, nvramsize);
if (argc == 1 && (err = read_pnvram (args[0])))
{
diff --git a/fs/i386/pc/pxe.c b/fs/i386/pc/pxe.c
index 1fc5680..5ee5fb7 100644
--- a/fs/i386/pc/pxe.c
+++ b/fs/i386/pc/pxe.c
@@ -146,11 +146,10 @@ grub_pxefs_open (struct grub_file *file, const char *name)
if (c.c2.status)
return grub_error (GRUB_ERR_BAD_FS, "open fails");
- data = grub_malloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
+ data = grub_malloc0 (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
if (! data)
return grub_errno;
- data->packet_number = 0;
data->block_size = grub_pxe_blksize;
grub_strcpy (data->filename, name);
diff --git a/fs/iso9660.c b/fs/iso9660.c
index c79ad4f..6e5c3a9 100644
--- a/fs/iso9660.c
+++ b/fs/iso9660.c
@@ -263,13 +263,11 @@ grub_iso9660_mount (grub_disk_t disk)
return 0;
}
- data = grub_malloc (sizeof (struct grub_iso9660_data));
+ data = grub_malloc0 (sizeof (struct grub_iso9660_data));
if (! data)
return 0;
data->disk = disk;
- data->rockridge = 0;
- data->joliet = 0;
block = 16;
do
@@ -509,8 +507,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
else
{
size = entry->len - 5;
- filename = grub_malloc (size + 1);
- filename[0] = '\0';
+ filename = grub_malloc0 (size + 1);
}
filename_alloc = 1;
grub_strncpy (filename, (char *) &entry->data[1], size);
diff --git a/fs/jfs.c b/fs/jfs.c
index 4f91825..fae2800 100644
--- a/fs/jfs.c
+++ b/fs/jfs.c
@@ -382,11 +382,10 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
return 0;
}
- diro = grub_malloc (sizeof (struct grub_jfs_diropen));
+ diro = grub_malloc0 (sizeof (struct grub_jfs_diropen));
if (!diro)
return 0;
- diro->index = 0;
diro->data = data;
diro->inode = inode;
@@ -397,7 +396,6 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
diro->sorted = (char *) (inode->dir.header.sorted);
diro->count = inode->dir.header.count;
- diro->dirpage = 0;
return diro;
}
diff --git a/fs/ntfs.c b/fs/ntfs.c
index c312b8b..bcbbdae 100644
--- a/fs/ntfs.c
+++ b/fs/ntfs.c
@@ -601,11 +601,10 @@ list_file (struct grub_ntfs_file *diro, char *pos,
(u32at (pos, 0x48) & ATTR_DIRECTORY) ? GRUB_FSHELP_DIR :
GRUB_FSHELP_REG;
- fdiro = grub_malloc (sizeof (struct grub_ntfs_file));
+ fdiro = grub_malloc0 (sizeof (struct grub_ntfs_file));
if (!fdiro)
return 0;
- grub_memset (fdiro, 0, sizeof (*fdiro));
fdiro->data = diro->data;
fdiro->ino = u32at (pos, 0);
@@ -791,12 +790,10 @@ grub_ntfs_mount (grub_disk_t disk)
if (!disk)
goto fail;
- data = (struct grub_ntfs_data *) grub_malloc (sizeof (*data));
+ data = (struct grub_ntfs_data *) grub_malloc0 (sizeof (*data));
if (!data)
goto fail;
- grub_memset (data, 0, sizeof (*data));
-
data->disk = disk;
/* Read the BPB. */
diff --git a/include/grub/mm.h b/include/grub/mm.h
index 4dd1363..413e439 100644
--- a/include/grub/mm.h
+++ b/include/grub/mm.h
@@ -30,6 +30,7 @@
void grub_mm_init_region (void *addr, grub_size_t size);
void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
+void *EXPORT_FUNC(grub_malloc0) (grub_size_t size);
void EXPORT_FUNC(grub_free) (void *ptr);
void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
@@ -45,6 +46,9 @@ void grub_mm_dump (unsigned lineno);
#define grub_malloc(size) \
grub_debug_malloc (__FILE__, __LINE__, size)
+#define grub_malloc0(size) \
+ grub_debug_malloc0 (__FILE__, __LINE__, size)
+
#define grub_realloc(ptr,size) \
grub_debug_realloc (__FILE__, __LINE__, ptr, size)
@@ -56,6 +60,8 @@ void grub_mm_dump (unsigned lineno);
void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
grub_size_t size);
+void *EXPORT_FUNC(grub_debug_malloc0) (const char *file, int line,
+ grub_size_t size);
void EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
void *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
grub_size_t size);
diff --git a/kern/disk.c b/kern/disk.c
index e167fb6..d1e3da3 100644
--- a/kern/disk.c
+++ b/kern/disk.c
@@ -244,14 +244,10 @@ grub_disk_open (const char *name)
grub_dprintf ("disk", "Opening `%s'...\n", name);
- disk = (grub_disk_t) grub_malloc (sizeof (*disk));
+ disk = (grub_disk_t) grub_malloc0 (sizeof (*disk));
if (! disk)
return 0;
- disk->dev = 0;
- disk->read_hook = 0;
- disk->partition = 0;
- disk->data = 0;
disk->name = grub_strdup (name);
if (! disk->name)
goto fail;
diff --git a/kern/dl.c b/kern/dl.c
index 122b6b9..ad6fc49 100644
--- a/kern/dl.c
+++ b/kern/dl.c
@@ -535,16 +535,11 @@ grub_dl_load_core (void *addr, grub_size_t size)
return 0;
}
- mod = (grub_dl_t) grub_malloc (sizeof (*mod));
+ mod = (grub_dl_t) grub_malloc0 (sizeof (*mod));
if (! mod)
return 0;
- mod->name = 0;
mod->ref_count = 1;
- mod->dep = 0;
- mod->segment = 0;
- mod->init = 0;
- mod->fini = 0;
grub_dprintf ("modules", "relocating to %p\n", mod);
if (grub_dl_resolve_name (mod, e)
diff --git a/kern/elf.c b/kern/elf.c
index 2590552..a9f4649 100644
--- a/kern/elf.c
+++ b/kern/elf.c
@@ -61,12 +61,11 @@ grub_elf_file (grub_file_t file)
{
grub_elf_t elf;
- elf = grub_malloc (sizeof (*elf));
+ elf = grub_malloc0 (sizeof (*elf));
if (! elf)
return 0;
elf->file = file;
- elf->phdrs = 0;
if (grub_file_seek (elf->file, 0) == (grub_off_t) -1)
goto fail;
diff --git a/kern/env.c b/kern/env.c
index e85627b..faca4c0 100644
--- a/kern/env.c
+++ b/kern/env.c
@@ -80,11 +80,10 @@ grub_env_context_open (int export)
struct grub_env_context *context;
int i;
- context = grub_malloc (sizeof (*context));
+ context = grub_malloc0 (sizeof (*context));
if (! context)
return grub_errno;
- grub_memset (context, 0, sizeof (*context));
context->prev = current_context;
current_context = context;
@@ -204,12 +203,10 @@ grub_env_set (const char *name, const char *val)
}
/* The variable does not exist, so create a new one. */
- var = grub_malloc (sizeof (*var));
+ var = grub_malloc0 (sizeof (*var));
if (! var)
return grub_errno;
- grub_memset (var, 0, sizeof (*var));
-
/* This is not necessary, because GRUB_ENV_VAR_LOCAL == 0. But leave
this for readability. */
var->type = GRUB_ENV_VAR_LOCAL;
@@ -379,12 +376,10 @@ grub_env_set_data_slot (const char *name, const void *ptr)
}
/* The variable does not exist, so create a new one. */
- var = grub_malloc (sizeof (*var));
+ var = grub_malloc0 (sizeof (*var));
if (! var)
goto fail;
- grub_memset (var, 0, sizeof (*var));
-
var->type = GRUB_ENV_VAR_DATA;
var->name = mangled_name;
var->value = (char *) ptr;
diff --git a/kern/file.c b/kern/file.c
index 5d5e640..2d7d967 100644
--- a/kern/file.c
+++ b/kern/file.c
@@ -75,14 +75,11 @@ grub_file_open (const char *name)
if (! device)
goto fail;
- file = (grub_file_t) grub_malloc (sizeof (*file));
+ file = (grub_file_t) grub_malloc0 (sizeof (*file));
if (! file)
goto fail;
file->device = device;
- file->offset = 0;
- file->data = 0;
- file->read_hook = 0;
if (device->disk && file_name[0] != '/')
/* This is a block list. */
diff --git a/kern/fs.c b/kern/fs.c
index c8f4970..f17347e 100644
--- a/kern/fs.c
+++ b/kern/fs.c
@@ -161,7 +161,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
while (p);
/* Allocate a block list. */
- blocks = grub_malloc (sizeof (struct grub_fs_block) * (num + 1));
+ blocks = grub_malloc0 (sizeof (struct grub_fs_block) * (num + 1));
if (! blocks)
return 0;
@@ -179,8 +179,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
goto fail;
}
}
- else
- blocks[i].offset = 0;
p++;
blocks[i].length = grub_strtoul (p, &p, 0);
@@ -203,7 +201,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
p++;
}
- blocks[i].length = 0;
file->data = blocks;
return GRUB_ERR_NONE;
diff --git a/kern/mm.c b/kern/mm.c
index 9a0ae56..a07bd42 100644
--- a/kern/mm.c
+++ b/kern/mm.c
@@ -68,6 +68,7 @@
#ifdef MM_DEBUG
# undef grub_malloc
+# undef grub_malloc0
# undef grub_realloc
# undef grub_free
# undef grub_memalign
@@ -348,6 +349,19 @@ grub_malloc (grub_size_t size)
return grub_memalign (0, size);
}
+/* Allocate SIZE bytes, clear them and return the pointer. */
+void *
+grub_malloc0 (grub_size_t size)
+{
+ void *ret;
+
+ ret = grub_memalign (0, size);
+ if (ret)
+ grub_memset (ret, 0, size);
+
+ return ret;
+}
+
/* Deallocate the pointer PTR. */
void
grub_free (void *ptr)
@@ -522,6 +536,19 @@ grub_debug_malloc (const char *file, int line, grub_size_t size)
return ptr;
}
+void *
+grub_debug_malloc0 (const char *file, int line, grub_size_t size)
+{
+ void *ptr;
+
+ if (grub_mm_debug)
+ grub_printf ("%s:%d: malloc0 (0x%zx) = ", file, line, size);
+ ptr = grub_malloc0 (size);
+ if (grub_mm_debug)
+ grub_printf ("%p\n", ptr);
+ return ptr;
+}
+
void
grub_debug_free (const char *file, int line, void *ptr)
{
diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c
index 8ce315e..7e9ac66 100644
--- a/loader/i386/multiboot.c
+++ b/loader/i386/multiboot.c
@@ -456,13 +456,12 @@ grub_module (int argc, char *argv[])
}
else
{
- struct grub_mod_list *modlist = grub_malloc (sizeof (struct grub_mod_list));
+ struct grub_mod_list *modlist = grub_malloc0 (sizeof (struct grub_mod_list));
if (! modlist)
goto fail;
modlist->mod_start = (grub_uint32_t) module;
modlist->mod_end = (grub_uint32_t) module + size;
modlist->cmdline = (grub_uint32_t) cmdline;
- modlist->pad = 0;
mbi->mods_count = 1;
mbi->mods_addr = (grub_uint32_t) modlist;
mbi->flags |= MULTIBOOT_INFO_MODS;
diff --git a/loader/xnu.c b/loader/xnu.c
index b2c6c05..0861b83 100644
--- a/loader/xnu.c
+++ b/loader/xnu.c
@@ -278,7 +278,7 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
ret = grub_xnu_find_key (*parent, name);
if (ret)
return ret;
- ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
+ ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
if (! ret)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create key %s", name);
@@ -292,7 +292,6 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
return 0;
}
ret->datasize = -1;
- ret->first_child = 0;
ret->next = *parent;
*parent = ret;
return ret;
@@ -313,7 +312,7 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
ret->data = 0;
return ret;
}
- ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
+ ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
if (! ret)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
@@ -326,8 +325,6 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
return 0;
}
- ret->datasize = 0;
- ret->data = 0;
ret->next = *parent;
*parent = ret;
return ret;
diff --git a/normal/main.c b/normal/main.c
index 7f6336e..878b947 100644
--- a/normal/main.c
+++ b/normal/main.c
@@ -166,11 +166,9 @@ grub_normal_add_menu_entry (int argc, const char **args,
struct grub_menu_entry_class *classes_tail;
/* Allocate dummy head node for class list. */
- classes_head = grub_malloc (sizeof (struct grub_menu_entry_class));
+ classes_head = grub_malloc0 (sizeof (struct grub_menu_entry_class));
if (! classes_head)
return grub_errno;
- classes_head->name = 0;
- classes_head->next = 0;
classes_tail = classes_head;
menu = grub_env_get_data_slot ("menu");
@@ -206,7 +204,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
}
/* Create a new class and add it at the tail of the list. */
- new_class = grub_malloc (sizeof (struct grub_menu_entry_class));
+ new_class = grub_malloc0 (sizeof (struct grub_menu_entry_class));
if (! new_class)
{
grub_free (class_name);
@@ -215,7 +213,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
}
/* Fill in the new class node. */
new_class->name = class_name;
- new_class->next = 0;
/* Link the tail to it, and make it the new tail. */
classes_tail->next = new_class;
classes_tail = new_class;
@@ -267,7 +264,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
while (*last)
last = &(*last)->next;
- *last = grub_malloc (sizeof (**last));
+ *last = grub_malloc0 (sizeof (**last));
if (! *last)
{
free_menu_entry_classes (classes_head);
@@ -278,7 +275,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
(*last)->title = menutitle;
(*last)->classes = classes_head;
- (*last)->next = 0;
(*last)->sourcecode = menusourcecode;
menu->size++;
@@ -346,11 +342,9 @@ read_config_file (const char *config)
newmenu = grub_env_get_data_slot ("menu");
if (! newmenu)
{
- newmenu = grub_malloc (sizeof (*newmenu));
+ newmenu = grub_malloc0 (sizeof (*newmenu));
if (! newmenu)
return 0;
- newmenu->size = 0;
- newmenu->entry_list = 0;
grub_env_set_data_slot ("menu", newmenu);
}
--git a/normal/menu_entry.c b/normal/menu_entry.c
index 86e581e..86cad0a 100644
--- a/normal/menu_entry.c
+++ b/normal/menu_entry.c
@@ -416,18 +416,11 @@ make_screen (grub_menu_entry_t entry)
struct screen *screen;
/* Initialize the screen. */
- screen = grub_malloc (sizeof (*screen));
+ screen = grub_malloc0 (sizeof (*screen));
if (! screen)
return 0;
screen->num_lines = 1;
- screen->column = 0;
- screen->real_column = 0;
- screen->line = 0;
- screen->x = 0;
- screen->y = 0;
- screen->killed_text = 0;
- screen->completion_shown = 0;
screen->lines = grub_malloc (sizeof (struct line));
if (! screen->lines)
goto fail;
diff --git a/partmap/sun.c b/partmap/sun.c
index 6094777..e442ff7 100644
--- a/partmap/sun.c
+++ b/partmap/sun.c
@@ -95,12 +95,10 @@ sun_partition_map_iterate (grub_disk_t disk,
raw = *disk;
raw.partition = 0;
- p = (grub_partition_t) grub_malloc (sizeof (struct grub_partition));
+ p = (grub_partition_t) grub_malloc0 (sizeof (struct grub_partition));
if (! p)
return grub_errno;
- p->offset = 0;
- p->data = 0;
p->partmap = &grub_sun_partition_map;
if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block),
&block) == GRUB_ERR_NONE)
diff --git a/script/sh/lexer.c b/script/sh/lexer.c
index 17f18e2..cbc33d7 100644
--- a/script/sh/lexer.c
+++ b/script/sh/lexer.c
@@ -49,22 +49,13 @@ grub_script_lexer_init (char *script, grub_reader_getline_t getline)
{
struct grub_lexer_param *param;
- param = grub_malloc (sizeof (*param));
+ param = grub_malloc0 (sizeof (*param));
if (! param)
return 0;
param->state = GRUB_PARSER_STATE_TEXT;
param->getline = getline;
- param->refs = 0;
- param->done = 0;
- param->newscript = 0;
param->script = script;
- param->record = 0;
- param->recording = 0;
- param->recordpos = 0;
- param->recordlen = 0;
- param->tokenonhold = 0;
- param->was_newline = 0;
return param;
}
diff --git a/script/sh/script.c b/script/sh/script.c
index 89fa947..3019cd7 100644
--- a/script/sh/script.c
+++ b/script/sh/script.c
@@ -304,15 +304,10 @@ grub_script_parse (char *script, grub_reader_getline_t getline)
if (! parsed)
return 0;
- parsestate = grub_malloc (sizeof (*parsestate));
+ parsestate = grub_malloc0 (sizeof (*parsestate));
if (! parsestate)
return 0;
- parsestate->err = 0;
- parsestate->func_mem = 0;
- parsestate->memused = 0;
- parsestate->parsed = 0;
-
/* Initialize the lexer. */
lexstate = grub_script_lexer_init (script, getline);
if (! lexstate)
diff --git a/util/misc.c b/util/misc.c
index f615a42..19a4244 100644
--- a/util/misc.c
+++ b/util/misc.c
@@ -257,6 +257,16 @@ grub_malloc (grub_size_t size)
return xmalloc (size);
}
+void *
+grub_malloc0 (grub_size_t size)
+{
+ void *ret;
+
+ ret = xmalloc (size);
+ memset (ret, 0, size);
+ return ret;
+}
+
void
grub_free (void *ptr)
{
diff --git a/video/bitmap.c b/video/bitmap.c
index d399fd7..009d3e4 100644
--- a/video/bitmap.c
+++ b/video/bitmap.c
@@ -137,7 +137,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
/* Calculate size needed for the data. */
size = (width * mode_info->bytes_per_pixel) * height;
- (*bitmap)->data = grub_malloc (size);
+ (*bitmap)->data = grub_malloc0 (size);
if (! (*bitmap)->data)
{
grub_free (*bitmap);
@@ -146,9 +146,6 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
return grub_errno;
}
- /* Clear bitmap. */
- grub_memset ((*bitmap)->data, 0, size);
-
return GRUB_ERR_NONE;
}
diff --git a/video/readers/jpeg.c b/video/readers/jpeg.c
index b64bf3f..076f6fd 100644
--- a/video/readers/jpeg.c
+++ b/video/readers/jpeg.c
@@ -667,12 +667,11 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
if (!file)
return grub_errno;
- data = grub_malloc (sizeof (*data));
+ data = grub_malloc0 (sizeof (*data));
if (data != NULL)
{
int i;
- grub_memset (data, 0, sizeof (*data));
data->file = file;
data->bitmap = bitmap;
grub_jpeg_decode_jpeg (data);
diff --git a/video/readers/png.c b/video/readers/png.c
index 733fa73..3ae8fb2 100644
--- a/video/readers/png.c
+++ b/video/readers/png.c
@@ -543,11 +543,10 @@ grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n)
if (data->first_line)
{
- blank_line = grub_malloc (row_bytes);
+ blank_line = grub_malloc0 (row_bytes);
if (blank_line == NULL)
return grub_errno;
- grub_memset (blank_line, 0, row_bytes);
up = blank_line;
}
else
@@ -843,10 +842,9 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap,
if (!file)
return grub_errno;
- data = grub_malloc (sizeof (*data));
+ data = grub_malloc0 (sizeof (*data));
if (data != NULL)
{
- grub_memset (data, 0, sizeof (*data));
data->file = file;
data->bitmap = bitmap;
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine
2009-07-15 23:40 [PATCH 1/2] Introduce grub_malloc0() Pavel Roskin
@ 2009-07-15 23:40 ` Pavel Roskin
2009-07-16 16:24 ` Vladimir 'phcoder' Serbinenko
2009-07-16 15:22 ` [PATCH 1/2] Introduce grub_malloc0() Vladimir 'phcoder' Serbinenko
1 sibling, 1 reply; 11+ messages in thread
From: Pavel Roskin @ 2009-07-15 23:40 UTC (permalink / raw)
To: grub-devel
ChangeLog:
* Makefile.in: Remove LIBLZO and enable_lzo.
* conf/i386-pc.rmk: Remove lzo support.
* configure.ac: Remove checks for lzo, don't define ENABLE_LZMA.
* include/grub/i386/pc/kernel.h: Define ENABLE_LZMA. Remove lzo
support.
* kern/i386/pc/lzo1x.S: Remove.
* kern/i386/pc/startup.S: Remove lzo support.
* util/i386/pc/grub-mkimage.c: Likewise.
---
Makefile.in | 2
conf/i386-pc.rmk | 6 -
configure.ac | 26 ---
include/grub/i386/pc/kernel.h | 7 -
kern/i386/pc/lzo1x.S | 315 -----------------------------------------
kern/i386/pc/startup.S | 19 --
util/i386/pc/grub-mkimage.c | 54 -------
7 files changed, 8 insertions(+), 421 deletions(-)
delete mode 100644 kern/i386/pc/lzo1x.S
diff --git a/Makefile.in b/Makefile.in
index 3d208e7..29e347a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -94,7 +94,6 @@ HELP2MAN := LANG=C $(HELP2MAN) --no-info --source=FSF
endif
AWK = @AWK@
LIBCURSES = @LIBCURSES@
-LIBLZO = @LIBLZO@
YACC = @YACC@
UNIFONT_BDF = @UNIFONT_BDF@
@@ -103,7 +102,6 @@ enable_grub_emu = @enable_grub_emu@
enable_grub_emu_usb = @enable_grub_emu_usb@
enable_grub_fstest = @enable_grub_fstest@
enable_grub_pe2elf = @enable_grub_pe2elf@
-enable_lzo = @enable_lzo@
enable_grub_mkfont = @enable_grub_mkfont@
freetype_cflags = @freetype_cflags@
freetype_libs = @freetype_libs@
diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
index f1915b6..f5bded2 100644
--- a/conf/i386-pc.rmk
+++ b/conf/i386-pc.rmk
@@ -89,14 +89,8 @@ sbin_UTILITIES += grub-emu
endif
# For grub-mkimage.
-ifeq ($(enable_lzo), yes)
-grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
- util/resolve.c
-grub_mkimage_LDFLAGS = $(LIBLZO)
-else
grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
util/resolve.c lib/LzmaEnc.c lib/LzFind.c
-endif
grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)
util/i386/pc/grub-mkimage.c_DEPENDENCIES = Makefile
diff --git a/configure.ac b/configure.ac
index 8b12c58..66f2b59 100644
--- a/configure.ac
+++ b/configure.ac
@@ -171,32 +171,6 @@ if test x$grub_cv_apple_cc = xyes ; then
ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
fi
-# Check LZO when compiling for the i386-pc.
-if test "$target_cpu"-"$platform" = i386-pc; then
- AC_ARG_ENABLE([lzo],
- [AS_HELP_STRING([--enable-lzo],
- [use lzo to compress kernel (default is lzma)])])
- [if [ x"$enable_lzo" = xyes ]; then
- # There are three possibilities. LZO version 2 installed with the name
- # liblzo2, with the name liblzo, and LZO version 1.]
- AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
- AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
- [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
- [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
- [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
- AC_SUBST([LIBLZO])
- [LIBS="$LIBS $LIBLZO"]
- AC_CHECK_FUNC([lzo1x_999_compress], ,
- [AC_MSG_ERROR([LZO1X-999 must be enabled])])
-
- [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
- AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
- [else]
- AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
- [fi]
- AC_SUBST([enable_lzo])
-fi
-
# Check for functions.
AC_CHECK_FUNCS(posix_memalign memalign asprintf)
diff --git a/include/grub/i386/pc/kernel.h b/include/grub/i386/pc/kernel.h
index 5b9d8dc..e830afa 100644
--- a/include/grub/i386/pc/kernel.h
+++ b/include/grub/i386/pc/kernel.h
@@ -41,11 +41,10 @@
#define GRUB_KERNEL_MACHINE_DATA_END 0x5c
/* The size of the first region which won't be compressed. */
-#if defined(ENABLE_LZO)
-#define GRUB_KERNEL_MACHINE_RAW_SIZE (GRUB_KERNEL_MACHINE_DATA_END + 0x450)
-#elif defined(ENABLE_LZMA)
#define GRUB_KERNEL_MACHINE_RAW_SIZE (GRUB_KERNEL_MACHINE_DATA_END + 0x5F0)
-#endif
+
+/* Enable LZMA compression */
+#define ENABLE_LZMA 1
#ifndef ASM_FILE
diff --git a/kern/i386/pc/lzo1x.S b/kern/i386/pc/lzo1x.S
deleted file mode 100644
index 49ba8cc..0000000
--- a/kern/i386/pc/lzo1x.S
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
- * Copyright (C) 2003,2007 Free Software Foundation, Inc.
- *
- * GRUB is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GRUB is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * This code was stolen from the files enter.sh, leave.sh, lzo1x_d.sh,
- * lzo1x_f.s and lzo_asm.h in LZO version 1.08, and was heavily modified
- * to adapt it to GRUB's requirement.
- *
- * See <http://www.oberhumer.com/opensource/lzo/>, for more information
- * about LZO.
- */
-
-#define INP 4+16(%esp)
-#define INS 8+16(%esp)
-#define OUTP 12+16(%esp)
-#define NN 3
-#define N_3 %ebp
-#define N_255 $255
-#define LODSB movb (%esi), %al ; incl %esi
-#define NOTL_3(r) xorl N_3, r
-#define MOVSL(r1,r2,x) movl (r1), x ; addl $4, r1 ; movl x, (r2) ; addl $4, r2
-#define COPYL_C(r1,r2,x,rc) 9: MOVSL(r1,r2,x) ; decl rc ; jnz 9b
-#define COPYL(r1,r2,x) COPYL_C(r1,r2,x,%ecx)
-
-lzo1x_decompress:
- pushl %ebp
- pushl %edi
- pushl %esi
- pushl %ebx
-
- cld
-
- movl INP, %esi
- movl OUTP, %edi
- movl $3, %ebp
-
-
- xorl %eax, %eax
- xorl %ebx, %ebx /* high bits 9-32 stay 0 */
- lodsb
- cmpb $17, %al
- jbe .L01
- subb $17-NN, %al
- jmp .LFLR
-
-
-/***********************************************************************
-// literal run
-************************************************************************/
-
-0: addl N_255, %eax
-1: movb (%esi), %bl
- incl %esi
- orb %bl, %bl
- jz 0b
- leal 18+NN(%eax,%ebx), %eax
- jmp 3f
-
-
-.L00:
- LODSB
-.L01:
- cmpb $16, %al
- jae .LMATCH
-
- /* a literal run */
- orb %al, %al
- jz 1b
- addl $3+NN, %eax
-3:
-.LFLR:
- movl %eax, %ecx
- NOTL_3(%eax)
- shrl $2, %ecx
- andl N_3, %eax
- COPYL(%esi,%edi,%edx)
- subl %eax, %esi
- subl %eax, %edi
-
- LODSB
- cmpb $16, %al
- jae .LMATCH
-
-
-/***********************************************************************
-// R1
-************************************************************************/
-
- shrl $2, %eax
- movb (%esi), %bl
- leal -0x801(%edi), %edx
- leal (%eax,%ebx,4), %eax
- incl %esi
- subl %eax, %edx
- movl (%edx), %ecx
- movl %ecx, (%edi)
- addl N_3, %edi
- jmp .LMDONE
-
-
-/***********************************************************************
-// M2
-************************************************************************/
-
-.LMATCH:
- cmpb $64, %al
- jb .LM3MATCH
-
- /* a M2 match */
- movl %eax, %ecx
- shrl $2, %eax
- leal -1(%edi), %edx
- andl $7, %eax
- movb (%esi), %bl
- shrl $5, %ecx
- leal (%eax,%ebx,8), %eax
- incl %esi
- subl %eax, %edx
-
- addl $1+3, %ecx
-
- cmpl N_3, %eax
- jae .LCOPYLONG
- jmp .LCOPYBYTE
-
-
-/***********************************************************************
-// M3
-************************************************************************/
-
-0: addl N_255, %eax
-1: movb (%esi), %bl
- incl %esi
- orb %bl, %bl
- jz 0b
- leal 33+NN(%eax,%ebx), %ecx
- xorl %eax, %eax
- jmp 3f
-
-
-.LM3MATCH:
- cmpb $32, %al
- jb .LM4MATCH
-
- /* a M3 match */
- andl $31, %eax
- jz 1b
- lea 2+NN(%eax), %ecx
-3:
- movw (%esi), %ax
- leal -1(%edi), %edx
- shrl $2, %eax
- addl $2, %esi
- subl %eax, %edx
-
- cmpl N_3, %eax
- jb .LCOPYBYTE
-
-
-/***********************************************************************
-// copy match
-************************************************************************/
-
-.LCOPYLONG: /* copy match using longwords */
- leal -3(%edi,%ecx), %eax
- shrl $2, %ecx
- COPYL(%edx,%edi,%ebx)
- movl %eax, %edi
- xorl %ebx, %ebx
-
-.LMDONE:
- movb -2(%esi), %al
- andl N_3, %eax
- jz .L00
-.LFLR3:
- movl (%esi), %edx
- addl %eax, %esi
- movl %edx, (%edi)
- addl %eax, %edi
-
- LODSB
- jmp .LMATCH
-
-
-.LCOPYBYTE: /* copy match using bytes */
- xchgl %edx,%esi
- subl N_3,%ecx
-
- rep
- movsb
- movl %edx, %esi
- jmp .LMDONE
-
-
-/***********************************************************************
-// M4
-************************************************************************/
-
-0: addl N_255, %ecx
-1: movb (%esi), %bl
- incl %esi
- orb %bl, %bl
- jz 0b
- leal 9+NN(%ebx,%ecx), %ecx
- jmp 3f
-
-
-.LM4MATCH:
- cmpb $16, %al
- jb .LM1MATCH
-
- /* a M4 match */
- movl %eax, %ecx
- andl $8, %eax
- shll $13, %eax /* save in bit 16 */
- andl $7, %ecx
- jz 1b
- addl $2+NN, %ecx
-3:
- movw (%esi), %ax
- addl $2, %esi
- leal -0x4000(%edi), %edx
- shrl $2, %eax
- jz .LEOF
- subl %eax, %edx
- jmp .LCOPYLONG
-
-
-/***********************************************************************
-// M1
-************************************************************************/
-
-.LM1MATCH:
- /* a M1 match */
- shrl $2, %eax
- movb (%esi), %bl
- leal -1(%edi), %edx
- leal (%eax,%ebx,4), %eax
- incl %esi
- subl %eax, %edx
-
- movb (%edx), %al /* we must use this because edx can be edi-1 */
- movb %al, (%edi)
- movb 1(%edx), %bl
- movb %bl, 1(%edi)
- addl $2, %edi
- jmp .LMDONE
-
-
-/***********************************************************************
-//
-************************************************************************/
-
-.LEOF:
-/**** xorl %eax,%eax eax=0 from above */
-
- cmpl $3+NN, %ecx /* ecx must be 3/6 */
- setnz %al
-
- /* check compressed size */
- movl INP, %edx
- addl INS, %edx
- cmpl %edx, %esi /* check compressed size */
- ja .L_input_overrun
- jb .L_input_not_consumed
-
-.L_leave:
- negl %eax
- jnz 1f
-
- subl OUTP, %edi /* write back the uncompressed size */
- movl %edi, %eax
-
-1: popl %ebx
- popl %esi
- popl %edi
- popl %ebp
- ret
-
-.L_input_not_consumed:
- movl $8, %eax /* LZO_E_INPUT_NOT_CONSUMED */
- jmp .L_leave
-
-.L_input_overrun:
- movl $4, %eax /* LZO_E_INPUT_OVERRUN */
- jmp .L_leave
-
-#undef INP
-#undef INS
-#undef OUTP
-#undef NN
-#undef NN
-#undef N_3
-#undef N_255
-#undef LODSB
-#undef NOTL_3
-#undef MOVSL
-#undef COPYL_C
-#undef COPYL
diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S
index 171fbea..be258fb 100644
--- a/kern/i386/pc/startup.S
+++ b/kern/i386/pc/startup.S
@@ -210,20 +210,7 @@ codestart:
incl %eax
call EXT_C(grub_gate_a20)
-#if defined(ENABLE_LZO)
- /* decompress the compressed part and put the result at 1MB */
- movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %esi
- movl $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
-
- pushl %esi
- pushl EXT_C(grub_compressed_size)
- pushl %edi
- call lzo1x_decompress
- addl $12, %esp
-
- movl %eax, %ecx
- cld
-#elif defined(ENABLE_LZMA)
+#ifdef ENABLE_LZMA
movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
movl $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi
pushl %edi
@@ -451,9 +438,7 @@ gate_a20_check_state:
popl %ebx
ret
-#if defined(ENABLE_LZO)
-#include "lzo1x.S"
-#elif defined(ENABLE_LZMA)
+#ifdef ENABLE_LZMA
#include "lzma_decode.S"
#endif
diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c
index ee1af82..b81392c 100644
--- a/util/i386/pc/grub-mkimage.c
+++ b/util/i386/pc/grub-mkimage.c
@@ -36,57 +36,9 @@
#define _GNU_SOURCE 1
#include <getopt.h>
-#if defined(ENABLE_LZO)
-
-#if defined(HAVE_LZO_LZO1X_H)
-# include <lzo/lzo1x.h>
-#elif defined(HAVE_LZO1X_H)
-# include <lzo1x.h>
-#endif
-
-#elif defined(ENABLE_LZMA)
-
+#ifdef ENABLE_LZMA
#include <grub/lib/LzmaEnc.h>
-#endif
-
-#if defined(ENABLE_LZO)
-
-static void
-compress_kernel (char *kernel_img, size_t kernel_size,
- char **core_img, size_t *core_size)
-{
- lzo_uint size;
- char *wrkmem;
-
- if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
- grub_util_error ("the core image is too small");
-
- if (lzo_init () != LZO_E_OK)
- grub_util_error ("cannot initialize LZO");
-
- *core_img = xmalloc (kernel_size + kernel_size / 64 + 16 + 3);
- wrkmem = xmalloc (LZO1X_999_MEM_COMPRESS);
-
- memcpy (*core_img, kernel_img, GRUB_KERNEL_MACHINE_RAW_SIZE);
-
- grub_util_info ("compressing the core image");
- if (lzo1x_999_compress ((const lzo_byte *) (kernel_img
- + GRUB_KERNEL_MACHINE_RAW_SIZE),
- kernel_size - GRUB_KERNEL_MACHINE_RAW_SIZE,
- (lzo_byte *) (*core_img
- + GRUB_KERNEL_MACHINE_RAW_SIZE),
- &size, wrkmem)
- != LZO_E_OK)
- grub_util_error ("cannot compress the kernel image");
-
- free (wrkmem);
-
- *core_size = (size_t) size + GRUB_KERNEL_MACHINE_RAW_SIZE;
-}
-
-#elif defined(ENABLE_LZMA)
-
static void *SzAlloc(void *p, size_t size) { p = p; return xmalloc(size); }
static void SzFree(void *p, void *address) { p = p; free(address); }
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
@@ -124,7 +76,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
*core_size += GRUB_KERNEL_MACHINE_RAW_SIZE;
}
-#else
+#else /* No lzma compression */
static void
compress_kernel (char *kernel_img, size_t kernel_size,
@@ -135,7 +87,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
*core_size = kernel_size;
}
-#endif
+#endif /* No lzma compression */
static void
generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine
2009-07-15 23:40 ` [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine Pavel Roskin
@ 2009-07-16 16:24 ` Vladimir 'phcoder' Serbinenko
2009-07-18 18:18 ` Robert Millan
0 siblings, 1 reply; 11+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-07-16 16:24 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, Jul 16, 2009 at 1:40 AM, Pavel Roskin<proski@gnu.org> wrote:
> ChangeLog:
>
> * Makefile.in: Remove LIBLZO and enable_lzo.
> * conf/i386-pc.rmk: Remove lzo support.
> * configure.ac: Remove checks for lzo, don't define ENABLE_LZMA.
> * include/grub/i386/pc/kernel.h: Define ENABLE_LZMA. Remove lzo
> support.
> * kern/i386/pc/lzo1x.S: Remove.
> * kern/i386/pc/startup.S: Remove lzo support.
> * util/i386/pc/grub-mkimage.c: Likewise.
Is there a reason to remove lzo? I know that lzma performs much better
in terms of compression but afaik lzo doesn't create any problems nor
is compiled by default and may be desirable for some users
> ---
> Makefile.in | 2
> conf/i386-pc.rmk | 6 -
> configure.ac | 26 ---
> include/grub/i386/pc/kernel.h | 7 -
> kern/i386/pc/lzo1x.S | 315 -----------------------------------------
> kern/i386/pc/startup.S | 19 --
> util/i386/pc/grub-mkimage.c | 54 -------
> 7 files changed, 8 insertions(+), 421 deletions(-)
> delete mode 100644 kern/i386/pc/lzo1x.S
>
> diff --git a/Makefile.in b/Makefile.in
> index 3d208e7..29e347a 100644
> --- a/Makefile.in
> +++ b/Makefile.in
> @@ -94,7 +94,6 @@ HELP2MAN := LANG=C $(HELP2MAN) --no-info --source=FSF
> endif
> AWK = @AWK@
> LIBCURSES = @LIBCURSES@
> -LIBLZO = @LIBLZO@
> YACC = @YACC@
> UNIFONT_BDF = @UNIFONT_BDF@
>
> @@ -103,7 +102,6 @@ enable_grub_emu = @enable_grub_emu@
> enable_grub_emu_usb = @enable_grub_emu_usb@
> enable_grub_fstest = @enable_grub_fstest@
> enable_grub_pe2elf = @enable_grub_pe2elf@
> -enable_lzo = @enable_lzo@
> enable_grub_mkfont = @enable_grub_mkfont@
> freetype_cflags = @freetype_cflags@
> freetype_libs = @freetype_libs@
> diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
> index f1915b6..f5bded2 100644
> --- a/conf/i386-pc.rmk
> +++ b/conf/i386-pc.rmk
> @@ -89,14 +89,8 @@ sbin_UTILITIES += grub-emu
> endif
>
> # For grub-mkimage.
> -ifeq ($(enable_lzo), yes)
> -grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
> - util/resolve.c
> -grub_mkimage_LDFLAGS = $(LIBLZO)
> -else
> grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
> util/resolve.c lib/LzmaEnc.c lib/LzFind.c
> -endif
> grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)
> util/i386/pc/grub-mkimage.c_DEPENDENCIES = Makefile
>
> diff --git a/configure.ac b/configure.ac
> index 8b12c58..66f2b59 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -171,32 +171,6 @@ if test x$grub_cv_apple_cc = xyes ; then
> ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
> fi
>
> -# Check LZO when compiling for the i386-pc.
> -if test "$target_cpu"-"$platform" = i386-pc; then
> - AC_ARG_ENABLE([lzo],
> - [AS_HELP_STRING([--enable-lzo],
> - [use lzo to compress kernel (default is lzma)])])
> - [if [ x"$enable_lzo" = xyes ]; then
> - # There are three possibilities. LZO version 2 installed with the name
> - # liblzo2, with the name liblzo, and LZO version 1.]
> - AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
> - AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
> - [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
> - [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
> - [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
> - AC_SUBST([LIBLZO])
> - [LIBS="$LIBS $LIBLZO"]
> - AC_CHECK_FUNC([lzo1x_999_compress], ,
> - [AC_MSG_ERROR([LZO1X-999 must be enabled])])
> -
> - [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
> - AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
> - [else]
> - AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
> - [fi]
> - AC_SUBST([enable_lzo])
> -fi
> -
> # Check for functions.
> AC_CHECK_FUNCS(posix_memalign memalign asprintf)
>
> diff --git a/include/grub/i386/pc/kernel.h b/include/grub/i386/pc/kernel.h
> index 5b9d8dc..e830afa 100644
> --- a/include/grub/i386/pc/kernel.h
> +++ b/include/grub/i386/pc/kernel.h
> @@ -41,11 +41,10 @@
> #define GRUB_KERNEL_MACHINE_DATA_END 0x5c
>
> /* The size of the first region which won't be compressed. */
> -#if defined(ENABLE_LZO)
> -#define GRUB_KERNEL_MACHINE_RAW_SIZE (GRUB_KERNEL_MACHINE_DATA_END + 0x450)
> -#elif defined(ENABLE_LZMA)
> #define GRUB_KERNEL_MACHINE_RAW_SIZE (GRUB_KERNEL_MACHINE_DATA_END + 0x5F0)
> -#endif
> +
> +/* Enable LZMA compression */
> +#define ENABLE_LZMA 1
>
> #ifndef ASM_FILE
>
> diff --git a/kern/i386/pc/lzo1x.S b/kern/i386/pc/lzo1x.S
> deleted file mode 100644
> index 49ba8cc..0000000
> --- a/kern/i386/pc/lzo1x.S
> +++ /dev/null
> @@ -1,315 +0,0 @@
> -/*
> - * GRUB -- GRand Unified Bootloader
> - * Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
> - * Copyright (C) 2003,2007 Free Software Foundation, Inc.
> - *
> - * GRUB is free software: you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License as published by
> - * the Free Software Foundation, either version 3 of the License, or
> - * (at your option) any later version.
> - *
> - * GRUB is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> - * GNU General Public License for more details.
> - *
> - * You should have received a copy of the GNU General Public License
> - * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
> - */
> -
> -/*
> - * This code was stolen from the files enter.sh, leave.sh, lzo1x_d.sh,
> - * lzo1x_f.s and lzo_asm.h in LZO version 1.08, and was heavily modified
> - * to adapt it to GRUB's requirement.
> - *
> - * See <http://www.oberhumer.com/opensource/lzo/>, for more information
> - * about LZO.
> - */
> -
> -#define INP 4+16(%esp)
> -#define INS 8+16(%esp)
> -#define OUTP 12+16(%esp)
> -#define NN 3
> -#define N_3 %ebp
> -#define N_255 $255
> -#define LODSB movb (%esi), %al ; incl %esi
> -#define NOTL_3(r) xorl N_3, r
> -#define MOVSL(r1,r2,x) movl (r1), x ; addl $4, r1 ; movl x, (r2) ; addl $4, r2
> -#define COPYL_C(r1,r2,x,rc) 9: MOVSL(r1,r2,x) ; decl rc ; jnz 9b
> -#define COPYL(r1,r2,x) COPYL_C(r1,r2,x,%ecx)
> -
> -lzo1x_decompress:
> - pushl %ebp
> - pushl %edi
> - pushl %esi
> - pushl %ebx
> -
> - cld
> -
> - movl INP, %esi
> - movl OUTP, %edi
> - movl $3, %ebp
> -
> -
> - xorl %eax, %eax
> - xorl %ebx, %ebx /* high bits 9-32 stay 0 */
> - lodsb
> - cmpb $17, %al
> - jbe .L01
> - subb $17-NN, %al
> - jmp .LFLR
> -
> -
> -/***********************************************************************
> -// literal run
> -************************************************************************/
> -
> -0: addl N_255, %eax
> -1: movb (%esi), %bl
> - incl %esi
> - orb %bl, %bl
> - jz 0b
> - leal 18+NN(%eax,%ebx), %eax
> - jmp 3f
> -
> -
> -.L00:
> - LODSB
> -.L01:
> - cmpb $16, %al
> - jae .LMATCH
> -
> - /* a literal run */
> - orb %al, %al
> - jz 1b
> - addl $3+NN, %eax
> -3:
> -.LFLR:
> - movl %eax, %ecx
> - NOTL_3(%eax)
> - shrl $2, %ecx
> - andl N_3, %eax
> - COPYL(%esi,%edi,%edx)
> - subl %eax, %esi
> - subl %eax, %edi
> -
> - LODSB
> - cmpb $16, %al
> - jae .LMATCH
> -
> -
> -/***********************************************************************
> -// R1
> -************************************************************************/
> -
> - shrl $2, %eax
> - movb (%esi), %bl
> - leal -0x801(%edi), %edx
> - leal (%eax,%ebx,4), %eax
> - incl %esi
> - subl %eax, %edx
> - movl (%edx), %ecx
> - movl %ecx, (%edi)
> - addl N_3, %edi
> - jmp .LMDONE
> -
> -
> -/***********************************************************************
> -// M2
> -************************************************************************/
> -
> -.LMATCH:
> - cmpb $64, %al
> - jb .LM3MATCH
> -
> - /* a M2 match */
> - movl %eax, %ecx
> - shrl $2, %eax
> - leal -1(%edi), %edx
> - andl $7, %eax
> - movb (%esi), %bl
> - shrl $5, %ecx
> - leal (%eax,%ebx,8), %eax
> - incl %esi
> - subl %eax, %edx
> -
> - addl $1+3, %ecx
> -
> - cmpl N_3, %eax
> - jae .LCOPYLONG
> - jmp .LCOPYBYTE
> -
> -
> -/***********************************************************************
> -// M3
> -************************************************************************/
> -
> -0: addl N_255, %eax
> -1: movb (%esi), %bl
> - incl %esi
> - orb %bl, %bl
> - jz 0b
> - leal 33+NN(%eax,%ebx), %ecx
> - xorl %eax, %eax
> - jmp 3f
> -
> -
> -.LM3MATCH:
> - cmpb $32, %al
> - jb .LM4MATCH
> -
> - /* a M3 match */
> - andl $31, %eax
> - jz 1b
> - lea 2+NN(%eax), %ecx
> -3:
> - movw (%esi), %ax
> - leal -1(%edi), %edx
> - shrl $2, %eax
> - addl $2, %esi
> - subl %eax, %edx
> -
> - cmpl N_3, %eax
> - jb .LCOPYBYTE
> -
> -
> -/***********************************************************************
> -// copy match
> -************************************************************************/
> -
> -.LCOPYLONG: /* copy match using longwords */
> - leal -3(%edi,%ecx), %eax
> - shrl $2, %ecx
> - COPYL(%edx,%edi,%ebx)
> - movl %eax, %edi
> - xorl %ebx, %ebx
> -
> -.LMDONE:
> - movb -2(%esi), %al
> - andl N_3, %eax
> - jz .L00
> -.LFLR3:
> - movl (%esi), %edx
> - addl %eax, %esi
> - movl %edx, (%edi)
> - addl %eax, %edi
> -
> - LODSB
> - jmp .LMATCH
> -
> -
> -.LCOPYBYTE: /* copy match using bytes */
> - xchgl %edx,%esi
> - subl N_3,%ecx
> -
> - rep
> - movsb
> - movl %edx, %esi
> - jmp .LMDONE
> -
> -
> -/***********************************************************************
> -// M4
> -************************************************************************/
> -
> -0: addl N_255, %ecx
> -1: movb (%esi), %bl
> - incl %esi
> - orb %bl, %bl
> - jz 0b
> - leal 9+NN(%ebx,%ecx), %ecx
> - jmp 3f
> -
> -
> -.LM4MATCH:
> - cmpb $16, %al
> - jb .LM1MATCH
> -
> - /* a M4 match */
> - movl %eax, %ecx
> - andl $8, %eax
> - shll $13, %eax /* save in bit 16 */
> - andl $7, %ecx
> - jz 1b
> - addl $2+NN, %ecx
> -3:
> - movw (%esi), %ax
> - addl $2, %esi
> - leal -0x4000(%edi), %edx
> - shrl $2, %eax
> - jz .LEOF
> - subl %eax, %edx
> - jmp .LCOPYLONG
> -
> -
> -/***********************************************************************
> -// M1
> -************************************************************************/
> -
> -.LM1MATCH:
> - /* a M1 match */
> - shrl $2, %eax
> - movb (%esi), %bl
> - leal -1(%edi), %edx
> - leal (%eax,%ebx,4), %eax
> - incl %esi
> - subl %eax, %edx
> -
> - movb (%edx), %al /* we must use this because edx can be edi-1 */
> - movb %al, (%edi)
> - movb 1(%edx), %bl
> - movb %bl, 1(%edi)
> - addl $2, %edi
> - jmp .LMDONE
> -
> -
> -/***********************************************************************
> -//
> -************************************************************************/
> -
> -.LEOF:
> -/**** xorl %eax,%eax eax=0 from above */
> -
> - cmpl $3+NN, %ecx /* ecx must be 3/6 */
> - setnz %al
> -
> - /* check compressed size */
> - movl INP, %edx
> - addl INS, %edx
> - cmpl %edx, %esi /* check compressed size */
> - ja .L_input_overrun
> - jb .L_input_not_consumed
> -
> -.L_leave:
> - negl %eax
> - jnz 1f
> -
> - subl OUTP, %edi /* write back the uncompressed size */
> - movl %edi, %eax
> -
> -1: popl %ebx
> - popl %esi
> - popl %edi
> - popl %ebp
> - ret
> -
> -.L_input_not_consumed:
> - movl $8, %eax /* LZO_E_INPUT_NOT_CONSUMED */
> - jmp .L_leave
> -
> -.L_input_overrun:
> - movl $4, %eax /* LZO_E_INPUT_OVERRUN */
> - jmp .L_leave
> -
> -#undef INP
> -#undef INS
> -#undef OUTP
> -#undef NN
> -#undef NN
> -#undef N_3
> -#undef N_255
> -#undef LODSB
> -#undef NOTL_3
> -#undef MOVSL
> -#undef COPYL_C
> -#undef COPYL
> diff --git a/kern/i386/pc/startup.S b/kern/i386/pc/startup.S
> index 171fbea..be258fb 100644
> --- a/kern/i386/pc/startup.S
> +++ b/kern/i386/pc/startup.S
> @@ -210,20 +210,7 @@ codestart:
> incl %eax
> call EXT_C(grub_gate_a20)
>
> -#if defined(ENABLE_LZO)
> - /* decompress the compressed part and put the result at 1MB */
> - movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %esi
> - movl $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
> -
> - pushl %esi
> - pushl EXT_C(grub_compressed_size)
> - pushl %edi
> - call lzo1x_decompress
> - addl $12, %esp
> -
> - movl %eax, %ecx
> - cld
> -#elif defined(ENABLE_LZMA)
> +#ifdef ENABLE_LZMA
> movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
> movl $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi
> pushl %edi
> @@ -451,9 +438,7 @@ gate_a20_check_state:
> popl %ebx
> ret
>
> -#if defined(ENABLE_LZO)
> -#include "lzo1x.S"
> -#elif defined(ENABLE_LZMA)
> +#ifdef ENABLE_LZMA
> #include "lzma_decode.S"
> #endif
>
> diff --git a/util/i386/pc/grub-mkimage.c b/util/i386/pc/grub-mkimage.c
> index ee1af82..b81392c 100644
> --- a/util/i386/pc/grub-mkimage.c
> +++ b/util/i386/pc/grub-mkimage.c
> @@ -36,57 +36,9 @@
> #define _GNU_SOURCE 1
> #include <getopt.h>
>
> -#if defined(ENABLE_LZO)
> -
> -#if defined(HAVE_LZO_LZO1X_H)
> -# include <lzo/lzo1x.h>
> -#elif defined(HAVE_LZO1X_H)
> -# include <lzo1x.h>
> -#endif
> -
> -#elif defined(ENABLE_LZMA)
> -
> +#ifdef ENABLE_LZMA
> #include <grub/lib/LzmaEnc.h>
>
> -#endif
> -
> -#if defined(ENABLE_LZO)
> -
> -static void
> -compress_kernel (char *kernel_img, size_t kernel_size,
> - char **core_img, size_t *core_size)
> -{
> - lzo_uint size;
> - char *wrkmem;
> -
> - if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
> - grub_util_error ("the core image is too small");
> -
> - if (lzo_init () != LZO_E_OK)
> - grub_util_error ("cannot initialize LZO");
> -
> - *core_img = xmalloc (kernel_size + kernel_size / 64 + 16 + 3);
> - wrkmem = xmalloc (LZO1X_999_MEM_COMPRESS);
> -
> - memcpy (*core_img, kernel_img, GRUB_KERNEL_MACHINE_RAW_SIZE);
> -
> - grub_util_info ("compressing the core image");
> - if (lzo1x_999_compress ((const lzo_byte *) (kernel_img
> - + GRUB_KERNEL_MACHINE_RAW_SIZE),
> - kernel_size - GRUB_KERNEL_MACHINE_RAW_SIZE,
> - (lzo_byte *) (*core_img
> - + GRUB_KERNEL_MACHINE_RAW_SIZE),
> - &size, wrkmem)
> - != LZO_E_OK)
> - grub_util_error ("cannot compress the kernel image");
> -
> - free (wrkmem);
> -
> - *core_size = (size_t) size + GRUB_KERNEL_MACHINE_RAW_SIZE;
> -}
> -
> -#elif defined(ENABLE_LZMA)
> -
> static void *SzAlloc(void *p, size_t size) { p = p; return xmalloc(size); }
> static void SzFree(void *p, void *address) { p = p; free(address); }
> static ISzAlloc g_Alloc = { SzAlloc, SzFree };
> @@ -124,7 +76,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
> *core_size += GRUB_KERNEL_MACHINE_RAW_SIZE;
> }
>
> -#else
> +#else /* No lzma compression */
>
> static void
> compress_kernel (char *kernel_img, size_t kernel_size,
> @@ -135,7 +87,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
> *core_size = kernel_size;
> }
>
> -#endif
> +#endif /* No lzma compression */
>
> static void
> generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine
2009-07-16 16:24 ` Vladimir 'phcoder' Serbinenko
@ 2009-07-18 18:18 ` Robert Millan
2009-07-19 17:45 ` Pavel Roskin
0 siblings, 1 reply; 11+ messages in thread
From: Robert Millan @ 2009-07-18 18:18 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, Jul 16, 2009 at 06:24:14PM +0200, Vladimir 'phcoder' Serbinenko wrote:
> On Thu, Jul 16, 2009 at 1:40 AM, Pavel Roskin<proski@gnu.org> wrote:
> > ChangeLog:
> >
> > * Makefile.in: Remove LIBLZO and enable_lzo.
> > * conf/i386-pc.rmk: Remove lzo support.
> > * configure.ac: Remove checks for lzo, don't define ENABLE_LZMA.
> > * include/grub/i386/pc/kernel.h: Define ENABLE_LZMA. Remove lzo
> > support.
> > * kern/i386/pc/lzo1x.S: Remove.
> > * kern/i386/pc/startup.S: Remove lzo support.
> > * util/i386/pc/grub-mkimage.c: Likewise.
> Is there a reason to remove lzo? I know that lzma performs much better
> in terms of compression but afaik lzo doesn't create any problems nor
> is compiled by default
It doesn't break things, since it's barely modified, and doesn't interact with
the rest of the code, but simply having more code means an added work to
maintain it when we restructure things, etc. It needs to pay off in some way.
> and may be desirable for some users
Can you give an example?
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine
2009-07-18 18:18 ` Robert Millan
@ 2009-07-19 17:45 ` Pavel Roskin
2009-07-19 18:24 ` Vladimir 'phcoder' Serbinenko
0 siblings, 1 reply; 11+ messages in thread
From: Pavel Roskin @ 2009-07-19 17:45 UTC (permalink / raw)
To: The development of GRUB 2
On Sat, 2009-07-18 at 20:18 +0200, Robert Millan wrote:
> It doesn't break things, since it's barely modified, and doesn't interact with
> the rest of the code, but simply having more code means an added work to
> maintain it when we restructure things, etc. It needs to pay off in some way.
Exactly.
Actually, my intention was to improve test coverage. To test lzma and
lzo, GRUB needs to be compiled twice.
If we want to support MacOS compilation properly (I mean local labels),
we'll need to adjust both lzma and lzo.
Extra code means more development time wasted on mostly unused code.
There then there is an issue of user choice. I think we are offering
too many choices without explaining what's behind it.
I could say lzo is "old and proven" and lzma is "new and more
effective", but since lzo is disabled by default and there are no
complaints about it, keeping lzo becomes pointless.
I don't think we are going to see compression much more effecting than
lzma to justify keeping the infrastructure for more than one compression
algorithm.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine
2009-07-19 17:45 ` Pavel Roskin
@ 2009-07-19 18:24 ` Vladimir 'phcoder' Serbinenko
2009-07-19 20:33 ` Pavel Roskin
0 siblings, 1 reply; 11+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-07-19 18:24 UTC (permalink / raw)
To: The development of GRUB 2
> There then there is an issue of user choice. I think we are offering
> too many choices without explaining what's behind it.
>
> I could say lzo is "old and proven" and lzma is "new and more
> effective", but since lzo is disabled by default and there are no
> complaints about it, keeping lzo becomes pointless.
lzo is faster than lzma but I did a small count and seen that
decompression time is around 10 ms on 31 KiB image on slow computer.
Difference of few ms doesn't pay off
>
> I don't think we are going to see compression much more effecting than
> lzma to justify keeping the infrastructure for more than one compression
> algorithm.
Now I agree with you. No further oppositions from me
>
> --
> Regards,
> Pavel Roskin
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] Introduce grub_malloc0()
2009-07-15 23:40 [PATCH 1/2] Introduce grub_malloc0() Pavel Roskin
2009-07-15 23:40 ` [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine Pavel Roskin
@ 2009-07-16 15:22 ` Vladimir 'phcoder' Serbinenko
2009-07-16 15:41 ` Pavel Roskin
1 sibling, 1 reply; 11+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-07-16 15:22 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, Jul 16, 2009 at 1:40 AM, Pavel Roskin<proski@gnu.org> wrote:
> Even though it's a new function added to the core, its use makes
> core.img smaller. And it makes modules smaller too.
I like the idea even if function name is inexplicit. Do you have a
better alterative?
>
> ChangeLog:
>
> * kern/mm.c (grub_malloc0): New function.
> (grub_debug_malloc0): Likewise.
> * include/grub/mm.h: Declare grub_malloc0() and
> grub_debug_malloc0().
> * util/misc.c (grub_malloc0): New function.
> * bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_malloc0()
> instead of grub_malloc(), remove unneeded initializations.
> * bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise.
> * commands/extcmd.c (grub_extcmd_dispatcher): Likewise.
> * commands/parttool.c (grub_cmd_parttool): Likewise.
> * disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise.
> * disk/raid5_recover.c (grub_raid5_recover): Likewise.
> * disk/raid6_recover.c (grub_raid6_recover): Likewise.
> * disk/usbms.c (grub_usbms_finddevs): Likewise.
> * efiemu/mm.c (grub_efiemu_request_memalign): Likewise.
> * efiemu/pnvram.c (grub_efiemu_pnvram): Likewise.
> (grub_cmd_efiemu_pnvram): Likewise.
> * fs/i386/pc/pxe.c (grub_pxefs_open): Likewise.
> * fs/iso9660.c (grub_iso9660_mount): Likewise.
> (grub_iso9660_iterate_dir): Likewise.
> * fs/jfs.c (grub_jfs_opendir): Likewise.
> * fs/ntfs.c (list_file): Likewise.
> (grub_ntfs_mount): Likewise.
> * kern/disk.c (grub_disk_open): Likewise.
> * kern/dl.c (grub_dl_load_core): Likewise.
> * kern/elf.c (grub_elf_file): Likewise.
> * kern/env.c (grub_env_context_open): Likewise.
> (grub_env_set): Likewise.
> (grub_env_set_data_slot): Likewise.
> * kern/file.c (grub_file_open): Likewise.
> * kern/fs.c (grub_fs_blocklist_open): Likewise.
> * loader/i386/multiboot.c (grub_module): Likewise.
> * loader/xnu.c (grub_xnu_create_key): Likewise.
> (grub_xnu_create_value): Likewise.
> * normal/main.c (grub_normal_add_menu_entry): Likewise.
> (read_config_file): Likewise.
> * normal/menu_entry.c (make_screen): Likewise.
> * partmap/sun.c (sun_partition_map_iterate): Likewise.
> * script/sh/lexer.c (grub_script_lexer_init): Likewise.
> * script/sh/script.c (grub_script_parse): Likewise.
> * video/bitmap.c (grub_video_bitmap_create): Likewise.
> * video/readers/jpeg.c (grub_video_reader_jpeg): Likewise.
> * video/readers/png.c (grub_png_output_byte): Likewise.
> (grub_video_reader_png): Likewise.
> ---
> bus/usb/uhci.c | 5 +----
> bus/usb/usbhub.c | 4 +---
> commands/extcmd.c | 3 +--
> commands/parttool.c | 7 ++-----
> disk/i386/pc/biosdisk.c | 3 +--
> disk/raid5_recover.c | 4 +---
> disk/raid6_recover.c | 7 ++-----
> disk/usbms.c | 4 +---
> efiemu/mm.c | 4 +---
> efiemu/pnvram.c | 6 ++----
> fs/i386/pc/pxe.c | 3 +--
> fs/iso9660.c | 7 ++-----
> fs/jfs.c | 4 +---
> fs/ntfs.c | 7 ++-----
> include/grub/mm.h | 6 ++++++
> kern/disk.c | 6 +-----
> kern/dl.c | 7 +------
> kern/elf.c | 3 +--
> kern/env.c | 11 +++--------
> kern/file.c | 5 +----
> kern/fs.c | 5 +----
> kern/mm.c | 27 +++++++++++++++++++++++++++
> loader/i386/multiboot.c | 3 +--
> loader/xnu.c | 7 ++-----
> normal/main.c | 14 ++++----------
> normal/menu_entry.c | 9 +--------
> partmap/sun.c | 4 +---
> script/sh/lexer.c | 11 +----------
> script/sh/script.c | 7 +------
> util/misc.c | 10 ++++++++++
> video/bitmap.c | 5 +----
> video/readers/jpeg.c | 3 +--
> video/readers/png.c | 6 ++----
> 33 files changed, 85 insertions(+), 132 deletions(-)
>
> diff --git a/bus/usb/uhci.c b/bus/usb/uhci.c
> index 84cd48d..f902488 100644
> --- a/bus/usb/uhci.c
> +++ b/bus/usb/uhci.c
> @@ -170,14 +170,11 @@ grub_uhci_pci_iter (int bus, int device, int func,
> return 0;
>
> /* Allocate memory for the controller and register it. */
> - u = grub_malloc (sizeof (*u));
> + u = grub_malloc0 (sizeof (*u));
> if (! u)
> return 1;
>
> u->iobase = base & GRUB_UHCI_IOMASK;
> - u->framelist = 0;
> - u->qh = 0;
> - u->td = 0;
> grub_dprintf ("uhci", "class=0x%02x 0x%02x interface 0x%02x base=0x%x\n",
> class, subclass, interf, u->iobase);
>
> diff --git a/bus/usb/usbhub.c b/bus/usb/usbhub.c
> index ba0925a..336d657 100644
> --- a/bus/usb/usbhub.c
> +++ b/bus/usb/usbhub.c
> @@ -33,13 +33,11 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
> grub_usb_device_t dev;
> int i;
>
> - dev = grub_malloc (sizeof (struct grub_usb_device));
> + dev = grub_malloc0 (sizeof (struct grub_usb_device));
> if (! dev)
> return NULL;
>
> dev->controller = *controller;
> - dev->addr = 0;
> - dev->initialized = 0;
> dev->speed = speed;
>
> grub_usb_device_initialize (dev);
> diff --git a/commands/extcmd.c b/commands/extcmd.c
> index a605387..2e0d993 100644
> --- a/commands/extcmd.c
> +++ b/commands/extcmd.c
> @@ -40,8 +40,7 @@ grub_extcmd_dispatcher (struct grub_command *cmd,
> maxargs++;
>
> /* Set up the option state. */
> - state = grub_malloc (sizeof (struct grub_arg_list) * maxargs);
> - grub_memset (state, 0, sizeof (struct grub_arg_list) * maxargs);
> + state = grub_malloc0 (sizeof (struct grub_arg_list) * maxargs);
>
> if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc))
> {
> diff --git a/commands/parttool.c b/commands/parttool.c
> index c807f06..7e72791 100644
> --- a/commands/parttool.c
> +++ b/commands/parttool.c
> @@ -242,8 +242,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
> if (grub_strcmp (args[i], "help") == 0)
> return show_help ();
>
> - parsed = (int *) grub_malloc (argc * sizeof (int));
> - grub_memset (parsed, 0, argc * sizeof (int));
> + parsed = (int *) grub_malloc0 (argc * sizeof (int));
>
> for (i = 1; i < argc; i++)
> if (! parsed[i])
> @@ -272,9 +271,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
> args[i]);
> ptool = cur;
> pargs = (struct grub_parttool_args *)
> - grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
> - grub_memset (pargs, 0,
> - ptool->nargs * sizeof (struct grub_parttool_args));
> + grub_malloc0 (ptool->nargs * sizeof (struct grub_parttool_args));
> for (j = i; j < argc; j++)
> if (! parsed[j])
> {
> diff --git a/disk/i386/pc/biosdisk.c b/disk/i386/pc/biosdisk.c
> index 09f0ce7..a71a8f4 100644
> --- a/disk/i386/pc/biosdisk.c
> +++ b/disk/i386/pc/biosdisk.c
> @@ -109,12 +109,11 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
> disk->has_partitions = ((drive & 0x80) && (drive != cd_drive));
> disk->id = drive;
>
> - data = (struct grub_biosdisk_data *) grub_malloc (sizeof (*data));
> + data = (struct grub_biosdisk_data *) grub_malloc0 (sizeof (*data));
> if (! data)
> return grub_errno;
>
> data->drive = drive;
> - data->flags = 0;
>
> if ((cd_drive) && (drive == cd_drive))
> {
> diff --git a/disk/raid5_recover.c b/disk/raid5_recover.c
> index 31cef88..e4f1f78 100644
> --- a/disk/raid5_recover.c
> +++ b/disk/raid5_recover.c
> @@ -32,12 +32,10 @@ grub_raid5_recover (struct grub_raid_array *array, int disknr,
> int i;
>
> size <<= GRUB_DISK_SECTOR_BITS;
> - buf2 = grub_malloc (size);
> + buf2 = grub_malloc0 (size);
> if (!buf2)
> return grub_errno;
>
> - grub_memset (buf, 0, size);
> -
> for (i = 0; i < (int) array->total_devs; i++)
> {
> grub_err_t err;
> diff --git a/disk/raid6_recover.c b/disk/raid6_recover.c
> index 3a994af..0b7242c 100644
> --- a/disk/raid6_recover.c
> +++ b/disk/raid6_recover.c
> @@ -96,11 +96,11 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
> char *pbuf = 0, *qbuf = 0;
>
> size <<= GRUB_DISK_SECTOR_BITS;
> - pbuf = grub_malloc (size);
> + pbuf = grub_malloc0 (size);
> if (!pbuf)
> goto quit;
>
> - qbuf = grub_malloc (size);
> + qbuf = grub_malloc0 (size);
> if (!qbuf)
> goto quit;
>
> @@ -108,9 +108,6 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
> if (q == (int) array->total_devs)
> q = 0;
>
> - grub_memset (pbuf, 0, size);
> - grub_memset (qbuf, 0, size);
> -
> pos = q + 1;
> if (pos == (int) array->total_devs)
> pos = 0;
> diff --git a/disk/usbms.c b/disk/usbms.c
> index 3c7ebaf..4c5e216 100644
> --- a/disk/usbms.c
> +++ b/disk/usbms.c
> @@ -107,14 +107,12 @@ grub_usbms_finddevs (void)
> }
>
> devcnt++;
> - usbms = grub_malloc (sizeof (struct grub_usbms_dev));
> + usbms = grub_malloc0 (sizeof (struct grub_usbms_dev));
> if (! usbms)
> return 1;
>
> usbms->dev = usbdev;
> usbms->interface = i;
> - usbms->in = NULL;
> - usbms->out = NULL;
>
> /* Iterate over all endpoints of this interface, at least a
> IN and OUT bulk endpoint are required. */
> diff --git a/efiemu/mm.c b/efiemu/mm.c
> index 7d6a5d4..290ca11 100644
> --- a/efiemu/mm.c
> +++ b/efiemu/mm.c
> @@ -104,14 +104,12 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
> requested_memory[type] += align_overhead + size;
>
> /* Remember the request */
> - ret = grub_malloc (sizeof (*ret));
> + ret = grub_malloc0 (sizeof (*ret));
> if (!ret)
> return -1;
> ret->type = type;
> ret->size = size;
> ret->align_overhead = align_overhead;
> - ret->val = 0;
> - ret->next = 0;
> prev = 0;
>
> /* Add request to the end of the chain.
> diff --git a/efiemu/pnvram.c b/efiemu/pnvram.c
> index d5daaab..21f7d93 100644
> --- a/efiemu/pnvram.c
> +++ b/efiemu/pnvram.c
> @@ -339,11 +339,10 @@ grub_efiemu_pnvram (void)
> accuracy = 50000000;
> daylight = 0;
>
> - nvram = grub_malloc (nvramsize);
> + nvram = grub_malloc0 (nvramsize);
> if (!nvram)
> return grub_error (GRUB_ERR_OUT_OF_MEMORY,
> "Couldn't allocate space for temporary pnvram storage");
> - grub_memset (nvram, 0, nvramsize);
>
> return grub_efiemu_make_nvram ();
> }
> @@ -365,11 +364,10 @@ grub_cmd_efiemu_pnvram (struct grub_extcmd *cmd,
> accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000;
> daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0;
>
> - nvram = grub_malloc (nvramsize);
> + nvram = grub_malloc0 (nvramsize);
> if (!nvram)
> return grub_error (GRUB_ERR_OUT_OF_MEMORY,
> "Couldn't allocate space for temporary pnvram storage");
> - grub_memset (nvram, 0, nvramsize);
>
> if (argc == 1 && (err = read_pnvram (args[0])))
> {
> diff --git a/fs/i386/pc/pxe.c b/fs/i386/pc/pxe.c
> index 1fc5680..5ee5fb7 100644
> --- a/fs/i386/pc/pxe.c
> +++ b/fs/i386/pc/pxe.c
> @@ -146,11 +146,10 @@ grub_pxefs_open (struct grub_file *file, const char *name)
> if (c.c2.status)
> return grub_error (GRUB_ERR_BAD_FS, "open fails");
>
> - data = grub_malloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
> + data = grub_malloc0 (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
> if (! data)
> return grub_errno;
>
> - data->packet_number = 0;
> data->block_size = grub_pxe_blksize;
> grub_strcpy (data->filename, name);
>
> diff --git a/fs/iso9660.c b/fs/iso9660.c
> index c79ad4f..6e5c3a9 100644
> --- a/fs/iso9660.c
> +++ b/fs/iso9660.c
> @@ -263,13 +263,11 @@ grub_iso9660_mount (grub_disk_t disk)
> return 0;
> }
>
> - data = grub_malloc (sizeof (struct grub_iso9660_data));
> + data = grub_malloc0 (sizeof (struct grub_iso9660_data));
> if (! data)
> return 0;
>
> data->disk = disk;
> - data->rockridge = 0;
> - data->joliet = 0;
>
> block = 16;
> do
> @@ -509,8 +507,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
> else
> {
> size = entry->len - 5;
> - filename = grub_malloc (size + 1);
> - filename[0] = '\0';
> + filename = grub_malloc0 (size + 1);
> }
> filename_alloc = 1;
> grub_strncpy (filename, (char *) &entry->data[1], size);
> diff --git a/fs/jfs.c b/fs/jfs.c
> index 4f91825..fae2800 100644
> --- a/fs/jfs.c
> +++ b/fs/jfs.c
> @@ -382,11 +382,10 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
> return 0;
> }
>
> - diro = grub_malloc (sizeof (struct grub_jfs_diropen));
> + diro = grub_malloc0 (sizeof (struct grub_jfs_diropen));
> if (!diro)
> return 0;
>
> - diro->index = 0;
> diro->data = data;
> diro->inode = inode;
>
> @@ -397,7 +396,6 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
> diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
> diro->sorted = (char *) (inode->dir.header.sorted);
> diro->count = inode->dir.header.count;
> - diro->dirpage = 0;
>
> return diro;
> }
> diff --git a/fs/ntfs.c b/fs/ntfs.c
> index c312b8b..bcbbdae 100644
> --- a/fs/ntfs.c
> +++ b/fs/ntfs.c
> @@ -601,11 +601,10 @@ list_file (struct grub_ntfs_file *diro, char *pos,
> (u32at (pos, 0x48) & ATTR_DIRECTORY) ? GRUB_FSHELP_DIR :
> GRUB_FSHELP_REG;
>
> - fdiro = grub_malloc (sizeof (struct grub_ntfs_file));
> + fdiro = grub_malloc0 (sizeof (struct grub_ntfs_file));
> if (!fdiro)
> return 0;
>
> - grub_memset (fdiro, 0, sizeof (*fdiro));
> fdiro->data = diro->data;
> fdiro->ino = u32at (pos, 0);
>
> @@ -791,12 +790,10 @@ grub_ntfs_mount (grub_disk_t disk)
> if (!disk)
> goto fail;
>
> - data = (struct grub_ntfs_data *) grub_malloc (sizeof (*data));
> + data = (struct grub_ntfs_data *) grub_malloc0 (sizeof (*data));
> if (!data)
> goto fail;
>
> - grub_memset (data, 0, sizeof (*data));
> -
> data->disk = disk;
>
> /* Read the BPB. */
> diff --git a/include/grub/mm.h b/include/grub/mm.h
> index 4dd1363..413e439 100644
> --- a/include/grub/mm.h
> +++ b/include/grub/mm.h
> @@ -30,6 +30,7 @@
>
> void grub_mm_init_region (void *addr, grub_size_t size);
> void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
> +void *EXPORT_FUNC(grub_malloc0) (grub_size_t size);
> void EXPORT_FUNC(grub_free) (void *ptr);
> void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
> void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
> @@ -45,6 +46,9 @@ void grub_mm_dump (unsigned lineno);
> #define grub_malloc(size) \
> grub_debug_malloc (__FILE__, __LINE__, size)
>
> +#define grub_malloc0(size) \
> + grub_debug_malloc0 (__FILE__, __LINE__, size)
> +
> #define grub_realloc(ptr,size) \
> grub_debug_realloc (__FILE__, __LINE__, ptr, size)
>
> @@ -56,6 +60,8 @@ void grub_mm_dump (unsigned lineno);
>
> void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
> grub_size_t size);
> +void *EXPORT_FUNC(grub_debug_malloc0) (const char *file, int line,
> + grub_size_t size);
> void EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
> void *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
> grub_size_t size);
> diff --git a/kern/disk.c b/kern/disk.c
> index e167fb6..d1e3da3 100644
> --- a/kern/disk.c
> +++ b/kern/disk.c
> @@ -244,14 +244,10 @@ grub_disk_open (const char *name)
>
> grub_dprintf ("disk", "Opening `%s'...\n", name);
>
> - disk = (grub_disk_t) grub_malloc (sizeof (*disk));
> + disk = (grub_disk_t) grub_malloc0 (sizeof (*disk));
> if (! disk)
> return 0;
>
> - disk->dev = 0;
> - disk->read_hook = 0;
> - disk->partition = 0;
> - disk->data = 0;
> disk->name = grub_strdup (name);
> if (! disk->name)
> goto fail;
> diff --git a/kern/dl.c b/kern/dl.c
> index 122b6b9..ad6fc49 100644
> --- a/kern/dl.c
> +++ b/kern/dl.c
> @@ -535,16 +535,11 @@ grub_dl_load_core (void *addr, grub_size_t size)
> return 0;
> }
>
> - mod = (grub_dl_t) grub_malloc (sizeof (*mod));
> + mod = (grub_dl_t) grub_malloc0 (sizeof (*mod));
> if (! mod)
> return 0;
>
> - mod->name = 0;
> mod->ref_count = 1;
> - mod->dep = 0;
> - mod->segment = 0;
> - mod->init = 0;
> - mod->fini = 0;
>
> grub_dprintf ("modules", "relocating to %p\n", mod);
> if (grub_dl_resolve_name (mod, e)
> diff --git a/kern/elf.c b/kern/elf.c
> index 2590552..a9f4649 100644
> --- a/kern/elf.c
> +++ b/kern/elf.c
> @@ -61,12 +61,11 @@ grub_elf_file (grub_file_t file)
> {
> grub_elf_t elf;
>
> - elf = grub_malloc (sizeof (*elf));
> + elf = grub_malloc0 (sizeof (*elf));
> if (! elf)
> return 0;
>
> elf->file = file;
> - elf->phdrs = 0;
>
> if (grub_file_seek (elf->file, 0) == (grub_off_t) -1)
> goto fail;
> diff --git a/kern/env.c b/kern/env.c
> index e85627b..faca4c0 100644
> --- a/kern/env.c
> +++ b/kern/env.c
> @@ -80,11 +80,10 @@ grub_env_context_open (int export)
> struct grub_env_context *context;
> int i;
>
> - context = grub_malloc (sizeof (*context));
> + context = grub_malloc0 (sizeof (*context));
> if (! context)
> return grub_errno;
>
> - grub_memset (context, 0, sizeof (*context));
> context->prev = current_context;
> current_context = context;
>
> @@ -204,12 +203,10 @@ grub_env_set (const char *name, const char *val)
> }
>
> /* The variable does not exist, so create a new one. */
> - var = grub_malloc (sizeof (*var));
> + var = grub_malloc0 (sizeof (*var));
> if (! var)
> return grub_errno;
>
> - grub_memset (var, 0, sizeof (*var));
> -
> /* This is not necessary, because GRUB_ENV_VAR_LOCAL == 0. But leave
> this for readability. */
> var->type = GRUB_ENV_VAR_LOCAL;
> @@ -379,12 +376,10 @@ grub_env_set_data_slot (const char *name, const void *ptr)
> }
>
> /* The variable does not exist, so create a new one. */
> - var = grub_malloc (sizeof (*var));
> + var = grub_malloc0 (sizeof (*var));
> if (! var)
> goto fail;
>
> - grub_memset (var, 0, sizeof (*var));
> -
> var->type = GRUB_ENV_VAR_DATA;
> var->name = mangled_name;
> var->value = (char *) ptr;
> diff --git a/kern/file.c b/kern/file.c
> index 5d5e640..2d7d967 100644
> --- a/kern/file.c
> +++ b/kern/file.c
> @@ -75,14 +75,11 @@ grub_file_open (const char *name)
> if (! device)
> goto fail;
>
> - file = (grub_file_t) grub_malloc (sizeof (*file));
> + file = (grub_file_t) grub_malloc0 (sizeof (*file));
> if (! file)
> goto fail;
>
> file->device = device;
> - file->offset = 0;
> - file->data = 0;
> - file->read_hook = 0;
>
> if (device->disk && file_name[0] != '/')
> /* This is a block list. */
> diff --git a/kern/fs.c b/kern/fs.c
> index c8f4970..f17347e 100644
> --- a/kern/fs.c
> +++ b/kern/fs.c
> @@ -161,7 +161,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
> while (p);
>
> /* Allocate a block list. */
> - blocks = grub_malloc (sizeof (struct grub_fs_block) * (num + 1));
> + blocks = grub_malloc0 (sizeof (struct grub_fs_block) * (num + 1));
> if (! blocks)
> return 0;
>
> @@ -179,8 +179,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
> goto fail;
> }
> }
> - else
> - blocks[i].offset = 0;
>
> p++;
> blocks[i].length = grub_strtoul (p, &p, 0);
> @@ -203,7 +201,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
> p++;
> }
>
> - blocks[i].length = 0;
> file->data = blocks;
>
> return GRUB_ERR_NONE;
> diff --git a/kern/mm.c b/kern/mm.c
> index 9a0ae56..a07bd42 100644
> --- a/kern/mm.c
> +++ b/kern/mm.c
> @@ -68,6 +68,7 @@
>
> #ifdef MM_DEBUG
> # undef grub_malloc
> +# undef grub_malloc0
> # undef grub_realloc
> # undef grub_free
> # undef grub_memalign
> @@ -348,6 +349,19 @@ grub_malloc (grub_size_t size)
> return grub_memalign (0, size);
> }
>
> +/* Allocate SIZE bytes, clear them and return the pointer. */
> +void *
> +grub_malloc0 (grub_size_t size)
> +{
> + void *ret;
> +
> + ret = grub_memalign (0, size);
> + if (ret)
> + grub_memset (ret, 0, size);
> +
> + return ret;
> +}
> +
> /* Deallocate the pointer PTR. */
> void
> grub_free (void *ptr)
> @@ -522,6 +536,19 @@ grub_debug_malloc (const char *file, int line, grub_size_t size)
> return ptr;
> }
>
> +void *
> +grub_debug_malloc0 (const char *file, int line, grub_size_t size)
> +{
> + void *ptr;
> +
> + if (grub_mm_debug)
> + grub_printf ("%s:%d: malloc0 (0x%zx) = ", file, line, size);
> + ptr = grub_malloc0 (size);
> + if (grub_mm_debug)
> + grub_printf ("%p\n", ptr);
> + return ptr;
> +}
> +
> void
> grub_debug_free (const char *file, int line, void *ptr)
> {
> diff --git a/loader/i386/multiboot.c b/loader/i386/multiboot.c
> index 8ce315e..7e9ac66 100644
> --- a/loader/i386/multiboot.c
> +++ b/loader/i386/multiboot.c
> @@ -456,13 +456,12 @@ grub_module (int argc, char *argv[])
> }
> else
> {
> - struct grub_mod_list *modlist = grub_malloc (sizeof (struct grub_mod_list));
> + struct grub_mod_list *modlist = grub_malloc0 (sizeof (struct grub_mod_list));
> if (! modlist)
> goto fail;
> modlist->mod_start = (grub_uint32_t) module;
> modlist->mod_end = (grub_uint32_t) module + size;
> modlist->cmdline = (grub_uint32_t) cmdline;
> - modlist->pad = 0;
> mbi->mods_count = 1;
> mbi->mods_addr = (grub_uint32_t) modlist;
> mbi->flags |= MULTIBOOT_INFO_MODS;
> diff --git a/loader/xnu.c b/loader/xnu.c
> index b2c6c05..0861b83 100644
> --- a/loader/xnu.c
> +++ b/loader/xnu.c
> @@ -278,7 +278,7 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
> ret = grub_xnu_find_key (*parent, name);
> if (ret)
> return ret;
> - ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
> + ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
> if (! ret)
> {
> grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create key %s", name);
> @@ -292,7 +292,6 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
> return 0;
> }
> ret->datasize = -1;
> - ret->first_child = 0;
> ret->next = *parent;
> *parent = ret;
> return ret;
> @@ -313,7 +312,7 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
> ret->data = 0;
> return ret;
> }
> - ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
> + ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
> if (! ret)
> {
> grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
> @@ -326,8 +325,6 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
> grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
> return 0;
> }
> - ret->datasize = 0;
> - ret->data = 0;
> ret->next = *parent;
> *parent = ret;
> return ret;
> diff --git a/normal/main.c b/normal/main.c
> index 7f6336e..878b947 100644
> --- a/normal/main.c
> +++ b/normal/main.c
> @@ -166,11 +166,9 @@ grub_normal_add_menu_entry (int argc, const char **args,
> struct grub_menu_entry_class *classes_tail;
>
> /* Allocate dummy head node for class list. */
> - classes_head = grub_malloc (sizeof (struct grub_menu_entry_class));
> + classes_head = grub_malloc0 (sizeof (struct grub_menu_entry_class));
> if (! classes_head)
> return grub_errno;
> - classes_head->name = 0;
> - classes_head->next = 0;
> classes_tail = classes_head;
>
> menu = grub_env_get_data_slot ("menu");
> @@ -206,7 +204,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
> }
>
> /* Create a new class and add it at the tail of the list. */
> - new_class = grub_malloc (sizeof (struct grub_menu_entry_class));
> + new_class = grub_malloc0 (sizeof (struct grub_menu_entry_class));
> if (! new_class)
> {
> grub_free (class_name);
> @@ -215,7 +213,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
> }
> /* Fill in the new class node. */
> new_class->name = class_name;
> - new_class->next = 0;
> /* Link the tail to it, and make it the new tail. */
> classes_tail->next = new_class;
> classes_tail = new_class;
> @@ -267,7 +264,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
> while (*last)
> last = &(*last)->next;
>
> - *last = grub_malloc (sizeof (**last));
> + *last = grub_malloc0 (sizeof (**last));
> if (! *last)
> {
> free_menu_entry_classes (classes_head);
> @@ -278,7 +275,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
>
> (*last)->title = menutitle;
> (*last)->classes = classes_head;
> - (*last)->next = 0;
> (*last)->sourcecode = menusourcecode;
>
> menu->size++;
> @@ -346,11 +342,9 @@ read_config_file (const char *config)
> newmenu = grub_env_get_data_slot ("menu");
> if (! newmenu)
> {
> - newmenu = grub_malloc (sizeof (*newmenu));
> + newmenu = grub_malloc0 (sizeof (*newmenu));
> if (! newmenu)
> return 0;
> - newmenu->size = 0;
> - newmenu->entry_list = 0;
>
> grub_env_set_data_slot ("menu", newmenu);
> }
> diff --git a/normal/menu_entry.c b/normal/menu_entry.c
> index 86e581e..86cad0a 100644
> --- a/normal/menu_entry.c
> +++ b/normal/menu_entry.c
> @@ -416,18 +416,11 @@ make_screen (grub_menu_entry_t entry)
> struct screen *screen;
>
> /* Initialize the screen. */
> - screen = grub_malloc (sizeof (*screen));
> + screen = grub_malloc0 (sizeof (*screen));
> if (! screen)
> return 0;
>
> screen->num_lines = 1;
> - screen->column = 0;
> - screen->real_column = 0;
> - screen->line = 0;
> - screen->x = 0;
> - screen->y = 0;
> - screen->killed_text = 0;
> - screen->completion_shown = 0;
> screen->lines = grub_malloc (sizeof (struct line));
> if (! screen->lines)
> goto fail;
> diff --git a/partmap/sun.c b/partmap/sun.c
> index 6094777..e442ff7 100644
> --- a/partmap/sun.c
> +++ b/partmap/sun.c
> @@ -95,12 +95,10 @@ sun_partition_map_iterate (grub_disk_t disk,
> raw = *disk;
> raw.partition = 0;
>
> - p = (grub_partition_t) grub_malloc (sizeof (struct grub_partition));
> + p = (grub_partition_t) grub_malloc0 (sizeof (struct grub_partition));
> if (! p)
> return grub_errno;
>
> - p->offset = 0;
> - p->data = 0;
> p->partmap = &grub_sun_partition_map;
> if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block),
> &block) == GRUB_ERR_NONE)
> diff --git a/script/sh/lexer.c b/script/sh/lexer.c
> index 17f18e2..cbc33d7 100644
> --- a/script/sh/lexer.c
> +++ b/script/sh/lexer.c
> @@ -49,22 +49,13 @@ grub_script_lexer_init (char *script, grub_reader_getline_t getline)
> {
> struct grub_lexer_param *param;
>
> - param = grub_malloc (sizeof (*param));
> + param = grub_malloc0 (sizeof (*param));
> if (! param)
> return 0;
>
> param->state = GRUB_PARSER_STATE_TEXT;
> param->getline = getline;
> - param->refs = 0;
> - param->done = 0;
> - param->newscript = 0;
> param->script = script;
> - param->record = 0;
> - param->recording = 0;
> - param->recordpos = 0;
> - param->recordlen = 0;
> - param->tokenonhold = 0;
> - param->was_newline = 0;
>
> return param;
> }
> diff --git a/script/sh/script.c b/script/sh/script.c
> index 89fa947..3019cd7 100644
> --- a/script/sh/script.c
> +++ b/script/sh/script.c
> @@ -304,15 +304,10 @@ grub_script_parse (char *script, grub_reader_getline_t getline)
> if (! parsed)
> return 0;
>
> - parsestate = grub_malloc (sizeof (*parsestate));
> + parsestate = grub_malloc0 (sizeof (*parsestate));
> if (! parsestate)
> return 0;
>
> - parsestate->err = 0;
> - parsestate->func_mem = 0;
> - parsestate->memused = 0;
> - parsestate->parsed = 0;
> -
> /* Initialize the lexer. */
> lexstate = grub_script_lexer_init (script, getline);
> if (! lexstate)
> diff --git a/util/misc.c b/util/misc.c
> index f615a42..19a4244 100644
> --- a/util/misc.c
> +++ b/util/misc.c
> @@ -257,6 +257,16 @@ grub_malloc (grub_size_t size)
> return xmalloc (size);
> }
>
> +void *
> +grub_malloc0 (grub_size_t size)
> +{
> + void *ret;
> +
> + ret = xmalloc (size);
> + memset (ret, 0, size);
> + return ret;
> +}
> +
> void
> grub_free (void *ptr)
> {
> diff --git a/video/bitmap.c b/video/bitmap.c
> index d399fd7..009d3e4 100644
> --- a/video/bitmap.c
> +++ b/video/bitmap.c
> @@ -137,7 +137,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
> /* Calculate size needed for the data. */
> size = (width * mode_info->bytes_per_pixel) * height;
>
> - (*bitmap)->data = grub_malloc (size);
> + (*bitmap)->data = grub_malloc0 (size);
> if (! (*bitmap)->data)
> {
> grub_free (*bitmap);
> @@ -146,9 +146,6 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
> return grub_errno;
> }
>
> - /* Clear bitmap. */
> - grub_memset ((*bitmap)->data, 0, size);
> -
> return GRUB_ERR_NONE;
> }
>
> diff --git a/video/readers/jpeg.c b/video/readers/jpeg.c
> index b64bf3f..076f6fd 100644
> --- a/video/readers/jpeg.c
> +++ b/video/readers/jpeg.c
> @@ -667,12 +667,11 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
> if (!file)
> return grub_errno;
>
> - data = grub_malloc (sizeof (*data));
> + data = grub_malloc0 (sizeof (*data));
> if (data != NULL)
> {
> int i;
>
> - grub_memset (data, 0, sizeof (*data));
> data->file = file;
> data->bitmap = bitmap;
> grub_jpeg_decode_jpeg (data);
> diff --git a/video/readers/png.c b/video/readers/png.c
> index 733fa73..3ae8fb2 100644
> --- a/video/readers/png.c
> +++ b/video/readers/png.c
> @@ -543,11 +543,10 @@ grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n)
>
> if (data->first_line)
> {
> - blank_line = grub_malloc (row_bytes);
> + blank_line = grub_malloc0 (row_bytes);
> if (blank_line == NULL)
> return grub_errno;
>
> - grub_memset (blank_line, 0, row_bytes);
> up = blank_line;
> }
> else
> @@ -843,10 +842,9 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap,
> if (!file)
> return grub_errno;
>
> - data = grub_malloc (sizeof (*data));
> + data = grub_malloc0 (sizeof (*data));
> if (data != NULL)
> {
> - grub_memset (data, 0, sizeof (*data));
> data->file = file;
> data->bitmap = bitmap;
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 1/2] Introduce grub_malloc0()
2009-07-16 15:22 ` [PATCH 1/2] Introduce grub_malloc0() Vladimir 'phcoder' Serbinenko
@ 2009-07-16 15:41 ` Pavel Roskin
2009-07-16 15:53 ` Vladimir 'phcoder' Serbinenko
0 siblings, 1 reply; 11+ messages in thread
From: Pavel Roskin @ 2009-07-16 15:41 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, 2009-07-16 at 17:22 +0200, Vladimir 'phcoder' Serbinenko wrote:
> On Thu, Jul 16, 2009 at 1:40 AM, Pavel Roskin<proski@gnu.org> wrote:
> > Even though it's a new function added to the core, its use makes
> > core.img smaller. And it makes modules smaller too.
> I like the idea even if function name is inexplicit. Do you have a
> better alterative?
I was thinking about it. Here are some ideas:
grub_malloc0 - good that "0" is there, bad that malloc0 is not a
traditional libc name. It's easy to scan sources for both grub_malloc
and grub_malloc0
grub_calloc - we would need two arguments (element size and element
number) to be compatible with libc. We could make it a macro expandable
to grub_malloc0 to optimize out multiplication. Still, having two
arguments introduces unnecessary choice to the caller.
grub_calloc with one argument - this break the tradition or replacing
libc functions with equivalents.
grub_zalloc - similar to Linux kzalloc and kmalloc. By zalloc is not a
libc function.
grub_malloc_cleared, grub_malloc_zero - too long and just as nonstandard
as grub_zalloc.
grub_0malloc - even more weird than grub_malloc0, and it's harder to
scan for both.
After having written that, I actually tend to prefer grub_zalloc().
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] Introduce grub_malloc0()
2009-07-16 15:41 ` Pavel Roskin
@ 2009-07-16 15:53 ` Vladimir 'phcoder' Serbinenko
2009-07-17 15:02 ` Pavel Roskin
0 siblings, 1 reply; 11+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2009-07-16 15:53 UTC (permalink / raw)
To: The development of GRUB 2
On Thu, Jul 16, 2009 at 5:41 PM, Pavel Roskin<proski@gnu.org> wrote:
> On Thu, 2009-07-16 at 17:22 +0200, Vladimir 'phcoder' Serbinenko wrote:
>> On Thu, Jul 16, 2009 at 1:40 AM, Pavel Roskin<proski@gnu.org> wrote:
>> > Even though it's a new function added to the core, its use makes
>> > core.img smaller. And it makes modules smaller too.
>> I like the idea even if function name is inexplicit. Do you have a
>> better alterative?
>
> I was thinking about it. Here are some ideas:
>
> grub_malloc0 - good that "0" is there, bad that malloc0 is not a
> traditional libc name. It's easy to scan sources for both grub_malloc
> and grub_malloc0
>
> grub_calloc - we would need two arguments (element size and element
> number) to be compatible with libc. We could make it a macro expandable
> to grub_malloc0 to optimize out multiplication. Still, having two
> arguments introduces unnecessary choice to the caller.
>
> grub_calloc with one argument - this break the tradition or replacing
> libc functions with equivalents.
>
> grub_zalloc - similar to Linux kzalloc and kmalloc. By zalloc is not a
> libc function.
>
> grub_malloc_cleared, grub_malloc_zero - too long and just as nonstandard
> as grub_zalloc.
>
> grub_0malloc - even more weird than grub_malloc0, and it's harder to
> scan for both.
>
>
> After having written that, I actually tend to prefer grub_zalloc().
After having read this I agree with you
>
> --
> Regards,
> Pavel Roskin
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
--
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2009-07-19 20:33 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-15 23:40 [PATCH 1/2] Introduce grub_malloc0() Pavel Roskin
2009-07-15 23:40 ` [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine Pavel Roskin
2009-07-16 16:24 ` Vladimir 'phcoder' Serbinenko
2009-07-18 18:18 ` Robert Millan
2009-07-19 17:45 ` Pavel Roskin
2009-07-19 18:24 ` Vladimir 'phcoder' Serbinenko
2009-07-19 20:33 ` Pavel Roskin
2009-07-16 15:22 ` [PATCH 1/2] Introduce grub_malloc0() Vladimir 'phcoder' Serbinenko
2009-07-16 15:41 ` Pavel Roskin
2009-07-16 15:53 ` Vladimir 'phcoder' Serbinenko
2009-07-17 15:02 ` Pavel Roskin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.