blob: 54874f5e0e88c6dbb10a6e7d0e07cf39efaea5b6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glasscd0684f2011-10-03 19:26:44 +00002/*
Simon Glass3196d752012-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 Glasscd0684f2011-10-03 19:26:44 +00008 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glasscd0684f2011-10-03 19:26:44 +00009 */
10
Mike Frysinger999a5792012-01-19 22:57:29 -050011#ifndef __OS_H__
12#define __OS_H__
13
Simon Glassfb4b4e82013-05-19 16:45:35 -070014#include <linux/types.h>
15
Simon Glass504548f2015-04-20 12:37:22 -060016struct rtc_time;
Simon Glass8a3e0352012-02-15 15:51:16 -080017struct sandbox_state;
18
Simon Glasscd0684f2011-10-03 19:26:44 +000019/**
Heinrich Schuchardtbb63ea82022-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 Glasscd0684f2011-10-03 19:26:44 +000027 * Access to the OS read() system call
28 *
Heinrich Schuchardt1ffe0042020-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 Glasscd0684f2011-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 Schuchardt1ffe0042020-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 Glasscd0684f2011-10-03 19:26:44 +000043 */
44ssize_t os_write(int fd, const void *buf, size_t count);
45
46/**
Mike Frysinger60addac2011-10-25 13:02:58 +020047 * Access to the OS lseek() system call
48 *
Heinrich Schuchardt1ffe0042020-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 Frysinger60addac2011-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 Glass7b9cf84f2021-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 Glasscd0684f2011-10-03 19:26:44 +000070 * Access to the OS open() system call
71 *
Heinrich Schuchardt1ffe0042020-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 Glasscd0684f2011-10-03 19:26:44 +000075 */
76int os_open(const char *pathname, int flags);
77
Simon Glass3196d752012-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 Glassce55a112018-10-01 11:55:07 -060083#define OS_O_TRUNC 01000
Simon Glass3196d752012-02-20 23:56:58 -050084
Simon Glasscd0684f2011-10-03 19:26:44 +000085/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +010086 * os_close() - access to the OS close() system call
Simon Glasscd0684f2011-10-03 19:26:44 +000087 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +010088 * @fd: File descriptor to close
89 * Return: 0 on success, -1 on error
Simon Glasscd0684f2011-10-03 19:26:44 +000090 */
91int os_close(int fd);
92
93/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +010094 * os_unlink() - access to the OS unlink() system call
Stephen Warrencd5edba2014-03-01 22:18:00 -070095 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +010096 * @pathname: Path of file to delete
97 * Return: 0 for success, other for error
Stephen Warrencd5edba2014-03-01 22:18:00 -070098 */
99int os_unlink(const char *pathname);
100
101/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100102 * os_exit() - access to the OS exit() system call
Simon Glasscd0684f2011-10-03 19:26:44 +0000103 *
104 * This exits with the supplied return code, which should be 0 to indicate
105 * success.
106 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100107 * @exit_code: exit code for U-Boot
Simon Glasscd0684f2011-10-03 19:26:44 +0000108 */
Mike Frysingerbc036d32012-02-26 17:46:30 -0500109void os_exit(int exit_code) __attribute__((noreturn));
Mike Frysingera5baaee2011-10-26 00:21:29 +0000110
111/**
Rasmus Villemoesae400f32022-09-27 11:54:04 +0200112 * os_alarm() - access to the OS alarm() system call
113 */
114unsigned int os_alarm(unsigned int seconds);
115
116/**
117 * os_set_alarm_handler() - set handler for SIGALRM
118 *
119 * @handler: The handler function. Pass NULL for SIG_DFL.
120 */
121void os_set_alarm_handler(void (*handler)(int));
122
123/**
124 * os_raise_sigalrm() - do raise(SIGALRM)
125 */
126void os_raise_sigalrm(void);
127
128/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100129 * os_tty_raw() - put tty into raw mode to mimic serial console better
Simon Glass678ef472014-02-27 13:26:22 -0700130 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100131 * @fd: File descriptor of stdin (normally 0)
132 * @allow_sigs: Allow Ctrl-C, Ctrl-Z to generate signals rather than
133 * be handled by U-Boot
Mike Frysingera5baaee2011-10-26 00:21:29 +0000134 */
Simon Glass678ef472014-02-27 13:26:22 -0700135void os_tty_raw(int fd, bool allow_sigs);
Matthias Weisserb5f7b472011-11-05 11:40:34 +0100136
137/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100138 * os_fs_restore() - restore the tty to its original mode
Simon Glass9c3b7d62015-05-10 21:07:27 -0600139 *
140 * Call this to restore the original terminal mode, after it has been changed
141 * by os_tty_raw(). This is an internal function.
142 */
143void os_fd_restore(void);
144
145/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100146 * os_malloc() - aquires some memory from the underlying os.
Matthias Weisserb5f7b472011-11-05 11:40:34 +0100147 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100148 * @length: Number of bytes to be allocated
Simon Glass4c902fa2021-02-06 09:57:32 -0700149 * Return: Pointer to length bytes or NULL if @length is 0 or on error
Matthias Weisserb5f7b472011-11-05 11:40:34 +0100150 */
151void *os_malloc(size_t length);
Matthias Weisser0d3dd142011-11-29 12:16:40 +0100152
153/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100154 * os_free() - free memory previous allocated with os_malloc()
Simon Glass1e6594c2013-11-10 10:26:57 -0700155 *
156 * This returns the memory to the OS.
157 *
Simon Glassedd094e2021-02-06 09:57:33 -0700158 * @ptr: Pointer to memory block to free. If this is NULL then this
159 * function does nothing
Simon Glass1e6594c2013-11-10 10:26:57 -0700160 */
Masahiro Yamadaee957282014-01-15 13:06:41 +0900161void os_free(void *ptr);
Simon Glass1e6594c2013-11-10 10:26:57 -0700162
163/**
Simon Glass4c902fa2021-02-06 09:57:32 -0700164 * os_realloc() - reallocate memory
165 *
166 * This follows the semantics of realloc(), so can perform an os_malloc() or
167 * os_free() depending on @ptr and @length.
168 *
Heinrich Schuchardt70e29992021-03-28 11:05:00 +0200169 * @ptr: pointer to previously allocated memory of NULL
170 * @length: number of bytes to allocate
171 * Return: pointer to reallocated memory or NULL if @length is 0
Simon Glass4c902fa2021-02-06 09:57:32 -0700172 */
173void *os_realloc(void *ptr, size_t length);
174
175/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100176 * os_usleep() - access to the usleep function of the os
Matthias Weisser0d3dd142011-11-29 12:16:40 +0100177 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100178 * @usec: time to sleep in micro seconds
Matthias Weisser0d3dd142011-11-29 12:16:40 +0100179 */
180void os_usleep(unsigned long usec);
181
182/**
183 * Gets a monotonic increasing number of nano seconds from the OS
184 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100185 * Return: a monotonic increasing time scaled in nano seconds
Matthias Weisser0d3dd142011-11-29 12:16:40 +0100186 */
Simon Glassfb4b4e82013-05-19 16:45:35 -0700187uint64_t os_get_nsec(void);
Mike Frysinger999a5792012-01-19 22:57:29 -0500188
Simon Glass8a3e0352012-02-15 15:51:16 -0800189/**
190 * Parse arguments and update sandbox state.
191 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100192 * @state: sandbox state to update
193 * @argc: argument count
194 * @argv: argument vector
195 * Return:
196 * * 0 if ok, and program should continue
197 * * 1 if ok, but program should stop
198 * * -1 on error: program should terminate
Simon Glass8a3e0352012-02-15 15:51:16 -0800199 */
200int os_parse_args(struct sandbox_state *state, int argc, char *argv[]);
201
Simon Glassf1c45c82012-12-26 09:53:34 +0000202/*
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100203 * enum os_dirent_t - type of directory entry
204 *
Simon Glassf1c45c82012-12-26 09:53:34 +0000205 * Types of directory entry that we support. See also os_dirent_typename in
206 * the C file.
207 */
208enum os_dirent_t {
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100209 /**
210 * @OS_FILET_REG: regular file
211 */
212 OS_FILET_REG,
213 /**
214 * @OS_FILET_LNK: symbolic link
215 */
216 OS_FILET_LNK,
217 /**
218 * @OS_FILET_DIR: directory
219 */
220 OS_FILET_DIR,
221 /**
222 * @OS_FILET_UNKNOWN: something else
223 */
224 OS_FILET_UNKNOWN,
225 /**
226 * @OS_FILET_COUNT: number of directory entry types
227 */
Simon Glassf1c45c82012-12-26 09:53:34 +0000228 OS_FILET_COUNT,
229};
230
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100231/**
232 * struct os_dirent_node - directory node
233 *
234 * A directory entry node, containing information about a single dirent
235 *
236 */
Simon Glassf1c45c82012-12-26 09:53:34 +0000237struct os_dirent_node {
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100238 /**
239 * @next: pointer to next node, or NULL
240 */
241 struct os_dirent_node *next;
242 /**
243 * @size: size of file in bytes
244 */
245 ulong size;
246 /**
247 * @type: type of entry
248 */
249 enum os_dirent_t type;
250 /**
251 * @name: name of entry
252 */
253 char name[0];
Simon Glassf1c45c82012-12-26 09:53:34 +0000254};
255
256/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100257 * os_dirent_ls() - get a directory listing
Simon Glassf1c45c82012-12-26 09:53:34 +0000258 *
259 * This allocates and returns a linked list containing the directory listing.
260 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100261 * @dirname: directory to examine
262 * @headp: on return pointer to head of linked list, or NULL if none
263 * Return: 0 if ok, -ve on error
Simon Glassf1c45c82012-12-26 09:53:34 +0000264 */
265int os_dirent_ls(const char *dirname, struct os_dirent_node **headp);
266
267/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100268 * os_dirent_free() - free directory list
Stefan Brünse0582842016-10-01 20:41:38 +0200269 *
270 * This frees a linked list containing a directory listing.
271 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100272 * @node: pointer to head of linked list
Stefan Brünse0582842016-10-01 20:41:38 +0200273 */
274void os_dirent_free(struct os_dirent_node *node);
275
276/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100277 * os_dirent_get_typename() - get the name of a directory entry type
Simon Glassf1c45c82012-12-26 09:53:34 +0000278 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100279 * @type: type to check
280 * Return:
281 * string containing the name of that type,
282 * or "???" if none/invalid
Simon Glassf1c45c82012-12-26 09:53:34 +0000283 */
284const char *os_dirent_get_typename(enum os_dirent_t type);
285
286/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100287 * os_get_filesize() - get the size of a file
Simon Glassf1c45c82012-12-26 09:53:34 +0000288 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100289 * @fname: filename to check
290 * @size: size of file is returned if no error
291 * Return: 0 on success or -1 if an error ocurred
Simon Glassf1c45c82012-12-26 09:53:34 +0000292 */
Heinrich Schuchardt011a1e02022-01-11 01:50:24 +0100293int os_get_filesize(const char *fname, long long *size);
Simon Glassf1c45c82012-12-26 09:53:34 +0000294
Simon Glass3e9fd242013-11-10 10:27:01 -0700295/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100296 * os_putc() - write a character to the controlling OS terminal
Simon Glass29d11432017-12-04 13:48:17 -0700297 *
298 * This bypasses the U-Boot console support and writes directly to the OS
299 * stdout file descriptor.
300 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100301 * @ch: haracter to write
Simon Glass29d11432017-12-04 13:48:17 -0700302 */
303void os_putc(int ch);
304
305/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100306 * os_puts() - write a string to the controlling OS terminal
Simon Glass29d11432017-12-04 13:48:17 -0700307 *
308 * This bypasses the U-Boot console support and writes directly to the OS
309 * stdout file descriptor.
310 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100311 * @str: string to write (note that \n is not appended)
Simon Glass29d11432017-12-04 13:48:17 -0700312 */
313void os_puts(const char *str);
314
315/**
Pali Rohár4acd1a02022-09-05 11:31:16 +0200316 * os_flush() - flush controlling OS terminal
317 *
318 * This bypasses the U-Boot console support and flushes directly the OS
319 * stdout file descriptor.
320 */
321void os_flush(void);
322
323/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100324 * os_write_ram_buf() - write the sandbox RAM buffer to a existing file
Simon Glass9dd10bf2013-11-10 10:27:03 -0700325 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100326 * @fname: filename to write memory to (simple binary format)
327 * Return: 0 if OK, -ve on error
Simon Glass9dd10bf2013-11-10 10:27:03 -0700328 */
329int os_write_ram_buf(const char *fname);
330
331/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100332 * os_read_ram_buf() - read the sandbox RAM buffer from an existing file
Simon Glass9dd10bf2013-11-10 10:27:03 -0700333 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100334 * @fname: filename containing memory (simple binary format)
335 * Return: 0 if OK, -ve on error
Simon Glass9dd10bf2013-11-10 10:27:03 -0700336 */
337int os_read_ram_buf(const char *fname);
338
Simon Glass860b7d92014-02-27 13:26:15 -0700339/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100340 * os_jump_to_image() - jump to a new executable image
Simon Glass860b7d92014-02-27 13:26:15 -0700341 *
342 * This uses exec() to run a new executable image, after putting it in a
343 * temporary file. The same arguments and environment are passed to this
344 * new image, with the addition of:
345 *
346 * -j <filename> Specifies the filename the image was written to. The
347 * calling image may want to delete this at some point.
348 * -m <filename> Specifies the file containing the sandbox memory
349 * (ram_buf) from this image, so that the new image can
350 * have access to this. It also means that the original
351 * memory filename passed to U-Boot will be left intact.
352 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100353 * @dest: buffer containing executable image
354 * @size: size of buffer
355 * Return: 0 if OK, -ve on error
Simon Glass860b7d92014-02-27 13:26:15 -0700356 */
357int os_jump_to_image(const void *dest, int size);
358
Simon Glass504548f2015-04-20 12:37:22 -0600359/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100360 * os_find_u_boot() - determine the path to U-Boot proper
Simon Glass2c931ba2016-07-04 11:57:45 -0600361 *
362 * This function is intended to be called from within sandbox SPL. It uses
363 * a few heuristics to find U-Boot proper. Normally it is either in the same
364 * directory, or the directory above (since u-boot-spl is normally in an
365 * spl/ subdirectory when built).
366 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100367 * @fname: place to put full path to U-Boot
368 * @maxlen: maximum size of @fname
Simon Glassb90e4872021-03-07 17:35:13 -0700369 * @use_img: select the 'u-boot.img' file instead of the 'u-boot' ELF file
Simon Glass1cd06002021-07-05 16:32:45 -0600370 * @cur_prefix: prefix of current executable, e.g. "spl" or "tpl"
371 * @next_prefix: prefix of executable to find, e.g. "spl" or ""
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100372 * Return: 0 if OK, -NOSPC if the filename is too large, -ENOENT if not found
Simon Glass2c931ba2016-07-04 11:57:45 -0600373 */
Simon Glass1cd06002021-07-05 16:32:45 -0600374int os_find_u_boot(char *fname, int maxlen, bool use_img,
375 const char *cur_prefix, const char *next_prefix);
Simon Glass2c931ba2016-07-04 11:57:45 -0600376
377/**
378 * os_spl_to_uboot() - Run U-Boot proper
379 *
380 * When called from SPL, this runs U-Boot proper. The filename is obtained by
381 * calling os_find_u_boot().
382 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100383 * @fname: full pathname to U-Boot executable
384 * Return: 0 if OK, -ve on error
Simon Glass2c931ba2016-07-04 11:57:45 -0600385 */
386int os_spl_to_uboot(const char *fname);
387
388/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100389 * os_localtime() - read the current system time
Simon Glass504548f2015-04-20 12:37:22 -0600390 *
391 * This reads the current Local Time and places it into the provided
392 * structure.
393 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100394 * @rt: place to put system time
Simon Glass504548f2015-04-20 12:37:22 -0600395 */
396void os_localtime(struct rtc_time *rt);
397
Simon Glass5dccd152018-05-16 09:42:22 -0600398/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100399 * os_abort() - raise SIGABRT to exit sandbox (e.g. to debugger)
Simon Glassb7255ef2018-09-15 00:50:55 -0600400 */
Heinrich Schuchardt2165d0c2021-02-01 01:24:10 +0100401void os_abort(void) __attribute__((noreturn));
Simon Glass4e766c22018-10-01 21:12:32 -0600402
403/**
404 * os_mprotect_allow() - Remove write-protection on a region of memory
405 *
406 * The start and length will be page-aligned before use.
407 *
408 * @start: Region start
409 * @len: Region length in bytes
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100410 * Return: 0 if OK, -1 on error from mprotect()
Simon Glass4e766c22018-10-01 21:12:32 -0600411 */
412int os_mprotect_allow(void *start, size_t len);
413
Simon Glasscbfa8452018-10-01 11:55:08 -0600414/**
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100415 * os_write_file() - write a file to the host filesystem
Simon Glasscbfa8452018-10-01 11:55:08 -0600416 *
417 * This can be useful when debugging for writing data out of sandbox for
418 * inspection by external tools.
419 *
420 * @name: File path to write to
421 * @buf: Data to write
422 * @size: Size of data to write
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100423 * Return: 0 if OK, -ve on error
Simon Glasscbfa8452018-10-01 11:55:08 -0600424 */
425int os_write_file(const char *name, const void *buf, int size);
426
Simon Glass8d176d82018-11-06 15:21:25 -0700427/**
428 * os_read_file() - Read a file from the host filesystem
429 *
430 * This can be useful when reading test data into sandbox for use by test
431 * routines. The data is allocated using os_malloc() and should be freed by
432 * the caller.
433 *
434 * @name: File path to read from
435 * @bufp: Returns buffer containing data read
436 * @sizep: Returns size of data
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100437 * Return: 0 if OK, -ve on error
Simon Glass8d176d82018-11-06 15:21:25 -0700438 */
439int os_read_file(const char *name, void **bufp, int *sizep);
440
Simon Glasse4c25c82021-08-18 21:40:31 -0600441/**
442 * os_map_file() - Map a file from the host filesystem into memory
443 *
444 * This can be useful when to provide a backing store for an emulated device
445 *
446 * @pathname: File pathname to map
447 * @os_flags: Flags, like OS_O_RDONLY, OS_O_RDWR
448 * @bufp: Returns buffer containing the file
449 * @sizep: Returns size of data
450 * Return: 0 if OK, -ve on error
451 */
452int os_map_file(const char *pathname, int os_flags, void **bufp, int *sizep);
453
Simon Glass5c1fd582021-10-23 17:25:58 -0600454/**
455 * os_unmap() - Unmap a file previously mapped
456 *
457 * @buf: Mapped address
458 * @size: Size in bytes
459 * Return: 0 if OK, -ve on error
460 */
461int os_unmap(void *buf, int size);
462
Simon Glass752707a2019-04-08 13:20:41 -0600463/*
464 * os_find_text_base() - Find the text section in this running process
465 *
466 * This tries to find the address of the text section in this running process.
467 * It can be useful to map the address of functions to the address listed in
468 * the u-boot.map file.
469 *
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100470 * Return: address if found, else NULL
Simon Glass752707a2019-04-08 13:20:41 -0600471 */
472void *os_find_text_base(void);
473
Heinrich Schuchardt1c678442020-10-27 20:29:25 +0100474/**
475 * os_relaunch() - restart the sandbox
476 *
477 * This functions is used to implement the cold reboot of the sand box.
Heinrich Schuchardt1ffe0042020-10-27 20:29:27 +0100478 * @argv\[0] specifies the binary that is started while the calling process
Heinrich Schuchardt1c678442020-10-27 20:29:25 +0100479 * stops immediately. If the new binary cannot be started, the process is
480 * terminated and 1 is set as shell return code.
481 *
482 * The PID of the process stays the same. All file descriptors that have not
483 * been opened with O_CLOEXEC stay open including stdin, stdout, stderr.
484 *
485 * @argv: NULL terminated list of command line parameters
486 */
487void os_relaunch(char *argv[]);
488
Heinrich Schuchardt28eb5092020-11-12 00:29:56 +0100489/**
490 * os_setup_signal_handlers() - setup signal handlers
491 *
492 * Install signal handlers for SIGBUS and SIGSEGV.
493 *
494 * Return: 0 for success
495 */
496int os_setup_signal_handlers(void);
497
498/**
499 * os_signal_action() - handle a signal
500 *
501 * @sig: signal
502 * @pc: program counter
503 */
504void os_signal_action(int sig, unsigned long pc);
505
Heinrich Schuchardtc0d1a002020-12-30 18:07:48 +0100506/**
507 * os_get_time_offset() - get time offset
508 *
509 * Get the time offset from environment variable UBOOT_SB_TIME_OFFSET.
510 *
511 * Return: offset in seconds
512 */
513long os_get_time_offset(void);
514
515/**
516 * os_set_time_offset() - set time offset
517 *
518 * Save the time offset in environment variable UBOOT_SB_TIME_OFFSET.
519 *
520 * @offset: offset in seconds
521 */
522void os_set_time_offset(long offset);
523
Mike Frysinger999a5792012-01-19 22:57:29 -0500524#endif