KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
resource.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 sys/resource.h
4 Copyright (C) 2025 Donald Haase
5*/
6
7/** \file sys/resource.h
8 \brief Basic definitions for resource operations
9
10 This file provides a basic implementation of the POSIX/XSI
11 standard for resource operations. These are meant to be
12 per-process, so are basically stubs for the purposes of KOS
13 which is single-process.
14*/
15
16#ifndef __SYS_RESOURCE_H
17#define __SYS_RESOURCE_H
18
19#include <sys/cdefs.h>
20__BEGIN_DECLS
21
22#include <limits.h>
23#include <sys/time.h>
24#include <sys/types.h>
25
26/* Possible values for the `which` argument of
27 `getpriority()` and`setpriority()` */
28enum {
32};
33
34/** \brief Obtain the nice value of a process, process group, or user.
35
36 In KOS we don't have a concept currently of any of these things, so
37 this is effectively a stub that will only return a value if requested
38 for the default/current id.
39
40 \param which Which type of ID to get the nice value of.
41 \param who Only 0 is currently valid.
42 \retval 0 On success.
43 \retval -1 On error, errno will be set as appropriate.
44
45 \par Error Conditions:
46 \em EINVAL - `which` was an invalid value.
47 \em EINVAL - `who` was a value other than 0.
48*/
49int getpriority(int which, id_t who);
50
51/** \brief Sets the nice value of a process, process group, or user.
52
53 In KOS we don't have a concept currently of any of these things, so
54 this is effectively a stub that will only set a value if requested
55 for the default/current id. This also currently has no impact aside
56 from changing the return of `getpriority`.
57
58 \param which Which type of ID to set the nice value of.
59 \param who Only 0 is currently valid.
60 \param value nice value to set.
61 \retval 0 On success.
62 \retval -1 On error, errno will be set as appropriate.
63
64 \par Error Conditions:
65 \em EINVAL - `which` was an invalid value.
66 \em EINVAL - `who` was a value other than 0.
67*/
68int setpriority(int which, id_t who, int value);
69
70/* An unsigned integer type used for limit values */
71typedef unsigned int rlim_t;
72
73#define RLIM_INFINITY UINT_MAX
74#define RLIM_SAVED_MAX RLIM_INFINITY
75#define RLIM_SAVED_CUR RLIM_INFINITY
76
77struct rlimit {
78 rlim_t rlim_cur; /* The current (soft) limit. */
79 rlim_t rlim_max; /* The hard limit. */
80};
81
82/* Possible values for the `resource` argument of
83 `getrlimit()` and`setrlimit()` */
84enum {
85 RLIMIT_CORE, /* Limit on size of core image. */
86 RLIMIT_CPU, /* Limit on CPU time per process. */
87 RLIMIT_DATA, /* Limit on data segment size. */
88 RLIMIT_FSIZE, /* Limit on file size. */
89 RLIMIT_NOFILE, /* Limit on number of open files. */
90 RLIMIT_STACK, /* Limit on stack size. */
91 RLIMIT_AS /* Limit on address space size. */
92};
93
94/** \brief Gets the maximum resource consumption limits.
95
96 Everything will return `RLIM_INFINITY` as we impose no such
97 limits.
98
99 \param resource The type of resource to get the rlimit for.
100 \param rlp Where to place the rlimit data.
101
102 \retval 0 On success.
103 \retval -1 On error, errno will be set as appropriate.
104
105 \par Error Conditions:
106 \em EINVAL - `resource` was an invalid value.
107*/
108int getrlimit(int resource, struct rlimit *rlp);
109
110/** \brief Sets the maximum resource consumption limits.
111
112 Just a stub. Errors on bad input, otherwise always succeeds.
113
114 \param resource The type of resource to set the rlimit for.
115 \param rlp Ignored.
116
117 \retval 0 On success.
118 \retval -1 On error, errno will be set as appropriate.
119
120 \par Error Conditions:
121 \em EINVAL - `resource` was an invalid value.
122*/
123int setrlimit(int resource, const struct rlimit *rlp);
124
125/* Possible values for the `who` argument of `getrusage()` */
126enum {
127 RUSAGE_SELF, /* Returns information about the current process. */
128 RUSAGE_CHILDREN /* Returns information about children of the current process. */
130
131struct rusage {
132 struct timeval ru_utime; /* user time used */
133 struct timeval ru_stime; /* system time used */
134};
135
136/** \brief Get information about cpu utilization.
137
138 For the purposes of this function, KOS is treated as having a
139 single process that all threads are running under. As such `RUSAGE_SELF`
140 will return user time that is the sum of all living threads and
141 system time that is all the rest (IRQs + dead threads).
142 `RUSAGE_CHILDREN` will return zero.
143
144 \param who `RUSAGE_SELF` or `RUSAGE_CHILDREN`.
145 \param r_usage rusage data to be filled.
146 \retval 0 On success.
147 \retval -1 On error, errno will be set as appropriate.
148
149 \par Error Conditions:
150 \em EINVAL - `who` was an invalid value.
151*/
152int getrusage(int who, struct rusage *r_usage);
153
154__END_DECLS
155
156#endif /* !__SYS_RESOURCE_H */
Limits.
@ RLIMIT_CORE
Definition resource.h:85
@ RLIMIT_AS
Definition resource.h:91
@ RLIMIT_NOFILE
Definition resource.h:89
@ RLIMIT_CPU
Definition resource.h:86
@ RLIMIT_DATA
Definition resource.h:87
@ RLIMIT_FSIZE
Definition resource.h:88
@ RLIMIT_STACK
Definition resource.h:90
int setpriority(int which, id_t who, int value)
Sets the nice value of a process, process group, or user.
@ PRIO_USER
Definition resource.h:31
@ PRIO_PROCESS
Definition resource.h:29
@ PRIO_PGRP
Definition resource.h:30
int getrlimit(int resource, struct rlimit *rlp)
Gets the maximum resource consumption limits.
@ RUSAGE_CHILDREN
Definition resource.h:128
@ RUSAGE_SELF
Definition resource.h:127
int getpriority(int which, id_t who)
Obtain the nice value of a process, process group, or user.
int getrusage(int who, struct rusage *r_usage)
Get information about cpu utilization.
unsigned int rlim_t
Definition resource.h:71
int setrlimit(int resource, const struct rlimit *rlp)
Sets the maximum resource consumption limits.
Definition resource.h:77
rlim_t rlim_max
Definition resource.h:79
rlim_t rlim_cur
Definition resource.h:78
Definition resource.h:131
struct timeval ru_utime
Definition resource.h:132
struct timeval ru_stime
Definition resource.h:133