指向 NULL 的指针

Pointer to NULL

我有这个功能:

int execve(const char* filename, char* const argv[], char* const envp[]); 

并且我需要将 envp 参数设置为 NULL,因此在执行函数之前我需要一个指向 edx 寄存器中的 NULL 的指针(更好的说法是,带有 int 0x80 的系统调用)。问题是,我能做吗:

mov eax, 0
mov edx, eax  ; edx points to NULL, no to some address that contains NULL

或者需要我做:

push 0
mov edx, esp ; edx points to some address that contains NULL

这取决于操作系统。在Linux中你可以直接使用一个NULL指针。

man execve:

On Linux, argv and envp can be specified as NULL. In both cases, this has the same effect as specifying the argument as a pointer to a list containing a single null pointer. Do not take advantage of this misfeature! It is nonstandard and nonportable: on most other UNIX systems doing this will result in an error (EFAULT).