/*------------------------------------------------------------*/
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));
// 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);
}
}
}
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;
}
#endif
-static void print(const char *str)
+static void print(const HChar *str)
{
VG_(printf)("%s", str);
}
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);
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;
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);
*/
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)
{
}
-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?
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;
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)) {
}
-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))
// 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)) {
// 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;
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);
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;
}
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 );
#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;
/* 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.
}
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;