Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shm key and drm for rawfb option, this will support both x11 and wayland. #227

Merged
merged 4 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4395,8 +4395,12 @@ Options:
whole frame).

For shared memory segments string is of the form:
"shm:N@WxHxB" which specifies a shmid N and with
"shm:N@WxHxB" which specifies a shm key(or a shmid) N and with
WxHxB as above. See shmat(1) and ipcs(1)

Since shm key can be defined constantly, you should use
shm key rather than shmid. Unless you have a special purpose,
a mutable shmid may cause problems.

If you do not supply a type "map" is assumed if
the file exists (see the next paragraphs for some
Expand Down
13 changes: 13 additions & 0 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,19 @@ if (db) fprintf(stderr, "initialize_raw_fb reset\n");
if (sscanf(str, "shm:%d", &shmid) == 1) {
/* shm:N */
#if HAVE_XSHM || HAVE_SHMAT
/* try to use shm key*/
key_t shmkey = 0;
size_t size = 0;
int newshmid = -1;

shmkey = shmid;
size = w * h * b / 8;
newshmid = shmget(shmkey, size, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the man page,

A new shared memory segment, with size equal to the value of size rounded up to a multiple of PAGE_SIZE, is created if key has the value IPC_PRIVATE or key isn't IPC_PRIVATE, no
shared memory segment corresponding to key exists, and IPC_CREAT is specified in shmflg.

So this likely breaks the original behaviour where the user enters some shmid and expects the shmat() down below to attach this. With this change, it's very likely that a new shared memory segment is created; this is not what the users expect.

Copy link
Contributor Author

@linex-cd linex-cd Jun 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I made a mistake. For an existed shared memory, the size for shmget should be 0. Then this will not alloc new shared memory segment and use the old way to seek shmid.
The change has committed, thanks for your review!

if (newshmid != -1) {
rfbLog("rawfb: use %d as shm key, shmid is %d \n", shmid, newshmid);
shmid = newshmid;
}

raw_fb_addr = (char *) shmat(shmid, 0, SHM_RDONLY);
if (! raw_fb_addr) {
rfbLogEnable(1);
Expand Down