| 718 | | while (size > 0) { |
|---|
| 719 | | if (fd != -1 || |
|---|
| 720 | | (fd = shmget(IPC_PRIVATE, (size > seg_size)?seg_size:size, (IPC_CREAT | SHM_R | SHM_W))) != -1) { |
|---|
| 721 | | if ((p = (void *)shmat(fd, prev?(prev+seg_size):NULL, 0)) != ((void *)-1) && |
|---|
| 722 | | (prev == NULL || prev + seg_size == p)) { |
|---|
| 723 | | struct shmid_ds shmbuf; |
|---|
| 724 | | /*??? |
|---|
| 725 | | memset(p, 0, (size > seg_size)?seg_size:size); |
|---|
| 726 | | */ |
|---|
| 727 | | if (shmctl(fd, IPC_STAT, &shmbuf) == 0) { |
|---|
| 728 | | shmbuf.shm_perm.uid = getuid(); |
|---|
| 729 | | shmbuf.shm_perm.gid = getgid(); |
|---|
| 730 | | if (shmctl(fd, IPC_SET, &shmbuf) == 0) { |
|---|
| 731 | | shmctl(fd, IPC_RMID, NULL); |
|---|
| 732 | | if (root == NULL) { |
|---|
| 733 | | root = (MM*)p; |
|---|
| 734 | | segment = (void**)((char*)p+sizeof(MM)); |
|---|
| 735 | | } else { |
|---|
| 736 | | *segment = p; |
|---|
| 737 | | segment++; |
|---|
| 738 | | } |
|---|
| 739 | | prev = (char*)p; |
|---|
| 740 | | fd = -1; |
|---|
| 741 | | if (size > seg_size) { |
|---|
| 742 | | size -= seg_size; |
|---|
| 743 | | } else { |
|---|
| 744 | | size = 0; |
|---|
| 745 | | } |
|---|
| 746 | | continue; |
|---|
| 747 | | } |
|---|
| 748 | | } |
|---|
| 749 | | shmdt(p); |
|---|
| 750 | | } |
|---|
| 751 | | shmctl(fd, IPC_RMID, NULL); |
|---|
| 752 | | } |
|---|
| 753 | | if (root != NULL) { |
|---|
| 754 | | while (segment > (void**)((char*)root+sizeof(MM))) { |
|---|
| 755 | | segment--; |
|---|
| 756 | | shmdt(*segment); |
|---|
| 757 | | } |
|---|
| 758 | | } |
|---|
| 759 | | shmdt(root); |
|---|
| 760 | | return (MM*)-1; |
|---|
| 761 | | } |
|---|
| 762 | | *segment = (void*)-1; |
|---|
| 763 | | segment++; |
|---|
| 764 | | root->size = orig_size; |
|---|
| 765 | | root->start = (void*)segment; |
|---|
| 766 | | return root; |
|---|
| | 714 | ea_debug_error("eAccelerator: Could not allocate %d bytes, the maximum size the kernel allows is %d bytes. " |
|---|
| | 715 | "Lower the amount of memory request or increase the limit in /proc/sys/kernel/shmmax.\n", size, seg_size); |
|---|
| | 716 | |
|---|
| | 717 | /* bart: Removed the code that tried to allocate more then one segment |
|---|
| | 718 | * because it didn't work, this part needs a redesign of the mm code to |
|---|
| | 719 | * allow this. It should allocate one to init the shared memory and add |
|---|
| | 720 | * the other to the free list. |
|---|
| | 721 | */ |
|---|