diff --git a/coregrind/m_ume/elf.c b/coregrind/m_ume/elf.c index 4cc4df6a0..4686e43d2 100644 --- a/coregrind/m_ume/elf.c +++ b/coregrind/m_ume/elf.c @@ -89,7 +89,7 @@ static void check_mmap(SysRes res, Addr base, SizeT len) /*------------------------------------------------------------*/ static -struct elfinfo *readelf(Int fd, const char *filename) +struct elfinfo *readelf(Int fd, const HChar *filename) { SysRes sres; struct elfinfo *e = VG_(malloc)("ume.re.1", sizeof(*e)); @@ -238,7 +238,7 @@ ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base) // The 'prot' condition allows for a read-only bss if ((prot & VKI_PROT_WRITE) && (bytes > 0)) { bytes = VKI_PAGE_SIZE - bytes; - VG_(memset)((char *)bss, 0, bytes); + VG_(memset)((void *)bss, 0, bytes); } } } @@ -246,9 +246,9 @@ ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base) return elfbrk; } -Bool VG_(match_ELF)(Char *hdr, Int len) +Bool VG_(match_ELF)(const void *hdr, Int len) { - ESZ(Ehdr) *e = (ESZ(Ehdr) *)hdr; + const ESZ(Ehdr) *e = hdr; return (len > sizeof(*e)) && VG_(memcmp)(&e->e_ident[0], ELFMAG, SELFMAG) == 0; } diff --git a/coregrind/m_ume/macho.c b/coregrind/m_ume/macho.c index e2a587b13..e42832656 100644 --- a/coregrind/m_ume/macho.c +++ b/coregrind/m_ume/macho.c @@ -68,7 +68,7 @@ #endif -static void print(const char *str) +static void print(const HChar *str) { VG_(printf)("%s", str); } @@ -95,19 +95,19 @@ static void check_mmap_float(SysRes res, SizeT len, HChar* who) static int load_thin_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, - const char *filename, + const HChar *filename, vki_uint8_t **out_stack_start, vki_uint8_t **out_stack_end, vki_uint8_t **out_text, vki_uint8_t **out_entry, vki_uint8_t **out_linker_entry); static int load_fat_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, - const char *filename, + const HChar *filename, vki_uint8_t **out_stack_start, vki_uint8_t **out_stack_end, vki_uint8_t **out_text, vki_uint8_t **out_entry, vki_uint8_t **out_linker_entry); static int load_mach_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, - const char *filename, + const HChar *filename, vki_uint8_t **out_stack_start, vki_uint8_t **out_stack_end, vki_uint8_t **out_text, vki_uint8_t **out_entry, vki_uint8_t **out_linker_entry); @@ -118,7 +118,7 @@ load_mach_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, The dylinker's entry point is returned in *out_linker_entry. */ static int -open_dylinker(const char *filename, vki_uint8_t **out_linker_entry) +open_dylinker(const HChar *filename, vki_uint8_t **out_linker_entry) { struct vg_stat sb; vki_size_t filesize; @@ -429,14 +429,14 @@ handle_lcmain ( vki_uint8_t **out_stack_start, static int load_dylinker(vki_uint8_t **linker_entry, struct dylinker_command *dycmd) { - const char *name; + const HChar *name; if (dycmd->name.offset >= dycmd->cmdsize) { print("bad executable (invalid dylinker command)\n"); return -1; } - name = dycmd->name.offset + (char *)dycmd; + name = dycmd->name.offset + (HChar *)dycmd; // GrP fixme assumes name is terminated somewhere return open_dylinker(name, linker_entry); @@ -478,7 +478,7 @@ load_thread(vki_uint8_t **out_entry, struct thread_command *threadcmd) */ static int load_thin_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, - const char *filename, + const HChar *filename, vki_uint8_t **out_stack_start, vki_uint8_t **out_stack_end, vki_uint8_t **out_text, vki_uint8_t **out_entry, vki_uint8_t **out_linker_entry) { @@ -687,7 +687,7 @@ load_thin_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, */ static int load_fat_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, - const char *filename, + const HChar *filename, vki_uint8_t **out_stack_start, vki_uint8_t **out_stack_end, vki_uint8_t **out_text, vki_uint8_t **out_entry, vki_uint8_t **out_linker_entry) { @@ -766,7 +766,7 @@ load_fat_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, */ static int load_mach_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, - const char *filename, + const HChar *filename, vki_uint8_t **out_stack_start, vki_uint8_t **out_stack_end, vki_uint8_t **out_text, vki_uint8_t **out_entry, vki_uint8_t **out_linker_entry) { @@ -801,9 +801,9 @@ load_mach_file(int fd, vki_off_t offset, vki_off_t size, unsigned long filetype, } -Bool VG_(match_macho)(Char *hdr, Int len) +Bool VG_(match_macho)(const void *hdr, Int len) { - vki_uint32_t *magic = (vki_uint32_t *)hdr; + const vki_uint32_t *magic = hdr; // GrP fixme check more carefully for matching fat arch? diff --git a/coregrind/m_ume/main.c b/coregrind/m_ume/main.c index 65b7ba570..679b106da 100644 --- a/coregrind/m_ume/main.c +++ b/coregrind/m_ume/main.c @@ -46,7 +46,7 @@ typedef struct { - Bool (*match_fn)(Char *hdr, Int len); + Bool (*match_fn)(const void *hdr, Int len); Int (*load_fn)(Int fd, const HChar *name, ExeInfo *info); } ExeHandler; @@ -81,7 +81,7 @@ VG_(pre_exec_check)(const HChar* exe_name, Int* out_fd, Bool allow_setuid) fd = sr_Res(res); // Check we have execute permissions - ret = VG_(check_executable)(&is_setuid, (HChar*)exe_name, allow_setuid); + ret = VG_(check_executable)(&is_setuid, exe_name, allow_setuid); if (0 != ret) { VG_(close)(fd); if (is_setuid && !VG_(clo_xml)) { @@ -155,11 +155,11 @@ Int VG_(do_exec_inner)(const HChar* exe, ExeInfo* info) } -static Bool is_hash_bang_file(Char* f) +static Bool is_hash_bang_file(const HChar* f) { SysRes res = VG_(open)(f, VKI_O_RDONLY, 0); if (!sr_isError(res)) { - Char buf[3] = {0,0,0}; + HChar buf[3] = {0,0,0}; Int fd = sr_Res(res); Int n = VG_(read)(fd, buf, 2); if (n == 2 && VG_STREQ("#!", buf)) @@ -171,7 +171,7 @@ static Bool is_hash_bang_file(Char* f) // Look at the first 80 chars, and if any are greater than 127, it's binary. // This is crude, but should be good enough. Note that it fails on a // zero-length file, as we want. -static Bool is_binary_file(Char* f) +static Bool is_binary_file(const HChar* f) { SysRes res = VG_(open)(f, VKI_O_RDONLY, 0); if (!sr_isError(res)) { @@ -197,12 +197,12 @@ static Bool is_binary_file(Char* f) // bash as a guide). It's worth noting that the shell can execute some // things that VG_(do_exec)() (which subsitutes for the kernel's exec()) // will refuse to (eg. scripts lacking a "#!" prefix). -static Int do_exec_shell_followup(Int ret, HChar* exe_name, ExeInfo* info) +static Int do_exec_shell_followup(Int ret, const HChar* exe_name, ExeInfo* info) { # if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) - Char* default_interp_name = "/system/bin/sh"; + const HChar* default_interp_name = "/system/bin/sh"; # else - Char* default_interp_name = "/bin/sh"; + const HChar* default_interp_name = "/bin/sh"; # endif SysRes res; @@ -224,7 +224,7 @@ static Int do_exec_shell_followup(Int ret, HChar* exe_name, ExeInfo* info) info->interp_name = VG_(strdup)("ume.desf.1", default_interp_name); info->interp_args = NULL; if (info->argv && info->argv[0] != NULL) - info->argv[0] = (char *)exe_name; + info->argv[0] = (HChar *)exe_name; // FIXME: can argv be const qualified ? ret = VG_(do_exec_inner)(info->interp_name, info); @@ -280,8 +280,7 @@ Int VG_(do_exec)(const HChar* exe_name, ExeInfo* info) ret = VG_(do_exec_inner)(exe_name, info); if (0 != ret) { - Char* exe_name_casted = (Char*)exe_name; - ret = do_exec_shell_followup(ret, exe_name_casted, info); + ret = do_exec_shell_followup(ret, exe_name, info); } return ret; } diff --git a/coregrind/m_ume/priv_ume.h b/coregrind/m_ume/priv_ume.h index be7b09cbd..cba484abe 100644 --- a/coregrind/m_ume/priv_ume.h +++ b/coregrind/m_ume/priv_ume.h @@ -35,16 +35,16 @@ extern int VG_(do_exec_inner)(const HChar *exe, ExeInfo *info); #if defined(VGO_linux) -extern Bool VG_(match_ELF) ( Char *hdr, Int len ); +extern Bool VG_(match_ELF) ( const void *hdr, Int len ); extern Int VG_(load_ELF) ( Int fd, const HChar *name, ExeInfo *info ); #elif defined(VGO_darwin) -extern Bool VG_(match_macho) ( Char *hdr, Int len ); +extern Bool VG_(match_macho) ( const void *hdr, Int len ); extern Int VG_(load_macho) ( Int fd, const HChar *name, ExeInfo *info ); #else # error Unknown OS #endif -extern Bool VG_(match_script) ( Char *hdr, Int len ); +extern Bool VG_(match_script) ( const void *hdr, Int len ); extern Int VG_(load_script) ( Int fd, const HChar *name, ExeInfo *info ); diff --git a/coregrind/m_ume/script.c b/coregrind/m_ume/script.c index 53e3190d9..bab8efecc 100644 --- a/coregrind/m_ume/script.c +++ b/coregrind/m_ume/script.c @@ -42,10 +42,11 @@ #include "priv_ume.h" -Bool VG_(match_script)(Char *hdr, Int len) +Bool VG_(match_script)(const void *hdr, Int len) { - Char* end = hdr + len; - Char* interp = hdr + 2; + const HChar* script = hdr; + const HChar* end = script + len; + const HChar* interp = script + 2; // len < 4: need '#', '!', plus at least a '/' and one more char if (len < 4) return False; @@ -78,13 +79,13 @@ Bool VG_(match_script)(Char *hdr, Int len) /* returns: 0 = success, non-0 is failure */ Int VG_(load_script)(Int fd, const HChar* name, ExeInfo* info) { - Char hdr[4096]; - Int len = 4096; - Int eol; - Char* interp; - Char* end; - Char* cp; - Char* arg = NULL; + HChar hdr[4096]; + Int len = 4096; + Int eol; + HChar* interp; + HChar* end; + HChar* cp; + HChar* arg = NULL; SysRes res; // Read the first part of the file. @@ -133,7 +134,7 @@ Int VG_(load_script)(Int fd, const HChar* name, ExeInfo* info) } if (info->argv && info->argv[0] != NULL) - info->argv[0] = (char *)name; + info->argv[0] = (HChar *)name; // FIXME: can argv be const qualified? VG_(args_the_exename) = name;