gpt4 book ai didi

android - getsockname 返回-1,errno 是 EBADF?

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:52 25 4
gpt4 key购买 nike

程序运行到getsockname,返回-1,errno为9(EBADF,错误的文件描述符)。但是,Android 应用程序中检测的代码运行良好。

void sysLibCSendHookHandler(CPUState* env, int isStart){

if(isStart){
int fd = env->regs[0];
int buf = env->regs[1];
int len = env->regs[2];
int flags = env->regs[3];
DECAF_printf("xxxxx send(%d, %p, %d, %d)\n", fd, buf, len, flags);
extern int errno;
struct sockaddr_un sock_addr;
socklen_t sock_addr_len;
sock_addr_len = sizeof(sock_addr);
int t = getsockname(fd, (struct sockaddr*)&sock_addr, &sock_addr_len);
DECAF_printf("fd:%d",fd);}

最佳答案

此代码导致未定义的行为:

extern int errno;

根据 the C Standard7.5 个错误 (注意粗体部分):

The header defines several macros, all relating to the reporting of error conditions.

The macros are

EDOM
EILSEQ
ERANGE

which expand to integer constant expressions with type int, distinct positive values, and which are suitable for use in #if preprocessing directives; and

errno

which expands to a modifiable lvalue that has type int and thread local storage duration, the value of which is set to a positive error number by several library functions. If a macro definition is suppressed in order to access an actual object, or a program defines an identifier with the name errno, the behavior is undefined.

根据Google Android source code , errno 是定义为的宏

extern int *__geterrno(void);

#define errno (*__geterrno())

既然如此,您在 extern int errno 中看到的值就没有意义了。

关于android - getsockname 返回-1,errno 是 EBADF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44888482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com