/*
 * object.h
 *
 * Copyright (C) 2013 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_OBJECT_H__
#define __MONOLITHIUM_OBJECT_H__

#include "defs.h"

#define INVALID_HANDLE  (handle_t)-1
#define NO_ACCESS       (access_flags_t)0
#define FULL_ACCESS     (access_flags_t)-1
#define OBJECT_ANY_TYPE OBJECT_TYPE_MAX

typedef dword_t handle_t;
typedef dword_t access_flags_t;

typedef enum
{
    OBJECT_FILE,
    OBJECT_FILE_INSTANCE,
    OBJECT_PIPELINE,
    OBJECT_PIPE,
    OBJECT_PROCESS,
    OBJECT_THREAD,
    OBJECT_MEMORY,
    OBJECT_SEMAPHORE,
    OBJECT_USER,

    OBJECT_TYPE_MAX
} object_type_t;

typedef enum
{
    HANDLE_INFO_NAME,
    HANDLE_INFO_TYPE,
} handle_info_type_t;

sysret_t syscall_close_object(handle_t handle);
sysret_t syscall_query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size);
sysret_t syscall_duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate);
sysret_t syscall_wait_for_one(handle_t handle, void *parameter, timeout_t timeout);
sysret_t syscall_wait_for_any(const handle_t *handles, void *const *parameters, size_t count, timeout_t timeout);
sysret_t syscall_wait_for_all(const handle_t *handles, void *const *parameters, size_t count, timeout_t timeout);

#endif
