diff --git a/lib/libcuse/cuse_lib.c b/lib/libcuse/cuse_lib.c --- a/lib/libcuse/cuse_lib.c +++ b/lib/libcuse/cuse_lib.c @@ -1,6 +1,6 @@ /* $FreeBSD$ */ /*- - * Copyright (c) 2010-2012 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2010-2022 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -142,7 +142,7 @@ uint8_t *ptr_max; uint8_t *ptr = _ptr; unsigned long remainder; - int n; + unsigned long n; CUSE_LOCK(); for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) { @@ -158,9 +158,10 @@ remainder = (ptr - ptr_min); - remainder -= remainder % PAGE_SIZE; + remainder -= remainder % + (unsigned long)getpagesize(); - return ((n * PAGE_SIZE * CUSE_ALLOC_PAGES_MAX) + remainder); + return ((n * CUSE_ALLOC_BYTES_MAX) + remainder); } } CUSE_UNLOCK(); @@ -172,9 +173,10 @@ cuse_vmalloc(int size) { struct cuse_alloc_info info; + unsigned long pgsize; + unsigned long n; void *ptr; int error; - int n; if (f_cuse < 0) return (NULL); @@ -184,7 +186,8 @@ if (size < 1) return (NULL); - info.page_count = howmany(size, PAGE_SIZE); + pgsize = getpagesize(); + info.page_count = howmany(size, pgsize); CUSE_LOCK(); for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) { @@ -212,10 +215,9 @@ else break; } - ptr = mmap(NULL, info.page_count * PAGE_SIZE, + ptr = mmap(NULL, info.page_count * pgsize, PROT_READ | PROT_WRITE, - MAP_SHARED, f_cuse, CUSE_ALLOC_PAGES_MAX * - PAGE_SIZE * n); + MAP_SHARED, f_cuse, CUSE_ALLOC_BYTES_MAX * n); if (ptr == MAP_FAILED) { diff --git a/sys/fs/cuse/cuse.c b/sys/fs/cuse/cuse.c --- a/sys/fs/cuse/cuse.c +++ b/sys/fs/cuse/cuse.c @@ -1,6 +1,6 @@ /* $FreeBSD$ */ /*- - * Copyright (c) 2010-2020 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2010-2022 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -64,6 +64,13 @@ #include #include +#define CUSE_ALLOC_PAGES_MAX \ + (CUSE_ALLOC_BYTES_MAX / PAGE_SIZE) + +#if (CUSE_ALLOC_PAGES_MAX == 0) +#error "PAGE_SIZE is too big!" +#endif + static int cuse_modevent(module_t mod, int type, void *data) { diff --git a/sys/fs/cuse/cuse_ioctl.h b/sys/fs/cuse/cuse_ioctl.h --- a/sys/fs/cuse/cuse_ioctl.h +++ b/sys/fs/cuse/cuse_ioctl.h @@ -1,6 +1,6 @@ /* $FreeBSD$ */ /*- - * Copyright (c) 2014 Hans Petter Selasky. All rights reserved. + * Copyright (c) 2014-2022 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,13 +30,13 @@ #include #include -#define CUSE_BUFFER_MAX PAGE_SIZE +#define CUSE_BUFFER_MAX (1 << 12) /* bytes */ #define CUSE_DEVICES_MAX 64 /* units */ #define CUSE_BUF_MIN_PTR 0x10000UL #define CUSE_BUF_MAX_PTR 0x20000UL #define CUSE_ALLOC_UNIT_MAX 128 /* units */ /* All memory allocations must be less than the following limit */ -#define CUSE_ALLOC_PAGES_MAX (((16UL * 1024UL * 1024UL) + PAGE_SIZE - 1) / PAGE_SIZE) +#define CUSE_ALLOC_BYTES_MAX (1UL << 24) /* bytes */ struct cuse_dev;