| 601 | #define SHM_EXEC 0100000 /* execution access */ |
| 602 | |
| 603 | U32 KSystem::shmat(KThread* thread, U32 shmid, U32 shmaddr, U32 shmflg, U32 rtnAddr, U32* nativeRtnAddr) { |
| 604 | U32 permissions = 0; |
| 605 | std::shared_ptr<SHM> shm; |
| 606 | |
| 607 | if (shmid & PRIVATE_SHMID) { |
| 608 | shm = thread->process->getSHM(shmid); |
| 609 | } else { |
| 610 | shm = publicShm[shmid]; |
| 611 | } |
| 612 | |
| 613 | if (!shm) { |
| 614 | return -K_EINVAL; |
| 615 | } |
| 616 | if (shmaddr && (shmflg & SHM_RND)) { |
| 617 | shmaddr = shmaddr & ~K_PAGE_MASK; |
| 618 | } |
| 619 | if (shmaddr && (shmaddr & K_PAGE_MASK)) { |
| 620 | return -K_EINVAL; |
| 621 | } |
| 622 | if (shmflg & SHM_REMAP) { |
| 623 | kpanic("syscall_shmat SHM_REMAP not implemented"); |
| 624 | } |
| 625 | if (shmflg & SHM_RDONLY) { |
| 626 | permissions = K_PROT_READ; |
| 627 | } else { |
| 628 | permissions = K_PROT_READ | K_PROT_WRITE; |
| 629 | } |
| 630 | U32 result = thread->process->memory->mapPages(thread, shmaddr >> K_PAGE_SHIFT, shm->pages, permissions); |
| 631 | if (result == 0) { |
| 632 | return -K_EINVAL; |
| 633 | } |
| 634 | if (rtnAddr) { |
| 635 | thread->process->memory->writed(rtnAddr, result); |
| 636 | } |
| 637 | if (nativeRtnAddr) { |
| 638 | *nativeRtnAddr = result; |
| 639 | } |
| 640 | thread->process->attachSHM(result, shm); |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | |
| 645 | U32 KSystem::shmdt(KThread* thread, U32 shmaddr) { |