libc

Libc's environ is zero on Android/Intel

北城以北 提交于 2019-12-11 04:42:26
问题 Why would the value of libc 's global variable environ be zero on Android/Intel? I have a piece of third party native code that unconditionally dereferences environ as provided by libc . It occasionally crashes on Android Intel devices; last time observed on ASUS ME371MG tablet with Intel Atom Z2420 under Android 4.2.1. I could not reproduce it on the emulator with the same 4.2.1. The code in question is in a shared object (SO) startup code. The startup code is being invoked, judging by the

How do I access fields of a *mut libc::FILE?

夙愿已清 提交于 2019-12-11 04:06:57
问题 I'm trying to access the different fields of the FILE struct of libc . FILE implementation in Rust according to the memory mapping in stdio.h : #[repr(C)] pub struct FILE { pub _p: libc::c_char, pub _r: libc::c_int, pub _w: libc::c_int, pub _flags: libc::c_short, pub _file: libc::c_short, ... } when working with FILE s in libc they come in the mut * variant, and this somehow is in the way to access the fields. The following code triggers error: attempted access of field _flags on type '*mut

Difference between result of ftell(FILE* fd) and lseek(int fd, off_t offset, int whence)

余生颓废 提交于 2019-12-11 04:00:46
问题 Consider this sample of code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { //this file exists and contains data: "ABCDEFGHIJKLM" FILE* file = fopen("file.txt", "r"); char data[4]; long int pos = ftell(file); fseek(file, 0, SEEK_SET); fread(data, 4, 1, file); fseek(file, pos, SEEK_SET); printf("ftell: %d\n", ftell(file)); printf("lseek: %d\n", lseek(fileno(file), 0, SEEK_CUR)); fread(data, 1, 4, file); //this correctly prints A //but external function needs fileno

qsort and bsearch an array of pointers

∥☆過路亽.° 提交于 2019-12-11 02:54:28
问题 I need to sort an array of pointers to struc. In fact, I need to do searching among adresses to see if a given pointer to a struct is present in the array. Unfortunately, I don't have nothing "comparable" inside those structures and so I want to sort'em just by address. My code is like that: item* arr[SIZE]; //something is inserted qsort(arr, SIZE, sizeof(item*), (void*)compare_funct); //CUT bsearch(curr, arr, SIZE, sizeof(item*), (void*)compare_funct); I tried creating a compare_funct just

compilation error on clock_gettime and CLOCK_MONOTONIC

大憨熊 提交于 2019-12-11 02:08:19
问题 I'm using clock_gettime in a program. I've tried including as well as but neither works. I have also added -lrt to my compiler arguments but still I get the same errors. This is on CentOS Linux release 7.2.1511 (Core) gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4) GNU ld version 2.23.52.0.1-55.el7 20130226 ldd (GNU libc) 2.17 Compiler output: gcc -o main packet.c connect.c transport.c accept.c main.c close.c util.c receive.c send.c congestion.c -Wall -g -std=c99 -lrt util.c: In function ‘millis’:

No qsort_r for Android (or how to disable force Thumb to use CLZ in Android ARM code)

送分小仙女□ 提交于 2019-12-11 01:31:32
问题 What I want to do (high-level): use qsort_r on Android. There is no default implementation. So I've grabbed one from BSD. Unfortunately it needs fls functions which is also unavailable on Android. So I've grabbed Apple Open Source Libc library and copied ARM implementation into an inline assembly. Now I'm getting this: Assembler messages: Error: selected processor does not support Thumb mode `clz r3,r0' Error: cannot honor width suffix -- `rsb r0,r3,#32' AFAIR ARM-6 doesn't support it in

Load both musl libc.so and gcc libc.so in the same process?

不羁的心 提交于 2019-12-10 17:46:33
问题 I have a shared library compiled with musl libc $ readelf -d ./libinterop_d.so Dynamic section at offset 0x8ecb0 contains 22 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED) Shared library: [libc.so] 0x000000000000000f (RPATH) Library rpath: [/usr/local/musl/lib] 0x000000000000000c (INIT) 0x46350 0x000000000000000d (FINI) 0x7664a 0x0000000000000019 (INIT_ARRAY) 0x28e700 0x000000000000001b (INIT_ARRAYSZ) 64 (bytes) 0x000000000000001a (FINI_ARRAY) 0x28e740 0x000000000000001c (FINI

valgrind complaining about __mktime - is that my fault?

大憨熊 提交于 2019-12-10 16:39:35
问题 For the first time (in my new dev environment) I'm seeing valgrind complain about mktime, but I'm not sure if this is a bug in the libc library, valgrind, or my code. I'll start with the error (below) - is this enough info to explain the cause? ==3682== at 0x38ACE9A505: __mktime_internal (in /lib64/libc-2.12.so) ==3682== by 0x4D66F7: ??? ==3682== by 0x4D7611: ??? ==3682== by 0x4D23CD: ??? ==3682== by 0x4D175B: ??? ==3682== by 0x38ACE1ECDC: (below main) (in /lib64/libc-2.12.so) ==3682==

Is there a linker flag to force it to load all shared libraries at start time?

痞子三分冷 提交于 2019-12-10 15:59:45
问题 Is there a flag or any other directive that I can use to force the Linux Dynamic Linker ld.so to load all shared libraries at once at start of the program instead of lazy binding. Essentially I want to turn off lazy binding. Thanks 回答1: Setting environment variable LD_BIND_NOW = 1 will do that. Thanks to @skwllsp for the answer. 回答2: man ld sayes: -z keyword now - When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is

What is the purpose of glibc's atomic_forced_read function?

帅比萌擦擦* 提交于 2019-12-10 15:59:10
问题 I am trying to understand the purpose of the definition of atomic_forced_read which shows up frequently in the GNU libc implementation of malloc.c. I am not great when it comes to inline assembly, but it looks like this returns the exact same value, with the same type as the input value. what am I missing here? Atomic forced read definition in atomic.h 523 #ifndef atomic_forced_read 524 # define atomic_forced_read(x) \ 525 ({ __typeof (x) __x; __asm ("" : "=r" (__x) : "0" (x)); __x; }) 526