(gdb) info symbol exit
exit in section .text of /lib64/libc.so.6
(gdb) info symbol _exit
_exit in section .text of /lib64/libc.so.6
Run Code Online (Sandbox Code Playgroud)
有谁知道?
好的..我制作了一个使用 zlib 解压缩字符串的系统......我认为它有效,但我的 base64 转换器有问题,所以我不能确定数据是否正确......它适用于一个非常小的字符串,即“帮助”,但该字符串会导致缓冲区溢出“eJxjZMAOmHCIM+MQZ8EhzgrEAAKAABA=”
this is the function in question!
#include <zlib.h>
#include <stdlib.h>
#include <string.h>
#include "../../inc/tools/Zunz.h"
using namespace tool;
static const int maxUncompressedSize = 4096;
std::string Zunz::UnZip(std::string const& s)
{
char *cmprsd;
char uncompressed[maxUncompressedSize];
int sizeOfS = sizeof(s);
cmprsd = (char*) malloc(sizeOfS);
strcpy(cmprsd, s.c_str());
// deflate
// zlib struct
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = (uInt)strlen(cmprsd)+1; // size of input, string + terminator
defstream.next_in = (Bytef *)cmprsd; // input char …Run Code Online (Sandbox Code Playgroud) 我运行的是 32 位 SUSE Linux,内核级别为 3.0.76。
我可以看到代码中的 stat() 调用在 strace 输出中转换为 stat64(),而无需指定任何 CPP 选项,例如 _LARGEFILE64_SOURCE 或 _FILE_OFFSET_BITS=64。
#include<stdio.h>
#include<sys/stat.h>
int main ( int argc, char * argv[] )
{
char * path = "nofile";
struct stat b;
if (stat(path, &b) != 0) {
}
}
Run Code Online (Sandbox Code Playgroud)
我用 gcc 编译了这个文件,没有编译器选项/标志。
运行程序时,相关的 strace 输出为:
munmap(0xb770a000, 200704) = 0
stat64("nofile", 0xbfb17834) = -1 ENOENT (No such file or directory)
exit_group(-1)
Run Code Online (Sandbox Code Playgroud)
谁能告诉我 stat() 是如何转换为 stat64() 的?
提前致谢!
我正在用 Rust 编写的 shell 中实现 I/O 重定向。我通过使用带有原始文件描述符和pipe()libc crate 的不安全代码成功地在两个子进程之间进行管道传输。
当我尝试将stdout最后一个子进程重定向到我有权访问的文件时,它失败了:
extern crate libc;
use std::process::{Command, Stdio};
use std::os::unix::io::{FromRawFd, IntoRawFd};
use std::fs::File;
use self::libc::c_int;
fn main() {
let mut fds = [-1 as c_int, -1 as c_int];
let fd1 = File::open("test1").unwrap().into_raw_fd();
let fd2 = File::open("test2").unwrap().into_raw_fd();
let fd3 = File::open("test3").unwrap().into_raw_fd();
println!("{:?}, {:?}, {:?}", fd1, fd2, fd3);
unsafe {
libc::pipe(&mut fds[0] as *mut c_int);
let cmd1 = Command::new("ls")
.arg("/")
.stdout(Stdio::from_raw_fd(fds[1]))
.spawn()
.unwrap();
let mut cmd2 = Command::new("grep")
.arg("etc")
.stdin(Stdio::from_raw_fd(fds[0])) …Run Code Online (Sandbox Code Playgroud) 我遇到了一个非常烦人的问题:我有一个程序在开始时创建一个线程,该线程将在执行期间启动其他内容(fork() 紧随其后的是 execve())。
这是我的程序达到(我认为)死锁时两个线程的 bt:
线程 2 (LWP 8839):
#0 0x00007ffff6cdf736 在 __libc_fork () 中 ../sysdeps/nptl/fork.c:125
#1 _IO_new_proc_open 中的 0x00007ffff6c8f8c0 (fp=fp@entry=0x7ffff00031d0, command=command@entry=0x7ffff6c26e20 "ps -u brejon | grep \"cvc\"
#2 _IO_new_popen 中的 0x00007ffff6c8fbcc (命令 = 0x7ffff6c26e20 "ps -u user| grep \"cvc\" | wc -l", mode=0x42c7fd "r") at iopopen.c:296
#3-4...
#5 0x00007ffff74d9434 在 pthread_create.c:333 处的 start_thread (arg=0x7ffff6c27700)
#6 0x00007ffff6d0fcfd 在克隆()中位于../sysdeps/unix/sysv/linux/x86_64/clone.S:109
线程 1 (LWP 8835):
#0 __lll_lock_wait_private () 位于 ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
malloc_atfork 中的 #1 0x00007ffff6ca0ad9 (sz=140737337120848,调用者=) at arena.c:179
#2 0x00007ffff6c8d875 在 __GI__IO_file_doallocate (fp=0x17a72230) …
我正在尝试使用 NASM 和 GCC 制作一个程序:
global main
extern puts
section .data
hi db 'hello', 0
section .text
main:
push hi
call puts
ret
Run Code Online (Sandbox Code Playgroud)
我正在构建:
nasm -f elf64 main.asm
gcc main.o -o main
rm main.o
Run Code Online (Sandbox Code Playgroud)
我得到:
/usr/bin/ld: main.o: relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
从像这样的示例中存在奇怪的堆栈操作来判断,我有一种感觉我做错了一些事情。不过,出于某种原因,我找不到任何实际解释这一点的文档(事实上,我几乎找不到任何使用 NASM 进行 64 位开发的有用文档,这使得我迄今为止所做的一切都成为真正的做起来很痛苦),并且添加类似的东西对我的错误输出没有任何影响。
更新:
我一直在看 …
是什么行为::ferror(FILE *),并std::ferror(FILE *)在传递无效指针?
C ++标准仅指C(请参阅草稿)。但是在C标准中,在ferror功能说明下没有提及有关NULL传递无效指针或传递指针时会发生的情况。
我的理解是,根据与C草案N1570 §7.21.3.4:
FILE关闭关联文件(包括标准文本流)后,指向对象的指针的值不确定。
但这不应该阻止检查给定FILE *指针(不确定)是否指向有效FILE对象的实现。¹
无论哪种方式,这些标准甚至都没有对这是未定义的行为,实现的定义还是其他内容保持沉默。
¹例如,fopen()可以将返回的指针存储在某个全局集中(例如std::set<FILE *>),ferror()然后类似的函数可以检查其参数是否包含在该集中,并另外fclose()将其从该集中删除。
我试图理解对main()inside的调用__libc_start_main()。我知道 的参数之一__libc_start_main()是 的地址main()。但是,我无法弄清楚 main() 是如何在内部调用的,__libc_start_main()因为没有操作码CALL或JMP. 在执行跳转到main().
0x7ffff7ded08b <__libc_start_main+203>: lea rax,[rsp+0x20]
0x7ffff7ded090 <__libc_start_main+208>: mov QWORD PTR fs:0x300,rax
=> 0x7ffff7ded099 <__libc_start_main+217>: mov rax,QWORD PTR [rip+0x1c3e10] # 0x7ffff7fb0eb0
Run Code Online (Sandbox Code Playgroud)
我"Hello, World!!"用 C写了一个简单的。在上面的程序集中:
main()地址处的指令之后0x7ffff7ded099。MOV(到RAX)指令导致跳转到main()?我目前正在编写一些 x86 汇编代码,并使用as和将其与 glibc 链接ld。
.section .data
str1:
.asciz "\n"
str3:
.asciz "Hello"
str4:
.asciz "Goodbye"
str5:
.asciz "Guten Tag!"
str6:
.asciz "Guten Morgen!"
.section .bss
.section .text
.globl _start
_start:
call main
movl %eax, %ebx
movl $1, %eax
int $0x80
# void writeLine(char*);
.type writeLine, @function
writeLine:
pushl %ebp
movl %esp, %ebp
movl $str1, %ecx
pushl %ecx
movl 8(%ebp), %ecx
pushl %ecx
call strcat
movl %eax, %ecx
pushl %ecx
call puts
popl %ebx
.leaver1:
movl …Run Code Online (Sandbox Code Playgroud) C 库的许多函数都明确标记为线程安全或非线程安全。例如,当我查看gmtime(3)的手册时,有一个很好的表格显示了这些函数中哪些是线程安全的,哪些不是。
查看stat(2)函数的手册页,它没有说明其中一种方式。除非另有说明,否则函数应该是线程安全的吗?
阅读POSIX 安全概念并没有真正清楚地表明未标记为不安全的函数是安全的。也许我在某个地方漏掉了一句话?