提交 221c8dac 编写于 作者: 指向BIOS的野指针's avatar 指向BIOS的野指针

complete functions creating or deleting

pages or frames
上级 fb5f6041
...@@ -32,7 +32,7 @@ namespace bwl ...@@ -32,7 +32,7 @@ namespace bwl
__page *createPage(id_t pgid) __page *createPage(id_t pgid)
{ {
mkdir((PAGEDIR + std::to_string(pgid)).c_str(), 0755); mkdir((PAGEDIR + std::to_string(pgid)).c_str(), 0755);
int shmf = shm_open((PAGEDIR + std::to_string(pgid) + "shm").c_str(), O_RDWR | O_EXCL, 0); int shmf = shm_open((PAGEDIR + std::to_string(pgid) + "/shm").c_str(), O_RDWR | O_EXCL, 0);
if (shmf == -1) if (shmf == -1)
{ {
return CREATE_PAGE_FAULT; return CREATE_PAGE_FAULT;
...@@ -49,7 +49,7 @@ namespace bwl ...@@ -49,7 +49,7 @@ namespace bwl
if (page != (__page *)-1) if (page != (__page *)-1)
{ {
page->pgid = pgid; page->pgid = pgid;
shmf = shm_open((PAGEDIR + std::to_string(pgid) + "bgbuffer").c_str(), O_RDWR | O_EXCL, 0); shmf = shm_open((PAGEDIR + std::to_string(pgid) + "/bgbuffer").c_str(), O_RDWR | O_EXCL, 0);
if (shmf == -1) if (shmf == -1)
{ {
return CREATE_PAGE_FAULT; return CREATE_PAGE_FAULT;
...@@ -63,7 +63,7 @@ namespace bwl ...@@ -63,7 +63,7 @@ namespace bwl
if (page->server_bg_layer == (void *)-1) if (page->server_bg_layer == (void *)-1)
{ {
munmap(page, sizeof(__page)); munmap(page, sizeof(__page));
shm_unlink((PAGEDIR + std::to_string(pgid) + "shm").c_str()); shm_unlink((PAGEDIR + std::to_string(pgid) + "/shm").c_str());
return (__page *)MAP_FAILED; return (__page *)MAP_FAILED;
} }
} }
...@@ -75,9 +75,9 @@ namespace bwl ...@@ -75,9 +75,9 @@ namespace bwl
{ {
int pgid = page->pgid; int pgid = page->pgid;
munmap(page->server_bg_layer, BGBUFSIZE); munmap(page->server_bg_layer, BGBUFSIZE);
shm_unlink((PAGEDIR + std::to_string(pgid) + "bgbuffer").c_str()); shm_unlink((PAGEDIR + std::to_string(pgid) + "/bgbuffer").c_str());
munmap(page, sizeof(__page)); munmap(page, sizeof(__page));
shm_unlink((PAGEDIR + std::to_string(pgid) + "shm").c_str()); shm_unlink((PAGEDIR + std::to_string(pgid) + "/shm").c_str());
rmdir((PAGEDIR + std::to_string(pgid)).c_str()); rmdir((PAGEDIR + std::to_string(pgid)).c_str());
} }
...@@ -97,7 +97,7 @@ namespace bwl ...@@ -97,7 +97,7 @@ namespace bwl
__frame *createFrame(id_t fid, __page *page, std::string name, uint64_t width, uint64_t height, int64_t x, int64_t y) __frame *createFrame(id_t fid, __page *page, std::string name, uint64_t width, uint64_t height, int64_t x, int64_t y)
{ {
mkdir((FRMDIR + std::to_string(fid)).c_str(), 0755); mkdir((FRMDIR + std::to_string(fid)).c_str(), 0755);
int shmf = shm_open((FRMDIR + std::to_string(fid) + "shm").c_str(), O_RDWR | O_EXCL, 0); int shmf = shm_open((FRMDIR + std::to_string(fid) + "/shm").c_str(), O_RDWR | O_EXCL, 0);
if (shmf == -1) if (shmf == -1)
{ {
return CREATE_FRAME_FAULT; return CREATE_FRAME_FAULT;
...@@ -126,8 +126,9 @@ namespace bwl ...@@ -126,8 +126,9 @@ namespace bwl
frame->size[1] = height; frame->size[1] = height;
frame->pos[0] = x; frame->pos[0] = x;
frame->pos[1] = y; frame->pos[1] = y;
frame->pixdepth = pix_depth;
shmf = shm_open((FRMDIR + std::to_string(fid) + "buffer").c_str(), O_RDWR | O_EXCL, 0); shmf = shm_open((FRMDIR + std::to_string(fid) + "/buffer").c_str(), O_RDWR | O_EXCL, 0);
if (shmf == -1) if (shmf == -1)
{ {
return CREATE_FRAME_FAULT; return CREATE_FRAME_FAULT;
...@@ -141,7 +142,7 @@ namespace bwl ...@@ -141,7 +142,7 @@ namespace bwl
if (frame->server_buf == (void *)-1) if (frame->server_buf == (void *)-1)
{ {
munmap(frame, sizeof(__frame)); munmap(frame, sizeof(__frame));
shm_unlink((FRMDIR + std::to_string(fid) + "shm").c_str()); shm_unlink((FRMDIR + std::to_string(fid) + "/shm").c_str());
return (__frame *)MAP_FAILED; return (__frame *)MAP_FAILED;
} }
} }
...@@ -156,9 +157,9 @@ namespace bwl ...@@ -156,9 +157,9 @@ namespace bwl
{ {
int fid = frame->fid; int fid = frame->fid;
munmap(frame->server_buf, frame->size[0] * frame->size[1] * pix_depth); munmap(frame->server_buf, frame->size[0] * frame->size[1] * pix_depth);
shm_unlink((FRMDIR + std::to_string(fid) + "buffer").c_str()); shm_unlink((FRMDIR + std::to_string(fid) + "/buffer").c_str());
munmap(frame, sizeof(__frame) + frame->namelen); munmap(frame, sizeof(__frame) + frame->namelen);
shm_unlink((FRMDIR + std::to_string(fid) + "shm").c_str()); shm_unlink((FRMDIR + std::to_string(fid) + "/shm").c_str());
rmdir((FRMDIR + std::to_string(fid)).c_str()); rmdir((FRMDIR + std::to_string(fid)).c_str());
} }
......
...@@ -48,7 +48,7 @@ namespace bwl ...@@ -48,7 +48,7 @@ namespace bwl
} }
host >> bad_wayland_server::server_pid; host >> bad_wayland_server::server_pid;
host.close(); host.close();
//TODO 向wayland服务器询问屏幕设备大小和像素深度 // TODO 向wayland服务器询问屏幕设备大小和像素深度
} }
uint64_t getBgBuffSize() uint64_t getBgBuffSize()
...@@ -74,7 +74,7 @@ namespace bwl ...@@ -74,7 +74,7 @@ namespace bwl
getting.read((char *)&pgid, sizeof(id_t)); getting.read((char *)&pgid, sizeof(id_t));
getting.close(); getting.close();
//获取数据结构 //获取数据结构
int shmf = std::shm_open((PAGEDIR + std::to_string(pgid) + "shm").c_str(), O_RDWR | O_CREAT, 0); int shmf = std::shm_open((PAGEDIR + std::to_string(pgid) + "/shm").c_str(), O_RDWR | O_CREAT, 0);
if (shmf == -1) if (shmf == -1)
{ {
return CREATE_PAGE_FAULT; return CREATE_PAGE_FAULT;
...@@ -83,7 +83,7 @@ namespace bwl ...@@ -83,7 +83,7 @@ namespace bwl
std::close(shmf); std::close(shmf);
if (page != (__page *)-1) if (page != (__page *)-1)
{ {
shmf = std::shm_open((PAGEDIR + std::to_string(pgid) + "bgbuffer").c_str(), O_RDWR | O_CREAT, 0); shmf = std::shm_open((PAGEDIR + std::to_string(pgid) + "/bgbuffer").c_str(), O_RDWR | O_CREAT, 0);
if (shmf == -1) if (shmf == -1)
{ {
return CREATE_PAGE_FAULT; return CREATE_PAGE_FAULT;
...@@ -93,7 +93,7 @@ namespace bwl ...@@ -93,7 +93,7 @@ namespace bwl
if (page->client_bg_layer == (void *)-1) if (page->client_bg_layer == (void *)-1)
{ {
std::munmap(page, sizeof(__page)); std::munmap(page, sizeof(__page));
std::shm_unlink((PAGEDIR + std::to_string(pgid) + "shm").c_str()); std::shm_unlink((PAGEDIR + std::to_string(pgid) + "/shm").c_str());
return (__page *)MAP_FAILED; return (__page *)MAP_FAILED;
} }
} }
...@@ -105,9 +105,9 @@ namespace bwl ...@@ -105,9 +105,9 @@ namespace bwl
{ {
int pgid = page->pgid; int pgid = page->pgid;
std::munmap(page->client_bg_layer, getBgBuffSize()); std::munmap(page->client_bg_layer, getBgBuffSize());
std::shm_unlink((PAGEDIR + std::to_string(pgid) + "bgbuffer").c_str()); std::shm_unlink((PAGEDIR + std::to_string(pgid) + "/bgbuffer").c_str());
std::munmap(page, sizeof(__page)); std::munmap(page, sizeof(__page));
std::shm_unlink((PAGEDIR + std::to_string(pgid) + "shm").c_str()); std::shm_unlink((PAGEDIR + std::to_string(pgid) + "/shm").c_str());
req_pack *rp = new req_pack; req_pack *rp = new req_pack;
rp->request = requests::del_page; rp->request = requests::del_page;
rp->pid = std::getpid(); rp->pid = std::getpid();
...@@ -120,4 +120,76 @@ namespace bwl ...@@ -120,4 +120,76 @@ namespace bwl
delete rp; delete rp;
} }
__frame *createFrame(id_t fid, __page *page, std::string name, uint64_t width, uint64_t height, int64_t x, int64_t y)
{
req_pack *rp = new req_pack;
rp->request = requests::create_frame;
rp->pid = std::getpid();
rp->magic = REQMAGIC;
std::memcpy(rp->arguments.a_create_frame.name, name.c_str(), name.length());
rp->arguments.a_create_frame.namelen = name.length();
rp->arguments.a_create_frame.pgid = page->pgid;
rp->arguments.a_create_frame.pos[0] = x;
rp->arguments.a_create_frame.pos[1] = y;
rp->arguments.a_create_frame.size[0] = width;
rp->arguments.a_create_frame.size[1] = height;
rp->arguments.a_create_frame.space = colorspace::rgb;
Pipe push("/dev/bwl/reciever.pipe", bwl::Pipe::out);
push.write((char *)rp, sizeof(req_pack));
push.close();
std::kill(bad_wayland_server::server_pid, SIGBWLREQ);
delete rp;
//等待服务器回复
Pipe getting(BWLDIR + "/reply/" + std::to_string(std::getpid()) + ".pipe", Pipe::in);
getting.read((char *)&fid, sizeof(id_t));
getting.close();
//映射数据
int shmf = std::shm_open((FRMDIR + std::to_string(fid) + "/shm").c_str(), O_RDWR | O_CREAT, 0);
if (shmf == -1)
{
return CREATE_FRAME_FAULT;
}
__frame *frame = (__frame *)std::mmap(nullptr, sizeof(__frame) + name.length() + 1,
PROT_READ | PROT_WRITE, MAP_SHARED, shmf, 0);
std::close(shmf);
if (frame != (__frame *)-1)
{
shmf = std::shm_open((FRMDIR + std::to_string(fid) + "/buffer").c_str(), O_RDWR | O_EXCL, 0);
if (shmf == -1)
{
return CREATE_FRAME_FAULT;
}
frame->client_buf = std::mmap(nullptr, width * height * frame->pixdepth, PROT_READ | PROT_WRITE, MAP_SHARED, shmf, 0);
std::close(shmf);
if (frame->client_buf == (void *)-1)
{
std::munmap(frame, sizeof(__frame));
std::shm_unlink((FRMDIR + std::to_string(fid) + "/shm").c_str());
return (__frame *)MAP_FAILED;
}
}
return frame;
}
void deleteFrame(__frame * frame)
{
int fid = frame->fid;
std::munmap(frame->client_buf, frame->size[0] * frame->size[1] * frame->pixdepth);
std::shm_unlink((FRMDIR + std::to_string(fid) + "/buffer").c_str());
std::munmap(frame, sizeof(__frame) + frame->namelen);
std::shm_unlink((FRMDIR + std::to_string(fid) + "/shm").c_str());
req_pack *rp = new req_pack;
rp->request = requests::del_frame;
rp->pid = std::getpid();
rp->magic = REQMAGIC;
rp->arguments.a_del_frame.fid = fid;
Pipe push("/dev/bwl/reciever.pipe", bwl::Pipe::out);
push.write((char *)rp, sizeof(req_pack));
push.close();
std::kill(bad_wayland_server::server_pid, SIGBWLREQ);
delete rp;
}
}; };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册