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