Fix header file generation for ptrace

This commit is contained in:
jD91mZM2
2019-07-07 15:37:29 +02:00
parent 43ff8801bc
commit 7f702720af
9 changed files with 37 additions and 14 deletions
+1 -4
View File
@@ -27,10 +27,7 @@ endif
SRC=\
Cargo.* \
src/* \
src/*/* \
src/*/*/* \
src/*/*/*/*
$(shell find src -type f)
.PHONY: all clean fmt headers install install-headers libs test
+5 -9
View File
@@ -1,6 +1,6 @@
extern crate cc;
use std::env;
use std::{env, fs};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
@@ -8,16 +8,12 @@ fn main() {
cc::Build::new()
.flag("-nostdinc")
.flag("-nostdlib")
.flag("-I")
.flag(&format!("{}/include", crate_dir))
.include(&format!("{}/include", crate_dir))
.flag("-fno-stack-protector")
.flag("-Wno-expansion-to-defined")
.file("src/c/dlmalloc.c")
.file("src/c/fcntl.c")
.file("src/c/stack_chk.c")
.file("src/c/stdio.c")
.file("src/c/stdlib.c")
.file("src/c/unistd.c")
.files(fs::read_dir("src/c")
.expect("src/c directory missing")
.map(|res| res.expect("read_dir error").path()))
.compile("relibc_c");
println!("cargo:rustc-link-lib=static=relibc_c");
+6
View File
@@ -0,0 +1,6 @@
#ifndef _BITS_SYS_PTRACE_H
#define _BITS_SYS_PTRACE_H
int ptrace(int request, ...);
#endif
+2
View File
@@ -1,6 +1,8 @@
#include <stdarg.h>
#include <sys/types.h>
// TODO: Can be implemented in rust when cbindgen supports "..." syntax
int sys_open(const char* filename, int flags, mode_t mode);
int open(const char* filename, int flags, ...) {
+13
View File
@@ -0,0 +1,13 @@
// TODO: Can be implemented in rust when cbindgen supports "..." syntax
#include <stdarg.h>
int sys_ptrace(int request, va_list ap);
int ptrace(int request, ...) {
va_list ap;
va_start(ap, request);
int ret = sys_ptrace(request, ap);
va_end(ap);
return ret;
}
+2
View File
@@ -3,6 +3,8 @@
typedef struct FILE FILE;
// TODO: Can be implemented in rust when cbindgen supports "..." syntax
int vasprintf(char ** strp, const char * fmt, va_list ap);
int asprintf(char ** strp, const char * fmt, ...) {
+2
View File
@@ -1,6 +1,8 @@
#include <stdarg.h>
#include <stddef.h>
// TODO: Can be implemented in rust when cbindgen supports "..." syntax
int execv(const char *path, char *const *argv);
int execl(const char *path, const char* argv0, ...)
+1
View File
@@ -2,6 +2,7 @@ sys_includes = []
include_guard = "_SYS_PTRACE_H"
language = "C"
style = "Tag"
trailer = "#include <bits/sys/ptrace.h>"
[enum]
prefix_with_name = true
+5 -1
View File
@@ -1,8 +1,10 @@
//! ptrace compatibility layer for Redox OS
use core::ffi::VaList;
use platform::types::*;
use platform::{PalPtrace, Sys};
pub const PTRACE_TRACEME: c_int = 0;
pub const PTRACE_PEEKTEXT: c_int = 1;
pub const PTRACE_PEEKDATA: c_int = 2;
pub const PTRACE_POKETEXT: c_int = 4;
@@ -16,9 +18,11 @@ pub const PTRACE_GETFPREGS: c_int = 14;
pub const PTRACE_SETFPREGS: c_int = 15;
pub const PTRACE_ATTACH: c_int = 16;
pub const PTRACE_DETACH: c_int = 17;
pub const PTRACE_SYSCALL: c_int = 24;
// Can't use "params: ..." syntax, because... guess what? Cbingen again :(
#[no_mangle]
pub unsafe extern "C" fn ptrace(request: c_int, mut params: ...) -> c_int {
pub unsafe extern "C" fn sys_ptrace(request: c_int, mut params: VaList) -> c_int {
// Musl also just grabs the arguments from the varargs...
Sys::ptrace(request, params.arg(), params.arg(), params.arg())
}