小编cha*_*umQ的帖子

如何在将共同值移动到新集合中的同时将两个 HashSet 相交?

use std::collections::HashSet;
let mut a: HashSet<T> = HashSet::new();
let mut b: HashSet<T> = HashSet::new();
let mut c: HashSet<T> = a.intersection(&b).collect();
// Error: a collection of type `std::collections::HashSet<T>` cannot be built from an iterator over elements of type `&T`
Run Code Online (Sandbox Code Playgroud)

我不再需要不相交的值。如何偷/移动从集数据abc无需复制或克隆?理想情况下,这将具有理论上最佳的时间复杂度:O(min(a, b))。

rust

3
推荐指数
1
解决办法
904
查看次数

如何写入Linux内核中的受保护页面?

我正在尝试在模块中添加系统调用。我的理由是:

  1. 这是一个研究项目,因此具体实施并不重要。
  2. 在内核中添加系统调用需要非常长的时间来重新编译。我可以用扩展的系统调用表进行一次编译,但不是每次都如此。即使使用增量编译,链接和归档最终的二进制文件也需要很长时间。
  3. 由于该项目对时间敏感,因此使用kprobes拦截系统调用处理程序会减慢系统调用处理程序的速度。

我仍然对添加系统调用的其他方法持开放态度,但由于上述原因,我认为在模块中写入sys_call_table是完成我想做的事情的最干净的方法。

我已经从禁用的 kaslr 获取了系统调用表的地址System.map,并且我正在尝试清除页面保护,但某些写保护仍然阻碍我。

// following https://web.iiit.ac.in/~arjun.nath/random_notes/modifying_sys_call.html

// clear cr0 write protection
write_cr0 (read_cr0 () & (~ 0x10000));

// clear page write protection
sys_call_table_page = virt_to_page(&sys_call_table[__NR_execves]);
set_pages_rw(sys_call_table_page, 1);

// do write
sys_call_table[__NR_execves] = sys_execves;
Run Code Online (Sandbox Code Playgroud)

但是,我仍然收到权限错误,但我不知道它的执行机制:

[   11.145647] ------------[ cut here ]------------
[   11.148893] CR0 WP bit went missing!?
[   11.151539] WARNING: CPU: 0 PID: 749 at arch/x86/kernel/cpu/common.c:386 native_write_cr0+0x3e/0x70
...
Here was a call trace pointing to the write of sys_call_table …
Run Code Online (Sandbox Code Playgroud)

paging system-calls linux-kernel

3
推荐指数
1
解决办法
4598
查看次数

C++函数返回数组

我是C++的新手.我习惯用Java编程.这个特殊的问题给我带来了很大的问题,因为C++在处理数组时并不像Java那样.在C++中,数组只是指针.

但为什么这个代码:

#include <iostream>
#define SIZE 3
using namespace std;

void printArray(int*, int);
int * getArray();
int ctr = 0;

int main() {
  int * array = getArray();

  cout << endl << "Verifying 2" << endl;
  for (ctr = 0; ctr < SIZE; ctr++)
    cout << array[ctr] << endl;

  printArray(array, SIZE);
  return 0;
}

int * getArray() {
  int a[] = {1, 2, 3};
  cout << endl << "Verifying 1" << endl;
  for (ctr = 0; ctr < SIZE; ctr++) …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers return

2
推荐指数
2
解决办法
2万
查看次数

C++语法错误和缺少类型说明符

Visual C++ 2008给了我这个奇怪的错误,所以我在我的头文件(util.h)中删除了所有多余的东西,归结为:

#ifndef UTIL_H
#define UTIL_H

void pause();

#endif
Run Code Online (Sandbox Code Playgroud)

当我尝试编译上面的代码时,我得到了这个:

Compiling...
util.cpp
util.h(4) : error C2144: syntax error : 'void' should be preceded by ';'
util.h(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<snip>
Run Code Online (Sandbox Code Playgroud)

我很困惑.即使我注释掉ifndef,define和endif,预处理器指令,它仍然说同样的事情.

c++ compiler-errors compiler-warnings visual-c++

1
推荐指数
1
解决办法
297
查看次数