diff options
author | 2021-01-06 19:09:16 +1100 | |
---|---|---|
committer | 2021-01-06 19:09:16 +1100 | |
commit | 8228719f036324734b804b1488c6233fe14b0b36 (patch) | |
tree | 3957e5e8515d11eabc00558690f7b83cc23743fb /src/devices | |
parent | 542cf128ba89e8554c6d595264b2b7b68b7fb25a (diff) |
Tidy up loose ends:
* Fixed a couple of fixed-size buffers in Windows OSD code.
* Marked MAME as aware of long paths in Windows manifest.
* Made a cleaner, thread-safe API for getting volume names.
* Added compile-time option to disable recompiler W^X mode.
* NuBus image device current directory doesn't need to be pinned.
Diffstat (limited to 'src/devices')
-rw-r--r-- | src/devices/bus/nubus/nubus_image.cpp | 67 | ||||
-rw-r--r-- | src/devices/bus/nubus/nubus_image.h | 4 | ||||
-rw-r--r-- | src/devices/cpu/drccache.cpp | 30 |
3 files changed, 54 insertions, 47 deletions
diff --git a/src/devices/bus/nubus/nubus_image.cpp b/src/devices/bus/nubus/nubus_image.cpp index 9d75788c469..5cdaabeb995 100644 --- a/src/devices/bus/nubus/nubus_image.cpp +++ b/src/devices/bus/nubus/nubus_image.cpp @@ -6,12 +6,26 @@ HFS images, including floppy images (DD and HD) and vMac/Basilisk HDD volumes up to 256 MB in size. + TODO: + * Get get directory and get listing commands have no way to indicate + that the path/name is too long for the buffer. + * The set directory command doesn't work well with host filesystems that + have roots (e.g. Windows drive letters). + * The set directory command assumes '/' is a valid host directory + separator character. + * The get listing commands have no way to indicate whether an entry is + a directory. + ***************************************************************************/ #include "emu.h" #include "nubus_image.h" + #include "osdcore.h" +#include <algorithm> + + #define IMAGE_ROM_REGION "image_rom" #define IMAGE_DISK0_TAG "nb_disk" @@ -189,10 +203,9 @@ void nubus_image_device::device_start() m_image = subdevice<messimg_disk_image_device>(IMAGE_DISK0_TAG); - filectx.curdir[0] = '.'; - filectx.curdir[1] = '\0'; - filectx.dirp = nullptr; - filectx.fd = nullptr; + filectx.curdir = "."; + filectx.dirp.reset(); + filectx.fd.reset(); } //------------------------------------------------- @@ -249,55 +262,51 @@ void nubus_image_device::file_cmd_w(uint32_t data) { // data = ((data & 0xff) << 24) | ((data & 0xff00) << 8) | ((data & 0xff0000) >> 8) | ((data & 0xff000000) >> 24); filectx.curcmd = data; - switch(data) { + switch (data) { case kFileCmdGetDir: - strcpy((char*)filectx.filename, (char*)filectx.curdir); + strncpy(filectx.filename, filectx.curdir.c_str(), ARRAY_LENGTH(filectx.filename)); break; case kFileCmdSetDir: if ((filectx.filename[0] == '/') || (filectx.filename[0] == '$')) { - strcpy((char*)filectx.curdir, (char*)filectx.filename); + filectx.curdir.assign(std::begin(filectx.filename), std::find(std::begin(filectx.filename), std::end(filectx.filename), '\0')); } else { - strcat((char*)filectx.curdir, "/"); - strcat((char*)filectx.curdir, (char*)filectx.filename); + filectx.curdir += '/'; + filectx.curdir.append(std::begin(filectx.filename), std::find(std::begin(filectx.filename), std::end(filectx.filename), '\0')); } break; case kFileCmdGetFirstListing: - filectx.dirp = osd::directory::open((const char *)filectx.curdir); + filectx.dirp = osd::directory::open(filectx.curdir); [[fallthrough]]; case kFileCmdGetNextListing: if (filectx.dirp) { osd::directory::entry const *const dp = filectx.dirp->read(); - if(dp) { - strncpy((char*)filectx.filename, dp->name, sizeof(filectx.filename)); + if (dp) { + strncpy(filectx.filename, dp->name, ARRAY_LENGTH(filectx.filename)); } else { - memset(filectx.filename, 0, sizeof(filectx.filename)); + std::fill(std::begin(filectx.filename), std::end(filectx.filename), '\0'); } } else { - memset(filectx.filename, 0, sizeof(filectx.filename)); + std::fill(std::begin(filectx.filename), std::end(filectx.filename), '\0'); } break; case kFileCmdGetFile: { - std::string fullpath; - fullpath.reserve(1024); - fullpath.assign((const char *)filectx.curdir); - fullpath.append(PATH_SEPARATOR); - fullpath.append((const char*)filectx.filename); - if(osd_file::open(fullpath, OPEN_FLAG_READ, filectx.fd, filectx.filelen) != osd_file::error::NONE) + std::string fullpath(filectx.curdir); + fullpath += PATH_SEPARATOR; + fullpath.append(std::begin(filectx.filename), std::find(std::begin(filectx.filename), std::end(filectx.filename), '\0')); + if (osd_file::open(fullpath, OPEN_FLAG_READ, filectx.fd, filectx.filelen) != osd_file::error::NONE) osd_printf_error("Error opening %s\n", fullpath); filectx.bytecount = 0; } break; case kFileCmdPutFile: { - std::string fullpath; - fullpath.reserve(1024); - fullpath.assign((const char *)filectx.curdir); - fullpath.append(PATH_SEPARATOR); - fullpath.append((const char*)filectx.filename); + std::string fullpath(filectx.curdir); + fullpath += PATH_SEPARATOR; + fullpath.append(std::begin(filectx.filename), std::find(std::begin(filectx.filename), std::end(filectx.filename), '\0')); uint64_t filesize; // unused, but it's an output from the open call - if(osd_file::open(fullpath, OPEN_FLAG_WRITE|OPEN_FLAG_CREATE, filectx.fd, filesize) != osd_file::error::NONE) + if (osd_file::open(fullpath, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, filectx.fd, filesize) != osd_file::error::NONE) osd_printf_error("Error opening %s\n", fullpath); filectx.bytecount = 0; } @@ -356,12 +365,10 @@ uint32_t nubus_image_device::file_len_r() void nubus_image_device::file_name_w(offs_t offset, uint32_t data) { - ((uint32_t*)(filectx.filename))[offset] = big_endianize_int32(data); + reinterpret_cast<uint32_t *>(filectx.filename)[offset] = big_endianize_int32(data); } uint32_t nubus_image_device::file_name_r(offs_t offset) { - uint32_t ret; - ret = big_endianize_int32(((uint32_t*)(filectx.filename))[offset]); - return ret; + return big_endianize_int32(reinterpret_cast<uint32_t const *>(filectx.filename)[offset]); } diff --git a/src/devices/bus/nubus/nubus_image.h b/src/devices/bus/nubus/nubus_image.h index 9ead3fd1a53..c6dcf6db388 100644 --- a/src/devices/bus/nubus/nubus_image.h +++ b/src/devices/bus/nubus/nubus_image.h @@ -38,8 +38,8 @@ protected: struct nbfilectx { uint32_t curcmd; - uint8_t filename[128]; - uint8_t curdir[1024]; + char filename[128]; + std::string curdir; osd::directory::ptr dirp; osd_file::ptr fd; uint64_t filelen; diff --git a/src/devices/cpu/drccache.cpp b/src/devices/cpu/drccache.cpp index 44ff2cf9371..e75305cc6ba 100644 --- a/src/devices/cpu/drccache.cpp +++ b/src/devices/cpu/drccache.cpp @@ -14,6 +14,10 @@ #include <algorithm> +// this improves performance of some emulated systems but doesn't work on W^X hosts +//#define MAME_DRC_CACHE_RWX + + namespace { template <typename T, typename U> constexpr T *ALIGN_PTR_UP(T *p, U align) @@ -59,7 +63,11 @@ drc_cache::drc_cache(size_t bytes) : std::fill(std::begin(m_free), std::end(m_free), nullptr); std::fill(std::begin(m_nearfree), std::end(m_nearfree), nullptr); +#if defined(MAME_DRC_CACHE_RWX) + m_cache.set_access(0, m_size, osd::virtual_memory_allocation::READ_WRITE | osd::virtual_memory_allocation::EXECUTE); +#else // defined(MAME_DRC_CACHE_RWX) m_cache.set_access(0, m_size, osd::virtual_memory_allocation::READ_WRITE); +#endif // defined(MAME_DRC_CACHE_RWX) } @@ -84,11 +92,7 @@ void drc_cache::flush() // just reset the top back to the base and re-seed m_top = m_base; - if (m_executable) - { - m_cache.set_access(0, m_size, osd::virtual_memory_allocation::READ_WRITE); - m_executable = false; - } + codegen_init(); } @@ -174,11 +178,7 @@ void *drc_cache::alloc_temporary(size_t bytes) return nullptr; // otherwise, update the cache top - if (m_executable) - { - m_cache.set_access(0, m_size, osd::virtual_memory_allocation::READ_WRITE); - m_executable = false; - } + codegen_init(); m_top = ALIGN_PTR_UP(ptr + bytes, CACHE_ALIGNMENT); return ptr; } @@ -209,7 +209,9 @@ void drc_cache::codegen_init() { if (m_executable) { +#if !defined(MAME_DRC_CACHE_RWX) m_cache.set_access(0, m_size, osd::virtual_memory_allocation::READ_WRITE); +#endif // !defined(MAME_DRC_CACHE_RWX) m_executable = false; } } @@ -219,7 +221,9 @@ void drc_cache::codegen_complete() { if (!m_executable) { +#if !defined(MAME_DRC_CACHE_RWX) m_cache.set_access(m_base - m_near, ALIGN_PTR_UP(m_top, m_cache.page_size()) - m_base, osd::virtual_memory_allocation::READ_EXECUTE); +#endif // !defined(MAME_DRC_CACHE_RWX) m_executable = true; } } @@ -240,11 +244,7 @@ drccodeptr *drc_cache::begin_codegen(uint32_t reserve_bytes) return nullptr; // otherwise, return a pointer to the cache top - if (m_executable) - { - m_cache.set_access(0, m_size, osd::virtual_memory_allocation::READ_WRITE); - m_executable = false; - } + codegen_init(); m_codegen = m_top; return &m_top; } |