rldd 0.4.0

A program to print shared object dependencies
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
use std::collections::{HashMap, HashSet};
use std::ffi::OsStr;
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;

use crate::elf::android::*;
use crate::search_path;

use object::elf::{FileClass, Machine};

pub type NamespaceLinkingConfigVec = Vec<String>;

#[derive(Debug)]
pub struct NamespaceConfig {
    name: String,
    isolated: bool,
    visible: bool,
    allowed_libs: Vec<String>,
    pub search_paths: search_path::SearchPathVec,
    pub namespaces: NamespaceLinkingConfigVec,
}

impl NamespaceConfig {
    pub fn is_accessible<S: AsRef<str>>(&self, file: S) -> bool {
        if !self.isolated {
            return true;
        }

        if !self.allowed_libs.is_empty() && !self.allowed_libs.contains(&file.as_ref().to_string())
        {
            return false;
        }

        // The resolve_dependency_ld_cache will check the search_path and fail if it is not
        // found.
        true
    }
}

const DEFAULT_NAME_CONFIG: &str = "default";

pub type LdCacheNs = HashMap<String, NamespaceConfig>;

#[derive(Debug)]
pub struct LdCache {
    namespaces_config: LdCacheNs,
}

impl LdCache {
    fn new() -> LdCache {
        LdCache {
            namespaces_config: LdCacheNs::new(),
        }
    }

    pub fn get_default_namespace(&self) -> Option<&NamespaceConfig> {
        self.namespaces_config.get(DEFAULT_NAME_CONFIG)
    }

    pub fn get_namespace<S: AsRef<str>>(&self, name: S) -> Option<&NamespaceConfig> {
        self.namespaces_config.get(name.as_ref())
    }

    pub fn namespaces_count(&self) -> usize {
        self.namespaces_config.len()
    }

    fn config_set(&self) -> HashSet<String> {
        self.namespaces_config.keys().cloned().collect()
    }

    fn push_namespace(&mut self, name: &str) {
        self.namespaces_config.insert(
            name.to_string(),
            NamespaceConfig {
                name: name.to_string(),
                isolated: false,
                visible: false,
                search_paths: search_path::SearchPathVec::new(),
                allowed_libs: Vec::<String>::new(),
                namespaces: NamespaceLinkingConfigVec::new(),
            },
        );
    }
}

struct Properties {
    properties: HashMap<String, String>,
    target_sdk_version: String,
}

impl Properties {
    fn new() -> Properties {
        Properties {
            properties: HashMap::<String, String>::new(),
            target_sdk_version: "".to_string(),
        }
    }

    fn add<K: AsRef<str>, V: AsRef<str>>(&mut self, key: K, value: V) {
        self.properties
            .insert(key.as_ref().to_string(), value.as_ref().to_string());
    }

    fn append<K: AsRef<str>, V: AsRef<str>>(&mut self, key: K, value: V) {
        let key = key.as_ref().to_string();
        if let Some(v) = self.properties.get_mut(&key) {
            let sep = if key.ends_with(".links") || key.ends_with(".namespaces") {
                ','
            } else if key.ends_with(".paths")
                || key.ends_with(".shared_libs")
                || key.ends_with(".whitelisted")
                || key.ends_with(".allowed_libs")
            {
                ':'
            } else {
                return;
            };
            v.push_str(&format!("{sep}{}", value.as_ref()));
        } else {
            self.add(key, value);
        };
    }

    fn get<S: AsRef<str>>(&self, name: S) -> Option<&String> {
        self.properties.get(name.as_ref())
    }

    fn get_bool<S: AsRef<str>>(&self, name: S) -> bool {
        self.properties
            .get(name.as_ref())
            .map(|s| s == "true")
            .unwrap_or(false)
    }

    fn get_string<S: AsRef<str>>(&self, name: S) -> String {
        self.properties
            .get(name.as_ref())
            .unwrap_or(&"".to_string())
            .to_string()
    }

    fn get_paths<S: AsRef<str>>(
        &self,
        name: S,
        e_machine: Machine,
        ei_class: FileClass,
    ) -> search_path::SearchPathVec {
        let mut path = self.get_string(name);

        let lib = libpath(e_machine, ei_class).unwrap();

        path = path.replace("${SDK_VER}", self.target_sdk_version.as_str());

        let vndk_version_str = get_vndk_version_str('-');

        path = path.replace("${VNDK_VER}", vndk_version_str.as_str());
        path = path.replace("${VNDK_APEX_VER}", vndk_version_str.as_str());

        path = path.replace("${LIB}", lib);

        search_path::from_string(path, &[':'])
    }
}

#[derive(Debug)]
enum Token {
    PropertyAssign,
    PropertyAppend,
    Section,
    Error,
}

fn get_vndk_version_str(delimiter: char) -> String {
    let vndk_str = get_vndk_version_string("");
    if vndk_str.is_empty() || vndk_str == "default" {
        return "".to_string();
    }
    format!("{delimiter}{vndk_str}")
}

pub fn get_ld_config_path<P: AsRef<Path>>(
    executable: &P,
    e_machine: Machine,
    ei_class: FileClass,
) -> Option<String> {
    fn get_ld_config_vndk_path() -> String {
        if get_property_bool("ro.vndk.lite", false).unwrap() {
            return "/system/etc/ld.config.vndk_lite.txt".to_string();
        }

        format!("/system/etc/ld.config{}.txt", get_vndk_version_str('.'))
    }

    fn get_default_ld_config_path() -> Option<String> {
        Some("/system/etc/ld.config.txt".to_string())
    }

    fn get_vndk_ld_config_path(
        e_machine: Machine,
        ei_class: FileClass,
        linkerconfig: bool,
    ) -> Option<String> {
        if let Some(abi) = abi_string(e_machine, ei_class) {
            let ld_config_arch = format!("/system/etc/ld.config.{abi}.txt");
            if Path::new(&ld_config_arch).exists() {
                return Some(ld_config_arch);
            }
        }

        if linkerconfig {
            let linkerconfig_path = "/linkerconfig/ld.config.txt".to_string();
            if Path::new(&linkerconfig_path).exists() {
                return Some(linkerconfig_path);
            }
        }

        let vndk_config = get_ld_config_vndk_path();
        if Path::new(&vndk_config).exists() {
            return Some(vndk_config);
        }

        get_default_ld_config_path()
    }

    fn get_apex_ld_config_path<P: AsRef<Path>>(
        executable: &P,
        linkerconfig: bool,
    ) -> Option<String> {
        let parts: Vec<&OsStr> = executable.as_ref().iter().collect();
        if parts.len() == 5 && parts[1] == "apex" && parts[3] == "bin" {
            let name = parts[2].to_string_lossy();
            if linkerconfig {
                let linkerconfig_path = format!("/linkerconfig/{name}/ld.config.txt)");
                if Path::new(&linkerconfig_path).exists() {
                    return Some(linkerconfig_path);
                }
            }
            let apex_config = format!("/apex/{name}/etc/ld.config.txt");
            if Path::new(&apex_config).exists() {
                return Some(apex_config);
            }
        }
        None
    }

    if let Ok(release) = get_release() {
        return match release {
            // Android 7.0/7.1 does not support ld.config.txt.
            AndroidRelease::AndroidR24 | AndroidRelease::AndroidR25 => None,

            // Android 8.0/8.1 has the ld.config.txt hardcoded.
            AndroidRelease::AndroidR26 | AndroidRelease::AndroidR27 => get_default_ld_config_path(),

            // Android 9 added support for abi and vndk specific path.
            AndroidRelease::AndroidR28 => get_vndk_ld_config_path(e_machine, ei_class, false),

            // Android 10 added support per binary ld.config.txt.
            AndroidRelease::AndroidR29 => {
                if let Some(cfg) = get_apex_ld_config_path(executable, false) {
                    return Some(cfg);
                }
                get_vndk_ld_config_path(e_machine, ei_class, false)
            }

            // Android 11 added the /linkerconfig folder support.
            AndroidRelease::AndroidR30
            | AndroidRelease::AndroidR31
            | AndroidRelease::AndroidR32
            | AndroidRelease::AndroidR33
            | AndroidRelease::AndroidR34 => {
                if let Some(cfg) = get_apex_ld_config_path(executable, true) {
                    return Some(cfg);
                }
                get_vndk_ld_config_path(e_machine, ei_class, true)
            }
        };
    }
    None
}

pub fn read_version_file<P: AsRef<Path>>(binary: &P) -> Result<i64, &'static str> {
    if let Some(parent) = binary.as_ref().parent() {
        if let Ok(version_str) = std::fs::read_to_string(parent.join(".version")) {
            if let Ok(value) = version_str.parse::<i64>() {
                return Ok(value);
            }
        }
    }
    Err("error reading version file")
}

pub fn parse_ld_config_txt<P1: AsRef<Path>, P2: AsRef<Path>, S: AsRef<str>>(
    filename: &P2,
    binary: &P1,
    interp: S,
    e_machine: Machine,
    ei_class: FileClass,
) -> Result<LdCache, &'static str> {
    let is_asan = is_asan(interp);
    let release = get_release().map_err(|_| "invalid android release")?;

    if is_asan && matches!(release, AndroidRelease::AndroidR26) {
        return Err("asan not supported");
    }

    let mut lines = match read_lines(filename) {
        Ok(lines) => lines,
        Err(_e) => return Err("Could not open the filename"),
    };

    let section = find_initial_section(binary, &mut lines)?;

    find_section(&section, &mut lines)?;

    let mut properties = Properties::new();
    while let Some(Ok(line)) = lines.next() {
        let (token, line) = match next_token(&line) {
            Some(fields) => fields,
            None => continue,
        };
        match token {
            Token::PropertyAssign => {
                let (name, value) = parse_assignment(&line)?;
                properties.add(name, value);
            }
            Token::PropertyAppend => {
                let (name, value) = parse_append(&line)?;
                properties.append(name, value);
            }
            Token::Section | Token::Error => break,
        }
    }

    let target_sdk_version = if properties.get_bool("enable.target.sdk.version") {
        read_version_file(binary)?.to_string()
    } else {
        release.to_string()
    };
    properties.target_sdk_version = target_sdk_version;

    let mut ldcache = LdCache::new();

    ldcache.push_namespace(DEFAULT_NAME_CONFIG);

    if let Some(additional_namespaces) = properties.get("additional.namespaces") {
        for namespace in additional_namespaces.split(',') {
            ldcache.push_namespace(namespace);
        }
    }

    // The loop below borrow as immutable, so it can not check if the linked namespace
    // is within the ldcache.  To accomplish a different set with only ldcache
    // keys is used.
    let ns_configs_set = ldcache.config_set();

    for (_, ns) in ldcache.namespaces_config.iter_mut() {
        let mut property_name_prefix = format!("namespace.{}", ns.name);
        if let Some(linked_namespaces) = properties.get(&format!("{property_name_prefix}.links")) {
            for ns_linked in linked_namespaces.split(',') {
                if !ns_configs_set.contains(ns_linked) {
                    return Err("undefined namespace");
                }

                let allow_all = properties.get_bool(format!(
                    "{property_name_prefix}.link.{ns_linked}.allow_all_shared_libs"
                ));

                let shared_libs = properties.get_string(format!(
                    "{property_name_prefix}.link.{ns_linked}.shared_libs"
                ));

                if !allow_all && shared_libs.is_empty() {
                    return Err("list of shared_libs is not specified or is empty.");
                }

                if allow_all && !shared_libs.is_empty() {
                    return Err("both shared_libs and allow_all_shared_libs are set.");
                }

                ns.namespaces.push(ns_linked.to_string());
            }
        }

        ns.isolated = properties.get_bool(format!("{property_name_prefix}.isolated"));
        ns.visible = properties.get_bool(format!("{property_name_prefix}.visible"));

        // Android r31 added 'allowed_libs' as synonym for 'whitelisted'.
        let mut allowed_libs: Vec<String> = properties
            .get_string(format!("{property_name_prefix}.whitelisted"))
            .split(':')
            .map(|s| s.to_string())
            .filter(|x| !x.is_empty())
            .collect();
        allowed_libs.append(
            &mut properties
                .get_string(format!("{property_name_prefix}.allowed_libs"))
                .split(':')
                .map(|s| s.to_string())
                .filter(|x| !x.is_empty())
                .collect(),
        );
        ns.allowed_libs = allowed_libs;

        if is_asan {
            property_name_prefix.push_str(".asan");
        }

        ns.search_paths = properties.get_paths(
            format!("{property_name_prefix}.search.paths"),
            e_machine,
            ei_class,
        );

        // Skip the permitted.paths, since it is not required for program loading.
    }

    Ok(ldcache)
}

fn find_initial_section<P: AsRef<Path>>(
    binary: &P,
    lines: &mut io::Lines<io::BufReader<File>>,
) -> Result<String, &'static str> {
    while let Some(Ok(line)) = lines.next() {
        let (token, line) = match next_token(&line) {
            Some(fields) => fields,
            None => continue,
        };
        // Bionic loader ignore ill formatted lines.
        match token {
            Token::PropertyAssign => {
                let (name, value) = parse_assignment(&line)?;
                if !name.starts_with("dir.") {
                    continue;
                }

                if let Ok(resolved) = std::fs::canonicalize(value) {
                    if binary.as_ref().starts_with(resolved) {
                        return Ok(name[4..].to_string());
                    }
                }
            }
            Token::Section => break,
            Token::PropertyAppend | Token::Error => continue,
        }
    }
    Err("initial section for binary not found")
}

fn find_section(
    section: &String,
    lines: &mut io::Lines<io::BufReader<File>>,
) -> Result<(), &'static str> {
    while let Some(Ok(line)) = lines.next() {
        let (token, line) = match next_token(&line) {
            Some(line) => line,
            None => continue,
        };
        match token {
            Token::PropertyAssign | Token::PropertyAppend => continue,
            Token::Section => {
                if section == &line {
                    return Ok(());
                }
            }
            _ => break,
        }
    }
    Err("section for binary not found")
}

fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where
    P: AsRef<Path>,
{
    let file = File::open(filename)?;
    Ok(io::BufReader::new(file).lines())
}

fn next_token(line: &str) -> Option<(Token, String)> {
    // Remove leading whitespace.
    let line = line.trim_start();
    // Remove trailing comments.
    let comment = match line.find('#') {
        Some(comment) => comment,
        None => line.len(),
    };
    let line = &line[0..comment];
    // Remove trailing whitespaces.
    let line = line.trim_end();
    // Skip empty lines.
    if line.is_empty() {
        return None;
    }

    if line.starts_with('[') && line.ends_with(']') {
        return Some((Token::Section, line[1..line.len() - 1].to_string()));
    } else if line.contains("+=") {
        return Some((Token::PropertyAppend, line.to_string()));
    } else if line.contains('=') {
        return Some((Token::PropertyAssign, line.to_string()));
    }

    Some((Token::Error, line.to_string()))
}

fn parse_assignment(line: &str) -> Result<(&str, &str), &'static str> {
    let vec: Vec<&str> = line.split('=').collect();
    if vec.len() != 2 {
        return Err("invalid assigment line");
    }
    Ok((vec[0].trim(), vec[1].trim()))
}

fn parse_append(line: &str) -> Result<(&str, &str), &'static str> {
    let vec: Vec<&str> = line.split("+=").collect();
    if vec.len() != 2 {
        return Err("invalid append line");
    }
    Ok((vec[0].trim(), vec[1].trim()))
}

#[cfg(test)]
mod tests {
    use super::*;
    use object::elf::*;
    use std::fs;
    use std::fs::File;
    use std::io::{Error, ErrorKind, Write};
    use std::iter::zip;
    use tempfile::TempDir;

    fn create_cfg(tmp_path: &str) -> String {
        format!(
            "# comment \n\
      dir.test = {base}\n\
      \n\
      [test]\n\
      \n\
      enable.target.sdk.version = true\n\
      additional.namespaces=system\n\
      additional.namespaces+=vndk\n\
      additional.namespaces+=vndk_in_system\n\
      namespace.default.isolated = true\n\
      namespace.default.search.paths = {base}/vendor/${{LIB}}\n\
      namespace.default.permitted.paths = {base}/vendor/${{LIB}}\n\
      namespace.default.asan.search.paths = {base}/data\n\
      namespace.default.asan.search.paths += {base}/vendor/${{LIB}}\n\
      namespace.default.asan.permitted.paths = {base}/data:{base}/vendor\n\
      namespace.default.links = system\n\
      namespace.default.links += vndk\n\
      namespace.default.link.system.shared_libs=  libc.so\n\
      namespace.default.link.system.shared_libs +=   libm.so:libdl.so\n\
      namespace.default.link.system.shared_libs   +=libstdc++.so\n\
      namespace.default.link.vndk.shared_libs = libcutils.so:libbase.so\n\
      namespace.system.isolated = true\n\
      namespace.system.visible = true\n\
      namespace.system.search.paths = {base}/system/${{LIB}}\n\
      namespace.system.permitted.paths = {base}/system/${{LIB}}\n\
      namespace.system.asan.search.paths = {base}/data:{base}/system/${{LIB}}\n\
      namespace.system.asan.permitted.paths = {base}/data:{base}/system\n\
      namespace.vndk.isolated = tr\n\
      namespace.vndk.isolated += ue\n\
      namespace.vndk.search.paths = {base}/system/${{LIB}}/vndk\n\
      namespace.vndk.asan.search.paths = {base}/data\n\
      namespace.vndk.asan.search.paths += {base}/system/${{LIB}}/vndk\n\
      namespace.vndk.links = default\n\
      namespace.vndk.link.default.allow_all_shared_libs = true\n\
      namespace.vndk.link.vndk_in_system.allow_all_shared_libs = true\n\
      namespace.vndk_in_system.isolated = true\n\
      namespace.vndk_in_system.visible = true\n\
      namespace.vndk_in_system.search.paths = {base}/system/${{LIB}}\n\
      namespace.vndk_in_system.permitted.paths = {base}/system/${{LIB}}\n\
      namespace.vndk_in_system.whitelisted = libz.so:libyuv.so:libtinyxml2.so\n\
      \n",
            base = tmp_path
        )
    }

    fn test_skeleton(is_asan: bool) -> Result<(), std::io::Error> {
        let interp = match &is_asan {
            true => "linker_asan",
            false => "linker",
        };

        let tmpdir = TempDir::new()?;
        let cfgpath = tmpdir.path().join("ld.config.txt");

        let dirtest = tmpdir.path().join("tmp");
        fs::create_dir(&dirtest)?;

        let binpath = dirtest.join("binary");
        File::create(&binpath)?;

        let versiondir = dirtest.join(".version");
        let mut versionfile = File::create(&versiondir)?;
        write!(versionfile, "26")?;

        let vendor = dirtest.join("vendor");
        fs::create_dir(&vendor)?;

        let vendorlib = dirtest.join("vendor/lib");
        fs::create_dir(&vendorlib)?;

        let data = dirtest.join("data");
        fs::create_dir(&data)?;

        let system = dirtest.join("system");
        fs::create_dir(&system)?;

        let systemlib = dirtest.join("system/lib");
        fs::create_dir(&systemlib)?;

        let vndklib = dirtest.join("system/lib/vndk");
        fs::create_dir(&vndklib)?;

        let cfgcontent = create_cfg(&dirtest.to_string_lossy());

        let mut file = File::create(&cfgpath)?;
        file.write_all(cfgcontent.as_bytes())?;

        let expected_default_search_paths = match &is_asan {
            true => vec![data.to_str().unwrap(), vendorlib.to_str().unwrap()],
            false => vec![vendorlib.to_str().unwrap()],
        };
        let expected_system_search_paths = match &is_asan {
            true => vec![data.to_str().unwrap(), systemlib.to_str().unwrap()],
            false => vec![systemlib.to_str().unwrap()],
        };
        let expected_vndk_search_paths = match &is_asan {
            true => vec![data.to_str().unwrap(), vndklib.to_str().unwrap()],
            false => vec![vndklib.to_str().unwrap()],
        };
        let expected_vndk_in_system_search_paths = match &is_asan {
            true => vec![],
            false => vec![systemlib.to_str().unwrap()],
        };

        match parse_ld_config_txt(&cfgpath, &binpath, interp, EM_386, ELFCLASS32) {
            Ok(ldcache) => {
                let default_ns = ldcache
                    .get_default_namespace()
                    .ok_or(Error::new(ErrorKind::Other, "default namespace not found"))?;

                assert_eq!(default_ns.isolated, true);
                assert_eq!(default_ns.visible, false);
                assert_eq!(
                    default_ns.search_paths.len(),
                    expected_default_search_paths.len()
                );
                for (d, e) in zip(&default_ns.search_paths, &expected_default_search_paths) {
                    assert_eq!(d, e);
                }

                assert_eq!(default_ns.namespaces.len(), 2);
                assert_eq!(default_ns.namespaces[0], "system");
                assert_eq!(default_ns.namespaces[1], "vndk");

                assert_eq!(ldcache.namespaces_config.len(), 4);

                let system_ns = ldcache.namespaces_config.get("system").unwrap();
                assert_eq!(system_ns.name, "system");
                assert_eq!(system_ns.isolated, true);
                assert_eq!(system_ns.visible, true);
                assert_eq!(
                    system_ns.search_paths.len(),
                    expected_system_search_paths.len()
                );
                for (d, e) in zip(&system_ns.search_paths, &expected_system_search_paths) {
                    assert_eq!(d, e);
                }

                let vndk_ns = ldcache.namespaces_config.get("vndk").unwrap();
                assert_eq!(vndk_ns.name, "vndk");
                assert_eq!(vndk_ns.isolated, false);
                assert_eq!(vndk_ns.visible, false);
                assert_eq!(vndk_ns.search_paths.len(), expected_vndk_search_paths.len());
                for (d, e) in zip(&vndk_ns.search_paths, &expected_vndk_search_paths) {
                    assert_eq!(d, e);
                }
                assert_eq!(vndk_ns.namespaces.len(), 1);

                let vndk_ns_system = ldcache.namespaces_config.get("vndk_in_system").unwrap();
                assert_eq!(vndk_ns_system.name, "vndk_in_system");
                assert_eq!(vndk_ns_system.isolated, true);
                assert_eq!(vndk_ns_system.visible, true);
                assert_eq!(
                    vndk_ns_system.search_paths.len(),
                    expected_vndk_in_system_search_paths.len()
                );
                for (d, e) in zip(
                    &vndk_ns_system.search_paths,
                    &expected_vndk_in_system_search_paths,
                ) {
                    assert_eq!(d, e);
                }
                assert_eq!(
                    vndk_ns_system.allowed_libs,
                    vec!["libz.so", "libyuv.so", "libtinyxml2.so"]
                );

                Ok(())
            }
            Err(e) => Err(Error::new(ErrorKind::Other, e)),
        }
    }

    #[test]
    fn smoke() -> Result<(), std::io::Error> {
        test_skeleton(false)
    }

    #[test]
    fn smoke_asan() -> Result<(), std::io::Error> {
        test_skeleton(true)
    }
}