Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Software
Commits
f93b99e8
Commit
f93b99e8
authored
Jan 27, 2021
by
Adam Wujek
Committed by
Adam Wujek
Feb 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature:
#227
] userspace/libwr: allow writer to reopen shmem
Signed-off-by:
Adam Wujek
<
dev_public@wujek.eu
>
parent
926d79b6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
9 deletions
+36
-9
shmem.h
userspace/libwr/include/libwr/shmem.h
+1
-0
shmem.c
userspace/libwr/shmem.c
+35
-9
No files found.
userspace/libwr/include/libwr/shmem.h
View file @
f93b99e8
...
...
@@ -9,6 +9,7 @@
#define WRS_SHM_DEFAULT_PATH "/dev/shm"
#define WRS_SHM_FILE "wrs-shmem-%i"
#define WRS_SHM_MAPADDR 0x10000000
#define WRS_SHM_MIN_SIZE (4*1024)
#define WRS_SHM_MAX_SIZE (512*1024)
...
...
userspace/libwr/shmem.c
View file @
f93b99e8
...
...
@@ -49,6 +49,7 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
char
fname
[
64
];
int
write_access
=
flags
&
WRS_SHM_WRITE
;
int
fd
;
void
*
prev_mapbase
;
if
(
name_id
>=
WRS_SHM_N_NAMES
)
{
errno
=
EINVAL
;
...
...
@@ -70,7 +71,8 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
write
(
fd
,
""
,
1
);
}
map
=
mmap
(
0
,
WRS_SHM_MAX_SIZE
,
map
=
mmap
((
void
*
)(
WRS_SHM_MAPADDR
+
WRS_SHM_MAX_SIZE
*
name_id
),
WRS_SHM_MAX_SIZE
,
PROT_READ
|
(
write_access
?
PROT_WRITE
:
0
),
MAP_SHARED
,
fd
,
0
);
if
(
map
==
MAP_FAILED
)
{
...
...
@@ -110,21 +112,45 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
close
(
fd
);
return
NULL
;
}
head
->
fd
=
fd
;
head
->
sequence
=
1
;
/* a sort of lock */
/* Set mapbase only for the first call of wrs_shm_get.
* At further calls (probably due to a restart of a writ
ter/writ
er),
* At further calls (probably due to a restart of a writer),
* this is used by wrs_shm_follow to calculate the offset of a given
* pointer from the beginning of shmem. */
if
(
!
head
->
mapbase
)
head
->
mapbase
=
head
;
if
(
!
head
->
mapbase
||
head
->
mapbase
==
head
)
{
head
->
mapbase
=
head
;
head
->
data_off
=
sizeof
(
*
head
);
head
->
data_size
=
0
;
}
else
{
/* try to remap at the previous mapbase */
prev_mapbase
=
head
->
mapbase
;
munmap
(
map
,
WRS_SHM_MAX_SIZE
);
/* Do not use MAP_FIXED because it unmaps previous mappings
* that overlap with the current one */
map
=
mmap
(
prev_mapbase
,
WRS_SHM_MAX_SIZE
,
PROT_READ
|
(
write_access
?
PROT_WRITE
:
0
),
MAP_SHARED
,
fd
,
0
);
if
(
map
==
MAP_FAILED
)
{
close
(
fd
);
return
NULL
;
/* keep errno */
}
if
(
map
!=
prev_mapbase
)
{
/* mapped at the different address than expected,
* clean the mapped memory (pointers may be unusable)*/
memset
(
map
,
0
,
stbuf
.
st_size
);
}
head
=
map
;
/* Keep data_off and data_size as it was to allow further
* memory allocations */
}
head
->
fd
=
fd
;
strncpy
(
head
->
name
,
name
,
sizeof
(
head
->
name
));
head
->
name
[
sizeof
(
head
->
name
)
-
1
]
=
'\0'
;
head
->
stamp
=
0
;
head
->
data_off
=
sizeof
(
*
head
);
head
->
data_size
=
0
;
if
(
flags
&
wrs_shm_locked
)
head
->
sequence
=
1
;
/* a sort of lock */
else
...
...
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