glibc

writing a glibc api for a system call [duplicate]

爱⌒轻易说出口 提交于 2019-12-01 09:06:31
Possible Duplicate: Need help with glibc source I understand how to implement our own system calls in linux kernel. I know we can call this with syscall() or with _asm() in a c program. But I want to understand how to write glibc api for this new system call?. How the open() and read() glibc function calls mapping into system call in kernel?. char message[ ] = "Hello!\n"; int main( void ) { write( 1, message, 7 ); exit( 0 ); } When I convert the above program into assembly it is giving main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %ecx subl $20, %esp

GDB step into Dynamic linker(ld.so) code

时间秒杀一切 提交于 2019-12-01 07:48:17
问题 I wanted to step into the code of ld.so whenever it will be used in my normal c code. I am trying to code flow through GDB in the TUI mode where you can see both source code and assembly as you step over the code. For this I also installed libc-dbg binutils-source package from ubuntu package manager. GDB can find the debug symbols for the ld.so itself and I can step at the instruction level that is using si but I cant step at the source level as GDB is not able to find the source for ld.so

malloc_trim(0) Releases Fastbins of Thread Arenas?

馋奶兔 提交于 2019-12-01 07:15:27
For the last week or so I've been investigating a problem in an application where the memory usage accumulates over time. I narrowed it down to a line that copies a std::vector< std::vector< std::vector< std::map< uint, map< uint, std::bitset< N> > > > > > in a worker thread (I realize this is a ridiculous way to organize memory). On a regular basis, the worker thread is destroyed, recreated, and that memory structure copied by the thread when it starts. The original data that gets copied is passed to the worker thread by reference from the main thread. Using malloc_stat and malloc_info, I can

How do you call vsnprintf() safely?

≯℡__Kan透↙ 提交于 2019-12-01 06:45:01
I'm porting some very old (> 10y) C code to modern Linuxes. I'm getting segmentation faults within a custom-written vsnprintf() wrapper (apparently its task is to detect duplicate output strings and intern them): char* strVPrintf(const String fmt, va_list ap) { /* Guess we need no more than 50 bytes. */ int n, size = 50; char* p = (char*)memMalloc(size), q; while (1) { /* Try to print in the allocated space. */ n = vsnprintf(p, size, fmt, ap); /* If that worked, return the string. */ if (n > -1 && n < size) { break; } /* Else try again with more space. */ if (n > -1) /* glibc 2.1 */ size = n +

writing a glibc api for a system call [duplicate]

人盡茶涼 提交于 2019-12-01 06:32:21
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Need help with glibc source I understand how to implement our own system calls in linux kernel. I know we can call this with syscall() or with _asm() in a c program. But I want to understand how to write glibc api for this new system call?. How the open() and read() glibc function calls mapping into system call in kernel?. char message[ ] = "Hello!\n"; int main( void ) { write( 1, message, 7 ); exit( 0 ); } When

Relevance of libc.so.6 in Linux kernel [closed]

孤街醉人 提交于 2019-12-01 05:57:35
My question is whether Linux kernel contains libc.so.6 ? After googling and going through different links, we found that libc.so.6 , is not a part of Linux kernel, as the kernel has same libraries implemented for its own use in kernel space. libc.so.6 is a userspace library. But, still, the question was left, if the libc.so.6 is removed from "/lib", it crashes, as all the basic applications of Linux crashes. So, the basic questions were left on: Can Linux run without libc.so.6 ? If yes, where such implementation is used? Who provides libc.so.6 ? Is it provided by Linux distributions only? Does

How do you call vsnprintf() safely?

我与影子孤独终老i 提交于 2019-12-01 05:34:19
问题 I'm porting some very old (> 10y) C code to modern Linuxes. I'm getting segmentation faults within a custom-written vsnprintf() wrapper (apparently its task is to detect duplicate output strings and intern them): char* strVPrintf(const String fmt, va_list ap) { /* Guess we need no more than 50 bytes. */ int n, size = 50; char* p = (char*)memMalloc(size), q; while (1) { /* Try to print in the allocated space. */ n = vsnprintf(p, size, fmt, ap); /* If that worked, return the string. */ if (n >

Relevance of libc.so.6 in Linux kernel [closed]

白昼怎懂夜的黑 提交于 2019-12-01 03:33:40
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . My question is whether Linux kernel contains libc.so.6 ? After googling and going through different links, we found that libc.so.6 , is not a part of Linux kernel, as the kernel has same libraries implemented for its own use in kernel space. libc.so.6 is a userspace library. But, still, the question was left, if

Async signal safety of fork()

自闭症网瘾萝莉.ら 提交于 2019-12-01 02:52:43
问题 According to Oracle's Multithreaded Programming Guide, fork() should be safe-to-use inside signal handlers. But my process got stuck inside signal handler with to following back trace: #0 __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95 #1 0x00007f86e6a9990d in _L_lock_48 () from /lib/x86_64-linux- gnu/libc.so.6 #2 0x00007f86e6a922ec in ptmalloc_lock_all () at arena.c:242 #3 0x00007f86e6ad5e82 in __libc_fork () at ./nptl/sysdeps/unix/sysv/linux/x86_64/..

How to tell if glibc is used

久未见 提交于 2019-12-01 02:07:42
I am trying to implement backtrace functionality for a large framework, which is used for different platforms and OS'es. In some of them, it is linked against glibc, while in the other, something different (eg. uclibc) is used. backtrace() function exists only in the former. Is there any way to tell whether glibc is used? Any #define? I was unable to find an answer in glibc manual. I know I can't have linking-time information during compilation, but I guess include files have to differ. At least backtrace have to be declared somewhere. I would like to check it without being forced to pass