Skip to content

Commit 831badc

Browse files
Refactored mmap compatibility.
- Added HAVE_MMAP definition. - Made mmap usage dependent on HAVE_MMAP. - Removed mmap compatibility from platform.h
1 parent f94f092 commit 831badc

3 files changed

Lines changed: 19 additions & 27 deletions

File tree

libnvme/src/platform/windows.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,6 @@ static inline int sigaction(int signum, const struct sigaction *act,
221221
#define mkdir(path, mode) _mkdir(path)
222222

223223

224-
/* mman.h memory mapping stubs - not supported on Windows */
225-
226-
#define PROT_READ 0x1
227-
#define PROT_WRITE 0x2
228-
#define MAP_SHARED 0x01
229-
#define MAP_FAILED ((void *) -1)
230-
231-
static inline void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
232-
{
233-
(void)addr; (void)length; (void)prot; (void)flags; (void)fd; (void)offset;
234-
errno = ENOSYS;
235-
return MAP_FAILED;
236-
}
237-
238-
static inline int munmap(void *addr, size_t length)
239-
{
240-
(void)addr; (void)length;
241-
errno = ENOSYS;
242-
return -1;
243-
}
244-
245-
246224
/* dlfcn.h compatibility */
247225

248226
static inline void *dlsym(void *handle, const char *symbol)

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ conf.set(
427427

428428
conf.set('NVME_HAVE_SENDFILE', cc.has_function('sendfile'))
429429

430+
conf.set('HAVE_MMAP', cc.has_function('mmap'))
431+
430432
project_config_file = 'nvme-config.h'
431433
nvme_config_h = configure_file(output: project_config_file, configuration: conf)
432434
config_dep = declare_dependency(

nvme.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ struct nvme_args nvme_args = {
253253
};
254254

255255
static void *mmap_registers(struct libnvme_transport_handle *hdl, bool writable);
256+
static int munmap_registers(void *addr);
256257

257258
static OPT_VALS(feature_name) = {
258259
VAL_BYTE("arbitration", NVME_FEAT_FID_ARBITRATION),
@@ -1103,7 +1104,7 @@ static int get_effects_log(int argc, char **argv, struct command *acmd, struct p
11031104

11041105
if (bar) {
11051106
cap = mmio_read64(bar + NVME_REG_CAP);
1106-
munmap(bar, getpagesize());
1107+
munmap_registers(bar);
11071108
} else {
11081109
nvme_init_get_property(&cmd, NVME_REG_CAP);
11091110
err = libnvme_submit_admin_passthru(hdl, &cmd);
@@ -5798,8 +5799,9 @@ static int nvme_get_properties(struct libnvme_transport_handle *hdl, void **pbar
57985799

57995800
static void *mmap_registers(struct libnvme_transport_handle *hdl, bool writable)
58005801
{
5802+
void *membase = NULL;
5803+
#ifdef HAVE_MMAP
58015804
char path[512];
5802-
void *membase;
58035805
int fd;
58045806
int prot = PROT_READ;
58055807

@@ -5828,9 +5830,19 @@ static void *mmap_registers(struct libnvme_transport_handle *hdl, bool writable)
58285830
}
58295831

58305832
close(fd);
5833+
#endif
58315834
return membase;
58325835
}
58335836

5837+
static int munmap_registers(void *addr)
5838+
{
5839+
#ifdef HAVE_MMAP
5840+
return munmap(addr, getpagesize());
5841+
#else
5842+
return 0;
5843+
#endif
5844+
}
5845+
58345846
static int show_registers(int argc, char **argv, struct command *acmd, struct plugin *plugin)
58355847
{
58365848
const char *desc = "Reads and shows the defined NVMe controller registers\n"
@@ -5882,7 +5894,7 @@ static int show_registers(int argc, char **argv, struct command *acmd, struct pl
58825894
if (cfg.fabrics)
58835895
free(bar);
58845896
else
5885-
munmap(bar, getpagesize());
5897+
munmap_registers(bar);
58865898

58875899
return 0;
58885900
}
@@ -6167,7 +6179,7 @@ static int get_register(int argc, char **argv, struct command *acmd, struct plug
61676179
if (fabrics)
61686180
free(bar);
61696181
else
6170-
munmap(bar, getpagesize());
6182+
munmap_registers(bar);
61716183

61726184
return err;
61736185
}
@@ -6451,7 +6463,7 @@ static int set_register(int argc, char **argv, struct command *acmd, struct plug
64516463
err = set_register_names(hdl, bar, opts, &cfg);
64526464

64536465
if (bar)
6454-
munmap(bar, getpagesize());
6466+
munmap_registers(bar);
64556467

64566468
return err;
64576469
}

0 commit comments

Comments
 (0)