1 // Licensed to the Apache Software Foundation (ASF) under one 2 // or more contributor license agreements. See the NOTICE file 3 // distributed with this work for additional information 4 // regarding copyright ownership. The ASF licenses this file 5 // to you under the Apache License, Version 2.0 (the 6 // "License"); you may not use this file except in compliance 7 // with the License. You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 use optee_utee_sys as raw; 19 use core::ffi::*; 20 use core::fmt::{Arguments, Write, Result}; 21 22 pub struct Trace; 23 24 impl Trace { new() -> Self25 fn new() -> Self { 26 Trace {} 27 } 28 _print(fmt: Arguments)29 pub fn _print(fmt: Arguments) { 30 let mut writer = Trace::new(); 31 let result = writer.write_fmt(fmt); 32 33 if let Err(e) = result { 34 panic!("failed printing to trace: {}", e); 35 } 36 } 37 set_level(level: i32)38 pub fn set_level(level: i32) { 39 unsafe { 40 raw::trace_set_level(level); 41 } 42 } 43 get_level() -> i3244 pub fn get_level() -> i32 { 45 unsafe { raw::trace_get_level() } 46 } 47 } 48 49 impl Write for Trace { write_str(&mut self, buf: &str) -> Result<>50 fn write_str(&mut self, buf: &str) -> Result<> { 51 unsafe { 52 raw::_utee_log(buf.as_ptr() as *const c_void, buf.len()); 53 } 54 Ok(()) 55 } 56 } 57