小编0x9*_*x90的帖子

为什么这段代码可以被利用?

为什么这段代码不安全?

#include <stdio.h>
int main( int argc, char *argv[] )
    {
       printf(argv[1]);
       printf("\n");
       return 0;
    }
Run Code Online (Sandbox Code Playgroud)

c security

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

如何在内核模块中获取数组的地址,以便我能够在用户空间应用程序中使用它?

我有一个名为的内核模块mymodule,我有:

static struct file_operations my_mod_fops = {
        .owner = THIS_MODULE
        .write = my_write,
        .open = my_open,
        .unlocked_ioctl = my_ioctl,
        .read = my_read,

};
Run Code Online (Sandbox Code Playgroud)

测试了前一个结构中映射的所有函数,它们都没问题.我想声明全局(并且静态地,如果可用)一个char kernel_array[128],我想编写一个可以执行此操作的用户空间应用程序:

int main(){

char* ptr_to_kernel_arr = get_kernel_array_address();

for (int i=0 ; i<128;++i)
    *(ptr_to_kernel_arr+i) = i;

return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的困难是:

  1. 如何获取kernel_array[128]可以从用户空间应用程序分配值的地址?

  2. 内核如何知道其lsmod列表中的哪个模块拥有该模块kernel_array

  3. 如何处理mmap所有这些情况?

我阅读了第15章和更多材料,但无法弄清楚如何做到这一点.我在网上找到的所有例子都声明了一个文件并与内核和用户空间共享.

c linux memory linux-device-driver linux-kernel

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

是否有可能构建一个编程给定API的图灵机?

我想知道,是否可以定义一个API并将其作为TM图灵机的输入,输出将是代码c或任何其他自然/编程语言?

我猜不是,但我如何通过减少等正式展示?

theory nlp turing-machines

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

如何在linux用户空间应用程序中获得最精确的时钟?

我有一个嵌入式系统,我想在内核模块/驱动程序中共享最准确的时钟,其中一个用户空间应用程序对时钟非常敏感,应该是最准确的.

  1. 这些功能需要上下文切换和巨大的开销,因为系统调用,时钟将不准确.

  2. 我认为增加共享整数每一个瞬间从内核模块,假设用户空间应用程序可以直接访问它,问题是,我不能共享一个integer/long未对齐到页面大小,并宣布了一个全新的页面只有一个long变量是一个巨大的开销.

我该怎么办?

c linux arm clock linux-kernel

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

为什么我不能使用python 2.7在使用pip和/或easy_install安装后使用python 2.7导入beautifulsoup?

$ sudo pip install beautifulsoup4
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Cleaning up...
Run Code Online (Sandbox Code Playgroud)

我已安装beautifulsoup4并且似乎已成功完成但我无法导入它:

Python 2.7.3 (v2.7.3:70, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import beautifulsoup4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named beautifulsoup4
>>> import beautifulsoup
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: …
Run Code Online (Sandbox Code Playgroud)

python pip beautifulsoup easy-install python-2.7

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

Python扩展:找不到架构x86_64错误的符号

我想在c中写一个python扩展.我在Mac上工作,我从这里拿了代码:

#include <Python.h>

static PyObject* say_hello(PyObject* self, PyObject* args)
{
    const char* name;

    if (!PyArg_ParseTuple(args, "s", &name))
        return NULL;

    printf("Hello %s!\n", name);

    Py_RETURN_NONE;
}

static PyMethodDef HelloMethods[] =
{
     {"say_hello", say_hello, METH_VARARGS, "Greet somebody."},
     {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC

inithello(void)
{
     (void) Py_InitModule("hello", HelloMethods);
}
Run Code Online (Sandbox Code Playgroud)

我编译它:

gcc -c -o py_module.o py_module.c -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/
gcc -o py_module py_module.o -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/ -lm
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

Undefined symbols for architecture x86_64:
  "_PyArg_ParseTuple", referenced from:
      _say_hello in py_module.o
  "_Py_InitModule4_64", referenced from:
      _inithello in py_module.o
  "__Py_NoneStruct", …
Run Code Online (Sandbox Code Playgroud)

c python python-2.7

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

Erlang vs Haskell:什么时候比另一个更喜欢?

  • 什么时候人们会更喜欢Erlang而不是Haskell
  • 两个都不能TCP在一个进程中处理大量流量吗?

erlang haskell tcp

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

为什么更改块和网格大小会对运行时产生如此大的影响?

我正在研究一些将RGBA图像转换为灰度的cuda 教程.但我无法弄清楚为什么改变它blockSizegridSize进行X33时间的改进.

__global__
void rgba_to_greyscale(const uchar4* const rgbaImage,
                       unsigned char* const greyImage,
                       int numRows, int numCols)
{
    int i = blockIdx.x*numCols + threadIdx.x;
    float channelSum = .299f * rgbaImage[i].x + .587f * rgbaImage[i].y + .114f * rgbaImage[i].z;
    greyImage[i]= channelSum;
}

void your_rgba_to_greyscale(const uchar4 * const h_rgbaImage, uchar4 * const d_rgbaImage,
                            unsigned char* const d_greyImage, size_t numRows, size_t numCols)
{
  const dim3 blockSize(numCols, 1, 1);
  const dim3 gridSize(numRows, 1 , 1);
  rgba_to_greyscale<<<gridSize, blockSize>>>(d_rgbaImage, d_greyImage, numRows, numCols); …
Run Code Online (Sandbox Code Playgroud)

c c++ cuda gpu gpgpu

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

当一个人应该使用Set [例如对于SpecialCells的返回值]?

我担心我误解了VBA的excel文档,我有这条似乎是一个错误的行:

Range a = Selection.SpecialCells(xlCellTypeConstants, 23)
Run Code Online (Sandbox Code Playgroud)

但是这个很好:

Set a = Selection.SpecialCells(xlCellTypeConstants, 23)
Run Code Online (Sandbox Code Playgroud)

文件声称:

返回一个Range 对象,该对象表示与指定类型和值匹配的所有单元格.

但它实际上返回一个byRef对象,这就是我必须使用的原因Set.

我在这里想念什么?

这是Range.SpecialCellsExcel中的方法帮助:

在此输入图像描述

excel vba excel-vba excel-2010

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

无法在Windows 7上导入ctypes

任何想法为什么我在尝试导入时会出现此错误ctypes:

>>> from ctypes import *

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    from ctypes import *
  File "C:/Python27\ctypes.py", line 3, in <module>
    libc = ctypes.windll.msvcrt
AttributeError: 'module' object has no attribute 'windll'
Run Code Online (Sandbox Code Playgroud)

python windows ctypes python-2.7

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