Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
bc38458d
Commit
bc38458d
authored
Oct 23, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
d27af7e8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
10 deletions
+43
-10
wcfs/internal/wcfs_misc.cpp
wcfs/internal/wcfs_misc.cpp
+6
-2
wcfs/internal/wcfs_misc.h
wcfs/internal/wcfs_misc.h
+4
-4
wcfs/internal/wcfs_virtmem.cpp
wcfs/internal/wcfs_virtmem.cpp
+33
-4
No files found.
wcfs/internal/wcfs_misc.cpp
View file @
bc38458d
...
...
@@ -21,9 +21,13 @@
#include "wcfs_misc.h"
#include <golang/libgolang.h>
using
namespace
golang
;
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <memory>
...
...
@@ -86,10 +90,10 @@ namespace mm {
// flags is MAP_* from mmap(2); MAP_FIXED is added to flags.
//
// XXX split from File?
error
map_into
(
void
*
addr
,
size_t
size
,
int
prot
,
int
flags
,
const
File
&
f
,
off_t
offset
)
{
error
map_into
(
void
*
addr
,
size_t
size
,
int
prot
,
int
flags
,
const
os
::
File
&
f
,
off_t
offset
)
{
void
*
addr2
;
addr2
=
mmap
(
addr
,
size
,
PROT_READ
,
MAP_FIXED
|
MAP_SHARED
,
f
->
fd
(),
offset
);
addr2
=
mmap
(
addr
,
size
,
prot
,
MAP_FIXED
|
flags
,
f
.
fd
(),
offset
);
if
(
addr2
==
MAP_FAILED
)
return
_pathError
(
"mmap"
,
f
.
name
(),
errno
);
if
(
addr2
!=
addr
)
...
...
wcfs/internal/wcfs_misc.h
View file @
bc38458d
...
...
@@ -63,8 +63,8 @@ class File {
public:
friend
tuple
<
File
,
error
>
open
(
const
string
&
path
,
int
flags
,
mode_t
mode
);
// XXX empty ctor -> fd=-1, path=?
int
fd
()
;
string
name
()
;
int
fd
()
const
;
string
name
()
const
;
error
close
();
error
stat
(
struct
stat
*
st
);
...
...
wcfs/internal/wcfs_virtmem.cpp
View file @
bc38458d
...
...
@@ -58,8 +58,10 @@ typedef uint64_t Oid; // XXX ok?
// TidHead is invalid Tid which is larged Tid value and means @head
const
Tid
TidHead
=
-
1ULL
;
string
h
(
uint64_t
v
);
// v -> 016x hex representation
st
atic
st
ring
h
(
uint64_t
v
);
// v -> 016x hex representation
#define h_(v) (h(v).c_str())
static
error
mmap_zero_into_ro
(
void
*
addr
,
size_t
size
);
// XXX ok?
...
...
@@ -275,11 +277,12 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
// block is beyond file size - mmap with zeros - else access to memory
// after file.size will raise SIGBUS. (assumes head/f size ↑=)
if
((
blk
+
1
)
*
f
->
blksize
>
st
.
st_size
)
{
mm
.
map_zero_into_ro
(
blkmem
);
// XXX err
err
=
mmap_zero_into_ro
(
blkmem
,
1
*
f
->
blksize
);
// XXX err handle
}
// block is inside file - mmap file data
else
{
err
=
mm
::
map_into
(
blkmem
,
f
->
blksize
,
PROT_READ
,
MAP_SHARED
,
fsfile
,
blk
*
f
->
blksize
);
err
=
mm
::
map_into
(
blkmem
,
1
*
f
->
blksize
,
PROT_READ
,
MAP_SHARED
,
fsfile
,
blk
*
f
->
blksize
);
// XXX err handle
}
...
...
@@ -306,6 +309,32 @@ tuple<os::File, error> WCFS::_open(const string &path, int flags) {
// ---- misc ----
string
h
(
uint64_t
v
)
{
st
atic
st
ring
h
(
uint64_t
v
)
{
return
fmt
::
sprintf
(
"%016x"
,
v
);
}
// map_zero_ro mmaps read-only zeros into [addr +size) so that region as all zeros.
// created mapping, even after it is accessed, does not consume memory.
static
error
_mmap_zero_into_ro
(
void
*
addr
,
size_t
size
);
static
error
mmap_zero_into_ro
(
void
*
addr
,
size_t
size
)
{
error
err
=
_mmap_zero_into_ro
(
addr
,
size
);
if
(
err
!=
nil
)
err
=
fmt
::
errorf
(
"mmap zero"
);
// XXX -> xerr::contextf?
return
err
;
}
static
error
_mmap_zero_into_ro
(
void
*
addr
,
size_t
size
)
{
// mmap /dev/zero with MAP_NORESERVE and MAP_SHARED
// this way the mapping will be able to be read, but no memory will be allocated to keep it.
os
::
File
z
;
error
err
;
tie
(
z
,
err
)
=
os
::
open
(
"/dev/zero"
);
if
(
err
!=
nil
)
return
err
;
defer
([
&
]()
{
z
.
close
();
});
err
=
mm
::
map_into
(
addr
,
size
,
PROT_READ
,
MAP_SHARED
|
MAP_NORESERVE
,
z
,
0
);
if
(
err
!=
nil
)
return
err
;
return
nil
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment