libc

How to build apple's opensource libc?

 ̄綄美尐妖づ 提交于 2019-12-04 11:38:01
问题 I'm trying to build apple's opensource libc (from http://www.opensource.apple.com/source/Libc/Libc-763.11/) on my OS X 10.6.8 laptop. This is in an attempt to essentially get a locally generated replica of /usr/lib/libSystem.B.dylib, which I intend to experiment on further. I see a couple basic roadblocks though (unless, obviously, I'm missing something basic): No instructions on how to do the build. There are a couple of Makefiles in the URL I reference above, but they fail to build when I

What is “namespace cleanliness”, and how does glibc achieve it?

情到浓时终转凉″ 提交于 2019-12-04 10:53:51
问题 I came across this paragraph from this answer by @zwol recently: The __libc_ prefix on read is because there are actually three different names for read in the C library: read , __read , and __libc_read . This is a hack to achieve "namespace cleanliness", which you only need to worry about if you ever set out to implement a full-fledged and fully standards compliant C library. The short version is that there are many functions in the C library that need to call read , but some of them cannot

Installing a prebuilt binary on Android: “not found”

折月煮酒 提交于 2019-12-04 07:29:26
I'm trying to install a prebuilt binary in a custom Android image. For that I have copied it to a new directory in prebuilt/android-arm/ with an Android.mk file similar to this one: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := binary_name LOCAL_MODULE := binary_name LOCAL_MODULE_CLASS := EXECUTABLES include $(BUILD_PREBUILT) So if I run make system_image binary_name , the binary file is copied to /bin/ in system image. And if I run the emulator I can see the binary file in /system/bin . The permissions are the same as the other executables ( -rwxr-xr-x ) and, according

Atomically swap contents of two files on Linux

◇◆丶佛笑我妖孽 提交于 2019-12-04 07:28:10
I have two files, A and B , each with its own content. I would like to swap these two files, so A would become B , and B would become A . But I would like to do with a guaranty that no other process will find these two files in an inconsistent state, nor any process will find any of those files missing, even for a short while. So, as a side operation, I would also like to have a guaranty that if anything would go wrong during the operation, nothing will be changed (kind of like a transaction I guess). On OS X there is a exchangedata() function, so I guess I'm looking for a Linux equivalent of

Wrong mapping of C struct to Rust

不问归期 提交于 2019-12-04 04:28:17
问题 For educational purpose I try to access the FILE struct in Rust: unsafe { let passwd = libc::fopen("/etc/passwd".to_ptr(), &('r' as libc::c_char)); let fp = &mut *(passwd as *mut MY_FILE); println!("flags={}, file={}", fp._flags, fp._file); } the MY_FILE struct I obtained by running bindgen on stdio.h (I'm on OS X): bindgen /usr/include/stdio.h Somehow _flags is always 8 for files open in write mode (4 in read mode), so this flags seems off (I tested with a C code to verify that it indeed is

Segmentation Fault 11 linking os x 32-bit assembler

南笙酒味 提交于 2019-12-04 04:26:29
问题 UPDATE: Sure enough, it was a bug in the latest version of nasm. I "downgraded" and after fixing my code as shown in the answer I accepted, everything is working properly. Thanks, everyone! I'm having problems with what should be a very simple program in 32-bit assembler on OS X. First, the code: section .data hello db "Hello, world", 0x0a, 0x00 section .text default rel global _main extern _printf, _exit _main: sub esp, 12 ; 16-byte align stack push hello call _printf push 0 call _exit It

Jump to entry point of ELF from loader

╄→гoц情女王★ 提交于 2019-12-04 04:21:01
问题 Thanks to the help in this question, the loader can now map a statically compiled hello world into memory and jump somewhere in that memory region. The problem I'm facing now is I seem not to jump to the right address or I'm calling the function in the wrong way (or wrong function?). Below is the code to try; I can't find in glibc where the loader calls the entry point of the program to verify I'm doing the right thing. I tried: Calling _start(void) Calling _start(int, char**, char**) Calling

realloc but only first few bytes is meaningful

爷,独闯天下 提交于 2019-12-04 03:12:43
Assume I have used ptr = malloc(old_size); to allocate a memory block with old_size bytes. Only the first header_size bytes is meaningful. I'm going to increase the size to new_size . new_size is greater than old_size and old_size is greater than header_size . before: /- - - - - - - old_size - - - - - - - \ +===============+---------------------+ \-header_size-/ after: /- - - - - - - - - - - - - - - new_size - - - - - - - - - - - - - - - - - - -\ +===============+------------------------------------------------------------+ \- header_size-/ I don't care what is stored after ptr + header_size

gets() function and '\0' zero byte in input

被刻印的时光 ゝ 提交于 2019-12-04 02:17:43
问题 Will the gets() function from C language (e.g. from glibc) stop, if it reads a zero byte ( '\0' ) from the file ? Quick test: echo -ne 'AB\0CDE' Thanks. PS this question arises from comments in this question: return to libc - problem PPS the gets function is dangerous, but it is a question about this function itself, not about should anybody use it or not. 回答1: The behavior of gets() is that it stops when a newline character is encountered or if EOF is encountered. It does not care if it

How to debug standard c library functions like printf?

╄→гoц情女王★ 提交于 2019-12-04 02:11:25
问题 I wanted to debug printf function, so when I step inside the printf function (gdb debugger) it showed me this: __printf (format=0x80484d0 " my name is Adam") at printf.c:28 28 printf.c: No such file or directory. What is the meaning of this? And when I again started step then there are a lot more statements like this. Please help me to understand this. 回答1: I think it's pretty clear. There is a place where the gdb expects the source code to be, so download glibc 's source code and put it