本文整理汇总了C++中SharedMemory::map方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory::map方法的具体用法?C++ SharedMemory::map怎么用?C++ SharedMemory::map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharedMemory
的用法示例。
在下文中一共展示了SharedMemory::map方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: monapi_clipboard_get
SharedMemory* monapi_clipboard_get()
{
uint32_t tid ;
if (monapi_name_whereis("/servers/clipboard", tid) != M_OK) {
return NULL;
}
MessageInfo msg;
if (Message::sendReceive(&msg, tid, MSG_CLIPBOARD_GET) != M_OK) {
return NULL;
}
if ((intptr_t)msg.arg2 < M_OK) { return NULL;}
SharedMemory* ret = new SharedMemory(msg.arg2, msg.arg3);
if (ret->size() == 0) {
return ret;
}
intptr_t mapResult = ret->map(true);
if (mapResult != M_OK) {
delete ret;
monapi_warn("%s map error = %d\n", __func__, mapResult);
return NULL;
} else {
return ret;
}
}
示例2: alloc_buffer_size
static SharedMemory* alloc_buffer_size(const char* message, int size)
{
SharedMemory* buffer = new SharedMemory(size);
buffer->map();
memcpy(buffer->data(), message, buffer->size());
return buffer;
}
示例3: file_receive_shm
static SharedMemory* file_receive_shm(int header, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, const char* str)
{
uint32_t tid;
if (monapi_name_whereis("/servers/file", tid) != M_OK) {
return NULL;
}
MessageInfo msg;
if (Message::sendReceive(&msg, tid, header, arg1, arg2, arg3, str) != M_OK) {
return NULL;
}
if ((intptr_t)msg.arg2 < M_OK) {
int status = Message::reply(&msg);
if (status != M_OK) {
monapi_warn("%s reply failed : %s\n", __func__, monapi_error_string(status));
}
return NULL;
}
uintptr_t handle = msg.arg2;
uintptr_t size = msg.arg3;
SharedMemory* shm = new SharedMemory(handle, size);
if (shm->map(true) != M_OK) {
int status = Message::reply(&msg);
delete shm;
if (status != M_OK) {
monapi_warn("%s reply failed : %s\n", __func__, monapi_error_string(status));
}
return NULL;
} else {
int status = Message::reply(&msg);
if (status != M_OK) {
monapi_warn("%s reply failed : %s\n", __func__, monapi_error_string(status));
}
return shm;
}
}
示例4: test_fatfs_write_file_overwrite_expand
static void test_fatfs_write_file_overwrite_expand()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
const char* FILENAME = "MY1.TXT";
Vnode* found;
ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));
const int BUFFER_SIZE = 1540;
SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
ASSERT_EQ(M_OK, buffer->map());
memset(buffer->data(), 0xce, BUFFER_SIZE);
buffer->data()[0] = 0xca;
buffer->data()[buffer->size() - 1] = 0xfe;
io::Context c;
c.offset = 513;
c.size = BUFFER_SIZE;
c.memory = buffer;
ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));
io::Context readContext;
SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
ASSERT_TRUE(cmi != NULL);
ASSERT_TRUE(cmi->data() != NULL);
ASSERT_EQ(2053, cmi->size());
EXPECT_EQ(0xde, cmi->data()[0]);
EXPECT_EQ(0xca, cmi->data()[513]);
EXPECT_EQ(0xfe, cmi->data()[513 + BUFFER_SIZE - 1]);
}
示例5: test_fatfs_write_file
static void test_fatfs_write_file()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
const char* FILENAME = "MY1.TXT";
Vnode* found;
ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));
const int BUFFER_SIZE = 1029;
SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
ASSERT_EQ(M_OK, buffer->map());
memset(buffer->data(), 0, BUFFER_SIZE);
buffer->data()[0] = 0xde;
buffer->data()[BUFFER_SIZE - 1] = 0xad;
io::Context c;
c.offset = 0;
c.size = BUFFER_SIZE;
c.memory = buffer;
ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));
io::Context readContext;
SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
ASSERT_TRUE(cmi != NULL);
ASSERT_TRUE(cmi->data() != NULL);
ASSERT_EQ(BUFFER_SIZE, cmi->size());
EXPECT_TRUE(memcmp(buffer->data(), cmi->data(), BUFFER_SIZE) == 0);
}
示例6: SharedMemory
SharedMemory* monapi_call_file_decompress_bz2(const SharedMemory& shm)
{
uint32_t tid;
if (monapi_name_whereis("/servers/file", tid) != M_OK) {
return NULL;
}
MessageInfo msg;
if (Message::sendReceive(&msg, tid, MSG_FILE_DECOMPRESS_BZ2, shm.handle(), shm.size()) != M_OK) {
return NULL;
}
if (msg.arg2 == 0) return NULL;
SharedMemory* ret = new SharedMemory(msg.arg2, msg.arg3);
if (ret->map(true) != M_OK) {
delete ret;
return NULL;
} else {
return ret;
}
}
示例7: test_fatfs_write_file_overwrite
static void test_fatfs_write_file_overwrite()
{
TestFatFS fs;
FatFileSystem* fat = fs.get();
Vnode* root = fat->getRoot();
const char* FILENAME = "MY1.TXT";
Vnode* found;
ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));
const int BUFFER_SIZE = 10;
SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
ASSERT_EQ(M_OK, buffer->map());
memset(buffer->data(), 0, BUFFER_SIZE);
for (int i = 0; i < BUFFER_SIZE; i++) {
buffer->data()[i] = i;
}
io::Context c;
c.offset = 513;
c.size = BUFFER_SIZE;
c.memory = buffer;
ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));
io::Context readContext;
SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
ASSERT_TRUE(cmi != NULL);
ASSERT_TRUE(cmi->data() != NULL);
EXPECT_EQ(0xde, cmi->data()[0]);
EXPECT_EQ(0xad, cmi->data()[cmi->size() -1]);
for (int i = 0; i < BUFFER_SIZE; i++) {
EXPECT_EQ(i, cmi->data()[513 + i]);
}
}
示例8: Load
bool Load()
{
uint32_t imageSize = 0;
uint32_t bootstrapSize = getBootstrapSize();
PEDataList::size_type len = this->list.size();
for (PEDataList::size_type i = 0; i < len; i++)
{
imageSize += this->list[i]->Parser.get_ImageSize();
}
imageSize += bootstrapSize;
SharedMemory* dst = new SharedMemory(imageSize);
if (dst->map(true) != M_OK)
{
delete dst;
this->Result = 3;
return false;
}
uint32_t addr = 0;
for (PEDataList::size_type i = 0; i < len; i++)
{
PEData* data = this->list[i];
uint8_t* ptr = &dst->data()[addr];
if (!data->Parser.Load(ptr))
{
if (this->prompt) _printf("%s: can not load: %s\n", SVR, (const char*)data->Name);
#ifdef NO_CACHE
delete dst;
#endif
this->Result = 3;
return false;
}
if (i > 0 && !data->Parser.Relocate(ptr, ORG + addr))
{
if (this->prompt) _printf("%s: can not relocate: %s\n", SVR, (const char*)data->Name);
#ifdef NO_CACHE
delete dst;
#endif
this->Result = 3;
return false;
}
addr += data->Parser.get_ImageSize();
}
addr = 0;
for (PEDataList::size_type i = 0; i < len; i++)
{
PEData* data = this->list[i];
int its = data->Parser.get_ImportTableCount();
for (int j = 0; j < its; j++)
{
CString dll = CString(data->Parser.GetImportTableName(j)).toUpper();
PEData* target = this->Find(dll);
if (target == NULL || !data->Parser.Link(&dst->data()[addr], j, &target->Parser))
{
if (this->prompt)
{
_printf("NG\n");
_printf("%s: can not link %s to %s!\n", SVR, (const char*)dll, (const char*)data->Name);
}
#ifdef NO_CACHE
delete dst;
#endif
this->Result = 3;
return false;
}
}
addr += data->Parser.get_ImageSize();
}
// make bootstrap code
uint8_t* bootstrap = &dst->data()[dst->size() - bootstrapSize];
uint8_t* start = &bootstrap[3];
bootstrap[0] = 0x55; // push ebp
bootstrap[1] = 0x89; // mov ebp
bootstrap[2] = 0xE5; // ,esp
PEDataList::size_type i;
//char buf[128];
const uint32_t CALL_CODE_SIZE = 13;
// dllmain construct
for (i = 0; i < dlls.size(); i++)
{
PEData* dll = dlls[i];
start[i * CALL_CODE_SIZE] = 0xB8; // mov eax
*(uint32_t*)(&start[i * CALL_CODE_SIZE + 1]) = dll->Parser.get_EntryPoint(); // ,address
start[i * CALL_CODE_SIZE + 5] = 0x68; // push
*(uint32_t*)(&start[i * CALL_CODE_SIZE + 6]) = 0; // 0x00000000 = argument of dllmain
start[i * CALL_CODE_SIZE + 10] = 0xFF; // call eax
start[i * CALL_CODE_SIZE + 11] = 0xD0; // call eax
start[i * CALL_CODE_SIZE + 12] = 0x58; // pop eax
}
PEData* exe = list[0];
start[i * CALL_CODE_SIZE + 0] = 0xB8; // mov eax
*(uint32_t*)(&start[i * CALL_CODE_SIZE + 1]) = exe->Parser.get_EntryPoint();
start[i * CALL_CODE_SIZE + 5] = 0xFF;
start[i * CALL_CODE_SIZE + 6] = 0xD0;
start = &start[i * CALL_CODE_SIZE + 7];
// destruct
for (i = 0; i < dlls.size(); i++)
//.........这里部分代码省略.........