1 : /*
2 : * Copyright 2010 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can
4 : * be found in the LICENSE file.
5 : */
6 :
7 :
8 : // This module defines the interface for interacting with platform specific
9 : // threads . This API provides a mechanism to query for a thread, by using
10 : // the acquire method with the ID of a pre-existing thread. The register
11 : // accessors are expected to return false if the thread is not in a state
12 : // where the registers can be accessed, such RUNNING or SYSCALL. This API
13 : // will throw:
14 : // std::exception - if a unexpected OS Error is encountered.
15 : // std::out_of_range - if the register index is out of range.
16 :
17 : #ifndef NATIVE_CLIENT_PORT_THREAD_H_
18 : #define NATIVE_CLIENT_PORT_THREAD_H_ 1
19 :
20 : #include <stdlib.h>
21 : #include <map>
22 :
23 : #include "native_client/src/trusted/port/std_types.h"
24 :
25 : namespace port {
26 :
27 4 : class IThread {
28 : public:
29 : enum State {
30 : DEAD =-1, // The thread has exited or been killed
31 : RUNNING = 0, // The thread is currently running
32 : SUSPENDED= 1, // The thread has been suspended
33 : SIGNALED = 2, // The thread is signaled
34 : SYSCALL = 3 // In a sys call, it's registers can not be modified.
35 : };
36 :
37 : typedef void (*CatchFunc_t)(uint32_t id, int8_t sig, void *cookie);
38 : typedef std::map<uint32_t, IThread*> ThreadMap_t;
39 :
40 : virtual uint32_t GetId() = 0;
41 : virtual State GetState() = 0;
42 :
43 : virtual bool SetStep(bool on) = 0;
44 :
45 : virtual bool GetRegister(uint32_t index, void *dst, uint32_t len) = 0;
46 : virtual bool SetRegister(uint32_t index, void *src, uint32_t len) = 0;
47 :
48 : virtual bool Suspend() = 0;
49 : virtual bool Resume() = 0;
50 :
51 : virtual void *GetContext() = 0;
52 :
53 : static IThread *Acquire(uint32_t id, bool create = true);
54 : static void Release(IThread *thread);
55 : static void SetExceptionCatch(CatchFunc_t func, void *cookie);
56 :
57 : protected:
58 0 : virtual ~IThread() {} // Prevent delete of base pointer
59 : };
60 :
61 : } // namespace port
62 :
63 : #endif // PORT_THREAD_H_
64 :
|