Skip to content

Commit

Permalink
Remove SB impls of uprv_mapFile/uprv_unmapFile (#3812)
Browse files Browse the repository at this point in the history
Now that ICU data is linked into the binary, uprv_mapFile is no longer
used. uprv_unmapFile is still used but shouldn't need to do any work.

b/209049814
  • Loading branch information
hlwarriner committed Jul 11, 2024
1 parent 321d5bf commit b3f1f6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 101 deletions.
99 changes: 0 additions & 99 deletions third_party/icu/source/common/umapfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#include "udatamem.h"
#include "umapfile.h"

#if MAP_IMPLEMENTATION==MAP_STARBOARD
#include "starboard/extension/memory_mapped_file.h"
#endif

/* memory-mapping base definitions ------------------------------------------ */

#if MAP_IMPLEMENTATION==MAP_WIN32
Expand Down Expand Up @@ -99,14 +95,6 @@ typedef HANDLE MemoryMap;
typedef void *MemoryMap;

# define IS_MAP(map) ((map)!=nullptr)
#elif MAP_IMPLEMENTATION==MAP_STARBOARD
# include "starboard/file.h"
# include "cmemory.h"
# include <sys/mman.h>

typedef void *MemoryMap;

# define IS_MAP(map) ((map)!=NULL)
#endif

/*----------------------------------------------------------------------------*
Expand Down Expand Up @@ -352,93 +340,6 @@ typedef HANDLE MemoryMap;
}
}

#elif MAP_IMPLEMENTATION==MAP_STARBOARD
U_CFUNC UBool
uprv_mapFile(UDataMemory *pData, const char *path, UErrorCode *status) {
if (U_FAILURE(*status)) {
return FALSE;
}

UDataMemory_init(pData); /* Clear the output struct. */

/* open the input file */
SbFile file = SbFileOpen(path, kSbFileOpenOnly | kSbFileRead, NULL, NULL);
if (!SbFileIsValid(file)) {
return FALSE;
}

/* get the file length */
SbFileInfo info;
if (!SbFileGetInfo(file, &info)) {
SbFileClose(file);
return FALSE;
}

int32_t fileLength = info.size;
if (fileLength <= 20) {
SbFileClose(file);
return FALSE;
}

pData->heapAllocated = false;

const auto* memory_mapped_file_extension =
reinterpret_cast<const CobaltExtensionMemoryMappedFileApi*>(
SbSystemGetExtension(kCobaltExtensionMemoryMappedFileName));

if(memory_mapped_file_extension &&
strcmp(memory_mapped_file_extension->name,
kCobaltExtensionMemoryMappedFileName) == 0 &&
memory_mapped_file_extension->version >= 1) {
void *p = memory_mapped_file_extension->MemoryMapFile(
NULL, path, kSbMemoryMapProtectRead, 0,fileLength);
if(p) {
pData->map=p;
pData->pHeader=(const DataHeader *)p;
pData->mapAddr=p;
SbFileClose(file);
return TRUE;
}
// If mmap extension didn't work, fall back to allocating
}

/* allocate the memory to hold the file data */
void *p = uprv_malloc(fileLength);
if (!p) {
SbFileClose(file);
return FALSE;
}

/* read the file */
if (fileLength != SbFileReadAll(file, static_cast<char *>(p), fileLength)) {
uprv_free(p);
SbFileClose(file);
return FALSE;
}

SbFileClose(file);
pData->map=p;
pData->pHeader=(const DataHeader *)p;
pData->mapAddr=p;
pData->heapAllocated = true;
return TRUE;
}

U_CFUNC void
uprv_unmapFile(UDataMemory *pData) {
if(pData!=NULL && pData->map!=NULL) {
if(pData->heapAllocated) {
uprv_free(pData->map);
} else {
size_t dataLen = (char *)pData->map - (char *)pData->mapAddr;
munmap(pData->mapAddr, dataLen);
}
pData->map = NULL;
pData->mapAddr = NULL;
pData->pHeader = NULL;
}
}

#elif MAP_IMPLEMENTATION==MAP_390DLL
/* 390 specific Library Loading.
* This is the only platform left that dynamically loads an ICU Data Library.
Expand Down
8 changes: 6 additions & 2 deletions third_party/icu/source/common/umapfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ U_CFUNC void uprv_unmapFile(UDataMemory *pData);
#define MAP_POSIX 2
#define MAP_STDIO 3
#define MAP_390DLL 4
#define MAP_STARBOARD 5

#if UCONFIG_NO_FILE_IO
# define MAP_IMPLEMENTATION MAP_NONE
#elif (U_PLATFORM == U_STARBOARD)
# define MAP_IMPLEMENTATION MAP_STARBOARD
/*
* Starboard of course can provide file access, and real memory mapping on
* some platforms, but it's not needed here since ICU data is linked into
* the binary.
*/
# define MAP_IMPLEMENTATION MAP_NONE
#elif U_PLATFORM_USES_ONLY_WIN32_API
# define MAP_IMPLEMENTATION MAP_WIN32
#elif U_HAVE_MMAP || U_PLATFORM == U_PF_OS390
Expand Down

0 comments on commit b3f1f6d

Please sign in to comment.