Skip to content
Snippets Groups Projects
Verified Commit 7f702720 authored by jD91mZM2's avatar jD91mZM2
Browse files

Fix header file generation for ptrace

parent 43ff8801
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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");
......
#ifndef _BITS_SYS_PTRACE_H
#define _BITS_SYS_PTRACE_H
int ptrace(int request, ...);
#endif
#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, ...) {
......
// 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;
}
......@@ -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, ...) {
......
#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, ...)
......
......@@ -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
//! 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())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment