blob: 0415f0f0e7a16d1981d690d94fdf418b4c443da0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass7a9219c2011-10-03 19:26:44 +00002/*
Simon Glassd9165152012-02-20 23:56:58 -05003 * Operating System Interface
4 *
5 * This provides access to useful OS routines for the sandbox architecture.
6 * They are kept in a separate file so we can include system headers.
7 *
Simon Glass7a9219c2011-10-03 19:26:44 +00008 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass7a9219c2011-10-03 19:26:44 +00009 */
10
Mike Frysinger4f345d52012-01-19 22:57:29 -050011#ifndef __OS_H__
12#define __OS_H__
13
Simon Glass2a54d152013-05-19 16:45:35 -070014#include <linux/types.h>
15
Simon Glass94eefde2015-04-20 12:37:22 -060016struct rtc_time;
Simon Glass70db4212012-02-15 15:51:16 -080017struct sandbox_state;
18
Simon Glass7a9219c2011-10-03 19:26:44 +000019/**
Heinrich Schuchardt7750ee42022-04-04 22:45:03 +020020 * os_printf() - print directly to OS console
21 *
22 * @format: format string
23 */
24int os_printf(const char *format, ...);
25
26/**
Simon Glass7a9219c2011-10-03 19:26:44 +000027 * Access to the OS read() system call
28 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010029 * @fd: File descriptor as returned by os_open()
30 * @buf: Buffer to place data
31 * @count: Number of bytes to read
32 * Return: number of bytes read, or -1 on error
Simon Glass7a9219c2011-10-03 19:26:44 +000033 */
34ssize_t os_read(int fd, void *buf, size_t count);
35
36/**
37 * Access to the OS write() system call
38 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010039 * @fd: File descriptor as returned by os_open()
40 * @buf: Buffer containing data to write
41 * @count: Number of bytes to write
42 * Return: number of bytes written, or -1 on error
Simon Glass7a9219c2011-10-03 19:26:44 +000043 */
44ssize_t os_write(int fd, const void *buf, size_t count);
45
46/**
Mike Frysingere2dcefc2011-10-25 13:02:58 +020047 * Access to the OS lseek() system call
48 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010049 * @fd: File descriptor as returned by os_open()
50 * @offset: File offset (based on whence)
51 * @whence: Position offset is relative to (see below)
52 * Return: new file offset
Mike Frysingere2dcefc2011-10-25 13:02:58 +020053 */
54off_t os_lseek(int fd, off_t offset, int whence);
55
56/* Defines for "whence" in os_lseek() */
57#define OS_SEEK_SET 0
58#define OS_SEEK_CUR 1
59#define OS_SEEK_END 2
60
61/**
Simon Glassb4467fa2021-08-18 21:40:30 -060062 * os_filesize() - Calculate the size of a file
63 *
64 * @fd: File descriptor as returned by os_open()
65 * Return: file size or negative error code
66 */
67int os_filesize(int fd);
68
69/**
Simon Glass7a9219c2011-10-03 19:26:44 +000070 * Access to the OS open() system call
71 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010072 * @pathname: Pathname of file to open
73 * @flags: Flags, like OS_O_RDONLY, OS_O_RDWR
74 * Return: file descriptor, or -1 on error
Simon Glass7a9219c2011-10-03 19:26:44 +000075 */
76int os_open(const char *pathname, int flags);
77
Simon Glassd9165152012-02-20 23:56:58 -050078#define OS_O_RDONLY 0
79#define OS_O_WRONLY 1
80#define OS_O_RDWR 2
81#define OS_O_MASK 3 /* Mask for read/write flags */
82#define OS_O_CREAT 0100
Simon Glass50b288a2018-10-01 11:55:07 -060083#define OS_O_TRUNC 01000
Simon Glassd9165152012-02-20 23:56:58 -050084
Simon Glass7a9219c2011-10-03 19:26:44 +000085/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010086 * os_close() - access to the OS close() system call
Simon Glass7a9219c2011-10-03 19:26:44 +000087 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010088 * @fd: File descriptor to close
89 * Return: 0 on success, -1 on error
Simon Glass7a9219c2011-10-03 19:26:44 +000090 */
91int os_close(int fd);
92
93/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010094 * os_unlink() - access to the OS unlink() system call
Stephen Warrencfd13e82014-03-01 22:18:00 -070095 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +010096 * @pathname: Path of file to delete
97 * Return: 0 for success, other for error
Stephen Warrencfd13e82014-03-01 22:18:00 -070098 */
99int os_unlink(const char *pathname);
100
101/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100102 * os_exit() - access to the OS exit() system call
Simon Glass7a9219c2011-10-03 19:26:44 +0000103 *
104 * This exits with the supplied return code, which should be 0 to indicate
105 * success.
106 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100107 * @exit_code: exit code for U-Boot
Simon Glass7a9219c2011-10-03 19:26:44 +0000108 */
Mike Frysinger9d72e672012-02-26 17:46:30 -0500109void os_exit(int exit_code) __attribute__((noreturn));
Mike Frysingerab06a752011-10-26 00:21:29 +0000110
111/**
Rasmus Villemoes10107ef2022-09-27 11:54:04 +0200112 * os_alarm() - access to the OS alarm() system call
Simon Glass6ca4d5b2022-10-29 19:47:04 -0600113 *
114 * @seconds: number of seconds before the signal is sent
115 * Returns: number of seconds remaining until any previously scheduled alarm was
116 * due to be delivered; 0 if there was no previously scheduled alarm
Rasmus Villemoes10107ef2022-09-27 11:54:04 +0200117 */
118unsigned int os_alarm(unsigned int seconds);
119
120/**
121 * os_set_alarm_handler() - set handler for SIGALRM
122 *
123 * @handler: The handler function. Pass NULL for SIG_DFL.
124 */
125void os_set_alarm_handler(void (*handler)(int));
126
127/**
128 * os_raise_sigalrm() - do raise(SIGALRM)
129 */
130void os_raise_sigalrm(void);
131
132/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100133 * os_tty_raw() - put tty into raw mode to mimic serial console better
Simon Glassffb87902014-02-27 13:26:22 -0700134 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100135 * @fd: File descriptor of stdin (normally 0)
136 * @allow_sigs: Allow Ctrl-C, Ctrl-Z to generate signals rather than
137 * be handled by U-Boot
Mike Frysingerab06a752011-10-26 00:21:29 +0000138 */
Simon Glassffb87902014-02-27 13:26:22 -0700139void os_tty_raw(int fd, bool allow_sigs);
Matthias Weisser21899b12011-11-05 11:40:34 +0100140
141/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100142 * os_fs_restore() - restore the tty to its original mode
Simon Glass8939df02015-05-10 21:07:27 -0600143 *
144 * Call this to restore the original terminal mode, after it has been changed
145 * by os_tty_raw(). This is an internal function.
146 */
147void os_fd_restore(void);
148
149/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100150 * os_malloc() - aquires some memory from the underlying os.
Matthias Weisser21899b12011-11-05 11:40:34 +0100151 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100152 * @length: Number of bytes to be allocated
Simon Glass14e46df2021-02-06 09:57:32 -0700153 * Return: Pointer to length bytes or NULL if @length is 0 or on error
Matthias Weisser21899b12011-11-05 11:40:34 +0100154 */
155void *os_malloc(size_t length);
Matthias Weisserd99a6872011-11-29 12:16:40 +0100156
157/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100158 * os_free() - free memory previous allocated with os_malloc()
Simon Glass77595c62013-11-10 10:26:57 -0700159 *
160 * This returns the memory to the OS.
161 *
Simon Glassb308d9f2021-02-06 09:57:33 -0700162 * @ptr: Pointer to memory block to free. If this is NULL then this
163 * function does nothing
Simon Glass77595c62013-11-10 10:26:57 -0700164 */
Masahiro Yamada347d06d2014-01-15 13:06:41 +0900165void os_free(void *ptr);
Simon Glass77595c62013-11-10 10:26:57 -0700166
167/**
Simon Glass14e46df2021-02-06 09:57:32 -0700168 * os_realloc() - reallocate memory
169 *
170 * This follows the semantics of realloc(), so can perform an os_malloc() or
171 * os_free() depending on @ptr and @length.
172 *
Heinrich Schuchardt4c30d182021-03-28 11:05:00 +0200173 * @ptr: pointer to previously allocated memory of NULL
174 * @length: number of bytes to allocate
175 * Return: pointer to reallocated memory or NULL if @length is 0
Simon Glass14e46df2021-02-06 09:57:32 -0700176 */
177void *os_realloc(void *ptr, size_t length);
178
179/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100180 * os_usleep() - access to the usleep function of the os
Matthias Weisserd99a6872011-11-29 12:16:40 +0100181 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100182 * @usec: time to sleep in micro seconds
Matthias Weisserd99a6872011-11-29 12:16:40 +0100183 */
184void os_usleep(unsigned long usec);
185
186/**
187 * Gets a monotonic increasing number of nano seconds from the OS
188 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100189 * Return: a monotonic increasing time scaled in nano seconds
Matthias Weisserd99a6872011-11-29 12:16:40 +0100190 */
Simon Glass2a54d152013-05-19 16:45:35 -0700191uint64_t os_get_nsec(void);
Mike Frysinger4f345d52012-01-19 22:57:29 -0500192
Simon Glass70db4212012-02-15 15:51:16 -0800193/**
194 * Parse arguments and update sandbox state.
195 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100196 * @state: sandbox state to update
197 * @argc: argument count
198 * @argv: argument vector
199 * Return:
200 * * 0 if ok, and program should continue
201 * * 1 if ok, but program should stop
202 * * -1 on error: program should terminate
Simon Glass70db4212012-02-15 15:51:16 -0800203 */
204int os_parse_args(struct sandbox_state *state, int argc, char *argv[]);
205
Simon Glass62584db2012-12-26 09:53:34 +0000206/*
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100207 * enum os_dirent_t - type of directory entry
208 *
Simon Glass62584db2012-12-26 09:53:34 +0000209 * Types of directory entry that we support. See also os_dirent_typename in
210 * the C file.
211 */
212enum os_dirent_t {
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100213 /**
214 * @OS_FILET_REG: regular file
215 */
216 OS_FILET_REG,
217 /**
218 * @OS_FILET_LNK: symbolic link
219 */
220 OS_FILET_LNK,
221 /**
222 * @OS_FILET_DIR: directory
223 */
224 OS_FILET_DIR,
225 /**
226 * @OS_FILET_UNKNOWN: something else
227 */
228 OS_FILET_UNKNOWN,
229 /**
230 * @OS_FILET_COUNT: number of directory entry types
231 */
Simon Glass62584db2012-12-26 09:53:34 +0000232 OS_FILET_COUNT,
233};
234
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100235/**
236 * struct os_dirent_node - directory node
237 *
238 * A directory entry node, containing information about a single dirent
239 *
240 */
Simon Glass62584db2012-12-26 09:53:34 +0000241struct os_dirent_node {
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100242 /**
243 * @next: pointer to next node, or NULL
244 */
245 struct os_dirent_node *next;
246 /**
247 * @size: size of file in bytes
248 */
249 ulong size;
250 /**
251 * @type: type of entry
252 */
253 enum os_dirent_t type;
254 /**
255 * @name: name of entry
256 */
257 char name[0];
Simon Glass62584db2012-12-26 09:53:34 +0000258};
259
260/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100261 * os_dirent_ls() - get a directory listing
Simon Glass62584db2012-12-26 09:53:34 +0000262 *
263 * This allocates and returns a linked list containing the directory listing.
264 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100265 * @dirname: directory to examine
266 * @headp: on return pointer to head of linked list, or NULL if none
267 * Return: 0 if ok, -ve on error
Simon Glass62584db2012-12-26 09:53:34 +0000268 */
269int os_dirent_ls(const char *dirname, struct os_dirent_node **headp);
270
271/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100272 * os_dirent_free() - free directory list
Stefan Brüns86167082016-10-01 20:41:38 +0200273 *
274 * This frees a linked list containing a directory listing.
275 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100276 * @node: pointer to head of linked list
Stefan Brüns86167082016-10-01 20:41:38 +0200277 */
278void os_dirent_free(struct os_dirent_node *node);
279
280/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100281 * os_dirent_get_typename() - get the name of a directory entry type
Simon Glass62584db2012-12-26 09:53:34 +0000282 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100283 * @type: type to check
284 * Return:
285 * string containing the name of that type,
286 * or "???" if none/invalid
Simon Glass62584db2012-12-26 09:53:34 +0000287 */
288const char *os_dirent_get_typename(enum os_dirent_t type);
289
290/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100291 * os_get_filesize() - get the size of a file
Simon Glass62584db2012-12-26 09:53:34 +0000292 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100293 * @fname: filename to check
294 * @size: size of file is returned if no error
295 * Return: 0 on success or -1 if an error ocurred
Simon Glass62584db2012-12-26 09:53:34 +0000296 */
Heinrich Schuchardt880dbc52022-01-11 01:50:24 +0100297int os_get_filesize(const char *fname, long long *size);
Simon Glass62584db2012-12-26 09:53:34 +0000298
Simon Glass91b136c2013-11-10 10:27:01 -0700299/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100300 * os_putc() - write a character to the controlling OS terminal
Simon Glass0b189b62017-12-04 13:48:17 -0700301 *
302 * This bypasses the U-Boot console support and writes directly to the OS
303 * stdout file descriptor.
304 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100305 * @ch: haracter to write
Simon Glass0b189b62017-12-04 13:48:17 -0700306 */
307void os_putc(int ch);
308
309/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100310 * os_puts() - write a string to the controlling OS terminal
Simon Glass0b189b62017-12-04 13:48:17 -0700311 *
312 * This bypasses the U-Boot console support and writes directly to the OS
313 * stdout file descriptor.
314 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100315 * @str: string to write (note that \n is not appended)
Simon Glass0b189b62017-12-04 13:48:17 -0700316 */
317void os_puts(const char *str);
318
319/**
Pali Rohár7df5b352022-09-05 11:31:16 +0200320 * os_flush() - flush controlling OS terminal
321 *
322 * This bypasses the U-Boot console support and flushes directly the OS
323 * stdout file descriptor.
324 */
325void os_flush(void);
326
327/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100328 * os_write_ram_buf() - write the sandbox RAM buffer to a existing file
Simon Glass5c2859c2013-11-10 10:27:03 -0700329 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100330 * @fname: filename to write memory to (simple binary format)
331 * Return: 0 if OK, -ve on error
Simon Glass5c2859c2013-11-10 10:27:03 -0700332 */
333int os_write_ram_buf(const char *fname);
334
335/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100336 * os_read_ram_buf() - read the sandbox RAM buffer from an existing file
Simon Glass5c2859c2013-11-10 10:27:03 -0700337 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100338 * @fname: filename containing memory (simple binary format)
339 * Return: 0 if OK, -ve on error
Simon Glass5c2859c2013-11-10 10:27:03 -0700340 */
341int os_read_ram_buf(const char *fname);
342
Simon Glass47f5fcf2014-02-27 13:26:15 -0700343/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100344 * os_jump_to_image() - jump to a new executable image
Simon Glass47f5fcf2014-02-27 13:26:15 -0700345 *
346 * This uses exec() to run a new executable image, after putting it in a
347 * temporary file. The same arguments and environment are passed to this
348 * new image, with the addition of:
349 *
350 * -j <filename> Specifies the filename the image was written to. The
351 * calling image may want to delete this at some point.
352 * -m <filename> Specifies the file containing the sandbox memory
353 * (ram_buf) from this image, so that the new image can
354 * have access to this. It also means that the original
355 * memory filename passed to U-Boot will be left intact.
356 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100357 * @dest: buffer containing executable image
358 * @size: size of buffer
359 * Return: 0 if OK, -ve on error
Simon Glass47f5fcf2014-02-27 13:26:15 -0700360 */
361int os_jump_to_image(const void *dest, int size);
362
Simon Glass94eefde2015-04-20 12:37:22 -0600363/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100364 * os_find_u_boot() - determine the path to U-Boot proper
Simon Glassd4e33f52016-07-04 11:57:45 -0600365 *
366 * This function is intended to be called from within sandbox SPL. It uses
367 * a few heuristics to find U-Boot proper. Normally it is either in the same
368 * directory, or the directory above (since u-boot-spl is normally in an
369 * spl/ subdirectory when built).
370 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100371 * @fname: place to put full path to U-Boot
372 * @maxlen: maximum size of @fname
Simon Glass01ad9f72021-03-07 17:35:13 -0700373 * @use_img: select the 'u-boot.img' file instead of the 'u-boot' ELF file
Simon Glassf178beb2021-07-05 16:32:45 -0600374 * @cur_prefix: prefix of current executable, e.g. "spl" or "tpl"
375 * @next_prefix: prefix of executable to find, e.g. "spl" or ""
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100376 * Return: 0 if OK, -NOSPC if the filename is too large, -ENOENT if not found
Simon Glassd4e33f52016-07-04 11:57:45 -0600377 */
Simon Glassf178beb2021-07-05 16:32:45 -0600378int os_find_u_boot(char *fname, int maxlen, bool use_img,
379 const char *cur_prefix, const char *next_prefix);
Simon Glassd4e33f52016-07-04 11:57:45 -0600380
381/**
382 * os_spl_to_uboot() - Run U-Boot proper
383 *
384 * When called from SPL, this runs U-Boot proper. The filename is obtained by
385 * calling os_find_u_boot().
386 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100387 * @fname: full pathname to U-Boot executable
388 * Return: 0 if OK, -ve on error
Simon Glassd4e33f52016-07-04 11:57:45 -0600389 */
390int os_spl_to_uboot(const char *fname);
391
392/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100393 * os_localtime() - read the current system time
Simon Glass94eefde2015-04-20 12:37:22 -0600394 *
395 * This reads the current Local Time and places it into the provided
396 * structure.
397 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100398 * @rt: place to put system time
Simon Glass94eefde2015-04-20 12:37:22 -0600399 */
400void os_localtime(struct rtc_time *rt);
401
Simon Glass30eef212018-05-16 09:42:22 -0600402/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100403 * os_abort() - raise SIGABRT to exit sandbox (e.g. to debugger)
Simon Glassfe938fb2018-09-15 00:50:55 -0600404 */
Heinrich Schuchardtc30a7092021-02-01 01:24:10 +0100405void os_abort(void) __attribute__((noreturn));
Simon Glass9f8037e2018-10-01 21:12:32 -0600406
407/**
408 * os_mprotect_allow() - Remove write-protection on a region of memory
409 *
410 * The start and length will be page-aligned before use.
411 *
412 * @start: Region start
413 * @len: Region length in bytes
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100414 * Return: 0 if OK, -1 on error from mprotect()
Simon Glass9f8037e2018-10-01 21:12:32 -0600415 */
416int os_mprotect_allow(void *start, size_t len);
417
Simon Glass056a5ce2018-10-01 11:55:08 -0600418/**
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100419 * os_write_file() - write a file to the host filesystem
Simon Glass056a5ce2018-10-01 11:55:08 -0600420 *
421 * This can be useful when debugging for writing data out of sandbox for
422 * inspection by external tools.
423 *
424 * @name: File path to write to
425 * @buf: Data to write
426 * @size: Size of data to write
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100427 * Return: 0 if OK, -ve on error
Simon Glass056a5ce2018-10-01 11:55:08 -0600428 */
429int os_write_file(const char *name, const void *buf, int size);
430
Simon Glass566bf3a2018-11-06 15:21:25 -0700431/**
432 * os_read_file() - Read a file from the host filesystem
433 *
434 * This can be useful when reading test data into sandbox for use by test
435 * routines. The data is allocated using os_malloc() and should be freed by
436 * the caller.
437 *
438 * @name: File path to read from
439 * @bufp: Returns buffer containing data read
440 * @sizep: Returns size of data
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100441 * Return: 0 if OK, -ve on error
Simon Glass566bf3a2018-11-06 15:21:25 -0700442 */
443int os_read_file(const char *name, void **bufp, int *sizep);
444
Simon Glassb9274092021-08-18 21:40:31 -0600445/**
446 * os_map_file() - Map a file from the host filesystem into memory
447 *
448 * This can be useful when to provide a backing store for an emulated device
449 *
450 * @pathname: File pathname to map
451 * @os_flags: Flags, like OS_O_RDONLY, OS_O_RDWR
452 * @bufp: Returns buffer containing the file
453 * @sizep: Returns size of data
454 * Return: 0 if OK, -ve on error
455 */
456int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep);
457
Simon Glassa0ff2802021-10-23 17:25:58 -0600458/**
459 * os_unmap() - Unmap a file previously mapped
460 *
461 * @buf: Mapped address
462 * @size: Size in bytes
463 * Return: 0 if OK, -ve on error
464 */
465int os_unmap(void *buf, int size);
466
Simon Glass001d1882019-04-08 13:20:41 -0600467/*
468 * os_find_text_base() - Find the text section in this running process
469 *
470 * This tries to find the address of the text section in this running process.
471 * It can be useful to map the address of functions to the address listed in
472 * the u-boot.map file.
473 *
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100474 * Return: address if found, else NULL
Simon Glass001d1882019-04-08 13:20:41 -0600475 */
476void *os_find_text_base(void);
477
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100478/**
479 * os_relaunch() - restart the sandbox
480 *
481 * This functions is used to implement the cold reboot of the sand box.
Heinrich Schuchardt063790c2020-10-27 20:29:27 +0100482 * @argv\[0] specifies the binary that is started while the calling process
Heinrich Schuchardt329dccc2020-10-27 20:29:25 +0100483 * stops immediately. If the new binary cannot be started, the process is
484 * terminated and 1 is set as shell return code.
485 *
486 * The PID of the process stays the same. All file descriptors that have not
487 * been opened with O_CLOEXEC stay open including stdin, stdout, stderr.
488 *
489 * @argv: NULL terminated list of command line parameters
490 */
491void os_relaunch(char *argv[]);
492
Heinrich Schuchardtb46f30a2020-11-12 00:29:56 +0100493/**
494 * os_setup_signal_handlers() - setup signal handlers
495 *
496 * Install signal handlers for SIGBUS and SIGSEGV.
497 *
498 * Return: 0 for success
499 */
500int os_setup_signal_handlers(void);
501
502/**
503 * os_signal_action() - handle a signal
504 *
505 * @sig: signal
506 * @pc: program counter
507 */
508void os_signal_action(int sig, unsigned long pc);
509
Heinrich Schuchardt43db0752020-12-30 18:07:48 +0100510/**
511 * os_get_time_offset() - get time offset
512 *
513 * Get the time offset from environment variable UBOOT_SB_TIME_OFFSET.
514 *
515 * Return: offset in seconds
516 */
517long os_get_time_offset(void);
518
519/**
520 * os_set_time_offset() - set time offset
521 *
522 * Save the time offset in environment variable UBOOT_SB_TIME_OFFSET.
523 *
524 * @offset: offset in seconds
525 */
526void os_set_time_offset(long offset);
527
Mike Frysinger4f345d52012-01-19 22:57:29 -0500528#endif