Common shared memory module. Using O_CLOEXEC for opened files.

This commit is contained in:
sorgelig
2021-04-16 23:12:46 +08:00
parent 2899437499
commit 9cd404ea65
22 changed files with 186 additions and 240 deletions

View File

@@ -2,7 +2,6 @@
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <errno.h>
#include <sys/ioctl.h>
@@ -20,6 +19,7 @@
#include "menu.h"
#include "video.h"
#include "input.h"
#include "shmem.h"
#include "support.h"
#include "lib/imlib2/Imlib2.h"
@@ -576,16 +576,11 @@ static void fb_init()
{
if (!fb_base)
{
int fd = open("/dev/mem", O_RDWR | O_SYNC);
if (fd == -1) return;
fb_base = (volatile uint32_t*)mmap(0, FB_SIZE * 4 * 3, PROT_READ | PROT_WRITE, MAP_SHARED, fd, FB_ADDR);
if (fb_base == (void *)-1)
fb_base = (volatile uint32_t*)shmem_map(FB_ADDR, FB_SIZE * 4 * 3);
if (!fb_base)
{
printf("Unable to mmap FB!\n");
fb_base = 0;
}
close(fd);
}
spi_uio_cmd16(UIO_SET_FBUF, 0);
}
@@ -1068,7 +1063,7 @@ static uint64_t getus()
static void vs_wait()
{
int fb = open("/dev/fb0", O_RDWR);
int fb = open("/dev/fb0", O_RDWR | O_CLOEXEC);
int zero = 0;
uint64_t t1, t2;
if (ioctl(fb, FBIO_WAITFORVSYNC, &zero) == -1)
@@ -1139,7 +1134,7 @@ static Imlib_Image load_bg()
if (PathIsDir(bgdir))
{
int rndfd = open("/dev/urandom", O_RDONLY);
int rndfd = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
if (rndfd >= 0)
{
uint32_t rnd;
@@ -1383,7 +1378,7 @@ int video_chvt(int num)
{
cur_vt = num;
int fd;
if ((fd = open("/dev/tty0", O_RDONLY)) >= 0)
if ((fd = open("/dev/tty0", O_RDONLY | O_CLOEXEC)) >= 0)
{
if (ioctl(fd, VT_ACTIVATE, cur_vt)) printf("ioctl VT_ACTIVATE fails\n");
if (ioctl(fd, VT_WAITACTIVE, cur_vt)) printf("ioctl VT_WAITACTIVE fails\n");