/*
 * process.h
 *
 * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __MONOLITHIUM_PROCESS_H__
#define __MONOLITHIUM_PROCESS_H__

#include "object.h"

#define CLONE_MAGIC 0x79706F43

#define PROCESS_CREATE_NO_INHERIT    (1 << 0)
#define PROCESS_CREATE_NO_THREADS    (1 << 1)
#define PROCESS_CREATE_FROZEN_THREAD (1 << 2)

typedef enum
{
    PROCESS_PID_INFO,
    PROCESS_NAME_INFO,
    PROCESS_START_TIME_INFO,
    PROCESS_MEMORY_INFO,
    PROCESS_EXIT_CODE_INFO,
    PROCESS_USER_INFO,
    PROCESS_THREAD_INFO,
    PROCESS_HANDLE_INFO,
} process_info_t;

typedef struct
{
    char *command_line;
    char *working_directory;
    handle_t standard_input;
    handle_t standard_output;
    handle_t standard_error;
} process_params_t;

sysret_t syscall_open_process(dword_t pid, handle_t *handle);
sysret_t syscall_create_process(const char *path, dword_t flags, process_params_t *parameters, handle_t *process_handle, handle_t *thread_handle);
sysret_t syscall_terminate(handle_t handle, dword_t exit_code);
sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *buffer, dword_t size);
sysret_t syscall_enum_processes(dword_t *pid_array, dword_t *count);

#endif
