#include <glib.h>
#include <string.h>
#include <pthread.h>
-#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <mono/io-layer/io-portability.h>
#include <mono/io-layer/error.h>
#include <mono/utils/strenc.h>
+#include <mono/utils/mono-mmap.h>
#define LOGDEBUG(...)
//define LOGDEBUG(...) g_message(__VA_ARGS__)
#define ALIGN32(ptr) ptr = (gpointer)((char *)ptr + 3); ptr = (gpointer)((char *)ptr - ((gsize)ptr & 3));
-static WapiImageSectionHeader *get_enclosing_section_header (guint32 rva, WapiImageNTHeaders32 *nt_headers)
+static WapiImageSectionHeader *
+get_enclosing_section_header (guint32 rva, WapiImageNTHeaders32 *nt_headers)
{
WapiImageSectionHeader *section = _WAPI_IMAGE_FIRST_SECTION32 (nt_headers);
guint32 i;
/* This works for both 32bit and 64bit files, as the differences are
* all after the section header block
*/
-static gpointer get_ptr_from_rva (guint32 rva, WapiImageNTHeaders32 *ntheaders,
- gpointer file_map)
+static gpointer
+get_ptr_from_rva (guint32 rva, WapiImageNTHeaders32 *ntheaders, gpointer file_map)
{
WapiImageSectionHeader *section_header;
guint32 delta;
return((guint8 *)file_map + rva - delta);
}
-static gpointer scan_resource_dir (WapiImageResourceDirectory *root,
- WapiImageNTHeaders32 *nt_headers,
- gpointer file_map,
- WapiImageResourceDirectoryEntry *entry,
- int level, guint32 res_id, guint32 lang_id,
- guint32 *size)
+static gpointer
+scan_resource_dir (WapiImageResourceDirectory *root,
+ WapiImageNTHeaders32 *nt_headers,
+ gpointer file_map,
+ WapiImageResourceDirectoryEntry *entry,
+ int level, guint32 res_id, guint32 lang_id,
+ guint32 *size)
{
WapiImageResourceDirectoryEntry swapped_entry;
gboolean is_string, is_dir;
}
}
-static gpointer find_pe_file_resources32 (gpointer file_map, guint32 map_size,
- guint32 res_id, guint32 lang_id,
- guint32 *size)
+static gpointer
+find_pe_file_resources32 (gpointer file_map, guint32 map_size,
+ guint32 res_id, guint32 lang_id,
+ guint32 *size)
{
WapiImageDosHeader *dos_header;
WapiImageNTHeaders32 *nt_headers;
return(NULL);
}
-static gpointer find_pe_file_resources64 (gpointer file_map, guint32 map_size,
- guint32 res_id, guint32 lang_id,
- guint32 *size)
+static gpointer
+find_pe_file_resources64 (gpointer file_map, guint32 map_size,
+ guint32 res_id, guint32 lang_id,
+ guint32 *size)
{
WapiImageDosHeader *dos_header;
WapiImageNTHeaders64 *nt_headers;
return(NULL);
}
-static gpointer find_pe_file_resources (gpointer file_map, guint32 map_size,
- guint32 res_id, guint32 lang_id,
- guint32 *size)
+static gpointer
+find_pe_file_resources (gpointer file_map, guint32 map_size,
+ guint32 res_id, guint32 lang_id,
+ guint32 *size)
{
/* Figure this out when we support 64bit PE files */
if (1) {
}
}
-static gpointer map_pe_file (gunichar2 *filename, guint32 *map_size)
+static gpointer
+map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
{
gchar *filename_ext;
int fd;
return(NULL);
}
*map_size = statbuf.st_size;
-
+
/* Check basic file size */
if (statbuf.st_size < sizeof(WapiImageDosHeader)) {
LOGDEBUG ("%s: File %s is too small: %lld", __func__, filename_ext, statbuf.st_size);
return(NULL);
}
- file_map = mmap (NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- if (file_map == MAP_FAILED) {
+ file_map = mono_file_map (statbuf.st_size, MONO_MMAP_READ | MONO_MMAP_PRIVATE, fd, 0, handle);
+ if (file_map == NULL) {
LOGDEBUG ("%s: Error mmap()int file %s: %s", __func__, filename_ext, strerror (errno));
SetLastError (_wapi_get_win32_file_error (errno));
return(file_map);
}
-static void unmap_pe_file (gpointer file_map, guint32 map_size)
+static void
+unmap_pe_file (gpointer file_map, void *handle)
{
- munmap (file_map, map_size);
+ mono_file_unmap (file_map, handle);
}
-static guint32 unicode_chars (const gunichar2 *str)
+static guint32
+unicode_chars (const gunichar2 *str)
{
guint32 len = 0;
} while(1);
}
-static gboolean unicode_compare (const gunichar2 *str1, const gunichar2 *str2)
+static gboolean
+unicode_compare (const gunichar2 *str1, const gunichar2 *str2)
{
while (*str1 && *str2) {
if (*str1 != *str2) {
/* compare a little-endian null-terminated utf16 string and a normal string.
* Can be used only for ascii or latin1 chars.
*/
-static gboolean unicode_string_equals (const gunichar2 *str1, const gchar *str2)
+static gboolean
+unicode_string_equals (const gunichar2 *str1, const gchar *str2)
{
while (*str1 && *str2) {
if (GUINT16_TO_LE (*str1) != *str2) {
/* Returns a pointer to the value data, because there's no way to know
* how big that data is (value_len is set to zero for most blocks :-( )
*/
-static gconstpointer get_versioninfo_block (gconstpointer data,
- version_data *block)
+static gconstpointer
+get_versioninfo_block (gconstpointer data, version_data *block)
{
block->data_len = GUINT16_FROM_LE (*((guint16 *)data));
data = (char *)data + sizeof(guint16);
return(data);
}
-static gconstpointer get_fixedfileinfo_block (gconstpointer data,
- version_data *block)
+static gconstpointer
+get_fixedfileinfo_block (gconstpointer data, version_data *block)
{
gconstpointer data_ptr;
gint32 data_len; /* signed to guard against underflow */
return(data_ptr);
}
-static gconstpointer get_varfileinfo_block (gconstpointer data_ptr,
- version_data *block)
+static gconstpointer
+get_varfileinfo_block (gconstpointer data_ptr, version_data *block)
{
/* data is pointing at a Var block
*/
return(data_ptr);
}
-static gconstpointer get_string_block (gconstpointer data_ptr,
- const gunichar2 *string_key,
- gpointer *string_value,
- guint32 *string_value_len,
- version_data *block)
+static gconstpointer
+get_string_block (gconstpointer data_ptr,
+ const gunichar2 *string_key,
+ gpointer *string_value,
+ guint32 *string_value_len,
+ version_data *block)
{
guint16 data_len = block->data_len;
guint16 string_len = 28; /* Length of the StringTable block */
*
* If lang == NULL it means we're just stepping through this block
*/
-static gconstpointer get_stringtable_block (gconstpointer data_ptr,
- gchar *lang,
- const gunichar2 *string_key,
- gpointer *string_value,
- guint32 *string_value_len,
- version_data *block)
+static gconstpointer
+get_stringtable_block (gconstpointer data_ptr,
+ gchar *lang,
+ const gunichar2 *string_key,
+ gpointer *string_value,
+ guint32 *string_value_len,
+ version_data *block)
{
guint16 data_len = block->data_len;
guint16 string_len = 36; /* length of the StringFileInfo block */
}
#if G_BYTE_ORDER == G_BIG_ENDIAN
-static gconstpointer big_up_string_block (gconstpointer data_ptr,
- version_data *block)
+static gconstpointer
+big_up_string_block (gconstpointer data_ptr, version_data *block)
{
guint16 data_len = block->data_len;
guint16 string_len = 28; /* Length of the StringTable block */
* because the data length does not include padding bytes, so it's not
* possible to just return the start position + length
*/
-static gconstpointer big_up_stringtable_block (gconstpointer data_ptr,
- version_data *block)
+static gconstpointer
+big_up_stringtable_block (gconstpointer data_ptr, version_data *block)
{
guint16 data_len = block->data_len;
guint16 string_len = 36; /* length of the StringFileInfo block */
/* Follows the data structures and turns all UTF-16 strings from the
* LE found in the resource section into UTF-16BE
*/
-static void big_up (gconstpointer datablock, guint32 size)
+static void
+big_up (gconstpointer datablock, guint32 size)
{
gconstpointer data_ptr;
gint32 data_len; /* signed to guard against underflow */
}
#endif
-gboolean VerQueryValue (gconstpointer datablock, const gunichar2 *subblock,
- gpointer *buffer, guint32 *len)
+gboolean
+VerQueryValue (gconstpointer datablock, const gunichar2 *subblock, gpointer *buffer, guint32 *len)
{
gchar *subblock_utf8, *lang_utf8 = NULL;
gboolean ret = FALSE;
return(ret);
}
-guint32 GetFileVersionInfoSize (gunichar2 *filename, guint32 *handle)
+guint32
+GetFileVersionInfoSize (gunichar2 *filename, guint32 *handle)
{
gpointer file_map;
gpointer versioninfo;
- guint32 map_size;
+ void *map_handle;
+ gint32 map_size;
guint32 size;
-
+
/* This value is unused, but set to zero */
*handle = 0;
- file_map = map_pe_file (filename, &map_size);
+ file_map = map_pe_file (filename, &map_size, &map_handle);
if (file_map == NULL) {
return(0);
}
- versioninfo = find_pe_file_resources (file_map, map_size, RT_VERSION,
- 0, &size);
+ versioninfo = find_pe_file_resources (file_map, map_size, RT_VERSION, 0, &size);
if (versioninfo == NULL) {
/* Didn't find the resource, so set the return value
* to 0
size = 0;
}
- unmap_pe_file (file_map, map_size);
+ unmap_pe_file (file_map, map_handle);
return(size);
}
-gboolean GetFileVersionInfo (gunichar2 *filename, guint32 handle G_GNUC_UNUSED,
- guint32 len, gpointer data)
+gboolean
+GetFileVersionInfo (gunichar2 *filename, guint32 handle G_GNUC_UNUSED, guint32 len, gpointer data)
{
gpointer file_map;
gpointer versioninfo;
- guint32 map_size;
+ void *map_handle;
+ gint32 map_size;
guint32 size;
gboolean ret = FALSE;
- file_map = map_pe_file (filename, &map_size);
+ file_map = map_pe_file (filename, &map_size, &map_handle);
if (file_map == NULL) {
return(FALSE);
}
#endif
}
- unmap_pe_file (file_map, map_size);
+ unmap_pe_file (file_map, &map_handle);
return(ret);
}
-static guint32 copy_lang (gunichar2 *lang_out, guint32 lang_len,
- const gchar *text)
+static guint32
+copy_lang (gunichar2 *lang_out, guint32 lang_len, const gchar *text)
{
gunichar2 *unitext;
int chars = strlen (text);
return(ret);
}
-guint32 VerLanguageName (guint32 lang, gunichar2 *lang_out, guint32 lang_len)
+guint32
+VerLanguageName (guint32 lang, gunichar2 *lang_out, guint32 lang_len)
{
int primary, secondary;