Compare commits
No commits in common. "b01aa72f176cde5f28e56f456e6efb01a7c9de8a" and "bfcca3a220f2c44d41e7b9a4bd9c50b30c54c2f0" have entirely different histories.
b01aa72f17
...
bfcca3a220
@ -292,15 +292,6 @@ static void mount_tmpfs()
|
||||
if (chmod("/tmp", 01777) < 0) exit(255);
|
||||
}
|
||||
|
||||
static void mount_shmfs()
|
||||
{
|
||||
if (mkdir("/dev/shm", 0755) < 0) exit(255);
|
||||
|
||||
if (mount("/dev/shm", "tmpfs", "tmpfs") < 0) exit(255);
|
||||
|
||||
if (chmod("/dev/shm", 01777) < 0) exit(255);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if (getpid() != 1)
|
||||
@ -316,7 +307,6 @@ int main()
|
||||
stderr = fopen("/dev/console", "w");
|
||||
|
||||
mount_tmpfs();
|
||||
mount_shmfs();
|
||||
|
||||
umask(022);
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/wait.h>
|
||||
@ -6,27 +5,15 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
int fd = shm_open("/shared", O_CREAT | O_RDWR, 0666);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("shm_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ftruncate(fd, PAGE_SIZE);
|
||||
|
||||
void* address = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
void* address = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
|
||||
if (address == MAP_FAILED)
|
||||
{
|
||||
perror("mmap");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* ptr = (char*)address;
|
||||
|
||||
printf("the value is %c\n", *ptr);
|
||||
|
||||
*ptr = 'a';
|
||||
int* ptr = (int*)address;
|
||||
*ptr = 16;
|
||||
|
||||
pid_t child = fork();
|
||||
if (child < 0)
|
||||
@ -36,13 +23,13 @@ int main()
|
||||
}
|
||||
if (child == 0)
|
||||
{
|
||||
*ptr = 'e';
|
||||
*ptr = 32;
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
waitpid(child, NULL, 0);
|
||||
|
||||
printf("the value is %c\n", *ptr);
|
||||
printf("the value is %d\n", *ptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -39,11 +39,6 @@ Result<u64> FramebufferDevice::query_shared_memory(off_t offset, usize count)
|
||||
}
|
||||
|
||||
auto* shm = g_shared_memory_map.try_get_ref(*m_shmid);
|
||||
if (!shm)
|
||||
{
|
||||
m_shmid = {};
|
||||
return query_shared_memory(offset, count);
|
||||
}
|
||||
if (shm->offset > offset)
|
||||
{
|
||||
TRY(shm->grow_backward(Framebuffer::ptr() + offset, (shm->offset - offset) / ARCH_PAGE_SIZE));
|
||||
|
@ -144,12 +144,6 @@ namespace TmpFS
|
||||
}
|
||||
|
||||
auto* shm = g_shared_memory_map.try_get_ref(*m_shmid);
|
||||
if (!shm)
|
||||
{
|
||||
m_shmid = {};
|
||||
return query_shared_memory(offset, count);
|
||||
}
|
||||
|
||||
if (shm->offset > offset)
|
||||
{
|
||||
TRY(shm->grow_backward(m_data_buffer.data() + offset, (shm->offset - offset) / ARCH_PAGE_SIZE));
|
||||
|
@ -107,16 +107,12 @@ Result<void> SharedMemory::map(u64 virt, int flags, off_t _offset, usize count)
|
||||
|
||||
void SharedMemory::free()
|
||||
{
|
||||
if ((inode || device) && (prot & PROT_WRITE))
|
||||
if (inode && (prot & PROT_WRITE))
|
||||
{
|
||||
for (u64 i = 0; i < frames.size(); i++)
|
||||
{
|
||||
if (inode)
|
||||
inode->write((u8*)MMU::translate_physical_address(frames[i]), offset + (i * ARCH_PAGE_SIZE),
|
||||
ARCH_PAGE_SIZE);
|
||||
if (device)
|
||||
device->write((u8*)MMU::translate_physical_address(frames[i]), offset + (i * ARCH_PAGE_SIZE),
|
||||
ARCH_PAGE_SIZE);
|
||||
inode->write((u8*)MMU::translate_physical_address(frames[i]), offset + (i * ARCH_PAGE_SIZE),
|
||||
ARCH_PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,6 @@ struct SharedMemory
|
||||
SharedPtr<Device> device {};
|
||||
int refs { 0 };
|
||||
|
||||
SharedMemory() = default;
|
||||
SharedMemory(SharedMemory&&) = default;
|
||||
|
||||
static Result<u64> create(u8* mem, off_t offset, usize count);
|
||||
|
||||
Result<void> grow_forward(u8* mem, usize count);
|
||||
@ -25,8 +22,6 @@ struct SharedMemory
|
||||
Result<void> map(u64 virt, int flags, off_t offset, usize count);
|
||||
|
||||
void free();
|
||||
|
||||
~SharedMemory() = default;
|
||||
};
|
||||
|
||||
extern HashMap<u64, SharedMemory> g_shared_memory_map;
|
||||
|
@ -50,7 +50,6 @@ Result<u64> sys_mmap(Registers*, SyscallArgs args)
|
||||
}
|
||||
shmem = g_shared_memory_map.try_get_ref(shmid);
|
||||
shmem->refs++;
|
||||
shmem->prot |= params.prot;
|
||||
}
|
||||
|
||||
u64 address;
|
||||
|
@ -28,12 +28,6 @@ extern "C"
|
||||
/* Write modified shared memory back to its associated file. */
|
||||
int msync(void* addr, size_t len, int flags);
|
||||
|
||||
/* Create a new POSIX shared memory object. */
|
||||
int shm_open(const char* name, int oflag, mode_t mode);
|
||||
|
||||
/* Delete a POSIX shared memory object from the file system. */
|
||||
int shm_unlink(const char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include <bits/errno-return.h>
|
||||
#include <bits/mmap.h>
|
||||
#include <fcntl.h>
|
||||
#include <luna/Heap.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
@ -27,18 +25,4 @@ extern "C"
|
||||
long rc = syscall(SYS_msync, addr, len);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
int shm_open(const char* name, int oflag, mode_t mode)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
snprintf(buf, sizeof(buf), "/dev/shm%s", name);
|
||||
return open(buf, oflag | O_CLOEXEC, mode);
|
||||
}
|
||||
|
||||
int shm_unlink(const char* name)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
snprintf(buf, sizeof(buf), "/dev/shm%s", name);
|
||||
return unlink(buf);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ struct Shareable
|
||||
return m_ref_count == 0;
|
||||
}
|
||||
|
||||
Atomic<int> m_ref_count { 0 };
|
||||
Atomic<int> m_ref_count { 1 };
|
||||
};
|
||||
|
||||
template <typename T> class SharedPtr
|
||||
@ -36,7 +36,6 @@ template <typename T> class SharedPtr
|
||||
|
||||
SharedPtr(T* ptr) : m_ptr(ptr)
|
||||
{
|
||||
if (m_ptr) shareable()->ref();
|
||||
}
|
||||
|
||||
SharedPtr(const SharedPtr<T>& other) : m_ptr(other.m_ptr)
|
||||
@ -51,6 +50,7 @@ template <typename T> class SharedPtr
|
||||
|
||||
template <typename Tp> operator SharedPtr<Tp>()
|
||||
{
|
||||
if (m_ptr) shareable()->ref();
|
||||
return { (Tp*)m_ptr };
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user