windows mmap

This commit is contained in:
lixianjing 2020-12-11 22:46:12 +08:00
parent 4b1b129280
commit 9ca1a25f0f
5 changed files with 212 additions and 16 deletions

View File

@ -1156,6 +1156,8 @@ EXPORTS
tk_free
tk_mem_dump
tk_mem_is_valid_addr
mmap_create
mmap_destroy
tk_mutex_nest_create
tk_mutex_nest_lock
tk_mutex_nest_try_lock
@ -1724,6 +1726,7 @@ EXPORTS
scroll_view_set_virtual_h
scroll_view_set_xslidable
scroll_view_set_yslidable
scroll_view_set_snap_to_page
scroll_view_set_offset
scroll_view_set_speed_scale
scroll_view_scroll_to

View File

@ -347,6 +347,8 @@ EXPORTS
tk_free
tk_mem_dump
tk_mem_is_valid_addr
mmap_create
mmap_destroy
tk_mutex_nest_create
tk_mutex_nest_lock
tk_mutex_nest_try_lock

View File

@ -31,25 +31,24 @@
mmap_t* mmap_create(const char* filename, bool_t writable, bool_t shared) {
#ifdef WIN32
DWORD err = 0;
mmap_t* map = NULL;
wchar_t wfilename[MAX_PATH + 1];
HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE handle = INVALID_HANDLE_VALUE;
DWORD flProtect = writable ? PAGE_READWRITE : PAGE_READONLY;
DWORD dwDesiredAccess = writable ? GENERIC_WRITE : GENERIC_READ;
DWORD dwDesiredAccess = writable ? GENERIC_WRITE | GENERIC_READ : GENERIC_READ;
uint32_t size = file_get_size(filename);
return_value_if_fail(filename != NULL && size > 0, NULL);
map = TKMEM_ZALLOC(mmap_t);
goto_error_if_fail(map != NULL);
tk_utf8_to_utf16(filename, wfilename, MAX_PATH);
hFile = CreateFileW(wfilename,
dwDesiredAccess,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
return_value_if_fail(hFile != INVALID_HANDLE_VALUE, NULL);
handle = CreateFileMapping(hFile, NULL, flProtect, DWORD_HI(0), DWORD_LO(size), NULL);
hFile =
CreateFileW(wfilename, dwDesiredAccess, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
goto_error_if_fail(hFile != INVALID_HANDLE_VALUE);
handle = CreateFileMapping(hFile, NULL, flProtect, 0, size, NULL);
goto_error_if_fail(handle != NULL);
dwDesiredAccess = shared ? FILE_MAP_WRITE : FILE_MAP_READ;
map->size = size;
@ -59,6 +58,8 @@ mmap_t* mmap_create(const char* filename, bool_t writable, bool_t shared) {
return map;
error:
err = GetLastError();
log_debug("err=%u\n", err);
if (hFile != INVALID_HANDLE_VALUE) {
CloseHandle(hFile);
}

View File

@ -33310,6 +33310,83 @@
},
"level": 1
},
{
"type": "class",
"methods": [
{
"params": [
{
"type": "mmap_t*",
"name": "mmap",
"desc": "mmap对象。"
},
{
"type": "const char*",
"name": "filename",
"desc": "文件名。"
},
{
"type": "bool_t",
"name": "writable",
"desc": "是否可写。"
},
{
"type": "bool_t",
"name": "shared",
"desc": "是否共享。"
}
],
"annotation": {
"constructor": true
},
"desc": "初始化mmap对象。",
"name": "mmap_create",
"return": {
"type": "mmap_t*",
"desc": "mmap对象本身。"
}
},
{
"params": [
{
"type": "mmap_t*",
"name": "mmap",
"desc": "mmap对象。"
}
],
"annotation": {},
"desc": "销毁mmap。",
"name": "mmap_destroy",
"return": {
"type": "ret_t",
"desc": "返回RET_OK表示成功否则表示失败。"
}
}
],
"events": [],
"properties": [
{
"name": "data",
"desc": "内存地址。",
"type": "void*",
"annotation": {
"readable": true
}
},
{
"name": "size",
"desc": "数据长度。",
"type": "uint32_t",
"annotation": {
"readable": true
}
}
],
"header": "tkc/mmap.h",
"desc": "把文件内容映射到内存。",
"name": "mmap_t",
"level": 1
},
{
"type": "class",
"methods": [
@ -49712,6 +49789,29 @@
"desc": "返回RET_OK表示成功否则表示失败。"
}
},
{
"params": [
{
"type": "widget_t*",
"name": "widget",
"desc": "控件对象。"
},
{
"type": "bool_t",
"name": "snap_to_page",
"desc": "是否按页面对齐。"
}
],
"annotation": {
"scriptable": true
},
"desc": "设置滚动时offset是否按页面对齐。",
"name": "scroll_view_set_snap_to_page",
"return": {
"type": "ret_t",
"desc": "返回RET_OK表示成功否则表示失败。"
}
},
{
"params": [
{
@ -49750,12 +49850,12 @@
{
"type": "float_t",
"name": "xspeed_scale",
"desc": "x偏移速度比例。"
"desc": "x偏移速度比例。"
},
{
"type": "float_t",
"name": "yspeed_scale",
"desc": "y偏移速度比例。"
"desc": "y偏移速度比例。"
}
],
"annotation": {
@ -49956,6 +50056,19 @@
"design": true,
"scriptable": true
}
},
{
"name": "snap_to_page",
"desc": "滚动时offset是否按页面对齐。",
"type": "bool_t",
"annotation": {
"set_prop": true,
"get_prop": true,
"readable": true,
"persitent": true,
"design": true,
"scriptable": true
}
}
],
"header": "scroll_view/scroll_view.h",

View File

@ -9578,6 +9578,83 @@
},
"level": 1
},
{
"type": "class",
"methods": [
{
"params": [
{
"type": "mmap_t*",
"name": "mmap",
"desc": "mmap对象。"
},
{
"type": "const char*",
"name": "filename",
"desc": "文件名。"
},
{
"type": "bool_t",
"name": "writable",
"desc": "是否可写。"
},
{
"type": "bool_t",
"name": "shared",
"desc": "是否共享。"
}
],
"annotation": {
"constructor": true
},
"desc": "初始化mmap对象。",
"name": "mmap_create",
"return": {
"type": "mmap_t*",
"desc": "mmap对象本身。"
}
},
{
"params": [
{
"type": "mmap_t*",
"name": "mmap",
"desc": "mmap对象。"
}
],
"annotation": {},
"desc": "销毁mmap。",
"name": "mmap_destroy",
"return": {
"type": "ret_t",
"desc": "返回RET_OK表示成功否则表示失败。"
}
}
],
"events": [],
"properties": [
{
"name": "data",
"desc": "内存地址。",
"type": "void*",
"annotation": {
"readable": true
}
},
{
"name": "size",
"desc": "数据长度。",
"type": "uint32_t",
"annotation": {
"readable": true
}
}
],
"header": "tkc/mmap.h",
"desc": "把文件内容映射到内存。",
"name": "mmap_t",
"level": 1
},
{
"type": "class",
"methods": [