| 716 | } |
| 717 | |
| 718 | int |
| 719 | rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, |
| 720 | unsigned int elt_sz) |
| 721 | { |
| 722 | size_t page_sz, mmap_len; |
| 723 | char path[PATH_MAX]; |
| 724 | struct used_mask *msk; |
| 725 | struct mem_area *ma = NULL; |
| 726 | void *data = NULL; |
| 727 | int fd = -1; |
| 728 | const struct internal_config *internal_conf = |
| 729 | eal_get_internal_configuration(); |
| 730 | |
| 731 | if (arr == NULL) { |
| 732 | rte_errno = EINVAL; |
| 733 | return -1; |
| 734 | } |
| 735 | |
| 736 | if (fully_validate(name, elt_sz, len)) |
| 737 | return -1; |
| 738 | |
| 739 | /* allocate mem area before doing anything */ |
| 740 | ma = malloc(sizeof(*ma)); |
| 741 | if (ma == NULL) { |
| 742 | rte_errno = ENOMEM; |
| 743 | return -1; |
| 744 | } |
| 745 | |
| 746 | page_sz = rte_mem_page_size(); |
| 747 | if (page_sz == (size_t)-1) { |
| 748 | free(ma); |
| 749 | return -1; |
| 750 | } |
| 751 | |
| 752 | /* calculate our memory limits */ |
| 753 | mmap_len = calc_data_size(page_sz, elt_sz, len); |
| 754 | |
| 755 | data = eal_get_virtual_area(NULL, &mmap_len, page_sz, 0, 0); |
| 756 | if (data == NULL) { |
| 757 | free(ma); |
| 758 | return -1; |
| 759 | } |
| 760 | |
| 761 | rte_spinlock_lock(&mem_area_lock); |
| 762 | |
| 763 | fd = -1; |
| 764 | |
| 765 | if (internal_conf->no_shconf) { |
| 766 | /* remap virtual area as writable */ |
| 767 | static const int flags = RTE_MAP_FORCE_ADDRESS | |
| 768 | RTE_MAP_PRIVATE | RTE_MAP_ANONYMOUS; |
| 769 | void *new_data = rte_mem_map(data, mmap_len, |
| 770 | RTE_PROT_READ | RTE_PROT_WRITE, flags, fd, 0); |
| 771 | if (new_data == NULL) { |
| 772 | RTE_LOG(DEBUG, EAL, "%s(): couldn't remap anonymous memory: %s\n", |
| 773 | __func__, rte_strerror(rte_errno)); |
| 774 | goto fail; |
| 775 | } |