mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-18 14:34:04 +08:00
Add mmap
This commit is contained in:

committed by
Christian Mauderer

parent
bc2ba9a9cd
commit
b68ca55c96
@@ -30,8 +30,10 @@
|
||||
*/
|
||||
|
||||
#include <machine/rtems-bsd-kernel-space.h>
|
||||
#include <machine/vm.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <rtems/seterr.h>
|
||||
|
||||
@@ -46,6 +48,7 @@ static d_write_t testwrite;
|
||||
static d_ioctl_t testioctl;
|
||||
static d_poll_t testpoll;
|
||||
static d_kqfilter_t testkqfilter;
|
||||
static d_mmap_t testmmap;
|
||||
|
||||
static struct cdevsw test_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
@@ -59,6 +62,7 @@ static struct cdevsw test_cdevsw = {
|
||||
.d_ioctl = testioctl,
|
||||
.d_poll = testpoll,
|
||||
.d_kqfilter = testkqfilter,
|
||||
.d_mmap = testmmap,
|
||||
};
|
||||
|
||||
static int
|
||||
@@ -77,7 +81,7 @@ testclose(struct cdev *dev, int fflag, int devtype, struct thread *td)
|
||||
{
|
||||
test_state *state = dev->si_drv1;
|
||||
|
||||
assert(*state == TEST_KQFILTER);
|
||||
assert(*state == TEST_MMAP);
|
||||
*state = TEST_CLOSED;
|
||||
|
||||
return 0;
|
||||
@@ -148,6 +152,21 @@ testkqfilter(struct cdev *dev, struct knote *kn)
|
||||
return TEST_KQ_ERRNO;
|
||||
}
|
||||
|
||||
static int
|
||||
testmmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
|
||||
int nprot, vm_memattr_t *memattr)
|
||||
{
|
||||
test_state *state = dev->si_drv1;
|
||||
|
||||
assert(paddr != NULL);
|
||||
assert(memattr == VM_MEMATTR_DEFAULT);
|
||||
assert(nprot == (PROT_READ | PROT_WRITE));
|
||||
assert(*state == TEST_KQFILTER);
|
||||
*state = TEST_MMAP;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
test_make_dev(test_state *state, const char *name)
|
||||
{
|
||||
|
@@ -42,7 +42,8 @@ typedef enum {
|
||||
TEST_WRITEV,
|
||||
TEST_POLL,
|
||||
TEST_KQFILTER,
|
||||
TEST_CLOSED
|
||||
TEST_MMAP,
|
||||
TEST_CLOSED,
|
||||
} test_state;
|
||||
|
||||
void test_make_dev(test_state *state, const char *name);
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
@@ -125,6 +126,9 @@ static void test_cdev(const char *path)
|
||||
assert(rv == -1);
|
||||
assert(errno == TEST_KQ_ERRNO);
|
||||
|
||||
rv = mmap(NULL, 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
assert(rv == 0);
|
||||
|
||||
rv = close(fd);
|
||||
assert(rv == 0);
|
||||
|
||||
|
Reference in New Issue
Block a user