Update libretro-common

This commit is contained in:
twinaphex 2015-09-01 11:43:17 +02:00
parent 27bb3f8e24
commit b74adf4d98
11 changed files with 347 additions and 256 deletions

View File

@ -38,7 +38,13 @@
#include <direct.h>
#include <windows.h>
#endif
#elif defined(VITA)
#include <psp2/io/fcntl.h>
#include <psp2/io/dirent.h>
#else
#if defined(PSP)
#include <pspiofilemgr.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
@ -96,7 +102,6 @@ void dir_list_free(struct string_list *list)
string_list_free(list);
}
#ifndef _WIN32
/**
*
* dirent_is_directory:
@ -109,12 +114,22 @@ void dir_list_free(struct string_list *list)
* a directory, false if not.
*/
static bool dirent_is_directory(const char *path,
const struct dirent *entry)
static bool dirent_is_directory(const char *path, const void *data)
{
#if defined(_WIN32)
const WIN32_FIND_DATA *entry = (const WIN32_FIND_DATA*)data;
return entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
#elif defined(PSP) || defined(VITA)
const SceIoDirent *entry = (const SceIoDirent*)data;
#if defined(PSP)
return (entry->d_stat.st_attr & FIO_SO_IFDIR) == FIO_SO_IFDIR;
#elif defined(VITA)
return PSP2_S_ISDIR(entry->d_stat.st_mode);
#endif
#elif defined(DT_DIR)
const struct dirent *entry = (const struct dirent*)data;
if (entry->d_type == DT_DIR)
return true;
else if (entry->d_type == DT_UNKNOWN /* This can happen on certain file systems. */
@ -122,20 +137,21 @@ static bool dirent_is_directory(const char *path,
return path_is_directory(path);
return false;
#else /* dirent struct doesn't have d_type, do it the slow way ... */
const struct dirent *entry = (const struct dirent*)data;
return path_is_directory(path);
#endif
}
#endif
/**
* parse_dir_entry:
* @name : name of the directory listing entry.
* @file_path : file path of the directory listing entry.
* @is_dir : is the directory listing a directory?
* @include_dirs : include directories as part of the finished directory listing?
* @list : pointer to directory listing.
* @ext_list : pointer to allowed file extensions listing.
* @file_ext : file extension of the directory listing entry.
* @name : name of the directory listing entry.
* @file_path : file path of the directory listing entry.
* @is_dir : is the directory listing a directory?
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : Include compressed files, even if not part of ext_list.
* @list : pointer to directory listing.
* @ext_list : pointer to allowed file extensions listing.
* @file_ext : file extension of the directory listing entry.
*
* Parses a directory listing.
*
@ -143,7 +159,7 @@ static bool dirent_is_directory(const char *path,
* continue to the next entry in the directory listing.
**/
static int parse_dir_entry(const char *name, char *file_path,
bool is_dir, bool include_dirs,
bool is_dir, bool include_dirs, bool include_compressed,
struct string_list *list, struct string_list *ext_list,
const char *file_ext)
{
@ -166,7 +182,9 @@ static int parse_dir_entry(const char *name, char *file_path,
if (!strcmp(name, ".") || !strcmp(name, ".."))
return 1;
if (!is_compressed_file && !is_dir && ext_list && !supported_by_core)
if (!is_dir && ext_list &&
((!is_compressed_file && !supported_by_core) ||
(!supported_by_core && !include_compressed)))
return 1;
if (is_dir)
@ -190,11 +208,50 @@ static int parse_dir_entry(const char *name, char *file_path,
return 0;
}
#if defined(_WIN32)
#define dirent_opendir(directory, dir) \
{ \
char path_buf[PATH_MAX_LENGTH]; \
snprintf(path_buf, sizeof(path_buf), "%s\\*", dir); \
directory = FindFirstFile(path_buf, &entry); \
}
#elif defined(VITA) || defined(PSP)
#define dirent_opendir(directory, dir) directory = sceIoDopen(dir)
#else
#define dirent_opendir(directory, dir) directory = opendir(dir)
#endif
#if defined(_WIN32)
#define dirent_error(directory) ((directory) == INVALID_HANDLE_VALUE)
#elif defined(VITA) || defined(PSP)
#define dirent_error(directory) ((directory) < 0)
#else
#define dirent_error(directory) (!(directory))
#endif
#if defined(_WIN32)
#define dirent_readdir(directory, entry) (FindNextFile((directory), &(entry)) != 0)
#elif defined(VITA) || defined(PSP)
#define dirent_readdir(directory, entry) (sceIoDread((directory), &(entry)) > 0)
#else
#define dirent_readdir(directory, entry) (entry = readdir(directory))
#endif
#if defined(_WIN32)
#define dirent_closedir(directory) if (directory != INVALID_HANDLE_VALUE) FindClose(directory)
#elif defined(VITA) || defined(PSP)
#define dirent_closedir(directory) sceIoDclose(directory)
#else
#define dirent_closedir(directory) if (directory) closedir(directory)
#endif
/**
* dir_list_new:
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : Only include files which match ext. Do not try to match compressed files, etc.
*
* Create a directory listing.
*
@ -202,80 +259,52 @@ static int parse_dir_entry(const char *name, char *file_path,
* NULL in case of error. Has to be freed manually.
**/
struct string_list *dir_list_new(const char *dir,
const char *ext, bool include_dirs)
const char *ext, bool include_dirs, bool include_compressed)
{
#ifdef _WIN32
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
#if defined(_WIN32)
WIN32_FIND_DATA entry;
HANDLE directory = INVALID_HANDLE_VALUE;
#elif defined(VITA) || defined(PSP)
SceUID directory;
SceIoDirent entry;
#else
DIR *directory = NULL;
const struct dirent *entry = NULL;
DIR *directory = NULL;
const struct dirent *entry = NULL;
#endif
char path_buf[PATH_MAX_LENGTH] = {0};
struct string_list *ext_list = NULL;
struct string_list *list = NULL;
(void)path_buf;
if (!(list = string_list_new()))
return NULL;
if (ext)
ext_list = string_split(ext, "|");
dirent_opendir(directory, dir);
if (dirent_error(directory))
goto error;
while (dirent_readdir(directory, entry))
{
char file_path[PATH_MAX_LENGTH];
int ret = 0;
#ifdef _WIN32
snprintf(path_buf, sizeof(path_buf), "%s\\*", dir);
hFind = FindFirstFile(path_buf, &ffd);
if (hFind == INVALID_HANDLE_VALUE)
goto error;
do
{
char file_path[PATH_MAX_LENGTH];
int ret = 0;
const char *name = ffd.cFileName;
const char *file_ext = path_get_extension(name);
bool is_dir = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
fill_pathname_join(file_path, dir, name, sizeof(file_path));
ret = parse_dir_entry(name, file_path, is_dir,
include_dirs, list, ext_list, file_ext);
if (ret == -1)
goto error;
if (ret == 1)
continue;
}while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
string_list_free(ext_list);
return list;
error:
if (hFind != INVALID_HANDLE_VALUE)
FindClose(hFind);
const char *name = entry.cFileName;
bool is_dir = dirent_is_directory(file_path, &entry);
#elif defined(VITA) || defined(PSP)
const char *name = entry.d_name;
bool is_dir = dirent_is_directory(file_path, &entry);
#else
directory = opendir(dir);
if (!directory)
goto error;
while ((entry = readdir(directory)))
{
char file_path[PATH_MAX_LENGTH];
int ret = 0;
const char *name = entry->d_name;
bool is_dir = dirent_is_directory(file_path, entry);
#endif
const char *file_ext = path_get_extension(name);
bool is_dir = false;
fill_pathname_join(file_path, dir, name, sizeof(file_path));
is_dir = dirent_is_directory(file_path, entry);
ret = parse_dir_entry(name, file_path, is_dir,
include_dirs, list, ext_list, file_ext);
ret = parse_dir_entry(name, file_path, is_dir,
include_dirs, include_compressed, list, ext_list, file_ext);
if (ret == -1)
goto error;
@ -284,17 +313,14 @@ error:
continue;
}
closedir(directory);
dirent_closedir(directory);
string_list_free(ext_list);
return list;
error:
dirent_closedir(directory);
if (directory)
closedir(directory);
#endif
string_list_free(list);
string_list_free(ext_list);
return NULL;

View File

@ -105,13 +105,14 @@ static bool dirent_is_directory(const char *path)
/**
* parse_dir_entry:
* @name : name of the directory listing entry.
* @file_path : file path of the directory listing entry.
* @is_dir : is the directory listing a directory?
* @include_dirs : include directories as part of the finished directory listing?
* @list : pointer to directory listing.
* @ext_list : pointer to allowed file extensions listing.
* @file_ext : file extension of the directory listing entry.
* @name : name of the directory listing entry.
* @file_path : file path of the directory listing entry.
* @is_dir : is the directory listing a directory?
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : include compressed files, even when not part of ext_list.
* @list : pointer to directory listing.
* @ext_list : pointer to allowed file extensions listing.
* @file_ext : file extension of the directory listing entry.
*
* Parses a directory listing.
*
@ -119,7 +120,7 @@ static bool dirent_is_directory(const char *path)
* continue to the next entry in the directory listing.
**/
static int parse_dir_entry(const char *name, char *file_path,
bool is_dir, bool include_dirs,
bool is_dir, bool include_dirs, bool include_compressed,
struct string_list *list, struct string_list *ext_list,
const char *file_ext)
{
@ -142,7 +143,9 @@ static int parse_dir_entry(const char *name, char *file_path,
if (!strcmp(name, ".") || !strcmp(name, ".."))
return 1;
if (!is_compressed_file && !is_dir && ext_list && !supported_by_core)
if (!is_dir && ext_list &&
((!is_compressed_file && !supported_by_core) ||
(!supported_by_core && !include_compressed)))
return 1;
if (is_dir)
@ -168,9 +171,10 @@ static int parse_dir_entry(const char *name, char *file_path,
/**
* dir_list_new:
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : Include compressed files, even if not part of ext.
*
* Create a directory listing.
*
@ -178,7 +182,7 @@ static int parse_dir_entry(const char *name, char *file_path,
* NULL in case of error. Has to be freed manually.
**/
struct string_list *dir_list_new(const char *dir,
const char *ext, bool include_dirs)
const char *ext, bool include_dirs, bool include_compressed)
{
NSArray *entries = NULL;
char path_buf[PATH_MAX_LENGTH] = {0};
@ -207,7 +211,7 @@ struct string_list *dir_list_new(const char *dir,
is_dir = dirent_is_directory(file_path);
ret = parse_dir_entry([name UTF8String], file_path, is_dir,
include_dirs, list, ext_list, file_ext);
include_dirs, include_compressed, list, ext_list, file_ext);
if (ret == -1)
goto error;

View File

@ -40,7 +40,9 @@
#include <compat/posix_string.h>
#include <retro_miscellaneous.h>
#ifdef HAVE_COMPRESSION
#include <rhash.h>
#endif
#if defined(__CELLOS_LV2__)
@ -63,6 +65,9 @@
#include <direct.h>
#include <windows.h>
#endif
#elif defined(VITA)
#include <psp2/io/fcntl.h>
#include <psp2/io/dirent.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
@ -70,11 +75,15 @@
#include <unistd.h>
#endif
#if defined(PSP)
#include <pspkernel.h>
#endif
/**
* path_get_extension:
* @path : path
*
* Gets extension of file. Only '.'s
* Gets extension of file. Only '.'s
* after the last slash are considered.
*
* Returns: extension part from the path.
@ -204,7 +213,7 @@ bool path_file_exists(const char *path)
* fill_pathname:
* @out_path : output path
* @in_path : input path
* @replace : what to replace
* @replace : what to replace
* @size : buffer size of output path
*
* FIXME: Verify
@ -216,10 +225,10 @@ bool path_file_exists(const char *path)
* Only '.'s after the last slash are considered as extensions.
* If no '.' is present, in_path and replace will simply be concatenated.
* 'size' is buffer size of 'out_path'.
* E.g.: in_path = "/foo/bar/baz/boo.c", replace = ".asm" =>
* out_path = "/foo/bar/baz/boo.asm"
* E.g.: in_path = "/foo/bar/baz/boo.c", replace = ".asm" =>
* out_path = "/foo/bar/baz/boo.asm"
* E.g.: in_path = "/foo/bar/baz/boo.c", replace = "" =>
* out_path = "/foo/bar/baz/boo"
* out_path = "/foo/bar/baz/boo"
*/
void fill_pathname(char *out_path, const char *in_path,
const char *replace, size_t size)
@ -240,7 +249,7 @@ void fill_pathname(char *out_path, const char *in_path,
* fill_pathname_noext:
* @out_path : output path
* @in_path : input path
* @replace : what to replace
* @replace : what to replace
* @size : buffer size of output path
*
* Appends a filename extension 'replace' to 'in_path', and outputs
@ -270,7 +279,7 @@ static char *find_last_slash(const char *str)
return (char*)slash;
}
/**
/**
* fill_pathname_slash:
* @path : path
* @size : size of path
@ -324,7 +333,7 @@ void fill_pathname_dir(char *in_dir, const char *in_basename,
/**
* fill_pathname_base:
* @out : output path
* @out : output path
* @in_path : input path
* @size : size of output path
*
@ -362,7 +371,7 @@ void fill_pathname_base(char *out, const char *in_path, size_t size)
/**
* fill_pathname_basedir:
* @out_dir : output directory
* @out_dir : output directory
* @in_path : input path
* @size : size of output directory
*
@ -379,7 +388,7 @@ void fill_pathname_basedir(char *out_dir,
/**
* fill_pathname_parent_dir:
* @out_dir : output directory
* @out_dir : output directory
* @in_dir : input directory
* @size : size of output directory
*
@ -399,10 +408,10 @@ void fill_pathname_parent_dir(char *out_dir,
* @ext : extension of output filename
* @size : buffer size of output filename
*
* Creates a 'dated' filename prefixed by 'RetroArch', and
* Creates a 'dated' filename prefixed by 'RetroArch', and
* concatenates extension (@ext) to it.
*
* E.g.:
* E.g.:
* out_filename = "RetroArch-{month}{day}-{Hours}{Minutes}.{@ext}"
**/
void fill_dated_filename(char *out_filename,
@ -418,7 +427,7 @@ void fill_dated_filename(char *out_filename,
/**
* path_basedir:
* @path : path
* @path : path
*
* Extracts base directory by mutating path.
* Keeps trailing '/'.
@ -556,6 +565,8 @@ static bool path_mkdir_norecurse(const char *dir)
ret = _mkdir(dir);
#elif defined(IOS)
ret = mkdir(dir, 0755);
#elif defined(VITA) || defined(PSP)
ret = sceIoMkdir(dir, 0755);
#else
ret = mkdir(dir, 0750);
#endif
@ -643,12 +654,12 @@ void fill_pathname_resolve_relative(char *out_path,
/**
* fill_pathname_join:
* @out_path : output path
* @dir : directory
* @dir : directory
* @path : path
* @size : size of output path
*
* Joins a directory (@dir) and path (@path) together.
* Makes sure not to get two consecutive slashes
* Makes sure not to get two consecutive slashes
* between directory and path.
**/
void fill_pathname_join(char *out_path,
@ -665,12 +676,12 @@ void fill_pathname_join(char *out_path,
/**
* fill_pathname_join_delim:
* @out_path : output path
* @dir : directory
* @dir : directory
* @path : path
* @delim : delimiter
* @delim : delimiter
* @size : size of output path
*
* Joins a directory (@dir) and path (@path) together
* Joins a directory (@dir) and path (@path) together
* using the given delimiter (@delim).
**/
void fill_pathname_join_delim(char *out_path, const char *dir,
@ -716,7 +727,7 @@ void fill_short_pathname_representation(char* out_rep,
*/
if(last_hash != NULL)
{
/* We check whether something is actually
/* We check whether something is actually
* after the hash to avoid going over the buffer.
*/
rarch_assert(strlen(last_hash) > 1);

View File

@ -253,6 +253,34 @@ void conv_rgb565_argb8888(void *output_, const void *input_,
}
}
void conv_argb8888_rgba4444(void *output_, const void *input_,
int width, int height,
int out_stride, int in_stride)
{
int h, w;
const uint32_t *input = (const uint32_t*)input_;
uint16_t *output = (uint16_t*)output_;
for (h = 0; h < height;
h++, output += out_stride >> 2, input += in_stride >> 1)
{
for (w = 0; w < width; w++)
{
uint32_t col = input[w];
uint32_t r = (col >> 16) & 0xf;
uint32_t g = (col >> 8) & 0xf;
uint32_t b = (col) & 0xf;
uint32_t a = (col >> 24) & 0xf;
r = (r >> 4) | r;
g = (g >> 4) | g;
b = (b >> 4) | b;
a = (a >> 4) | a;
output[w] = (r << 12) | (g << 8) | (b << 4) | a;
}
}
}
void conv_rgba4444_argb8888(void *output_, const void *input_,
int width, int height,
int out_stride, int in_stride)

View File

@ -116,42 +116,88 @@ static bool set_direct_pix_conv(struct scaler_ctx *ctx)
switch (ctx->in_fmt)
{
case SCALER_FMT_0RGB1555:
if (ctx->out_fmt == SCALER_FMT_ARGB8888)
ctx->direct_pixconv = conv_0rgb1555_argb8888;
else if (ctx->out_fmt == SCALER_FMT_RGB565)
ctx->direct_pixconv = conv_0rgb1555_rgb565;
else if (ctx->out_fmt == SCALER_FMT_BGR24)
ctx->direct_pixconv = conv_0rgb1555_bgr24;
switch (ctx->out_fmt)
{
case SCALER_FMT_ARGB8888:
ctx->direct_pixconv = conv_0rgb1555_argb8888;
break;
case SCALER_FMT_RGB565:
ctx->direct_pixconv = conv_0rgb1555_rgb565;
break;
case SCALER_FMT_BGR24:
ctx->direct_pixconv = conv_0rgb1555_bgr24;
break;
default:
break;
}
break;
case SCALER_FMT_RGB565:
if (ctx->out_fmt == SCALER_FMT_ARGB8888)
ctx->direct_pixconv = conv_rgb565_argb8888;
else if (ctx->out_fmt == SCALER_FMT_BGR24)
ctx->direct_pixconv = conv_rgb565_bgr24;
else if (ctx->out_fmt == SCALER_FMT_0RGB1555)
ctx->direct_pixconv = conv_rgb565_0rgb1555;
switch (ctx->out_fmt)
{
case SCALER_FMT_ARGB8888:
ctx->direct_pixconv = conv_rgb565_argb8888;
break;
case SCALER_FMT_BGR24:
ctx->direct_pixconv = conv_rgb565_bgr24;
break;
case SCALER_FMT_0RGB1555:
ctx->direct_pixconv = conv_rgb565_0rgb1555;
break;
default:
break;
}
break;
case SCALER_FMT_BGR24:
if (ctx->out_fmt == SCALER_FMT_ARGB8888)
ctx->direct_pixconv = conv_bgr24_argb8888;
switch (ctx->out_fmt)
{
case SCALER_FMT_ARGB8888:
ctx->direct_pixconv = conv_bgr24_argb8888;
break;
default:
break;
}
break;
case SCALER_FMT_ARGB8888:
if (ctx->out_fmt == SCALER_FMT_0RGB1555)
ctx->direct_pixconv = conv_argb8888_0rgb1555;
else if (ctx->out_fmt == SCALER_FMT_BGR24)
ctx->direct_pixconv = conv_argb8888_bgr24;
else if (ctx->out_fmt == SCALER_FMT_ABGR8888)
ctx->direct_pixconv = conv_argb8888_abgr8888;
switch (ctx->out_fmt)
{
case SCALER_FMT_0RGB1555:
ctx->direct_pixconv = conv_argb8888_0rgb1555;
break;
case SCALER_FMT_BGR24:
ctx->direct_pixconv = conv_argb8888_bgr24;
break;
case SCALER_FMT_ABGR8888:
ctx->direct_pixconv = conv_argb8888_abgr8888;
break;
case SCALER_FMT_RGBA4444:
ctx->direct_pixconv = conv_argb8888_rgba4444;
break;
default:
break;
}
break;
case SCALER_FMT_YUYV:
if (ctx->out_fmt == SCALER_FMT_ARGB8888)
ctx->direct_pixconv = conv_yuyv_argb8888;
switch (ctx->out_fmt)
{
case SCALER_FMT_ARGB8888:
ctx->direct_pixconv = conv_yuyv_argb8888;
break;
default:
break;
}
break;
case SCALER_FMT_RGBA4444:
if (ctx->out_fmt == SCALER_FMT_ARGB8888)
ctx->direct_pixconv = conv_rgba4444_argb8888;
else if (ctx->out_fmt == SCALER_FMT_RGB565)
ctx->direct_pixconv = conv_rgba4444_rgb565;
switch (ctx->out_fmt)
{
case SCALER_FMT_ARGB8888:
ctx->direct_pixconv = conv_rgba4444_argb8888;
break;
case SCALER_FMT_RGB565:
ctx->direct_pixconv = conv_rgba4444_rgb565;
break;
default:
break;
}
break;
case SCALER_FMT_ABGR8888:
/* FIXME/TODO */
@ -198,6 +244,10 @@ static bool set_pix_conv(struct scaler_ctx *ctx)
/* No need to convert :D */
break;
case SCALER_FMT_RGBA4444:
ctx->out_pixconv = conv_argb8888_rgba4444;
break;
case SCALER_FMT_0RGB1555:
ctx->out_pixconv = conv_argb8888_0rgb1555;
break;

View File

@ -31,9 +31,10 @@ extern "C" {
/**
* dir_list_new:
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @dir : directory path.
* @ext : allowed extensions of file directory entries to include.
* @include_dirs : include directories as part of the finished directory listing?
* @include_compressed : include compressed files, even when not part of ext.
*
* Create a directory listing.
*
@ -41,7 +42,7 @@ extern "C" {
* NULL in case of error. Has to be freed manually.
**/
struct string_list *dir_list_new(const char *dir, const char *ext,
bool include_dirs);
bool include_dirs, bool include_compressed);
/**
* dir_list_sort:

View File

@ -57,6 +57,10 @@ void conv_argb8888_0rgb1555(void *output, const void *input,
int width, int height,
int out_stride, int in_stride);
void conv_argb8888_rgba4444(void *output_, const void *input_,
int width, int height,
int out_stride, int in_stride);
void conv_argb8888_rgb565(void *output, const void *input,
int width, int height,
int out_stride, int in_stride);

View File

@ -34,23 +34,10 @@
#include <sys/mman.h>
#endif
#if !defined(HAVE_MMAN)
#define PROT_EXEC 0x04
#define MAP_FAILED 0
#define PROT_READ 0
#define PROT_WRITE 0
#define MAP_PRIVATE 0
#define MAP_ANONYMOUS 0
#endif
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
#if !defined(HAVE_MMAN) || defined(_WIN32)
void* mmap(void *desired_addr, size_t len, int mmap_prot, int mmap_flags, int fildes, size_t off);
void* mmap(void *addr, size_t len, int mmap_prot, int mmap_flags, int fildes, size_t off);
void munmap(void *base_addr, size_t len);
int munmap(void *addr, size_t len);
int mprotect(void *addr, size_t len, int prot);
#endif

View File

@ -1,7 +1,7 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
*
*
* RetroArch 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
@ -51,6 +51,16 @@
#include <network.h>
#elif defined(VITA)
#include <psp2/net/net.h>
#include <psp2/net/netctl.h>
#define sockaddr_in SceNetSockaddrIn
#define sockaddr SceNetSockaddr
#define sendto sceNetSendto
#define MSG_DONTWAIT PSP2_NET_MSG_DONTWAIT
#else
#include <sys/select.h>
#include <sys/types.h>
@ -112,7 +122,7 @@ static INLINE bool isagain(int bytes)
#ifdef _XBOX
#define socklen_t int
#ifndef h_addr
#ifndef h_addr
#define h_addr h_addr_list[0] /* for backward compatibility */
#endif

View File

@ -23,109 +23,72 @@
#include <stdint.h>
#include <memmap.h>
#ifndef PROT_READ
#define PROT_READ 0x1 /* Page can be read */
#endif
#ifndef PROT_WRITE
#define PROT_WRITE 0x2 /* Page can be written. */
#endif
#ifndef PROT_EXEC
#define PROT_EXEC 0x4 /* Page can be executed. */
#endif
#ifndef PROT_NONE
#define PROT_NONE 0x0 /* Page can not be accessed. */
#endif
#ifdef _WIN32
#define MAP_SHARED 0x01
#ifndef MAP_PRIVATE
#define MAP_PRIVATE 0x02
#endif
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS 0x20
#endif
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED ((void *) -1)
#define PROT_READ 0x1
#define PROT_WRITE 0x2
/* This flag is only available in WinXP+ */
#ifdef FILE_MAP_EXECUTE
#ifndef PROT_EXEC
#define PROT_EXEC 0x4
#endif
#else
#ifndef PROT_EXEC
#define PROT_EXEC 0x0
#endif
#define FILE_MAP_EXECUTE 0
#endif
#ifdef __USE_FILE_OFFSET64
# define DWORD_HI(x) (x >> 32)
# define DWORD_LO(x) ((x) & 0xffffffff)
#else
# define DWORD_HI(x) (0)
# define DWORD_LO(x) (x)
#endif
void *mmap(void *start, size_t length, int prot, int flags, int fd, size_t offset)
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, size_t offset)
{
uint32_t flProtect, dwDesiredAccess;
off_t end;
HANDLE mmap_fd, h;
void *ret;
void *map = (void*)NULL;
HANDLE handle = INVALID_HANDLE_VALUE;
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
return MAP_FAILED;
if (fd == -1)
switch (prot)
{
if (!(flags & MAP_ANON) || offset)
return MAP_FAILED;
}
else if (flags & MAP_ANON)
return MAP_FAILED;
if (prot & PROT_WRITE)
{
flProtect = PAGE_READWRITE;
if (prot & PROT_EXEC)
flProtect = PAGE_EXECUTE_READWRITE;
case PROT_READ:
default:
{
handle = CreateFileMapping((HANDLE) _get_osfhandle(fildes), 0, PAGE_READONLY, 0,
len, 0);
if (!handle)
break;
map = (void*)MapViewOfFile(handle, FILE_MAP_READ, 0, 0, len);
CloseHandle(handle);
break;
}
case PROT_WRITE:
{
handle = CreateFileMapping((HANDLE) _get_osfhandle(fildes),0,PAGE_READWRITE,0,
len, 0);
if (!handle)
break;
map = (void*)MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, len);
CloseHandle(handle);
break;
}
case PROT_READWRITE:
{
handle = CreateFileMapping((HANDLE) _get_osfhandle(fildes),0,PAGE_READWRITE,0,
len, 0);
if (!handle)
break;
map = (void*)MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, len);
CloseHandle(handle);
break;
}
}
else if (prot & PROT_EXEC)
{
flProtect = PAGE_EXECUTE;
if (prot & PROT_READ)
flProtect = PAGE_EXECUTE_READ;
}
else
flProtect = PAGE_READONLY;
end = length + offset;
if (fd == -1)
mmap_fd = INVALID_HANDLE_VALUE;
else
mmap_fd = (HANDLE)_get_osfhandle(fd);
h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL);
if (h == NULL)
return MAP_FAILED;
dwDesiredAccess = FILE_MAP_READ;
if (prot & PROT_WRITE)
dwDesiredAccess = FILE_MAP_WRITE;
if (prot & PROT_EXEC)
dwDesiredAccess |= FILE_MAP_EXECUTE;
if (flags & MAP_PRIVATE)
dwDesiredAccess |= FILE_MAP_COPY;
ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length);
if (ret == NULL)
{
CloseHandle(h);
ret = MAP_FAILED;
}
return ret;
if (map == (void*)NULL)
return((void*)MAP_FAILED);
return((void*) ((int8_t*)map + offset));
}
void munmap(void *addr, size_t length)
int munmap(void *addr, size_t length)
{
UnmapViewOfFile(addr);
/* ruh-ro, we leaked handle from CreateFileMapping() ... */
if (!UnmapViewOfFile(addr))
return -1;
return 0;
}
int mprotect(void *addr, size_t len, int prot)
@ -139,14 +102,15 @@ int mprotect(void *addr, size_t len, int prot)
}
#elif !defined(HAVE_MMAN)
void* mmap(void *desired_addr, size_t len, int mmap_prot, int mmap_flags, int fildes, size_t off)
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, size_t offset)
{
return malloc(len);
}
void munmap(void *base_addr, size_t len)
int munmap(void *addr, size_t len)
{
free(base_addr);
free(addr);
return 0;
}
int mprotect(void *addr, size_t len, int prot)

View File

@ -121,17 +121,23 @@ static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex)
static INLINE int pthread_join(pthread_t thread, void **retval)
{
int exit_status;
SceUInt timeout = (SceUInt)-1;
sceKernelWaitThreadEnd(thread, &timeout);
int exit_status = sceKernelGetThreadExitStatus(thread);
exit_status = sceKernelGetThreadExitStatus(thread);
sceKernelDeleteThread(thread);
return exit_status;
}
static INLINE int pthread_mutex_trylock(pthread_mutex_t *mutex)
{
//FIXME: stub
#ifdef VITA
return sceKernelTryLockMutex(*mutex, 1 /* not sure about this last param */);
#else
/* FIXME: stub */
return 1;
#endif
}
static INLINE int pthread_cond_wait(pthread_cond_t *cond,