1*4b9c6d91SCole Faust // Copyright 2019 The ChromiumOS Authors 2*4b9c6d91SCole Faust // Use of this source code is governed by a BSD-style license that can be 3*4b9c6d91SCole Faust // found in the LICENSE file. 4*4b9c6d91SCole Faust 5*4b9c6d91SCole Faust /// libminijail bindings for Rust. 6*4b9c6d91SCole Faust 7*4b9c6d91SCole Faust // TODO(crbug.com/1032672): Generate bindings at build time. 8*4b9c6d91SCole Faust // 9*4b9c6d91SCole Faust // Bindgen will invoke the C preprocessor to process headers, which means that the bindings 10*4b9c6d91SCole Faust // generated can depend on the architecture that actually ran bindgen. In particular, for 11*4b9c6d91SCole Faust // portability across compilers glibc defines types like __u8 and __rlim64_t in terms of C types 12*4b9c6d91SCole Faust // like unsigned char and unsigned long. This is problematic for __rlim64_t since that resolves to 13*4b9c6d91SCole Faust // unsigned long int on amd64, which will end up being 32-bit on 32-bit platforms. 14*4b9c6d91SCole Faust // 15*4b9c6d91SCole Faust // As a workaround to let us commit these bindings and still use them on 32-bit platforms, the 16*4b9c6d91SCole Faust // bindgen invocation blocklists some of the generated fixed-width types and redefines them 17*4b9c6d91SCole Faust // manually as Rust fixed-width types. 18*4b9c6d91SCole Faust // 19*4b9c6d91SCole Faust // Generated in CrOS SDK chroot with: 20*4b9c6d91SCole Faust // bindgen --default-enum-style rust \ 21*4b9c6d91SCole Faust // --blocklist-type '__rlim64_t' \ 22*4b9c6d91SCole Faust // --raw-line 'pub type __rlim64_t = u64;' \ 23*4b9c6d91SCole Faust // --blocklist-type '__u\d{1,2}' \ 24*4b9c6d91SCole Faust // --raw-line 'pub type __u8 = u8;' \ 25*4b9c6d91SCole Faust // --raw-line 'pub type __u16 = u16;' \ 26*4b9c6d91SCole Faust // --raw-line 'pub type __u32 = u32;' \ 27*4b9c6d91SCole Faust // --blocklist-type '__uint64_t' \ 28*4b9c6d91SCole Faust // --allowlist-function '^minijail_.*' \ 29*4b9c6d91SCole Faust // --allowlist-var '^MINIJAIL_.*' \ 30*4b9c6d91SCole Faust // --no-layout-tests \ 31*4b9c6d91SCole Faust // --output libminijail.rs \ 32*4b9c6d91SCole Faust // libminijail.h -- \ 33*4b9c6d91SCole Faust // -DUSE_BINDGEN \ 34*4b9c6d91SCole Faust // -D_FILE_OFFSET_BITS=64 \ 35*4b9c6d91SCole Faust // -D_LARGEFILE_SOURCE \ 36*4b9c6d91SCole Faust // -D_LARGEFILE64_SOURCE 37*4b9c6d91SCole Faust // 38*4b9c6d91SCole Faust // Enum variants in rust are customarily camel case, but bindgen will leave the original names 39*4b9c6d91SCole Faust // intact. 40*4b9c6d91SCole Faust #[allow( 41*4b9c6d91SCole Faust clippy::all, 42*4b9c6d91SCole Faust non_camel_case_types, 43*4b9c6d91SCole Faust non_snake_case, 44*4b9c6d91SCole Faust non_upper_case_globals 45*4b9c6d91SCole Faust )] 46*4b9c6d91SCole Faust mod libminijail; 47*4b9c6d91SCole Faust pub use crate::libminijail::*; 48